Skip to content

Commit

Permalink
Don't emit errors containing type error as another (more useful) er…
Browse files Browse the repository at this point in the history
…ror must have been emitted already
  • Loading branch information
oli-obk committed Mar 18, 2021
1 parent 0382c00 commit 93f3d08
Showing 12 changed files with 13 additions and 74 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
@@ -540,7 +540,10 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
}

if let Some((prev_span, prev_ty)) = self.found {
if *concrete_type != prev_ty {
if *concrete_type != prev_ty
&& !concrete_type.references_error()
&& !prev_ty.references_error()
{
debug!("find_opaque_ty_constraints: span={:?}", span);
// Found different concrete types for the opaque type.
let mut err = self.tcx.sess.struct_span_err(
14 changes: 1 addition & 13 deletions src/test/ui/generator/layout-error.min_tait.stderr
Original file line number Diff line number Diff line change
@@ -22,19 +22,7 @@ LL | static POOL: Task<F> = Task::new();
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable

error: concrete type differs from previous defining opaque type use
--> $DIR/layout-error.rs:31:24
|
LL | Task::spawn(&POOL, || cb());
| ^^^^^^^ expected `[type error]`, got `impl Future`
|
note: previous use here
--> $DIR/layout-error.rs:30:5
|
LL | static POOL: Task<F> = Task::new();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0425, E0658.
For more information about an error, try `rustc --explain E0425`.
1 change: 0 additions & 1 deletion src/test/ui/generator/layout-error.rs
Original file line number Diff line number Diff line change
@@ -29,5 +29,4 @@ fn main() {
// Check that statics are inhabited computes they layout.
static POOL: Task<F> = Task::new(); //[min_tait]~ ERROR not permitted here
Task::spawn(&POOL, || cb()); //[min_tait]~ ERROR type alias impl trait is not permitted here
//[min_tait]~^ ERROR concrete type differs from previous
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ LL | #![cfg_attr(full_tait, feature(type_alias_impl_trait, impl_trait_in_binding
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information

error: fatal error triggered by #[rustc_error]
--> $DIR/metadata-sufficient-for-layout.rs:29:1
--> $DIR/metadata-sufficient-for-layout.rs:28:1
|
LL | fn main() {}
| ^^^^^^^^^
Original file line number Diff line number Diff line change
@@ -7,18 +7,6 @@ LL | static A: Option<F> = None;
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable

error: concrete type differs from previous defining opaque type use
--> $DIR/metadata-sufficient-for-layout.rs:25:1
|
LL | fn f() -> F { metadata_sufficient_for_layout::g() }
| ^^^^^^^^^^^ expected `[type error]`, got `impl Generator`
|
note: previous use here
--> $DIR/metadata-sufficient-for-layout.rs:22:1
|
LL | static A: Option<F> = None;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
1 change: 0 additions & 1 deletion src/test/ui/generator/metadata-sufficient-for-layout.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ static A: Option<F> = None;
//[min_tait]~^ ERROR not permitted here

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

#[rustc_error]
fn main() {} //[full_tait]~ ERROR
Original file line number Diff line number Diff line change
@@ -7,18 +7,6 @@ LL | let null = || -> Opaque { 0 };
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable

error: concrete type differs from previous defining opaque type use
--> $DIR/issue-52843-closure-constrain.rs:13:16
|
LL | let null = || -> Opaque { 0 };
| ^^^^^^^^^^^^^^^^^^ expected `String`, got `[type error]`
|
note: previous use here
--> $DIR/issue-52843-closure-constrain.rs:12:5
|
LL | fn _unused() -> Opaque { String::new() }
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@ fn main() {
type Opaque = impl Debug;
fn _unused() -> Opaque { String::new() }
let null = || -> Opaque { 0 }; //[min_tait]~ ERROR: not permitted here
//~^ ERROR: concrete type differs from previous defining opaque type use
//[full_tait]~^ ERROR: concrete type differs from previous defining opaque type use
println!("{:?}", null());
}
14 changes: 1 addition & 13 deletions src/test/ui/type-alias-impl-trait/issue-60407.min_tait.stderr
Original file line number Diff line number Diff line change
@@ -7,18 +7,6 @@ LL | static mut TEST: Option<Debuggable> = None;
= note: see issue #63065 <https://github.com/rust-lang/rust/issues/63065> for more information
= help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable

error: concrete type differs from previous defining opaque type use
--> $DIR/issue-60407.rs:16:1
|
LL | fn foo() -> Debuggable {
| ^^^^^^^^^^^^^^^^^^^^^^ expected `[type error]`, got `u32`
|
note: previous use here
--> $DIR/issue-60407.rs:9:1
|
LL | static mut TEST: Option<Debuggable> = None;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
2 changes: 1 addition & 1 deletion src/test/ui/type-alias-impl-trait/issue-60407.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,6 @@ fn main() { //[full_tait]~ ERROR
unsafe { TEST = Some(foo()) }
}

fn foo() -> Debuggable { //[min_tait]~ ERROR concrete type differs
fn foo() -> Debuggable {
0u32
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B, A>)
}

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

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

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

error: concrete type differs from previous defining opaque type use
--> $DIR/multiple-def-uses-in-one-fn3.rs:15:1
|
LL | fn g<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<A, B>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[type error]`, got `A`
|
note: previous use here
--> $DIR/multiple-def-uses-in-one-fn3.rs:9:1
|
LL | fn f<A: ToString + Clone, B: ToString + Clone>(a: A, b: B) -> (X<A, B>, X<B, A>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

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

0 comments on commit 93f3d08

Please sign in to comment.