-
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
Properly check that array length is valid type during built-in unsizing in index #136205
Conversation
changes to the core type system |
We don't check the array is wf because we assume that field types are wf if the struct is wf right? Why do we believe that only arrays will cause issues and not arbitrary other types, because we only expect mir building to interact with builtin types in ways that would be wrong if they were not-wf? |
No, we definitely do not do this, and in general it's kind of a non-local assumption to make, since the index operator (or a method call, for example) can't really know from where a type originated. If I have some struct like:
and I do:
I'll get a WF error if
This bug is specifically caused by our special casing of array types in hir typeck here in a way that side-steps the wf obligations that we would've otherwise collected by actually applying an impl like To me this feels like we're incompletely applying a built-in impl's where clauses that we really ought to be enforcing, and are just luckily avoiding because we can ensure that they're satisfied elsewhere.
We're already checking these predicates practically everywhere else -- all impls with const generics and on array types themselves. I could queue a perf run tho. @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Properly check that array length is valid type during built-in unsizing in index This results in duplicated errors, but this class of errors is not new; in general, we aren't really equipped to detect cases where a WF error due to a field type would be shadowed by the parent struct of that field also not being WF. This also adds a note for these types of mismatches to make it clear that this is due to an array type. Fixes rust-lang#134352 r? boxyuwu
In other words, in a perfect compiler, we'd be registering the
which would have an implicit But because we're not actually going thru that impl, we're side-stepping that predicate, which means that we don't taint the infcx, and end up getting generating malformed MIR which is built off of the assumption that array len consts are always type |
If we don't assume that field types are wf then why does the crashes test ICE? struct Struct<const N: i128>(pub [u8; N]);
pub fn function(value: Struct<3>) -> u8 {
value.0[0]
}
|
Well so we do assume the field types are WF, but what I'm saying is that that's not an assumption we can or should rely on, because it's really just a side-effect of how we type check the indexing operation in this one case. We don't assume it's WF in other cases such as method lookup, which is that example that I provided above. |
If we're not assuming field types are wf why do we not just check edit: tbc when I say assume I don't mean in an implied bounds sense, just a "we dont bother explicitly checking wf(typeof(a.b))`" |
The fact that we're skipping a where clause on the builtin impl does make sense though. |
Yeah, kinda that's the state of things. I think changing this to always check that |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (fd022b2): comparison URL. Overall result: ✅ improvements - 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 is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -0.8%, secondary 2.3%)This 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.
CyclesResults (secondary -1.7%)This 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: 772.605s -> 771.032s (-0.20%) |
@bors r+ rollup |
Properly check that array length is valid type during built-in unsizing in index This results in duplicated errors, but this class of errors is not new; in general, we aren't really equipped to detect cases where a WF error due to a field type would be shadowed by the parent struct of that field also not being WF. This also adds a note for these types of mismatches to make it clear that this is due to an array type. Fixes rust-lang#134352 r? boxyuwu
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#133382 (Suggest considering casting fn item as fn pointer in more cases) - rust-lang#136092 (Test pipes also when not running on Windows and Linux simultaneously) - rust-lang#136190 (Remove duplicated code in RISC-V asm bad-reg test) - rust-lang#136192 (ci: remove unused windows runner) - rust-lang#136205 (Properly check that array length is valid type during built-in unsizing in index) - rust-lang#136211 (Update mdbook to 0.4.44) - rust-lang#136212 (Tweak `&mut self` suggestion span) - rust-lang#136214 (Make crate AST mutation accessible for driver callback) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#136205 - compiler-errors:len-3, r=BoxyUwU Properly check that array length is valid type during built-in unsizing in index This results in duplicated errors, but this class of errors is not new; in general, we aren't really equipped to detect cases where a WF error due to a field type would be shadowed by the parent struct of that field also not being WF. This also adds a note for these types of mismatches to make it clear that this is due to an array type. Fixes rust-lang#134352 r? boxyuwu
This results in duplicated errors, but this class of errors is not new; in general, we aren't really equipped to detect cases where a WF error due to a field type would be shadowed by the parent struct of that field also not being WF.
This also adds a note for these types of mismatches to make it clear that this is due to an array type.
Fixes #134352
r? boxyuwu