Use FnSig instead of raw FnDecl for ForeignItemKind::Fn
This commit is contained in:
parent
a73bc4a131
commit
833af65f38
23 changed files with 113 additions and 98 deletions
|
@ -189,7 +189,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
) -> hir::FnSig<'hir> {
|
||||
let header = if let Some(local_sig_id) = sig_id.as_local() {
|
||||
match self.resolver.delegation_fn_sigs.get(&local_sig_id) {
|
||||
Some(sig) => self.lower_fn_header(sig.header),
|
||||
Some(sig) => self.lower_fn_header(sig.header, hir::Safety::Safe),
|
||||
None => self.generate_header_error(),
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -237,7 +237,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
});
|
||||
let sig = hir::FnSig {
|
||||
decl,
|
||||
header: this.lower_fn_header(*header),
|
||||
header: this.lower_fn_header(*header, hir::Safety::Safe),
|
||||
span: this.lower_span(*fn_sig_span),
|
||||
};
|
||||
hir::ItemKind::Fn(sig, generics, body_id)
|
||||
|
@ -668,7 +668,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
ForeignItemKind::Fn(box Fn { sig, generics, .. }) => {
|
||||
let fdec = &sig.decl;
|
||||
let itctx = ImplTraitContext::Universal;
|
||||
let (generics, (fn_dec, fn_args)) =
|
||||
let (generics, (decl, fn_args)) =
|
||||
self.lower_generics(generics, Const::No, false, i.id, itctx, |this| {
|
||||
(
|
||||
// Disallow `impl Trait` in foreign items.
|
||||
|
@ -682,9 +682,15 @@ 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, safety)
|
||||
// Unmarked safety in unsafe block defaults to unsafe.
|
||||
let header = self.lower_fn_header(sig.header, hir::Safety::Unsafe);
|
||||
|
||||
hir::ForeignItemKind::Fn(
|
||||
hir::FnSig { header, decl, span: self.lower_span(sig.span) },
|
||||
fn_args,
|
||||
generics,
|
||||
)
|
||||
}
|
||||
ForeignItemKind::Static(box StaticItem { ty, mutability, expr: _, safety }) => {
|
||||
let ty = self
|
||||
|
@ -1390,7 +1396,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
coroutine_kind: Option<CoroutineKind>,
|
||||
parent_constness: Const,
|
||||
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
|
||||
let header = self.lower_fn_header(sig.header);
|
||||
let header = self.lower_fn_header(sig.header, hir::Safety::Safe);
|
||||
// Don't pass along the user-provided constness of trait associated functions; we don't want to
|
||||
// synthesize a host effect param for them. We reject `const` on them during AST validation.
|
||||
let constness =
|
||||
|
@ -1403,14 +1409,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
|
||||
}
|
||||
|
||||
pub(super) fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader {
|
||||
pub(super) fn lower_fn_header(
|
||||
&mut self,
|
||||
h: FnHeader,
|
||||
default_safety: hir::Safety,
|
||||
) -> hir::FnHeader {
|
||||
let asyncness = if let Some(CoroutineKind::Async { span, .. }) = h.coroutine_kind {
|
||||
hir::IsAsync::Async(span)
|
||||
} else {
|
||||
hir::IsAsync::NotAsync
|
||||
};
|
||||
hir::FnHeader {
|
||||
safety: self.lower_safety(h.safety, hir::Safety::Safe),
|
||||
safety: self.lower_safety(h.safety, default_safety),
|
||||
asyncness: asyncness,
|
||||
constness: self.lower_constness(h.constness),
|
||||
abi: self.lower_extern(h.ext),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue