Skip to content

Commit 401b3ae

Browse files
authored
Rollup merge of rust-lang#72401 - ecstatic-morse:issue-72394, r=eddyb
Use correct function for detecting `const fn` in unsafety checking Resolves rust-lang#72394.
2 parents e38fdda + 09619bc commit 401b3ae

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/librustc_mir/transform/check_unsafety.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_span::symbol::{sym, Symbol};
1414

1515
use std::ops::Bound;
1616

17-
use crate::const_eval::{is_const_fn, is_min_const_fn};
17+
use crate::const_eval::is_min_const_fn;
1818
use crate::util;
1919

2020
pub struct UnsafetyChecker<'a, 'tcx> {
@@ -527,7 +527,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckRe
527527
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
528528
hir::BodyOwnerKind::Closure => (false, false),
529529
hir::BodyOwnerKind::Fn => {
530-
(is_const_fn(tcx, def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
530+
(tcx.is_const_fn_raw(def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
531531
}
532532
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false),
533533
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![stable(feature = "foo", since = "1.33.0")]
2+
#![feature(staged_api)]
3+
#![feature(const_compare_raw_pointers)]
4+
#![feature(const_fn)]
5+
6+
#[stable(feature = "foo", since = "1.33.0")]
7+
#[rustc_const_unstable(feature = "const_foo", issue = "none")]
8+
const fn unstable(a: *const i32, b: *const i32) -> bool {
9+
a == b
10+
//~^ pointer operation is unsafe
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0133]: pointer operation is unsafe and requires unsafe function or block
2+
--> $DIR/unsafe-unstable-const-fn.rs:9:5
3+
|
4+
LL | a == b
5+
| ^^^^^^ pointer operation
6+
|
7+
= note: operations on pointers in constants
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0133`.

0 commit comments

Comments
 (0)