Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3f661d2
borrowck `DefId` -> `LocalDefId`
lcnr May 11, 2020
a8ed9aa
impl From<[T; N]> for Box<[T]>
pickfire Apr 13, 2020
eccaa01
rustc_target: Add a target spec option for static-pie support
petrochenkov May 1, 2020
96a466c
linker: Support `-static-pie` and `-static -shared`
petrochenkov May 1, 2020
08df311
librustc_mir: Add support for const fn offset/arith_offset
josephlr Apr 24, 2020
9b3dfd8
core: Make pointer offset methods "const fn"
josephlr Apr 24, 2020
88a37a2
test/ui/consts: Add tests for const ptr offsets
josephlr May 15, 2020
6b20f58
miri_unleached: We now allow offset in const fn
josephlr May 18, 2020
55577b4
librustc_mir: Add back use statement
josephlr May 25, 2020
6367b54
librustc_middle: Add function for computing unsigned abs
josephlr May 26, 2020
71ef841
Add checks and tests for computing abs(offset_bytes)
josephlr May 26, 2020
822ad87
Add Peekable::next_if
jyn514 May 18, 2020
a977df3
Implement RFC 2585
LeSeulArtichaut May 3, 2020
594c499
Add tests
LeSeulArtichaut May 3, 2020
bb67915
Apply suggestions from code review
LeSeulArtichaut May 13, 2020
3ce9d5c
Add more cases to the test
LeSeulArtichaut May 14, 2020
b3e012b
Fix inverted `if` condition
LeSeulArtichaut May 18, 2020
a41f763
Use the lowest of `unsafe_op_in_unsafe_fn` and `safe_borrow_packed` f…
LeSeulArtichaut May 18, 2020
a3bae5c
Fix wrong conflict resolution
LeSeulArtichaut May 19, 2020
925d5ac
Fix and bless tests
LeSeulArtichaut May 21, 2020
9671b44
Add tests for packed borrows in unsafe fns
LeSeulArtichaut May 22, 2020
3599ada
Mark deduplicated errors as expected in gate test
LeSeulArtichaut May 23, 2020
4a538d3
Do not hardcode lint name
LeSeulArtichaut May 23, 2020
e3d27ec
Add explanation about taking the minimum of the two lints
LeSeulArtichaut May 23, 2020
1b08850
Fix import
LeSeulArtichaut May 23, 2020
63066c0
Use `LintId`s to check for gated lints
LeSeulArtichaut May 23, 2020
db684be
Whitelist `unsafe_op_in_unsafe_fn` in rustdoc
LeSeulArtichaut May 27, 2020
3fea832
Fix spacing of expected/found notes without a label
estebank Dec 20, 2019
5ba2220
Name `RegionKind::ReVar` lifetimes in diagnostics
estebank Dec 20, 2019
eb0f4d5
Tweak output for mismatched impl item
estebank Dec 22, 2019
3811232
review comments
estebank Dec 23, 2019
2e2f820
review comment: use FxIndexSet
estebank Dec 27, 2019
d0d30b0
fix rebase
estebank Jan 7, 2020
2b35247
Modify wording
estebank Feb 17, 2020
500504c
fix rebase
estebank Mar 30, 2020
c52dbbc
fix rebase
estebank Apr 14, 2020
7d5415b
Add additional checks for isize overflow
josephlr May 27, 2020
cb6408a
Fix rebase
estebank May 28, 2020
f213acf
review comments: change wording and visual output
estebank May 28, 2020
0e3b31c
Update src/librustdoc/core.rs
nikomatsakis May 28, 2020
1bd6970
Account for `Self` as a type param
estebank May 28, 2020
ce10b6d
Rollup merge of #67460 - estebank:named-lts, r=nikomatsakis
RalfJung May 29, 2020
de90e0d
Rollup merge of #71095 - pickfire:box-from-array, r=dtolnay
RalfJung May 29, 2020
b014e61
Rollup merge of #71500 - josephlr:offset, r=oli-obk,RalfJung
RalfJung May 29, 2020
b08168e
Rollup merge of #71804 - petrochenkov:static-pie, r=cuviper
RalfJung May 29, 2020
4e2351e
Rollup merge of #71862 - LeSeulArtichaut:unsafe-block-in-unsafe-fn, r…
RalfJung May 29, 2020
92329c7
Rollup merge of #72103 - lcnr:borrowck-localdefid, r=jonas-schievink
RalfJung May 29, 2020
783cfb1
Rollup merge of #72310 - jyn514:peekable-next-if, r=dtolnay
RalfJung May 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix and bless tests
  • Loading branch information
LeSeulArtichaut committed May 27, 2020
commit 925d5ac45f4a44dd61f1ebd4b7bd3cc89fcb2b5f
71 changes: 59 additions & 12 deletions src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(unsafe_block_in_unsafe_fn)]
#![warn(unsafe_op_in_unsafe_fn)]
#![deny(unsafe_op_in_unsafe_fn)]
#![deny(unused_unsafe)]
#![deny(safe_packed_borrows)]

