Skip to content

Fix a wrong error message in 2024 edition #140056

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yuk1ty
Copy link
Contributor

@yuk1ty yuk1ty commented Apr 20, 2025

Fixes #139952

@rustbot
Copy link
Collaborator

rustbot commented Apr 20, 2025

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 20, 2025
@@ -1,4 +1,4 @@
warning: creating a shared reference to mutable static is discouraged
warning: creating a shared reference to mutable static is not allowed
Copy link
Contributor Author

@yuk1ty yuk1ty Apr 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to ask if we should keep the error message as "discouraged" here (or other tests related to 2021 Edition) since my update will change the existing message in 2021 Edition 🤔 This is the first time to contribute the diagnostic issue, it would be nice if someone could tell me about the compatibility thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The easy way is to reword this message to...

warning: creating a shared reference to mutable static

that way, it doesn't really matter if it's Edition 2021 / 2024.

The more complex way is to introduce different diagnostics between edition < 2024 and edition >= 2024, with edition 2021 wording being

warning: creating a shared reference to mutable static is discouraged

and edition 2024 wording being

error: creating a shared reference to mutable static is not allowed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that creating a shared reference to mutable static is better.

The warning: and error: will be enough information to let people know whether it's discouraged or not allowed.

("error" implies not being allowed and "warning" implies being discouraged)

Copy link
Contributor Author

