@@ -92,7 +92,6 @@ pub enum Lint {
92
92
TypeOverflow ,
93
93
UnusedUnsafe ,
94
94
UnsafeBlock ,
95
- AttributeUsage ,
96
95
UnusedAttribute ,
97
96
UnknownFeatures ,
98
97
UnknownCrateType ,
@@ -294,13 +293,6 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
294
293
default : Allow
295
294
} ) ,
296
295
297
- ( "attribute_usage" ,
298
- LintSpec {
299
- lint : AttributeUsage ,
300
- desc : "detects bad use of attributes" ,
301
- default : Warn
302
- } ) ,
303
-
304
296
( "unused_attribute" ,
305
297
LintSpec {
306
298
lint : UnusedAttribute ,
@@ -1096,93 +1088,6 @@ fn check_raw_ptr_deriving(cx: &mut Context, item: &ast::Item) {
1096
1088
}
1097
1089
}
1098
1090
1099
- static crate_attrs: & ' static [ & ' static str ] = & [
1100
- "crate_type" , "feature" , "no_start" , "no_main" , "no_std" , "crate_id" ,
1101
- "desc" , "comment" , "license" , "copyright" , // not used in rustc now
1102
- "no_builtins" ,
1103
- ] ;
1104
-
1105
-
1106
- static obsolete_attrs: & ' static [ ( & ' static str , & ' static str ) ] = & [
1107
- ( "abi" , "Use `extern \" abi\" fn` instead" ) ,
1108
- ( "auto_encode" , "Use `#[deriving(Encodable)]` instead" ) ,
1109
- ( "auto_decode" , "Use `#[deriving(Decodable)]` instead" ) ,
1110
- ( "fast_ffi" , "Remove it" ) ,
1111
- ( "fixed_stack_segment" , "Remove it" ) ,
1112
- ( "rust_stack" , "Remove it" ) ,
1113
- ] ;
1114
-
1115
- static other_attrs: & ' static [ & ' static str ] = & [
1116
- // item-level
1117
- "address_insignificant" , // can be crate-level too
1118
- "thread_local" , // for statics
1119
- "allow" , "deny" , "forbid" , "warn" , // lint options
1120
- "deprecated" , "experimental" , "unstable" , "stable" , "locked" , "frozen" , //item stability
1121
- "cfg" , "doc" , "export_name" , "link_section" ,
1122
- "no_mangle" , "static_assert" , "unsafe_no_drop_flag" , "packed" ,
1123
- "simd" , "repr" , "deriving" , "unsafe_destructor" , "link" , "phase" ,
1124
- "macro_export" , "must_use" , "automatically_derived" ,
1125
-
1126
- //mod-level
1127
- "path" , "link_name" , "link_args" , "macro_escape" , "no_implicit_prelude" ,
1128
-
1129
- // fn-level
1130
- "test" , "bench" , "should_fail" , "ignore" , "inline" , "lang" , "main" , "start" ,
1131
- "no_split_stack" , "cold" , "macro_registrar" , "linkage" ,
1132
-
1133
- // internal attribute: bypass privacy inside items
1134
- "!resolve_unexported" ,
1135
- ] ;
1136
-
1137
- fn check_crate_attrs_usage ( cx : & Context , attrs : & [ ast:: Attribute ] ) {
1138
-
1139
- for attr in attrs. iter ( ) {
1140
- let name = attr. node . value . name ( ) ;
1141
- let mut iter = crate_attrs. iter ( ) . chain ( other_attrs. iter ( ) ) ;
1142
- if !iter. any ( |other_attr| { name. equiv ( other_attr) } ) {
1143
- cx. span_lint ( AttributeUsage , attr. span , "unknown crate attribute" ) ;
1144
- }
1145
- if name. equiv ( & ( "link" ) ) {
1146
- cx. tcx . sess . span_err ( attr. span ,
1147
- "obsolete crate `link` attribute" ) ;
1148
- cx. tcx . sess . note ( "the link attribute has been superceded by the crate_id \
1149
- attribute, which has the format `#[crate_id = \" name#version\" ]`") ;
1150
- }
1151
- }
1152
- }
1153
-
1154
- fn check_attrs_usage ( cx : & Context , attrs : & [ ast:: Attribute ] ) {
1155
- // check if element has crate-level, obsolete, or any unknown attributes.
1156
-
1157
- for attr in attrs. iter ( ) {
1158
- let name = attr. node . value . name ( ) ;
1159
- for crate_attr in crate_attrs. iter ( ) {
1160
- if name. equiv ( crate_attr) {
1161
- let msg = match attr. node . style {
1162
- ast:: AttrOuter => "crate-level attribute should be an inner attribute: \
1163
- add an exclamation mark: #![foo]",
1164
- ast:: AttrInner => "crate-level attribute should be in the root module" ,
1165
- } ;
1166
- cx. span_lint ( AttributeUsage , attr. span , msg) ;
1167
- return ;
1168
- }
1169
- }
1170
-
1171
- for & ( obs_attr, obs_alter) in obsolete_attrs. iter ( ) {
1172
- if name. equiv ( & obs_attr) {
1173
- cx. span_lint ( AttributeUsage , attr. span ,
1174
- format ! ( "obsolete attribute: {:s}" ,
1175
- obs_alter) . as_slice ( ) ) ;
1176
- return ;
1177
- }
1178
- }
1179
-
1180
- if !other_attrs. iter ( ) . any ( |other_attr| { name. equiv ( other_attr) } ) {
1181
- cx. span_lint ( AttributeUsage , attr. span , "unknown attribute" ) ;
1182
- }
1183
- }
1184
- }
1185
-
1186
1091
fn check_unused_attribute ( cx : & Context , attr : & ast:: Attribute ) {
1187
1092
static ATTRIBUTE_WHITELIST : & ' static [ & ' static str ] = & ' static [
1188
1093
// FIXME: #14408 whitelist docs since rustdoc looks at them
@@ -1834,7 +1739,6 @@ impl<'a> Visitor<()> for Context<'a> {
1834
1739
check_item_non_uppercase_statics ( cx, it) ;
1835
1740
check_heap_item ( cx, it) ;
1836
1741
check_missing_doc_item ( cx, it) ;
1837
- check_attrs_usage ( cx, it. attrs . as_slice ( ) ) ;
1838
1742
check_raw_ptr_deriving ( cx, it) ;
1839
1743
1840
1744
cx. visit_ids ( |v| v. visit_item ( it, ( ) ) ) ;
@@ -1845,15 +1749,12 @@ impl<'a> Visitor<()> for Context<'a> {
1845
1749
1846
1750
fn visit_foreign_item ( & mut self , it : & ast:: ForeignItem , _: ( ) ) {
1847
1751
self . with_lint_attrs ( it. attrs . as_slice ( ) , |cx| {
1848
- check_attrs_usage ( cx, it. attrs . as_slice ( ) ) ;
1849
1752
visit:: walk_foreign_item ( cx, it, ( ) ) ;
1850
1753
} )
1851
1754
}
1852
1755
1853
1756
fn visit_view_item ( & mut self , i : & ast:: ViewItem , _: ( ) ) {
1854
1757
self . with_lint_attrs ( i. attrs . as_slice ( ) , |cx| {
1855
- check_attrs_usage ( cx, i. attrs . as_slice ( ) ) ;
1856
-
1857
1758
cx. visit_ids ( |v| v. visit_view_item ( i, ( ) ) ) ;
1858
1759
1859
1760
visit:: walk_view_item ( cx, i, ( ) ) ;
@@ -1935,7 +1836,6 @@ impl<'a> Visitor<()> for Context<'a> {
1935
1836
visit:: FkMethod ( ident, _, m) => {
1936
1837
self . with_lint_attrs ( m. attrs . as_slice ( ) , |cx| {
1937
1838
check_missing_doc_method ( cx, m) ;
1938
- check_attrs_usage ( cx, m. attrs . as_slice ( ) ) ;
1939
1839
1940
1840
match method_context ( cx, m) {
1941
1841
PlainImpl => check_snake_case ( cx, "method" , ident, span) ,
@@ -1960,7 +1860,6 @@ impl<'a> Visitor<()> for Context<'a> {
1960
1860
fn visit_ty_method ( & mut self , t : & ast:: TypeMethod , _: ( ) ) {
1961
1861
self . with_lint_attrs ( t. attrs . as_slice ( ) , |cx| {
1962
1862
check_missing_doc_ty_method ( cx, t) ;
1963
- check_attrs_usage ( cx, t. attrs . as_slice ( ) ) ;
1964
1863
check_snake_case ( cx, "trait method" , t. ident , t. span ) ;
1965
1864
1966
1865
visit:: walk_ty_method ( cx, t, ( ) ) ;
@@ -1984,7 +1883,6 @@ impl<'a> Visitor<()> for Context<'a> {
1984
1883
fn visit_struct_field ( & mut self , s : & ast:: StructField , _: ( ) ) {
1985
1884
self . with_lint_attrs ( s. node . attrs . as_slice ( ) , |cx| {
1986
1885
check_missing_doc_struct_field ( cx, s) ;
1987
- check_attrs_usage ( cx, s. node . attrs . as_slice ( ) ) ;
1988
1886
1989
1887
visit:: walk_struct_field ( cx, s, ( ) ) ;
1990
1888
} )
@@ -1993,7 +1891,6 @@ impl<'a> Visitor<()> for Context<'a> {
1993
1891
fn visit_variant ( & mut self , v : & ast:: Variant , g : & ast:: Generics , _: ( ) ) {
1994
1892
self . with_lint_attrs ( v. node . attrs . as_slice ( ) , |cx| {
1995
1893
check_missing_doc_variant ( cx, v) ;
1996
- check_attrs_usage ( cx, v. node . attrs . as_slice ( ) ) ;
1997
1894
1998
1895
visit:: walk_variant ( cx, v, g, ( ) ) ;
1999
1896
} )
@@ -2053,7 +1950,6 @@ pub fn check_crate(tcx: &ty::ctxt,
2053
1950
visit:: walk_crate ( v, krate, ( ) ) ;
2054
1951
} ) ;
2055
1952
2056
- check_crate_attrs_usage ( cx, krate. attrs . as_slice ( ) ) ;
2057
1953
// since the root module isn't visited as an item (because it isn't an item), warn for it
2058
1954
// here.
2059
1955
check_missing_doc_attrs ( cx,
0 commit comments