Expand All @@ -14,18 +14,34 @@ pub struct Packed {

const PACKED: Packed = Packed { data: &0 };

unsafe fn foo() {
unsafe fn deny_level() {
unsf();
//~^ WARNING call to unsafe function is unsafe and requires unsafe block
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
*PTR;
//~^ WARNING dereference of raw pointer is unsafe and requires unsafe block
//~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
VOID = ();
//~^ WARNING use of mutable static is unsafe and requires unsafe block
&PACKED.data; // the level for the `safe_packed_borrows` lint is ignored
//~^ WARNING borrow of packed field is unsafe and requires unsafe block
//~^ ERROR use of mutable static is unsafe and requires unsafe block
&PACKED.data;
//~^ ERROR borrow of packed field is unsafe and requires unsafe block
//~| WARNING this was previously accepted by the compiler but is being phased out
}

unsafe fn bar() {
// Check that `unsafe_op_in_unsafe_fn` works starting from the `warn` level.
#[warn(unsafe_op_in_unsafe_fn)]
#[deny(warnings)]
unsafe fn warning_level() {
unsf();
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
*PTR;
//~^ ERROR dereference of raw pointer is unsafe and requires unsafe block
VOID = ();
//~^ ERROR use of mutable static is unsafe and requires unsafe block
&PACKED.data;
//~^ ERROR borrow of packed field is unsafe and requires unsafe block
//~| WARNING this was previously accepted by the compiler but is being phased out
}

unsafe fn explicit_block() {
// no error
unsafe {
unsf();
Expand All @@ -35,13 +51,25 @@ unsafe fn bar() {
}
}

unsafe fn baz() {
unsafe fn two_explicit_blocks() {
unsafe { unsafe { unsf() } }
//~^ ERROR unnecessary `unsafe` block
}

#[warn(safe_packed_borrows)]
unsafe fn warn_packed_borrows() {
&PACKED.data;
//~^ WARNING borrow of packed field is unsafe and requires unsafe block
//~| WARNING this was previously accepted by the compiler but is being phased out
}

#[allow(safe_packed_borrows)]
unsafe fn allow_packed_borrows() {
&PACKED.data; // `safe_packed_borrows` is allowed, no error
}

#[allow(unsafe_op_in_unsafe_fn)]
unsafe fn qux() {
unsafe fn allow_level() {
// lint allowed -> no error
unsf();
*PTR;
Expand All @@ -52,7 +80,26 @@ unsafe fn qux() {
//~^ ERROR unnecessary `unsafe` block
}

unsafe fn nested_allow_level() {
#[allow(unsafe_op_in_unsafe_fn)]
{
// lint allowed -> no error
unsf();
*PTR;
VOID = ();
&PACKED.data;

unsafe { unsf() }
//~^ ERROR unnecessary `unsafe` block
}
}

fn main() {
unsf()
//~^ ERROR call to unsafe function is unsafe and requires unsafe function or block
unsf();
//~^ ERROR call to unsafe function is unsafe and requires unsafe block
#[allow(unsafe_op_in_unsafe_fn)]
{
unsf();
//~^ ERROR call to unsafe function is unsafe and requires unsafe function or block
}
}
118 changes: 109 additions & 9 deletions src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,89 @@
warning: call to unsafe function is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:8:5
error: call to unsafe function is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:18:5
|
LL | unsf();
| ^^^^^^ call to unsafe function
|
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:2:9
|
LL | #![warn(unsafe_op_in_unsafe_fn)]
LL | #![deny(unsafe_op_in_unsafe_fn)]
| ^^^^^^^^^^^^^^^^^^^^^^
= note: consult the function's documentation for information on how to avoid undefined behavior

error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:20:5
|
LL | *PTR;
| ^^^^ dereference of raw pointer
|
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior

error: use of mutable static is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:22:5
|
LL | VOID = ();
| ^^^^^^^^^ use of mutable static
|
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior

error: borrow of packed field is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:24:5
|
LL | &PACKED.data;
| ^^^^^^^^^^^^ borrow of packed field
|
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:4:9
|
LL | #![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: call to unsafe function is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:33:5
|
LL | unsf();
| ^^^^^^ call to unsafe function
|
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:31:8
|
LL | #[deny(warnings)]
| ^^^^^^^^
= note: `#[deny(unsafe_op_in_unsafe_fn)]` implied by `#[deny(warnings)]`
= note: consult the function's documentation for information on how to avoid undefined behavior

error: dereference of raw pointer is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:35:5
|
LL | *PTR;
| ^^^^ dereference of raw pointer
|
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior

error: use of mutable static is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:37:5
|
LL | VOID = ();
| ^^^^^^^^^ use of mutable static
|
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior

error: borrow of packed field is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:39:5
|
LL | &PACKED.data;
| ^^^^^^^^^^^^ borrow of packed field
|
= 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: unnecessary `unsafe` block
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:17:14
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:55:14
|
LL | unsafe { unsafe { unsf() } }
| ------ ^^^^^^ unnecessary `unsafe` block
Expand All @@ -25,20 +96,49 @@ note: the lint level is defined here
LL | #![deny(unused_unsafe)]
| ^^^^^^^^^^^^^

warning: borrow of packed field is unsafe and requires unsafe block (error E0133)
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:61:5
|
LL | &PACKED.data;
| ^^^^^^^^^^^^ borrow of packed field
|
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:59:8
|
LL | #[warn(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: unnecessary `unsafe` block
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:25:5
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:79:5
|
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:30:5
error: unnecessary `unsafe` block
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:92:9
|
LL | unsf()
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block

error[E0133]: call to unsafe function is unsafe and requires unsafe block
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:98:5
|
LL | unsf();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to 3 previous errors; 1 warning emitted
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:102:9
|
LL | unsf();
| ^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior

error: aborting due to 13 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0133`.