Skip to content

Commit 06aeed6

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 c105896 commit 06aeed6

File tree

10 files changed

+119
-18
lines changed

10 files changed

+119
-18
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

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

13341334
// Instruction builders
1335-
|wrap pub(crate) fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
1335+
|wrap #[allow(clippy::mut_from_ref)] // FIXME?
1336+
pub(crate) fn LLVMCreateBuilderInContext(C: &Context) -> &mut Builder<'_>;
13361337
pub(crate) fn LLVMPositionBuilderAtEnd<'a>(Builder: &Builder<'a>, Block: &'a BasicBlock);
13371338
|wrap pub(crate) fn LLVMGetInsertBlock<'a>(Builder_: &Builder<'a>) -> &'a BasicBlock;
13381339
pub(crate) fn LLVMDisposeBuilder<'a>(Builder: &'a mut Builder<'a>);
@@ -2587,7 +2588,8 @@ unsafe extern "C" {
25872588
pub(crate) fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
25882589

25892590
pub(crate) fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
2590-
|wrap pub(crate) fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
2591+
|wrap #[allow(clippy::mut_from_ref)] // FIXME?
2592+
pub(crate) fn LLVMRustArchiveIteratorNew(AR: &Archive) -> &mut ArchiveIterator<'_>;
25912593
pub(crate) fn LLVMRustArchiveIteratorNext<'a>(
25922594
AIR: &ArchiveIterator<'a>,
25932595
) -> Option<&'a mut ArchiveChild<'a>>;
@@ -2702,7 +2704,8 @@ unsafe extern "C" {
27022704
Identifier: *const c_char,
27032705
) -> Option<&Module>;
27042706

