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

Denote ControlFlow as #[must_use] #137449

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

I've repeatedly hit bugs in the compiler due to ControlFlow not being marked #[must_use]. There seems to be an accepted ACP to make the type #[must_use] (rust-lang/libs-team#444), so this PR implements that part of it.

Most of the usages in the compiler that trigger this new warning are "root" usages (calling into an API that uses control-flow internally, but for which the callee doesn't really care) and have been suppressed by let _ = ..., but I did legitimately find one instance of a missing ? and one for a never-used ControlFlow value in #137448.

Presumably this needs an FCP too, so I'm opening this and nominating it for T-libs-api.

This PR also touches the tools (incl. rust-analyzer), but if this went into FCP, I'd split those out into separate PRs which can land before this one does.

r? libs-api
@rustbot label: T-libs-api I-libs-api-nominated

@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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Feb 23, 2025
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
#22 exporting to docker image format
#22 sending tarball 29.3s done
#22 DONE 35.7s
##[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-18]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Listening on address 127.0.0.1:4226
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-18', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--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-18/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---
  Downloaded boml v0.3.1
   Compiling boml v0.3.1
   Compiling y v0.1.0 (/checkout/compiler/rustc_codegen_gcc/build_system)
    Finished `release` profile [optimized] target(s) in 4.25s
     Running `/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-codegen/x86_64-unknown-linux-gnu/release/y test --use-system-gcc --use-backend gcc --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-tools/cg_gcc --release --mini-tests --std-tests`
Using system GCC
warning: target feature `x87` must be enabled to ensure that the ABI of the current target can be implemented correctly
  |
  = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #116344 <https://github.com/rust-lang/rust/issues/116344>
---
   Compiling rustdoc v0.0.0 (/checkout/src/librustdoc)
error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:12:5
   |
12 |     buf.push("Hello ");
   |
   = note: `-D unused-must-use` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unused_must_use)]`
help: use `let _ = ...` to ignore the resulting value
help: use `let _ = ...` to ignore the resulting value
   |
12 |     let _ = buf.push("Hello ");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:14:5
   |
   |
14 |     buf.push("world");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
14 |     let _ = buf.push("world");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:16:5
   |
   |
16 |     buf.push("!");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
16 |     let _ = buf.push("!");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:23:5
   |
   |
23 |     buf.push("Hello");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
23 |     let _ = buf.push("Hello");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:24:5
   |
   |
24 |     buf.push(" world!");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
24 |     let _ = buf.push(" world!");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:31:5
   |
   |
31 |     buf.push("Hello ");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
31 |     let _ = buf.push("Hello ");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:33:5
   |
   |
33 |     buf.push("world");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
33 |     let _ = buf.push("world");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:35:5
   |
   |
35 |     buf.push("!");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
35 |     let _ = buf.push("!");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:42:5
   |
   |
42 |     buf.push("Hello ");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
42 |     let _ = buf.push("Hello ");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:44:5
   |
   |
44 |     buf.push("world");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
44 |     let _ = buf.push("world");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:46:5
   |
   |
46 |     buf.push("!");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
46 |     let _ = buf.push("!");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:54:5
   |
   |
54 |     buf.push("This is a ");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
54 |     let _ = buf.push("This is a ");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:56:5
   |
   |
56 |     buf.push("paragraph");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
56 |     let _ = buf.push("paragraph");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:58:5
   |
   |
58 |     buf.push("!");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
58 |     let _ = buf.push("!");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:69:5
   |
   |
69 |     buf.push("This is a ");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
69 |     let _ = buf.push("This is a ");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:71:5
   |
   |
71 |     buf.push("paragraph");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
71 |     let _ = buf.push("paragraph");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:73:5
   |
   |
73 |     buf.push("!");
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
73 |     let _ = buf.push("!");

error: unused `std::ops::ControlFlow` that must be used
  --> src/librustdoc/html/length_limit/tests.rs:81:5
   |
   |
81 | /     (0..10).try_for_each(|n| {
82 | |         buf.open_tag("strong");
83 | |         buf.push("word#")?;
84 | |         buf.push(&n.to_string())?;
85 | |         buf.close_tag();
86 | |         ControlFlow::Continue(())
   | |______^
   |
help: use `let _ = ...` to ignore the resulting value
   |
   |
81 |     let _ = (0..10).try_for_each(|n| {

error: unused `std::ops::ControlFlow` that must be used
   --> src/librustdoc/html/length_limit/tests.rs:103:5
    |
    |
103 |     buf.push("Hello");
    |
help: use `let _ = ...` to ignore the resulting value
    |
    |
103 |     let _ = buf.push("Hello");

error: unused `std::ops::ControlFlow` that must be used
   --> src/librustdoc/html/length_limit/tests.rs:104:5
    |
    |
104 |     buf.push(" World");
    |
help: use `let _ = ...` to ignore the resulting value
    |
    |
104 |     let _ = buf.push(" World");

error: unused `std::ops::ControlFlow` that must be used
   --> src/librustdoc/html/length_limit/tests.rs:113:5
    |
    |
113 |     buf.push("Hello");
    |
help: use `let _ = ...` to ignore the resulting value
    |
    |
113 |     let _ = buf.push("Hello");

error: could not compile `rustdoc` (lib test) due to 21 previous errors
Build completed unsuccessfully in 0:34:40
  local time: Sun Feb 23 00:42:26 UTC 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants