-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Output from clippy.
after fixes were automatically applied the compiler reported errors within these files:
* examples/threads.rs
This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag
The following errors were reported:
error[E0277]: the `?` operator can only be used in an async block that returns `Result` or `Option` (or another type that implements `std::ops::FromResidual`)
--> examples/threads.rs:61:32
|
60 | rt.block_on(async {
| _______________________-
61 | | client.register().await?
| | ^ cannot use the `?` operator in an async block that returns `()`
62 | | })?;
| |_____- this function should return `Result` or `Option` to accept `?`
|
= help: the trait `std::ops::FromResidual<std::result::Result<std::convert::Infallible, std::boxed::Box<dyn std::error::Error + std::marker::Send + std::marker::Sync>>>` is not implemented for `()`
error[E0277]: the `?` operator can only be applied to values that implement `std::ops::Try`
--> examples/threads.rs:60:5
|
60 | / rt.block_on(async {
61 | | client.register().await?
62 | | })?;
| |_______^ the `?` operator cannot be applied to type `()`
|
= help: the trait `std::ops::Try` is not implemented for `()`
error: aborting due to 2 previous errors
I would be happy if either the lint didn't fire, or if clippy fixed things with code that works.
Meta
The same error occurs with nightly.
rustc --version --verbose
:
rustc 1.64.0 (a55dd71d5 2022-09-19)
rustc 1.66.0-nightly (57f097ea2 2022-10-01)
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
Alexendoo commentedon Oct 3, 2022
Could you share the output of running
cargo clippy
without--fix
, or the code this occurred on?rbtcollins commentedon Oct 3, 2022
https://github.com/rbtcollins/unleash-client-rust/blob/744b0e64d879b7c681fe14f922bbcf943d8efdf5/examples/threads.rs#L61-L68
rbtcollins commentedon Oct 3, 2022
The allow was added after this.
for permanence
BenjaminBrienen commentedon Jun 17, 2025
I also get this.
blyxyas commentedon Jun 19, 2025
This issue is currently not happening anymore in the repo's current state. Could you post an example of the problematic code @BenjaminBrienen? =^w^=
BenjaminBrienen commentedon Jun 19, 2025
This code would cause it if you remove the closure wrapper
https://github.com/rust-lang/rust/blob/8de4c7234dd9b97c9d76b58671343fdbbc9a433e/src/tools/rust-analyzer/crates/rust-analyzer/src/lsp/capabilities.rs#L211
blyxyas commentedon Jun 20, 2025
Minimized example of this behaviour:
Which rustfix tries to change into:
which produces:
odysa commentedon Jun 26, 2025
@rustbot claim
odysa commentedon Jun 26, 2025
I think the expected behavior is
odysa commentedon Jun 26, 2025
Possible solution:
If the closure body is a block, and the block contains no statements but has a final expression, we can suggest replacing the entire closure with just that expression.
For example,
(|| { Some(true) })()
can be simplified toSome(true)
.fix: redundant_closure_call lint for closures with block (#15144)