Skip to content

Commit

Permalink
Do not suggest <_ as Into<_>> blanket impl
Browse files Browse the repository at this point in the history
We will usually have a better, more specific, alternative suggestion.
  • Loading branch information
estebank committed Nov 6, 2024
1 parent 1f00265 commit 78f1303
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
assoc
} else {
// The method isn't in this `impl` or `trait`? Not useful to us then.
return;
return;
}
};
let Some(trait_assoc_item) = assoc.trait_item_def_id else {
Expand All @@ -863,7 +863,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
});
}
InferenceSuggestionFormat::FullyQualifiedMethodCall => {
paths.push(self.tcx.value_path_str_with_args(def_id, args));
if let Some(did) = tcx.get_diagnostic_item(sym::Into)
&& did == trait_def_id
&& let Some(arg) = impl_args.types().skip(1).next()
&& let ty::Infer(_) | ty::Param(_) = arg.kind()
{
// Skip `<T as Into<_>>` blanket
} else {
paths.push(self.tcx.value_path_str_with_args(def_id, args));
}
}
}
});
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/error-codes/E0283.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ LL | impl Into<u32> for Impl {
where U: From<T>;
help: try using a fully qualified path to specify the expected types
|
LL | let bar = <_ as Into<_>>::into(foo_impl) * 1u32;
| +++++++++++++++++++++ ~
help: try using a fully qualified path to specify the expected types
|
LL | let bar = <Impl as Into<u32>>::into(foo_impl) * 1u32;
| ++++++++++++++++++++++++++ ~

Expand Down
8 changes: 0 additions & 8 deletions tests/ui/pattern/slice-pattern-refutable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ LL | if let [a, b, c] = Zeroes.into() {
|
help: try using a fully qualified path to specify the expected types
|
LL | if let [a, b, c] = <_ as Into<_>>::into(Zeroes) {
| +++++++++++++++++++++ ~
help: try using a fully qualified path to specify the expected types
|
LL | if let [a, b, c] = <Zeroes as Into<[usize; 3]>>::into(Zeroes) {
| +++++++++++++++++++++++++++++++++++ ~

Expand All @@ -40,10 +36,6 @@ LL | if let [a, b, c] = Zeroes.into() {
|
help: try using a fully qualified path to specify the expected types
|
LL | if let [a, b, c] = <_ as Into<_>>::into(Zeroes) {
| +++++++++++++++++++++ ~
help: try using a fully qualified path to specify the expected types
|
LL | if let [a, b, c] = <Zeroes as Into<[usize; 3]>>::into(Zeroes) {
| +++++++++++++++++++++++++++++++++++ ~

Expand Down
8 changes: 0 additions & 8 deletions tests/ui/pattern/slice-patterns-ambiguity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ LL | if let &[a, b] = Zeroes.into() {
|
help: try using a fully qualified path to specify the expected types
|
LL | if let &[a, b] = <_ as Into<_>>::into(Zeroes) {
| +++++++++++++++++++++ ~
help: try using a fully qualified path to specify the expected types
|
LL | if let &[a, b] = <Zeroes as Into<&'static [usize; 2]>>::into(Zeroes) {
| ++++++++++++++++++++++++++++++++++++++++++++ ~
help: try using a fully qualified path to specify the expected types
Expand All @@ -40,10 +36,6 @@ LL | if let &[a, b] = Zeroes.into() {
|
help: try using a fully qualified path to specify the expected types
|
LL | if let &[a, b] = <_ as Into<_>>::into(Zeroes) {
| +++++++++++++++++++++ ~
help: try using a fully qualified path to specify the expected types
|
LL | if let &[a, b] = <Zeroes as Into<&'static [usize; 2]>>::into(Zeroes) {
| ++++++++++++++++++++++++++++++++++++++++++++ ~
help: try using a fully qualified path to specify the expected types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | .into()?;
= note: required for `FilterMap<Map<std::slice::Iter<'_, &str>, {closure@$DIR/into-inference-needs-type.rs:10:14: 10:17}>, fn(Option<&str>) -> Option<Option<&str>> {Option::<Option<&str>>::Some}>` to implement `Into<_>`
help: try using a fully qualified path to specify the expected types
|
LL ~ let list = <_ as Into<_>>::into(vec
LL ~ let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec
LL | .iter()
LL | .map(|s| s.strip_prefix("t"))
LL ~ .filter_map(Option::Some))?;
Expand Down

0 comments on commit 78f1303

Please sign in to comment.