Auto merge of #76195 - lcnr:const-Self, r=varkor
allow concrete self types in consts This is quite a bad hack to fix #75486. There might be a better way to check if the self type depends on generic parameters, but I wasn't able to come up with one. r? `@varkor` cc `@petrochenkov`
This commit is contained in:
commit
56d8a933b3
13 changed files with 146 additions and 20 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() {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
error: generic parameters must not be used inside of non trivial constant values
|
||||
error: generic `Self` types are currently not permitted in anonymous constants
|
||||
--> $DIR/issue-62504.rs:19:25
|
||||
|
|
||||
LL | ArrayHolder([0; Self::SIZE])
|
||||
| ^^^^^^^^^^ 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
|
||||
note: not a concrete type
|
||||
--> $DIR/issue-62504.rs:17:22
|
||||
|
|
||||
LL | impl<const X: usize> ArrayHolder<X> {
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ impl<const X: usize> ArrayHolder<X> {
|
|||
pub const fn new() -> Self {
|
||||
ArrayHolder([0; Self::SIZE])
|
||||
//[full]~^ ERROR constant expression depends on a generic parameter
|
||||
//[min]~^^ ERROR generic parameters must not be used inside of non trivial constant values
|
||||
//[min]~^^ ERROR generic `Self` types are currently
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,22 @@
|
|||
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:9
|
||||
|
|
||||
LL | impl<T> Bar<T> {
|
||||
| ^^^^^^
|
||||
|
||||
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,14 @@
|
|||
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:17
|
||||
|
|
||||
LL | impl<T> Baz for Bar<T> {
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue