1
Fork 0

Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726

Rename Unsafe to Safety

Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks.

This leaves us today with:

```rust
enum ast::Safety {
    Unsafe(Span),
    Default,
    // Safe (going to be added for unsafe extern blocks)
}

enum hir::Safety {
    Unsafe,
    Safe,
}
```

We would convert from `ast::Safety::Default` into the right Safety level according the context.
This commit is contained in:
bors 2024-05-18 19:35:24 +00:00
commit eb1a5c9bb3
115 changed files with 460 additions and 494 deletions

View file

@ -1053,8 +1053,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
// ^^^^^^
values.0.push(sig1.unsafety.prefix_str(), sig1.unsafety != sig2.unsafety);
values.1.push(sig2.unsafety.prefix_str(), sig1.unsafety != sig2.unsafety);
values.0.push(sig1.safety.prefix_str(), sig1.safety != sig2.safety);
values.1.push(sig2.safety.prefix_str(), sig1.safety != sig2.safety);
// unsafe extern "C" for<'a> fn(&'a T) -> &'a T
// ^^^^^^^^^^
@ -1928,7 +1928,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
self.tcx
.signature_unclosure(
args.as_closure().sig(),
rustc_hir::Unsafety::Normal,
rustc_hir::Safety::Safe,
)
.to_string(),
),

View file

@ -168,7 +168,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ClosureEraser<'tcx> {
let closure_sig = args.as_closure().sig();
Ty::new_fn_ptr(
self.tcx,
self.tcx.signature_unclosure(closure_sig, hir::Unsafety::Normal),
self.tcx.signature_unclosure(closure_sig, hir::Safety::Safe),
)
}
_ => ty.super_fold_with(self),

View file

@ -409,10 +409,8 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
{
let closure_sig = self_ty.map(|closure| {
if let ty::Closure(_, args) = closure.kind() {
self.tcx().signature_unclosure(
args.as_closure().sig(),
rustc_hir::Unsafety::Normal,
)
self.tcx()
.signature_unclosure(args.as_closure().sig(), rustc_hir::Safety::Safe)
} else {
bug!("type is not longer closure");
}

View file

@ -452,7 +452,7 @@ impl<T> Trait<T> for X {
}
(ty::FnPtr(sig), ty::FnDef(def_id, _))
| (ty::FnDef(def_id, _), ty::FnPtr(sig)) => {
if tcx.fn_sig(def_id).skip_binder().unsafety() < sig.unsafety() {
if tcx.fn_sig(def_id).skip_binder().safety() < sig.safety() {
diag.note(
"unsafe functions cannot be coerced into safe function pointers",
);