Introduce const Trait (always-const trait bounds)
This commit is contained in:
@@ -309,23 +309,22 @@ impl Visibility {
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)]
|
||||
pub enum BoundConstness {
|
||||
/// `T: Trait`
|
||||
/// `Type: Trait`
|
||||
NotConst,
|
||||
/// `T: ~const Trait`
|
||||
/// `Type: const Trait`
|
||||
Const,
|
||||
/// `Type: ~const Trait`
|
||||
///
|
||||
/// Requires resolving to const only when we are in a const context.
|
||||
ConstIfConst,
|
||||
}
|
||||
|
||||
impl BoundConstness {
|
||||
/// Reduce `self` and `constness` to two possible combined states instead of four.
|
||||
pub fn and(&mut self, constness: hir::Constness) -> hir::Constness {
|
||||
match (constness, self) {
|
||||
(hir::Constness::Const, BoundConstness::ConstIfConst) => hir::Constness::Const,
|
||||
(_, this) => {
|
||||
*this = BoundConstness::NotConst;
|
||||
hir::Constness::NotConst
|
||||
}
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::NotConst => "",
|
||||
Self::Const => "const",
|
||||
Self::ConstIfConst => "~const",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,7 +333,7 @@ impl fmt::Display for BoundConstness {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::NotConst => f.write_str("normal"),
|
||||
Self::ConstIfConst => f.write_str("`~const`"),
|
||||
_ => write!(f, "`{self}`"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user