Reduce follow-up errors that are not helpful

This commit is contained in:
Oli Scherer 2022-01-28 17:18:53 +00:00
parent 6560d77a53
commit 59d0bff0e6
27 changed files with 40 additions and 210 deletions

View File

@ -58,7 +58,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
) -> VecMap<OpaqueTypeKey<'tcx>, Ty<'tcx>> {
opaque_ty_decls
.into_iter()
.filter_map(|(opaque_type_key, (concrete_type, decl_span, origin))| {
.map(|(opaque_type_key, (concrete_type, decl_span, origin))| {
let substs = opaque_type_key.substs;
// FIXME: why are the spans in decl_span often DUMMY_SP?
let span = decl_span.substitute_dummy(span);
@ -112,8 +112,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
span,
);
check_opaque_type_parameter_valid(infcx.tcx, opaque_type_key, origin, span)
.then_some((opaque_type_key, remapped_type))
(
opaque_type_key,
if check_opaque_type_parameter_valid(infcx.tcx, opaque_type_key, origin, span) {
remapped_type
} else {
infcx.tcx.ty_error()
},
)
})
.collect()
}

View File

@ -18,7 +18,6 @@ struct C;
impl<'a> A<'a> for C {
type B<'b> = impl Clone;
//~^ ERROR: lifetime bound not satisfied
//~| ERROR: unconstrained opaque type
fn a(&'a self) -> Self::B<'a> {} //~ ERROR: non-defining opaque type use in defining scope
}

View File

@ -16,7 +16,7 @@ LL | type B<'b> = impl Clone;
| ^^
error: non-defining opaque type use in defining scope
--> $DIR/issue-88595.rs:23:35
--> $DIR/issue-88595.rs:22:35
|
LL | fn a(&'a self) -> Self::B<'a> {}
| ^^
@ -29,14 +29,6 @@ LL | impl<'a> A<'a> for C {
LL | type B<'b> = impl Clone;
| ^^
error: unconstrained opaque type
--> $DIR/issue-88595.rs:19:18
|
LL | type B<'b> = impl Clone;
| ^^^^^^^^^^
|
= note: `B` must be used in combination with a concrete type within the same module
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0478`.

View File

@ -7,7 +7,6 @@ trait TraitWithAssoc {
}
type Foo<V> = impl Trait<V>;
//~^ ERROR unconstrained opaque type
trait Trait<U> {}

View File

@ -1,5 +1,5 @@
error: non-defining opaque type use in defining scope
--> $DIR/bound_reduction2.rs:17:5
--> $DIR/bound_reduction2.rs:16:5
|
LL | ()
| ^^
@ -10,13 +10,5 @@ note: used non-generic type `<T as TraitWithAssoc>::Assoc` for generic parameter
LL | type Foo<V> = impl Trait<V>;
| ^
error: unconstrained opaque type
--> $DIR/bound_reduction2.rs:9:15
|
LL | type Foo<V> = impl Trait<V>;
| ^^^^^^^^^^^^^
|
= note: `Foo` must be used in combination with a concrete type within the same module
error: aborting due to 2 previous errors
error: aborting due to previous error

View File

@ -4,7 +4,6 @@
#![feature(type_alias_impl_trait)]
type X<'a> = impl Into<&'static str> + From<&'a str>;
//~^ ERROR unconstrained opaque type
fn f<'a: 'static>(t: &'a str) -> X<'a> {
//~^ WARNING unnecessary lifetime parameter

View File

@ -1,5 +1,5 @@
warning: unnecessary lifetime parameter `'a`
--> $DIR/bounds-are-checked.rs:9:6
--> $DIR/bounds-are-checked.rs:8:6
|
LL | fn f<'a: 'static>(t: &'a str) -> X<'a> {
| ^^^^^^^^^^^
@ -7,7 +7,7 @@ LL | fn f<'a: 'static>(t: &'a str) -> X<'a> {
= help: you can use the `'static` lifetime directly, in place of `'a`
error: non-defining opaque type use in defining scope
--> $DIR/bounds-are-checked.rs:11:5
--> $DIR/bounds-are-checked.rs:10:5
|
LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
@ -15,13 +15,5 @@ LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
LL | t
| ^
error: unconstrained opaque type
--> $DIR/bounds-are-checked.rs:6:14
|
LL | type X<'a> = impl Into<&'static str> + From<&'a str>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `X` must be used in combination with a concrete type within the same module
error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to previous error; 1 warning emitted

View File

@ -3,7 +3,7 @@
fn main() {}
type Two<'a, 'b> = impl std::fmt::Debug;
//~^ ERROR unconstrained opaque type
fn one<'a>(t: &'a ()) -> Two<'a, 'a> {
t

View File

@ -10,13 +10,5 @@ note: lifetime used multiple times
LL | type Two<'a, 'b> = impl std::fmt::Debug;
| ^^ ^^
error: unconstrained opaque type
--> $DIR/generic_duplicate_lifetime_param.rs:5:20
|
LL | type Two<'a, 'b> = impl std::fmt::Debug;
| ^^^^^^^^^^^^^^^^^^^^
|
= note: `Two` must be used in combination with a concrete type within the same module
error: aborting due to 2 previous errors
error: aborting due to previous error

View File

@ -6,11 +6,11 @@ fn main() {}
// test that unused generic parameters are ok
type TwoTys<T, U> = impl Debug;
//~^ ERROR unconstrained opaque type
type TwoLifetimes<'a, 'b> = impl Debug;
//~^ ERROR unconstrained opaque type
type TwoConsts<const X: usize, const Y: usize> = impl Debug;
//~^ ERROR unconstrained opaque type
fn one_ty<T: Debug>(t: T) -> TwoTys<T, T> {
t

View File

@ -10,14 +10,6 @@ note: type used multiple times
LL | type TwoTys<T, U> = impl Debug;
| ^ ^
error: unconstrained opaque type
--> $DIR/generic_duplicate_param_use.rs:8:21
|
LL | type TwoTys<T, U> = impl Debug;
| ^^^^^^^^^^
|
= note: `TwoTys` must be used in combination with a concrete type within the same module
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:21:5
|
@ -30,14 +22,6 @@ note: lifetime used multiple times
LL | type TwoLifetimes<'a, 'b> = impl Debug;
| ^^ ^^
error: unconstrained opaque type
--> $DIR/generic_duplicate_param_use.rs:10:29
|
LL | type TwoLifetimes<'a, 'b> = impl Debug;
| ^^^^^^^^^^
|
= note: `TwoLifetimes` must be used in combination with a concrete type within the same module
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use.rs:26:5
|
@ -50,13 +34,5 @@ note: constant used multiple times
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^ ^
error: unconstrained opaque type
--> $DIR/generic_duplicate_param_use.rs:12:50
|
LL | type TwoConsts<const X: usize, const Y: usize> = impl Debug;
| ^^^^^^^^^^
|
= note: `TwoConsts` must be used in combination with a concrete type within the same module
error: aborting due to 6 previous errors
error: aborting due to 3 previous errors

View File

@ -8,11 +8,6 @@ fn main() {}
type Two<T, U> = impl Debug;
//~^ ERROR `T` doesn't implement `Debug`
fn one<T: Debug>(t: T) -> Two<T, T> {
t
//~^ ERROR non-defining opaque type use in defining scope
}
fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
t
}

View File

@ -1,15 +1,3 @@
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use2.rs:12:5
|
LL | t
| ^
|
note: type used multiple times
--> $DIR/generic_duplicate_param_use2.rs:8:10
|
LL | type Two<T, U> = impl Debug;
| ^ ^
error[E0277]: `T` doesn't implement `Debug`
--> $DIR/generic_duplicate_param_use2.rs:8:18
|
@ -21,6 +9,6 @@ help: consider restricting type parameter `T`
LL | type Two<T: std::fmt::Debug, U> = 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

@ -8,11 +8,6 @@ fn main() {}
type Two<T, U> = impl Debug;
//~^ ERROR `T` doesn't implement `Debug`
fn one<T: Debug>(t: T) -> Two<T, T> {
t
//~^ ERROR non-defining opaque type use in defining scope
}
fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
t
}

View File

@ -1,23 +1,11 @@
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use3.rs:12:5
|
LL | t
| ^
|
note: type used multiple times
--> $DIR/generic_duplicate_param_use3.rs:8:10
|
LL | type Two<T, U> = impl Debug;
| ^ ^
error: concrete type differs from previous defining opaque type use
--> $DIR/generic_duplicate_param_use3.rs:20:1
--> $DIR/generic_duplicate_param_use3.rs:15:1
|
LL | fn three<T, U: Debug>(_: T, u: U) -> Two<T, U> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `T`, got `U`
|
note: previous use here
--> $DIR/generic_duplicate_param_use3.rs:16:1
--> $DIR/generic_duplicate_param_use3.rs:11:1
|
LL | fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -33,6 +21,6 @@ help: consider restricting type parameter `T`
LL | type Two<T: std::fmt::Debug, U> = impl Debug;
| +++++++++++++++++
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View File

@ -8,11 +8,6 @@ fn main() {}
type Two<T, U> = impl Debug;
//~^ ERROR `U` doesn't implement `Debug`
fn one<T: Debug>(t: T) -> Two<T, T> {
t
//~^ ERROR non-defining opaque type use in defining scope
}
fn three<T, U: Debug>(_: T, u: U) -> Two<T, U> {
u
}

View File

@ -1,15 +1,3 @@
error: non-defining opaque type use in defining scope
--> $DIR/generic_duplicate_param_use4.rs:12:5
|
LL | t
| ^
|
note: type used multiple times
--> $DIR/generic_duplicate_param_use4.rs:8:10
|
LL | type Two<T, U> = impl Debug;
| ^ ^
error[E0277]: `U` doesn't implement `Debug`
--> $DIR/generic_duplicate_param_use4.rs:8:18
|
@ -21,6 +9,6 @@ help: consider restricting type parameter `U`
LL | type Two<T, U: std::fmt::Debug> = 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

@ -5,11 +5,11 @@ use std::fmt::Debug;
fn main() {}
type OneTy<T> = impl Debug;
//~^ ERROR unconstrained opaque type
type OneLifetime<'a> = impl Debug;
//~^ ERROR unconstrained opaque type
type OneConst<const X: usize> = impl Debug;
//~^ ERROR unconstrained opaque type
// Not defining uses, because they doesn't define *all* possible generics.

View File

@ -10,14 +10,6 @@ note: used non-generic type `u32` for generic parameter
LL | type OneTy<T> = impl Debug;
| ^
error: unconstrained opaque type
--> $DIR/generic_nondefining_use.rs:7:17
|
LL | type OneTy<T> = impl Debug;
| ^^^^^^^^^^
|
= note: `OneTy` must be used in combination with a concrete type within the same module
error: non-defining opaque type use in defining scope
--> $DIR/generic_nondefining_use.rs:22:5
|
@ -27,14 +19,6 @@ LL | type OneLifetime<'a> = impl Debug;
LL | 6u32
| ^^^^
error: unconstrained opaque type
--> $DIR/generic_nondefining_use.rs:9:24
|
LL | type OneLifetime<'a> = impl Debug;
| ^^^^^^^^^^
|
= note: `OneLifetime` must be used in combination with a concrete type within the same module
error: non-defining opaque type use in defining scope
--> $DIR/generic_nondefining_use.rs:27:5
|
@ -47,13 +31,5 @@ note: used non-generic constant `123_usize` for generic parameter
LL | type OneConst<const X: usize> = impl Debug;
| ^
error: unconstrained opaque type
--> $DIR/generic_nondefining_use.rs:11:33
|
LL | type OneConst<const X: usize> = impl Debug;
| ^^^^^^^^^^
|
= note: `OneConst` must be used in combination with a concrete type within the same module
error: aborting due to 6 previous errors
error: aborting due to 3 previous errors

View File

@ -6,7 +6,6 @@ trait IterBits {
}
type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
//~^ ERROR unconstrained opaque type
impl<T: Copy, E> IterBits for T
where

View File

@ -1,5 +1,5 @@
error: non-defining opaque type use in defining scope
--> $DIR/issue-60564.rs:21:9
--> $DIR/issue-60564.rs:20:9
|
LL | (0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -10,13 +10,5 @@ note: used non-generic type `u8` for generic parameter
LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
| ^
error: unconstrained opaque type
--> $DIR/issue-60564.rs:8:30
|
LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `IterBitsIter` must be used in combination with a concrete type within the same module
error: aborting due to 2 previous errors
error: aborting due to previous error

View File

@ -5,7 +5,7 @@
#![feature(type_alias_impl_trait)]
trait Trait<T> {}
type Alias<'a, U> = impl Trait<U>;
//~^ ERROR unconstrained opaque type
fn f<'a>() -> Alias<'a, ()> {}
//~^ ERROR non-defining opaque type use in defining scope

View File

@ -10,13 +10,5 @@ note: used non-generic type `()` for generic parameter
LL | type Alias<'a, U> = impl Trait<U>;
| ^
error: unconstrained opaque type
--> $DIR/issue-68368-non-defining-use-2.rs:7:21
|
LL | type Alias<'a, U> = impl Trait<U>;
| ^^^^^^^^^^^^^
|
= note: `Alias` must be used in combination with a concrete type within the same module
error: aborting due to 2 previous errors
error: aborting due to previous error

View File

@ -5,7 +5,7 @@
#![feature(type_alias_impl_trait)]
trait Trait<T> {}
type Alias<'a, U> = impl Trait<U>;
//~^ ERROR unconstrained opaque type
fn f<'a>() -> Alias<'a, ()> {}
//~^ ERROR non-defining opaque type use in defining scope

View File

@ -10,13 +10,5 @@ note: used non-generic type `()` for generic parameter
LL | type Alias<'a, U> = impl Trait<U>;
| ^
error: unconstrained opaque type
--> $DIR/issue-68368-non-defining-use.rs:7:21
|
LL | type Alias<'a, U> = impl Trait<U>;
| ^^^^^^^^^^^^^
|
= note: `Alias` must be used in combination with a concrete type within the same module
error: aborting due to 2 previous errors
error: aborting due to previous error

View File

@ -7,11 +7,6 @@ fn main() {}
type Two<T, U> = impl Debug;
//~^ ERROR `T` doesn't implement `Debug`
fn two<T: Debug>(t: T) -> Two<T, u32> {
(t, 4i8)
//~^ ERROR non-defining opaque type use in defining scope
}
fn three<T: Debug, U>(t: T) -> Two<T, U> {
(t, 5i8)
}

View File

@ -1,23 +1,11 @@
error: non-defining opaque type use in defining scope
--> $DIR/not_a_defining_use.rs:11:5
|
LL | (t, 4i8)
| ^^^^^^^^
|
note: used non-generic type `u32` for generic parameter
--> $DIR/not_a_defining_use.rs:7:13
|
LL | type Two<T, U> = impl Debug;
| ^
error: concrete type differs from previous defining opaque type use
--> $DIR/not_a_defining_use.rs:29:1
--> $DIR/not_a_defining_use.rs:24:1
|
LL | fn four<T: Debug, U: Bar>(t: T) -> Two<T, U> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `(T, i8)`, got `(T, <U as Bar>::Blub)`
|
note: previous use here
--> $DIR/not_a_defining_use.rs:15:1
--> $DIR/not_a_defining_use.rs:10:1
|
LL | fn three<T: Debug, U>(t: T) -> Two<T, U> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -34,6 +22,6 @@ help: consider restricting type parameter `T`
LL | type Two<T: std::fmt::Debug, U> = impl Debug;
| +++++++++++++++++
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.