make replace_prefix only take &str as arguments
https://github.com/rust-lang/rust/pull/76828#issuecomment-694078200
This commit is contained in:
parent
012974da7a
commit
026922ad60
@ -362,16 +362,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
false
|
||||
}
|
||||
|
||||
fn replace_prefix<A, B, C>(&self, s: A, old: B, new: C) -> Option<String>
|
||||
where
|
||||
A: AsRef<str>,
|
||||
B: AsRef<str>,
|
||||
C: AsRef<str>,
|
||||
{
|
||||
let s = s.as_ref();
|
||||
let old = old.as_ref();
|
||||
fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
|
||||
if let Some(stripped) = s.strip_prefix(old) {
|
||||
Some(new.as_ref().to_owned() + stripped)
|
||||
Some(new.to_string() + stripped)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -422,7 +415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
|
||||
if let hir::ExprKind::Lit(_) = expr.kind {
|
||||
if let Ok(src) = sm.span_to_snippet(sp) {
|
||||
if let Some(src) = self.replace_prefix(src, "b\"", "\"") {
|
||||
if let Some(src) = self.replace_prefix(&src, "b\"", "\"") {
|
||||
return Some((
|
||||
sp,
|
||||
"consider removing the leading `b`",
|
||||
@ -436,7 +429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
|
||||
if let hir::ExprKind::Lit(_) = expr.kind {
|
||||
if let Ok(src) = sm.span_to_snippet(sp) {
|
||||
if let Some(src) = self.replace_prefix(src, "\"", "b\"") {
|
||||
if let Some(src) = self.replace_prefix(&src, "\"", "b\"") {
|
||||
return Some((
|
||||
sp,
|
||||
"consider adding a leading `b`",
|
||||
@ -561,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// we may want to suggest removing a `&`.
|
||||
if sm.is_imported(expr.span) {
|
||||
if let Ok(src) = sm.span_to_snippet(sp) {
|
||||
if let Some(src) = self.replace_prefix(src, "&", "") {
|
||||
if let Some(src) = self.replace_prefix(&src, "&", "") {
|
||||
return Some((
|
||||
sp,
|
||||
"consider removing the borrow",
|
||||
@ -598,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
match mutbl_a {
|
||||
hir::Mutability::Mut => {
|
||||
if let Some(s) =
|
||||
self.replace_prefix(src, "&mut ", new_prefix)
|
||||
self.replace_prefix(&src, "&mut ", &new_prefix)
|
||||
{
|
||||
Some((s, Applicability::MachineApplicable))
|
||||
} else {
|
||||
@ -607,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
hir::Mutability::Not => {
|
||||
if let Some(s) =
|
||||
self.replace_prefix(src, "&", new_prefix)
|
||||
self.replace_prefix(&src, "&", &new_prefix)
|
||||
{
|
||||
Some((s, Applicability::Unspecified))
|
||||
} else {
|
||||
@ -621,7 +614,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
match mutbl_a {
|
||||
hir::Mutability::Mut => {
|
||||
if let Some(s) =
|
||||
self.replace_prefix(src, "&mut ", new_prefix)
|
||||
self.replace_prefix(&src, "&mut ", &new_prefix)
|
||||
{
|
||||
Some((s, Applicability::MachineApplicable))
|
||||
} else {
|
||||
@ -630,7 +623,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
hir::Mutability::Not => {
|
||||
if let Some(s) =
|
||||
self.replace_prefix(src, "&", new_prefix)
|
||||
self.replace_prefix(&src, "&", &new_prefix)
|
||||
{
|
||||
Some((s, Applicability::MachineApplicable))
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user