-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Finalize repeat expr inference behaviour with inferred repeat counts #139635
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
Open
BoxyUwU
wants to merge
6
commits into
rust-lang:master
Choose a base branch
from
BoxyUwU:no_order_dependent_copy_checks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+349
−148
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
feabf1b
Don't allow repeat expr count inference side effects to propagate
BoxyUwU daf5886
Properly test whether repeat expr checks are pre/post integer fallback
BoxyUwU 71373c5
GAI logic on stable too
BoxyUwU 5d0a80b
Check for element being `const` before resolving repeat count
BoxyUwU b27b151
Anon consts cant appear as repeat expr elements
BoxyUwU 186099c
Reviews
BoxyUwU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/ui/repeat-expr/copy-check-const-element-uninferred-count.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#![feature(generic_arg_infer)] | ||
|
||
// Test when deferring repeat expr copy checks to end of typechecking whether elements | ||
// that are const items allow for repeat counts to go uninferred without an error being | ||
// emitted if they would later wind up inferred by integer fallback. | ||
// | ||
// This test should be updated if we wind up deferring repeat expr checks until *after* | ||
// integer fallback as the point of the test is not *specifically* about integer fallback | ||
// but rather about the behaviour of `const` element exprs. | ||
|
||
trait Trait<const N: usize> {} | ||
|
||
// We impl `Trait` for both `i32` and `u32` to avoid being able | ||
// to prove `?int: Trait<?n>` from there only being one impl. | ||
impl Trait<2> for i32 {} | ||
impl Trait<2> for u32 {} | ||
|
||
fn tie_and_make_goal<const N: usize, T: Trait<N>>(_: &T, _: &[String; N]) {} | ||
|
||
fn const_block() { | ||
// Deferred repeat expr `String; ?n` | ||
let a = [const { String::new() }; _]; | ||
|
||
// `?int: Trait<?n>` goal | ||
tie_and_make_goal(&1, &a); | ||
|
||
// If repeat expr checks structurally resolve the `?n`s before checking if the | ||
// element is a `const` then we would error here. Otherwise we avoid doing so, | ||
// integer fallback occurs, allowing `?int: Trait<?n>` goals to make progress, | ||
// inferring the repeat counts (to `2` but that doesn't matter as the element is `const`). | ||
} | ||
|
||
fn const_item() { | ||
const MY_CONST: String = String::new(); | ||
|
||
// Deferred repeat expr `String; ?n` | ||
let a = [MY_CONST; _]; | ||
|
||
// `?int: Trait<?n>` goal | ||
tie_and_make_goal(&1, &a); | ||
|
||
// ... same as `const_block` | ||
} | ||
|
||
fn assoc_const() { | ||
trait Dummy { | ||
const ASSOC: String; | ||
} | ||
impl Dummy for () { | ||
const ASSOC: String = String::new(); | ||
} | ||
|
||
// Deferred repeat expr `String; ?n` | ||
let a = [<() as Dummy>::ASSOC; _]; | ||
|
||
// `?int: Trait<?n>` goal | ||
tie_and_make_goal(&1, &a); | ||
|
||
// ... same as `const_block` | ||
} | ||
|
||
fn const_block_but_uninferred() { | ||
// Deferred repeat expr `String; ?n` | ||
let a = [const { String::new() }; _]; | ||
//~^ ERROR: type annotations needed for `[String; _]` | ||
|
||
// Even if we don't structurally resolve the repeat count as part of repeat expr | ||
// checks, we still error on the repeat count being uninferred as we require all | ||
// types/consts to be inferred by the end of type checking. | ||
} | ||
|
||
fn main() {} |
15 changes: 15 additions & 0 deletions
15
tests/ui/repeat-expr/copy-check-const-element-uninferred-count.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0284]: type annotations needed for `[String; _]` | ||
--> $DIR/copy-check-const-element-uninferred-count.rs:64:9 | ||
| | ||
LL | let a = [const { String::new() }; _]; | ||
| ^ ---------------------------- type must be known at this point | ||
| | ||
= note: the length of array `[String; _]` must be type `usize` | ||
help: consider giving `a` an explicit type, where the placeholders `_` are specified | ||
| | ||
LL | let a: [_; _] = [const { String::new() }; _]; | ||
| ++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0284`. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 changed this to an explicit match instead of the
to_target_usize().is_none_or()
as theis_none_or
felt like somewhat subtle logic given the soundness sensitive nature of how we should be handling each variant 🤔