Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1342913

Browse files
committedOct 7, 2018
Auto merge of #54451 - alexcrichton:no-mangle-extern-linkage, r=michaelwoerister
rustc: Allow `#[no_mangle]` anywhere in a crate This commit updates the compiler to allow the `#[no_mangle]` (and `#[export_name]` attributes) to be located anywhere within a crate. These attributes are unconditionally processed, causing the compiler to always generate an exported symbol with the appropriate name. After some discussion on #54135 it was found that not a great reason this hasn't been allowed already, and it seems to match the behavior that many expect! Previously the compiler would only export a `#[no_mangle]` symbol if it were *publicly reachable*, meaning that it itself is `pub` and it's otherwise publicly reachable from the root of the crate. This new definition is that `#[no_mangle]` *is always reachable*, no matter where it is in a crate or whether it has `pub` or not. This should make it much easier to declare an exported symbol with a known and unique name, even when it's an internal implementation detail of the crate itself. Note that these symbols will persist beyond LTO as well, always making their way to the linker. Along the way this commit removes the `private_no_mangle_functions` lint (also for statics) as there's no longer any need to lint these situations. Furthermore a good number of tests were updated now that symbol visibility has been changed. Closes #54135
2 parents dbecb7a + d7d7045 commit 1342913

File tree

22 files changed

+400
-307
lines changed

22 files changed

+400
-307
lines changed
 

‎src/librustc/hir/mod.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,9 +2467,22 @@ impl CodegenFnAttrs {
24672467
}
24682468
}
24692469

2470-
/// True if `#[no_mangle]` or `#[export_name(...)]` is present.
2470+
/// True if it looks like this symbol needs to be exported, for example:
2471+
///
2472+
/// * `#[no_mangle]` is present
2473+
/// * `#[export_name(...)]` is present
2474+
/// * `#[linkage]` is present
24712475
pub fn contains_extern_indicator(&self) -> bool {
2472-
self.flags.contains(CodegenFnAttrFlags::NO_MANGLE) || self.export_name.is_some()
2476+
self.flags.contains(CodegenFnAttrFlags::NO_MANGLE) ||
2477+
self.export_name.is_some() ||
2478+
match self.linkage {
2479+
// these are private, make sure we don't try to consider
2480+
// them external
2481+
None |
2482+
Some(Linkage::Internal) |
2483+
Some(Linkage::Private) => false,
2484+
Some(_) => true,
2485+
}
24732486
}
24742487
}
24752488

‎src/librustc/middle/dead.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use hir::intravisit::{self, Visitor, NestedVisitorMap};
1818
use hir::itemlikevisit::ItemLikeVisitor;
1919

2020
use hir::def::Def;
21+
use hir::CodegenFnAttrFlags;
2122
use hir::def_id::{DefId, LOCAL_CRATE};
2223
use lint;
2324
use middle::privacy;
@@ -302,14 +303,18 @@ fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>,
302303
return true;
303304
}
304305

305-
// #[used] also keeps the item alive forcefully,
306-
// e.g. for placing it in a specific section.
307-
if attr::contains_name(attrs, "used") {
306+
// Don't lint about global allocators
307+
if attr::contains_name(attrs, "global_allocator") {
308308
return true;
309309
}
310310

311-
// Don't lint about global allocators
312-
if attr::contains_name(attrs, "global_allocator") {
311+
let def_id = tcx.hir.local_def_id(id);
312+
let cg_attrs = tcx.codegen_fn_attrs(def_id);
313+
314+
// #[used], #[no_mangle], #[export_name], etc also keeps the item alive
315+
// forcefully, e.g. for placing it in a specific section.
316+
if cg_attrs.contains_extern_indicator() ||
317+
cg_attrs.flags.contains(CodegenFnAttrFlags::USED) {
313318
return true;
314319
}
315320

‎src/librustc/middle/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl<'a, 'tcx: 'a> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a,
352352
// which are currently akin to allocator symbols.
353353
let def_id = self.tcx.hir.local_def_id(item.id);
354354
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
355-
if codegen_attrs.linkage.is_some() ||
355+
if codegen_attrs.contains_extern_indicator() ||
356356
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) {
357357
self.worklist.push(item.id);
358358
}

‎src/librustc_lint/builtin.rs

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,18 +1163,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary {
11631163
}
11641164
}
11651165

