-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for `static_mut_ref` lint
- Loading branch information
Showing
12 changed files
with
220 additions
and
2 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
16 changes: 16 additions & 0 deletions
16
tests/ui/borrowck/borrowck-unsafe-static-mutable-borrows.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
warning: use of mutable static is discouraged | ||
--> $DIR/borrowck-unsafe-static-mutable-borrows.rs:19:30 | ||
| | ||
LL | let sfoo: *mut Foo = &mut SFOO; | ||
| ^^^^^^^^^ use of mutable static | ||
| | ||
= note: use of mutable static is a hard error from 2024 edition | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
= note: `#[warn(static_mut_ref)]` on by default | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let sfoo: *mut Foo = addr_of_mut!(SFOO); | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
||
warning: 1 warning emitted | ||
|
20 changes: 20 additions & 0 deletions
20
tests/ui/static/use_of_mutable_static_unsafe_block.e2015.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: use of mutable static is discouraged | ||
--> $DIR/use_of_mutable_static_unsafe_block.rs:18:18 | ||
| | ||
LL | let _y = &X; | ||
| ^^ use of mutable static | ||
| | ||
= note: use of mutable static is a hard error from 2024 edition | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
note: the lint level is defined here | ||
--> $DIR/use_of_mutable_static_unsafe_block.rs:8:9 | ||
| | ||
LL | #![deny(static_mut_ref)] | ||
| ^^^^^^^^^^^^^^ | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let _y = addr_of_mut!(X); | ||
| ~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|
20 changes: 20 additions & 0 deletions
20
tests/ui/static/use_of_mutable_static_unsafe_block.e2018.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: use of mutable static is discouraged | ||
--> $DIR/use_of_mutable_static_unsafe_block.rs:18:18 | ||
| | ||
LL | let _y = &X; | ||
| ^^ use of mutable static | ||
| | ||
= note: use of mutable static is a hard error from 2024 edition | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
note: the lint level is defined here | ||
--> $DIR/use_of_mutable_static_unsafe_block.rs:8:9 | ||
| | ||
LL | #![deny(static_mut_ref)] | ||
| ^^^^^^^^^^^^^^ | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let _y = addr_of_mut!(X); | ||
| ~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|
20 changes: 20 additions & 0 deletions
20
tests/ui/static/use_of_mutable_static_unsafe_block.e2021.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: use of mutable static is discouraged | ||
--> $DIR/use_of_mutable_static_unsafe_block.rs:18:18 | ||
| | ||
LL | let _y = &X; | ||
| ^^ use of mutable static | ||
| | ||
= note: use of mutable static is a hard error from 2024 edition | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
note: the lint level is defined here | ||
--> $DIR/use_of_mutable_static_unsafe_block.rs:8:9 | ||
| | ||
LL | #![deny(static_mut_ref)] | ||
| ^^^^^^^^^^^^^^ | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let _y = addr_of_mut!(X); | ||
| ~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|
15 changes: 15 additions & 0 deletions
15
tests/ui/static/use_of_mutable_static_unsafe_block.e2024.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0796]: use of mutable static is disallowed | ||
--> $DIR/use_of_mutable_static_unsafe_block.rs:18:18 | ||
| | ||
LL | let _y = &X; | ||
| ^^ use of mutable static | ||
| | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let _y = addr_of_mut!(X); | ||
| ~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0796`. |
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,28 @@ | ||
// revisions: e2015 e2018 e2021 e2024 | ||
|
||
// [e2015] edition:2015 | ||
// [e2018] edition:2018 | ||
// [e2021] edition:2021 | ||
// [e2024] compile-flags: --edition 2024 -Zunstable-options | ||
|
||
#![deny(static_mut_ref)] | ||
|
||
use std::ptr::addr_of_mut; | ||
|
||
fn main() { | ||
static mut X: i32 = 1; | ||
|
||
static mut FOO: [u8; 3] = [1, 2, 3]; | ||
|
||
unsafe { | ||
let _y = &X; | ||
//[e2024]~^ ERROR use of mutable static is disallowed | ||
//[e2021]~^^ ERROR use of mutable static is discouraged [static_mut_ref] | ||
//[e2018]~^^^ ERROR use of mutable static is discouraged [static_mut_ref] | ||
//[e2015]~^^^^ ERROR use of mutable static is discouraged [static_mut_ref] | ||
|
||
let _z = addr_of_mut!(X); | ||
|
||
let _ = FOO.len(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/ui/static/use_of_mutable_static_unsafe_fn.e2015.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: use of mutable static is discouraged | ||
--> $DIR/use_of_mutable_static_unsafe_fn.rs:14:14 | ||
| | ||
LL | let _y = &X; | ||
| ^^ use of mutable static | ||
| | ||
= note: use of mutable static is a hard error from 2024 edition | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
note: the lint level is defined here | ||
--> $DIR/use_of_mutable_static_unsafe_fn.rs:8:9 | ||
| | ||
LL | #![deny(static_mut_ref)] | ||
| ^^^^^^^^^^^^^^ | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let _y = addr_of_mut!(X); | ||
| ~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|
20 changes: 20 additions & 0 deletions
20
tests/ui/static/use_of_mutable_static_unsafe_fn.e2018.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: use of mutable static is discouraged | ||
--> $DIR/use_of_mutable_static_unsafe_fn.rs:14:14 | ||
| | ||
LL | let _y = &X; | ||
| ^^ use of mutable static | ||
| | ||
= note: use of mutable static is a hard error from 2024 edition | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
note: the lint level is defined here | ||
--> $DIR/use_of_mutable_static_unsafe_fn.rs:8:9 | ||
| | ||
LL | #![deny(static_mut_ref)] | ||
| ^^^^^^^^^^^^^^ | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let _y = addr_of_mut!(X); | ||
| ~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|
20 changes: 20 additions & 0 deletions
20
tests/ui/static/use_of_mutable_static_unsafe_fn.e2021.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: use of mutable static is discouraged | ||
--> $DIR/use_of_mutable_static_unsafe_fn.rs:14:14 | ||
| | ||
LL | let _y = &X; | ||
| ^^ use of mutable static | ||
| | ||
= note: use of mutable static is a hard error from 2024 edition | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
note: the lint level is defined here | ||
--> $DIR/use_of_mutable_static_unsafe_fn.rs:8:9 | ||
| | ||
LL | #![deny(static_mut_ref)] | ||
| ^^^^^^^^^^^^^^ | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let _y = addr_of_mut!(X); | ||
| ~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|
15 changes: 15 additions & 0 deletions
15
tests/ui/static/use_of_mutable_static_unsafe_fn.e2024.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0796]: use of mutable static is disallowed | ||
--> $DIR/use_of_mutable_static_unsafe_fn.rs:14:14 | ||
| | ||
LL | let _y = &X; | ||
| ^^ use of mutable static | ||
| | ||
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior | ||
help: use `addr_of_mut!` macro | ||
| | ||
LL | let _y = addr_of_mut!(X); | ||
| ~~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0796`. |
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,19 @@ | ||
// revisions: e2015 e2018 e2021 e2024 | ||
|
||
// [e2015] edition:2015 | ||
// [e2018] edition:2018 | ||
// [e2021] edition:2021 | ||
// [e2024] compile-flags: --edition 2024 -Zunstable-options | ||
|
||
#![deny(static_mut_ref)] | ||
|
||
fn main() {} | ||
|
||
unsafe fn _foo() { | ||
static mut X: i32 = 1; | ||
let _y = &X; | ||
//[e2024]~^ ERROR use of mutable static is disallowed | ||
//[e2021]~^^ ERROR use of mutable static is discouraged [static_mut_ref] | ||
//[e2018]~^^^ ERROR use of mutable static is discouraged [static_mut_ref] | ||
//[e2015]~^^^^ ERROR use of mutable static is discouraged [static_mut_ref] | ||
} |