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