@@ -2359,14 +2359,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
23592359 }
23602360
23612361 fn future_proof_import ( & mut self , use_tree : & ast:: UseTree ) {
2362- if !self . session . rust_2018 ( ) {
2363- return ;
2364- }
2365-
23662362 let segments = & use_tree. prefix . segments ;
23672363 if !segments. is_empty ( ) {
23682364 let ident = segments[ 0 ] . ident ;
2369- if ident. is_path_segment_keyword ( ) {
2365+ if ident. is_path_segment_keyword ( ) || ident . span . rust_2015 ( ) {
23702366 return ;
23712367 }
23722368
@@ -3186,10 +3182,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
31863182
31873183 // Try to lookup the name in more relaxed fashion for better error reporting.
31883184 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) ;
31903186 if candidates. is_empty ( ) && is_expected ( Def :: Enum ( DefId :: local ( CRATE_DEF_INDEX ) ) ) {
31913187 let enum_candidates =
3192- this. lookup_import_candidates ( ident. name , ns, is_enum_variant) ;
3188+ this. lookup_import_candidates ( ident, ns, is_enum_variant) ;
31933189 let mut enum_candidates = enum_candidates. iter ( )
31943190 . map ( |suggestion| import_candidate_to_paths ( & suggestion) ) . collect :: < Vec < _ > > ( ) ;
31953191 enum_candidates. sort ( ) ;
@@ -3774,7 +3770,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
37743770 continue ;
37753771 }
37763772 if name == keywords:: Extern . name ( ) ||
3777- name == keywords:: CrateRoot . name ( ) && self . session . rust_2018 ( ) {
3773+ name == keywords:: CrateRoot . name ( ) && ident . span . rust_2018 ( ) {
37783774 module =
37793775 Some ( ModuleOrUniformRoot :: UniformRoot ( UniformRootKind :: ExternPrelude ) ) ;
37803776 continue ;
@@ -3877,7 +3873,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
38773873 let msg = if module_def == self . graph_root . def ( ) {
38783874 let is_mod = |def| match def { Def :: Mod ( ..) => true , _ => false } ;
38793875 let mut candidates =
3880- self . lookup_import_candidates ( name , TypeNS , is_mod) ;
3876+ self . lookup_import_candidates ( ident , TypeNS , is_mod) ;
38813877 candidates. sort_by_cached_key ( |c| {
38823878 ( c. path . segments . len ( ) , c. path . to_string ( ) )
38833879 } ) ;
@@ -3913,11 +3909,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
39133909 path_span : Span ,
39143910 second_binding : Option < & NameBinding > ,
39153911 ) {
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-
39213912 let ( diag_id, diag_span) = match crate_lint {
39223913 CrateLint :: No => return ,
39233914 CrateLint :: SimplePath ( id) => ( id, path_span) ,
@@ -3926,8 +3917,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
39263917 } ;
39273918
39283919 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 ,
39313923 } ;
39323924
39333925 // We're only interested in `use` paths which should start with
@@ -4509,7 +4501,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45094501 }
45104502
45114503 fn lookup_import_candidates_from_module < FilterFn > ( & mut self ,
4512- lookup_name : Name ,
4504+ lookup_ident : Ident ,
45134505 namespace : Namespace ,
45144506 start_module : & ' a ModuleData < ' a > ,
45154507 crate_name : Ident ,
@@ -4536,11 +4528,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45364528 if !name_binding. is_importable ( ) { return ; }
45374529
45384530 // collect results based on the filter function
4539- if ident. name == lookup_name && ns == namespace {
4531+ if ident. name == lookup_ident . name && ns == namespace {
45404532 if filter_fn ( name_binding. def ( ) ) {
45414533 // create the path
45424534 let mut segms = path_segments. clone ( ) ;
4543- if self . session . rust_2018 ( ) {
4535+ if lookup_ident . span . rust_2018 ( ) {
45444536 // crate-local absolute paths start with `crate::` in edition 2018
45454537 // FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
45464538 segms. insert (
@@ -4574,7 +4566,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45744566
45754567 let is_extern_crate_that_also_appears_in_prelude =
45764568 name_binding. is_extern_crate ( ) &&
4577- self . session . rust_2018 ( ) ;
4569+ lookup_ident . span . rust_2018 ( ) ;
45784570
45794571 let is_visible_to_user =
45804572 !in_module_is_extern || name_binding. vis == ty:: Visibility :: Public ;
@@ -4601,16 +4593,16 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
46014593 /// NOTE: The method does not look into imports, but this is not a problem,
46024594 /// since we report the definitions (thus, the de-aliased imports).
46034595 fn lookup_import_candidates < FilterFn > ( & mut self ,
4604- lookup_name : Name ,
4596+ lookup_ident : Ident ,
46054597 namespace : Namespace ,
46064598 filter_fn : FilterFn )
46074599 -> Vec < ImportSuggestion >
46084600 where FilterFn : Fn ( Def ) -> bool
46094601 {
46104602 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) ;
46124604
4613- if self . session . rust_2018 ( ) {
4605+ if lookup_ident . span . rust_2018 ( ) {
46144606 let extern_prelude_names = self . extern_prelude . clone ( ) ;
46154607 for ( ident, _) in extern_prelude_names. into_iter ( ) {
46164608 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> {
46224614 self . populate_module_if_necessary ( & crate_root) ;
46234615
46244616 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) ) ;
46264618 }
46274619 }
46284620 }
@@ -4714,19 +4706,26 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47144706 ast:: VisibilityKind :: Restricted { ref path, id, .. } => {
47154707 // For visibilities we are not ready to provide correct implementation of "uniform
47164708 // 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 ( ) {
47194715 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)
47214717 . span_suggestion ( path. span , "try" , format ! ( "crate::{}" , path) )
47224718 . emit ( ) ;
47234719 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 < _ > > ( ) ;
47304729 let def = self . smart_resolve_path_fragment (
47314730 id,
47324731 None ,
@@ -4839,7 +4838,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
48394838 help_msgs. push ( format ! ( "consider adding an explicit import of \
48404839 `{ident}` to disambiguate", ident = ident) )
48414840 }
4842- if b. is_extern_crate ( ) && self . session . rust_2018 ( ) {
4841+ if b. is_extern_crate ( ) && ident . span . rust_2018 ( ) {
48434842 help_msgs. push ( format ! ( "use `::{ident}` to refer to this {thing} unambiguously" ,
48444843 ident = ident, thing = b. descr( ) ) )
48454844 }
0 commit comments