Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8ffb2f1
Do not use `gen` as binding name
estebank Jun 9, 2025
ce7480d
Add edition checks for some tests that had divergent output
estebank Jun 9, 2025
595e88a
Windows: make read_dir stop iterating on error
ChrisDenton Jun 13, 2025
e627f88
Implement pinned borrows, part of `pin_ergonomics`
frank-king Jan 19, 2025
2090f40
Move `tests/ui/async-await/pin-ergonomics` to `tests/ui`
frank-king Mar 16, 2025
afdb54a
Move the place in `&pin mut $place` when `!Unpin` to ensure soundness
frank-king Apr 4, 2025
5d16a7b
Avoid a bitcast FFI call in transmuting
scottmcm Jun 20, 2025
ba5556d
Add `#[loop_match]` for improved DFA codegen
bjorn3 Feb 18, 2025
c3200c3
Tweak `-Zmacro-stats` measurement.
nnethercote Jun 23, 2025
77232fb
Fix normalization in linker-warning
bjorn3 Jun 24, 2025
fcb718b
Fix function signature for rust_eh_personality
bjorn3 Jun 24, 2025
659da58
Fix a bunch of missing unwinder related definitions
bjorn3 Jun 24, 2025
943d379
Error on invalid signatures for interrupt ABIs
folkertdev Jun 16, 2025
84f92f3
rustdoc: Don't mark `#[target_feature]` functions as ⚠
aDotInTheVoid Jun 24, 2025
ad5d698
compiler: Trim the misleading C from ExternAbi::CCmse*
workingjubilee Jun 7, 2025
1080b57
Corrected spelling mistake in c_str.rs
MetaNova Jun 24, 2025
3583a41
compiler: remove misleading 'c' from `abi_c_cmse_nonsecure_call` feature
workingjubilee Jun 24, 2025
4ce1412
compiler: Trim the misleading C of C-cmse from errors
workingjubilee Jun 7, 2025
64c658f
tests: s/C-cmse/cmse/
workingjubilee Jun 7, 2025
b97282e
tests: bless s/C-cmse/cmse/
workingjubilee Jun 9, 2025
ea799ae
move unstable book page and account for it
workingjubilee Jun 24, 2025
b769c62
unstable-book: Update cmse feature descriptions
workingjubilee Jun 7, 2025
5d44fdd
Rewrite #[track_caller]
jdonszelmann Jun 21, 2025
40a33af
fix clippy
jdonszelmann Jun 21, 2025
f9cdf3f
fix 142783
jdonszelmann Jun 21, 2025
4c7f054
Enable short-ice for Windows
dpaoliello Jun 21, 2025
4a112db
Update wasm-component-ld to 0.5.14
alexcrichton Jun 24, 2025
041fbe8
Update cargo
ehuss Jun 25, 2025
02e9952
Rollup merge of #135731 - frank-king:feature/pin-borrow, r=eholk,trav…
workingjubilee Jun 25, 2025
7854342
Rollup merge of #138780 - trifectatechfoundation:loop_match_attr, r=o…
workingjubilee Jun 25, 2025
bb145c2
Rollup merge of #142146 - workingjubilee:doubt-that-cmse-nonsecure-ab…
workingjubilee Jun 25, 2025
571b58b
Rollup merge of #142255 - estebank:edition-diagnostic-changes, r=fee1…
workingjubilee Jun 25, 2025
6479091
Rollup merge of #142453 - ChrisDenton:fused, r=Amanieu
workingjubilee Jun 25, 2025
13ff5de
Rollup merge of #142633 - folkertdev:interrupt-abi-restrict-signature…
workingjubilee Jun 25, 2025
a30de99
Rollup merge of #142768 - scottmcm:avoid-unneeded-bitcast, r=WaffleLa…
workingjubilee Jun 25, 2025
30a3d29
Rollup merge of #142825 - jdonszelmann:track-caller, r=oli-obk
workingjubilee Jun 25, 2025
25d6fb3
Rollup merge of #142844 - dpaoliello:short-ice, r=jieyouxu
workingjubilee Jun 25, 2025
de25e6e
Rollup merge of #142934 - nnethercote:tweak-macro-stats, r=petrochenkov
workingjubilee Jun 25, 2025
12529eb
Rollup merge of #142955 - bjorn3:cg_clif_test_fixes, r=jieyouxu
workingjubilee Jun 25, 2025
b9c5ed9
Rollup merge of #142977 - aDotInTheVoid:rustdochtml-targetfeature, r=…
workingjubilee Jun 25, 2025
cef8ef1
Rollup merge of #142982 - MetaNova:patch-1, r=jhpratt
workingjubilee Jun 25, 2025
6c6eb37
Rollup merge of #142988 - alexcrichton:update-wasm-component-ld, r=Ma…
workingjubilee Jun 25, 2025
d6c0d37
Rollup merge of #142993 - ehuss:update-cargo, r=ehuss
workingjubilee Jun 25, 2025
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
Prev Previous commit
Next Next commit
Rewrite #[track_caller]
  • Loading branch information
