-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Defer repeat expr Copy
checks to end of type checking
#137045
Conversation
@bors try |
…<try> Defer repeat expr `Copy` checks to end of type checking Fixes rust-lang#110443 r? `@ghost`
tests/ui/repeat-expr/infer-eager.rs
Outdated
|
||
fn main() { | ||
let x = [Foo(PhantomData); 2]; | ||
//~^ ERROR: type annotations needed |
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.
always deferring the check is a breaking change in cases where the Copy
impl has inference constraints that are then used in order to perform method lookup (or any other kind of hir typeck check that relies on matching on a type).
want to crater this to see how breaking it is but it would be very easy to just not break this and think that is my preference :3
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 think my preference now is actually to either always defer and eat the breaking change or do a less-hacky attempt to avoid the breaking change by introducing a new goal kind for repeat expr checks that can be deferred exactly as long as is necessary and no furthur
☀️ Try build successful - checks-actions |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
c09f183
to
8966d60
Compare
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🎉 Experiment
|
(all spurrious) |
75bb3ab
to
1ff88a7
Compare
// FIXME: Infer `?ct = {const error}`? | ||
ty::Const::new_error(self.tcx, e) |
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's no fcx.demand_subtype
for consts yet.
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.
You could just self.at(..).eq(ct, err)
?
// first as errors from not having inferred array lengths yet seem less confusing than errors from inference | ||
// fallback arbitrarily inferring something incompatible with `Copy` inference side effects. | ||
// | ||
// This should also be forwards compatible with moving repeat expr checks to a custom goal kind or using |
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 feel somewhat hesitant to add a custom goal kind for repeat expr checks but I do think it would be "optimal" behaviour-wise as the goals could stall on the repeat count infer var and be deferred ~as long as necessary while also not delaying inference constraints from them any later than is needed.
// FIXME: Infer `?ct = {const error}`? | ||
ty::Const::new_error(self.tcx, e) |
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.
You could just self.at(..).eq(ct, err)
?
lgtm, r=me with or without applying the nit; i think it may not be needed b/c all it's gonna do is slightly improve duplicated/unnecessary errors. |
1ff88a7
to
6c3243f
Compare
(rebased) @bors r=compiler-errors |
🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened. |
…r=compiler-errors Defer repeat expr `Copy` checks to end of type checking Fixes rust-lang#110443 Defers repeat expr checks that the element type is `Copy` when the length is > 1 (or generic) to end of typeck so that under `generic_arg_infer` repeat exprs are able to have an inferred count, e.g. `let a: [_; 1] = [String::new(); _];`. Currently the deferring is gated under `generic_arg_infer` though I intend to separately types FCP deferring the checks even outside of `generic_arg_infer` if we wind up not going with an alternative.
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#137045 (Defer repeat expr `Copy` checks to end of type checking) - rust-lang#137171 (Suggest swapping equality on E0277) - rust-lang#137634 (Update `compiler-builtins` to 0.1.149) - rust-lang#137686 (Handle asm const similar to inline const) - rust-lang#137689 (Use `Binder<Vec<Ty>>` instead of `Vec<Binder<Ty>>` in both solvers for sized/auto traits/etc.) - rust-lang#137718 (Use original command for showing sccache stats) - rust-lang#137723 (Make `rust.description` more general-purpose and pass `CFG_VER_DESCRIPTION`) - rust-lang#137730 (checked_ilog tests: deal with a bit of float imprecision) - rust-lang#137735 (Update E0133 docs for 2024 edition) - rust-lang#137742 (unconditionally lower match arm even if it's unneeded for never pattern in match) - rust-lang#137771 (Tweak incorrect ABI suggestion) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#137045 (Defer repeat expr `Copy` checks to end of type checking) - rust-lang#137171 (Suggest swapping equality on E0277) - rust-lang#137634 (Update `compiler-builtins` to 0.1.149) - rust-lang#137686 (Handle asm const similar to inline const) - rust-lang#137689 (Use `Binder<Vec<Ty>>` instead of `Vec<Binder<Ty>>` in both solvers for sized/auto traits/etc.) - rust-lang#137718 (Use original command for showing sccache stats) - rust-lang#137723 (Make `rust.description` more general-purpose and pass `CFG_VER_DESCRIPTION`) - rust-lang#137730 (checked_ilog tests: deal with a bit of float imprecision) - rust-lang#137735 (Update E0133 docs for 2024 edition) - rust-lang#137742 (unconditionally lower match arm even if it's unneeded for never pattern in match) - rust-lang#137771 (Tweak incorrect ABI suggestion) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#137045 (Defer repeat expr `Copy` checks to end of type checking) - rust-lang#137171 (Suggest swapping equality on E0277) - rust-lang#137634 (Update `compiler-builtins` to 0.1.149) - rust-lang#137686 (Handle asm const similar to inline const) - rust-lang#137689 (Use `Binder<Vec<Ty>>` instead of `Vec<Binder<Ty>>` in both solvers for sized/auto traits/etc.) - rust-lang#137718 (Use original command for showing sccache stats) - rust-lang#137723 (Make `rust.description` more general-purpose and pass `CFG_VER_DESCRIPTION`) - rust-lang#137730 (checked_ilog tests: deal with a bit of float imprecision) - rust-lang#137735 (Update E0133 docs for 2024 edition) - rust-lang#137742 (unconditionally lower match arm even if it's unneeded for never pattern in match) - rust-lang#137771 (Tweak incorrect ABI suggestion) r? `@ghost` `@rustbot` modify labels: rollup
…r=compiler-errors Defer repeat expr `Copy` checks to end of type checking Fixes rust-lang#110443 Defers repeat expr checks that the element type is `Copy` when the length is > 1 (or generic) to end of typeck so that under `generic_arg_infer` repeat exprs are able to have an inferred count, e.g. `let a: [_; 1] = [String::new(); _];`. Currently the deferring is gated under `generic_arg_infer` though I intend to separately types FCP deferring the checks even outside of `generic_arg_infer` if we wind up not going with an alternative.
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#137045 (Defer repeat expr `Copy` checks to end of type checking) - rust-lang#137171 (Suggest swapping equality on E0277) - rust-lang#137686 (Handle asm const similar to inline const) - rust-lang#137689 (Use `Binder<Vec<Ty>>` instead of `Vec<Binder<Ty>>` in both solvers for sized/auto traits/etc.) - rust-lang#137718 (Use original command for showing sccache stats) - rust-lang#137730 (checked_ilog tests: deal with a bit of float imprecision) - rust-lang#137735 (Update E0133 docs for 2024 edition) - rust-lang#137742 (unconditionally lower match arm even if it's unneeded for never pattern in match) - rust-lang#137771 (Tweak incorrect ABI suggestion and make suggestion verbose) Failed merges: - rust-lang#137723 (Make `rust.description` more general-purpose and pass `CFG_VER_DESCRIPTION`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#137045 - BoxyUwU:defer_repeat_expr_checks, r=compiler-errors Defer repeat expr `Copy` checks to end of type checking Fixes rust-lang#110443 Defers repeat expr checks that the element type is `Copy` when the length is > 1 (or generic) to end of typeck so that under `generic_arg_infer` repeat exprs are able to have an inferred count, e.g. `let a: [_; 1] = [String::new(); _];`. Currently the deferring is gated under `generic_arg_infer` though I intend to separately types FCP deferring the checks even outside of `generic_arg_infer` if we wind up not going with an alternative.
Fixes #110443
Defers repeat expr checks that the element type is
Copy
when the length is > 1 (or generic) to end of typeck so that undergeneric_arg_infer
repeat exprs are able to have an inferred count, e.g.let a: [_; 1] = [String::new(); _];
.Currently the deferring is gated under
generic_arg_infer
though I intend to separately types FCP deferring the checks even outside ofgeneric_arg_infer
if we wind up not going with an alternative.