Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #119767

Merged
merged 26 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift click to select a range
bc6a5c7
std: getrandom simplification for freebsd.
devnexen Dec 8, 2023
2c088f9
Disallow reference to `static mut` for expressions
obeis Dec 22, 2023
70ba4d1
Disallow reference to `static mut` for statements
obeis Dec 22, 2023
a82fd2b
Call `maybe_expr_static_mut` inside `resolve_expr`
obeis Dec 22, 2023
e36f7b7
Call `maybe_stmt_static_mut` inside `resolve_stmt`
obeis Dec 22, 2023
18edf9a
Add test for `E0796` and `static_mut_ref` lint
obeis Dec 22, 2023
5617361
don't reexport atomic::ordering via rustc_data_structures, use std im…
klensy Jan 2, 2024
a8aa687
Update test for `E0796` and `static_mut_ref` lint
obeis Dec 22, 2023
4071572
Merge dead bb pruning and unreachable bb deduplication.
cjgillot Jan 7, 2024
e61be1b
rustdoc-search: reuse empty map/array in function signatures
notriddle Jan 8, 2024
8356802
Move promote_consts back to rustc_mir_transform.
cjgillot May 20, 2023
cae0dc2
Simplify code flow.
cjgillot May 20, 2023
5d6463c
Make match exhaustive.
cjgillot Jan 8, 2024
a2b765f
Remove `-Zdont-buffer-diagnostics`.
nnethercote Jan 7, 2024
c3cd657
rustdoc-search: intern function search types
notriddle Jan 8, 2024
c8ded52
GNU/Hurd: unconditionally use inline stack probes
erikdesjardins Jan 9, 2024
3611014
Rework and improve unstable documentation of check-cfg
Urgau Dec 22, 2023
4a24b5b
Rollup merge of #117556 - obeis:static-mut-ref-lint, r=davidtwco
GuillaumeGomez Jan 9, 2024
df2f4ae
Rollup merge of #118748 - devnexen:fbsd_getrandom_simpl, r=Nilstrieb,…
GuillaumeGomez Jan 9, 2024
5c9a8d7
Rollup merge of #119282 - Urgau:check-cfg-rework-unstable-doc, r=John…
GuillaumeGomez Jan 9, 2024
d3574be
Rollup merge of #119527 - klensy:ordering, r=compiler-errors
GuillaumeGomez Jan 9, 2024
72fdaf5
Rollup merge of #119668 - cjgillot:transform-promote, r=oli-obk
GuillaumeGomez Jan 9, 2024
9b90541
Rollup merge of #119699 - cjgillot:simplify-unreachable, r=oli-obk
GuillaumeGomez Jan 9, 2024
b0aa3d8
Rollup merge of #119723 - nnethercote:rm-Zdont-buffer-diagnostics, r=…
GuillaumeGomez Jan 9, 2024
f9cadb9
Rollup merge of #119756 - notriddle:notriddle/reuse-map, r=GuillaumeG…
GuillaumeGomez Jan 9, 2024
f41d773
Rollup merge of #119758 - erikdesjardins:hurd, r=petrochenkov
GuillaumeGomez Jan 9, 2024
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
Add test for E0796 and static_mut_ref lint
  • Loading branch information
obeis committed Jan 6, 2024
commit 18edf9a64e8d84e72a6be67df3822e57dea8d34a
26 changes: 26 additions & 0 deletions tests/ui/static/reference-of-mut-static-safe.e2021.stderr
Original file line number Diff line number Diff line change
@@ -0,0 1,26 @@
warning: shared reference of mutable static is discouraged
--> $DIR/reference-of-mut-static-safe.rs:9:14
|
LL | let _x = &X;
| ^^ shared reference of mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: reference 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: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let _x = addr_of!(X);
| ~~~~~~~~~~~

error[E0133]: use of mutable static is unsafe and requires unsafe function or block
--> $DIR/reference-of-mut-static-safe.rs:9:14
|
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 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0133`.
15 changes: 15 additions & 0 deletions tests/ui/static/reference-of-mut-static-safe.e2024.stderr
Original file line number Diff line number Diff line change
@@ -0,0 1,15 @@
error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static-safe.rs:9:14
|
LL | let _x = &X;
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let _x = addr_of!(X);
| ~~~~~~~~~~~

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0796`.
13 changes: 13 additions & 0 deletions tests/ui/static/reference-of-mut-static-safe.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,13 @@
// revisions: e2021 e2024

// [e2021] edition:2021
// [e2024] compile-flags: --edition 2024 -Z unstable-options

fn main() {
static mut X: i32 = 1;

let _x = &X;
//[e2024]~^ reference of mutable static is disallowed [E0796]
//[e2021]~^^ use of mutable static is unsafe and requires unsafe function or block [E0133]
//[e2021]~^^^ shared reference of mutable static is discouraged [static_mut_ref]
}
23 changes: 23 additions & 0 deletions tests/ui/static/reference-of-mut-static-unsafe-fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,23 @@
// 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 reference of mutable static is disallowed

let ref _a = X;
//~^ ERROR reference of mutable static is disallowed

let (_b, _c) = (&X, &Y);
//~^ ERROR reference of mutable static is disallowed
//~^^ ERROR reference of mutable static is disallowed

foo(&X);
//~^ ERROR reference of mutable static is disallowed
}

