1
Fork 0

Proper const stability check, default to unstable

Rather than deferring to const eval for checking if a trait is const, we
now check up-front. This allows the error to be emitted earlier, notably
at the same time as other stability checks.

Also included in this commit is a change of the default const stability
level to UNstable. Previously, an item that was `const` but did not
explicitly state it was unstable was implicitly stable.
This commit is contained in:
Jacob Pratt 2022-02-13 05:54:00 -05:00 committed by Oli Scherer
parent a9dd4cfa6b
commit f0620c9503
16 changed files with 196 additions and 93 deletions

View file

@ -2808,6 +2808,21 @@ impl<'tcx> TyCtxt<'tcx> {
false
}
}
/// Whether the trait impl is marked const. This does not consider stability or feature gates.
pub fn is_const_trait_impl_raw(self, def_id: DefId) -> bool {
let Some(local_def_id) = def_id.as_local() else { return false };
let hir_id = self.local_def_id_to_hir_id(local_def_id);
let node = self.hir().get(hir_id);
matches!(
node,
hir::Node::Item(hir::Item {
kind: hir::ItemKind::Impl(hir::Impl { constness: hir::Constness::Const, .. }),
..
})
)
}
}
impl<'tcx> TyCtxtAt<'tcx> {