Uh oh!
There was an error while loading. Please reload this page.
Test validity of pattern types - #136145
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
RalfJung
commented
Jan 27, 2025
Surely patterns can express more than what fits into So some tests that probably still fail are:
|
oli-obk
commented
Jan 27, 2025
Those patterns are not supported yet and will just error out in ast lowering, never reaching the type system |
RalfJung
commented
Jan 28, 2025
What exactly is the full set of patterns supported currently? And how can we increase the probability that when that set gets expanded, the validity check is updated accordingly? |
oli-obk
commented
Jan 28, 2025
The validity check automatically handles everything, because it looks at the layout of pattern types. The problem will be once we can't represent something in the layout anymore. I could add an exhaustive match with a comment on the range pattern saying it's fully handled by the layout logic |
d9865d7 to
2ed0e74Comparerustbot
commented
Jan 28, 2025
Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri Some changes occurred to the CTFE machinery cc @rust-lang/wg-const-eval |
2ed0e74 to
cb79d1bCompareoli-obk
commented
Jan 28, 2025
done |
oli-obk
commented
Jan 28, 2025
Ah... I need to check nesting pattern types within each other. And for that we need to actually recurse into the base type. |
rustbot
commented
Jan 28, 2025
HIR ty lowering was modified cc @fmease |
This comment has been minimized.
This comment has been minimized.
de6c522 to
6697731Compareoli-obk
commented
Jan 28, 2025
Ok, I think I rejected everything that is relevant for validation and added tests for the rest |
d743801 to
bd1a54cCompareUh oh!
There was an error while loading. Please reload this page.
| // tests/ui/type/pattern_types/validity.rs | ||
| match **pat { | ||
| // Range patterns are handled fully by looking at the layout | ||
| ty::PatternKind::Range { .. } => {}, |
There was a problem hiding this comment.
Seems worth asserting that layout.backend_repr is indeed Scalar... skipping the recursion here is a bit dubious, we don't do this for anything else.
There was a problem hiding this comment.
In particular, I think this means that e.g. if a u32 range pattern type is uninitialized, or a char range pattern type is not a valid char, we skip the nice error that try_visit_primitive would generate, and instead show a more generic error in visit_scalar.
There was a problem hiding this comment.
Hmm tried recursing, but it doesn't actually do anything better
There was a problem hiding this comment.
Can you add char cases to pattern_types/validity.rs, one case where the character is valid but outside the range and one case where it's not even a valid char?
There was a problem hiding this comment.
So that test does show a different error with the extra call to visit_value? Great :)
RalfJung
commented
Feb 2, 2025
@rustbot author |
72dea42 to
640d948Compare
This comment has been minimized.
This comment has been minimized.
640d948 to
b5d3029Compare
This comment has been minimized.
This comment has been minimized.
b5d3029 to
c17eee6Compareoli-obk
commented
Feb 2, 2025
@rustbot ready |
RalfJung
commented
Feb 2, 2025
Please avoid rebasing when there is no conflict; now I can't see what the diff is to my last review. |
There was a problem hiding this comment.
This seems like it should be known-bug? We surely don't want to see these ICE reports, right?^^
There was a problem hiding this comment.
it is already, just with no issue open, so known-bug: unknown
oli-obk
commented
Feb 2, 2025
There were diffs that confused me, so I thought rebasing would solve them, but it turned out it was diffs in the LOC of the panic location. So now I filtered out those. |
c17eee6 to
7e4ccc2Compareoli-obk
commented
Feb 2, 2025
@rustbot ready |
| } | ||
| ty::Pat(base, pat) => { | ||
| // First check that the base type is valid | ||
| self.visit_value(&val.transmute(self.ecx.layout_of(*base)?, self.ecx)?)?; |
There was a problem hiding this comment.
Is there a field projection for this? Or is transmute the way this is meant to be done?
There was a problem hiding this comment.
There is no field projection. Using a field like representation is what we want to get rid of with pattern types to avoid all the pains we have with the rustc_scalar_layout attributes. We could add something to the validation path to show that we're validating the base type, but there's no projection for it, just like niche optimized enums have no projection for the discriminant really
RalfJung
commented
Feb 2, 2025
r=me with CI green, assuming that there is indeed no field projection. |
oli-obk
commented
Feb 2, 2025
@bors r=RalfJung |
bors
commented
Feb 2, 2025
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#136145 (Test validity of pattern types) - rust-lang#136339 (CompileTest: Add Directives to Ignore `arm-unknown-*` Targets) - rust-lang#136403 (Fix malformed error annotations in a UI test) - rust-lang#136414 (Shorten error message for callable with wrong return type) - rust-lang#136425 (Move `rustc_middle::infer::unify_key`) - rust-lang#136426 (Explain why we retroactively change a static initializer to have a different type) - rust-lang#136445 (Couple of cleanups to DiagCtxt and EarlyDiagCtxt) - rust-lang#136452 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#136145 (Test validity of pattern types) - rust-lang#136339 (CompileTest: Add Directives to Ignore `arm-unknown-*` Targets) - rust-lang#136403 (Fix malformed error annotations in a UI test) - rust-lang#136414 (Shorten error message for callable with wrong return type) - rust-lang#136425 (Move `rustc_middle::infer::unify_key`) - rust-lang#136426 (Explain why we retroactively change a static initializer to have a different type) - rust-lang#136445 (Couple of cleanups to DiagCtxt and EarlyDiagCtxt) - rust-lang#136452 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#136145 - oli-obk:push-wxvpklmkppqz, r=RalfJung Test validity of pattern types r? `@RalfJung` pulled out of rust-lang#136006 so we don't have to rely on libcore types excercising this code path There's nothing to fix. `rustc_layout_scalar_valid_range_start` structs just failed their validation on their value instead of their fields' value, causing a diff where moving to pattern types adds an additional `.0` field access to the validation error
r? @RalfJung
pulled out of #136006 so we don't have to rely on libcore types excercising this code path
There's nothing to fix.
rustc_layout_scalar_valid_range_startstructs just failed their validation on their value instead of their fields' value, causing a diff where moving to pattern types adds an additional.0field access to the validation error