Skip to content

Commit b6d57ec

Browse files
committed
Hide further opaque type errors if items that could constrain the opaque type have errors
1 parent e4794d9 commit b6d57ec

27 files changed

+40
-124
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,12 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
607607
// // because we again need to reveal `Foo` so we can check whether the
608608
// // constant does not contain interior mutability.
609609
// ```
610-
if self.tcx.typeck(def_id).concrete_opaque_types.get(&self.def_id).is_none() {
610+
let tables = self.tcx.typeck(def_id);
611+
if let Some(_) = tables.tainted_by_errors {
612+
self.found = Some((DUMMY_SP, self.tcx.ty_error()));
613+
return;
614+
}
615+
if tables.concrete_opaque_types.get(&self.def_id).is_none() {
611616
debug!("no constraints in typeck results");
612617
return;
613618
}

src/test/ui/associated-type-bounds/assoc-type-eq-with-dyn-atb-fail.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ impl Bar for AssocNoCopy {
2828

2929
impl Thing for AssocNoCopy {
3030
type Out = Box<dyn Bar<Assoc: Copy>>;
31-
//~^ ERROR could not find defining uses
3231

3332
fn func() -> Self::Out {
3433
Box::new(AssocNoCopy)
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
error[E0277]: the trait bound `String: Copy` is not satisfied
2-
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:34:9
2+
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:33:9
33
|
44
LL | Box::new(AssocNoCopy)
55
| ^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
66
|
77
= note: required for the cast to the object type `dyn Bar<Assoc = impl Copy>`
88

9-
error: could not find defining uses
10-
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28
11-
|
12-
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
13-
| ^^^^^^^^^^^
14-
15-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1610

1711
For more information about this error, try `rustc --explain E0277`.

src/test/ui/impl-trait/issue-55872-1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub trait Bar {
88

99
impl<S: Default> Bar for S {
1010
type E = impl Copy;
11-
//~^ ERROR could not find defining uses
1211

1312
fn foo<T: Default>() -> Self::E {
1413
//~^ ERROR impl has stricter requirements than trait
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0276]: impl has stricter requirements than trait
2-
--> $DIR/issue-55872-1.rs:13:15
2+
--> $DIR/issue-55872-1.rs:12:15
33
|
44
LL | fn foo<T>() -> Self::E;
55
| ----------------------- definition of `foo` from trait
@@ -8,7 +8,7 @@ LL | fn foo<T: Default>() -> Self::E {
88
| ^^^^^^^ impl has extra requirement `T: Default`
99

1010
error[E0277]: the trait bound `S: Copy` is not satisfied in `(S, T)`
11-
--> $DIR/issue-55872-1.rs:15:9
11+
--> $DIR/issue-55872-1.rs:14:9
1212
|
1313
LL | (S::default(), T::default())
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 {
2020
| +++++++++++++++++++
2121

2222
error[E0277]: the trait bound `T: Copy` is not satisfied in `(S, T)`
23-
--> $DIR/issue-55872-1.rs:15:9
23+
--> $DIR/issue-55872-1.rs:14:9
2424
|
2525
LL | (S::default(), T::default())
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ within `(S, T)`, the trait `Copy` is not implemented for `T`
@@ -31,13 +31,7 @@ help: consider further restricting this bound
3131
LL | fn foo<T: Default + std::marker::Copy>() -> Self::E {
3232
| +++++++++++++++++++
3333

34-
error: could not find defining uses
35-
--> $DIR/issue-55872-1.rs:10:14
36-
|
37-
LL | type E = impl Copy;
38-
| ^^^^^^^^^
39-
40-
error: aborting due to 4 previous errors
34+
error: aborting due to 3 previous errors
4135

4236
Some errors have detailed explanations: E0276, E0277.
4337
For more information about an error, try `rustc --explain E0276`.

src/test/ui/impl-trait/issue-55872-3.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub trait Bar {
1111

1212
impl<S> Bar for S {
1313
type E = impl std::marker::Copy;
14-
//~^ ERROR could not find defining uses
1514
fn foo<T>() -> Self::E {
1615
async {}
1716
//~^ ERROR the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied [E0277]
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
error[E0277]: the trait bound `impl Future<Output = [async output]>: Copy` is not satisfied
2-
--> $DIR/issue-55872-3.rs:16:9
2+
--> $DIR/issue-55872-3.rs:15:9
33
|
44
LL | async {}
55
| ^^^^^^^^ the trait `Copy` is not implemented for `impl Future<Output = [async output]>`
66

7-
error: could not find defining uses
8-
--> $DIR/issue-55872-3.rs:13:14
9-
|
10-
LL | type E = impl std::marker::Copy;
11-
| ^^^^^^^^^^^^^^^^^^^^^^
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
148

159
For more information about this error, try `rustc --explain E0277`.

src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | type WrongGeneric<T> = impl 'static;
1717
| ^
1818

1919
error[E0310]: the parameter type `T` may not live long enough
20-
--> $DIR/generic_type_does_not_live_long_enough.rs:15:5
20+
--> $DIR/generic_type_does_not_live_long_enough.rs:14:5
2121
|
2222
LL | t
2323
| ^

src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ fn main() {
99

1010
type WrongGeneric<T> = impl 'static;
1111
//~^ ERROR: at least one trait must be specified
12-
//~| ERROR could not find defining uses
1312

1413
fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
1514
t

src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,13 @@ LL | type WrongGeneric<T> = impl 'static;
1717
| ^
1818

1919
error[E0310]: the parameter type `T` may not live long enough
20-
--> $DIR/generic_type_does_not_live_long_enough.rs:15:5
20+
--> $DIR/generic_type_does_not_live_long_enough.rs:14:5
2121
|
2222
LL | fn wrong_generic<T>(t: T) -> WrongGeneric<T> {
2323
| - help: consider adding an explicit lifetime bound...: `T: 'static`
2424
LL | t
2525
| ^ ...so that the type `T` will meet its required lifetime bounds
2626

27-
error: could not find defining uses
28-
--> $DIR/generic_type_does_not_live_long_enough.rs:10:24
29-
|
30-
LL | type WrongGeneric<T> = impl 'static;
31-
| ^^^^^^^^^^^^
32-
33-
error: aborting due to 4 previous errors
27+
error: aborting due to 3 previous errors
3428

3529
For more information about this error, try `rustc --explain E0310`.

0 commit comments

Comments
 (0)