Handle safety keyword for extern block inner items
This commit is contained in:
parent
bbddc9b58f
commit
2a377122dd
52 changed files with 168 additions and 84 deletions
|
@ -388,7 +388,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(*s)),
|
||||
};
|
||||
hir::ItemKind::Impl(self.arena.alloc(hir::Impl {
|
||||
safety: self.lower_safety(*safety),
|
||||
safety: self.lower_safety(*safety, hir::Safety::Safe),
|
||||
polarity,
|
||||
defaultness,
|
||||
defaultness_span,
|
||||
|
@ -418,7 +418,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
let items = this.arena.alloc_from_iter(
|
||||
items.iter().map(|item| this.lower_trait_item_ref(item)),
|
||||
);
|
||||
let safety = this.lower_safety(*safety);
|
||||
let safety = this.lower_safety(*safety, hir::Safety::Safe);
|
||||
(safety, items, bounds)
|
||||
},
|
||||
);
|
||||
|
@ -660,13 +660,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
this.lower_fn_params_to_names(fdec),
|
||||
)
|
||||
});
|
||||
let safety = self.lower_safety(sig.header.safety, hir::Safety::Unsafe);
|
||||
|
||||
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
|
||||
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics, safety)
|
||||
}
|
||||
ForeignItemKind::Static(box StaticForeignItem { ty, mutability, expr: _ }) => {
|
||||
ForeignItemKind::Static(box StaticForeignItem {
|
||||
ty,
|
||||
mutability,
|
||||
expr: _,
|
||||
safety,
|
||||
}) => {
|
||||
let ty = self
|
||||
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
|
||||
hir::ForeignItemKind::Static(ty, *mutability)
|
||||
let safety = self.lower_safety(*safety, hir::Safety::Unsafe);
|
||||
|
||||
hir::ForeignItemKind::Static(ty, *mutability, safety)
|
||||
}
|
||||
ForeignItemKind::TyAlias(..) => hir::ForeignItemKind::Type,
|
||||
ForeignItemKind::MacCall(_) => panic!("macro shouldn't exist here"),
|
||||
|
@ -1360,7 +1368,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
hir::IsAsync::NotAsync
|
||||
};
|
||||
hir::FnHeader {
|
||||
safety: self.lower_safety(h.safety),
|
||||
safety: self.lower_safety(h.safety, hir::Safety::Safe),
|
||||
asyncness: asyncness,
|
||||
constness: self.lower_constness(h.constness),
|
||||
abi: self.lower_extern(h.ext),
|
||||
|
@ -1410,10 +1418,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(super) fn lower_safety(&mut self, s: Safety) -> hir::Safety {
|
||||
pub(super) fn lower_safety(&mut self, s: Safety, default: hir::Safety) -> hir::Safety {
|
||||
match s {
|
||||
Safety::Unsafe(_) => hir::Safety::Unsafe,
|
||||
Safety::Default => hir::Safety::Safe,
|
||||
Safety::Default => default,
|
||||
Safety::Safe(_) => hir::Safety::Safe,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1321,7 +1321,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params);
|
||||
hir::TyKind::BareFn(self.arena.alloc(hir::BareFnTy {
|
||||
generic_params,
|
||||
safety: self.lower_safety(f.safety),
|
||||
safety: self.lower_safety(f.safety, hir::Safety::Safe),
|
||||
abi: self.lower_extern(f.ext),
|
||||
decl: self.lower_fn_decl(&f.decl, t.id, t.span, FnDeclKind::Pointer, None),
|
||||
param_names: self.lower_fn_params_to_names(&f.decl),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue