Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip pointing out ambiguous impls in alloc/std crates too in inference errors #93469

Merged
merged 1 commit into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {

if self.is_tainted_by_errors()
&& crate_names.len() == 1
&& crate_names[0] == "`core`"
&& ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str())
&& spans.len() == 0
{
// Avoid complaining about other inference issues for expressions like
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/impl-trait/equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn two(x: bool) -> impl Foo {
//~| expected `i32`, found `u32`
}

fn sum_to(n: u32) -> impl Foo { //~ ERROR type annotations needed
fn sum_to(n: u32) -> impl Foo {
if n == 0 {
0
} else {
Expand Down
19 changes: 2 additions & 17 deletions src/test/ui/impl-trait/equality.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,7 @@ LL | n + sum_to(n - 1)
|
= help: the trait `Add<impl Foo>` is not implemented for `u32`

error[E0283]: type annotations needed
--> $DIR/equality.rs:20:22
|
LL | fn sum_to(n: u32) -> impl Foo {
| ^^^^^^^^ cannot infer type for type `{integer}`
|
= note: multiple `impl`s satisfying `{integer}: ToString` found in the `alloc` crate:
- impl ToString for i8;
- impl ToString for u8;
note: required because of the requirements on the impl of `Foo` for `{integer}`
--> $DIR/equality.rs:5:26
|
LL | impl<T: Copy + ToString> Foo for T {}
| ^^^ ^

error: aborting due to 3 previous errors; 1 warning emitted
error: aborting due to 2 previous errors; 1 warning emitted

Some errors have detailed explanations: E0277, E0283, E0308.
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
1 change: 0 additions & 1 deletion src/test/ui/issues/issue-72690.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ fn err() {

fn arg_pat_closure_err() {
|x| String::from("x".as_ref()); //~ ERROR type annotations needed
//~^ ERROR type annotations needed
//~| ERROR type annotations needed
}

Expand Down
38 changes: 14 additions & 24 deletions src/test/ui/issues/issue-72690.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ error[E0282]: type annotations needed
LL | |x| String::from("x".as_ref());
| ^ consider giving this closure parameter a type

error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:12:9
|
LL | |x| String::from("x".as_ref());
| ^^^^^^^^^^^^ cannot infer type for reference `&_`
|
= note: multiple `impl`s satisfying `String: From<&_>` found in the `alloc` crate:
- impl<> From<&String> for String;
- impl<> From<&str> for String;

error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:12:26
|
Expand All @@ -55,7 +45,7 @@ LL | |x| String::from("x".as_ref());
- impl AsRef<str> for str;

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

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

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

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

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

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

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

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

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

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

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

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

error[E0283]: type annotations needed
--> $DIR/issue-72690.rs:63:22
--> $DIR/issue-72690.rs:62:22
|
LL | String::from("x".as_ref());
| ----^^^^^^--
Expand All @@ -218,7 +208,7 @@ LL | String::from("x".as_ref());
- impl AsRef<[u8]> for str;
- impl AsRef<str> for str;

error: aborting due to 18 previous errors
error: aborting due to 17 previous errors

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