Skip to content

Commit

Permalink
Rollup merge of #72401 - ecstatic-morse:issue-72394, r=eddyb
Browse files Browse the repository at this point in the history
Use correct function for detecting `const fn` in unsafety checking

Resolves #72394.
  • Loading branch information
Dylan-DPC authored May 26, 2020
2 parents e38fdda + 09619bc commit 401b3ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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),
};
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/unsafe/unsafe-unstable-const-fn.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions src/test/ui/unsafe/unsafe-unstable-const-fn.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 401b3ae

Please sign in to comment.