@@ -21,7 +21,6 @@ use rustc::session::Session;
2121use syntax:: ast:: * ;
2222use syntax:: attr;
2323use syntax:: codemap:: Spanned ;
24- use syntax:: symbol:: keywords;
2524use syntax:: visit:: { self , Visitor } ;
2625use syntax_pos:: Span ;
2726use errors;
@@ -35,8 +34,16 @@ impl<'a> AstValidator<'a> {
3534 & self . session . parse_sess . span_diagnostic
3635 }
3736
37+ fn check_lifetime ( & self , lifetime : & Lifetime ) {
38+ if !lifetime. ident . without_first_quote ( ) . is_valid ( ) &&
39+ !lifetime. ident . name . is_static_keyword ( ) {
40+ self . err_handler ( ) . span_err ( lifetime. span , "lifetimes cannot use keyword names" ) ;
41+ }
42+ }
43+
3844 fn check_label ( & self , label : Ident , span : Span ) {
39- if label. name == keywords:: StaticLifetime . name ( ) || label. name == "'_" {
45+ if label. name . is_static_keyword ( ) || !label. without_first_quote ( ) . is_valid ( )
46+ || label. name == "'_" {
4047 self . err_handler ( ) . span_err ( span, & format ! ( "invalid label name `{}`" , label. name) ) ;
4148 }
4249 }
@@ -202,19 +209,21 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
202209
203210 fn visit_item ( & mut self , item : & ' a Item ) {
204211 match item. node {
205- ItemKind :: Impl ( .., Some ( ..) , _, ref impl_items) => {
212+ ItemKind :: Impl ( .., ref generics , Some ( ..) , _, ref impl_items) => {
206213 self . invalid_visibility ( & item. vis , item. span , None ) ;
207214 for impl_item in impl_items {
208215 self . invalid_visibility ( & impl_item. vis , impl_item. span , None ) ;
209216 if let ImplItemKind :: Method ( ref sig, _) = impl_item. node {
210217 self . check_trait_fn_not_const ( sig. constness ) ;
211218 }
212219 }
220+ generics. lifetimes . iter ( ) . for_each ( |l| self . check_lifetime ( & l. lifetime ) )
213221 }
214- ItemKind :: Impl ( .., None , _, _) => {
222+ ItemKind :: Impl ( .., ref generics , None , _, _) => {
215223 self . invalid_visibility ( & item. vis ,
216224 item. span ,
217225 Some ( "place qualifiers on individual impl items instead" ) ) ;
226+ generics. lifetimes . iter ( ) . for_each ( |l| self . check_lifetime ( & l. lifetime ) )
218227 }
219228 ItemKind :: AutoImpl ( ..) => {
220229 self . invalid_visibility ( & item. vis , item. span , None ) ;
@@ -225,13 +234,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
225234 Some ( "place qualifiers on individual foreign items \
226235 instead") ) ;
227236 }
228- ItemKind :: Enum ( ref def, _ ) => {
237+ ItemKind :: Enum ( ref def, ref generics ) => {
229238 for variant in & def. variants {
230239 self . invalid_non_exhaustive_attribute ( variant) ;
231240 for field in variant. node . data . fields ( ) {
232241 self . invalid_visibility ( & field. vis , field. span , None ) ;
233242 }
234243 }
244+ generics. lifetimes . iter ( ) . for_each ( |l| self . check_lifetime ( & l. lifetime ) )
235245 }
236246 ItemKind :: Trait ( is_auto, _, ref generics, ref bounds, ref trait_items) => {
237247 if is_auto == IsAuto :: Yes {
@@ -268,6 +278,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
268278 }
269279 }
270280 }
281+ generics. lifetimes . iter ( ) . for_each ( |l| self . check_lifetime ( & l. lifetime ) )
271282 }
272283 ItemKind :: Mod ( _) => {
273284 // Ensure that `path` attributes on modules are recorded as used (c.f. #35584).
@@ -278,7 +289,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
278289 self . session . buffer_lint ( lint, item. id , item. span , msg) ;
279290 }
280291 }
281- ItemKind :: Union ( ref vdata, _ ) => {
292+ ItemKind :: Union ( ref vdata, ref generics ) => {
282293 if !vdata. is_struct ( ) {
283294 self . err_handler ( ) . span_err ( item. span ,
284295 "tuple and unit unions are not permitted" ) ;
@@ -287,6 +298,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
287298 self . err_handler ( ) . span_err ( item. span ,
288299 "unions cannot have zero fields" ) ;
289300 }
301+ generics. lifetimes . iter ( ) . for_each ( |l| self . check_lifetime ( & l. lifetime ) )
302+ }
303+ ItemKind :: Fn ( .., ref generics, _) |
304+ ItemKind :: Ty ( _, ref generics) |
305+ ItemKind :: Struct ( _, ref generics) => {
306+ generics. lifetimes . iter ( ) . for_each ( |l| self . check_lifetime ( & l. lifetime ) )
290307 }
291308 _ => { }
292309 }
0 commit comments