-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specializing on const trait bounds
- Loading branch information
Showing
2 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// check-pass | ||
#![feature(const_trait_impl, min_specialization, rustc_attrs)] | ||
|
||
#[rustc_specialization_trait] | ||
#[const_trait] | ||
pub unsafe trait Sup { | ||
fn foo() -> u32; | ||
} | ||
|
||
#[rustc_specialization_trait] | ||
#[const_trait] | ||
pub unsafe trait Sub: ~const Sup {} | ||
|
||
unsafe impl const Sup for u8 { | ||
default fn foo() -> u32 { | ||
1 | ||
} | ||
} | ||
|
||
unsafe impl const Sup for () { | ||
fn foo() -> u32 { | ||
42 | ||
} | ||
} | ||
|
||
unsafe impl const Sub for () {} | ||
|
||
#[const_trait] | ||
pub trait A { | ||
fn a() -> u32; | ||
} | ||
|
||
impl<T: ~const Default> const A for T { | ||
default fn a() -> u32 { | ||
2 | ||
} | ||
} | ||
|
||
impl<T: ~const Default + ~const Sup> const A for T { | ||
default fn a() -> u32 { | ||
3 | ||
} | ||
} | ||
|
||
impl<T: ~const Default + ~const Sub> const A for T { | ||
fn a() -> u32 { | ||
T::foo() | ||
} | ||
} | ||
|
||
const _: () = assert!(<()>::a() == 42); | ||
const _: () = assert!(<u8>::a() == 3); | ||
const _: () = assert!(<u16>::a() == 2); | ||
|
||
fn main() {} |