Skip to content

Commit c72a5dd

Browse files
committed
Rename the lint to clashing_extern_declarations.
Also, run RustFmt on the clashing_extern_fn test case and update stderrs.
1 parent 394e1b4 commit c72a5dd

File tree

12 files changed

+91
-64
lines changed

12 files changed

+91
-64
lines changed

src/libcore/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ pub mod primitive;
279279
// crate uses the this crate as its libcore.
280280
#[path = "../stdarch/crates/core_arch/src/mod.rs"]
281281
#[allow(missing_docs, missing_debug_implementations, dead_code, unused_imports)]
282-
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_decl is
282+
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
283283
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
284-
#[cfg_attr(not(bootstrap), allow(clashing_extern_decl))]
284+
#[cfg_attr(not(bootstrap), allow(clashing_extern_declarations))]
285285
#[unstable(feature = "stdsimd", issue = "48556")]
286286
mod core_arch;
287287

src/librustc_lint/builtin.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2055,12 +2055,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
20552055
}
20562056

20572057
declare_lint! {
2058-
pub CLASHING_EXTERN_DECL,
2058+
pub CLASHING_EXTERN_DECLARATIONS,
20592059
Warn,
20602060
"detects when an extern fn has been declared with the same name but different types"
20612061
}
20622062

2063-
pub struct ClashingExternDecl {
2063+
pub struct ClashingExternDeclarations {
20642064
seen_decls: FxHashMap<Symbol, HirId>,
20652065
}
20662066

@@ -2083,9 +2083,9 @@ impl SymbolName {
20832083
}
20842084
}
20852085

