@@ -2354,14 +2354,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
23542354 }
23552355
23562356 fn future_proof_import ( & mut self , use_tree : & ast:: UseTree ) {
2357- if !self . session . rust_2018 ( ) {
2358- return ;
2359- }
2360-
23612357 let segments = & use_tree. prefix . segments ;
23622358 if !segments. is_empty ( ) {
23632359 let ident = segments[ 0 ] . ident ;
2364- if ident. is_path_segment_keyword ( ) {
2360+ if ident. is_path_segment_keyword ( ) || ident . span . rust_2015 ( ) {
23652361 return ;
23662362 }
23672363
@@ -3181,10 +3177,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
31813177
31823178 // Try to lookup the name in more relaxed fashion for better error reporting.
31833179 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) ;
31853181 if candidates. is_empty ( ) && is_expected ( Def :: Enum ( DefId :: local ( CRATE_DEF_INDEX ) ) ) {
31863182 let enum_candidates =
3187- this. lookup_import_candidates ( ident. name , ns, is_enum_variant) ;
3183+ this. lookup_import_candidates ( ident, ns, is_enum_variant) ;
31883184 let mut enum_candidates = enum_candidates. iter ( )
31893185 . map ( |suggestion| import_candidate_to_paths ( & suggestion) ) . collect :: < Vec < _ > > ( ) ;
31903186 enum_candidates. sort ( ) ;
@@ -3772,7 +3768,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
37723768 continue ;
37733769 }
37743770 if name == keywords:: Extern . name ( ) ||
3775- name == keywords:: CrateRoot . name ( ) && self . session . rust_2018 ( ) {
3771+ name == keywords:: CrateRoot . name ( ) && ident . span . rust_2018 ( ) {
37763772 module =
37773773 Some ( ModuleOrUniformRoot :: UniformRoot ( UniformRootKind :: ExternPrelude ) ) ;
37783774 continue ;
@@ -3875,7 +3871,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
38753871 let msg = if module_def == self . graph_root . def ( ) {
38763872 let is_mod = |def| match def { Def :: Mod ( ..) => true , _ => false } ;
38773873 let mut candidates =
3878- self . lookup_import_candidates ( name , TypeNS , is_mod) ;
3874+ self . lookup_import_candidates ( ident , TypeNS , is_mod) ;
38793875 candidates. sort_by_cached_key ( |c| {
38803876 ( c. path . segments . len ( ) , c. path . to_string ( ) )
38813877 } ) ;
@@ -3911,11 +3907,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
39113907 path_span : Span ,
39123908 second_binding : Option < & NameBinding > ,
39133909 ) {
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-
39193910 let ( diag_id, diag_span) = match crate_lint {
39203911 CrateLint :: No => return ,
39213912 CrateLint :: SimplePath ( id) => ( id, path_span) ,
@@ -3924,8 +3915,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
39243915 } ;
39253916
39263917 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 ,
39293921 } ;
39303922
39313923 // We're only interested in `use` paths which should start with
@@ -4507,7 +4499,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45074499 }
45084500
45094501 fn lookup_import_candidates_from_module < FilterFn > ( & mut self ,
4510- lookup_name : Name ,
4502+ lookup_ident : Ident ,
45114503 namespace : Namespace ,
45124504 start_module : & ' a ModuleData < ' a > ,
45134505 crate_name : Ident ,
@@ -4534,11 +4526,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45344526 if !name_binding. is_importable ( ) { return ; }
45354527
45364528 // collect results based on the filter function
4537- if ident. name == lookup_name && ns == namespace {
4529+ if ident. name == lookup_ident . name && ns == namespace {
45384530 if filter_fn ( name_binding. def ( ) ) {
45394531 // create the path
45404532 let mut segms = path_segments. clone ( ) ;
4541- if self . session . rust_2018 ( ) {
4533+ if lookup_ident . span . rust_2018 ( ) {
45424534 // crate-local absolute paths start with `crate::` in edition 2018
45434535 // FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
45444536 segms. insert (
@@ -4572,7 +4564,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45724564
45734565 let is_extern_crate_that_also_appears_in_prelude =
45744566 name_binding. is_extern_crate ( ) &&
4575- self . session . rust_2018 ( ) ;
4567+ lookup_ident . span . rust_2018 ( ) ;
45764568
45774569 let is_visible_to_user =
45784570 !in_module_is_extern || name_binding. vis == ty:: Visibility :: Public ;
@@ -4599,16 +4591,16 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
45994591 /// NOTE: The method does not look into imports, but this is not a problem,
46004592 /// since we report the definitions (thus, the de-aliased imports).
46014593 fn lookup_import_candidates < FilterFn > ( & mut self ,
4602- lookup_name : Name ,
4594+ lookup_ident : Ident ,
46034595 namespace : Namespace ,
46044596 filter_fn : FilterFn )
46054597 -> Vec < ImportSuggestion >
46064598 where FilterFn : Fn ( Def ) -> bool
46074599 {
46084600 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) ;
46104602
4611- if self . session . rust_2018 ( ) {
4603+ if lookup_ident . span . rust_2018 ( ) {
46124604 let extern_prelude_names = self . extern_prelude . clone ( ) ;
46134605 for ( ident, _) in extern_prelude_names. into_iter ( ) {
46144606 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> {
46204612 self . populate_module_if_necessary ( & crate_root) ;
46214613
46224614 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) ) ;
46244616 }
46254617 }
46264618 }
@@ -4712,19 +4704,26 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47124704 ast:: VisibilityKind :: Restricted { ref path, id, .. } => {
47134705 // For visibilities we are not ready to provide correct implementation of "uniform
47144706 // 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 ( ) {
47174713 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)
47194715 . span_suggestion ( path. span , "try" , format ! ( "crate::{}" , path) )
47204716 . emit ( ) ;
47214717 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 < _ > > ( ) ;
47284727 let def = self . smart_resolve_path_fragment (
47294728 id,
47304729 None ,
@@ -4837,7 +4836,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
48374836 help_msgs. push ( format ! ( "consider adding an explicit import of \
48384837 `{ident}` to disambiguate", ident = ident) )
48394838 }
4840- if b. is_extern_crate ( ) && self . session . rust_2018 ( ) {
4839+ if b. is_extern_crate ( ) && ident . span . rust_2018 ( ) {
48414840 help_msgs. push ( format ! ( "use `::{ident}` to refer to this {thing} unambiguously" ,
48424841 ident = ident, thing = b. descr( ) ) )
48434842 }
0 commit comments