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! {
20652065 "functions marked #[no_mangle] should be exported"
20662066}
20672067
2068+ declare_lint ! {
2069+ NO_MANGLE_CONST_ITEMS ,
2070+ Deny ,
2071+ "const items will not have their symbols exported"
2072+ }
2073+
20682074#[ derive( Copy ) ]
2069- pub struct PrivateNoMangleFns ;
2075+ pub struct InvalidNoMangleItems ;
20702076
2071- impl LintPass for PrivateNoMangleFns {
2077+ impl LintPass for InvalidNoMangleItems {
20722078 fn get_lints ( & self ) -> LintArray {
2073- lint_array ! ( PRIVATE_NO_MANGLE_FNS )
2079+ lint_array ! ( PRIVATE_NO_MANGLE_FNS ,
2080+ NO_MANGLE_CONST_ITEMS )
20742081 }
20752082
20762083 fn check_item ( & mut self , cx : & Context , it : & ast:: Item ) {
@@ -2083,6 +2090,12 @@ impl LintPass for PrivateNoMangleFns {
20832090 cx. span_lint ( PRIVATE_NO_MANGLE_FNS , it. span , msg. as_slice ( ) ) ;
20842091 }
20852092 } ,
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+ }
20862099 _ => { } ,
20872100 }
20882101 }
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ impl LintStore {
213213 UnstableFeatures ,
214214 Stability ,
215215 UnconditionalRecursion ,
216- PrivateNoMangleFns ,
216+ InvalidNoMangleItems ,
217217 ) ;
218218
219219 add_builtin_with_new ! ( sess,
Original file line number Diff line number Diff line change 88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- // compile-flags:-F private_no_mangle_fns
11+ // compile-flags:-F private_no_mangle_fns -F no_mangle_const_items
1212
1313// FIXME(#19495) no_mangle'ing main ICE's.
1414#[ no_mangle]
1515fn foo ( ) { //~ ERROR function foo is marked #[no_mangle], but not exported
1616}
1717
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+
1825#[ no_mangle]
1926pub fn bar ( ) {
2027}
You can’t perform that action at this time.
0 commit comments