diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-06-26 16:01:38 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-06-26 16:01:45 +0000 |
| commit | 86c8eae7745b47ada8305dcdac16b7f2dbdd68c9 (patch) | |
| tree | 5106049c25a1627cd237af19ac12f6fe479577de /tests/ui/static | |
| parent | 5988078aa20bf642bc1bbab15a45ac5cb74e77e2 (diff) | |
| download | rust-86c8eae7745b47ada8305dcdac16b7f2dbdd68c9.tar.gz rust-86c8eae7745b47ada8305dcdac16b7f2dbdd68c9.zip | |
Automatically taint InferCtxt when errors are emitted
Diffstat (limited to 'tests/ui/static')
9 files changed, 57 insertions, 363 deletions
diff --git a/tests/ui/static/reference-of-mut-static-unsafe-fn.rs b/tests/ui/static/reference-of-mut-static-unsafe-fn.rs deleted file mode 100644 index 5652703a271..00000000000 --- a/tests/ui/static/reference-of-mut-static-unsafe-fn.rs +++ /dev/null @@ -1,26 +0,0 @@ -//@ compile-flags: --edition 2024 -Z unstable-options - -fn main() {} - -unsafe fn _foo() { - static mut X: i32 = 1; - static mut Y: i32 = 1; - - let _y = &X; - //~^ ERROR creating a shared reference to a mutable static [E0796] - - let ref _a = X; - //~^ ERROR creating a shared reference to a mutable static [E0796] - - let ref mut _a = X; - //~^ ERROR creating a mutable reference to a mutable static [E0796] - - let (_b, _c) = (&X, &mut Y); - //~^ ERROR creating a shared reference to a mutable static [E0796] - //~^^ ERROR creating a mutable reference to a mutable static [E0796] - - foo(&X); - //~^ ERROR creating a shared reference to a mutable static [E0796] -} - -fn foo<'a>(_x: &'a i32) {} diff --git a/tests/ui/static/reference-of-mut-static-unsafe-fn.stderr b/tests/ui/static/reference-of-mut-static-unsafe-fn.stderr deleted file mode 100644 index 5675d313e07..00000000000 --- a/tests/ui/static/reference-of-mut-static-unsafe-fn.stderr +++ /dev/null @@ -1,75 +0,0 @@ -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static-unsafe-fn.rs:9:14 - | -LL | let _y = &X; - | ^^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let _y = addr_of!(X); - | ~~~~~~~~~~~ - -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static-unsafe-fn.rs:12:18 - | -LL | let ref _a = X; - | ^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let ref _a = addr_of!(X); - | ~~~~~~~~~~~ - -error[E0796]: creating a mutable reference to a mutable static - --> $DIR/reference-of-mut-static-unsafe-fn.rs:15:22 - | -LL | let ref mut _a = X; - | ^ mutable reference to mutable static - | - = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior -help: use `addr_of_mut!` instead to create a raw pointer - | -LL | let ref mut _a = addr_of_mut!(X); - | ~~~~~~~~~~~~~~~ - -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static-unsafe-fn.rs:18:21 - | -LL | let (_b, _c) = (&X, &mut Y); - | ^^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let (_b, _c) = (addr_of!(X), &mut Y); - | ~~~~~~~~~~~ - -error[E0796]: creating a mutable reference to a mutable static - --> $DIR/reference-of-mut-static-unsafe-fn.rs:18:25 - | -LL | let (_b, _c) = (&X, &mut Y); - | ^^^^^^ mutable reference to mutable static - | - = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior -help: use `addr_of_mut!` instead to create a raw pointer - | -LL | let (_b, _c) = (&X, addr_of_mut!(Y)); - | ~~~~~~~~~~~~~~~ - -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static-unsafe-fn.rs:22:9 - | -LL | foo(&X); - | ^^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | foo(addr_of!(X)); - | ~~~~~~~~~~~ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0796`. diff --git a/tests/ui/static/reference-of-mut-static.e2021.stderr b/tests/ui/static/reference-of-mut-static.e2021.stderr deleted file mode 100644 index f7ad51b6157..00000000000 --- a/tests/ui/static/reference-of-mut-static.e2021.stderr +++ /dev/null @@ -1,91 +0,0 @@ -error: creating a shared reference to mutable static is discouraged - --> $DIR/reference-of-mut-static.rs:16:18 - | -LL | let _y = &X; - | ^^ shared reference to mutable static - | - = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447> - = note: this will be a hard error in the 2024 edition - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -note: the lint level is defined here - --> $DIR/reference-of-mut-static.rs:6:9 - | -LL | #![deny(static_mut_refs)] - | ^^^^^^^^^^^^^^^ -help: use `addr_of!` instead to create a raw pointer - | -LL | let _y = addr_of!(X); - | ~~~~~~~~~~~ - -error: creating a mutable reference to mutable static is discouraged - --> $DIR/reference-of-mut-static.rs:20:18 - | -LL | let _y = &mut X; - | ^^^^^^ mutable reference to mutable static - | - = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447> - = note: this will be a hard error in the 2024 edition - = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior -help: use `addr_of_mut!` instead to create a raw pointer - | -LL | let _y = addr_of_mut!(X); - | ~~~~~~~~~~~~~~~ - -error: creating a shared reference to mutable static is discouraged - --> $DIR/reference-of-mut-static.rs:28:22 - | -LL | let ref _a = X; - | ^ shared reference to mutable static - | - = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447> - = note: this will be a hard error in the 2024 edition - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let ref _a = addr_of!(X); - | ~~~~~~~~~~~ - -error: creating a shared reference to mutable static is discouraged - --> $DIR/reference-of-mut-static.rs:32:25 - | -LL | let (_b, _c) = (&X, &Y); - | ^^ shared reference to mutable static - | - = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447> - = note: this will be a hard error in the 2024 edition - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let (_b, _c) = (addr_of!(X), &Y); - | ~~~~~~~~~~~ - -error: creating a shared reference to mutable static is discouraged - --> $DIR/reference-of-mut-static.rs:32:29 - | -LL | let (_b, _c) = (&X, &Y); - | ^^ shared reference to mutable static - | - = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447> - = note: this will be a hard error in the 2024 edition - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let (_b, _c) = (&X, addr_of!(Y)); - | ~~~~~~~~~~~ - -error: creating a shared reference to mutable static is discouraged - --> $DIR/reference-of-mut-static.rs:38:13 - | -LL | foo(&X); - | ^^ shared reference to mutable static - | - = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447> - = note: this will be a hard error in the 2024 edition - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | foo(addr_of!(X)); - | ~~~~~~~~~~~ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/static/reference-of-mut-static.e2024.stderr b/tests/ui/static/reference-of-mut-static.e2024.stderr deleted file mode 100644 index 6205c10ac41..00000000000 --- a/tests/ui/static/reference-of-mut-static.e2024.stderr +++ /dev/null @@ -1,75 +0,0 @@ -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static.rs:16:18 - | -LL | let _y = &X; - | ^^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let _y = addr_of!(X); - | ~~~~~~~~~~~ - -error[E0796]: creating a mutable reference to a mutable static - --> $DIR/reference-of-mut-static.rs:20:18 - | -LL | let _y = &mut X; - | ^^^^^^ mutable reference to mutable static - | - = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior -help: use `addr_of_mut!` instead to create a raw pointer - | -LL | let _y = addr_of_mut!(X); - | ~~~~~~~~~~~~~~~ - -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static.rs:28:22 - | -LL | let ref _a = X; - | ^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let ref _a = addr_of!(X); - | ~~~~~~~~~~~ - -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static.rs:32:25 - | -LL | let (_b, _c) = (&X, &Y); - | ^^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let (_b, _c) = (addr_of!(X), &Y); - | ~~~~~~~~~~~ - -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static.rs:32:29 - | -LL | let (_b, _c) = (&X, &Y); - | ^^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | let (_b, _c) = (&X, addr_of!(Y)); - | ~~~~~~~~~~~ - -error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-of-mut-static.rs:38:13 - | -LL | foo(&X); - | ^^ shared reference to mutable static - | - = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior -help: use `addr_of!` instead to create a raw pointer - | -LL | foo(addr_of!(X)); - | ~~~~~~~~~~~ - -error: aborting due to 6 previous errors - -For more information about this error, try `rustc --explain E0796`. diff --git a/tests/ui/static/reference-of-mut-static.rs b/tests/ui/static/reference-of-mut-static.rs deleted file mode 100644 index af2cab7dd87..00000000000 --- a/tests/ui/static/reference-of-mut-static.rs +++ /dev/null @@ -1,50 +0,0 @@ -//@ revisions: e2021 e2024 - -//@ [e2021] edition:2021 -//@ [e2024] compile-flags: --edition 2024 -Z unstable-options - -#![deny(static_mut_refs)] - -use std::ptr::{addr_of, addr_of_mut}; - -fn main() { - static mut X: i32 = 1; - - static mut Y: i32 = 1; - - unsafe { - let _y = &X; - //[e2024]~^ ERROR creating a shared reference to a mutable static [E0796] - //[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs] - - let _y = &mut X; - //[e2024]~^ ERROR creating a mutable reference to a mutable static [E0796] - //[e2021]~^^ ERROR mutable reference to mutable static is discouraged [static_mut_refs] - - let _z = addr_of_mut!(X); - - let _p = addr_of!(X); - - let ref _a = X; - //[e2024]~^ ERROR creating a shared reference to a mutable static [E0796] - //[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs] - - let (_b, _c) = (&X, &Y); - //[e2024]~^ ERROR creating a shared reference to a mutable static [E0796] - //[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs] - //[e2024]~^^^ ERROR creating a shared reference to a mutable static [E0796] - //[e2021]~^^^^ ERROR shared reference to mutable static is discouraged [static_mut_refs] - - foo(&X); - //[e2024]~^ ERROR creating a shared reference to a mutable static [E0796] - //[e2021]~^^ ERROR shared reference to mutable static is discouraged [static_mut_refs] - - static mut Z: &[i32; 3] = &[0, 1, 2]; - - let _ = Z.len(); - let _ = Z[0]; - let _ = format!("{:?}", Z); - } -} - -fn foo<'a>(_x: &'a i32) {} diff --git a/tests/ui/static/reference-to-mut-static-safe.e2024.stderr b/tests/ui/static/reference-to-mut-static-safe.e2024.stderr index 607c1bba135..c57b418d7b2 100644 --- a/tests/ui/static/reference-to-mut-static-safe.e2024.stderr +++ b/tests/ui/static/reference-to-mut-static-safe.e2024.stderr @@ -10,6 +10,15 @@ help: use `addr_of!` instead to create a raw pointer LL | let _x = addr_of!(X); | ~~~~~~~~~~~ -error: aborting due to 1 previous error +error[E0133]: use of mutable static is unsafe and requires unsafe block + --> $DIR/reference-to-mut-static-safe.rs:9:15 + | +LL | let _x = &X; + | ^ use of mutable static + | + = note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0796`. +Some errors have detailed explanations: E0133, E0796. +For more information about an error, try `rustc --explain E0133`. diff --git a/tests/ui/static/reference-to-mut-static-safe.rs b/tests/ui/static/reference-to-mut-static-safe.rs index de4f4be8f76..98afdadf4d2 100644 --- a/tests/ui/static/reference-to-mut-static-safe.rs +++ b/tests/ui/static/reference-to-mut-static-safe.rs @@ -8,6 +8,6 @@ fn main() { let _x = &X; //[e2024]~^ creating a shared reference to a mutable static [E0796] - //[e2021]~^^ use of mutable static is unsafe and requires unsafe function or block [E0133] + //~^^ use of mutable static is unsafe and requires unsafe //[e2021]~^^^ shared reference to mutable static is discouraged [static_mut_refs] } diff --git a/tests/ui/static/reference-to-mut-static-unsafe-fn.rs b/tests/ui/static/reference-to-mut-static-unsafe-fn.rs index 5652703a271..d63fd5460d8 100644 --- a/tests/ui/static/reference-to-mut-static-unsafe-fn.rs +++ b/tests/ui/static/reference-to-mut-static-unsafe-fn.rs @@ -3,24 +3,26 @@ fn main() {} unsafe fn _foo() { - static mut X: i32 = 1; - static mut Y: i32 = 1; + unsafe { + static mut X: i32 = 1; + static mut Y: i32 = 1; - let _y = &X; - //~^ ERROR creating a shared reference to a mutable static [E0796] + let _y = &X; + //~^ ERROR creating a shared reference to a mutable static [E0796] - let ref _a = X; - //~^ ERROR creating a shared reference to a mutable static [E0796] + let ref _a = X; + //~^ ERROR creating a shared reference to a mutable static [E0796] - let ref mut _a = X; - //~^ ERROR creating a mutable reference to a mutable static [E0796] + let ref mut _a = X; + //~^ ERROR creating a mutable reference to a mutable static [E0796] - let (_b, _c) = (&X, &mut Y); - //~^ ERROR creating a shared reference to a mutable static [E0796] - //~^^ ERROR creating a mutable reference to a mutable static [E0796] + let (_b, _c) = (&X, &mut Y); + //~^ ERROR creating a shared reference to a mutable static [E0796] + //~^^ ERROR creating a mutable reference to a mutable static [E0796] - foo(&X); - //~^ ERROR creating a shared reference to a mutable static [E0796] + foo(&X); + //~^ ERROR creating a shared reference to a mutable static [E0796] + } } fn foo<'a>(_x: &'a i32) {} diff --git a/tests/ui/static/reference-to-mut-static-unsafe-fn.stderr b/tests/ui/static/reference-to-mut-static-unsafe-fn.stderr index 77d2aa5d1ae..b24943cf593 100644 --- a/tests/ui/static/reference-to-mut-static-unsafe-fn.stderr +++ b/tests/ui/static/reference-to-mut-static-unsafe-fn.stderr @@ -1,74 +1,74 @@ error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-to-mut-static-unsafe-fn.rs:9:14 + --> $DIR/reference-to-mut-static-unsafe-fn.rs:10:18 | -LL | let _y = &X; - | ^^ shared reference to mutable static +LL | let _y = &X; + | ^^ shared reference to mutable static | = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior help: use `addr_of!` instead to create a raw pointer | -LL | let _y = addr_of!(X); - | ~~~~~~~~~~~ +LL | let _y = addr_of!(X); + | ~~~~~~~~~~~ error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-to-mut-static-unsafe-fn.rs:12:18 + --> $DIR/reference-to-mut-static-unsafe-fn.rs:13:22 | -LL | let ref _a = X; - | ^ shared reference to mutable static +LL | let ref _a = X; + | ^ shared reference to mutable static | = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior help: use `addr_of!` instead to create a raw pointer | -LL | let ref _a = addr_of!(X); - | ~~~~~~~~~~~ +LL | let ref _a = addr_of!(X); + | ~~~~~~~~~~~ error[E0796]: creating a mutable reference to a mutable static - --> $DIR/reference-to-mut-static-unsafe-fn.rs:15:22 + --> $DIR/reference-to-mut-static-unsafe-fn.rs:16:26 | -LL | let ref mut _a = X; - | ^ mutable reference to mutable static +LL | let ref mut _a = X; + | ^ mutable reference to mutable static | = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior help: use `addr_of_mut!` instead to create a raw pointer | -LL | let ref mut _a = addr_of_mut!(X); - | ~~~~~~~~~~~~~~~ +LL | let ref mut _a = addr_of_mut!(X); + | ~~~~~~~~~~~~~~~ error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-to-mut-static-unsafe-fn.rs:18:21 + --> $DIR/reference-to-mut-static-unsafe-fn.rs:19:25 | -LL | let (_b, _c) = (&X, &mut Y); - | ^^ shared reference to mutable static +LL | let (_b, _c) = (&X, &mut Y); + | ^^ shared reference to mutable static | = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior help: use `addr_of!` instead to create a raw pointer | -LL | let (_b, _c) = (addr_of!(X), &mut Y); - | ~~~~~~~~~~~ +LL | let (_b, _c) = (addr_of!(X), &mut Y); + | ~~~~~~~~~~~ error[E0796]: creating a mutable reference to a mutable static - --> $DIR/reference-to-mut-static-unsafe-fn.rs:18:25 + --> $DIR/reference-to-mut-static-unsafe-fn.rs:19:29 | -LL | let (_b, _c) = (&X, &mut Y); - | ^^^^^^ mutable reference to mutable static +LL | let (_b, _c) = (&X, &mut Y); + | ^^^^^^ mutable reference to mutable static | = note: this mutable reference has lifetime `'static`, but if the static gets accessed (read or written) by any other means, or any other reference is created, then any further use of this mutable reference is Undefined Behavior help: use `addr_of_mut!` instead to create a raw pointer | -LL | let (_b, _c) = (&X, addr_of_mut!(Y)); - | ~~~~~~~~~~~~~~~ +LL | let (_b, _c) = (&X, addr_of_mut!(Y)); + | ~~~~~~~~~~~~~~~ error[E0796]: creating a shared reference to a mutable static - --> $DIR/reference-to-mut-static-unsafe-fn.rs:22:9 + --> $DIR/reference-to-mut-static-unsafe-fn.rs:23:13 | -LL | foo(&X); - | ^^ shared reference to mutable static +LL | foo(&X); + | ^^ shared reference to mutable static | = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior help: use `addr_of!` instead to create a raw pointer | -LL | foo(addr_of!(X)); - | ~~~~~~~~~~~ +LL | foo(addr_of!(X)); + | ~~~~~~~~~~~ error: aborting due to 6 previous errors |