2705-
|wrap pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
2707+
|wrap #[allow(clippy::mut_from_ref)] // FIXME?
2708+
pub(crate) fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
27062709
pub(crate) fn LLVMRustLinkerAdd(
27072710
linker: &Linker<'_>,
27082711
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
@@ -2042,7 +2042,8 @@ declare_lint! {
20422042
/// ### Example
20432043
///
20442044
/// ```rust
2045-
/// # #![unsafe(no_mangle)]
2045+
/// # #[unsafe(no_mangle)]
2046+
/// # #[used]
20462047
/// static mut PLUGIN_ABI_MIN_VERSION: &'static str = "0.0.5";
20472048
/// ```
20482049
///

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
@@ -220,13 +220,13 @@ LL | fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
220220
| ^^^^^^^^^^^^^^^^ help: change this to: `&str`
221221

222222
error: writing `&String` instead of `&str` involves a new object where a slice will do
223-
--> tests/ui/ptr_arg.rs:347:17
223+
--> tests/ui/ptr_arg.rs:348:17
224224
|
225225
LL | fn good(v1: &String, v2: &String) {
226226
| ^^^^^^^ help: change this to: `&str`
227227

228228
error: writing `&String` instead of `&str` involves a new object where a slice will do
229-
--> tests/ui/ptr_arg.rs:347:30
229+
--> tests/ui/ptr_arg.rs:348:30
230230
|
231231
LL | fn good(v1: &String, v2: &String) {
232232
| ^^^^^^^ 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
@@ -30,6 +30,7 @@ static GROUP_DESCRIPTIONS: &[(&str, &str)] = &[
3030
"unknown-or-malformed-diagnostic-attributes",
3131
"detects unknown or malformed diagnostic attributes",
3232
),
33+
("improper-c-boundaries", "Lints for points where rust code interacts with non-rust code"),
3334
];
3435

3536
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: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 `(usize) is 1..`, which is not FFI-safe
43+
--> $DIR/lint-pattern-types.rs:55:9
44+
|
45+
LL | h1: pattern_type!(usize is 1..),
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
47+
|
48+
= help: consider using the base type instead, or wrapping `(usize) is 1..` in an `Option<_>`
49+
= note: integer-pattern types with one disallowed value and no `Option` wrapping cannot have their value be provided by non-rust code
50+
51+
error: `extern` fn uses type `(usize) is 0..=4294967293`, which is not FFI-safe
52+
--> $DIR/lint-pattern-types.rs:56:9
53+
|
54+
LL | h2: pattern_type!(usize is ..USZM1),
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
56+
|
57+
= help: consider using the base type instead
58+
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
59+
60+
error: `extern` fn uses type `(isize) is -2147483647..`, which is not FFI-safe
61+
--> $DIR/lint-pattern-types.rs:58:9
62+
|
63+
LL | h4: pattern_type!(isize is ISZP1..),
64+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
65+
|
66+
= help: consider using the base type instead, or wrapping `(isize) is -2147483647..` in an `Option<_>`
67+
= note: integer-pattern types with one disallowed value and no `Option` wrapping cannot have their value be provided by non-rust code
68+
69+
error: `extern` fn uses type `char`, which is not FFI-safe
70+
--> $DIR/lint-pattern-types.rs:60:8
71+
|
72+
LL | h: pattern_type!(char is '\0'..),
73+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
74+
|
75+
= help: consider using `u32` or `libc::wchar_t` instead
76+
= note: the `char` type has no C equivalent
77+
78+
error: `extern` fn uses type `(char) is '\0'..`, which is not FFI-safe
79+
--> $DIR/lint-pattern-types.rs:60:8
80+
|
81+
LL | h: pattern_type!(char is '\0'..),
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
83+
|
84+
= help: consider using the base type instead
85+
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
86+
87+
error: aborting due to 9 previous errors
88+

tests/ui/lint/improper_ctypes/lint-pattern-types.stderr renamed to tests/ui/lint/improper_ctypes/lint-pattern-types.size64.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error: `extern` fn uses type `Option<(u32) is 0..>`, which is not FFI-safe
2-
--> $DIR/lint-pattern-types.rs:21:9
2+
--> $DIR/lint-pattern-types.rs:27:9
33
|
44
LL | ao: Option<pattern_type!(u32 is 0..)>,
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
66
|
77
= help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
88
= note: enum has no representation hint
99
note: the lint level is defined here
10-
--> $DIR/lint-pattern-types.rs:4:9
10+
--> $DIR/lint-pattern-types.rs:10:9
1111
|
1212
LL | #![deny(improper_c_fn_definitions)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
error: `extern` fn uses type `(u32) is 1..`, which is not FFI-safe
16-
--> $DIR/lint-pattern-types.rs:22:8
16+
--> $DIR/lint-pattern-types.rs:28:8
1717
|
1818
LL | b: pattern_type!(u32 is 1..),
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -22,7 +22,7 @@ LL | b: pattern_type!(u32 is 1..),
2222
= note: integer-pattern types with one disallowed value and no `Option` wrapping cannot have their value be provided by non-rust code
2323

2424
error: `extern` fn uses type `(u32) is 2..`, which is not FFI-safe
25-
--> $DIR/lint-pattern-types.rs:24:8
25+
--> $DIR/lint-pattern-types.rs:30:8
2626
|
2727
LL | c: pattern_type!(u32 is 2..),
2828
| ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -31,7 +31,7 @@ LL | c: pattern_type!(u32 is 2..),
3131
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
3232

3333
error: `extern` fn uses type `(u32) is 2..`, which is not FFI-safe
34-
--> $DIR/lint-pattern-types.rs:25:9
34+
--> $DIR/lint-pattern-types.rs:31:9
3535
|
3636
LL | co: Option<pattern_type!(u32 is 2..)>,
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -40,7 +40,7 @@ LL | co: Option<pattern_type!(u32 is 2..)>,
4040
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
4141

4242
error: `extern` fn uses type `(usize) is 1..`, which is not FFI-safe
43-
--> $DIR/lint-pattern-types.rs:49:9
43+
--> $DIR/lint-pattern-types.rs:55:9
4444
|
4545
LL | h1: pattern_type!(usize is 1..),
4646
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -49,7 +49,7 @@ LL | h1: pattern_type!(usize is 1..),
4949
= note: integer-pattern types with one disallowed value and no `Option` wrapping cannot have their value be provided by non-rust code
5050

5151
error: `extern` fn uses type `(usize) is 0..=18446744073709551613`, which is not FFI-safe
52-
--> $DIR/lint-pattern-types.rs:50:9
52+
--> $DIR/lint-pattern-types.rs:56:9
5353
|
5454
LL | h2: pattern_type!(usize is ..USZM1),
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -58,7 +58,7 @@ LL | h2: pattern_type!(usize is ..USZM1),
5858
= note: integer-pattern types with more than one disallowed value cannot have their value be provided by non-rust code
5959

6060
error: `extern` fn uses type `(isize) is -9223372036854775807..`, which is not FFI-safe
61-
--> $DIR/lint-pattern-types.rs:52:9
61+
--> $DIR/lint-pattern-types.rs:58:9
6262
|
6363
LL | h4: pattern_type!(isize is ISZP1..),
6464
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -67,7 +67,7 @@ LL | h4: pattern_type!(isize is ISZP1..),
6767
= note: integer-pattern types with one disallowed value and no `Option` wrapping cannot have their value be provided by non-rust code
6868

6969
error: `extern` fn uses type `char`, which is not FFI-safe
70-
--> $DIR/lint-pattern-types.rs:54:8
70+
--> $DIR/lint-pattern-types.rs:60:8
7171
|
7272
LL | h: pattern_type!(char is '\0'..),
7373
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
@@ -76,7 +76,7 @@ LL | h: pattern_type!(char is '\0'..),
7676
= note: the `char` type has no C equivalent
7777

7878
error: `extern` fn uses type `(char) is '\0'..`, which is not FFI-safe
79-
--> $DIR/lint-pattern-types.rs:54:8
79+
--> $DIR/lint-pattern-types.rs:60:8
8080
|
8181
LL | h: pattern_type!(char is '\0'..),
8282
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe

0 commit comments

Comments
 (0)