Check associated opaque types in check_opaque_types

This commit is contained in:
Matthew Jasper 2020-05-10 11:25:23 +01:00
parent 50c0192c64
commit b87e8eae29
6 changed files with 58 additions and 27 deletions

View file

@ -0,0 +1,18 @@
// Ensure that we don't ICE if associated type impl trait is used in an impl
// with an unconstrained type parameter.
#![feature(type_alias_impl_trait)]
trait X {
type I;
fn f() -> Self::I;
}
impl<T> X for () {
type I = impl Sized;
//~^ ERROR could not find defining uses
fn f() -> Self::I {}
//~^ ERROR type annotations needed
}
fn main() {}

View file

@ -0,0 +1,15 @@
error[E0282]: type annotations needed
--> $DIR/impl-with-unconstrained-param.rs:14:23
|
LL | fn f() -> Self::I {}
| ^^ cannot infer type for type parameter `T`
error: could not find defining uses
--> $DIR/impl-with-unconstrained-param.rs:12:14
|
LL | type I = impl Sized;
| ^^^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0282`.

View file

@ -17,11 +17,8 @@ where
{
type BitsIter = IterBitsIter<T, E, u8>;
fn iter_bits(self, n: u8) -> Self::BitsIter {
//~^ ERROR non-defining opaque type use in defining scope
//~| ERROR non-defining opaque type use in defining scope
(0u8..n)
.rev()
.map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap())
//~^ ERROR non-defining opaque type use in defining scope
(0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap())
}
}

View file

@ -1,15 +1,3 @@
error: non-defining opaque type use in defining scope
--> $DIR/issue-60564.rs:19:34
|
LL | fn iter_bits(self, n: u8) -> Self::BitsIter {
| ^^^^^^^^^^^^^^
|
note: used non-generic type `_` for generic parameter
--> $DIR/issue-60564.rs:8:22
|
LL | type IterBitsIter<T, E, I> = impl std::iter::Iterator<Item = I>;
| ^
error: non-defining opaque type use in defining scope
--> $DIR/issue-60564.rs:19:34
|
@ -22,5 +10,5 @@ note: used non-generic type `u8` for generic parameter
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