Auto merge of #106302 - compiler-errors:terr-coerce-w-infer, r=estebank
Suppress errors due to TypeError not coercing with inference variables Fixes #75331 Fixes #68507 Fixes #82323 cc `@estebank`
This commit is contained in:
commit
726bbfc8f0
11 changed files with 35 additions and 72 deletions
|
@ -171,6 +171,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
|
||||||
|
|
||||||
// Just ignore error types.
|
// Just ignore error types.
|
||||||
if a.references_error() || b.references_error() {
|
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![]);
|
return success(vec![], self.fcx.tcx.ty_error(), vec![]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let p = Some(45).and_then({
|
let p = Some(45).and_then({
|
||||||
//~^ expected a `FnOnce<({integer},)>` closure, found `Option<_>`
|
|
||||||
|x| println!("doubling {}", x);
|
|x| println!("doubling {}", x);
|
||||||
Some(x * 2)
|
Some(x * 2)
|
||||||
//~^ ERROR: cannot find value `x` in this scope
|
//~^ ERROR: cannot find value `x` in this scope
|
||||||
|
|
|
@ -1,29 +1,9 @@
|
||||||
error[E0425]: cannot find value `x` in this scope
|
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)
|
LL | Some(x * 2)
|
||||||
| ^ not found in this scope
|
| ^ not found in this scope
|
||||||
|
|
||||||
error[E0277]: expected a `FnOnce<({integer},)>` closure, found `Option<_>`
|
error: aborting due to previous error
|
||||||
--> $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
|
For more information about this error, try `rustc --explain E0425`.
|
||||||
|
|
||||||
Some errors have detailed explanations: E0277, E0425.
|
|
||||||
For more information about an error, try `rustc --explain E0277`.
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ struct Foo;
|
||||||
|
|
||||||
trait Bar {
|
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
|
||||||
//~| NOTE `Bar` defines an item `bar`, perhaps you need to implement it
|
|
||||||
fn bar(&self) {}
|
fn bar(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +14,6 @@ fn main() {
|
||||||
//~^ ERROR cannot find value `oops` in this scope
|
//~^ ERROR cannot find value `oops` in this scope
|
||||||
//~| NOTE not found
|
//~| NOTE not found
|
||||||
arc.bar();
|
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);
|
let arc2 = std::sync::Arc::new(|| Foo);
|
||||||
arc2.bar();
|
arc2.bar();
|
||||||
|
|
|
@ -1,27 +1,14 @@
|
||||||
error[E0425]: cannot find value `oops` in this scope
|
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);
|
LL | let arc = std::sync::Arc::new(oops);
|
||||||
| ^^^^ not found in this scope
|
| ^^^^ not found in this scope
|
||||||
|
|
||||||
error[E0599]: no method named `bar` found for struct `Arc<_>` in the current scope
|
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:17:9
|
--> $DIR/fn-help-with-err.rs:19:10
|
||||||
|
|
|
||||||
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
|
|
||||||
|
|
|
|
||||||
LL | arc2.bar();
|
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
|
= 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
|
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();
|
LL | arc2().bar();
|
||||||
| ++
|
| ++
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0425, E0599.
|
Some errors have detailed explanations: E0425, E0599.
|
||||||
For more information about an error, try `rustc --explain E0425`.
|
For more information about an error, try `rustc --explain E0425`.
|
||||||
|
|
|
@ -5,7 +5,6 @@ pub struct Lint {}
|
||||||
impl Lint {}
|
impl Lint {}
|
||||||
|
|
||||||
pub fn gather_all() -> impl Iterator<Item = Lint> {
|
pub fn gather_all() -> impl Iterator<Item = Lint> {
|
||||||
//~^ ERROR type annotations needed
|
|
||||||
lint_files().flat_map(|f| gather_from_file(&f))
|
lint_files().flat_map(|f| gather_from_file(&f))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,15 @@
|
||||||
error[E0433]: failed to resolve: use of undeclared crate or module `foo`
|
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> {
|
LL | fn gather_from_file(dir_entry: &foo::MissingItem) -> impl Iterator<Item = Lint> {
|
||||||
| ^^^ use of undeclared crate or module `foo`
|
| ^^^ use of undeclared crate or module `foo`
|
||||||
|
|
||||||
error[E0433]: failed to resolve: 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> {
|
LL | fn lint_files() -> impl Iterator<Item = foo::MissingItem> {
|
||||||
| ^^^ use of undeclared crate or module `foo`
|
| ^^^ use of undeclared crate or module `foo`
|
||||||
|
|
||||||
error[E0282]: type annotations needed
|
error: aborting due to 2 previous errors
|
||||||
--> $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
|
For more information about this error, try `rustc --explain E0433`.
|
||||||
|
|
||||||
Some errors have detailed explanations: E0282, E0433.
|
|
||||||
For more information about an error, try `rustc --explain E0282`.
|
|
||||||
|
|
|
@ -69,8 +69,7 @@ fn main() {
|
||||||
//~^ ERROR `usize` is not an iterator
|
//~^ ERROR `usize` is not an iterator
|
||||||
|
|
||||||
let _res: i32 = ..6.take(2).sum();
|
let _res: i32 = ..6.take(2).sum();
|
||||||
//~^ can't call method `take` on ambiguous numeric type
|
//~^ ERROR can't call method `take` on ambiguous numeric type
|
||||||
//~| ERROR mismatched types [E0308]
|
|
||||||
//~| HELP you must specify a concrete type for this numeric value
|
//~| HELP you must specify a concrete type for this numeric value
|
||||||
// Won't suggest because `RangeTo` dest not implemented `take`
|
// Won't suggest because `RangeTo` dest not implemented `take`
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
LL | let _res: i32 = ..6_i32.take(2).sum();
|
||||||
| ~~~~~
|
| ~~~~~
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error: aborting due to 18 previous errors
|
||||||
--> $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
|
|
||||||
|
|
||||||
Some errors have detailed explanations: E0308, E0599, E0689.
|
Some errors have detailed explanations: E0308, E0599, E0689.
|
||||||
For more information about an error, try `rustc --explain E0308`.
|
For more information about an error, try `rustc --explain E0308`.
|
||||||
|
|
8
src/test/ui/typeck/nonexistent-field-not-ambiguous.rs
Normal file
8
src/test/ui/typeck/nonexistent-field-not-ambiguous.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
struct Foo {
|
||||||
|
val: MissingType,
|
||||||
|
//~^ ERROR cannot find type `MissingType` in this scope
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
Foo { val: Default::default() };
|
||||||
|
}
|
|
@ -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`.
|
Loading…
Add table
Add a link
Reference in a new issue