-
Notifications
You must be signed in to change notification settings - Fork 1.6k
explicit_auto_deref could suggest variale with borrows #9109
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
I think I have a similar case (let me know if it should be a separate issue), but I'm not sure if it's actually a bad diagnostic or just me holding it wrong. Given this code: use once_cell::sync::Lazy;
static BASE_URL: Lazy<String> =
Lazy::new(|| std::env::var("BASE_URL").expect("BASE_URL must be defined"));
fn main() {
function(&**BASE_URL);
}
fn function(url: &str) {
let _ = url;
} The emitted diagnostic is this:
At a first glance one might change this invocation to
|
I originally had it that way and I don't remember why I switched it. It had something to do with how the lint pass was implemented. Related question, how does the suggestion look with
This one looks fine to me unlike a immutable borrow. Edit: I guess #9127 answers that question. |
`explicit_auto_deref` changes fixes #9123 fixes #9109 fixes #9143 fixes #9101 This avoid suggesting code which hits a rustc bug. Basically `&{x}` won't use auto-deref if the target type is `Sized`. changelog: Don't suggest using auto deref for block expressions when the target type is `Sized` changelog: Include the borrow in the suggestion for `explicit_auto_deref` changelog: Don't lint `explicit_auto_deref` on `dyn Trait` return changelog: Don't lint `explicit_auto_deref` when other adjustments are required
Description
The
op_ref
lint already does this:IMO its easier to understand if the span and the suggestion includes the borrows
so
could become
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: