Skip to content

Commit ee6f1cd

Browse files
committed
lint ImproperCTypes: changes to pass CI [...]
- make clippy happy about the changes in rust_codegen_llvm - split a test stderr into 32bit and 64bit - fix some documentation
1 parent 882853e commit ee6f1cd

File tree

10 files changed

+191
-26
lines changed

10 files changed

+191
-26
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,8 @@ unsafe extern "C" {
13061306
);
13071307

13081308
// Instruction builders
1309-
|wrap pub(crate) fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
1309+
|wrap #[allow(clippy::mut_from_ref)] // FIXME?
1310+
pub(crate) fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
13101311
pub(crate) fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock);
13111312
|wrap pub(crate) fn LLVMGetInsertBlock<'a>(Builder_: &Builder<'a>) -> &'a BasicBlock;
13121313
pub(crate) fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
@@ -2566,7 +2567,8 @@ unsafe extern "C" {
25662567
pub(crate) fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
25672568

25682569
pub(crate) fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
2569-
|wrap pub(crate) fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
2570+
|wrap #[allow(clippy::mut_from_ref)] // FIXME?
2571+
pub(crate) fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
25702572
pub(crate) fn LLVMRustArchiveIteratorNext<'a>(
25712573
AIR: &ArchiveIterator<'a>,
25722574
) -> Option<&'a mut ArchiveChild<'a>>;
@@ -2687,7 +2689,8 @@ unsafe extern "C" {
26872689
out_len: &mut usize,
26882690
) -> *const u8;
26892691

2690-
|wrap pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
2692+
|wrap #[allow(clippy::mut_from_ref)] // FIXME?
2693+
pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
26912694
pub(crate) fn LLVMRustLinkerAdd(
26922695
linker: &Linker<'_>,
26932696
bytecode: *const c_char,

compiler/rustc_lint/src/types/improper_ctypes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2038,7 +2038,8 @@ declare_lint! {
20382038
/// ### Example
20392039
///
20402040
/// ```rust
2041-
/// # #![unsafe(no_mangle)]
2041+
/// # #[unsafe(no_mangle)]
2042+
/// # #[used]
20422043
/// static mut PLUGIN_ABI_MIN_VERSION: &'static str = "0.0.5";
20432044
/// ```
20442045
///

src/tools/clippy/tests/ui/boxed_local.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ mod issue_3739 {
171171
/// Issue #5542
172172
///
173173
/// This shouldn't warn for `boxed_local` as it is intended to called from non-Rust code.
174-
pub extern "C" fn do_not_warn_me(_c_pointer: Box<String>) -> () {}
174+
pub extern "C" fn do_not_warn_me(_c_pointer: Option<Box<String>>) -> () {}
175175

176176
#[allow(missing_abi)]
177177
#[rustfmt::skip] // Forces rustfmt to not add ABI
178-
pub extern fn do_not_warn_me_no_abi(_c_pointer: Box<String>) -> () {}
178+
pub extern fn do_not_warn_me_no_abi(_c_pointer: Option<Box<String>>) -> () {}
179179

180180
// Issue #4804 - default implementation in trait
181181
mod issue4804 {

src/tools/clippy/tests/ui/ptr_arg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ mod issue_9218 {
317317
}
318318
}
319319

320+
#[allow(improper_c_fn_definitions)]
320321
mod issue_11181 {
321322
extern "C" fn allowed(_v: &Vec<u32>) {}
322323

src/tools/clippy/tests/ui/ptr_arg.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,13 @@ LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
229229
| ^^^^^^^^^^^^^^^^ help: change this to: `&str`
230230

231231
error: writing `&String` instead of `&str` involves a new object where a slice will do
232-
--> tests/ui/ptr_arg.rs:347:17
232+
--> tests/ui/ptr_arg.rs:348:17
233233
|
234234
LL | fn good(v1: &String, v2: &String) {
235235
| ^^^^^^^ help: change this to: `&str`
236236

237237
error: writing `&String` instead of `&str` involves a new object where a slice will do
238-
--> tests/ui/ptr_arg.rs:347:30
238+
--> tests/ui/ptr_arg.rs:348:30
239239
|
240240
LL | fn good(v1: &String, v2: &String) {
241241
| ^^^^^^^ help: change this to: `&str`

src/tools/lint-docs/src/groups.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static GROUP_DESCRIPTIONS: &[(&str, &str)] = &[
2626
"Lints that detect identifiers which will be come keywords in later editions",
2727
),
2828
("deprecated-safe", "Lints for functions which were erroneously marked as safe in the past"),
29+
("improper-c-boundaries", "Lints for points where rust code interacts with non-rust code"),
2930
];
3031

3132
type LintGroups = BTreeMap<String, BTreeSet<String>>;

src/tools/miri/tests/fail/function_calls/exported_symbol_wrong_type.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#[no_mangle]
2+
#[allow(improper_c_var_definitions)]
23
static FOO: () = ();
34

45
fn main() {

tests/ui/lint/improper_ctypes/lint-pattern-types.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//@ revisions: size64 size32
2+
//@[size64] only-64bit
3+
//@[size32] only-32bit
4+
// (this is needed because stderr writes out usize::MAX-1)
5+
6+
17
#![feature(pattern_types, rustc_attrs)]
28
#![feature(pattern_type_macro)]
39
#![feature(pattern_type_range_trait,const_trait_impl)]
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
error: `extern` fn uses type `Option<(u32) is 0..>`, which is not FFI-safe
2+
--> $DIR/lint-pattern-types.rs:27:9
3+
|
4+
LL | ao: Option<pattern_type!(u32 is 0..)>,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
6+
|
7+
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
8+
= note: enum has no representation hint
9+
note: the lint level is defined here
10+
--> $DIR/lint-pattern-types.rs:10:9
11+
|
12+
LL | #![deny(improper_c_fn_definitions)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
error: `extern` fn uses type `(u32) is 1..`, which is not FFI-safe
16+
--> $DIR/lint-pattern-types.rs:28:8
17+
|
18+
LL | b: pattern_type!(u32 is 1..),
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
20+
|
21+
= help: consider using the base type instead, or wrapping `(u32) is 1..` in an `Option<_>`
22+
= note: integer-pattern types with one disallowed value and no `Option` wrapping cannot have their value be provided by non-rust code
23+
24+
error: `extern` fn uses type `(u32) is 2..`, which is not FFI-safe
25+
--> $DIR/lint-pattern-types.rs:30:8
26+
|
27+
LL | c: pattern_type!(u32 is 2..),
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
29+
|
30+
= help: consider using the base type instead
31+
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
32+
33+
error: `extern` fn uses type `(u32) is 2..`, which is not FFI-safe
34+
--> $DIR/lint-pattern-types.rs:31:9
35+
|
36+
LL | co: Option<pattern_type!(u32 is 2..)>,
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
38+
|
39+
= help: consider using the base type instead
40+
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
41+
42+
error: `extern` fn uses type `i128`, which is not FFI-safe
43+
--> $DIR/lint-pattern-types.rs:36:9
44+
|
45+
LL | e3: Option<pattern_type!(i128 is ..0x7fffffff_ffffffff_ffffffff_ffffffff)>,
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
47+
|
48+
= note: 128-bit integers don't currently have a known stable ABI
49+
50+
error: `extern` fn uses type `u128`, which is not FFI-safe
51+
--> $DIR/lint-pattern-types.rs:38:9
52+
|
53+
LL | e4: Option<pattern_type!(u128 is ..0xffffffff_ffffffff_ffffffff_ffffffff)>,
54+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
55+
|
56+
= note: 128-bit integers don't currently have a known stable ABI
57+
58+
error: `extern` fn uses type `i128`, which is not FFI-safe
59+
--> $DIR/lint-pattern-types.rs:42:9
60+
|
61+
LL | f3: Option<pattern_type!(i128 is -0x7fffffff_ffffffff_ffffffff_ffffffff..)>,
62+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
63+
|
64+
= note: 128-bit integers don't currently have a known stable ABI
65+
66+
error: `extern` fn uses type `u128`, which is not FFI-safe
67+
--> $DIR/lint-pattern-types.rs:44:9
68+
|
69+
LL | f4: Option<pattern_type!(u128 is 1..)>,
70+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
71+
|
72+
= note: 128-bit integers don't currently have a known stable ABI
73+
74+
error: `extern` fn uses type `i128`, which is not FFI-safe
75+
--> $DIR/lint-pattern-types.rs:52:10
76+
|
77+
LL | g31: Option<pattern_type!(i128 is ..-2 | -1..)>,
78+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
79+
|
80+
= note: 128-bit integers don't currently have a known stable ABI
81+
82+
error: `extern` fn uses type `i128`, which is not FFI-safe
83+
--> $DIR/lint-pattern-types.rs:54:10
84+
|
85+
LL | g32: Option<pattern_type!(i128 is ..-1 | 0..)>,
86+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
87+
|
88+
= note: 128-bit integers don't currently have a known stable ABI
89+
90+
error: `extern` fn uses type `i128`, which is not FFI-safe
91+
--> $DIR/lint-pattern-types.rs:56:10
92+
|
93+
LL | g33: Option<pattern_type!(i128 is ..0 | 1..)>,
94+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
95+
|
96+
= note: 128-bit integers don't currently have a known stable ABI
97+
98+
error: `extern` fn uses type `i128`, which is not FFI-safe
99+
--> $DIR/lint-pattern-types.rs:58:10
100+
|
101+
LL | g34: Option<pattern_type!(i128 is ..1 | 2..)>,
102+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
103+
|
104+
= note: 128-bit integers don't currently have a known stable ABI
105+
106+
error: `extern` fn uses type `(usize) is 1..`, which is not FFI-safe
107+
--> $DIR/lint-pattern-types.rs:64:9
108+
|
109+
LL | h1: pattern_type!(usize is 1..),
110+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
111+
|
112+
= help: consider using the base type instead, or wrapping `(usize) is 1..` in an `Option<_>`
113+
= note: integer-pattern types with one disallowed value and no `Option` wrapping cannot have their value be provided by non-rust code
114+
115+
error: `extern` fn uses type `(usize) is 0..=4294967293`, which is not FFI-safe
116+
--> $DIR/lint-pattern-types.rs:65:9
117+
|
118+
LL | h2: pattern_type!(usize is ..USZM1),
119+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
120+
|
121+
= help: consider using the base type instead
122+
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
123+
124+
error: `extern` fn uses type `(isize) is -2147483647..`, which is not FFI-safe
125+
--> $DIR/lint-pattern-types.rs:67:9
126+
|
127+
LL | h4: pattern_type!(isize is ISZP1..),
128+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
129+
|
130+
= help: consider using the base type instead, or wrapping `(isize) is -2147483647..` in an `Option<_>`
131+
= note: integer-pattern types with one disallowed value and no `Option` wrapping cannot have their value be provided by non-rust code
132+
133+
error: `extern` fn uses type `char`, which is not FFI-safe
134+
--> $DIR/lint-pattern-types.rs:69:8
135+
|
136+
LL | h: pattern_type!(char is '\0'..),
137+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
138+
|
139+
= help: consider using `u32` or `libc::wchar_t` instead
140+
= note: the `char` type has no C equivalent
141+
142+
error: `extern` fn uses type `(char) is '\0'..`, which is not FFI-safe
143+
--> $DIR/lint-pattern-types.rs:69:8
144+
|
145+
LL | h: pattern_type!(char is '\0'..),
146+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
147+
|
148+
= help: consider using the base type instead
149+
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
150+
151+
error: aborting due to 17 previous errors
152+

0 commit comments

Comments
 (0)