Skip to content

Commit c6bb219

Browse files
authored
Rollup merge of #93469 - compiler-errors:issue-93450, r=estebank
Skip pointing out ambiguous impls in alloc/std crates too in inference errors This generalizes the logic in `annotate_source_of_ambiguity` to skip printing ambiguity errors traits in `alloc` and `std` as well, not just `core`. While this does spot-fix the issue mentioned below, it would be nicer to generalize this logic, for example to detect when the trait predicate's `self_ty` has any numerical inference variables. Is it worthwhile to scrap this solution for one like that? Fixes #93450 r? `@estebank` feel free to reassign
2 parents 4435bb0 + 9072c8d commit c6bb219

File tree

5 files changed

+18
-44
lines changed

5 files changed

+18
-44
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
19541954

19551955
if self.is_tainted_by_errors()
19561956
&& crate_names.len() == 1
1957-
&& crate_names[0] == "`core`"
1957+
&& ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str())
19581958
&& spans.len() == 0
19591959
{
19601960
// Avoid complaining about other inference issues for expressions like

Diff for: src/test/ui/impl-trait/equality.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn two(x: bool) -> impl Foo {
1717
//~| expected `i32`, found `u32`
1818
}
1919

20-
fn sum_to(n: u32) -> impl Foo { //~ ERROR type annotations needed
20+
fn sum_to(n: u32) -> impl Foo {
2121
if n == 0 {
2222
0
2323
} else {

Diff for: src/test/ui/impl-trait/equality.stderr

+2-17
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,7 @@ LL | n + sum_to(n - 1)
3434
|
3535
= help: the trait `Add<impl Foo>` is not implemented for `u32`
3636

37-
error[E0283]: type annotations needed
38-
--> $DIR/equality.rs:20:22
39-
|
40-
LL | fn sum_to(n: u32) -> impl Foo {
41-
| ^^^^^^^^ cannot infer type for type `{integer}`
42-
|
43-
= note: multiple `impl`s satisfying `{integer}: ToString` found in the `alloc` crate:
44-
- impl ToString for i8;
45-
- impl ToString for u8;
46-
note: required because of the requirements on the impl of `Foo` for `{integer}`
47-
--> $DIR/equality.rs:5:26
48-
|
49-
LL | impl<T: Copy + ToString> Foo for T {}
50-
| ^^^ ^
51-
52-
error: aborting due to 3 previous errors; 1 warning emitted
37+
error: aborting due to 2 previous errors; 1 warning emitted
5338

54-
Some errors have detailed explanations: E0277, E0283, E0308.
39+
Some errors have detailed explanations: E0277, E0308.
5540
For more information about an error, try `rustc --explain E0277`.

Diff for: src/test/ui/issues/issue-72690.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ fn err() {
1010

1111
fn arg_pat_closure_err() {
1212
|x| String::from("x".as_ref()); //~ ERROR type annotations needed
13-
//~^ ERROR type annotations needed
1413
//~| ERROR type annotations needed
1514
}
1615

Diff for: src/test/ui/issues/issue-72690.stderr

+14-24
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ error[E0282]: type annotations needed
2929
LL | |x| String::from("x".as_ref());
3030
| ^ consider giving this closure parameter a type
3131

32-
error[E0283]: type annotations needed
33-
--> $DIR/issue-72690.rs:12:9
34-
|
35-
LL | |x| String::from("x".as_ref());
36-
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
37-
|
38-
= note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
39-
- impl<> From<&String> for String;
40-
- impl<> From<&str> for String;
41-
4232
error[E0283]: type annotations needed
4333
--> $DIR/issue-72690.rs:12:26
4434
|
@@ -55,7 +45,7 @@ LL | |x| String::from("x".as_ref());
5545
- impl AsRef<str> for str;
5646

5747
error[E0283]: type annotations needed for `&T`
58-
--> $DIR/issue-72690.rs:18:17
48+
--> $DIR/issue-72690.rs:17:17
5949
|
6050
LL | let _ = "x".as_ref();
6151
| - ^^^^^^ cannot infer type for type parameter `T` declared on the trait `AsRef`
@@ -69,7 +59,7 @@ LL | let _ = "x".as_ref();
6959
- impl AsRef<str> for str;
7060

7161
error[E0283]: type annotations needed
72-
--> $DIR/issue-72690.rs:22:5
62+
--> $DIR/issue-72690.rs:21:5
7363
|
7464
LL | String::from("x".as_ref());
7565
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@@ -79,7 +69,7 @@ LL | String::from("x".as_ref());
7969
- impl<> From<&str> for String;
8070

8171
error[E0283]: type annotations needed
82-
--> $DIR/issue-72690.rs:22:22
72+
--> $DIR/issue-72690.rs:21:22
8373
|
8474
LL | String::from("x".as_ref());
8575
| ----^^^^^^--
@@ -94,7 +84,7 @@ LL | String::from("x".as_ref());
9484
- impl AsRef<str> for str;
9585

9686
error[E0283]: type annotations needed
97-
--> $DIR/issue-72690.rs:29:5
87+
--> $DIR/issue-72690.rs:28:5
9888
|
9989
LL | String::from("x".as_ref());
10090
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@@ -104,7 +94,7 @@ LL | String::from("x".as_ref());
10494
- impl<> From<&str> for String;
10595

10696
error[E0283]: type annotations needed
107-
--> $DIR/issue-72690.rs:29:22
97+
--> $DIR/issue-72690.rs:28:22
10898
|
10999
LL | String::from("x".as_ref());
110100
| ----^^^^^^--
@@ -119,7 +109,7 @@ LL | String::from("x".as_ref());
119109
- impl AsRef<str> for str;
120110

121111
error[E0283]: type annotations needed
122-
--> $DIR/issue-72690.rs:38:5
112+
--> $DIR/issue-72690.rs:37:5
123113
|
124114
LL | String::from("x".as_ref());
125115
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@@ -129,7 +119,7 @@ LL | String::from("x".as_ref());
129119
- impl<> From<&str> for String;
130120

131121
error[E0283]: type annotations needed
132-
--> $DIR/issue-72690.rs:38:22
122+
--> $DIR/issue-72690.rs:37:22
133123
|
134124
LL | String::from("x".as_ref());
135125
| ----^^^^^^--
@@ -144,7 +134,7 @@ LL | String::from("x".as_ref());
144134
- impl AsRef<str> for str;
145135

146136
error[E0283]: type annotations needed
147-
--> $DIR/issue-72690.rs:47:5
137+
--> $DIR/issue-72690.rs:46:5
148138
|
149139
LL | String::from("x".as_ref());
150140
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@@ -154,7 +144,7 @@ LL | String::from("x".as_ref());
154144
- impl<> From<&str> for String;
155145

156146
error[E0283]: type annotations needed
157-
--> $DIR/issue-72690.rs:47:22
147+
--> $DIR/issue-72690.rs:46:22
158148
|
159149
LL | String::from("x".as_ref());
160150
| ----^^^^^^--
@@ -169,7 +159,7 @@ LL | String::from("x".as_ref());
169159
- impl AsRef<str> for str;
170160

171161
error[E0283]: type annotations needed
172-
--> $DIR/issue-72690.rs:54:5
162+
--> $DIR/issue-72690.rs:53:5
173163
|
174164
LL | String::from("x".as_ref());
175165
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@@ -179,7 +169,7 @@ LL | String::from("x".as_ref());
179169
- impl<> From<&str> for String;
180170

181171
error[E0283]: type annotations needed
182-
--> $DIR/issue-72690.rs:54:22
172+
--> $DIR/issue-72690.rs:53:22
183173
|
184174
LL | String::from("x".as_ref());
185175
| ----^^^^^^--
@@ -194,7 +184,7 @@ LL | String::from("x".as_ref());
194184
- impl AsRef<str> for str;
195185

196186
error[E0283]: type annotations needed
197-
--> $DIR/issue-72690.rs:63:5
187+
--> $DIR/issue-72690.rs:62:5
198188
|
199189
LL | String::from("x".as_ref());
200190
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
@@ -204,7 +194,7 @@ LL | String::from("x".as_ref());
204194
- impl<> From<&str> for String;
205195

206196
error[E0283]: type annotations needed
207-
--> $DIR/issue-72690.rs:63:22
197+
--> $DIR/issue-72690.rs:62:22
208198
|
209199
LL | String::from("x".as_ref());
210200
| ----^^^^^^--
@@ -218,7 +208,7 @@ LL | String::from("x".as_ref());
218208
- impl AsRef<[u8]> for str;
219209
- impl AsRef<str> for str;
220210

221-
error: aborting due to 18 previous errors
211+
error: aborting due to 17 previous errors
222212

223213
Some errors have detailed explanations: E0282, E0283.
224214
For more information about an error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)