-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Update to fix regression 90319 and correctly emit overflow errors when not inside an error reporting context #91238
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -262,6 +262,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
"probe(self_ty={:?}, return_type={}, scope_expr_id={})", | ||
self_ty, return_type, scope_expr_id | ||
); | ||
self.set_tainted_by_errors(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @estebank I moved it here because we only hit it when we're in an error reporting context here as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you look at the code in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you are correct - I think either location is fine but if you prefer it to be here then I can move it. I think however that we probably need a new flag to suppress errors that happen in the same pass, as |
||
let method_names = self | ||
.probe_op( | ||
span, | ||
|
@@ -1469,7 +1470,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { | |
let cause = traits::ObligationCause::misc(self.span, self.body_id); | ||
let predicate = ty::Binder::dummy(trait_ref).to_poly_trait_predicate(); | ||
let obligation = traits::Obligation::new(cause, self.param_env, predicate); | ||
traits::SelectionContext::new(self).select(&obligation) | ||
traits::SelectionContext::with_suggestion(self, self.is_suggestion.0).select(&obligation) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't modifying the selection context before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea so looking back at it I'm not sure I even need this new field I think I actually just needed to move where I set that we were tainted by errors. I'll see if I can change it this evening so we don't need the new selection context field. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what's happen is I wanted a way to distinguish inside the selection context itself whether we were creating a suggestion but forgetting that it derefs down into the function context that spawned it which already has the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had a look at it this evening - it starts ICEing again if I rely on I need to confirm this first however so will do some more digging. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can say for sure that without the new field in the selection context struct if It may be better to add the field to the infer_ctx struct to set instead of tainting it with errors so that I can be confident that I set it and can handle the overflow errors correctly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds like a reasonable avenue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can put it back however in my other implementation of this I don't rely on it anymore instead preferring to use a flag in the inferctx, I've linked my other implementation in the PR at the bottom which I think is more robust |
||
} | ||
|
||
fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource { | ||
|
@@ -1521,7 +1522,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { | |
let mut xform_ret_ty = probe.xform_ret_ty; | ||
debug!(?xform_ret_ty); | ||
|
||
let selcx = &mut traits::SelectionContext::new(self); | ||
let selcx = &mut traits::SelectionContext::with_suggestion(self, self.is_suggestion.0); | ||
let cause = traits::ObligationCause::misc(self.span, self.body_id); | ||
|
||
// If so, impls may carry other conditions (e.g., where | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
struct Wrapper<T>(T); | ||
|
||
trait Trait { | ||
fn method(&self) {} | ||
} | ||
|
||
impl<'a, T> Trait for Wrapper<&'a T> where Wrapper<T>: Trait {} | ||
|
||
fn get<T>() -> T { | ||
unimplemented!() | ||
} | ||
|
||
fn main() { | ||
let thing = get::<Thing>();//~ERROR 14:23: 14:28: cannot find type `Thing` in this scope [E0412] | ||
let wrapper = Wrapper(thing); | ||
Trait::method(&wrapper);//~ERROR 16:5: 16:18: overflow evaluating the requirement `_: Sized` [E0275] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error[E0412]: cannot find type `Thing` in this scope | ||
--> $DIR/issue-90319.rs:14:23 | ||
| | ||
LL | let thing = get::<Thing>(); | ||
| ^^^^^ not found in this scope | ||
|
||
error[E0275]: overflow evaluating the requirement `_: Sized` | ||
--> $DIR/issue-90319.rs:16:5 | ||
| | ||
LL | Trait::method(&wrapper); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_90319`) | ||
note: required because of the requirements on the impl of `Trait` for `Wrapper<&_>` | ||
--> $DIR/issue-90319.rs:7:13 | ||
| | ||
LL | impl<'a, T> Trait for Wrapper<&'a T> where Wrapper<T>: Trait {} | ||
| ^^^^^ ^^^^^^^^^^^^^^ | ||
= note: 128 redundant requirements hidden | ||
= note: required because of the requirements on the impl of `Trait` for `Wrapper<&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&_>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0275, E0412. | ||
For more information about an error, try `rustc --explain E0275`. |
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 is this removed?
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 actually moved it to the top of
probe_for_return
in the probe module as having it in this location meant that it was being hit when we weren't in an error context during trait bound fulfillment.Moving it to the new location meant it only got set when we were actively looking for a method suggestion in an error.
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.
Does keeping this call to
set_tainted_by_errors
cause any undesired effect?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 haven't tried it but can test it out - I think you're right that it can be kept there, I'm fairly sure that both spot I've tried it in are in error reporting pathways anyway.
I think the bigger issue is that
set_tainted_by_errors
is being called elsewhere before this point due to name resolution being unable to resolveThing
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 try getting this back in to see the effect?
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.
Replied in the wrong place - see my comment on the other review but I'm going to push a change tomorrow that I think works better