Skip to content

Commit

Permalink
Auto merge of #106302 - compiler-errors:terr-coerce-w-infer, r=estebank
Browse files Browse the repository at this point in the history
Suppress errors due to TypeError not coercing with inference variables

Fixes #75331
Fixes #68507
Fixes #82323

cc `@estebank`
  • Loading branch information
bors committed Dec 31, 2022
2 parents 96c1f33 + f6b45e3 commit 726bbfc
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 72 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]);
}

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/expr/malformed_closure/ruby_style_closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 3 additions & 23 deletions src/test/ui/expr/malformed_closure/ruby_style_closure.stderr
Original file line number Diff line number Diff line change
@@ -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::<T>::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`.
4 changes: 0 additions & 4 deletions src/test/ui/functions-closures/fn-help-with-err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Expand All @@ -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();
Expand Down
23 changes: 5 additions & 18 deletions src/test/ui/functions-closures/fn-help-with-err.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`.
1 change: 0 additions & 1 deletion src/test/ui/impl-trait/issue-72911.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub struct Lint {}
impl Lint {}

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

Expand Down
15 changes: 4 additions & 11 deletions src/test/ui/impl-trait/issue-72911.stderr
Original file line number Diff line number Diff line change
@@ -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<Item = Lint> {
| ^^^ 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<Item = foo::MissingItem> {
| ^^^ 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<Item = Lint> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`.
3 changes: 1 addition & 2 deletions src/test/ui/methods/issues/issue-90315.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
13 changes: 1 addition & 12 deletions src/test/ui/methods/issues/issue-90315.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
8 changes: 8 additions & 0 deletions src/test/ui/typeck/nonexistent-field-not-ambiguous.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct Foo {
val: MissingType,
//~^ ERROR cannot find type `MissingType` in this scope
}

fn main() {
Foo { val: Default::default() };
}
9 changes: 9 additions & 0 deletions src/test/ui/typeck/nonexistent-field-not-ambiguous.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 726bbfc

Please sign in to comment.