@@ -10,6 +10,7 @@ use crate::hir::def_id::DefId;
10
10
11
11
use rustc_data_structures:: fx:: FxHashSet ;
12
12
use rustc_data_structures:: sync:: Lrc ;
13
+ use rustc_errors:: Applicability ;
13
14
use rustc_hir as hir;
14
15
use rustc_hir:: def:: Namespace ;
15
16
use rustc_infer:: infer:: canonical:: OriginalQueryValues ;
@@ -1167,7 +1168,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1167
1168
//
1168
1169
// We suppress warning if we're picking the method only because it is a
1169
1170
// suggestion.
1170
- self . emit_unstable_name_collision_hint ( p, & unstable_candidates) ;
1171
+ self . emit_unstable_name_collision_hint ( p, & unstable_candidates, self_ty ) ;
1171
1172
}
1172
1173
}
1173
1174
return Some ( pick) ;
@@ -1246,24 +1247,46 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1246
1247
& self ,
1247
1248
stable_pick : & Pick < ' _ > ,
1248
1249
unstable_candidates : & [ ( & Candidate < ' tcx > , Symbol ) ] ,
1250
+ self_ty : Ty < ' tcx > ,
1249
1251
) {
1250
1252
self . tcx . struct_span_lint_hir (
1251
1253
lint:: builtin:: UNSTABLE_NAME_COLLISIONS ,
1252
1254
self . fcx . body_id ,
1253
1255
self . span ,
1254
1256
|lint| {
1255
- let mut diag = lint. build (
1256
- "a method with this name may be added to the standard library in the future" ,
1257
- ) ;
1258
- // FIXME: This should be a `span_suggestion` instead of `help`
1259
- // However `self.span` only
1260
- // highlights the method name, so we can't use it. Also consider reusing the code from
1261
- // `report_method_error()`.
1262
- diag. help ( & format ! (
1263
- "call with fully qualified syntax `{}(...)` to keep using the current method" ,
1264
- self . tcx. def_path_str( stable_pick. item. def_id) ,
1257
+ let def_kind = stable_pick. item . kind . as_def_kind ( ) ;
1258
+ let mut diag = lint. build ( & format ! (
1259
+ "{} {} with this name may be added to the standard library in the future" ,
1260
+ def_kind. article( ) ,
1261
+ def_kind. descr( stable_pick. item. def_id) ,
1265
1262
) ) ;
1266
-
1263
+ match ( stable_pick. item . kind , stable_pick. item . container ) {
1264
+ ( ty:: AssocKind :: Fn , _) => {
1265
+ // FIXME: This should be a `span_suggestion` instead of `help`
1266
+ // However `self.span` only
1267
+ // highlights the method name, so we can't use it. Also consider reusing
1268
+ // the code from `report_method_error()`.
1269
+ diag. help ( & format ! (
1270
+ "call with fully qualified syntax `{}(...)` to keep using the current \
1271
+ method",
1272
+ self . tcx. def_path_str( stable_pick. item. def_id) ,
1273
+ ) ) ;
1274
+ }
1275
+ ( ty:: AssocKind :: Const , ty:: AssocItemContainer :: TraitContainer ( def_id) ) => {
1276
+ diag. span_suggestion (
1277
+ self . span ,
1278
+ "use the fully qualified path to the associated const" ,
1279
+ format ! (
1280
+ "<{} as {}>::{}" ,
1281
+ self_ty,
1282
+ self . tcx. def_path_str( def_id) ,
1283
+ stable_pick. item. ident
1284
+ ) ,
1285
+ Applicability :: MachineApplicable ,
1286
+ ) ;
1287
+ }
1288
+ _ => { }
1289
+ }
1267
1290
if self . tcx . sess . is_nightly_build ( ) {
1268
1291
for ( candidate, feature) in unstable_candidates {
1269
1292
diag. help ( & format ! (
0 commit comments