1166-
declare_lint! {
1167-
PRIVATE_NO_MANGLE_FNS,
1168-
Warn,
1169-
"functions marked #[no_mangle] should be exported"
1170-
}
1171-
1172-
declare_lint! {
1173-
PRIVATE_NO_MANGLE_STATICS,
1174-
Warn,
1175-
"statics marked #[no_mangle] should be exported"
1176-
}
1177-
11781166
declare_lint! {
11791167
NO_MANGLE_CONST_ITEMS,
11801168
Deny,
@@ -1192,52 +1180,16 @@ pub struct InvalidNoMangleItems;
11921180

11931181
impl LintPass for InvalidNoMangleItems {
11941182
fn get_lints(&self) -> LintArray {
1195-
lint_array!(PRIVATE_NO_MANGLE_FNS,
1196-
PRIVATE_NO_MANGLE_STATICS,
1197-
NO_MANGLE_CONST_ITEMS,
1183+
lint_array!(NO_MANGLE_CONST_ITEMS,
11981184
NO_MANGLE_GENERIC_ITEMS)
11991185
}
12001186
}
12011187

12021188
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
12031189
fn check_item(&mut self, cx: &LateContext, it: &hir::Item) {
1204-
let suggest_export = |vis: &hir::Visibility, err: &mut DiagnosticBuilder| {
1205-
let suggestion = match vis.node {
1206-
hir::VisibilityKind::Inherited => {
1207-
// inherited visibility is empty span at item start; need an extra space
1208-
Some("pub ".to_owned())
1209-
},
1210-
hir::VisibilityKind::Restricted { .. } |
1211-
hir::VisibilityKind::Crate(_) => {
1212-
Some("pub".to_owned())
1213-
},
1214-
hir::VisibilityKind::Public => {
1215-
err.help("try exporting the item with a `pub use` statement");
1216-
None
1217-
}
1218-
};
1219-
if let Some(replacement) = suggestion {
1220-
err.span_suggestion_with_applicability(
1221-
vis.span,
1222-
"try making it public",
1223-
replacement,
1224-
Applicability::MachineApplicable
1225-
);
1226-
}
1227-
};
1228-
12291190
match it.node {
12301191
hir::ItemKind::Fn(.., ref generics, _) => {
12311192
if let Some(no_mangle_attr) = attr::find_by_name(&it.attrs, "no_mangle") {
1232-
if attr::contains_name(&it.attrs, "linkage") {
1233-
return;
1234-
}
1235-
if !cx.access_levels.is_reachable(it.id) {
1236-
let msg = "function is marked #[no_mangle], but not exported";
1237-
let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_FNS, it.span, msg);
1238-
suggest_export(&it.vis, &mut err);
1239-
err.emit();
1240-
}
12411193
for param in &generics.params {
12421194
match param.kind {
12431195
GenericParamKind::Lifetime { .. } => {}
@@ -1261,15 +1213,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems {
12611213
}
12621214
}
12631215
}
1264-
hir::ItemKind::Static(..) => {
1265-
if attr::contains_name(&it.attrs, "no_mangle") &&
1266-
!cx.access_levels.is_reachable(it.id) {
1267-
let msg = "static is marked #[no_mangle], but not exported";
1268-
let mut err = cx.struct_span_lint(PRIVATE_NO_MANGLE_STATICS, it.span, msg);
1269-
suggest_export(&it.vis, &mut err);
1270-
err.emit();
1271-
}
1272-
}
12731216
hir::ItemKind::Const(..) => {
12741217
if attr::contains_name(&it.attrs, "no_mangle") {
12751218
// Const items do not refer to a particular location in memory, and therefore
@@ -1785,8 +1728,6 @@ impl LintPass for SoftLints {
17851728
UNUSED_DOC_COMMENTS,
17861729
UNCONDITIONAL_RECURSION,
17871730
PLUGIN_AS_LIBRARY,
1788-
PRIVATE_NO_MANGLE_FNS,
1789-
PRIVATE_NO_MANGLE_STATICS,
17901731
NO_MANGLE_CONST_ITEMS,
17911732
NO_MANGLE_GENERIC_ITEMS,
17921733
MUTABLE_TRANSMUTES,

‎src/librustc_lint/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
387387
"converted into hard error, see https://github.com/rust-lang/rust/issues/48950");
388388
store.register_removed("resolve_trait_on_defaulted_unit",
389389
"converted into hard error, see https://github.com/rust-lang/rust/issues/48950");
390+
store.register_removed("private_no_mangle_fns",
391+
"no longer an warning, #[no_mangle] functions always exported");
392+
store.register_removed("private_no_mangle_statics",
393+
"no longer an warning, #[no_mangle] statics always exported");
390394
}

‎src/libstd/panicking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,11 @@ pub fn update_count_then_panic(msg: Box<dyn Any + Send>) -> ! {
515515
rust_panic(&mut RewrapBox(msg))
516516
}
517517

518-
/// A private no-mangle function on which to slap yer breakpoints.
518+
/// An unmangled function (through `rustc_std_internal_symbol`) on which to slap
519+
/// yer breakpoints.
519520
#[inline(never)]
520-
#[no_mangle]
521-
#[allow(private_no_mangle_fns)] // yes we get it, but we like breakpoints
522-
pub fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
521+
#[cfg_attr(not(test), rustc_std_internal_symbol)]
522+
fn rust_panic(mut msg: &mut dyn BoxMeUp) -> ! {
523523
let code = unsafe {
524524
let obj = &mut msg as *mut &mut dyn BoxMeUp;
525525
__rust_start_panic(obj as usize)

‎src/test/codegen/export-no-mangle.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type = "lib"]
12+
13+
mod private {
14+
// CHECK: @FOO =
15+
#[no_mangle]
16+
pub static FOO: u32 = 3;
17+
18+
// CHECK: @BAR =
19+
#[export_name = "BAR"]
20+
static BAR: u32 = 3;
21+
22+
// CHECK: void @foo()
23+
#[no_mangle]
24+
pub extern fn foo() {}
25+
26+
// CHECK: void @bar()
27+
#[export_name = "bar"]
28+
extern fn bar() {}
29+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -O
12+
// `#[no_mangle]`d functions always have external linkage, i.e. no `internal` in their `define`s
13+
14+
#![crate_type = "lib"]
15+
#![no_std]
16+
17+
// CHECK: define void @a()
18+
#[no_mangle]
19+
fn a() {}
20+
21+
// CHECK: define void @b()
22+
#[no_mangle]
23+
pub fn b() {}
24+
25+
mod private {
26+
// CHECK: define void @c()
27+
#[no_mangle]
28+
fn c() {}
29+
30+
// CHECK: define void @d()
31+
#[no_mangle]
32+
pub fn d() {}
33+
}
34+
35+
const HIDDEN: () = {
36+
// CHECK: define void @e()
37+
#[no_mangle]
38+
fn e() {}
39+
40+
// CHECK: define void @f()
41+
#[no_mangle]
42+
pub fn f() {}
43+
};
44+
45+
// The surrounding item should not accidentally become external
46+
// CHECK: define internal {{.*}} void @_ZN22external_no_mangle_fns1x
47+
#[inline(never)]
48+
fn x() {
49+
// CHECK: define void @g()
50+
#[no_mangle]
51+
fn g() {
52+
x();
53+
}
54+
55+
// CHECK: define void @h()
56+
#[no_mangle]
57+
pub fn h() {}
58+
59+
// side effect to keep `x` around
60+
unsafe {
61+
core::ptr::read_volatile(&42);
62+
}
63+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -O
12+
// `#[no_mangle]`d static variables always have external linkage, i.e. no `internal` in their
13+
// definitions
14+
15+
#![crate_type = "lib"]
16+
#![no_std]
17+
18+
// CHECK: @A = local_unnamed_addr constant
19+
#[no_mangle]
20+
static A: u8 = 0;
21+
22+
// CHECK: @B = local_unnamed_addr global
23+
#[no_mangle]
24+
static mut B: u8 = 0;
25+
26+
// CHECK: @C = local_unnamed_addr constant
27+
#[no_mangle]
28+
pub static C: u8 = 0;
29+
30+
// CHECK: @D = local_unnamed_addr global
31+
#[no_mangle]
32+
pub static mut D: u8 = 0;
33+
34+
mod private {
35+
// CHECK: @E = local_unnamed_addr constant
36+
#[no_mangle]
37+
static E: u8 = 0;
38+
39+
// CHECK: @F = local_unnamed_addr global
40+
#[no_mangle]
41+
static mut F: u8 = 0;
42+
43+
// CHECK: @G = local_unnamed_addr constant
44+
#[no_mangle]
45+
pub static G: u8 = 0;
46+
47+
// CHECK: @H = local_unnamed_addr global
48+
#[no_mangle]
49+
pub static mut H: u8 = 0;
50+
}
51+
52+
const HIDDEN: () = {
53+
// CHECK: @I = local_unnamed_addr constant
54+
#[no_mangle]
55+
static I: u8 = 0;
56+
57+
// CHECK: @J = local_unnamed_addr global
58+
#[no_mangle]
59+
static mut J: u8 = 0;
60+
61+
// CHECK: @K = local_unnamed_addr constant
62+
#[no_mangle]
63+
pub static K: u8 = 0;
64+
65+
// CHECK: @L = local_unnamed_addr global
66+
#[no_mangle]
67+
pub static mut L: u8 = 0;
68+
};
69+
70+
// The surrounding item should not accidentally become external
71+
fn x() {
72+
// CHECK: @M = local_unnamed_addr constant
73+
#[no_mangle]
74+
static M: fn() = x;
75+
76+
// CHECK: @N = local_unnamed_addr global
77+
#[no_mangle]
78+
static mut N: u8 = 0;
79+
80+
// CHECK: @O = local_unnamed_addr constant
81+
#[no_mangle]
82+
pub static O: u8 = 0;
83+
84+
// CHECK: @P = local_unnamed_addr global
85+
#[no_mangle]
86+
pub static mut P: u8 = 0;
87+
}
88+
// CHECK: define internal void @_ZN26external_no_mangle_statics1x{{.*$}}

‎src/test/codegen/issue-44056-macos-tls-align.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717
#![crate_type = "rlib"]
1818
#![feature(thread_local)]
1919

20-
// CHECK: @STATIC_VAR_1 = internal thread_local unnamed_addr global <{ [32 x i8] }> zeroinitializer, section "__DATA,__thread_bss", align 4
20+
// CHECK: @STATIC_VAR_1 = thread_local local_unnamed_addr global <{ [32 x i8] }> zeroinitializer, section "__DATA,__thread_bss", align 4
2121
#[no_mangle]
22-
#[allow(private_no_mangle_statics)]
2322
#[thread_local]
2423
static mut STATIC_VAR_1: [u32; 8] = [0; 8];
2524

26-
// CHECK: @STATIC_VAR_2 = internal thread_local unnamed_addr global <{ [32 x i8] }> <{{[^>]*}}>, section "__DATA,__thread_data", align 4
25+
// CHECK: @STATIC_VAR_2 = thread_local local_unnamed_addr global <{ [32 x i8] }> <{{[^>]*}}>, section "__DATA,__thread_data", align 4
2726
#[no_mangle]
28-
#[allow(private_no_mangle_statics)]
2927
#[thread_local]
3028
static mut STATIC_VAR_2: [u32; 8] = [4; 8];
3129

‎src/test/codegen/lto-removes-invokes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn main() {
2020
fn foo() {
2121
let _a = Box::new(3);
2222
bar();
23-
// CHECK-LABEL: foo
24-
// CHECK: call {{.*}} void @bar
23+
// CHECK-LABEL: define void @foo
24+
// CHECK: call void @bar
2525
}
2626

2727
#[inline(never)]

‎src/test/run-make-fulldeps/extern-fn-reachable/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub fn main() {
2020
let path = Path::new("libdylib.so");
2121
let a = DynamicLibrary::open(Some(&path)).unwrap();
2222
assert!(a.symbol::<isize>("fun1").is_ok());
23-
assert!(a.symbol::<isize>("fun2").is_err());
24-
assert!(a.symbol::<isize>("fun3").is_err());
23+
assert!(a.symbol::<isize>("fun2").is_ok());
24+
assert!(a.symbol::<isize>("fun3").is_ok());
2525
assert!(a.symbol::<isize>("fun4").is_ok());
2626
assert!(a.symbol::<isize>("fun5").is_ok());
2727
}

‎src/test/run-make/thumb-none-cortex-m/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ CRATE := cortex-m
2525
CRATE_URL := https://github.com/rust-embedded/cortex-m
2626
CRATE_SHA1 := a448e9156e2cb1e556e5441fd65426952ef4b927 # 0.5.0
2727

28+
export RUSTFLAGS := --cap-lints=allow
29+
2830
all:
2931
env
3032
mkdir -p $(WORK_DIR)

‎src/test/run-pass-fulldeps/auxiliary/linkage-visibility.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn test() {
3939
let lib = DynamicLibrary::open(None).unwrap();
4040
unsafe {
4141
assert!(lib.symbol::<isize>("foo").is_ok());
42-
assert!(lib.symbol::<isize>("baz").is_err());
43-
assert!(lib.symbol::<isize>("bar").is_err());
42+
assert!(lib.symbol::<isize>("baz").is_ok());
43+
assert!(lib.symbol::<isize>("bar").is_ok());
4444
}
4545
}

‎src/test/run-pass/issues/issue-33992.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// run-pass
1212
// ignore-windows
1313
// ignore-macos
14+
// ignore-wasm32-bare common linkage not implemented right now
1415

1516
#![feature(linkage)]
1617

‎src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ mod no_mangle {
393393
mod inner { #![no_mangle="3500"] }
394394

395395
#[no_mangle = "3500"] fn f() { }
396-
//~^ WARN function is marked #[no_mangle], but not exported
397396

398397
#[no_mangle = "3500"] struct S;
399398

‎src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr

Lines changed: 121 additions & 131 deletions
Large diffs are not rendered by default.

‎src/test/ui/lint/lint-unexported-no-mangle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// compile-flags:-F private_no_mangle_fns -F no_mangle_const_items -F private_no_mangle_statics
1212

1313
#[no_mangle]
14-
fn foo() { //~ ERROR function is marked #[no_mangle], but not exported
14+
fn foo() {
1515
}
1616

1717
#[allow(dead_code)]
@@ -30,7 +30,7 @@ pub static BAR: u64 = 1;
3030

3131
#[allow(dead_code)]
3232
#[no_mangle]
33-
static PRIVATE_BAR: u64 = 1; //~ ERROR static is marked #[no_mangle], but not exported
33+
static PRIVATE_BAR: u64 = 1;
3434

3535

3636
fn main() {
Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
error: function is marked #[no_mangle], but not exported
2-
--> $DIR/lint-unexported-no-mangle.rs:14:1
1+
warning: lint `private_no_mangle_fns` has been removed: `no longer an warning, #[no_mangle] functions always exported`
32
|
4-
LL | fn foo() { //~ ERROR function is marked #[no_mangle], but not exported
5-
| ^
6-
| |
7-
| _help: try making it public: `pub`
8-
| |
9-
LL | | }
10-
| |_^
3+
= note: requested on the command line with `-F private_no_mangle_fns`
4+
5+
warning: lint `private_no_mangle_statics` has been removed: `no longer an warning, #[no_mangle] statics always exported`
116
|
12-
= note: requested on the command line with `-F private-no-mangle-fns`
7+
= note: requested on the command line with `-F private_no_mangle_statics`
138

149
error: const items should never be #[no_mangle]
1510
--> $DIR/lint-unexported-no-mangle.rs:19:1
@@ -29,15 +24,5 @@ LL | pub const PUB_FOO: u64 = 1; //~ ERROR const items should never be #[no_mang
2924
| |
3025
| help: try a static value: `pub static`
3126

32-
error: static is marked #[no_mangle], but not exported
33-
--> $DIR/lint-unexported-no-mangle.rs:33:1
34-
|
35-
LL | static PRIVATE_BAR: u64 = 1; //~ ERROR static is marked #[no_mangle], but not exported
36-
| -^^^^^^^^^^^^^^^^^^^^^^^^^^^
37-
| |
38-
| help: try making it public: `pub`
39-
|
40-
= note: requested on the command line with `-F private-no-mangle-statics`
41-
42-
error: aborting due to 4 previous errors
27+
error: aborting due to 2 previous errors
4328

‎src/test/ui/lint/suggestions.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
#![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issue #43896
1414
#![feature(no_debug)]
1515

16-
#[no_mangle] static SHENZHOU: usize = 1;
17-
//~^ WARN static is marked #[no_mangle]
18-
//~| HELP try making it public
1916
#[no_mangle] const DISCOVERY: usize = 1;
2017
//~^ ERROR const items should never be #[no_mangle]
2118
//~| HELP try a static value
@@ -27,27 +24,25 @@ pub fn defiant<T>(_t: T) {}
2724

2825
#[no_mangle]
2926
fn rio_grande() {}
30-
//~^ WARN function is marked
31-
//~| HELP try making it public
3227

3328
mod badlands {
3429
// The private-no-mangle lints shouldn't suggest inserting `pub` when the
3530
// item is already `pub` (but triggered the lint because, e.g., it's in a
3631
// private module). (Issue #47383)
37-
#[no_mangle] pub static DAUNTLESS: bool = true;
38-
//~^ WARN static is marked
39-
//~| HELP try exporting the item with a `pub use` statement
40-
#[no_mangle] pub fn val_jean() {}
41-
//~^ WARN function is marked
42-
//~| HELP try exporting the item with a `pub use` statement
32+
#[no_mangle] pub const DAUNTLESS: bool = true;
33+
//~^ ERROR const items should never be #[no_mangle]
34+
//~| HELP try a static value
35+
#[no_mangle] pub fn val_jean<T>() {}
36+
//~^ WARN functions generic over types must be mangled
37+
//~| HELP remove this attribute
4338

4439
// ... but we can suggest just-`pub` instead of restricted
45-
#[no_mangle] pub(crate) static VETAR: bool = true;
46-
//~^ WARN static is marked
47-
//~| HELP try making it public
48-
#[no_mangle] pub(crate) fn crossfield() {}
49-
//~^ WARN function is marked
50-
//~| HELP try making it public
40+
#[no_mangle] pub(crate) const VETAR: bool = true;
41+
//~^ ERROR const items should never be #[no_mangle]
42+
//~| HELP try a static value
43+
#[no_mangle] pub(crate) fn crossfield<T>() {}
44+
//~^ WARN functions generic over types must be mangled
45+
//~| HELP remove this attribute
5146
}
5247

5348
struct Equinox {

‎src/test/ui/lint/suggestions.stderr

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unnecessary parentheses around assigned value
2-
--> $DIR/suggestions.rs:64:21
2+
--> $DIR/suggestions.rs:59:21
33
|
44
LL | let mut a = (1);
55
| ^^^ help: remove these parentheses
@@ -11,15 +11,15 @@ LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issu
1111
| ^^^^^^^^^^^^^
1212

1313
warning: use of deprecated attribute `no_debug`: the `#[no_debug]` attribute was an experimental feature that has been deprecated due to lack of demand. See https://github.com/rust-lang/rust/issues/29721
14-
--> $DIR/suggestions.rs:57:1
14+
--> $DIR/suggestions.rs:52:1
1515
|
1616
LL | #[no_debug] // should suggest removal of deprecated attribute
1717
| ^^^^^^^^^^^ help: remove this attribute
1818
|
1919
= note: #[warn(deprecated)] on by default
2020

2121
warning: variable does not need to be mutable
22-
--> $DIR/suggestions.rs:64:13
22+
--> $DIR/suggestions.rs:59:13
2323
|
2424
LL | let mut a = (1);
2525
| ----^
@@ -33,7 +33,7 @@ LL | #![warn(unused_mut, unused_parens)] // UI tests pass `-A unused`—see Issu
3333
| ^^^^^^^^^^
3434

3535
warning: variable does not need to be mutable
36-
--> $DIR/suggestions.rs:70:13
36+
--> $DIR/suggestions.rs:65:13
3737
|
3838
LL | let mut
3939
| _____________^
@@ -44,18 +44,8 @@ LL | || b = 1;
4444
| |____________|
4545
| help: remove this `mut`
4646

47-
warning: static is marked #[no_mangle], but not exported
48-
--> $DIR/suggestions.rs:16:14
49-
|
50-
LL | #[no_mangle] static SHENZHOU: usize = 1;
51-
| -^^^^^^^^^^^^^^^^^^^^^^^^^^
52-
| |
53-
| help: try making it public: `pub`
54-
|
55-
= note: #[warn(private_no_mangle_statics)] on by default
56-
5747
error: const items should never be #[no_mangle]
58-
--> $DIR/suggestions.rs:19:14
48+
--> $DIR/suggestions.rs:16:14
5949
|
6050
LL | #[no_mangle] const DISCOVERY: usize = 1;
6151
| -----^^^^^^^^^^^^^^^^^^^^^^
@@ -65,7 +55,7 @@ LL | #[no_mangle] const DISCOVERY: usize = 1;
6555
= note: #[deny(no_mangle_const_items)] on by default
6656

6757
warning: functions generic over types must be mangled
68-
--> $DIR/suggestions.rs:25:1
58+
--> $DIR/suggestions.rs:22:1
6959
|
7060
LL | #[no_mangle]
7161
| ------------ help: remove this attribute
@@ -75,58 +65,48 @@ LL | pub fn defiant<T>(_t: T) {}
7565
|
7666
= note: #[warn(no_mangle_generic_items)] on by default
7767

78-
warning: function is marked #[no_mangle], but not exported
79-
--> $DIR/suggestions.rs:29:1
80-
|
81-
LL | fn rio_grande() {}
82-
| -^^^^^^^^^^^^^^^^^
83-
| |
84-
| help: try making it public: `pub`
68+
error: const items should never be #[no_mangle]
69+
--> $DIR/suggestions.rs:32:18
8570
|
86-
= note: #[warn(private_no_mangle_fns)] on by default
71+
LL | #[no_mangle] pub const DAUNTLESS: bool = true;
72+
| ---------^^^^^^^^^^^^^^^^^^^^^^^^
73+
| |
74+
| help: try a static value: `pub static`
8775

88-
warning: static is marked #[no_mangle], but not exported
89-
--> $DIR/suggestions.rs:37:18
90-
|
91-
LL | #[no_mangle] pub static DAUNTLESS: bool = true;
92-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
76+
warning: functions generic over types must be mangled
77+
--> $DIR/suggestions.rs:35:18
9378
|
94-
= help: try exporting the item with a `pub use` statement
79+
LL | #[no_mangle] pub fn val_jean<T>() {}
80+
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^
81+
| |
82+
| help: remove this attribute
9583

96-
warning: function is marked #[no_mangle], but not exported
84+
error: const items should never be #[no_mangle]
9785
--> $DIR/suggestions.rs:40:18
9886
|
99-
LL | #[no_mangle] pub fn val_jean() {}
100-
| ^^^^^^^^^^^^^^^^^^^^
101-
|
102-
= help: try exporting the item with a `pub use` statement
103-
104-
warning: static is marked #[no_mangle], but not exported
105-
--> $DIR/suggestions.rs:45:18
106-
|
107-
LL | #[no_mangle] pub(crate) static VETAR: bool = true;
108-
| ----------^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
LL | #[no_mangle] pub(crate) const VETAR: bool = true;
88+
| ----------------^^^^^^^^^^^^^^^^^^^^
10989
| |
110-
| help: try making it public: `pub`
90+
| help: try a static value: `pub static`
11191

112-
warning: function is marked #[no_mangle], but not exported
113-
--> $DIR/suggestions.rs:48:18
92+
warning: functions generic over types must be mangled
93+
--> $DIR/suggestions.rs:43:18
11494
|
115-
LL | #[no_mangle] pub(crate) fn crossfield() {}
116-
| ----------^^^^^^^^^^^^^^^^^^^
117-
| |
118-
| help: try making it public: `pub`
95+
LL | #[no_mangle] pub(crate) fn crossfield<T>() {}
96+
| ------------ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
| |
98+
| help: remove this attribute
11999

120100
warning: denote infinite loops with `loop { ... }`
121-
--> $DIR/suggestions.rs:61:5
101+
--> $DIR/suggestions.rs:56:5
122102
|
123103
LL | while true {
124104
| ^^^^^^^^^^ help: use `loop`
125105
|
126106
= note: #[warn(while_true)] on by default
127107

128108
warning: the `warp_factor:` in this pattern is redundant
129-
--> $DIR/suggestions.rs:76:23
109+
--> $DIR/suggestions.rs:71:23
130110
|
131111
LL | Equinox { warp_factor: warp_factor } => {}
132112
| ------------^^^^^^^^^^^^
@@ -135,5 +115,5 @@ LL | Equinox { warp_factor: warp_factor } => {}
135115
|
136116
= note: #[warn(non_shorthand_field_patterns)] on by default
137117

138-
error: aborting due to previous error
118+
error: aborting due to 3 previous errors
139119

‎src/tools/cargotest/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ const TEST_REPOS: &'static [Test] = &[
6161
Test {
6262
name: "servo",
6363
repo: "https://github.com/servo/servo",
64-
sha: "17e97b9320fdb7cdb33bbc5f4d0fde0653bbf2e4",
64+
sha: "987e376ca7a4245dbc3e0c06e963278ee1ac92d1",
6565
lock: None,
6666
// Only test Stylo a.k.a. Quantum CSS, the parts of Servo going into Firefox.
6767
// This takes much less time to build than all of Servo and supports stable Rust.
68-
packages: &["stylo_tests", "selectors"],
68+
packages: &["selectors"],
6969
},
7070
Test {
7171
name: "webrender",

0 commit comments

Comments
 (0)
Please sign in to comment.