allow concrete self types in consts
This commit is contained in:
parent
7402a39447
commit
e5b82a56c5
11 changed files with 141 additions and 18 deletions
|
|
@ -601,7 +601,7 @@ pub fn register_res(cx: &DocContext<'_>, res: Res) -> DefId {
|
|||
},
|
||||
Res::Def(DefKind::TraitAlias, i) => (i, TypeKind::TraitAlias),
|
||||
Res::SelfTy(Some(def_id), _) => (def_id, TypeKind::Trait),
|
||||
Res::SelfTy(_, Some(impl_def_id)) => return impl_def_id,
|
||||
Res::SelfTy(_, Some((impl_def_id, _))) => return impl_def_id,
|
||||
_ => return res.def_id(),
|
||||
};
|
||||
if did.is_local() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
#![feature(min_const_generics)]
|
||||
|
||||
trait Foo {
|
||||
fn t1() -> [u8; std::mem::size_of::<Self>()]; //~ERROR generic parameters
|
||||
}
|
||||
|
||||
struct Bar<T>(T);
|
||||
|
||||
impl Bar<u8> {
|
||||
fn t2() -> [u8; std::mem::size_of::<Self>()] { todo!() } // ok
|
||||
}
|
||||
|
||||
impl<T> Bar<T> {
|
||||
fn t3() -> [u8; std::mem::size_of::<Self>()] {} //~ERROR generic `Self`
|
||||
}
|
||||
|
||||
trait Baz {
|
||||
fn hey();
|
||||
}
|
||||
|
||||
impl Baz for u16 {
|
||||
fn hey() {
|
||||
let _: [u8; std::mem::size_of::<Self>()]; // ok
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
error: generic parameters must not be used inside of non trivial constant values
|
||||
--> $DIR/self-ty-in-const-1.rs:4:41
|
||||
|
|
||||
LL | fn t1() -> [u8; std::mem::size_of::<Self>()];
|
||||
| ^^^^ non-trivial anonymous constants must not depend on the parameter `Self`
|
||||
|
|
||||
= help: it is currently only allowed to use either `Self` or `{ Self }` as generic constants
|
||||
|
||||
error: generic `Self` types are currently not permitted in anonymous constants
|
||||
--> $DIR/self-ty-in-const-1.rs:14:41
|
||||
|
|
||||
LL | fn t3() -> [u8; std::mem::size_of::<Self>()] {}
|
||||
| ^^^^
|
||||
|
|
||||
note: not a concrete type
|
||||
--> $DIR/self-ty-in-const-1.rs:13:1
|
||||
|
|
||||
LL | / impl<T> Bar<T> {
|
||||
LL | | fn t3() -> [u8; std::mem::size_of::<Self>()] {}
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#![feature(min_const_generics)]
|
||||
|
||||
struct Bar<T>(T);
|
||||
|
||||
trait Baz {
|
||||
fn hey();
|
||||
}
|
||||
|
||||
impl Baz for u16 {
|
||||
fn hey() {
|
||||
let _: [u8; std::mem::size_of::<Self>()]; // ok
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Baz for Bar<T> {
|
||||
fn hey() {
|
||||
let _: [u8; std::mem::size_of::<Self>()]; //~ERROR generic `Self`
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
error: generic `Self` types are currently not permitted in anonymous constants
|
||||
--> $DIR/self-ty-in-const-2.rs:17:41
|
||||
|
|
||||
LL | let _: [u8; std::mem::size_of::<Self>()];
|
||||
| ^^^^
|
||||
|
|
||||
note: not a concrete type
|
||||
--> $DIR/self-ty-in-const-2.rs:15:1
|
||||
|
|
||||
LL | / impl<T> Baz for Bar<T> {
|
||||
LL | | fn hey() {
|
||||
LL | | let _: [u8; std::mem::size_of::<Self>()];
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue