diff options
| author | Ralf Jung <post@ralfj.de> | 2020-09-21 15:30:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-21 15:30:39 +0200 |
| commit | 982c4a9c25f0a4ae769580f8093aea209cb8b8c1 (patch) | |
| tree | 08e8746020589ae1e08d5be57aa6f531d0a750e0 | |
| parent | ae4b677aa895a05e84abbb8a3307b0e96bc4a39f (diff) | |
| parent | 026922ad60a9529f16b792e8c2fe805ab3906259 (diff) | |
| download | rust-982c4a9c25f0a4ae769580f8093aea209cb8b8c1.tar.gz rust-982c4a9c25f0a4ae769580f8093aea209cb8b8c1.zip | |
Rollup merge of #76835 - matthiaskrgr:replace_prefix, r=lcnr
make replace_prefix only take &str as arguments included the clippy::manual strip commit to not run into merge conflicts later. r? @lcnr
| -rw-r--r-- | compiler/rustc_typeck/src/check/demand.rs | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index c7ce5008c33..247bbf637ce 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -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 { |