fn foo<'a>(_x: &'a i32) {}
63 changes: 63 additions & 0 deletions tests/ui/static/reference-of-mut-static-unsafe-fn.stderr
Original file line number Diff line number Diff line change
@@ -0,0 1,63 @@
error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static-unsafe-fn.rs:9:14
|
LL | let _y = &X;
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let _y = addr_of!(X);
| ~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static-unsafe-fn.rs:12:18
|
LL | let ref _a = X;
| ^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let ref _a = addr_of!(X);
| ~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static-unsafe-fn.rs:15:21
|
LL | let (_b, _c) = (&X, &Y);
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let (_b, _c) = (addr_of!(X), &Y);
| ~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static-unsafe-fn.rs:15:25
|
LL | let (_b, _c) = (&X, &Y);
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let (_b, _c) = (&X, addr_of!(Y));
| ~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static-unsafe-fn.rs:19:9
|
LL | foo(&X);
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | foo(addr_of!(X));
| ~~~~~~~~~~~

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0796`.
91 changes: 91 additions & 0 deletions tests/ui/static/reference-of-mut-static.e2021.stderr
Original file line number Diff line number Diff line change
@@ -0,0 1,91 @@
error: shared reference of mutable static is discouraged
--> $DIR/reference-of-mut-static.rs:16:18
|
LL | let _y = &X;
| ^^ shared reference of mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: reference 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/reference-of-mut-static.rs:6:9
|
LL | #![deny(static_mut_ref)]
| ^^^^^^^^^^^^^^
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let _y = addr_of!(X);
| ~~~~~~~~~~~

error: mutable reference of mutable static is discouraged
--> $DIR/reference-of-mut-static.rs:20:18
|
LL | let _y = &mut X;
| ^^^^^^ mutable reference of mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: reference 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
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
LL | let _y = addr_of_mut!(X);
| ~~~~~~~~~~~~~~~

error: shared reference of mutable static is discouraged
--> $DIR/reference-of-mut-static.rs:28:22
|
LL | let ref _a = X;
| ^ shared reference of mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: reference 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
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let ref _a = addr_of!(X);
| ~~~~~~~~~~~

error: shared reference of mutable static is discouraged
--> $DIR/reference-of-mut-static.rs:32:25
|
LL | let (_b, _c) = (&X, &Y);
| ^^ shared reference of mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: reference 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
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let (_b, _c) = (addr_of!(X), &Y);
| ~~~~~~~~~~~

error: shared reference of mutable static is discouraged
--> $DIR/reference-of-mut-static.rs:32:29
|
LL | let (_b, _c) = (&X, &Y);
| ^^ shared reference of mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: reference 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
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let (_b, _c) = (&X, addr_of!(Y));
| ~~~~~~~~~~~

error: shared reference of mutable static is discouraged
--> $DIR/reference-of-mut-static.rs:38:13
|
LL | foo(&X);
| ^^ shared reference of mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: reference 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
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | foo(addr_of!(X));
| ~~~~~~~~~~~

error: aborting due to 6 previous errors

75 changes: 75 additions & 0 deletions tests/ui/static/reference-of-mut-static.e2024.stderr
Original file line number Diff line number Diff line change
@@ -0,0 1,75 @@
error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static.rs:16:18
|
LL | let _y = &X;
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let _y = addr_of!(X);
| ~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static.rs:20:18
|
LL | let _y = &mut X;
| ^^^^^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: mutable references are dangerous since if there's any other pointer or reference used for that static while the reference lives, that's UB; use `addr_of_mut!` instead to create a raw pointer
|
LL | let _y = addr_of_mut!(X);
| ~~~~~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static.rs:28:22
|
LL | let ref _a = X;
| ^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let ref _a = addr_of!(X);
| ~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static.rs:32:25
|
LL | let (_b, _c) = (&X, &Y);
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let (_b, _c) = (addr_of!(X), &Y);
| ~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static.rs:32:29
|
LL | let (_b, _c) = (&X, &Y);
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; use `addr_of!` instead to create a raw pointer
|
LL | let (_b, _c) = (&X, addr_of!(Y));
| ~~~~~~~~~~~

error[E0796]: reference of mutable static is disallowed
--> $DIR/reference-of-mut-static.rs:38:13
|
LL | foo(&X);
| ^^ reference of mutable static
|
= note: mutable statics can be written to by multiple threads: aliasing violations or data races will cause undefined behavior
help: shared references are dangerous since if there's any kind of mutation of that static while the reference lives, that's UB; 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`.
50 changes: 50 additions & 0 deletions tests/ui/static/reference-of-mut-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,50 @@
// revisions: e2021 e2024

// [e2021] edition:2021
// [e2024] compile-flags: --edition 2024 -Z unstable-options

#![deny(static_mut_ref)]

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 reference of mutable static is disallowed
//[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]

let _y = &mut X;
//[e2024]~^ ERROR reference of mutable static is disallowed
//[e2021]~^^ ERROR mutable reference of mutable static is discouraged [static_mut_ref]

let _z = addr_of_mut!(X);

let _p = addr_of!(X);

let ref _a = X;
//[e2024]~^ ERROR reference of mutable static is disallowed
//[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]

let (_b, _c) = (&X, &Y);
//[e2024]~^ ERROR reference of mutable static is disallowed
//[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]
//[e2024]~^^^ ERROR reference of mutable static is disallowed
//[e2021]~^^^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]

foo(&X);
//[e2024]~^ ERROR reference of mutable static is disallowed
//[e2021]~^^ ERROR shared reference of mutable static is discouraged [static_mut_ref]

static mut Z: &[i32; 3] = &[0, 1, 2];

let _ = Z.len();
let _ = Z[0];
let _ = format!("{:?}", Z);
}
}

fn foo<'a>(_x: &'a i32) {}