typeck/type_of: don't ignore incorrect defining uses of opaque types.

This commit is contained in:
Eduard-Mihai Burtescu 2020-03-22 11:15:56 +02:00
parent 6465113852
commit a98b5340d1
16 changed files with 51 additions and 70 deletions

View File

@ -405,12 +405,12 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
let opaque_generics = self.tcx.generics_of(self.def_id);
let mut used_params: FxHashSet<ty::ParamTy> = FxHashSet::default();
let mut has_errors = false;
let mut duplicate_params: FxHashSet<ty::ParamTy> = FxHashSet::default();
for (i, arg) in substs.iter().enumerate() {
// FIXME(eddyb) enforce lifetime and const param 1:1 mapping.
if let GenericArgKind::Type(ty) = arg.unpack() {
if let ty::Param(p) = ty.kind {
if !used_params.insert(p) {
if !used_params.insert(p) && duplicate_params.insert(p) {
// There was already an entry for `p`, meaning a generic parameter
// was used twice.
self.tcx.sess.span_err(
@ -421,7 +421,6 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
p,
),
);
return;
}
} else {
let param = opaque_generics.param_at(i, self.tcx);
@ -435,15 +434,10 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
arg,
),
);
has_errors = true;
}
}
}
if has_errors {
return;
}
if let Some((prev_span, prev_ty)) = self.found {
if *concrete_type != prev_ty {
debug!("find_opaque_ty_constraints: span={:?}", span);

View File

@ -8,8 +8,7 @@ trait TraitWithAssoc {
}
type Foo<V> = impl Trait<V>;
//~^ ERROR could not find defining uses
//~| ERROR the trait bound `T: TraitWithAssoc` is not satisfied
//~^ ERROR the trait bound `T: TraitWithAssoc` is not satisfied
trait Trait<U> {}

View File

@ -10,19 +10,13 @@ LL | fn foo_desugared<T: TraitWithAssoc + TraitWithAssoc>(_: T) -> Foo<T::Assoc>
| ^^^^^^^^^^^^^^^^
error: defining opaque type use does not fully define opaque type: generic parameter `V` is specified as concrete type `<T as TraitWithAssoc>::Assoc`
--> $DIR/bound_reduction2.rs:18:1
--> $DIR/bound_reduction2.rs:17:1
|
LL | / fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
LL | | ()
LL | | }
| |_^
error: could not find defining uses
--> $DIR/bound_reduction2.rs:10:1
|
LL | type Foo<V> = impl Trait<V>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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

@ -6,7 +6,6 @@ fn main() {}
// test that unused generic parameters are ok
type Two<T, U> = impl Debug;
//~^ could not find defining uses
fn one<T: Debug>(t: T) -> Two<T, T> {
//~^ ERROR defining opaque type use restricts opaque type

View File

@ -1,5 +1,5 @@
error: defining opaque type use restricts opaque type by using the generic parameter `T` twice
--> $DIR/generic_duplicate_param_use.rs:11:1
--> $DIR/generic_duplicate_param_use.rs:10:1
|
LL | / fn one<T: Debug>(t: T) -> Two<T, T> {
LL | |
@ -7,11 +7,5 @@ LL | | t
LL | | }
| |_^
error: could not find defining uses
--> $DIR/generic_duplicate_param_use.rs:8:1
|
LL | type Two<T, U> = impl Debug;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error

View File

@ -8,10 +8,11 @@ fn main() {}
type Two<T, U> = impl Debug;
fn one<T: Debug>(t: T) -> Two<T, T> {
//~^ defining opaque type use restricts opaque type
//~^ ERROR defining opaque type use restricts opaque type
t
}
fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
//~^ ERROR concrete type differs from previous defining opaque type use
t
}

View File

@ -7,5 +7,23 @@ LL | | t
LL | | }
| |_^
error: aborting due to previous error
error: concrete type differs from previous defining opaque type use
--> $DIR/generic_duplicate_param_use2.rs:15:1
|
LL | / fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
LL | |
LL | | t
LL | | }
| |_^ expected `U`, got `T`
|
note: previous use here
--> $DIR/generic_duplicate_param_use2.rs:10:1
|
LL | / fn one<T: Debug>(t: T) -> Two<T, T> {
LL | |
LL | | t
LL | | }
| |_^
error: aborting due to 2 previous errors

