Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::iter;
use std::ops::ControlFlow;
use std::sync::Arc;

Expand Down Expand Up @@ -804,6 +805,37 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

pub(super) fn forward_inline(&mut self, _span: Span, outer_hir_id: HirId, inner_hir_id: HirId) {
let Some(attrs) = self.attrs.get(&outer_hir_id.local_id) else {
return;
};

let Some((inline_attr, span)) =
find_attr!(*attrs, AttributeKind::Inline(attr, span) => (attr, span))
else {
return;
};

let filtered_iter = attrs
.iter()
.cloned()
.filter(|attr| !matches!(attr, hir::Attribute::Parsed(AttributeKind::Inline(_, _))));

let filtered_attrs = self.arena.alloc_from_iter(filtered_iter);

if filtered_attrs.is_empty() {
self.attrs.remove(&outer_hir_id.local_id);
} else {
self.attrs.insert(outer_hir_id.local_id, filtered_attrs);
}

let attr = self.arena.alloc_from_iter(iter::once(hir::Attribute::Parsed(
AttributeKind::Inline(*inline_attr, *span),
)));

self.attrs.insert(inner_hir_id.local_id, attr);
}

/// Desugar `<expr>.await` into:
/// ```ignore (pseudo-rust)
/// match ::std::future::IntoFuture::into_future(<expr>) {
Expand Down Expand Up @@ -1167,6 +1199,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);

this.maybe_forward_track_caller(body.span, closure_hir_id, expr.hir_id);
this.forward_inline(body.span, closure_hir_id, expr.hir_id);

(parameters, expr)
});
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// FIXME(async_fn_track_caller): Can this be moved above?
let hir_id = expr.hir_id;
this.maybe_forward_track_caller(body.span, fn_id, hir_id);
this.forward_inline(body.span, fn_id, hir_id);

(parameters, expr)
})
Expand Down
Loading