Skip to content

Commit 5f06ce2

Browse files
Prevent const trait methods from being marked stable
1 parent cb81712 commit 5f06ce2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/librustc_mir/transform/qualify_min_const_fn.rs

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ use std::borrow::Cow;
1010
type McfResult = Result<(), (Span, Cow<'static, str>)>;
1111

1212
pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -> McfResult {
13+
// Prevent const trait methods from being annotated as `stable`.
14+
if tcx.features().staged_api {
15+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
16+
if crate::const_eval::is_parent_const_impl_raw(tcx, hir_id) {
17+
return Err((body.span, "trait methods cannot be stable const fn".into()));
18+
}
19+
}
20+
1321
let mut current = def_id;
1422
loop {
1523
let predicates = tcx.predicates_of(current);

0 commit comments

Comments
 (0)