Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 78f1303

Browse files
committedNov 6, 2024
Do not suggest <_ as Into<_>> blanket impl
We will usually have a better, more specific, alternative suggestion.
1 parent 1f00265 commit 78f1303

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed
 

‎compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
843843
assoc
844844
} else {
845845
// The method isn't in this `impl` or `trait`? Not useful to us then.
846-
return;
846+
return;
847847
}
848848
};
849849
let Some(trait_assoc_item) = assoc.trait_item_def_id else {
@@ -863,7 +863,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
863863
});
864864
}
865865
InferenceSuggestionFormat::FullyQualifiedMethodCall => {
866-
paths.push(self.tcx.value_path_str_with_args(def_id, args));
866+
if let Some(did) = tcx.get_diagnostic_item(sym::Into)
867+
&& did == trait_def_id
868+
&& let Some(arg) = impl_args.types().skip(1).next()
869+
&& let ty::Infer(_) | ty::Param(_) = arg.kind()
870+
{
871+
// Skip `<T as Into<_>>` blanket
872+
} else {
873+
paths.push(self.tcx.value_path_str_with_args(def_id, args));
874+
}
867875
}
868876
}
869877
});

‎tests/ui/error-codes/E0283.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ LL | impl Into<u32> for Impl {
3030
where U: From<T>;
3131
help: try using a fully qualified path to specify the expected types
3232
|
33-
LL | let bar = <_ as Into<_>>::into(foo_impl) * 1u32;
34-
| +++++++++++++++++++++ ~
35-
help: try using a fully qualified path to specify the expected types
36-
|
3733
LL | let bar = <Impl as Into<u32>>::into(foo_impl) * 1u32;
3834
| ++++++++++++++++++++++++++ ~
3935

‎tests/ui/pattern/slice-pattern-refutable.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ LL | if let [a, b, c] = Zeroes.into() {
2323
|
2424
help: try using a fully qualified path to specify the expected types
2525
|
26-
LL | if let [a, b, c] = <_ as Into<_>>::into(Zeroes) {
27-
| +++++++++++++++++++++ ~
28-
help: try using a fully qualified path to specify the expected types
29-
|
3026
LL | if let [a, b, c] = <Zeroes as Into<[usize; 3]>>::into(Zeroes) {
3127
| +++++++++++++++++++++++++++++++++++ ~
3228

@@ -40,10 +36,6 @@ LL | if let [a, b, c] = Zeroes.into() {
4036
|
4137
help: try using a fully qualified path to specify the expected types
4238
|
43-
LL | if let [a, b, c] = <_ as Into<_>>::into(Zeroes) {
44-
| +++++++++++++++++++++ ~
45-
help: try using a fully qualified path to specify the expected types
46-
|
4739
LL | if let [a, b, c] = <Zeroes as Into<[usize; 3]>>::into(Zeroes) {
4840
| +++++++++++++++++++++++++++++++++++ ~
4941

‎tests/ui/pattern/slice-patterns-ambiguity.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ LL | if let &[a, b] = Zeroes.into() {
1919
|
2020
help: try using a fully qualified path to specify the expected types
2121
|
22-
LL | if let &[a, b] = <_ as Into<_>>::into(Zeroes) {
23-
| +++++++++++++++++++++ ~
24-
help: try using a fully qualified path to specify the expected types
25-
|
2622
LL | if let &[a, b] = <Zeroes as Into<&'static [usize; 2]>>::into(Zeroes) {
2723
| ++++++++++++++++++++++++++++++++++++++++++++ ~
2824
help: try using a fully qualified path to specify the expected types
@@ -40,10 +36,6 @@ LL | if let &[a, b] = Zeroes.into() {
4036
|
4137
help: try using a fully qualified path to specify the expected types
4238
|
43-
LL | if let &[a, b] = <_ as Into<_>>::into(Zeroes) {
44-
| +++++++++++++++++++++ ~
45-
help: try using a fully qualified path to specify the expected types
46-
|
4739
LL | if let &[a, b] = <Zeroes as Into<&'static [usize; 2]>>::into(Zeroes) {
4840
| ++++++++++++++++++++++++++++++++++++++++++++ ~
4941
help: try using a fully qualified path to specify the expected types

‎tests/ui/suggestions/types/into-inference-needs-type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | .into()?;
88
= 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<_>`
99
help: try using a fully qualified path to specify the expected types
1010
|
11-
LL ~ let list = <_ as Into<_>>::into(vec
11+
LL ~ let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec
1212
LL | .iter()
1313
LL | .map(|s| s.strip_prefix("t"))
1414
LL ~ .filter_map(Option::Some))?;

0 commit comments

Comments
 (0)
Failed to load comments.