Skip to content

Allow parenthesis around inferred array lengths - #139641

Merged
bors merged 1 commit into
rust-lang:masterfrom
BoxyUwU:allow_parend_array_len_infer
Apr 11, 2025
Merged

Allow parenthesis around inferred array lengths#139641
bors merged 1 commit into
rust-lang:masterfrom
BoxyUwU:allow_parend_array_len_infer

Conversation

@BoxyUwU

Copy link
Copy Markdown
Member

In #135272 it was noticed that we weren't handling Vec<(((((_)))))> correctly under the new desugaring for generic_arg_infer, this had to be fixed in order to not regress stable code for types that should continue working. This has the side effect of also allowing the following to work:

#![feature(generic_arg_infer)]structBar<constN:usize>;fnmain(){let a:Bar<((_))> = Bar::<10>;}

However I did not make the same change for array lengths resulting in the following not compiling:

#![feature(generic_arg_infer)]fnmain(){let a:[u8;(((_)))] = [2;2];let a:[u8;2] = [2;(((((_)))))];}

This is rather inconsistent as parenthesis around _are supported for const args to non-arrays, and type args. This PR fixes this allowing the above example to compile. No stable impact.

r? compiler-errors

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 10, 2025
Comment on lines +16 to +17
#[rustfmt::skip]
let b: [u8; (_)] = [1; (((((_)))))];

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rustfmt wipes nested parenthesis in expressions so in order to make sure people dont accidentally format away part of the test..

Comment threadcompiler/rustc_ast_lowering/src/lib.rs
@BoxyUwU
BoxyUwUforce-pushed the allow_parend_array_len_infer branch 2 times, most recently from d9617ab to 95f90f3CompareApril 10, 2025 17:16

@compiler-errorscompiler-errors left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful!

@compiler-errors

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@bors

bors commented Apr 10, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 95f90f3 has been approved by compiler-errors

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 10, 2025
@rust-log-analyzer

This comment has been minimized.

@compiler-errors

compiler-errors commented Apr 10, 2025

Copy link
Copy Markdown
Contributor

@bors r-

pls bless 🙏

@borsbors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 10, 2025
@BoxyUwU

Copy link
Copy Markdown
MemberAuthor

whatd I fuck up here :thonk:

@BoxyUwU

Copy link
Copy Markdown
MemberAuthor

oh the rustfmt skip bumped line numbers

@BoxyUwU
BoxyUwUforce-pushed the allow_parend_array_len_infer branch from 95f90f3 to 8f00b1fCompareApril 10, 2025 17:59
@compiler-errors

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@bors

bors commented Apr 10, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 8f00b1f has been approved by compiler-errors

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 10, 2025
@ZalatharZalathar mentioned this pull request Apr 11, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 11, 2025
Rollup of 12 pull requests
Successful merges:
- rust-lang#137447 (add `core::intrinsics::simd::{simd_extract_dyn, simd_insert_dyn}`)
- rust-lang#138182 (rustc_target: update x86_win64 to match the documented calling convention for f128)
- rust-lang#138682 (Allow drivers to supply a list of extra symbols to intern)
- rust-lang#138904 (Test linking and running `no_std` binaries)
- rust-lang#138998 (Don't suggest the use of `impl Trait` in closure parameter)
- rust-lang#139447 (doc changes: debug assertions -> overflow checks)
- rust-lang#139469 (Introduce a `//@ needs-crate-type` compiletest directive)
- rust-lang#139564 (Deeply normalize obligations in `BestObligation` folder)
- rust-lang#139574 (bootstrap: improve `channel` handling)
- rust-lang#139600 (Update `compiler-builtins` to 0.1.153)
- rust-lang#139641 (Allow parenthesis around inferred array lengths)
- rust-lang#139654 (Improve `AssocItem::descr`.)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 25d282e into rust-lang:masterApr 11, 2025
@rustbotrustbot added this to the 1.88.0 milestone Apr 11, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 11, 2025
Rollup merge of rust-lang#139641 - BoxyUwU:allow_parend_array_len_infer, r=compiler-errors
Allow parenthesis around inferred array lengths
In rust-lang#135272 it was noticed that we weren't handling `Vec<(((((_)))))>` correctly under the new desugaring for `generic_arg_infer`, this had to be fixed in order to not regress stable code for types that should continue working. This has the side effect of *also* allowing the following to work:
```rust
#![feature(generic_arg_infer)]
struct Bar<const N: usize>;
fn main() {
let a: Bar<((_))> = Bar::<10>;
}
```
However I did not make the same change for array lengths resulting in the following not compiling:
```rust
#![feature(generic_arg_infer)]
fn main() {
let a: [u8; (((_)))] = [2; 2];
let a: [u8; 2] = [2; (((((_)))))];
}
```
This is rather inconsistent as parenthesis around `_` *are* supported for const args to non-arrays, and type args. This PR fixes this allowing the above example to compile. No stable impact.
r? compiler-errors
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@BoxyUwU@compiler-errors@bors@rust-log-analyzer@rustbot