View File

@ -8,15 +8,15 @@ fn main() {}
type Two<T, U> = impl Debug;
fn one<T: Debug>(t: T) -> Two<T, T> {
//~^ defining opaque type use restricts opaque type
//~^ ERROR defining opaque type use restricts opaque type
t
}
fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
//~^ ERROR concrete type differs from previous defining opaque type use
t
}
fn three<T, U: Debug>(_: T, u: U) -> Two<T, U> {
//~^ concrete type differs from previous defining opaque type use
u
}

View File

@ -8,18 +8,19 @@ LL | | }
| |_^
error: concrete type differs from previous defining opaque type use
--> $DIR/generic_duplicate_param_use3.rs:19:1
|
LL | / fn three<T, U: Debug>(_: T, u: U) -> Two<T, U> {
LL | |
LL | | u
LL | | }
| |_^ expected `T`, got `U`
|
note: previous use here
--> $DIR/generic_duplicate_param_use3.rs:15:1
|
LL | / fn two<T: Debug, U>(t: T, _: U) -> Two<T, U> {
LL | |
LL | | t
LL | | }
| |_^ expected `U`, got `T`
|
note: previous use here
--> $DIR/generic_duplicate_param_use3.rs:10:1
|
LL | / fn one<T: Debug>(t: T) -> Two<T, T> {
LL | |
LL | | t
LL | | }
| |_^

View File

@ -3,8 +3,7 @@
fn main() {}
type Cmp<T> = impl 'static;
//~^ ERROR could not find defining uses
//~^^ ERROR: at least one trait must be specified
//~^ ERROR: at least one trait must be specified
// not a defining use, because it doesn't define *all* possible generics

View File

@ -5,18 +5,12 @@ LL | type Cmp<T> = impl 'static;
| ^^^^^^^^^^^^
error: defining opaque type use does not fully define opaque type: generic parameter `T` is specified as concrete type `u32`
--> $DIR/generic_nondefining_use.rs:11:1
--> $DIR/generic_nondefining_use.rs:10:1
|
LL | / fn cmp() -> Cmp<u32> {
LL | | 5u32
LL | | }
| |_^
error: could not find defining uses
--> $DIR/generic_nondefining_use.rs:5:1
|
LL | type Cmp<T> = impl 'static;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

View File

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

View File

@ -1,5 +1,5 @@
error: defining opaque type use does not fully define opaque type: generic parameter `I` is specified as concrete type `u8`
--> $DIR/issue-60564.rs:20:5
--> $DIR/issue-60564.rs:19:5
|
LL | / fn iter_bits(self, n: u8) -> Self::BitsIter {
LL | |
@ -9,11 +9,5 @@ LL | | .map(move |shift| ((self >> T::from(shift)) & T::from(1)).try
LL | | }
| |_____^
error: could not find defining uses
--> $DIR/issue-60564.rs:8:1
|
LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error

View File

@ -4,7 +4,7 @@
#![feature(type_alias_impl_trait)]
trait Trait<T> {}
type Alias<'a, U> = impl Trait<U>; //~ ERROR could not find defining uses
type Alias<'a, U> = impl Trait<U>;
fn f<'a>() -> Alias<'a, ()> {}
//~^ ERROR defining opaque type use does not fully define opaque type: generic parameter `U`

View File

@ -4,11 +4,5 @@ error: defining opaque type use does not fully define opaque type: generic param
LL | fn f<'a>() -> Alias<'a, ()> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: could not find defining uses
--> $DIR/issue-68368-non-defining-use.rs:7:1
|
LL | type Alias<'a, U> = impl Trait<U>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to previous error

View File

@ -16,10 +16,11 @@ LL | | }
| |_^ expected `(T, i8)`, got `(T, <U as Bar>::Blub)`
|
note: previous use here
--> $DIR/not_a_defining_use.rs:14:1
--> $DIR/not_a_defining_use.rs:9:1
|
LL | / fn three<T: Debug, U>(t: T) -> Two<T, U> {
LL | | (t, 5i8)
LL | / fn two<T: Debug>(t: T) -> Two<T, u32> {
LL | |
LL | | (t, 4i8)
LL | | }
| |_^