-
Notifications
You must be signed in to change notification settings - Fork 14k
Fix ICE when suggesting dereferencing binop operands #119361
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
|
(rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
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 code continues to fail because it's trying to construct a trait predicate for the Sized trait with 2 generic arguments. We should not be trying to perform this code on traits that are not operators.
8a671d9 to
5b3ce22
Compare
|
That makes sense, thanks for the help. I've added a check for that. @rustbot review |
| && hir::lang_items::OPERATORS.iter().any(|&op| { | ||
| // Ensure we only run this code on operators | ||
| self.tcx.require_lang_item(op, None) == trait_pred.skip_binder().trait_ref.def_id | ||
| }) |
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.
Diagnostic code should not require language items. Please use a fallible API.
| && hir::lang_items::OPERATORS.iter().any(|&op| { | |
| // Ensure we only run this code on operators | |
| self.tcx.require_lang_item(op, None) == trait_pred.skip_binder().trait_ref.def_id | |
| }) | |
| // Ensure we only run this code on operators | |
| && hir::lang_items::OPERATORS.iter().filter_map(|&op| self.tcx.lang_items().get(op)).any(|op| { | |
| op == trait_pred.skip_binder().trait_ref.def_id | |
| }) |
@rustbot author
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 needs to check that it's a binary operator as well. This still would ICE if I had a nested unary operator as a predicate.
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.
Diagnostic code should not require language items. Please use a fallible API.
Fixed, thanks for pointing this out.
This still would ICE if I had a nested unary operator as a predicate.
I don't think this is necessarily the case--we already check that the rhs is Some, which would fail if it were a unary op: https://github.com/sjwang05/rust/blob/issue-119352/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs#L856
@rustbot review
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.
I don't think this is necessarily the case--we already check that the rhs is Some
No, you can have a binary operator predicate with a unary operator predicate as a where clause bound.
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.
Ahh, I see. I fixed the check to filter out unary ops.
@rustbot review
| self.tcx.mk_args( | ||
| &[&[l_ty.into(), r_ty.into()], &inner.trait_ref.args[2..]] | ||
| .concat(), | ||
| self.tcx.mk_args_trait( |
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.
Why did you use mk_args_trait here? It's harder to read, imo. You should just use mk_args like before. The indexing that was previous here should be correct if we're always using binop traits here.
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.
Mainly due to the indexing problem--I reverted it to mk_args.
c29b565 to
44e5631
Compare
WaffleLapkin
left a comment
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.
Just a small nitpick and I think we can merge this :)
| .filter_map(|&op| | ||
| (!matches!(op, LangItem::Neg | LangItem::Not)) | ||
| .then_some(self.tcx.lang_items().get(op)) | ||
| .flatten() | ||
| ) |
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.
| .filter_map(|&op| | |
| (!matches!(op, LangItem::Neg | LangItem::Not)) | |
| .then_some(self.tcx.lang_items().get(op)) | |
| .flatten() | |
| ) | |
| .filter(|op| !matches!(op, LangItem::Neg | LangItem::Not)) | |
| .filter_map(|&op| self.tcx.lang_items().get(op)) |
44e5631 to
824fd62
Compare
|
Fixed, thanks. @rustbot review |
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
824fd62 to
c36b5d5
Compare
WaffleLapkin
left a comment
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.
Thanks!
|
@bors r+ rollup |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (8847bda): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 668.181s -> 668.597s (0.06%) |
Fixes #119352