@@ -100,9 +100,10 @@ use rustc_hir::Node;
100
100
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
101
101
use rustc_middle:: mir:: mono:: { InstantiationMode , MonoItem } ;
102
102
use rustc_middle:: ty:: query:: Providers ;
103
- use rustc_middle:: ty:: subst:: SubstsRef ;
104
- use rustc_middle:: ty:: { self , Instance , Ty , TyCtxt } ;
103
+ use rustc_middle:: ty:: subst:: { InternalSubsts , SubstsRef } ;
104
+ use rustc_middle:: ty:: { self , Instance , InstanceDef , Ty , TyCtxt , WithOptConstParam } ;
105
105
use rustc_session:: config:: SymbolManglingVersion ;
106
+ use rustc_span:: def_id:: DefId ;
106
107
use rustc_target:: abi:: call:: FnAbi ;
107
108
108
109
use tracing:: debug;
@@ -124,13 +125,46 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
124
125
}
125
126
126
127
pub fn provide ( providers : & mut Providers ) {
127
- * providers = Providers { symbol_name : symbol_name_provider, ..* providers } ;
128
+ * providers = Providers {
129
+ symbol_name : symbol_name_provider,
130
+ symbol_name_for_plain_item : symbol_name_for_plain_item_provider,
131
+ ..* providers
132
+ } ;
133
+ }
134
+
135
+ fn symbol_name_for_plain_item_provider < ' tcx > (
136
+ tcx : TyCtxt < ' tcx > ,
137
+ def_id : DefId ,
138
+ ) -> ty:: SymbolName < ' tcx > {
139
+ symbol_name_provider_body (
140
+ tcx,
141
+ Instance {
142
+ def : InstanceDef :: Item ( WithOptConstParam :: unknown ( def_id) ) ,
143
+ substs : InternalSubsts :: empty ( ) ,
144
+ } ,
145
+ )
146
+ }
147
+
148
+ fn symbol_name_provider < ' tcx > ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> ty:: SymbolName < ' tcx > {
149
+ if let Instance {
150
+ def : InstanceDef :: Item ( WithOptConstParam { did : def_id, const_param_did : None } ) ,
151
+ substs,
152
+ } = instance
153
+ {
154
+ if substs. is_empty ( ) {
155
+ return tcx. symbol_name_for_plain_item ( def_id) ;
156
+ }
157
+ }
158
+ symbol_name_provider_body ( tcx, instance)
128
159
}
129
160
130
161
// The `symbol_name` query provides the symbol name for calling a given
131
162
// instance from the local crate. In particular, it will also look up the
132
163
// correct symbol name of instances from upstream crates.
133
- fn symbol_name_provider < ' tcx > ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> ty:: SymbolName < ' tcx > {
164
+ fn symbol_name_provider_body < ' tcx > (
165
+ tcx : TyCtxt < ' tcx > ,
166
+ instance : Instance < ' tcx > ,
167
+ ) -> ty:: SymbolName < ' tcx > {
134
168
let symbol_name = compute_symbol_name ( tcx, instance, || {
135
169
// This closure determines the instantiating crate for instances that
136
170
// need an instantiating-crate-suffix for their symbol name, in order
0 commit comments