Uh oh!
There was an error while loading. Please reload this page.
Make derive(Trait) suggestion more accurate - #119362
Conversation
rustbot
commented
Dec 27, 2023
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
| self.suggest_derive(err, &preds, suggest_derive); | ||
| } | ||
| pub fn suggest_derive( |
There was a problem hiding this comment.
I find it confusing that this method is called suggest_derive but apparently does more than suggesting #[derive]. It also adds the note the trait[…] […] must be implemented. Adding the flag suggest_derive to … suggest_derive makes it even more confusing. Could this method be renamed or even refactored into two methods potentially allowing us to get rid of the bool parameter altogether?
There was a problem hiding this comment.
I wanted to make this as minimal a diff as possible :)
suggest_derivealso emits some extra notes (that I didn't want to lose). I'm assuming we added that after the method was created and we didn't modify the method name then. I can either rename the method and keep the argument, or split the logic in two (or three?) methods and call them only when needed.
There was a problem hiding this comment.
I see :) If you can find a good name for it, go for a rename. You can also do a refactor instead either in this PR or or in a follow-up one, larger diffs are fine by me.
There was a problem hiding this comment.
What do you think of the change?
There was a problem hiding this comment.
Thanks, it's an improvement. Although, the way it's split into two methods doesn't feel right: note_predicate_source_and_get_derives still does two things, it calculates traits and derives and only adds a note for traits but never for derive and we do a bunch of work formatting derives just to throw it away if !suggest_derive.
105e206 to
c9b0707Compare
fmease
left a comment
There was a problem hiding this comment.
r=me with the actionable subset of my most recent suggestions applied or if you find a better way to split those two functions then go for it and re-request a review :)
Uh oh!
There was an error while loading. Please reload this page.
| Option<ObligationCause<'tcx>>, | ||
| )], | ||
| ) { | ||
| ) -> Vec<(String, Span, String)> { |
There was a problem hiding this comment.
Hmm, it's only in the error path but I'd love to skip the entire if let Some(diagnostic_name) = self.tcx.get_diagnostic_name(trait_pred.def_id()) check if !suggest_derive but then we'd need to introduce suggested_derive: bool to note_pre_src_and_get_derives :(
Uh oh!
There was an error while loading. Please reload this page.
Only suggest `derive(PartialEq)` when both LHS and RHS types are the same, otherwise the suggestion is not useful.
c9b0707 to
2474b37Compareestebank
commented
Jan 4, 2024
@bors r=fmease |
bors
commented
Jan 4, 2024
…n, r=fmease Make `derive(Trait)` suggestion more accurate Only suggest `derive(PartialEq)` when both LHS and RHS types are the same, otherwise the suggestion is not useful.
…mpiler-errors Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119414 (bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
…mpiler-errors Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119414 (bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119539 (Fix typos) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119539 (Fix typos) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#118521 (Enable address sanitizer for MSVC targets using INFERASANLIBS linker flag) - rust-lang#119026 (std::net::bind using -1 for openbsd which in turn sets it to somaxconn.) - rust-lang#119195 (Make named_asm_labels lint not trigger on unicode and trigger on format args) - rust-lang#119204 (macro_rules: Less hacky heuristic for using `tt` metavariable spans) - rust-lang#119362 (Make `derive(Trait)` suggestion more accurate) - rust-lang#119397 (Recover parentheses in range patterns) - rust-lang#119417 (Uplift some miscellaneous coroutine-specific machinery into `check_closure`) - rust-lang#119539 (Fix typos) - rust-lang#119540 (Don't synthesize host effect args inside trait object types) - rust-lang#119555 (Add codegen test for RVO on MaybeUninit) r? `@ghost` `@rustbot` modify labels: rollup
compiler-errors
commented
Jan 4, 2024
@bors rollup |
Rollup merge of rust-lang#119362 - estebank:restrict-derive-suggestion, r=fmease Make `derive(Trait)` suggestion more accurate Only suggest `derive(PartialEq)` when both LHS and RHS types are the same, otherwise the suggestion is not useful.
Only suggest
derive(PartialEq)when both LHS and RHS types are the same, otherwise the suggestion is not useful.