Skip to content

Commit 93f3d08

Browse files
committed
Don't emit errors containing type error as another (more useful) error must have been emitted already
1 parent 0382c00 commit 93f3d08

12 files changed

+13
-74
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,10 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
540540
}
541541

542542
if let Some((prev_span, prev_ty)) = self.found {
543-
if *concrete_type != prev_ty {
543+
if *concrete_type != prev_ty
544+
&& !concrete_type.references_error()
545+
&& !prev_ty.references_error()
546+
{
544547
debug!("find_opaque_ty_constraints: span={:?}", span);
545548
// Found different concrete types for the opaque type.
546549
let mut err = self.tcx.sess.struct_span_err(

src/test/ui/generator/layout-error.min_tait.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,7 @@ LL | static POOL: Task<F> = Task::new();
2222
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
2323
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
2424

25-
error: concrete type differs from previous defining opaque type use
26-
--> $DIR/layout-error.rs:31:24
27-
|
28-
LL | Task::spawn(&POOL, || cb());
29-
| ^^^^^^^ expected `[type error]`, got `impl Future`
30-
|
31-
note: previous use here
32-
--> $DIR/layout-error.rs:30:5
33-
|
34-
LL | static POOL: Task<F> = Task::new();
35-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36-
37-
error: aborting due to 4 previous errors
25+
error: aborting due to 3 previous errors
3826

3927
Some errors have detailed explanations: E0425, E0658.
4028
For more information about an error, try `rustc --explain E0425`.

src/test/ui/generator/layout-error.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,4 @@ fn main() {
2929
// Check that statics are inhabited computes they layout.
3030
static POOL: Task<F> = Task::new(); //[min_tait]~ ERROR not permitted here
3131
Task::spawn(&POOL, || cb()); //[min_tait]~ ERROR type alias impl trait is not permitted here
32-
//[min_tait]~^ ERROR concrete type differs from previous
3332
}

src/test/ui/generator/metadata-sufficient-for-layout.full_tait.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait, impl_trait_in_binding
1616
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
1717

1818
error: fatal error triggered by #[rustc_error]
19-
--> $DIR/metadata-sufficient-for-layout.rs:29:1
19+
--> $DIR/metadata-sufficient-for-layout.rs:28:1
2020
|
2121
LL | fn main() {}
2222
| ^^^^^^^^^

src/test/ui/generator/metadata-sufficient-for-layout.min_tait.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ LL | static A: Option<F> = None;
77
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
88
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
99

10-
error: concrete type differs from previous defining opaque type use
11-
--> $DIR/metadata-sufficient-for-layout.rs:25:1
12-
|
13-
LL | fn f() -> F { metadata_sufficient_for_layout::g() }
14-
| ^^^^^^^^^^^ expected `[type error]`, got `impl Generator`
15-
|
16-
note: previous use here
17-
--> $DIR/metadata-sufficient-for-layout.rs:22:1
18-
|
19-
LL | static A: Option<F> = None;
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
22-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2311

2412
For more information about this error, try `rustc --explain E0658`.

src/test/ui/generator/metadata-sufficient-for-layout.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ static A: Option<F> = None;
2323
//[min_tait]~^ ERROR not permitted here
2424

2525
fn f() -> F { metadata_sufficient_for_layout::g() }
26-
//[min_tait]~^ ERROR concrete type differs
2726

2827
#[rustc_error]
2928
fn main() {} //[full_tait]~ ERROR

src/test/ui/type-alias-impl-trait/issue-52843-closure-constrain.min_tait.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ LL | let null = || -> Opaque { 0 };
77
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
88
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
99

10-
error: concrete type differs from previous defining opaque type use
11-
--> $DIR/issue-52843-closure-constrain.rs:13:16
12-
|
13-
LL | let null = || -> Opaque { 0 };
14-
| ^^^^^^^^^^^^^^^^^^ expected `String`, got `[type error]`
15-
|
16-
note: previous use here
17-
--> $DIR/issue-52843-closure-constrain.rs:12:5
18-
|
19-
LL | fn _unused() -> Opaque { String::new() }
20-
| ^^^^^^^^^^^^^^^^^^^^^^
21-
22-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2311

2412
For more information about this error, try `rustc --explain E0658`.

src/test/ui/type-alias-impl-trait/issue-52843-closure-constrain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fn main() {
1111
type Opaque = impl Debug;
1212
fn _unused() -> Opaque { String::new() }
1313
let null = || -> Opaque { 0 }; //[min_tait]~ ERROR: not permitted here
14-
//~^ ERROR: concrete type differs from previous defining opaque type use
14+
//[full_tait]~^ ERROR: concrete type differs from previous defining opaque type use
1515
println!("{:?}", null());
1616
}

src/test/ui/type-alias-impl-trait/issue-60407.min_tait.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ LL | static mut TEST: Option<Debuggable> = None;
77
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
88
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable
99

10-
error: concrete type differs from previous defining opaque type use
11-
--> $DIR/issue-60407.rs:16:1
12-
|
13-
LL | fn foo() -> Debuggable {
14-
| ^^^^^^^^^^^^^^^^^^^^^^ expected `[type error]`, got `u32`
15-
|
16-
note: previous use here
17-
--> $DIR/issue-60407.rs:9:1
18-
|
19-
LL | static mut TEST: Option<Debuggable> = None;
20-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21-
22-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2311

2412
For more information about this error, try `rustc --explain E0658`.

src/test/ui/type-alias-impl-trait/issue-60407.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ fn main() { //[full_tait]~ ERROR
1313
unsafe { TEST = Some(foo()) }
1414
}
1515

16-
fn foo() -> Debuggable { //[min_tait]~ ERROR concrete type differs
16+
fn foo() -> Debuggable {
1717
0u32
1818
}

src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B, A>)
1313
}
1414

1515
fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
16-
//~^ ERROR concrete type differs from previous defining opaque type use
1716
(a, b) //~ ERROR mismatched types
1817
}
1918

src/test/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr

+2-15
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ LL | fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error[E0308]: mismatched types
26-
--> $DIR/multiple-def-uses-in-one-fn3.rs:17:9
26+
--> $DIR/multiple-def-uses-in-one-fn3.rs:16:9
2727
|
2828
LL | fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
2929
| - - found type parameter
3030
| |
3131
| expected type parameter
32-
LL |
3332
LL | (a, b)
3433
| ^ expected type parameter `A`, found type parameter `B`
3534
|
@@ -38,18 +37,6 @@ LL | (a, b)
3837
= note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
3938
= note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
4039

41-
error: concrete type differs from previous defining opaque type use
42-
--> $DIR/multiple-def-uses-in-one-fn3.rs:15:1
43-
|
44-
LL | fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[type error]`, got `A`
46-
|
47-
note: previous use here
48-
--> $DIR/multiple-def-uses-in-one-fn3.rs:9:1
49-
|
50-
LL | fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B, A>) {
51-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52-
53-
error: aborting due to 4 previous errors
40+
error: aborting due to 3 previous errors
5441

5542
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)