@yuk1ty yuk1ty Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jieyouxu @junderw Thank you for the comment. I will follow "creating a shared reference to mutable static" because from my quick investigation, the implementation is going to be really complexed (I think it's possible but) if we employ switching messages between 2021 and 2024.

@yuk1ty yuk1ty force-pushed the fix-static-mut-error-message branch from a8ec2f7 to 01eb091 Compare April 20, 2025 01:54
@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 21, 2025
@yuk1ty yuk1ty force-pushed the fix-static-mut-error-message branch from 01eb091 to 6daa8e9 Compare April 25, 2025 04:18
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/ui/ref_option/ref_option.all.fixed ... ok
tests/ui/non_std_lazy_static/non_std_lazy_static_fixable.fixed ... ok

FAILED TEST: tests/ui/checked_unwrap/simple_conditionals.rs
command: CLIPPY_CONF_DIR="tests" RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/clippy-driver" "--error-format=json" "--emit=metadata" "-Aunused" "-Ainternal_features" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Dwarnings" "-Ldependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps" "--extern=clippy_config=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_config-af4b67ede62bd94a.rlib" "--extern=clippy_lints=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_lints-0e3b06cfaa0e629a.rlib" "--extern=clippy_utils=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_utils-3f60d68f14f28ca6.rlib" "--extern=futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libfutures-6ae23cd7ef138de2.rlib" "--extern=if_chain=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libif_chain-d494e6b7c1a6e89b.rlib" "--extern=itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libitertools-d4e4179d28fd4b4c.rlib" "--extern=parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libparking_lot-c60316d1e8e896b7.rlib" "--extern=quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libquote-1717c86f14e427fe.rlib" "--extern=regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libregex-75c78277780d7d9c.rlib" "--extern=serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libserde-37f19c6bbbc5eedb.rlib" "--extern=serde_derive=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libserde_derive-b4ef3187156cf2a5.so" "--extern=syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libsyn-0086164b4f00891f.rlib" "--extern=tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/x86_64-unknown-linux-gnu/release/deps/libtokio-ab47290081742c1b.rlib" "-Ldependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/release/deps" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/ui_test/0/tests/ui/checked_unwrap" "tests/ui/checked_unwrap/simple_conditionals.rs" "--edition" "2024"

error: actual output differed from expected
Execute `./x test src/tools/clippy --bless` to update `tests/ui/checked_unwrap/simple_conditionals.stderr` to the actual output
--- tests/ui/checked_unwrap/simple_conditionals.stderr
+++ <stderr output>
---
Full unnormalized output:
error: called `unwrap` on `x` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:47:9
   |
LL |     if x.is_some() {
   |     -------------- help: try: `if let Some(<item>) = x`
LL |         // unnecessary
LL |         x.unwrap();
   |         ^^^^^^^^^^
   |
note: the lint level is defined here
  --> tests/ui/checked_unwrap/simple_conditionals.rs:2:35
   |
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: called `expect` on `x` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:51:9
   |
LL |     if x.is_some() {
   |     -------------- help: try: `if let Some(<item>) = x`
...
LL |         x.expect("an error message");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:55:9
   |
---
   |
LL |     if x.is_some() {
   |        ----------- because of this check
...
LL |         x.expect("an error message");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:64:9
   |
---

error: called `unwrap` on `x` after checking its variant with `is_none`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:68:9
   |
LL |     if x.is_none() {
   |     -------------- help: try: `if let Some(<item>) = x`
...
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: called `unwrap` on `x` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:13:13
   |
LL |         if $a.is_some() {
   |         --------------- help: try: `if let Some(<item>) = x`
LL |             // unnecessary
LL |             $a.unwrap();
   |             ^^^^^^^^^^^
...
LL |     m!(x);
   |     ----- in this macro invocation
   |
   = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

error: called `unwrap` on `x` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:81:9
   |
LL |     if x.is_ok() {
   |     ------------ help: try: `if let Ok(<item>) = x`
LL |         // unnecessary
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: called `expect` on `x` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:85:9
   |
LL |     if x.is_ok() {
   |     ------------ help: try: `if let Ok(<item>) = x`
...
LL |         x.expect("an error message");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap_err()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:89:9
   |
LL |     if x.is_ok() {
   |        --------- because of this check
...
LL |         x.unwrap_err();
   |         ^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:93:9
   |
LL |     if x.is_ok() {
   |        --------- because of this check
...
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: this call to `expect()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:97:9
   |
LL |     if x.is_ok() {
   |        --------- because of this check
...
LL |         x.expect("an error message");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: called `unwrap_err` on `x` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:101:9
   |
LL |     if x.is_ok() {
   |     ------------ help: try: `if let Err(<item>) = x`
...
LL |         x.unwrap_err();
   |         ^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:106:9
   |
LL |     if x.is_err() {
   |        ---------- because of this check
LL |         // will panic
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: called `unwrap_err` on `x` after checking its variant with `is_err`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:110:9
   |
LL |     if x.is_err() {
   |     ------------- help: try: `if let Err(<item>) = x`
...
LL |         x.unwrap_err();
   |         ^^^^^^^^^^^^^^

error: called `unwrap` on `x` after checking its variant with `is_err`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:114:9
   |
LL |     if x.is_err() {
   |     ------------- help: try: `if let Ok(<item>) = x`
...
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: this call to `unwrap_err()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:118:9
   |
LL |     if x.is_err() {
   |        ---------- because of this check
...
LL |         x.unwrap_err();
   |         ^^^^^^^^^^^^^^

error: called `unwrap` on `option` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:143:9
   |
LL |     if option.is_some() {
   |     ------------------- help: try: `if let Some(<item>) = &option`
LL |         option.as_ref().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:146:9
   |
---

error: called `unwrap` on `result` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:153:9
   |
LL |     if result.is_ok() {
   |     ----------------- help: try: `if let Ok(<item>) = &result`
LL |         result.as_ref().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:156:9
   |
LL |     if result.is_ok() {
   |        -------------- because of this check
...
LL |         result.as_ref().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: called `unwrap` on `option` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:162:9
   |
LL |     if option.is_some() {
   |     ------------------- help: try: `if let Some(<item>) = &mut option`
LL |         option.as_mut().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:165:9
   |
---

error: called `unwrap` on `result` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:171:9
   |
LL |     if result.is_ok() {
   |     ----------------- help: try: `if let Ok(<item>) = &mut result`
LL |         result.as_mut().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:174:9
   |
LL |     if result.is_ok() {
   |        -------------- because of this check
...
LL |         result.as_mut().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

---
full stderr:
error: called `unwrap` on `x` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:47:9
   |
LL |     if x.is_some() {
   |     -------------- help: try: `if let Some(<item>) = x`
LL |         // unnecessary
LL |         x.unwrap();
   |         ^^^^^^^^^^
   |
note: the lint level is defined here
  --> tests/ui/checked_unwrap/simple_conditionals.rs:2:35
   |
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
   |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: called `expect` on `x` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:51:9
   |
LL |     if x.is_some() {
   |     -------------- help: try: `if let Some(<item>) = x`
...
LL |         x.expect("an error message");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:55:9
   |
---
   |
LL |     if x.is_some() {
   |        ----------- because of this check
...
LL |         x.expect("an error message");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:64:9
   |
---

error: called `unwrap` on `x` after checking its variant with `is_none`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:68:9
   |
LL |     if x.is_none() {
   |     -------------- help: try: `if let Some(<item>) = x`
...
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: called `unwrap` on `x` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:13:13
   |
LL |         if $a.is_some() {
   |         --------------- help: try: `if let Some(<item>) = x`
LL |             // unnecessary
LL |             $a.unwrap();
   |             ^^^^^^^^^^^
...
LL |     m!(x);
   |     ----- in this macro invocation
   |
   = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

error: called `unwrap` on `x` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:81:9
   |
LL |     if x.is_ok() {
   |     ------------ help: try: `if let Ok(<item>) = x`
LL |         // unnecessary
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: called `expect` on `x` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:85:9
   |
LL |     if x.is_ok() {
   |     ------------ help: try: `if let Ok(<item>) = x`
...
LL |         x.expect("an error message");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap_err()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:89:9
   |
LL |     if x.is_ok() {
   |        --------- because of this check
...
LL |         x.unwrap_err();
   |         ^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:93:9
   |
LL |     if x.is_ok() {
   |        --------- because of this check
...
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: this call to `expect()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:97:9
   |
LL |     if x.is_ok() {
   |        --------- because of this check
...
LL |         x.expect("an error message");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: called `unwrap_err` on `x` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:101:9
   |
LL |     if x.is_ok() {
   |     ------------ help: try: `if let Err(<item>) = x`
...
LL |         x.unwrap_err();
   |         ^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:106:9
   |
LL |     if x.is_err() {
   |        ---------- because of this check
LL |         // will panic
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: called `unwrap_err` on `x` after checking its variant with `is_err`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:110:9
   |
LL |     if x.is_err() {
   |     ------------- help: try: `if let Err(<item>) = x`
...
LL |         x.unwrap_err();
   |         ^^^^^^^^^^^^^^

error: called `unwrap` on `x` after checking its variant with `is_err`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:114:9
   |
LL |     if x.is_err() {
   |     ------------- help: try: `if let Ok(<item>) = x`
...
LL |         x.unwrap();
   |         ^^^^^^^^^^

error: this call to `unwrap_err()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:118:9
   |
LL |     if x.is_err() {
   |        ---------- because of this check
...
LL |         x.unwrap_err();
   |         ^^^^^^^^^^^^^^

error: called `unwrap` on `option` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:143:9
   |
LL |     if option.is_some() {
   |     ------------------- help: try: `if let Some(<item>) = &option`
LL |         option.as_ref().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:146:9
   |
---

error: called `unwrap` on `result` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:153:9
   |
LL |     if result.is_ok() {
   |     ----------------- help: try: `if let Ok(<item>) = &result`
LL |         result.as_ref().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:156:9
   |
LL |     if result.is_ok() {
   |        -------------- because of this check
...
LL |         result.as_ref().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: called `unwrap` on `option` after checking its variant with `is_some`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:162:9
   |
LL |     if option.is_some() {
   |     ------------------- help: try: `if let Some(<item>) = &mut option`
LL |         option.as_mut().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:165:9
   |
---

error: called `unwrap` on `result` after checking its variant with `is_ok`
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:171:9
   |
LL |     if result.is_ok() {
   |     ----------------- help: try: `if let Ok(<item>) = &mut result`
LL |         result.as_mut().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

error: this call to `unwrap()` will always panic
##[error]  --> tests/ui/checked_unwrap/simple_conditionals.rs:174:9
   |
LL |     if result.is_ok() {
   |        -------------- because of this check
...
LL |         result.as_mut().unwrap();
   |         ^^^^^^^^^^^^^^^^^^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In edition 2024 error message "error: creating a shared reference to mutable static is discouraged" is wrong
5 participants