2086-
impl ClashingExternDecl {
2086+
impl ClashingExternDeclarations {
20872087
crate fn new() -> Self {
2088-
ClashingExternDecl { seen_decls: FxHashMap::default() }
2088+
ClashingExternDeclarations { seen_decls: FxHashMap::default() }
20892089
}
20902090
/// Insert a new foreign item into the seen set. If a symbol with the same name already exists
20912091
/// for the item, return its HirId without updating the set.
@@ -2211,18 +2211,18 @@ impl ClashingExternDecl {
22112211
}
22122212
}
22132213

2214-
impl_lint_pass!(ClashingExternDecl => [CLASHING_EXTERN_DECL]);
2214+
impl_lint_pass!(ClashingExternDeclarations => [CLASHING_EXTERN_DECLARATIONS]);
22152215

2216-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ClashingExternDecl {
2216+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ClashingExternDeclarations {
22172217
fn check_foreign_item(&mut self, cx: &LateContext<'a, 'tcx>, this_fi: &hir::ForeignItem<'_>) {
2218-
trace!("ClashingExternDecl: check_foreign_item: {:?}", this_fi);
2218+
trace!("ClashingExternDeclarations: check_foreign_item: {:?}", this_fi);
22192219
if let ForeignItemKind::Fn(..) = this_fi.kind {
22202220
let tcx = *&cx.tcx;
22212221
if let Some(existing_hid) = self.insert(tcx, this_fi) {
22222222
let existing_decl_ty = tcx.type_of(tcx.hir().local_def_id(existing_hid));
22232223
let this_decl_ty = tcx.type_of(tcx.hir().local_def_id(this_fi.hir_id));
22242224
debug!(
2225-
"ClashingExternDecl: Comparing existing {:?}: {:?} to this {:?}: {:?}",
2225+
"ClashingExternDeclarations: Comparing existing {:?}: {:?} to this {:?}: {:?}",
22262226
existing_hid, existing_decl_ty, this_fi.hir_id, this_decl_ty
22272227
);
22282228
// Check that the declarations match.
@@ -2239,7 +2239,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ClashingExternDecl {
22392239
};
22402240
// Finally, emit the diagnostic.
22412241
tcx.struct_span_lint_hir(
2242-
CLASHING_EXTERN_DECL,
2242+
CLASHING_EXTERN_DECLARATIONS,
22432243
this_fi.hir_id,
22442244
get_relevant_span(this_fi),
22452245
|lint| {

src/librustc_lint/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ macro_rules! late_lint_passes {
155155
// and change this to a module lint pass
156156
MissingDebugImplementations: MissingDebugImplementations::default(),
157157
ArrayIntoIter: ArrayIntoIter,
158-
ClashingExternDecl: ClashingExternDecl::new(),
158+
ClashingExternDeclarations: ClashingExternDeclarations::new(),
159159
]
160160
);
161161
};

src/libstd/sys/unix/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ mod imp {
205205
#[cfg(target_arch = "aarch64")]
206206
extern "C" {
207207
fn objc_msgSend(obj: NsId, sel: Sel) -> NsId;
208-
#[cfg_attr(not(bootstrap), allow(clashing_extern_decl))]
208+
#[cfg_attr(not(bootstrap), allow(clashing_extern_declarations))]
209209
#[link_name = "objc_msgSend"]
210210
fn objc_msgSend_ul(obj: NsId, sel: Sel, i: libc::c_ulong) -> NsId;
211211
}
212212

213213
#[cfg(not(target_arch = "aarch64"))]
214214
extern "C" {
215215
fn objc_msgSend(obj: NsId, sel: Sel, ...) -> NsId;
216-
#[cfg_attr(not(bootstrap), allow(clashing_extern_decl))]
216+
#[cfg_attr(not(bootstrap), allow(clashing_extern_declarations))]
217217
#[link_name = "objc_msgSend"]
218218
fn objc_msgSend_ul(obj: NsId, sel: Sel, ...) -> NsId;
219219
}

src/test/ui/issues/issue-1866.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// build-pass
22
#![allow(dead_code)]
33
#![allow(non_camel_case_types)]
4-
#![warn(clashing_extern_decl)]
4+
#![warn(clashing_extern_declarations)]
55

66
// pretty-expanded FIXME #23616
77

src/test/ui/issues/issue-1866.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ LL | pub fn rust_task_is_unwinding(rt: *const rust_task) -> bool;
1010
note: the lint level is defined here
1111
--> $DIR/issue-1866.rs:4:9
1212
|
13-
LL | #![warn(clashing_extern_decl)]
14-
| ^^^^^^^^^^^^^^^^^^^^
13+
LL | #![warn(clashing_extern_declarations)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
= note: expected `unsafe extern "C" fn(*const usize) -> bool`
1616
found `unsafe extern "C" fn(*const bool) -> bool`
1717

src/test/ui/issues/issue-5791.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22
#![allow(dead_code)]
3-
#![warn(clashing_extern_decl)]
3+
#![warn(clashing_extern_declarations)]
44
// pretty-expanded FIXME #23616
55

66
extern {

src/test/ui/issues/issue-5791.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ LL | | fn malloc2(len: i32, foo: i32) -> *const u8;
1212
note: the lint level is defined here
1313
--> $DIR/issue-5791.rs:3:9
1414
|
15-
LL | #![warn(clashing_extern_decl)]
16-
| ^^^^^^^^^^^^^^^^^^^^
15+
LL | #![warn(clashing_extern_declarations)]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= note: expected `unsafe extern "C" fn(i32) -> *const u8`
1818
found `unsafe extern "C" fn(i32, i32) -> *const u8`
1919

+57-30
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// check-pass
22
// aux-build:external_extern_fn.rs
33
#![crate_type = "lib"]
4-
#![warn(clashing_extern_decl)]
4+
#![warn(clashing_extern_declarations)]
55

66
extern crate external_extern_fn;
77

8-
extern {
8+
extern "C" {
99
fn clash(x: u8);
1010
fn no_clash(x: u8);
1111
}
1212

1313
fn redeclared_different_signature() {
14-
extern {
14+
extern "C" {
1515
fn clash(x: u64); //~ WARN `clash` redeclared with a different signature
1616
}
1717

@@ -22,20 +22,20 @@ fn redeclared_different_signature() {
2222
}
2323

2424
fn redeclared_same_signature() {
25-
extern {
25+
extern "C" {
2626
fn no_clash(x: u8);
2727
}
2828
unsafe {
2929
no_clash(123);
3030
}
3131
}
3232

33-
extern {
33+
extern "C" {
3434
fn extern_fn(x: u64);
3535
}
3636

3737
fn extern_clash() {
38-
extern {
38+
extern "C" {
3939
fn extern_fn(x: u32); //~ WARN `extern_fn` redeclared with a different signature
4040
}
4141
unsafe {
@@ -49,7 +49,7 @@ fn extern_no_clash() {
4949
crate::extern_fn(123);
5050
}
5151
}
52-
extern {
52+
extern "C" {
5353
fn some_other_new_name(x: i16);
5454

5555
#[link_name = "extern_link_name"]
@@ -60,7 +60,7 @@ extern {
6060
}
6161

6262
fn link_name_clash() {
63-
extern {
63+
extern "C" {
6464
fn extern_link_name(x: u32);
6565
//~^ WARN `extern_link_name` redeclared with a different signature
6666

@@ -75,85 +75,112 @@ fn link_name_clash() {
7575
}
7676

7777
mod a {
78-
extern {
78+
extern "C" {
7979
fn different_mod(x: u8);
8080
}
8181
}
8282
mod b {
83-
extern {
83+
extern "C" {
8484
fn different_mod(x: u64); //~ WARN `different_mod` redeclared with a different signature
8585
}
8686
}
8787

88-
extern {
88+
extern "C" {
8989
fn variadic_decl(x: u8, ...);
9090
}
9191

9292
fn variadic_clash() {
93-
extern {
93+
extern "C" {
9494
fn variadic_decl(x: u8); //~ WARN `variadic_decl` redeclared with a different signature
9595
}
9696
}
9797

9898
#[no_mangle]
99-
fn no_mangle_name(x: u8) { }
99+
fn no_mangle_name(x: u8) {}
100100

101-
extern {
101+
extern "C" {
102102
#[link_name = "unique_link_name"]
103103
fn link_name_specified(x: u8);
104104
}
105105

106106
fn tricky_no_clash() {
107-
extern {
107+
extern "C" {
108108
// Shouldn't warn, because the declaration above actually declares a different symbol (and
109109
// Rust's name resolution rules around shadowing will handle this gracefully).
110110
fn link_name_specified() -> u32;
111111

112112
// The case of a no_mangle name colliding with an extern decl (see #28179) is related but
113-
// shouldn't be reported by ClashingExternDecl, because this is an example of unmangled
114-
// name clash causing bad behaviour in functions with a defined body.
113+
// shouldn't be reported by ClashingExternDeclarations, because this is an example of
114+
// unmangled name clash causing bad behaviour in functions with a defined body.
115115
fn no_mangle_name() -> u32;
116116
}
117117
}
118118

119119
mod banana {
120120
mod one {
121-
#[repr(C)] struct Banana { weight: u32, length: u16 }
122-
extern "C" { fn weigh_banana(count: *const Banana) -> u64; }
121+
#[repr(C)]
122+
struct Banana {
123+
weight: u32,
124+
length: u16,
125+
}
126+
extern "C" {
127+
fn weigh_banana(count: *const Banana) -> u64;
128+
}
123129
}
124130

125131
mod two {
126-
#[repr(C)] struct Banana { weight: u32, length: u16 } // note: distinct type
127-
// This should not trigger the lint because two::Banana is structurally equivalent to
128-
// one::Banana.
129-
extern "C" { fn weigh_banana(count: *const Banana) -> u64; }
132+
#[repr(C)]
133+
struct Banana {
134+
weight: u32,
135+
length: u16,
136+
} // note: distinct type
137+
extern "C" {
138+
// This should not trigger the lint because two::Banana is structurally equivalent to
139+
// one::Banana.
140+
fn weigh_banana(count: *const Banana) -> u64;
141+
}
130142
}
131143

132144
mod three {
133145
// This _should_ trigger the lint, because repr(packed) should generate a struct that has a
134146
// different layout.
135-
#[repr(packed)] struct Banana { weight: u32, length: u16 }
147+
#[repr(packed)]
148+
struct Banana {
149+
weight: u32,
150+
length: u16,
151+
}
136152
#[allow(improper_ctypes)]
137-
extern "C" { fn weigh_banana(count: *const Banana) -> u64; }
138-
//~^ WARN `weigh_banana` redeclared with a different signature
153+
extern "C" {
154+
fn weigh_banana(count: *const Banana) -> u64;
155+
//~^ WARN `weigh_banana` redeclared with a different signature
156+
}
139157
}
140158
}
141159

142160
mod sameish_members {
143161
mod a {
144162
#[repr(C)]
145-
struct Point { x: i16, y: i16 }
163+
struct Point {
164+
x: i16,
165+
y: i16,
166+
}
146167

147-
extern "C" { fn draw_point(p: Point); }
168+
extern "C" {
169+
fn draw_point(p: Point);
170+
}
148171
}
149172
mod b {
150173
#[repr(C)]
151-
struct Point { coordinates: [i16; 2] }
174+
struct Point {
175+
coordinates: [i16; 2],
176+
}
152177

153178
// It's possible we are overconservative for this case, as accessing the elements of the
154179
// coordinates array might end up correctly accessing `.x` and `.y`. However, this may not
155180
// always be the case, for every architecture and situation. This is also a really odd
156181
// thing to do anyway.
157-
extern "C" { fn draw_point(p: Point); } //~ WARN `draw_point` redeclared with a different
182+
extern "C" {
183+
fn draw_point(p: Point); //~ WARN `draw_point` redeclared with a different
184+
}
158185
}
159186
}

src/test/ui/lint/clashing-extern-fn.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ LL | fn clash(x: u64);
1010
note: the lint level is defined here
1111
--> $DIR/clashing-extern-fn.rs:4:9
1212
|
13-
LL | #![warn(clashing_extern_decl)]
14-
| ^^^^^^^^^^^^^^^^^^^^
13+
LL | #![warn(clashing_extern_declarations)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
= note: expected `unsafe extern "C" fn(u8)`
1616
found `unsafe extern "C" fn(u64)`
1717

@@ -94,25 +94,25 @@ LL | fn variadic_decl(x: u8);
9494
found `unsafe extern "C" fn(u8)`
9595

9696
warning: `weigh_banana` redeclared with a different signature
97-
--> $DIR/clashing-extern-fn.rs:137:22
97+
--> $DIR/clashing-extern-fn.rs:154:13
9898
|
99-
LL | extern "C" { fn weigh_banana(count: *const Banana) -> u64; }
100-
| --------------------------------------------- `weigh_banana` previously declared here
99+
LL | fn weigh_banana(count: *const Banana) -> u64;
100+
| --------------------------------------------- `weigh_banana` previously declared here
101101
...
102-
LL | extern "C" { fn weigh_banana(count: *const Banana) -> u64; }
103-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
102+
LL | fn weigh_banana(count: *const Banana) -> u64;
103+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
104104
|
105105
= note: expected `unsafe extern "C" fn(*const banana::one::Banana) -> u64`
106106
found `unsafe extern "C" fn(*const banana::three::Banana) -> u64`
107107

108108
warning: `draw_point` redeclared with a different signature
109-
--> $DIR/clashing-extern-fn.rs:157:22
109+
--> $DIR/clashing-extern-fn.rs:183:13
110110
|
111-
LL | extern "C" { fn draw_point(p: Point); }
112-
| ------------------------ `draw_point` previously declared here
111+
LL | fn draw_point(p: Point);
112+
| ------------------------ `draw_point` previously declared here
113113
...
114-
LL | extern "C" { fn draw_point(p: Point); }
115-
| ^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
114+
LL | fn draw_point(p: Point);
115+
| ^^^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
116116
|
117117
= note: expected `unsafe extern "C" fn(sameish_members::a::Point)`
118118
found `unsafe extern "C" fn(sameish_members::b::Point)`

src/test/ui/lint/dead-code/lint-dead-code-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(unused_variables)]
22
#![allow(non_camel_case_types)]
3-
#![allow(clashing_extern_decl)]
3+
#![allow(clashing_extern_declarations)]
44
#![deny(dead_code)]
55

66
#![crate_type="lib"]

src/test/ui/parser/extern-abi-from-mac-literal-frag.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clashing_extern_decl)]
1+
#![allow(clashing_extern_declarations)]
22
// check-pass
33

44
// In this test we check that the parser accepts an ABI string when it

0 commit comments

Comments
 (0)