@@ -83,8 +83,6 @@ struct ProbeContext<'a, 'tcx> {
83
83
unsatisfied_predicates :
84
84
Vec < ( ty:: Predicate < ' tcx > , Option < ty:: Predicate < ' tcx > > , Option < ObligationCause < ' tcx > > ) > ,
85
85
86
- is_suggestion : IsSuggestion ,
87
-
88
86
scope_expr_id : hir:: HirId ,
89
87
}
90
88
@@ -209,6 +207,9 @@ pub struct Pick<'tcx> {
209
207
/// `*mut T`, convert it to `*const T`.
210
208
pub autoref_or_ptr_adjustment : Option < AutorefOrPtrAdjustment > ,
211
209
pub self_ty : Ty < ' tcx > ,
210
+
211
+ /// Unstable candidates alongside the stable ones.
212
+ unstable_candidates : Vec < ( Candidate < ' tcx > , Symbol ) > ,
212
213
}
213
214
214
215
#[ derive( Clone , Debug , PartialEq , Eq ) ]
@@ -445,7 +446,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
445
446
return_type,
446
447
orig_values,
447
448
steps. steps ,
448
- is_suggestion,
449
449
scope_expr_id,
450
450
) ;
451
451
@@ -540,7 +540,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
540
540
return_type : Option < Ty < ' tcx > > ,
541
541
orig_steps_var_values : OriginalQueryValues < ' tcx > ,
542
542
steps : & ' tcx [ CandidateStep < ' tcx > ] ,
543
- is_suggestion : IsSuggestion ,
544
543
scope_expr_id : hir:: HirId ,
545
544
) -> ProbeContext < ' a , ' tcx > {
546
545
ProbeContext {
@@ -558,7 +557,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
558
557
allow_similar_names : false ,
559
558
private_candidate : None ,
560
559
unsatisfied_predicates : Vec :: new ( ) ,
561
- is_suggestion,
562
560
scope_expr_id,
563
561
}
564
562
}
@@ -880,7 +878,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
880
878
}
881
879
}
882
880
883
- pub fn matches_return_type (
881
+ fn matches_return_type (
884
882
& self ,
885
883
method : & ty:: AssocItem ,
886
884
self_ty : Option < Ty < ' tcx > > ,
@@ -1051,26 +1049,17 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1051
1049
}
1052
1050
1053
1051
fn pick_core ( & mut self ) -> Option < PickResult < ' tcx > > {
1054
- let mut unstable_candidates = Vec :: new ( ) ;
1055
- let pick = self . pick_all_method ( Some ( & mut unstable_candidates) ) ;
1052
+ let pick = self . pick_all_method ( Some ( & mut vec ! [ ] ) ) ;
1056
1053
1057
1054
// In this case unstable picking is done by `pick_method`.
1058
1055
if !self . tcx . sess . opts . unstable_opts . pick_stable_methods_before_any_unstable {
1059
1056
return pick;
1060
1057
}
1061
1058
1062
- match pick {
1063
- // Emit a lint if there are unstable candidates alongside the stable ones.
1064
- //
1065
- // We suppress warning if we're picking the method only because it is a
1066
- // suggestion.
1067
- Some ( Ok ( ref p) ) if !self . is_suggestion . 0 && !unstable_candidates. is_empty ( ) => {
1068
- self . emit_unstable_name_collision_hint ( p, & unstable_candidates) ;
1069
- pick
1070
- }
1071
- Some ( _) => pick,
1072
- None => self . pick_all_method ( None ) ,
1059
+ if pick. is_none ( ) {
1060
+ return self . pick_all_method ( None ) ;
1073
1061
}
1062
+ pick
1074
1063
}
1075
1064
1076
1065
fn pick_all_method (
@@ -1215,7 +1204,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1215
1204
debug ! ( "pick_method_with_unstable(self_ty={})" , self . ty_to_string( self_ty) ) ;
1216
1205
1217
1206
let mut possibly_unsatisfied_predicates = Vec :: new ( ) ;
1218
- let mut unstable_candidates = Vec :: new ( ) ;
1219
1207
1220
1208
for ( kind, candidates) in
1221
1209
& [ ( "inherent" , & self . inherent_candidates ) , ( "extension" , & self . extension_candidates ) ]
@@ -1225,26 +1213,17 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1225
1213
self_ty,
1226
1214
candidates. iter ( ) ,
1227
1215
& mut possibly_unsatisfied_predicates,
1228
- Some ( & mut unstable_candidates ) ,
1216
+ Some ( & mut vec ! [ ] ) ,
1229
1217
) ;
1230
- if let Some ( pick) = res {
1231
- if !self . is_suggestion . 0 && !unstable_candidates. is_empty ( ) {
1232
- if let Ok ( p) = & pick {
1233
- // Emit a lint if there are unstable candidates alongside the stable ones.
1234
- //
1235
- // We suppress warning if we're picking the method only because it is a
1236
- // suggestion.
1237
- self . emit_unstable_name_collision_hint ( p, & unstable_candidates) ;
1238
- }
1239
- }
1240
- return Some ( pick) ;
1218
+ if res. is_some ( ) {
1219
+ return res;
1241
1220
}
1242
1221
}
1243
1222
1244
1223
debug ! ( "searching unstable candidates" ) ;
1245
1224
let res = self . consider_candidates (
1246
1225
self_ty,
1247
- unstable_candidates . iter ( ) . map ( | ( c , _ ) | c ) ,
1226
+ self . inherent_candidates . iter ( ) . chain ( & self . extension_candidates ) ,
1248
1227
& mut possibly_unsatisfied_predicates,
1249
1228
None ,
1250
1229
) ;
@@ -1299,7 +1278,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1299
1278
Option < ty:: Predicate < ' tcx > > ,
1300
1279
Option < ObligationCause < ' tcx > > ,
1301
1280
) > ,
1302
- unstable_candidates : Option < & mut Vec < ( Candidate < ' tcx > , Symbol ) > > ,
1281
+ mut unstable_candidates : Option < & mut Vec < ( Candidate < ' tcx > , Symbol ) > > ,
1303
1282
) -> Option < PickResult < ' tcx > >
1304
1283
where
1305
1284
ProbesIter : Iterator < Item = & ' b Candidate < ' tcx > > + Clone ,
@@ -1323,7 +1302,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1323
1302
}
1324
1303
}
1325
1304
1326
- if let Some ( uc) = unstable_candidates {
1305
+ if let Some ( uc) = & mut unstable_candidates {
1327
1306
applicable_candidates. retain ( |& ( p, _) | {
1328
1307
if let stability:: EvalResult :: Deny { feature, .. } =
1329
1308
self . tcx . eval_stability ( p. item . def_id , None , self . span , None )
@@ -1342,30 +1321,37 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1342
1321
1343
1322
applicable_candidates. pop ( ) . map ( |( probe, status) | {
1344
1323
if status == ProbeResult :: Match {
1345
- Ok ( probe. to_unadjusted_pick ( self_ty) )
1324
+ Ok ( probe
1325
+ . to_unadjusted_pick ( self_ty, unstable_candidates. cloned ( ) . unwrap_or_default ( ) ) )
1346
1326
} else {
1347
1327
Err ( MethodError :: BadReturnType )
1348
1328
}
1349
1329
} )
1350
1330
}
1331
+ }
1351
1332
1352
- fn emit_unstable_name_collision_hint (
1333
+ impl < ' tcx > Pick < ' tcx > {
1334
+ pub fn emit_unstable_name_collision_hint (
1353
1335
& self ,
1354
- stable_pick : & Pick < ' _ > ,
1355
- unstable_candidates : & [ ( Candidate < ' tcx > , Symbol ) ] ,
1336
+ tcx : TyCtxt < ' tcx > ,
1337
+ span : Span ,
1338
+ scope_expr_id : hir:: HirId ,
1356
1339
) {
1357
- let def_kind = stable_pick. item . kind . as_def_kind ( ) ;
1358
- self . tcx . struct_span_lint_hir (
1340
+ if self . unstable_candidates . is_empty ( ) {
1341
+ return ;
1342
+ }
1343
+ let def_kind = self . item . kind . as_def_kind ( ) ;
1344
+ tcx. struct_span_lint_hir (
1359
1345
lint:: builtin:: UNSTABLE_NAME_COLLISIONS ,
1360
- self . scope_expr_id ,
1361
- self . span ,
1346
+ scope_expr_id,
1347
+ span,
1362
1348
format ! (
1363
1349
"{} {} with this name may be added to the standard library in the future" ,
1364
1350
def_kind. article( ) ,
1365
- def_kind. descr( stable_pick . item. def_id) ,
1351
+ def_kind. descr( self . item. def_id) ,
1366
1352
) ,
1367
1353
|lint| {
1368
- match ( stable_pick . item . kind , stable_pick . item . container ) {
1354
+ match ( self . item . kind , self . item . container ) {
1369
1355
( ty:: AssocKind :: Fn , _) => {
1370
1356
// FIXME: This should be a `span_suggestion` instead of `help`
1371
1357
// However `self.span` only
@@ -1374,31 +1360,31 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1374
1360
lint. help ( & format ! (
1375
1361
"call with fully qualified syntax `{}(...)` to keep using the current \
1376
1362
method",
1377
- self . tcx. def_path_str( stable_pick . item. def_id) ,
1363
+ tcx. def_path_str( self . item. def_id) ,
1378
1364
) ) ;
1379
1365
}
1380
1366
( ty:: AssocKind :: Const , ty:: AssocItemContainer :: TraitContainer ) => {
1381
- let def_id = stable_pick . item . container_id ( self . tcx ) ;
1367
+ let def_id = self . item . container_id ( tcx) ;
1382
1368
lint. span_suggestion (
1383
- self . span ,
1369
+ span,
1384
1370
"use the fully qualified path to the associated const" ,
1385
1371
format ! (
1386
1372
"<{} as {}>::{}" ,
1387
- stable_pick . self_ty,
1388
- self . tcx. def_path_str( def_id) ,
1389
- stable_pick . item. name
1373
+ self . self_ty,
1374
+ tcx. def_path_str( def_id) ,
1375
+ self . item. name
1390
1376
) ,
1391
1377
Applicability :: MachineApplicable ,
1392
1378
) ;
1393
1379
}
1394
1380
_ => { }
1395
1381
}
1396
- if self . tcx . sess . is_nightly_build ( ) {
1397
- for ( candidate, feature) in unstable_candidates {
1382
+ if tcx. sess . is_nightly_build ( ) {
1383
+ for ( candidate, feature) in & self . unstable_candidates {
1398
1384
lint. help ( & format ! (
1399
1385
"add `#![feature({})]` to the crate attributes to enable `{}`" ,
1400
1386
feature,
1401
- self . tcx. def_path_str( candidate. item. def_id) ,
1387
+ tcx. def_path_str( candidate. item. def_id) ,
1402
1388
) ) ;
1403
1389
}
1404
1390
}
@@ -1407,7 +1393,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1407
1393
} ,
1408
1394
) ;
1409
1395
}
1396
+ }
1410
1397
1398
+ impl < ' a , ' tcx > ProbeContext < ' a , ' tcx > {
1411
1399
fn select_trait_candidate (
1412
1400
& self ,
1413
1401
trait_ref : ty:: TraitRef < ' tcx > ,
@@ -1666,6 +1654,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1666
1654
autoderefs : 0 ,
1667
1655
autoref_or_ptr_adjustment : None ,
1668
1656
self_ty,
1657
+ unstable_candidates : vec ! [ ] ,
1669
1658
} )
1670
1659
}
1671
1660
@@ -1685,7 +1674,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1685
1674
self . return_type ,
1686
1675
self . orig_steps_var_values . clone ( ) ,
1687
1676
steps,
1688
- IsSuggestion ( true ) ,
1689
1677
self . scope_expr_id ,
1690
1678
) ;
1691
1679
pcx. allow_similar_names = true ;
@@ -1893,7 +1881,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1893
1881
}
1894
1882
1895
1883
impl < ' tcx > Candidate < ' tcx > {
1896
- fn to_unadjusted_pick ( & self , self_ty : Ty < ' tcx > ) -> Pick < ' tcx > {
1884
+ fn to_unadjusted_pick (
1885
+ & self ,
1886
+ self_ty : Ty < ' tcx > ,
1887
+ unstable_candidates : Vec < ( Candidate < ' tcx > , Symbol ) > ,
1888
+ ) -> Pick < ' tcx > {
1897
1889
Pick {
1898
1890
item : self . item ,
1899
1891
kind : match self . kind {
@@ -1918,6 +1910,7 @@ impl<'tcx> Candidate<'tcx> {
1918
1910
autoderefs : 0 ,
1919
1911
autoref_or_ptr_adjustment : None ,
1920
1912
self_ty,
1913
+ unstable_candidates,
1921
1914
}
1922
1915
}
1923
1916
}
0 commit comments