diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index b0cd4a16e9869..3fb14e31ea116 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -171,6 +171,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // Just ignore error types. if a.references_error() || b.references_error() { + // Best-effort try to unify these types -- we're already on the error path, + // so this will have the side-effect of making sure we have no ambiguities + // due to `[type error]` and `_` not coercing together. + let _ = self.commit_if_ok(|_| self.at(&self.cause, self.param_env).eq(a, b)); return success(vec![], self.fcx.tcx.ty_error(), vec![]); } diff --git a/src/test/ui/expr/malformed_closure/ruby_style_closure.rs b/src/test/ui/expr/malformed_closure/ruby_style_closure.rs index e4341e196877b..fdec072b8a864 100644 --- a/src/test/ui/expr/malformed_closure/ruby_style_closure.rs +++ b/src/test/ui/expr/malformed_closure/ruby_style_closure.rs @@ -8,7 +8,6 @@ fn main() { let p = Some(45).and_then({ - //~^ expected a `FnOnce<({integer},)>` closure, found `Option<_>` |x| println!("doubling {}", x); Some(x * 2) //~^ ERROR: cannot find value `x` in this scope diff --git a/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr b/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr index 2f9d10d70a2fe..e8b34121b5f8d 100644 --- a/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr +++ b/src/test/ui/expr/malformed_closure/ruby_style_closure.stderr @@ -1,29 +1,9 @@ error[E0425]: cannot find value `x` in this scope - --> $DIR/ruby_style_closure.rs:13:14 + --> $DIR/ruby_style_closure.rs:12:14 | LL | Some(x * 2) | ^ not found in this scope -error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>` - --> $DIR/ruby_style_closure.rs:10:31 - | -LL | let p = Some(45).and_then({ - | ______________________--------_^ - | | | - | | required by a bound introduced by this call -LL | | -LL | | |x| println!("doubling {}", x); -LL | | Some(x * 2) - | | ----------- this tail expression is of type `Option<_>` -LL | | -LL | | }); - | |_____^ expected an `FnOnce<({integer},)>` closure, found `Option<_>` - | - = help: the trait `FnOnce<({integer},)>` is not implemented for `Option<_>` -note: required by a bound in `Option::::and_then` - --> $SRC_DIR/core/src/option.rs:LL:COL - -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0277, E0425. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/functions-closures/fn-help-with-err.rs b/src/test/ui/functions-closures/fn-help-with-err.rs index 49a514a8b4e34..612fe1b841918 100644 --- a/src/test/ui/functions-closures/fn-help-with-err.rs +++ b/src/test/ui/functions-closures/fn-help-with-err.rs @@ -4,7 +4,6 @@ struct Foo; trait Bar { //~^ NOTE `Bar` defines an item `bar`, perhaps you need to implement it - //~| NOTE `Bar` defines an item `bar`, perhaps you need to implement it fn bar(&self) {} } @@ -15,9 +14,6 @@ fn main() { //~^ ERROR cannot find value `oops` in this scope //~| NOTE not found arc.bar(); - //~^ ERROR no method named `bar` - //~| NOTE method not found - //~| HELP items from traits can only be used if the trait is implemented and in scope let arc2 = std::sync::Arc::new(|| Foo); arc2.bar(); diff --git a/src/test/ui/functions-closures/fn-help-with-err.stderr b/src/test/ui/functions-closures/fn-help-with-err.stderr index 463ac7684ecdf..83a2b1f58f9c5 100644 --- a/src/test/ui/functions-closures/fn-help-with-err.stderr +++ b/src/test/ui/functions-closures/fn-help-with-err.stderr @@ -1,27 +1,14 @@ error[E0425]: cannot find value `oops` in this scope - --> $DIR/fn-help-with-err.rs:14:35 + --> $DIR/fn-help-with-err.rs:13:35 | LL | let arc = std::sync::Arc::new(oops); | ^^^^ not found in this scope -error[E0599]: no method named `bar` found for struct `Arc<_>` in the current scope - --> $DIR/fn-help-with-err.rs:17:9 - | -LL | arc.bar(); - | ^^^ method not found in `Arc<_>` - | - = help: items from traits can only be used if the trait is implemented and in scope -note: `Bar` defines an item `bar`, perhaps you need to implement it - --> $DIR/fn-help-with-err.rs:5:1 - | -LL | trait Bar { - | ^^^^^^^^^ - -error[E0599]: no method named `bar` found for struct `Arc<[closure@fn-help-with-err.rs:22:36]>` in the current scope - --> $DIR/fn-help-with-err.rs:23:10 +error[E0599]: no method named `bar` found for struct `Arc<[closure@fn-help-with-err.rs:18:36]>` in the current scope + --> $DIR/fn-help-with-err.rs:19:10 | LL | arc2.bar(); - | ^^^ method not found in `Arc<[closure@fn-help-with-err.rs:22:36]>` + | ^^^ method not found in `Arc<[closure@fn-help-with-err.rs:18:36]>` | = help: items from traits can only be used if the trait is implemented and in scope note: `Bar` defines an item `bar`, perhaps you need to implement it @@ -34,7 +21,7 @@ help: use parentheses to call this closure LL | arc2().bar(); | ++ -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0425, E0599. For more information about an error, try `rustc --explain E0425`. diff --git a/src/test/ui/impl-trait/issue-72911.rs b/src/test/ui/impl-trait/issue-72911.rs index be9c643b2d881..63f4898f4306b 100644 --- a/src/test/ui/impl-trait/issue-72911.rs +++ b/src/test/ui/impl-trait/issue-72911.rs @@ -5,7 +5,6 @@ pub struct Lint {} impl Lint {} pub fn gather_all() -> impl Iterator { - //~^ ERROR type annotations needed lint_files().flat_map(|f| gather_from_file(&f)) } diff --git a/src/test/ui/impl-trait/issue-72911.stderr b/src/test/ui/impl-trait/issue-72911.stderr index fc7200c75c226..0e86561aa2779 100644 --- a/src/test/ui/impl-trait/issue-72911.stderr +++ b/src/test/ui/impl-trait/issue-72911.stderr @@ -1,22 +1,15 @@ error[E0433]: failed to resolve: use of undeclared crate or module `foo` - --> $DIR/issue-72911.rs:12:33 + --> $DIR/issue-72911.rs:11:33 | LL | fn gather_from_file(dir_entry: &foo::MissingItem) -> impl Iterator { | ^^^ use of undeclared crate or module `foo` error[E0433]: failed to resolve: use of undeclared crate or module `foo` - --> $DIR/issue-72911.rs:17:41 + --> $DIR/issue-72911.rs:16:41 | LL | fn lint_files() -> impl Iterator { | ^^^ use of undeclared crate or module `foo` -error[E0282]: type annotations needed - --> $DIR/issue-72911.rs:7:24 - | -LL | pub fn gather_all() -> impl Iterator { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors -Some errors have detailed explanations: E0282, E0433. -For more information about an error, try `rustc --explain E0282`. +For more information about this error, try `rustc --explain E0433`. diff --git a/src/test/ui/methods/issues/issue-90315.rs b/src/test/ui/methods/issues/issue-90315.rs index 79cdc41959a74..fbecaf9b971ff 100644 --- a/src/test/ui/methods/issues/issue-90315.rs +++ b/src/test/ui/methods/issues/issue-90315.rs @@ -69,8 +69,7 @@ fn main() { //~^ ERROR `usize` is not an iterator let _res: i32 = ..6.take(2).sum(); - //~^ can't call method `take` on ambiguous numeric type - //~| ERROR mismatched types [E0308] + //~^ ERROR can't call method `take` on ambiguous numeric type //~| HELP you must specify a concrete type for this numeric value // Won't suggest because `RangeTo` dest not implemented `take` } diff --git a/src/test/ui/methods/issues/issue-90315.stderr b/src/test/ui/methods/issues/issue-90315.stderr index 8d7b32e025a08..4d3c086ff6e8c 100644 --- a/src/test/ui/methods/issues/issue-90315.stderr +++ b/src/test/ui/methods/issues/issue-90315.stderr @@ -184,18 +184,7 @@ help: you must specify a concrete type for this numeric value, like `i32` LL | let _res: i32 = ..6_i32.take(2).sum(); | ~~~~~ -error[E0308]: mismatched types - --> $DIR/issue-90315.rs:71:21 - | -LL | let _res: i32 = ..6.take(2).sum(); - | --- ^^^^^^^^^^^^^^^^^ expected `i32`, found struct `RangeTo` - | | - | expected due to this - | - = note: expected type `i32` - found struct `RangeTo<_>` - -error: aborting due to 19 previous errors +error: aborting due to 18 previous errors Some errors have detailed explanations: E0308, E0599, E0689. For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/typeck/nonexistent-field-not-ambiguous.rs b/src/test/ui/typeck/nonexistent-field-not-ambiguous.rs new file mode 100644 index 0000000000000..1cd192b783cdb --- /dev/null +++ b/src/test/ui/typeck/nonexistent-field-not-ambiguous.rs @@ -0,0 +1,8 @@ +struct Foo { + val: MissingType, + //~^ ERROR cannot find type `MissingType` in this scope +} + +fn main() { + Foo { val: Default::default() }; +} diff --git a/src/test/ui/typeck/nonexistent-field-not-ambiguous.stderr b/src/test/ui/typeck/nonexistent-field-not-ambiguous.stderr new file mode 100644 index 0000000000000..76a2a5f99f2b6 --- /dev/null +++ b/src/test/ui/typeck/nonexistent-field-not-ambiguous.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `MissingType` in this scope + --> $DIR/nonexistent-field-not-ambiguous.rs:2:10 + | +LL | val: MissingType, + | ^^^^^^^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`.