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