-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
83: Improve error message for #[repr(packed(N))] r=taiki-e a=taiki-e #34 can [already detect this](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=7331036de27faeb8354e367ef514c6c6), but this will generate better error messages. This also adds some tests related to `#[repr(packed)]`. Co-authored-by: Taiki Endo <[email protected]>
- Loading branch information
Showing
18 changed files
with
254 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
tests/ui/cfg/packed_sneaky.stderr → tests/ui/cfg/packed_sneaky-1.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// run-pass | ||
// aux-build:sneaky_macro.rs | ||
|
||
#[macro_use] | ||
extern crate sneaky_macro; | ||
|
||
use pin_project::pin_project; | ||
|
||
// #[cfg_attr(any(), repr(packed))] | ||
#[pin_project] | ||
#[hidden_repr_cfg_any(packed)] | ||
struct Foo { | ||
#[pin] | ||
field: u32, | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) | ||
--> $DIR/packed_sneaky-3.rs:10:1 | ||
| | ||
10 | #[pin_project] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/packed_sneaky-3.rs:10:1 | ||
| | ||
10 | #[pin_project] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> | ||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
error: #[pin_project] attribute may not be used on #[repr(packed)] types | ||
--> $DIR/packed.rs:6:8 | ||
| | ||
6 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] type | ||
6 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types | ||
| ^^^^^^ | ||
|
||
error: #[pin_project] attribute may not be used on #[repr(packed)] types | ||
--> $DIR/packed.rs:13:8 | ||
| | ||
13 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] type | ||
13 | #[repr(packed, C)] //~ ERROR may not be used on #[repr(packed)] types | ||
| ^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
error: #[pin_project] attribute may not be used on #[repr(packed(N))] types | ||
--> $DIR/packed.rs:21:8 | ||
| | ||
21 | #[repr(packed(2))] //~ ERROR may not be used on #[repr(packed(N))] types | ||
| ^^^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// compile-fail | ||
// aux-build:sneaky_macro.rs | ||
|
||
#[macro_use] | ||
extern crate sneaky_macro; | ||
|
||
use pin_project::{pin_project, pinned_drop, UnsafeUnpin}; | ||
use std::pin::Pin; | ||
|
||
#[pin_project] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
#[hidden_repr(packed)] | ||
struct A { | ||
#[pin] | ||
field: u32, | ||
} | ||
|
||
#[pin_project(UnsafeUnpin)] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
#[hidden_repr(packed)] | ||
struct C { | ||
#[pin] | ||
field: u32, | ||
} | ||
|
||
unsafe impl UnsafeUnpin for C {} | ||
|
||
#[pin_project(PinnedDrop)] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
#[hidden_repr(packed)] | ||
struct D { | ||
#[pin] | ||
field: u32, | ||
} | ||
|
||
#[pinned_drop] | ||
fn drop_d(_: Pin<&mut D>) {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) | ||
--> $DIR/packed_sneaky-1.rs:10:1 | ||
| | ||
10 | #[pin_project] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/packed_sneaky-1.rs:10:1 | ||
| | ||
10 | #[pin_project] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> | ||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior | ||
|
||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) | ||
--> $DIR/packed_sneaky-1.rs:17:1 | ||
| | ||
17 | #[pin_project(UnsafeUnpin)] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/packed_sneaky-1.rs:17:1 | ||
| | ||
17 | #[pin_project(UnsafeUnpin)] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> | ||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior | ||
|
||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) | ||
--> $DIR/packed_sneaky-1.rs:26:1 | ||
| | ||
26 | #[pin_project(PinnedDrop)] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/packed_sneaky-1.rs:26:1 | ||
| | ||
26 | #[pin_project(PinnedDrop)] //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> | ||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior | ||
|
||
error: aborting due to 3 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// compile-fail | ||
// aux-build:sneaky_macro.rs | ||
|
||
#[macro_use] | ||
extern crate sneaky_macro; | ||
|
||
use pin_project::pin_project; | ||
|
||
hidden_repr_macro! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
#[pin_project] | ||
struct B { | ||
#[pin] | ||
field: u32, | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error: #[pin_project] attribute may not be used on #[repr(packed)] types | ||
--> $DIR/packed_sneaky-2.rs:9:1 | ||
| | ||
9 | / hidden_repr_macro! { //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
10 | | #[pin_project] | ||
11 | | struct B { | ||
12 | | #[pin] | ||
13 | | field: u32, | ||
14 | | } | ||
15 | | } | ||
| | ^ in this macro invocation | ||
| |_| | ||
| | ||
|
||
error: aborting due to previous error | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// compile-fail | ||
|
||
#![deny(safe_packed_borrows)] | ||
|
||
// Refs: https://github.com/rust-lang/rust/issues/46043 | ||
|
||
#[repr(packed)] | ||
struct A { | ||
field: u32, | ||
} | ||
|
||
#[repr(packed(2))] | ||
struct B { | ||
field: u32, | ||
} | ||
|
||
fn foo() { | ||
let a = A { field: 1 }; | ||
&a.field; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
|
||
let b = B { field: 1 }; | ||
&b.field; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) | ||
--> $DIR/safe_packed_borrows.rs:17:5 | ||
| | ||
17 | &a.field; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/safe_packed_borrows.rs:1:9 | ||
| | ||
1 | #![deny(safe_packed_borrows)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> | ||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior | ||
|
||
error: borrow of packed field is unsafe and requires unsafe function or block (error E0133) | ||
--> $DIR/safe_packed_borrows.rs:20:5 | ||
| | ||
20 | &b.field; //~ ERROR borrow of packed field is unsafe and requires unsafe function or block | ||
| ^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> | ||
= note: fields of packed structs might be misaligned: dereferencing a misaligned pointer or even just creating a misaligned reference is undefined behavior | ||
|
||
error: aborting due to 2 previous errors | ||
|