Skip to content

Commit e7f8c0d

Browse files
committed
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.
1 parent 6cfc603 commit e7f8c0d

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+
// This test is checking that extern items cannot be const. It also
2+
// checks that `rustfix` suggests the alternative of using an extern
3+
// static.
4+
//
5+
// #54388: an unused reference to an undefined static may or may not
6+
// compile. To sidestep this by using one that *is* defined.
7+
8+
// run-rustfix
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+
// This test is checking that extern items cannot be const. It also
2+
// checks that `rustfix` suggests the alternative of using an extern
3+
// static.
44
//
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.
5+
// #54388: an unused reference to an undefined static may or may not
6+
// compile. To sidestep this by using one that *is* defined.
107

11-
// FIXME(#54388): re-enable rustfix later, when this test has consistent output across targets
12-
// compile-flags: -Z continue-parse-after-error
8+
// run-rustfix
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)