jdonszelmann committed Jun 24, 2025
commit 5d44fdd972ee555b499c21068a03a5b3d88b1c7e
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,7 @@ dependencies = [
"rustc_abi",
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr_data_structures",
"rustc_attr_parsing",
"rustc_data_structures",
"rustc_errors",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_lowering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ doctest = false
rustc_abi = { path = "../rustc_abi" }
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr_data_structures = { path = "../rustc_attr_data_structures" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::sync::Arc;
use rustc_ast::ptr::P as AstP;
use rustc_ast::*;
use rustc_ast_pretty::pprust::expr_to_string;
use rustc_attr_data_structures::{AttributeKind, find_attr};
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir as hir;
use rustc_hir::HirId;
Expand Down Expand Up @@ -831,7 +832,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
) {
if self.tcx.features().async_fn_track_caller()
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
&& attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
&& find_attr!(*attrs, AttributeKind::TrackCaller(_))
{
let unstable_span = self.mark_span_with_reason(
DesugaringKind::Async,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,8 @@ pub enum AttributeKind {
/// Span of the attribute.
span: Span,
},

/// Represents `#[track_caller]`
TrackCaller(Span),
// tidy-alphabetical-end
}
24 changes: 21 additions & 3 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_attr_data_structures::{AttributeKind, OptimizeAttr};
use rustc_feature::{AttributeTemplate, template};
use rustc_session::parse::feature_err;
use rustc_span::{Span, sym};
use rustc_span::{Span, Symbol, sym};

use super::{AcceptMapping, AttributeOrder, AttributeParser, OnDuplicate, SingleAttributeParser};
use crate::context::{AcceptContext, FinalizeContext, Stage};
Expand All @@ -11,7 +11,7 @@ use crate::session_diagnostics::NakedFunctionIncompatibleAttribute;
pub(crate) struct OptimizeParser;

impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
const PATH: &[rustc_span::Symbol] = &[sym::optimize];
const PATH: &[Symbol] = &[sym::optimize];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none");
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
pub(crate) struct ColdParser;

impl<S: Stage> SingleAttributeParser<S> for ColdParser {
const PATH: &[rustc_span::Symbol] = &[sym::cold];
const PATH: &[Symbol] = &[sym::cold];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
const TEMPLATE: AttributeTemplate = template!(Word);
Expand Down Expand Up @@ -166,6 +166,24 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
}
}

pub(crate) struct TrackCallerParser;

impl<S: Stage> SingleAttributeParser<S> for TrackCallerParser {
const PATH: &[Symbol] = &[sym::track_caller];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
const TEMPLATE: AttributeTemplate = template!(Word);

fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
if let Err(span) = args.no_args() {
cx.expected_no_args(span);
return None;
}

Some(AttributeKind::TrackCaller(cx.attr_span))
}
}

pub(crate) struct NoMangleParser;

impl<S: Stage> SingleAttributeParser<S> for NoMangleParser {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use rustc_session::Session;
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};

use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
use crate::attributes::codegen_attrs::{ColdParser, NakedParser, NoMangleParser, OptimizeParser};
use crate::attributes::codegen_attrs::{
ColdParser, NakedParser, NoMangleParser, OptimizeParser, TrackCallerParser,
};
use crate::attributes::confusables::ConfusablesParser;
use crate::attributes::deprecation::DeprecationParser;
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
Expand Down Expand Up @@ -121,6 +123,7 @@ attribute_parsers!(
Single<PubTransparentParser>,
Single<RustcForceInlineParser>,
Single<SkipDuringMethodDispatchParser>,
Single<TrackCallerParser>,
Single<TransparencyParser>,
// tidy-alphabetical-end
];
Expand Down
54 changes: 26 additions & 28 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,15 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
// In these cases, we bail from performing further checks that are only meaningful for
// functions (such as calling `fn_sig`, which ICEs if given a non-function). We also
// report a delayed bug, just in case `check_attr` isn't doing its job.
let fn_sig = || {
let fn_sig = |attr_span| {
use DefKind::*;

let def_kind = tcx.def_kind(did);
if let Fn | AssocFn | Variant | Ctor(..) = def_kind {
Some(tcx.fn_sig(did))
} else {
tcx.dcx().span_delayed_bug(
attr.span(),
"this attribute can only be applied to functions",
);
tcx.dcx()
.span_delayed_bug(attr_span, "this attribute can only be applied to functions");
None
}
};
Expand Down Expand Up @@ -142,6 +140,29 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
});
}
}
AttributeKind::TrackCaller(attr_span) => {
let is_closure = tcx.is_closure_like(did.to_def_id());

if !is_closure
&& let Some(fn_sig) = fn_sig(*attr_span)
&& fn_sig.skip_binder().abi() != ExternAbi::Rust
{
tcx.dcx().emit_err(errors::RequiresRustAbi { span: *attr_span });
}
if is_closure
&& !tcx.features().closure_track_caller()
&& !attr_span.allows_unstable(sym::closure_track_caller)
{
feature_err(
&tcx.sess,
sym::closure_track_caller,
*attr_span,
"`#[track_caller]` on closures is currently unstable",
)
.emit();
}
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER
}
_ => {}
}
}
Expand Down Expand Up @@ -202,29 +223,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
}
}
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
sym::track_caller => {
let is_closure = tcx.is_closure_like(did.to_def_id());

if !is_closure
&& let Some(fn_sig) = fn_sig()
&& fn_sig.skip_binder().abi() != ExternAbi::Rust
{
tcx.dcx().emit_err(errors::RequiresRustAbi { span: attr.span() });
}
if is_closure
&& !tcx.features().closure_track_caller()
&& !attr.span().allows_unstable(sym::closure_track_caller)
{
feature_err(
&tcx.sess,
sym::closure_track_caller,
attr.span(),
"`#[track_caller]` on closures is currently unstable",
)
.emit();
}
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER
}
sym::export_name => {
if let Some(s) = attr.value_str() {
if s.as_str().contains('\0') {
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_hir_analysis/src/check/entry.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use std::ops::Not;

use rustc_abi::ExternAbi;
use rustc_attr_data_structures::{AttributeKind, find_attr};
use rustc_hir as hir;
use rustc_hir::Node;
use rustc_infer::infer::TyCtxtInferExt;
use rustc_middle::span_bug;
use rustc_middle::ty::{self, TyCtxt, TypingMode};
use rustc_session::config::EntryFnType;
use rustc_span::Span;
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
use rustc_span::{Span, sym};
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode};

Expand Down Expand Up @@ -98,8 +99,10 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
error = true;
}

for attr in tcx.get_attrs(main_def_id, sym::track_caller) {
tcx.dcx().emit_err(errors::TrackCallerOnMain { span: attr.span(), annotated: main_span });
if let Some(attr_span) =
find_attr!(tcx.get_all_attrs(main_def_id), AttributeKind::TrackCaller(span) => *span)
{
tcx.dcx().emit_err(errors::TrackCallerOnMain { span: attr_span, annotated: main_span });
error = true;
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,11 +1184,11 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
if fn_kind.asyncness().is_async()
&& !cx.tcx.features().async_fn_track_caller()
// Now, check if the function has the `#[track_caller]` attribute
&& let Some(attr) = cx.tcx.get_attr(def_id, sym::track_caller)
&& let Some(attr_span) = find_attr!(cx.tcx.get_all_attrs(def_id), AttributeKind::TrackCaller(span) => *span)
{
cx.emit_span_lint(
UNGATED_ASYNC_FN_TRACK_CALLER,
attr.span(),
attr_span,
BuiltinUngatedAsyncFnTrackCaller { label: span, session: &cx.tcx.sess },
);
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ fn emit_malformed_attribute(
| sym::naked
| sym::no_mangle
| sym::must_use
| sym::track_caller
) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Attribute::Parsed(AttributeKind::Naked(attr_span)) => {
self.check_naked(hir_id, *attr_span, span, target)
}
Attribute::Parsed(AttributeKind::TrackCaller(attr_span)) => {
self.check_track_caller(hir_id, *attr_span, attrs, span, target)
}
Attribute::Parsed(
AttributeKind::BodyStability { .. }
| AttributeKind::ConstStabilityIndirect
Expand Down Expand Up @@ -205,9 +208,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_target_feature(hir_id, attr, span, target, attrs)
}
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
[sym::track_caller, ..] => {
self.check_track_caller(hir_id, attr.span(), attrs, span, target)
}
[sym::doc, ..] => self.check_doc_attrs(
attr,
attr_item.style,
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/lint/unused/unused-attr-duplicate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ note: attribute also specified here
LL | #[automatically_derived]
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: unused attribute
--> $DIR/unused-attr-duplicate.rs:79:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unused-attr-duplicate.rs:78:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^

error: unused attribute
--> $DIR/unused-attr-duplicate.rs:92:1
|
Expand Down Expand Up @@ -277,6 +265,18 @@ note: attribute also specified here
LL | #[cold]
| ^^^^^^^

error: unused attribute
--> $DIR/unused-attr-duplicate.rs:79:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unused-attr-duplicate.rs:78:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^

error: unused attribute
--> $DIR/unused-attr-duplicate.rs:98:1
|
Expand Down