Suppress errors due to TypeError not coercing with inference variables

This commit is contained in:
Michael Goulet 2022-12-30 18:40:16 +00:00
parent 7c991868c6
commit f6b45e399e
11 changed files with 35 additions and 72 deletions

View File

@ -171,6 +171,10 @@ fn coerce(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> CoerceResult<'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![]);
}

View File

@ -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

View File

@ -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 previous error
error: aborting due to 2 previous errors
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`.

View File

@ -4,7 +4,6 @@
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();

View File

@ -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`.

View File

@ -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))
}

View File

@ -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 2 previous errors
error: aborting due to 3 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`.

View File

@ -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`
}

View File

@ -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`.

View File

@ -0,0 +1,8 @@
struct Foo {
val: MissingType,
//~^ ERROR cannot find type `MissingType` in this scope
}
fn main() {
Foo { val: Default::default() };
}

View File

@ -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`.