-
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
Silence unecessary !Sized binding error #122119
Conversation
r? @Nadrieril rustbot has assigned @Nadrieril. Use r? to explicitly pick a reviewer |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Silence unecessary !Sized binding error When gathering locals, we introduce a `Sized` obligation for each binding in the pattern. *After* doing so, we typecheck the init expression. If this has a type failure, we store `{type error}`, for both the expression and the pattern. But later we store an inference variable for the pattern. We now avoid any override of an existing type on a hir node when they've already been marked as `{type error}`, and on E0277, when it comes from `VariableType` we silence the error in support of the type error. Fix rust-lang#117846
This comment has been minimized.
This comment has been minimized.
if let Some(ty) = node_ty.remove(id) | ||
&& let ty::Error(e) = ty.kind() | ||
{ | ||
// Do not overwrite nodes that were already marked as `{type error}`. This allows us to | ||
// silence unnecessary errors from obligations that were set earlier than a type error | ||
// was produced, but that is overwritten by later analysis. This happens in particular | ||
// for `Sized` obligations introduced in gather_locals. (#117846) | ||
node_ty.insert(id, ty); |
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 not node_ty.get(id)
instead of remove
+insert
?
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.
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.
Wouldn't get_mut
work 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.
It would. It's just that the type would get discarded and overwritten regardless of the success or not of the let chain, but yeah, I can make it use get_mut
.
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.
Ah, my surprise came from the fact that you're reinserting the ty
you just removed. I guess you intended to insert the ty
you got as input to the function?
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 intended to reinsert the type I got because it is a ty::Err, which should remain, any other type would get rewritten.
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 see. I would indeed prefer if you used get_mut
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.
Or implemented get
tbh
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.
If you really prefer remove
+insert
could you then name the variable something like err_ty
to clarify the intent?
let mut typeck = self.typeck_results.borrow_mut(); | ||
let mut node_ty = typeck.node_types_mut(); | ||
if let Some(ty) = node_ty.remove(id) | ||
&& let ty::Error(e) = ty.kind() |
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.
Would there be value in a ty.error_reported()
check here to catch more errors?
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.
Isn't it enough to check we have an ErrorGuaranteed
for that?
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.
error_reported()
looks for ty::Error
even deep within the type, so it would also catch e.g. (T, {type error})
. I don't know if that's relevant to this check tho
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (36df47e): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never 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: 647.359s -> 647.517s (0.02%) |
r=me once the |
@rustbot author |
When gathering locals, we introduce a `Sized` obligation for each binding in the pattern. *After* doing so, we typecheck the init expression. If this has a type failure, we store `{type error}`, for both the expression and the pattern. But later we store an inference variable for the pattern. We now avoid any override of an existing type on a hir node when they've already been marked as `{type error}`, and on E0277, when it comes from `VariableType` we silence the error in support of the type error. Fix rust-lang#117846.
@bors r=Nadrieril |
☀️ Test successful - checks-actions |
Finished benchmarking commit (b7dcabe): 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.
CyclesResultsThis 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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 670.108s -> 669.559s (-0.08%) |
…rors Do not attempt to write `ty::Err` on binding that isn't from current HIR Owner Fix rust-lang#123009. Follow up to rust-lang#122119.
When gathering locals, we introduce a
Sized
obligation for eachbinding in the pattern. After doing so, we typecheck the init
expression. If this has a type failure, we store
{type error}
, forboth the expression and the pattern. But later we store an inference
variable for the pattern.
We now avoid any override of an existing type on a hir node when they've
already been marked as
{type error}
, and on E0277, when it comes fromVariableType
we silence the error in support of the type error.Fix #117846