-
- Notifications
You must be signed in to change notification settings - Fork 14.2k
recommend using a HashMap if a HashSet's second generic parameter doesn't implement BuildHasher #147171
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
Conversation
| r? @fee1-dead rustbot has assigned @fee1-dead. Use |
48c4887 to 65afb13 Compare This comment has been minimized.
This comment has been minimized.
65afb13 to 9d34ff5 Compare | note: the foreign item type `String` doesn't implement `BuildHasher` | ||
| --> $SRC_DIR/alloc/src/string.rs:LL:COL | ||
| | | ||
| = note: not implement `BuildHasher` |
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.
note to self, this probably needs improvement.
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. Could there be other tests that showcase when this help message could appear? For example when I try to insert, or when I try to create a new value of the HashSet type.
Also I think it might be better to put this under the less crowded tests/ui/hashmap directory.
| Still waiting on other tests. Also, use |
1703519 to 263ccbb Compare | I've added a test for the insert case. It seems pretty representative of most instances of this error, since the HashSet bounds are on methods. If we want to lint (not error) on HashSet construction with a second parameter that doesn't impl BuildHasher (and I'm not convinced we do), that's a separate conversation. @rustbot ready |
| help: you might have intended to use a HashMap instead | ||
| --> $DIR/hashset_generics.rs:8:5 | ||
| | | ||
| LL | #[derive(PartialEq)] | ||
| | --------- in this derive macro expansion | ||
| ... | ||
| LL | pub parameters: HashSet<String, String>, | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
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.
Can we just use err.help() to avoid highlighting the same thing again?
263ccbb to 9bad0ae Compare | ☔ The latest upstream changes (presumably #147957) made this pull request unmergeable. Please resolve the merge conflicts. |
9bad0ae to d83bbad Compare | This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| @rustbot ready |
d83bbad to 2656007 Compare | @rustbot ready |
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.
had one last nit, otherwise this is good to go!
| if foreign_preds.iter().any(|&(root_pred, pred)| { | ||
| if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(root_pred)) = | ||
| root_pred.kind().skip_binder() | ||
| && let Some(root_adt) = root_pred.self_ty().ty_adt_def() | ||
| { | ||
| self.tcx.is_diagnostic_item(sym::HashSet, root_adt.did()) | ||
| && self.tcx.is_diagnostic_item(sym::BuildHasher, pred.def_id()) | ||
| } else { | ||
| false | ||
| } | ||
| }) { | ||
| err.help("you might have intended to use a HashMap instead"); | ||
| } |
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.
Might be nice to extract this to a helper function that deduplicates the logic between this one and the one above, maybe named something like "suggest_hashmap_on_unsatisfied_hashset_buildhasher"
…sn't implement BuildHasher
2656007 to 754a82d Compare | @rustbot ready |
| @bors r+ rollup |
Rollup of 7 pull requests Successful merges: - #147171 (recommend using a HashMap if a HashSet's second generic parameter doesn't implement BuildHasher) - #147421 (Add check if span is from macro expansion) - #147521 (Make SIMD intrinsics available in `const`-contexts) - #148201 (Start documenting autodiff activities) - #148797 (feat: Add `bit_width` for unsigned `NonZero<T>`) - #148798 (Match <OsString as Debug>::fmt to that of str) - #149082 (autodiff: update formating, improve examples for the unstable-book) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #147171 - Qelxiros:hashmap_diag, r=fee1-dead recommend using a HashMap if a HashSet's second generic parameter doesn't implement BuildHasher closes #147147 ~The suggestion span is wrong, but I'm not sure how to find the right one.~ fixed I'm relatively new to the diagnostics ecosystem, so I'm not sure if `span_help` is the right choice. `span_suggestion_*` might be better, but the output from `x test` looks weird in that case.
Rollup of 7 pull requests Successful merges: - rust-lang/rust#147171 (recommend using a HashMap if a HashSet's second generic parameter doesn't implement BuildHasher) - rust-lang/rust#147421 (Add check if span is from macro expansion) - rust-lang/rust#147521 (Make SIMD intrinsics available in `const`-contexts) - rust-lang/rust#148201 (Start documenting autodiff activities) - rust-lang/rust#148797 (feat: Add `bit_width` for unsigned `NonZero<T>`) - rust-lang/rust#148798 (Match <OsString as Debug>::fmt to that of str) - rust-lang/rust#149082 (autodiff: update formating, improve examples for the unstable-book) r? `@ghost` `@rustbot` modify labels: rollup
recommend using a HashMap if a HashSet's second generic parameter doesn't implement BuildHasher closes rust-lang#147147 ~The suggestion span is wrong, but I'm not sure how to find the right one.~ fixed I'm relatively new to the diagnostics ecosystem, so I'm not sure if `span_help` is the right choice. `span_suggestion_*` might be better, but the output from `x test` looks weird in that case.
closes #147147
The suggestion span is wrong, but I'm not sure how to find the right one.fixedI'm relatively new to the diagnostics ecosystem, so I'm not sure if
span_helpis the right choice.span_suggestion_*might be better, but the output fromx testlooks weird in that case.