@@ -35,7 +35,8 @@ use syntax::ast::Expr;
3535use syntax:: attr;
3636use syntax:: source_map:: Spanned ;
3737use syntax:: edition:: Edition ;
38- use syntax:: feature_gate:: { AttributeGate , AttributeType , Stability , deprecated_attributes} ;
38+ use syntax:: feature_gate:: { AttributeGate , AttributeTemplate , AttributeType } ;
39+ use syntax:: feature_gate:: { Stability , deprecated_attributes} ;
3940use syntax_pos:: { BytePos , Span , SyntaxContext } ;
4041use syntax:: symbol:: keywords;
4142use syntax:: errors:: { Applicability , DiagnosticBuilder } ;
@@ -682,86 +683,12 @@ impl EarlyLintPass for AnonymousParameters {
682683 }
683684}
684685
685- /// Checks for incorrect use of `repr` attributes.
686- #[ derive( Clone ) ]
687- pub struct BadRepr ;
688-
689- impl LintPass for BadRepr {
690- fn get_lints ( & self ) -> LintArray {
691- lint_array ! ( )
692- }
693- }
694-
695- impl EarlyLintPass for BadRepr {
696- fn check_attribute ( & mut self , cx : & EarlyContext , attr : & ast:: Attribute ) {
697- if attr. name ( ) == "repr" {
698- let list = attr. meta_item_list ( ) ;
699-
700- let repr_str = |lit : & str | { format ! ( "#[repr({})]" , lit) } ;
701-
702- // Emit warnings with `repr` either has a literal assignment (`#[repr = "C"]`) or
703- // no hints (``#[repr]`)
704- let has_hints = list. as_ref ( ) . map ( |ref list| !list. is_empty ( ) ) . unwrap_or ( false ) ;
705- if !has_hints {
706- let mut suggested = false ;
707- let mut warn = if let Some ( ref lit) = attr. value_str ( ) {
708- // avoid warning about empty `repr` on `#[repr = "foo"]`
709- let mut warn = cx. struct_span_lint (
710- BAD_REPR ,
711- attr. span ,
712- "`repr` attribute isn't configurable with a literal" ,
713- ) ;
714- match lit. to_string ( ) . as_ref ( ) {
715- | "C" | "packed" | "rust" | "transparent"
716- | "u8" | "u16" | "u32" | "u64" | "u128" | "usize"
717- | "i8" | "i16" | "i32" | "i64" | "i128" | "isize" => {
718- // if the literal could have been a valid `repr` arg,
719- // suggest the correct syntax
720- warn. span_suggestion_with_applicability (
721- attr. span ,
722- "give `repr` a hint" ,
723- repr_str ( & lit. as_str ( ) ) ,
724- Applicability :: MachineApplicable
725- ) ;
726- suggested = true ;
727- }
728- _ => { // the literal wasn't a valid `repr` arg
729- warn. span_label ( attr. span , "needs a hint" ) ;
730- }
731- } ;
732- warn
733- } else {
734- let mut warn = cx. struct_span_lint (
735- BAD_REPR ,
736- attr. span ,
737- "`repr` attribute must have a hint" ,
738- ) ;
739- warn. span_label ( attr. span , "needs a hint" ) ;
740- warn
741- } ;
742- if !suggested {
743- warn. help ( & format ! (
744- "valid hints include `{}`, `{}`, `{}` and `{}`" ,
745- repr_str( "C" ) ,
746- repr_str( "packed" ) ,
747- repr_str( "rust" ) ,
748- repr_str( "transparent" ) ,
749- ) ) ;
750- warn. note ( "for more information, visit \
751- <https://doc.rust-lang.org/reference/type-layout.html>") ;
752- }
753- warn. emit ( ) ;
754- }
755- }
756- }
757- }
758-
759686/// Checks for use of attributes which have been deprecated.
760687#[ derive( Clone ) ]
761688pub struct DeprecatedAttr {
762689 // This is not free to compute, so we want to keep it around, rather than
763690 // compute it for every attribute.
764- depr_attrs : Vec < & ' static ( & ' static str , AttributeType , AttributeGate ) > ,
691+ depr_attrs : Vec < & ' static ( & ' static str , AttributeType , AttributeTemplate , AttributeGate ) > ,
765692}
766693
767694impl DeprecatedAttr {
@@ -780,7 +707,7 @@ impl LintPass for DeprecatedAttr {
780707
781708impl EarlyLintPass for DeprecatedAttr {
782709 fn check_attribute ( & mut self , cx : & EarlyContext , attr : & ast:: Attribute ) {
783- for & & ( n, _, ref g) in & self . depr_attrs {
710+ for & & ( n, _, _ , ref g) in & self . depr_attrs {
784711 if attr. name ( ) == n {
785712 if let & AttributeGate :: Gated ( Stability :: Deprecated ( link, suggestion) ,
786713 ref name,
0 commit comments