-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Always point at index span on index obligation failure #117856
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
Use more targetted span for index obligation failures by rewriting the obligation cause span. CC rust-lang#66023
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
@@ -2877,7 +2877,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
// two-phase not needed because index_ty is never mutable | |||
self.demand_coerce(idx, idx_t, index_ty, None, AllowTwoPhase::No); | |||
self.select_obligations_where_possible(|errors| { | |||
self.point_at_index_if_possible(errors, idx.span) | |||
self.point_at_index(errors, idx.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.
This makes me pretty uncomfortable. We may be selecting obligations that are only connected to the index expression by long chains of inference, i.e. that are only able to be selected due to coercion that happens above. This seems both non-local and order-dependent.
I would prefer if you just made the heuristic better in point_at_index_if_possible
-- which is already a hack, but at least currently it's localized to SliceIndex
trait predicates -- or find out where that Borrow
obligation comes from below and give it a better ObligationCauseCode
so that it may be noted more precisely.
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.
One check I could make is to pass in the whole expression span in and only modify those that are matched. I initially did that, but then it didn't make any difference to any test in the suite, so I reduced to what there is in the pr.
Why not just check that the root obligation (or at least when we peel the derives from the obligation cause) of the error comes from an |
Because the root obligation is MiscObligation, and figuring out where the relevant one is created is a chore 😅 Every now and then I add a u16 sentinel to them so that I can actually track them down, but it didn't seem worth the effort here. |
What do you mean? I just meant checking the trait def id of the root obligation for each fulfillment error you're modifying in
Given that no other test in the suite was affected here, I think it's probably most likely that we lack good testing. That's one of the contributing factors for my uncomfort towards how large of a hammer this PR is. In that case, I think it's best to make this modification more defensively rather than have to deal with users complaining about poor spans later on. |
{ | ||
seen_preds.insert(error.obligation.predicate.kind().skip_binder()); | ||
} | ||
(root, pred) if seen_preds.contains(&pred) | seen_preds.contains(&root) => {} |
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.
Is there a test exercising this branch?
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, ||
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, without this the new test ends up with 2 E0277, one pointing at the index (with depth=0) and one to the whole expr (with depth=1). The later doesn't have an Index root_obligation, but the same trait predicate, which is why I did this (which felt less hacky than maybe relying on Spans or something like that).
This comment has been minimized.
This comment has been minimized.
08fb7b1
to
e90fe80
Compare
r=me |
e90fe80
to
5061c09
Compare
@bors r=compiler-errors |
…rrors Always point at index span on index obligation failure Use more targetted span for index obligation failures by rewriting the obligation cause span. CC rust-lang#66023
☀️ Test successful - checks-actions |
Finished benchmarking commit (173b6e6): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. 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: 674.024s -> 672.988s (-0.15%) |
Use more targetted span for index obligation failures by rewriting the obligation cause span.
CC #66023