Hide further opaque type errors if items that could constrain the opaque type have errors

This commit is contained in:
Oli Scherer 2022-01-27 16:11:28 +00:00
parent e4794d9d1b
commit b6d57ecc0b
27 changed files with 40 additions and 124 deletions

View file

@ -607,7 +607,12 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
// // because we again need to reveal `Foo` so we can check whether the
// // constant does not contain interior mutability.
// ```
if self.tcx.typeck(def_id).concrete_opaque_types.get(&self.def_id).is_none() {
let tables = self.tcx.typeck(def_id);
if let Some(_) = tables.tainted_by_errors {
self.found = Some((DUMMY_SP, self.tcx.ty_error()));
return;
}
if tables.concrete_opaque_types.get(&self.def_id).is_none() {
debug!("no constraints in typeck results");
return;
}

View file

@ -28,7 +28,6 @@ impl Bar for AssocNoCopy {
impl Thing for AssocNoCopy {
type Out = Box<dyn Bar<Assoc: Copy>>;
//~^ ERROR could not find defining uses
fn func() -> Self::Out {
Box::new(AssocNoCopy)

View file

@ -1,17 +1,11 @@
error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:34:9
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:33:9
|
LL | Box::new(AssocNoCopy)
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
|
= note: required for the cast to the object type `dyn Bar<Assoc = impl Copy>`
error: could not find defining uses
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28
|
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
| ^^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -8,7 +8,6 @@ pub trait Bar {
impl<S: Default> Bar for S {
type E = impl Copy;
//~^ ERROR could not find defining uses
fn foo<T: Default>() -> Self::E {
//~^ ERROR impl has stricter requirements than trait

View file

@ -1,5 +1,5 @@
error[E0276]: impl has stricter requirements than trait
--> $DIR/issue-55872-1.rs:13:15
--> $DIR/issue-55872-1.rs:12:15
|
LL | fn foo<T>() -> Self::E;
| ----------------------- definition of `foo` from trait
@ -8,7 +8,7 @@ LL | fn foo<T: Default>() -> Self::E {
| ^^^^^^^ impl has extra requirement `T: Default`
error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)`
--> $DIR/issue-55872-1.rs:15:9
--> $DIR/issue-55872-1.rs:14:9
|
LL | (S::default(), T::default())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `S`
@ -20,7 +20,7 @@ LL | impl<S: Default + std::marker::Copy> Bar for S {
| +++++++++++++++++++
error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)`
--> $DIR/issue-55872-1.rs:15:9
--> $DIR/issue-55872-1.rs:14:9
|
LL | (S::default(), T::default())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
@ -31,13 +31,7 @@ help: consider further restricting this bound
LL | fn foo<T: Default + std::marker::Copy>() -> Self::E {
| +++++++++++++++++++
error: could not find defining uses
--> $DIR/issue-55872-1.rs:10:14
|
LL | type E = impl Copy;
| ^^^^^^^^^
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0276, E0277.
For more information about an error, try `rustc --explain E0276`.

View file

@ -11,7 +11,6 @@ pub trait Bar {
impl<S> Bar for S {
type E = impl std::marker::Copy;
//~^ ERROR could not find defining uses
fn foo<T>() -> Self::E {
async {}
//~^ ERROR the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied [E0277]

View file

@ -1,15 +1,9 @@
error[E0277]: the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied
--> $DIR/issue-55872-3.rs:16:9
--> $DIR/issue-55872-3.rs:15:9
|
LL | async {}
| ^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = [async output]>`
error: could not find defining uses
--> $DIR/issue-55872-3.rs:13:14
|
LL | type E = impl std::marker::Copy;
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -17,7 +17,7 @@ LL | type WrongGeneric<T> = impl 'static;
| ^
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/generic_type_does_not_live_long_enough.rs:15:5
--> $DIR/generic_type_does_not_live_long_enough.rs:14:5
|
LL | t
| ^

View file

@ -9,7 +9,6 @@ fn main() {
type WrongGeneric<T> = impl 'static;
//~^ ERROR: at least one trait must be specified
//~| ERROR could not find defining uses
fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
t

View file

@ -17,19 +17,13 @@ LL | type WrongGeneric<T> = impl 'static;
| ^
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/generic_type_does_not_live_long_enough.rs:15:5
--> $DIR/generic_type_does_not_live_long_enough.rs:14:5
|
LL | fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
| - help: consider adding an explicit lifetime bound...: `T: 'static`
LL | t
| ^ ...so that the type `T` will meet its required lifetime bounds
error: could not find defining uses
--> $DIR/generic_type_does_not_live_long_enough.rs:10:24
|
LL | type WrongGeneric<T> = impl 'static;
| ^^^^^^^^^^^^
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0310`.

View file

@ -16,7 +16,7 @@ mod m {
is_send(foo()); // Today: error
}
fn baz() { //~ ERROR concrete type differs from previous defining opaque type use
fn baz() {
let f: Foo = 22_u32;
}

View file

@ -34,18 +34,6 @@ note: cycle used when checking item types in module `m`
LL | mod m {
| ^^^^^
error: concrete type differs from previous defining opaque type use
--> $DIR/inference-cycle.rs:19:5
|
LL | fn baz() {
| ^^^^^^^^ expected `()`, got `u32`
|
note: previous use here
--> $DIR/inference-cycle.rs:11:5
|
LL | pub fn foo() -> Foo {
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0391`.

View file

@ -1,11 +1,11 @@
error: higher-ranked subtype error
--> $DIR/issue-57611-trait-alias.rs:21:9
--> $DIR/issue-57611-trait-alias.rs:20:9
|
LL | |x| x
| ^^^^^
error: higher-ranked subtype error
--> $DIR/issue-57611-trait-alias.rs:21:9
--> $DIR/issue-57611-trait-alias.rs:20:9
|
LL | |x| x
| ^^^^^
@ -19,7 +19,7 @@ LL | type Bar = impl Baz<Self, Self>;
= note: expected type `for<'r> Fn<(&'r X,)>`
found type `Fn<(&'static X,)>`
note: this closure does not fulfill the lifetime requirements
--> $DIR/issue-57611-trait-alias.rs:21:9
--> $DIR/issue-57611-trait-alias.rs:20:9
|
LL | |x| x
| ^^^^^

View file

@ -15,7 +15,6 @@ struct X;
impl Foo for X {
type Bar = impl Baz<Self, Self>;
//~^ ERROR could not find defining uses
fn bar(&self) -> Self::Bar {
|x| x

View file

@ -1,5 +1,5 @@
error: implementation of `FnOnce` is not general enough
--> $DIR/issue-57611-trait-alias.rs:21:9
--> $DIR/issue-57611-trait-alias.rs:20:9
|
LL | |x| x
| ^^^^^ implementation of `FnOnce` is not general enough
@ -7,11 +7,5 @@ LL | |x| x
= note: closure with signature `fn(&'2 X) -> &X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
error: could not find defining uses
--> $DIR/issue-57611-trait-alias.rs:17:16
|
LL | type Bar = impl Baz<Self, Self>;
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error

View file

@ -8,7 +8,6 @@ trait Bug {
impl Bug for &() {
type Item = impl Bug; //~ ERROR `impl Trait` in type aliases is unstable
//~^ ERROR could not find defining uses
const FUN: fn() -> Self::Item = || ();
//~^ ERROR the trait bound `(): Bug` is not satisfied

View file

@ -8,7 +8,7 @@ LL | type Item = impl Bug;
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
error[E0277]: the trait bound `(): Bug` is not satisfied
--> $DIR/issue-60371.rs:13:40
--> $DIR/issue-60371.rs:12:40
|
LL | const FUN: fn() -> Self::Item = || ();
| ^^ the trait `Bug` is not implemented for `()`
@ -16,13 +16,7 @@ LL | const FUN: fn() -> Self::Item = || ();
= help: the following implementations were found:
<&() as Bug>
error: could not find defining uses
--> $DIR/issue-60371.rs:10:17
|
LL | type Item = impl Bug;
| ^^^^^^^^
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0277, E0658.
For more information about an error, try `rustc --explain E0277`.

View file

@ -3,7 +3,6 @@
#![feature(type_alias_impl_trait)]
type Closure = impl FnOnce();
//~^ ERROR could not find defining uses
fn c() -> Closure {
|| -> Closure { || () }

View file

@ -1,5 +1,5 @@
error[E0277]: expected a `FnOnce<()>` closure, found `()`
--> $DIR/issue-63279.rs:9:11
--> $DIR/issue-63279.rs:8:11
|
LL | || -> Closure { || () }
| ^^^^^^^ expected an `FnOnce<()>` closure, found `()`
@ -8,16 +8,16 @@ LL | || -> Closure { || () }
= note: wrap the `()` in a closure with no arguments: `|| { /* code */ }`
error[E0308]: mismatched types
--> $DIR/issue-63279.rs:9:21
--> $DIR/issue-63279.rs:8:21
|
LL | || -> Closure { || () }
| ^^^^^ expected `()`, found closure
|
= note: expected unit type `()`
found closure `[closure@$DIR/issue-63279.rs:9:21: 9:26]`
found closure `[closure@$DIR/issue-63279.rs:8:21: 8:26]`
error[E0308]: mismatched types
--> $DIR/issue-63279.rs:9:5
--> $DIR/issue-63279.rs:8:5
|
LL | type Closure = impl FnOnce();
| ------------- the expected opaque type
@ -26,15 +26,9 @@ LL | || -> Closure { || () }
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found closure
|
= note: expected opaque type `impl FnOnce()`
found closure `[closure@$DIR/issue-63279.rs:9:5: 9:28]`
found closure `[closure@$DIR/issue-63279.rs:8:5: 8:28]`
error: could not find defining uses
--> $DIR/issue-63279.rs:5:16
|
LL | type Closure = impl FnOnce();
| ^^^^^^^^^^^^^
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

View file

@ -3,7 +3,6 @@
#![feature(type_alias_impl_trait)]
type Test = impl Copy;
//~^ ERROR could not find defining uses
fn test() -> Test {
let y = || -> Test { () };

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/issue-74280.rs:10:5
--> $DIR/issue-74280.rs:9:5
|
LL | type Test = impl Copy;
| --------- the expected opaque type
@ -10,12 +10,6 @@ LL | 7
= note: expected opaque type `impl Copy`
found type `{integer}`
error: could not find defining uses
--> $DIR/issue-74280.rs:5:13
|
LL | type Test = impl Copy;
| ^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View file

@ -5,7 +5,6 @@
#![feature(type_alias_impl_trait)]
type X<A, B> = impl Into<&'static A>;
//~^ ERROR could not find defining uses
fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) {
(a, a)

View file

@ -1,5 +1,5 @@
error[E0277]: the trait bound `&'static B: From<&A>` is not satisfied
--> $DIR/multiple-def-uses-in-one-fn.rs:11:9
--> $DIR/multiple-def-uses-in-one-fn.rs:10:9
|
LL | (a, a)
| ^ the trait `From<&A>` is not implemented for `&'static B`
@ -10,12 +10,6 @@ help: consider introducing a `where` bound, but there might be an alternative be
LL | fn f<A, B: 'static>(a: &'static A, b: B) -> (X<A, B>, X<B, A>) where &'static B: From<&A> {
| ++++++++++++++++++++++++++
error: could not find defining uses
--> $DIR/multiple-def-uses-in-one-fn.rs:7:16
|
LL | type X<A, B> = impl Into<&'static A>;
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -4,7 +4,6 @@
use std::fmt::Debug;
type FooX = impl Debug;
//~^ ERROR could not find defining uses
trait Foo<A> { }

View file

@ -1,5 +1,5 @@
error[E0277]: the trait bound `(): Foo<impl Debug>` is not satisfied
--> $DIR/nested-tait-inference.rs:15:5
--> $DIR/nested-tait-inference.rs:14:5
|
LL | ()
| ^^ the trait `Foo<impl Debug>` is not implemented for `()`
@ -7,12 +7,6 @@ LL | ()
= help: the following implementations were found:
<() as Foo<()>>
error: could not find defining uses
--> $DIR/nested-tait-inference.rs:6:13
|
LL | type FooX = impl Debug;
| ^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -4,7 +4,6 @@
use std::fmt::Debug;
type FooX = impl Debug;
//~^ ERROR could not find defining uses
trait Foo<A> {}

View file

@ -1,5 +1,5 @@
error[E0277]: the trait bound `(): Foo<impl Debug>` is not satisfied
--> $DIR/nested-tait-inference2.rs:15:5
--> $DIR/nested-tait-inference2.rs:14:5
|
LL | ()
| ^^ the trait `Foo<impl Debug>` is not implemented for `()`
@ -8,12 +8,6 @@ LL | ()
<() as Foo<()>>
<() as Foo<u32>>
error: could not find defining uses
--> $DIR/nested-tait-inference2.rs:6:13
|
LL | type FooX = impl Debug;
| ^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.