File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
compiler/rustc_middle/src/middle
tests/ui/rfcs/rfc-2091-track-caller Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,28 @@ impl<'tcx> TyCtxt<'tcx> {
2424 }
2525 }
2626
27+ // A shim created by `#[track_caller]` should not inherit any attributes
28+ // that modify the symbol name. Failing to remove these attributes from
29+ // the shim leads to errors like `symbol `foo` is already defined`.
30+ //
31+ // A `ClosureOnceShim` with the track_caller attribute does not have a symbol,
32+ // and therefore can be skipped here.
33+ if let InstanceKind :: ReifyShim ( _, _) = instance_kind
34+ && attrs. flags . contains ( CodegenFnAttrFlags :: TRACK_CALLER )
35+ {
36+ if attrs. flags . contains ( CodegenFnAttrFlags :: NO_MANGLE ) {
37+ attrs. to_mut ( ) . flags . remove ( CodegenFnAttrFlags :: NO_MANGLE ) ;
38+ }
39+
40+ if attrs. flags . contains ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ) {
41+ attrs. to_mut ( ) . flags . remove ( CodegenFnAttrFlags :: RUSTC_STD_INTERNAL_SYMBOL ) ;
42+ }
43+
44+ if attrs. symbol_name . is_some ( ) {
45+ attrs. to_mut ( ) . symbol_name = None ;
46+ }
47+ }
48+
2749 attrs
2850 }
2951}
Original file line number Diff line number Diff line change 1+ //@ run-pass
2+ #![ feature( rustc_attrs) ]
3+
4+ // The shim that is generated for a function annotated with `#[track_caller]` should not inherit
5+ // attributes that modify its symbol name. Failing to remove these attributes from the shim
6+ // leads to errors like `symbol `foo` is already defined`.
7+ //
8+ // See also https://github.com/rust-lang/rust/issues/143162.
9+
10+ #[ unsafe( no_mangle) ]
11+ #[ track_caller]
12+ pub fn foo ( ) { }
13+
14+ #[ unsafe( export_name = "bar" ) ]
15+ #[ track_caller]
16+ pub fn bar ( ) { }
17+
18+ #[ rustc_std_internal_symbol]
19+ #[ track_caller]
20+ pub fn baz ( ) { }
21+
22+ fn main ( ) {
23+ let _a = foo as fn ( ) ;
24+ let _b = bar as fn ( ) ;
25+ let _c = baz as fn ( ) ;
26+ }
You can’t perform that action at this time.
0 commit comments