Explain unsafety trickery of const functions
This commit is contained in:
parent
b75d5f1867
commit
932dbe816e
1 changed files with 14 additions and 5 deletions
|
|
@ -114,11 +114,20 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t
|
|||
hir::Unsafety::Normal => Safety::Safe,
|
||||
hir::Unsafety::Unsafe => Safety::FnUnsafe,
|
||||
};
|
||||
let safety = if implicit_argument.is_none() && tcx.is_min_const_fn(fn_def_id) {
|
||||
// the body of `const unsafe fn`s is treated like the body of safe `const fn`s
|
||||
Safety::Safe
|
||||
} else {
|
||||
safety
|
||||
|
||||
let safety = match fn_sig.unsafety {
|
||||
hir::Unsafety::Normal => Safety::Safe,
|
||||
hir::Unsafety::Unsafe => {
|
||||
if tcx.is_min_const_fn(fn_def_id) => {
|
||||
// As specified in #55607, a `const unsafe fn` differs
|
||||
// from an `unsafe fn` in that its body is still considered
|
||||
// safe code by default.
|
||||
assert!(!implicit_argument.is_none());
|
||||
Safety::Safe
|
||||
} else {
|
||||
Safety::Unsafe
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let body = tcx.hir.body(body_id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue