diff options
| author | bors <bors@rust-lang.org> | 2024-07-09 06:51:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-09 06:51:35 +0000 |
| commit | 5be2ec7245de6e8015a0daedf24d20e3e5bf2062 (patch) | |
| tree | d6dbc424f2d3f400c49b2ee30a713228dcde18c5 /compiler/rustc_middle/src | |
| parent | cd3d98b3bef709c1f42b1964ba7a3ea371f95773 (diff) | |
| parent | 46af9870727abe142963c9873e960242188dbaab (diff) | |
| download | rust-5be2ec7245de6e8015a0daedf24d20e3e5bf2062.tar.gz rust-5be2ec7245de6e8015a0daedf24d20e3e5bf2062.zip | |
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
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/trait_def.rs | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 4470db47474..e1bd3ad8ad3 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1968,8 +1968,13 @@ impl<'tcx> TyCtxt<'tcx> { } #[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 { diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index 076a74ca6f8..da5860043c9 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -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 |
