1
Fork 0

Auto merge of #127200 - fee1-dead-contrib:trait_def_const_trait, r=compiler-errors

Add `constness` to `TraitDef`

Second attempt at fixing the regression @ https://github.com/rust-lang/rust/pull/120639#issuecomment-2198373716

r? project-const-traits
This commit is contained in:
bors 2024-07-09 06:51:35 +00:00
commit 5be2ec7245
9 changed files with 42 additions and 31 deletions

View file

@ -1967,9 +1967,14 @@ impl<'tcx> TyCtxt<'tcx> {
) && self.constness(def_id) == hir::Constness::Const
}
#[inline]
pub fn is_const_trait(self, def_id: DefId) -> bool {
self.trait_def(def_id).constness == hir::Constness::Const
}
#[inline]
pub fn is_const_default_method(self, def_id: DefId) -> bool {
matches!(self.trait_of_item(def_id), Some(trait_id) if self.has_attr(trait_id, sym::const_trait))
matches!(self.trait_of_item(def_id), Some(trait_id) if self.is_const_trait(trait_id))
}
pub fn impl_method_has_trait_impl_trait_tys(self, def_id: DefId) -> bool {

View file

@ -18,6 +18,9 @@ pub struct TraitDef {
pub safety: hir::Safety,
/// Whether this trait has been annotated with `#[const_trait]`.
pub constness: hir::Constness,
/// If `true`, then this trait had the `#[rustc_paren_sugar]`
/// attribute, indicating that it should be used with `Foo()`
/// sugar. This is a temporary thing -- eventually any trait will