-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Disable code Action for clippy::needless_return #16542
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
Comments
Unfortunately, I don't think we respect {
"rust-analyzer.diagnostics.disabled": [
"needless_return"
]
} |
Weirdly, I see this showing up via eglot in emacs on a function which does not contain an explicit return. It's annotated with a |
Maybe this rule should not be applied on the macro expansions. 🤔 |
Our filtering for diagnostic level attributes is somewhat broken wrt to macros, that is a known issue. |
It should respect |
Might be that |
No, I think it's something kind of heuristic: // no warning
fn main() {
return tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed building the Runtime")
.block_on(async {});
}
// warning
fn main() {
return tokio::runtime::Runtime::new()
.expect("Failed building the Runtime")
.block_on(async {});
}
// warning
fn main() {
return tokio::runtime::Builder::new_current_thread()
.build()
.expect("Failed building the Runtime")
.block_on(async {});
} |
I suspect it's this check: https://github.com/rust-lang/rust-clippy/blob/d2f76f7/clippy_lints/src/returns.rs#L378-L381. |
Oh, that's probably due to temporaries? (Then we most likelyneed that as well) |
Yeah: https://github.com/rust-lang/rust-clippy/blame/48b4aea/clippy_lints/src/returns.rs#L19-L20
Sounds like a limitation of Clippy itself (it's too conservative here), but we probably want to match it anyway. |
Is there any way to disable this behavior? |
@arnfaldur see my comment at the top. |
@lnicola ah, sorry, didn't think too much about that as I don't use VSCode. There must be some way to configure LSPs in vim/emacs like that. I'll figure it out, thanks. |
@arnfaldur and anyone else who lands here looking for a workaround in emacs using eglot, here is the configuration tweak I have, which appears to work: (with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs
'((rust-ts-mode rust-mode) .
("rust-analyzer"
:initializationOptions
(:check
(:command "clippy")
:diagnostics
(:disabled ["needless_return"
"clippy::needless_return"])))))) The |
This comment was marked as off-topic.
This comment was marked as off-topic.
for lspconfig within mason: require("mason-lspconfig").setup_handlers({
["rust_analyzer"] = function()
require("lspconfig").rust_analyzer.setup({
on_attach = on_attach,
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
diagnostics = {
disabled = {
"needless_return",
},
},
},
},
})
end,
})
|
The lint shouldn't trigger by default anymore next release until opted-in, 676455f |
It has to be released right? Thanks! |
It will be released on Monday, or you could use the nightly (I've triggered a build now, should finish in about 15 minutes). We don't own |
I'll create a PR when it's released. Thanks :) |
I imagine they might not want to use nightlies, so it's probably fine to wait until Monday. |
mason-registry's versions are auto updated :) |
Didn't work for me on VSCode and clippy 0.1.79 (129f3b99 2024-06-10). Are there other solutions? |
#![allow(clippy::needless_return)] -- works in clippy 0.1.80. |
default_settings = {
checkOnSave = {
false
}
} For my configuraiotn, disable |
Uh oh!
There was an error while loading. Please reload this page.
Rust-analyzer has started to give code action suggestions for removing
return
from my code despite me allowingclippy::needless_return
via#![allow(clippy::needless_return)]
.In my coding style, I do not like my
returns
to be implicit, and I don't really align with the push to force not using return statements in the Rust tooling (e.g. Clippy, Rust-analyzer, etc).Could you add an option to remove this code action, or respect the clippy configuration enabled at the module level?
rust-analyzer version: 0.4.1838-standalone
rustc version: rustc 1.75.0-nightly (42b1224e9 2023-10-15)
relevant settings: (eg. client settings, or environment variables like
CARGO
,RUSTC
,RUSTUP_HOME
orCARGO_HOME
)The offending feature:
#16460
The text was updated successfully, but these errors were encountered: