Ensure inferred let pattern types are well-formed#157013
Conversation
|
r? @mejrs rustbot has assigned @mejrs. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? @lcnr |
| decl.pat.span, | ||
| ObligationCauseCode::WellFormed(None), | ||
| ); | ||
| } |
There was a problem hiding this comment.
is there a reason we need to limit this to pat_has_ref_binding? 🤔 This feels somewhat brittle even if it fixes the existing known issues.
We could do it for all non-trivial pattern. Or personally, if perf doesn't care, just for all locals which don't have an explicitly provided type
There was a problem hiding this comment.
It was only for perf, and I was assuming that there was no way to create invalid types without ref bindings. However, I wasn't sure about patterns coming from unstable features, and I agree with removing the limit. I've removed the limit and applied the change to all patterns.
| @@ -0,0 +1,53 @@ | |||
| #![allow(unused)] | |||
|
|
|||
There was a problem hiding this comment.
please comment explaining this test and linking to the relevant github issue
There was a problem hiding this comment.
I've added the comment. Please let me know if you need a more detailed description for each test case, and I'd be happy to provide that.
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Ensure inferred let pattern types are well-formed
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (7f60c49): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (primary -0.6%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 18.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 511.209s -> 509.706s (-0.29%) |
18d5e2e to
d45c8b8
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
d45c8b8 to
d780821
Compare
|
@lcnr I've updated the PR to check all non-trivial patterns for |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Ensure inferred let pattern types are well-formed
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (6523e71): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary 2.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 2.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 517.542s -> 519.208s (0.32%) |
|
thanks a lot! @bors r+ rollup |
Ensure inferred let pattern types are well-formed Fixes rust-lang#150040 This registers a well-formedness obligation for inferred `let` pattern types when the pattern contains `ref` bindings. Previously, `let PAT;` without an explicit type annotation could infer a non-well-formed pattern input type, such as `[str; 2]` or `(str, str)`. Some bindings inside the pattern can still have well-formed local types, for example `ref x` gives `x: &str`, so checking only the binding locals missed the enclosing array or tuple type. As a result, invalid unsized array/tuple pattern types were accepted and could later lead to layout ICEs. The new check registers a WF obligation for the inferred declaration type after pattern checking.
…uwer Rollup of 14 pull requests Successful merges: - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty) - #157282 (Fix post-monomorphization error note race in the parallel frontend) - #157352 (Make the retained dep graph deterministic under the parallel frontend) - #157601 (Emit error for unused target expression in glob and list delegations) - #157626 (Autogenerate unstable compiler flag stubs for unstable-book) - #157647 (Start using comptime for reflection intrinsics and their wrapper functions) - #157013 (Ensure inferred let pattern types are well-formed) - #157288 (platform support: add SNaN erratum to MIPS targets) - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs) - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust …) - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N)) - #157691 (Move symbol hiding code to a new file) - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N)) - #157703 (Fix doc link to Instant sub in saturating caveat) Failed merges: - #157699 (Arg splat experiment - hir FnDecl impl)
View all comments
Fixes #150040
This registers a well-formedness obligation for inferred
letpattern types when the pattern containsrefbindings.Previously,
let PAT;without an explicit type annotation could infer a non-well-formed pattern input type, such as[str; 2]or(str, str). Some bindings inside the pattern can still have well-formed local types, for exampleref xgivesx: &str, so checking only the binding locals missed the enclosing array or tuple type. As a result, invalid unsized array/tuple pattern types were accepted and could later lead to layout ICEs.The new check registers a WF obligation for the inferred declaration type after pattern checking.