Skip to content

Commit 7bd22e2

Browse files
only downgrade Error -> Ambiguous if type error is in predicate
1 parent 8f36334 commit 7bd22e2

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
231231
// `Err(Unimplemented)` to `Ok(None)`. This helps us avoid
232232
// emitting additional spurious errors, since we're guaranteed
233233
// to have emitted at least one.
234-
if stack.obligation.references_error() {
235-
debug!("no results for error type, treating as ambiguous");
234+
if stack.obligation.predicate.references_error() {
235+
debug!(?stack.obligation.predicate, "found error type in predicate, treating as ambiguous");
236236
return Ok(None);
237237
}
238238
return Err(Unimplemented);

src/test/ui/functions-closures/fn-help-with-err-generic-is-not-function.rs

-8
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ where
88
//~^ ERROR cannot find type `T` in this scope
99
//~| NOTE not found in this scope
1010
{
11-
// The part where it claims that there is no method named `len` is a bug. Feel free to fix it.
12-
// This test is intended to ensure that a different bug, where it claimed
13-
// that `v` was a function, does not regress.
1411
fn method(v: Vec<u8>) { v.len(); }
15-
//~^ ERROR type annotations needed
16-
//~| NOTE cannot infer type
17-
//~| NOTE type must be known at this point
18-
//~| ERROR no method named `len`
19-
//~| NOTE private field, not a method
2012
}
2113

2214
fn main() {}

src/test/ui/functions-closures/fn-help-with-err-generic-is-not-function.stderr

+2-17
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,6 @@ error[E0412]: cannot find type `T` in this scope
1212
LL | T: Copy,
1313
| ^ not found in this scope
1414

15-
error[E0282]: type annotations needed
16-
--> $DIR/fn-help-with-err-generic-is-not-function.rs:14:31
17-
|
18-
LL | fn method(v: Vec<u8>) { v.len(); }
19-
| ^^^ cannot infer type
20-
|
21-
= note: type must be known at this point
22-
23-
error[E0599]: no method named `len` found for struct `Vec<u8>` in the current scope
24-
--> $DIR/fn-help-with-err-generic-is-not-function.rs:14:31
25-
|
26-
LL | fn method(v: Vec<u8>) { v.len(); }
27-
| ^^^ private field, not a method
28-
29-
error: aborting due to 4 previous errors
15+
error: aborting due to 2 previous errors
3016

31-
Some errors have detailed explanations: E0282, E0412, E0599.
32-
For more information about an error, try `rustc --explain E0282`.
17+
For more information about this error, try `rustc --explain E0412`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn foo()
2+
where
3+
T: Send,
4+
//~^ cannot find type `T` in this scope
5+
{
6+
let s = "abc".to_string();
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0412]: cannot find type `T` in this scope
2+
--> $DIR/autoderef-with-param-env-error.rs:3:5
3+
|
4+
LL | fn foo()
5+
| - help: you might be missing a type parameter: `<T>`
6+
LL | where
7+
LL | T: Send,
8+
| ^ not found in this scope
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)