@@ -2359,14 +2359,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2359
2359
}
2360
2360
2361
2361
fn future_proof_import ( & mut self , use_tree : & ast:: UseTree ) {
2362
- if !self . session . rust_2018 ( ) {
2363
- return ;
2364
- }
2365
-
2366
2362
let segments = & use_tree. prefix . segments ;
2367
2363
if !segments. is_empty ( ) {
2368
2364
let ident = segments[ 0 ] . ident ;
2369
- if ident. is_path_segment_keyword ( ) {
2365
+ if ident. is_path_segment_keyword ( ) || ident . span . rust_2015 ( ) {
2370
2366
return ;
2371
2367
}
2372
2368
@@ -3186,10 +3182,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3186
3182
3187
3183
// Try to lookup the name in more relaxed fashion for better error reporting.
3188
3184
let ident = path. last ( ) . unwrap ( ) . ident ;
3189
- let candidates = this. lookup_import_candidates ( ident. name , ns, is_expected) ;
3185
+ let candidates = this. lookup_import_candidates ( ident, ns, is_expected) ;
3190
3186
if candidates. is_empty ( ) && is_expected ( Def :: Enum ( DefId :: local ( CRATE_DEF_INDEX ) ) ) {
3191
3187
let enum_candidates =
3192
- this. lookup_import_candidates ( ident. name , ns, is_enum_variant) ;
3188
+ this. lookup_import_candidates ( ident, ns, is_enum_variant) ;
3193
3189
let mut enum_candidates = enum_candidates. iter ( )
3194
3190
. map ( |suggestion| import_candidate_to_paths ( & suggestion) ) . collect :: < Vec < _ > > ( ) ;
3195
3191
enum_candidates. sort ( ) ;
@@ -3774,7 +3770,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3774
3770
continue ;
3775
3771
}
3776
3772
if name == keywords:: Extern . name ( ) ||
3777
- name == keywords:: CrateRoot . name ( ) && self . session . rust_2018 ( ) {
3773
+ name == keywords:: CrateRoot . name ( ) && ident . span . rust_2018 ( ) {
3778
3774
module =
3779
3775
Some ( ModuleOrUniformRoot :: UniformRoot ( UniformRootKind :: ExternPrelude ) ) ;
3780
3776
continue ;
@@ -3877,7 +3873,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3877
3873
let msg = if module_def == self . graph_root . def ( ) {
3878
3874
let is_mod = |def| match def { Def :: Mod ( ..) => true , _ => false } ;
3879
3875
let mut candidates =
3880
- self . lookup_import_candidates ( name , TypeNS , is_mod) ;
3876
+ self . lookup_import_candidates ( ident , TypeNS , is_mod) ;
3881
3877
candidates. sort_by_cached_key ( |c| {
3882
3878
( c. path . segments . len ( ) , c. path . to_string ( ) )
3883
3879
} ) ;
@@ -3913,11 +3909,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3913
3909
path_span : Span ,
3914
3910
second_binding : Option < & NameBinding > ,
3915
3911
) {
3916
- // In the 2018 edition this lint is a hard error, so nothing to do
3917
- if self . session . rust_2018 ( ) {
3918
- return
3919
- }
3920
-
3921
3912
let ( diag_id, diag_span) = match crate_lint {
3922
3913
CrateLint :: No => return ,
3923
3914
CrateLint :: SimplePath ( id) => ( id, path_span) ,
@@ -3926,8 +3917,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3926
3917
} ;
3927
3918
3928
3919
let first_name = match path. get ( 0 ) {
3929
- Some ( ident) => ident. ident . name ,
3930
- None => return ,
3920
+ // In the 2018 edition this lint is a hard error, so nothing to do
3921
+ Some ( seg) if seg. ident . span . rust_2015 ( ) => seg. ident . name ,
3922
+ _ => return ,
3931
3923
} ;
3932
3924
3933
3925
// We're only interested in `use` paths which should start with
@@ -4509,7 +4501,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4509
4501
}
4510
4502
4511
4503
fn lookup_import_candidates_from_module < FilterFn > ( & mut self ,
4512
- lookup_name : Name ,
4504
+ lookup_ident : Ident ,
4513
4505
namespace : Namespace ,
4514
4506
start_module : & ' a ModuleData < ' a > ,
4515
4507
crate_name : Ident ,
@@ -4536,11 +4528,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4536
4528
if !name_binding. is_importable ( ) { return ; }
4537
4529
4538
4530
// collect results based on the filter function
4539
- if ident. name == lookup_name && ns == namespace {
4531
+ if ident. name == lookup_ident . name && ns == namespace {
4540
4532
if filter_fn ( name_binding. def ( ) ) {
4541
4533
// create the path
4542
4534
let mut segms = path_segments. clone ( ) ;
4543
- if self . session . rust_2018 ( ) {
4535
+ if lookup_ident . span . rust_2018 ( ) {
4544
4536
// crate-local absolute paths start with `crate::` in edition 2018
4545
4537
// FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
4546
4538
segms. insert (
@@ -4574,7 +4566,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4574
4566
4575
4567
let is_extern_crate_that_also_appears_in_prelude =
4576
4568
name_binding. is_extern_crate ( ) &&
4577
- self . session . rust_2018 ( ) ;
4569
+ lookup_ident . span . rust_2018 ( ) ;
4578
4570
4579
4571
let is_visible_to_user =
4580
4572
!in_module_is_extern || name_binding. vis == ty:: Visibility :: Public ;
@@ -4601,16 +4593,16 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4601
4593
/// NOTE: The method does not look into imports, but this is not a problem,
4602
4594
/// since we report the definitions (thus, the de-aliased imports).
4603
4595
fn lookup_import_candidates < FilterFn > ( & mut self ,
4604
- lookup_name : Name ,
4596
+ lookup_ident : Ident ,
4605
4597
namespace : Namespace ,
4606
4598
filter_fn : FilterFn )
4607
4599
-> Vec < ImportSuggestion >
4608
4600
where FilterFn : Fn ( Def ) -> bool
4609
4601
{
4610
4602
let mut suggestions = self . lookup_import_candidates_from_module (
4611
- lookup_name , namespace, self . graph_root , keywords:: Crate . ident ( ) , & filter_fn) ;
4603
+ lookup_ident , namespace, self . graph_root , keywords:: Crate . ident ( ) , & filter_fn) ;
4612
4604
4613
- if self . session . rust_2018 ( ) {
4605
+ if lookup_ident . span . rust_2018 ( ) {
4614
4606
let extern_prelude_names = self . extern_prelude . clone ( ) ;
4615
4607
for ( ident, _) in extern_prelude_names. into_iter ( ) {
4616
4608
if let Some ( crate_id) = self . crate_loader . maybe_process_path_extern ( ident. name ,
@@ -4622,7 +4614,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4622
4614
self . populate_module_if_necessary ( & crate_root) ;
4623
4615
4624
4616
suggestions. extend ( self . lookup_import_candidates_from_module (
4625
- lookup_name , namespace, crate_root, ident, & filter_fn) ) ;
4617
+ lookup_ident , namespace, crate_root, ident, & filter_fn) ) ;
4626
4618
}
4627
4619
}
4628
4620
}
@@ -4714,19 +4706,26 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4714
4706
ast:: VisibilityKind :: Restricted { ref path, id, .. } => {
4715
4707
// For visibilities we are not ready to provide correct implementation of "uniform
4716
4708
// paths" right now, so on 2018 edition we only allow module-relative paths for now.
4717
- let first_ident = path. segments [ 0 ] . ident ;
4718
- if self . session . rust_2018 ( ) && !first_ident. is_path_segment_keyword ( ) {
4709
+ // On 2015 edition visibilities are resolved as crate-relative by default,
4710
+ // so we are prepending a root segment if necessary.
4711
+ let ident = path. segments . get ( 0 ) . expect ( "empty path in visibility" ) . ident ;
4712
+ let crate_root = if ident. is_path_segment_keyword ( ) {
4713
+ None
4714
+ } else if ident. span . rust_2018 ( ) {
4719
4715
let msg = "relative paths are not supported in visibilities on 2018 edition" ;
4720
- self . session . struct_span_err ( first_ident . span , msg)
4716
+ self . session . struct_span_err ( ident . span , msg)
4721
4717
. span_suggestion ( path. span , "try" , format ! ( "crate::{}" , path) )
4722
4718
. emit ( ) ;
4723
4719
return ty:: Visibility :: Public ;
4724
- }
4725
- // On 2015 visibilities are resolved as crate-relative by default,
4726
- // add starting root segment if necessary.
4727
- let segments = path. make_root ( ) . iter ( ) . chain ( path. segments . iter ( ) )
4728
- . map ( |seg| Segment { ident : seg. ident , id : Some ( seg. id ) } )
4729
- . collect :: < Vec < _ > > ( ) ;
4720
+ } else {
4721
+ let ctxt = ident. span . ctxt ( ) ;
4722
+ Some ( Segment :: from_ident ( Ident :: new (
4723
+ keywords:: CrateRoot . name ( ) , path. span . shrink_to_lo ( ) . with_ctxt ( ctxt)
4724
+ ) ) )
4725
+ } ;
4726
+
4727
+ let segments = crate_root. into_iter ( )
4728
+ . chain ( path. segments . iter ( ) . map ( |seg| seg. into ( ) ) ) . collect :: < Vec < _ > > ( ) ;
4730
4729
let def = self . smart_resolve_path_fragment (
4731
4730
id,
4732
4731
None ,
@@ -4839,7 +4838,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4839
4838
help_msgs. push ( format ! ( "consider adding an explicit import of \
4840
4839
`{ident}` to disambiguate", ident = ident) )
4841
4840
}
4842
- if b. is_extern_crate ( ) && self . session . rust_2018 ( ) {
4841
+ if b. is_extern_crate ( ) && ident . span . rust_2018 ( ) {
4843
4842
help_msgs. push ( format ! ( "use `::{ident}` to refer to this {thing} unambiguously" ,
4844
4843
ident = ident, thing = b. descr( ) ) )
4845
4844
}
0 commit comments