-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Suggest unwrapping ???<T>
if a method cannot be found on it but is present on T
.
#102288
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @compiler-errors (or someone else) soon. Please see the contribution instructions for more information. |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
This comment has been minimized.
This comment has been minimized.
I wonder if a cooler approach would be to make a diagnostic attribute that can be added to any struct that signals "hey, this is really just a wrapper for an inner type" (Though, its probably just easily to take the current approach) |
That's a cool idea - worth considering I think. It could end up being rather wordy though, like how |
☔ The latest upstream changes (presumably #102306) made this pull request unmergeable. Please resolve the merge conflicts. |
Some changes occurred in HTML/CSS themes.
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki rustdoc-json-types is a public (although nightly-only) API. If possible, consider changing cc @CraftSpider, @aDotInTheVoid, @Enselic, @obi1kenobi Some changes occurred in HTML/CSS/JS. cc @GuillaumeGomez, @Folyd, @jsha Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt A change occurred in the Ayu theme. cc @Cldfire This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras Some changes occurred in src/librustdoc/clean/types.rs cc @camelid Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
Hm, looks like a rebase was messed up here.. |
@rustbot label -A-bootstrap -A-query-system -A-rustdoc-json -A-translation -T-libs |
Some(Mutability::Not) => { | ||
err.span_suggestion_verbose( | ||
expr.span.shrink_to_hi(), | ||
format!( | ||
"use `.borrow()` to borrow the `{ty}`, \ | ||
panicking if any outstanding mutable borrows exist." | ||
), | ||
".borrow()", | ||
Applicability::MaybeIncorrect, | ||
); | ||
} | ||
Some(Mutability::Mut) => { | ||
err.span_suggestion_verbose( | ||
expr.span.shrink_to_hi(), | ||
format!( | ||
"use `.borrow_mut()` to mutably borrow the `{ty}`, \ | ||
panicking if any outstanding borrows exist." | ||
), | ||
".borrow_mut()", | ||
Applicability::MaybeIncorrect, | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps deduplicate a bit?
Some(Mutability::Not) => { | |
err.span_suggestion_verbose( | |
expr.span.shrink_to_hi(), | |
format!( | |
"use `.borrow()` to borrow the `{ty}`, \ | |
panicking if any outstanding mutable borrows exist." | |
), | |
".borrow()", | |
Applicability::MaybeIncorrect, | |
); | |
} | |
Some(Mutability::Mut) => { | |
err.span_suggestion_verbose( | |
expr.span.shrink_to_hi(), | |
format!( | |
"use `.borrow_mut()` to mutably borrow the `{ty}`, \ | |
panicking if any outstanding borrows exist." | |
), | |
".borrow_mut()", | |
Applicability::MaybeIncorrect, | |
); | |
} | |
Some(mutbl) => { | |
let (suggestion, mutbly, mutbl) = match mutbl { | |
Mutability::Not => (".borrow()", "", "mutable "), | |
Mutability::Mut => (".borrow()", "mutably ", ""), | |
}; | |
err.span_suggestion_verbose( | |
expr.span.shrink_to_hi(), | |
format!( | |
"use `.borrow()` to {mutbly}borrow the `{ty}`, \ | |
panicking if any outstanding {mutbl}borrows exist." | |
), | |
suggestion, | |
Applicability::MaybeIncorrect, | |
); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'm not sure. I prefer being too verbose rather than too clever, and this looks very clever 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very common pattern to deduplicate essentially identical diagnostic messages. I'd actually prefer if you deduplicated it even more, but this one is the easiest to apply.
This comment has been minimized.
This comment has been minimized.
Actually, since you're adding a bunch of new custom error messages here, do you mind just converting them to derived structs? https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-structs.html |
@rustbot ready I've deduplicated some of the logic but I don't think I can do anything more clever without making a big mess.
I could be misunderstanding but I can't emit a subdiagnostic struct on a diagnosticbuilder. So it looks to me like that would entail refactoring basically all of |
|
Whatever though, this is fine for now. @bors r+ rollup |
Rollup of 8 pull requests Successful merges: - rust-lang#100747 (Add long description and test for E0311) - rust-lang#102232 (Stabilize bench_black_box) - rust-lang#102288 (Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`.) - rust-lang#102338 (Deny associated type bindings within associated type bindings) - rust-lang#102347 (Unescaping cleanups) - rust-lang#102348 (Tweak `FulfillProcessor`.) - rust-lang#102378 (Use already resolved `self_ty` in `confirm_fn_pointer_candidate`) - rust-lang#102380 (rustdoc: remove redundant mobile `.source > .sidebar` CSS) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`. This suggests various ways to get inside wrapper types if the method cannot be found on the wrapper type, but is present on the wrappee. For this PR, those wrapper types include `Localkey`, `MaybeUninit`, `RefCell`, `RwLock` and `Mutex`.
Rollup of 8 pull requests Successful merges: - rust-lang#100747 (Add long description and test for E0311) - rust-lang#102232 (Stabilize bench_black_box) - rust-lang#102288 (Suggest unwrapping `???<T>` if a method cannot be found on it but is present on `T`.) - rust-lang#102338 (Deny associated type bindings within associated type bindings) - rust-lang#102347 (Unescaping cleanups) - rust-lang#102348 (Tweak `FulfillProcessor`.) - rust-lang#102378 (Use already resolved `self_ty` in `confirm_fn_pointer_candidate`) - rust-lang#102380 (rustdoc: remove redundant mobile `.source > .sidebar` CSS) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This suggests various ways to get inside wrapper types if the method cannot be found on the wrapper type, but is present on the wrappee.
For this PR, those wrapper types include
Localkey
,MaybeUninit
,RefCell
,RwLock
andMutex
.