@@ -24,13 +24,14 @@ use Resolver;
2424use { resolve_error, resolve_struct_error, ResolutionError } ;
2525
2626use rustc:: middle:: cstore:: { CrateStore , ChildItem , DlDef } ;
27+ use rustc:: lint;
2728use rustc:: middle:: def:: * ;
2829use rustc:: middle:: def_id:: { CRATE_DEF_INDEX , DefId } ;
2930use rustc:: ty:: VariantKind ;
3031
3132use syntax:: ast:: { Name , NodeId } ;
3233use syntax:: attr:: AttrMetaMethods ;
33- use syntax:: parse:: token:: special_idents;
34+ use syntax:: parse:: token:: { special_idents, SELF_KEYWORD_NAME , SUPER_KEYWORD_NAME } ;
3435use syntax:: codemap:: { Span , DUMMY_SP } ;
3536
3637use rustc_front:: hir;
@@ -117,8 +118,10 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
117118 // Extract and intern the module part of the path. For
118119 // globs and lists, the path is found directly in the AST;
119120 // for simple paths we have to munge the path a little.
120- let module_path = match view_path. node {
121+ let is_global;
122+ let module_path: Vec < Name > = match view_path. node {
121123 ViewPathSimple ( _, ref full_path) => {
124+ is_global = full_path. global ;
122125 full_path. segments
123126 . split_last ( )
124127 . unwrap ( )
@@ -130,13 +133,26 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
130133
131134 ViewPathGlob ( ref module_ident_path) |
132135 ViewPathList ( ref module_ident_path, _) => {
136+ is_global = module_ident_path. global ;
133137 module_ident_path. segments
134138 . iter ( )
135139 . map ( |seg| seg. identifier . name )
136140 . collect ( )
137141 }
138142 } ;
139143
144+ // Checking for special identifiers in path
145+ // prevent `self` or `super` at beginning of global path
146+ if is_global && ( module_path. first ( ) == Some ( & SELF_KEYWORD_NAME ) ||
147+ module_path. first ( ) == Some ( & SUPER_KEYWORD_NAME ) ) {
148+ self . session . add_lint (
149+ lint:: builtin:: SUPER_OR_SELF_IN_GLOBAL_PATH ,
150+ item. id ,
151+ item. span ,
152+ format ! ( "expected identifier, found keyword `{}`" ,
153+ module_path. first( ) . unwrap( ) . as_str( ) ) ) ;
154+ }
155+
140156 // Build up the import directives.
141157 let is_prelude = item. attrs . iter ( ) . any ( |attr| {
142158 attr. name ( ) == special_idents:: prelude_import. name . as_str ( )
0 commit comments