Skip to content

Commit abeed83

Browse files
authored
Rollup merge of rust-lang#106302 - compiler-errors:terr-coerce-w-infer, r=estebank
Suppress errors due to TypeError not coercing with inference variables Fixes rust-lang#75331 Fixes rust-lang#68507 Fixes rust-lang#82323 cc `@estebank`
2 parents 8b8d276 + f6b45e3 commit abeed83

11 files changed

+35
-72
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
171171

172172
// Just ignore error types.
173173
if a.references_error() || b.references_error() {
174+
// Best-effort try to unify these types -- we're already on the error path,
175+
// so this will have the side-effect of making sure we have no ambiguities
176+
// due to `[type error]` and `_` not coercing together.
177+
let _ = self.commit_if_ok(|_| self.at(&self.cause, self.param_env).eq(a, b));
174178
return success(vec![], self.fcx.tcx.ty_error(), vec![]);
175179
}
176180

src/test/ui/expr/malformed_closure/ruby_style_closure.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
fn main() {
1010
let p = Some(45).and_then({
11-
//~^ expected a `FnOnce<({integer},)>` closure, found `Option<_>`
1211
|x| println!("doubling {}", x);
1312
Some(x * 2)
1413
//~^ ERROR: cannot find value `x` in this scope
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
11
error[E0425]: cannot find value `x` in this scope
2-
--> $DIR/ruby_style_closure.rs:13:14
2+
--> $DIR/ruby_style_closure.rs:12:14
33
|
44
LL | Some(x * 2)
55
| ^ not found in this scope
66

7-
error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>`
8-
--> $DIR/ruby_style_closure.rs:10:31
9-
|
10-
LL | let p = Some(45).and_then({
11-
| ______________________--------_^
12-
| | |
13-
| | required by a bound introduced by this call
14-
LL | |
15-
LL | | |x| println!("doubling {}", x);
16-
LL | | Some(x * 2)
17-
| | ----------- this tail expression is of type `Option<_>`
18-
LL | |
19-
LL | | });
20-
| |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>`
21-
|
22-
= help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>`
23-
note: required by a bound in `Option::<T>::and_then`
24-
--> $SRC_DIR/core/src/option.rs:LL:COL
25-
26-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
278

28-
Some errors have detailed explanations: E0277, E0425.
29-
For more information about an error, try `rustc --explain E0277`.
9+
For more information about this error, try `rustc --explain E0425`.

src/test/ui/functions-closures/fn-help-with-err.rs

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ struct Foo;
44

55
trait Bar {
66
//~^ NOTE `Bar` defines an item `bar`, perhaps you need to implement it
7-
//~| NOTE `Bar` defines an item `bar`, perhaps you need to implement it
87
fn bar(&self) {}
98
}
109

@@ -15,9 +14,6 @@ fn main() {
1514
//~^ ERROR cannot find value `oops` in this scope
1615
//~| NOTE not found
1716
arc.bar();
18-
//~^ ERROR no method named `bar`
19-
//~| NOTE method not found
20-
//~| HELP items from traits can only be used if the trait is implemented and in scope
2117

2218
let arc2 = std::sync::Arc::new(|| Foo);
2319
arc2.bar();
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
error[E0425]: cannot find value `oops` in this scope
2-
--> $DIR/fn-help-with-err.rs:14:35
2+
--> $DIR/fn-help-with-err.rs:13:35
33
|
44
LL | let arc = std::sync::Arc::new(oops);
55
| ^^^^ not found in this scope
66

7-
error[E0599]: no method named `bar` found for struct `Arc<_>` in the current scope
8-
--> $DIR/fn-help-with-err.rs:17:9
9-
|
10-
LL | arc.bar();
11-
| ^^^ method not found in `Arc<_>`
12-
|
13-
= help: items from traits can only be used if the trait is implemented and in scope
14-
note: `Bar` defines an item `bar`, perhaps you need to implement it
15-
--> $DIR/fn-help-with-err.rs:5:1
16-
|
17-
LL | trait Bar {
18-
| ^^^^^^^^^
19-
20-
error[E0599]: no method named `bar` found for struct `Arc<[[email protected]:22:36]>` in the current scope
21-
--> $DIR/fn-help-with-err.rs:23:10
7+
error[E0599]: no method named `bar` found for struct `Arc<[[email protected]:18:36]>` in the current scope
8+
--> $DIR/fn-help-with-err.rs:19:10
229
|
2310
LL | arc2.bar();
24-
| ^^^ method not found in `Arc<[[email protected]:22:36]>`
11+
| ^^^ method not found in `Arc<[[email protected]:18:36]>`
2512
|
2613
= help: items from traits can only be used if the trait is implemented and in scope
2714
note: `Bar` defines an item `bar`, perhaps you need to implement it
@@ -34,7 +21,7 @@ help: use parentheses to call this closure
3421
LL | arc2().bar();
3522
| ++
3623

37-
error: aborting due to 3 previous errors
24+
error: aborting due to 2 previous errors
3825

3926
Some errors have detailed explanations: E0425, E0599.
4027
For more information about an error, try `rustc --explain E0425`.

src/test/ui/impl-trait/issue-72911.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pub struct Lint {}
55
impl Lint {}
66

77
pub fn gather_all() -> impl Iterator<Item = Lint> {
8-
//~^ ERROR type annotations needed
98
lint_files().flat_map(|f| gather_from_file(&f))
109
}
1110

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
error[E0433]: failed to resolve: use of undeclared crate or module `foo`
2-
--> $DIR/issue-72911.rs:12:33
2+
--> $DIR/issue-72911.rs:11:33
33
|
44
LL | fn gather_from_file(dir_entry: &foo::MissingItem) -> impl Iterator<Item = Lint> {
55
| ^^^ use of undeclared crate or module `foo`
66

77
error[E0433]: failed to resolve: use of undeclared crate or module `foo`
8-
--> $DIR/issue-72911.rs:17:41
8+
--> $DIR/issue-72911.rs:16:41
99
|
1010
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
1111
| ^^^ use of undeclared crate or module `foo`
1212

13-
error[E0282]: type annotations needed
14-
--> $DIR/issue-72911.rs:7:24
15-
|
16-
LL | pub fn gather_all() -> impl Iterator<Item = Lint> {
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
18-
19-
error: aborting due to 3 previous errors
13+
error: aborting due to 2 previous errors
2014

21-
Some errors have detailed explanations: E0282, E0433.
22-
For more information about an error, try `rustc --explain E0282`.
15+
For more information about this error, try `rustc --explain E0433`.

src/test/ui/methods/issues/issue-90315.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ fn main() {
6969
//~^ ERROR `usize` is not an iterator
7070

7171
let _res: i32 = ..6.take(2).sum();
72-
//~^ can't call method `take` on ambiguous numeric type
73-
//~| ERROR mismatched types [E0308]
72+
//~^ ERROR can't call method `take` on ambiguous numeric type
7473
//~| HELP you must specify a concrete type for this numeric value
7574
// Won't suggest because `RangeTo` dest not implemented `take`
7675
}

src/test/ui/methods/issues/issue-90315.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,7 @@ help: you must specify a concrete type for this numeric value, like `i32`
184184
LL | let _res: i32 = ..6_i32.take(2).sum();
185185
| ~~~~~
186186

187-
error[E0308]: mismatched types
188-
--> $DIR/issue-90315.rs:71:21
189-
|
190-
LL | let _res: i32 = ..6.take(2).sum();
191-
| --- ^^^^^^^^^^^^^^^^^ expected `i32`, found struct `RangeTo`
192-
| |
193-
| expected due to this
194-
|
195-
= note: expected type `i32`
196-
found struct `RangeTo<_>`
197-
198-
error: aborting due to 19 previous errors
187+
error: aborting due to 18 previous errors
199188

200189
Some errors have detailed explanations: E0308, E0599, E0689.
201190
For more information about an error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct Foo {
2+
val: MissingType,
3+
//~^ ERROR cannot find type `MissingType` in this scope
4+
}
5+
6+
fn main() {
7+
Foo { val: Default::default() };
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `MissingType` in this scope
2+
--> $DIR/nonexistent-field-not-ambiguous.rs:2:10
3+
|
4+
LL | val: MissingType,
5+
| ^^^^^^^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)