Skip to content

Commit e44e3b2

Browse files
committed
---
yaml --- r: 180073 b: refs/heads/auto c: 73d5d89 h: refs/heads/master i: 180071: e423365 v: v3
1 parent 3495b70 commit e44e3b2

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 51ed1ecefd016bd90b09fea399b9a989d756609d
13+
refs/heads/auto: 73d5d89567ef155dc12ee7d7ed61e206e43bf74e
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/lint/builtin.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,12 @@ declare_lint! {
20652065
"functions marked #[no_mangle] should be exported"
20662066
}
20672067

2068+
declare_lint! {
2069+
PRIVATE_NO_MANGLE_STATICS,
2070+
Warn,
2071+
"statics marked #[no_mangle] should be exported"
2072+
}
2073+
20682074
declare_lint! {
20692075
NO_MANGLE_CONST_ITEMS,
20702076
Deny,
@@ -2077,6 +2083,7 @@ pub struct InvalidNoMangleItems;
20772083
impl LintPass for InvalidNoMangleItems {
20782084
fn get_lints(&self) -> LintArray {
20792085
lint_array!(PRIVATE_NO_MANGLE_FNS,
2086+
PRIVATE_NO_MANGLE_STATICS,
20802087
NO_MANGLE_CONST_ITEMS)
20812088
}
20822089

@@ -2090,6 +2097,14 @@ impl LintPass for InvalidNoMangleItems {
20902097
cx.span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg.as_slice());
20912098
}
20922099
},
2100+
ast::ItemStatic(..) => {
2101+
if attr::contains_name(it.attrs.as_slice(), "no_mangle") &&
2102+
!cx.exported_items.contains(&it.id) {
2103+
let msg = format!("static {} is marked #[no_mangle], but not exported",
2104+
it.ident);
2105+
cx.span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, msg.as_slice());
2106+
}
2107+
},
20932108
ast::ItemConst(..) => {
20942109
if attr::contains_name(it.attrs.as_slice(), "no_mangle") {
20952110
let msg = "const items should never be #[no_mangle]";

branches/auto/src/test/compile-fail/lint-unexported-no-mangle.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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 -F no_mangle_const_items
11+
// compile-flags:-F private_no_mangle_fns -F no_mangle_const_items -F private_no_mangle_statics
1212

1313
// FIXME(#19495) no_mangle'ing main ICE's.
1414
#[no_mangle]
@@ -26,6 +26,14 @@ pub const PUB_FOO: u64 = 1; //~ ERROR const items should never be #[no_mangle]
2626
pub fn bar() {
2727
}
2828

29+
#[no_mangle]
30+
pub static BAR: u64 = 1;
31+
32+
#[allow(dead_code)]
33+
#[no_mangle]
34+
static PRIVATE_BAR: u64 = 1; //~ ERROR static PRIVATE_BAR is marked #[no_mangle], but not exported
35+
36+
2937
fn main() {
3038
foo();
3139
bar();

0 commit comments

Comments
 (0)