Skip to content

Commit 8d6a161

Browse files
authored
Rollup merge of rust-lang#55719 - pnkfelix:issue-54388-sidestep-link-error-from-rustfixed-code, r=alexcrichton
Sidestep link error from rustfix'ed code by using a *defined* static. As a drive-by, added `-g` to the compile-flags so that the test more reliably fails to compile when the extern static in question is *not* provided. (I.e. this is making the test more robust in the face of potential future revisions.) Fix rust-lang#54388.
2 parents 6b93f19 + 34ffbdb commit 8d6a161

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

src/test/ui/extern/extern-const.fixed

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Check extern items cannot be const + `rustfix` suggests using
2+
// extern static.
3+
//
4+
// #54388: an unused reference to an undefined static may or may not
5+
// compile. To sidestep this by using one that *is* defined.
6+
7+
// run-rustfix
8+
// ignore-wasm32 no external library to link to.
9+
// compile-flags: -g -Z continue-parse-after-error
10+
#![feature(libc)]
11+
extern crate libc;
12+
13+
#[link(name = "rust_test_helpers", kind = "static")]
14+
extern "C" {
15+
static rust_dbg_static_mut: libc::c_int; //~ ERROR extern items cannot be `const`
16+
}
17+
18+
fn main() {
19+
// We suggest turning the (illegal) extern `const` into an extern `static`,
20+
// but this also requires `unsafe` (a deny-by-default lint at comment time,
21+
// future error; Issue #36247)
22+
unsafe {
23+
let _x = rust_dbg_static_mut;
24+
}
25+
}

src/test/ui/extern/extern-const.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
// Copyright 2017 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.
1+
// Check extern items cannot be const + `rustfix` suggests using
2+
// extern static.
43
//
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.
4+
// #54388: an unused reference to an undefined static may or may not
5+
// compile. To sidestep this by using one that *is* defined.
106

11-
// FIXME(#54388): re-enable rustfix later, when this test has consistent output across targets
12-
// compile-flags: -Z continue-parse-after-error
7+
// run-rustfix
8+
// ignore-wasm32 no external library to link to.
9+
// compile-flags: -g -Z continue-parse-after-error
10+
#![feature(libc)]
11+
extern crate libc;
1312

13+
#[link(name = "rust_test_helpers", kind = "static")]
1414
extern "C" {
15-
const C: u8; //~ ERROR extern items cannot be `const`
15+
const rust_dbg_static_mut: libc::c_int; //~ ERROR extern items cannot be `const`
1616
}
1717

1818
fn main() {
1919
// We suggest turning the (illegal) extern `const` into an extern `static`,
2020
// but this also requires `unsafe` (a deny-by-default lint at comment time,
2121
// future error; Issue #36247)
2222
unsafe {
23-
let _x = C;
23+
let _x = rust_dbg_static_mut;
2424
}
2525
}

src/test/ui/extern/extern-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: extern items cannot be `const`
22
--> $DIR/extern-const.rs:15:5
33
|
4-
LL | const C: u8; //~ ERROR extern items cannot be `const`
4+
LL | const rust_dbg_static_mut: libc::c_int; //~ ERROR extern items cannot be `const`
55
| ^^^^^ help: try using a static value: `static`
66

77
error: aborting due to previous error

0 commit comments

Comments
 (0)