Rollup merge of #72401 - ecstatic-morse:issue-72394, r=eddyb
Use correct function for detecting `const fn` in unsafety checking Resolves #72394.
This commit is contained in:
commit
401b3aefe9
@ -14,7 +14,7 @@ use rustc_span::symbol::{sym, Symbol};
|
||||
|
||||
use std::ops::Bound;
|
||||
|
||||
use crate::const_eval::{is_const_fn, is_min_const_fn};
|
||||
use crate::const_eval::is_min_const_fn;
|
||||
use crate::util;
|
||||
|
||||
pub struct UnsafetyChecker<'a, 'tcx> {
|
||||
@ -527,7 +527,7 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckRe
|
||||
let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) {
|
||||
hir::BodyOwnerKind::Closure => (false, false),
|
||||
hir::BodyOwnerKind::Fn => {
|
||||
(is_const_fn(tcx, def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
|
||||
(tcx.is_const_fn_raw(def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id()))
|
||||
}
|
||||
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false),
|
||||
};
|
||||
|
13
src/test/ui/unsafe/unsafe-unstable-const-fn.rs
Normal file
13
src/test/ui/unsafe/unsafe-unstable-const-fn.rs
Normal file
@ -0,0 +1,13 @@
|
||||
#![stable(feature = "foo", since = "1.33.0")]
|
||||
#![feature(staged_api)]
|
||||
#![feature(const_compare_raw_pointers)]
|
||||
#![feature(const_fn)]
|
||||
|
||||
#[stable(feature = "foo", since = "1.33.0")]
|
||||
#[rustc_const_unstable(feature = "const_foo", issue = "none")]
|
||||
const fn unstable(a: *const i32, b: *const i32) -> bool {
|
||||
a == b
|
||||
//~^ pointer operation is unsafe
|
||||
}
|
||||
|
||||
fn main() {}
|
11
src/test/ui/unsafe/unsafe-unstable-const-fn.stderr
Normal file
11
src/test/ui/unsafe/unsafe-unstable-const-fn.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0133]: pointer operation is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-unstable-const-fn.rs:9:5
|
||||
|
|
||||
LL | a == b
|
||||
| ^^^^^^ pointer operation
|
||||
|
|
||||
= note: operations on pointers in constants
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0133`.
|
Loading…
x
Reference in New Issue
Block a user