File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -2065,12 +2065,19 @@ declare_lint! {
2065
2065
"functions marked #[no_mangle] should be exported"
2066
2066
}
2067
2067
2068
+ declare_lint ! {
2069
+ NO_MANGLE_CONST_ITEMS ,
2070
+ Deny ,
2071
+ "const items will not have their symbols exported"
2072
+ }
2073
+
2068
2074
#[ derive( Copy ) ]
2069
- pub struct PrivateNoMangleFns ;
2075
+ pub struct InvalidNoMangleItems ;
2070
2076
2071
- impl LintPass for PrivateNoMangleFns {
2077
+ impl LintPass for InvalidNoMangleItems {
2072
2078
fn get_lints ( & self ) -> LintArray {
2073
- lint_array ! ( PRIVATE_NO_MANGLE_FNS )
2079
+ lint_array ! ( PRIVATE_NO_MANGLE_FNS ,
2080
+ NO_MANGLE_CONST_ITEMS )
2074
2081
}
2075
2082
2076
2083
fn check_item ( & mut self , cx : & Context , it : & ast:: Item ) {
@@ -2083,6 +2090,12 @@ impl LintPass for PrivateNoMangleFns {
2083
2090
cx. span_lint ( PRIVATE_NO_MANGLE_FNS , it. span , msg. as_slice ( ) ) ;
2084
2091
}
2085
2092
} ,
2093
+ ast:: ItemConst ( ..) => {
2094
+ if attr:: contains_name ( it. attrs . as_slice ( ) , "no_mangle" ) {
2095
+ let msg = "const items should never be #[no_mangle]" ;
2096
+ cx. span_lint ( NO_MANGLE_CONST_ITEMS , it. span , msg) ;
2097
+ }
2098
+ }
2086
2099
_ => { } ,
2087
2100
}
2088
2101
}
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ impl LintStore {
213
213
UnstableFeatures ,
214
214
Stability ,
215
215
UnconditionalRecursion ,
216
- PrivateNoMangleFns ,
216
+ InvalidNoMangleItems ,
217
217
) ;
218
218
219
219
add_builtin_with_new ! ( sess,
Original file line number Diff line number Diff line change 8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- // compile-flags:-F private_no_mangle_fns
11
+ // compile-flags:-F private_no_mangle_fns -F no_mangle_const_items
12
12
13
13
// FIXME(#19495) no_mangle'ing main ICE's.
14
14
#[ no_mangle]
15
15
fn foo ( ) { //~ ERROR function foo is marked #[no_mangle], but not exported
16
16
}
17
17
18
+ #[ allow( dead_code) ]
19
+ #[ no_mangle]
20
+ const FOO : u64 = 1 ; //~ ERROR const items should never be #[no_mangle]
21
+
22
+ #[ no_mangle]
23
+ pub const PUB_FOO : u64 = 1 ; //~ ERROR const items should never be #[no_mangle]
24
+
18
25
#[ no_mangle]
19
26
pub fn bar ( ) {
20
27
}
You can’t perform that action at this time.
0 commit comments