-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Rework "point at arg" suggestions to be more accurate #100654
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d573569
to
c8d7081
Compare
This comment has been minimized.
This comment has been minimized.
a94562b
to
ab844c5
Compare
I think this is ready for review. I am happy to talk over zulip or meet with anyone to discuss the main changes in this PR if interested. I am also happy to explain any cases where diagnostics have changed, to help weigh the benefits over the shortcomings over this PR. In general, though, I think this is a major improvement over the old logic. r? diagnostics |
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 need to finish looking at checks.rs
, but I'm comfortable landing as is so far.
compiler/rustc_infer/src/infer/error_reporting/nice_region_error/mismatched_static_lifetime.rs
Show resolved
Hide resolved
) = | ||
(self.tcx.sess.source_map().span_to_snippet(span), obligation.cause.code()) | ||
} else if let Ok(snippet) = &self.tcx.sess.source_map().span_to_snippet(span) | ||
&& let ObligationCauseCode::BindingObligation(def_id, _) | ObligationCauseCode::ExprBindingObligation(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.
Seeing the proliferation of these kind of checks, we might want to start adding methods to the ObligationCauseCode
to deduplicate them.
let Some(arg_ty) = typeck_results.node_type_opt(*arg_hir_id) | ||
else { return false }; |
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.
IIRC there's a separate more appropriate method along the lines of resolved_node_type_opt
. I believe this method gives you the type before inference. It's still useful, but not maximally so. (Unless I'm wrong and I'm misremembering things.)
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.
do you mean expr_ty_adjusted
?
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.
Yes!
| _____|_____________within this `[closure@$DIR/no-send-res-ports.rs:25:19: 25:25]` | ||
| | | | ||
| | required by a bound introduced by this call | ||
LL | | | ||
LL | | let y = x; | ||
LL | | println!("{:?}", y); | ||
LL | | }); | ||
| |_____^ `Rc<()>` cannot be sent between threads safely |
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.
Maybe we should special case closures like we do for the within this
to customize the output here.
| | ||
LL | f_unpin(static || { yield; }); | ||
| ^^^^^^^ the trait `Unpin` is not implemented for `[static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:22]` | ||
| ------- ^^^^^^^^^^^^^^^^^^^^ the trait `Unpin` is not implemented for `[static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:22]` |
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 just realized that in cases where the closure would be the only label, and it's pointing at the closure itself, we can customize the output and refer to "this closure" 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.
This seems a bit difficult since I'm walking over the unsubstituted predicate here. I'm gonna leave that as a follow-up, since it's not technically a regression I think.
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.
Yeah, yeah, this was more of a general observation, not part of the review.
| ------------ ^^^^^ expected an `FnMut<(char,)>` closure, found `u8` | ||
| | | ||
| required by a bound introduced by this call | ||
| ^^^^^^^^^^^^ expected an `FnMut<(char,)>` closure, found `u8` |
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.
Do you know why we might have this regression? (We should also modify the main message to talk about Pattern
, like we did with the help
.
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.
Also not part of the review.
span, | ||
traits::SizedArgumentType(None), | ||
traits::SizedArgumentType(arg_span), |
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 think here is where we could keep around the info about the Sized
argument requirement coming from a call.
match hir.get(hir_id) { | ||
hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Path(qpath), hir_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.
Should we move all of this to its own method?
b25a1bc
to
f74e258
Compare
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
r=me |
This comment has been minimized.
This comment has been minimized.
I'm gonna fix CI, then land this and work on a couple of easy follow-ups like those weird closure overlapping spans. |
f74e258
to
cb7a2ec
Compare
Rebased, will wait until CI is green. |
@bors r=estebank rollup=never (kinda bitrotty probably) |
📌 Commit cb7a2ec40879726ec47c777e128e0c0de5f4e6dd has been approved by It is now in the queue for this repository. |
6d6e9f5
to
4045a26
Compare
Actually, I think I overestimated the difficulty of rebasing this. The fix was to just add an extra match for @bors r=estebank |
📌 Commit 4045a268443bed3a3688340e8550d1c7b03cf78d has been approved by It is now in the queue for this repository. |
This comment has been minimized.
This comment has been minimized.
Tidy is the bane of my existence. |
4045a26
to
d577eb0
Compare
@bors r=estebank |
☀️ Test successful - checks-actions |
Finished benchmarking commit (0b71ffc): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
Fixes #100560
Introduce a new set of
ObligationCauseCode
s which have additional bookeeping for what expression caused the obligation, and which predicate caused the obligation. This allows us to look at the unsubstituted signature to find out which parameter or generic type argument caused an obligaton to fail.This means that (in most cases) we significantly improve the likelihood of pointing out the right argument that causes a fulfillment error. Also, since this logic isn't happening in just the
select_where_possible_and_mutate_fulfillment()
calls in the argument checking code, but instead during all trait selection inFnCtxt
, we are also able to point out the correct argument even if inference means that we don't know whether an obligation has failed until well after a call expression has been checked.r? @ghost