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

Mark some macros with must_use hint #127509

Closed
wants to merge 1 commit into from

Conversation

aceArt-GmbH
Copy link

Uses unstable feature #94745

Part of #126475

Marking pin::pin!() currently results in errors like

error[E0716]: temporary value dropped while borrowed
  --> /home/tux/Downloads/rust/tests/ui/coroutine/async-gen-yield-ty-is-unit.rs:13:26
   |
LL |     let async_iterator = pin!(gen_fn());
   |                          ^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
   |                          |
   |                          creates a temporary value which is freed while still in use
LL |     let ctx = &mut Context::from_waker(Waker::noop());
LL |     async_iterator.poll_next(ctx);
   |     -------------- borrow later used here
   |
   = note: this error originates in the macro `pin` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider using a `let` binding to create a longer lived value
   |
LL ~     let binding = pin!(gen_fn());
LL ~     let async_iterator = binding;
   |

error: aborting due to 1 previous error

I think this is #124493?

r​? @oli-obk

@rustbot
Copy link
Collaborator

rustbot commented Jul 9, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @joboet (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 9, 2024
library/core/src/lib.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jul 9, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@aceArt-GmbH
Copy link
Author

I am not sure if all those changes are anticipated 🤔

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

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

This seems to have regressed a lot of clippy lints/tests (for example the useless_vec lint emits no warnings at all anymore).

I'm guessing that our clippy_utils::higher::VecArgs util no longer recognizes the vec! expansion and needs to be updated

@rust-log-analyzer

This comment has been minimized.

($fmt:expr) => {{ /* compiler built-in */ }};
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
($fmt:expr) => {
$crate::hint::must_use({ /* compiler built-in */ })
Copy link
Member

Choose a reason for hiding this comment

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

this doesn't do anything, same for all other builtin macros. you'd need to modify the compiler

Copy link
Author

Choose a reason for hiding this comment

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

I am afraid this undergoing is way above my capabilities

@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 46)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 49)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 61)
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---

---- [ui] tests/ui/macros/unknown-builtin.rs stdout ----
diff of stderr:

13 LL | macro_rules! line { () => () }
15 
- error: aborting due to 2 previous errors
+ error[E0658]: use of unstable library feature 'hint_must_use'
+   --> $DIR/unknown-builtin.rs:13:5
+   --> $DIR/unknown-builtin.rs:13:5
+    |
+ LL |     std::prelude::v1::line!();
+    |
+    = note: see issue #94745 <https://github.com/rust-lang/rust/issues/94745> for more information
+    = help: add `#![feature(hint_must_use)]` to the crate attributes to enable
+    = help: add `#![feature(hint_must_use)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = note: this error originates in the macro `std::prelude::v1::line` (in Nightly builds, run with -Z macro-backtrace for more info)
- For more information about this error, try `rustc --explain E0773`.
+ error: aborting due to 3 previous errors
+ 
+ Some errors have detailed explanations: E0658, E0773.
---
To only update this specific test, also pass `--test-args macros/unknown-builtin.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/macros/unknown-builtin.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/macros/unknown-builtin" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/macros/unknown-builtin/auxiliary"
--- stderr -------------------------------
error: cannot find a built-in macro with name `unknown`
##[error]  --> /checkout/tests/ui/macros/unknown-builtin.rs:6:1
   |
   |
LL | macro_rules! unknown { () => () } //~ ERROR cannot find a built-in macro with name `unknown`

error[E0773]: attempted to define built-in macro more than once
##[error]  --> /rustc/FAKE_PREFIX/library/core/src/macros/mod.rs:1237:5
   |
   |
note: previously defined here
  --> /checkout/tests/ui/macros/unknown-builtin.rs:9:1
   |
LL | macro_rules! line { () => () } //~ NOTE previously defined here

error[E0658]: use of unstable library feature 'hint_must_use'
##[error]  --> /checkout/tests/ui/macros/unknown-builtin.rs:13:5
   |
   |
LL |     std::prelude::v1::line!();
   |
   = note: see issue #94745 <https://github.com/rust-lang/rust/issues/94745> for more information
   = help: add `#![feature(hint_must_use)]` to the crate attributes to enable
   = help: add `#![feature(hint_must_use)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = note: this error originates in the macro `std::prelude::v1::line` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0658, E0773.
For more information about an error, try `rustc --explain E0658`.

@tgross35
Copy link
Contributor

tgross35 commented Jul 9, 2024

Note that there are some cases where we need to be careful with hint::must_use, since it causes some surprises for lifetimes #124493. Probably good to include a test to prove that those specific circumstances don't regress for anywhere that a new must_use gets added.

edit: wow I should really read the top post before commenting, ignore me -___-

@aceArt-GmbH
Copy link
Author

@rustbot author

@rustbot rustbot 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 Jul 12, 2024
@aceArt-GmbH aceArt-GmbH deleted the 126475-2 branch July 12, 2024 20:21
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants