Skip to content

Commit 5a267b1

Browse files
authored
Rollup merge of rust-lang#99393 - Logarithmus:feature/99255-omit-const-generic-suffixes, r=petrochenkov
feat: omit suffixes in const generics (e.g. `1_i32`) Closes rust-lang#99255
2 parents 6d33301 + 8530407 commit 5a267b1

File tree

48 files changed

+189
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+189
-180
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
17271727
}
17281728

17291729
fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
1730-
self.pretty_print_const(ct, true)
1730+
self.pretty_print_const(ct, false)
17311731
}
17321732

17331733
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {

src/test/rustdoc/const-generics/add-impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct Simd<T, const WIDTH: usize> {
77
inner: T,
88
}
99

10-
// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl Add<Simd<u8, 16_usize>> for Simd<u8, 16>'
10+
// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3[@class="code-header in-band"]' 'impl Add<Simd<u8, 16>> for Simd<u8, 16>'
1111
impl Add for Simd<u8, 16> {
1212
type Output = Self;
1313

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_name = "foo"]
22

33
// @has foo/struct.Foo.html '//pre[@class="rust struct"]' \
4-
// 'pub struct Foo<const M: usize = 10_usize, const N: usize = M, T = i32>(_);'
4+
// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(_);'
55
pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(T);

src/test/rustdoc/const-generics/const-generics-docs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ pub use extern_crate::WTrait;
1919

2020
// @has foo/trait.Trait.html '//pre[@class="rust trait"]' \
2121
// 'pub trait Trait<const N: usize>'
22-
// @has - '//*[@id="impl-Trait%3C1_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1_usize> for u8'
23-
// @has - '//*[@id="impl-Trait%3C2_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2_usize> for u8'
22+
// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1> for u8'
23+
// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2> for u8'
2424
// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<{1 + 2}> for u8'
2525
// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header in-band"]' \
2626
// 'impl<const N: usize> Trait<N> for [u8; N]'

src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ struct WithParameters<T, const N: usize, M = u32> {
4444
}
4545

4646
impl<T> WithParameters<T, 1> {
47-
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1_usize>` by reference
47+
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1>` by reference
4848
}
4949

5050
impl<T> WithParameters<T, 1, u8> {
51-
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1_usize, u8>` by reference
51+
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1, u8>` by reference
5252
}
5353

5454
fn main() {}

src/test/ui-fulldeps/internal-lints/rustc_pass_by_value_self.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ error: passing `Foo` by reference
2222
LL | fn with_ref(&self) {}
2323
| ^^^^^ help: try passing by value: `Foo`
2424

25-
error: passing `WithParameters<T, 1_usize>` by reference
25+
error: passing `WithParameters<T, 1>` by reference
2626
--> $DIR/rustc_pass_by_value_self.rs:47:17
2727
|
2828
LL | fn with_ref(&self) {}
29-
| ^^^^^ help: try passing by value: `WithParameters<T, 1_usize>`
29+
| ^^^^^ help: try passing by value: `WithParameters<T, 1>`
3030

31-
error: passing `WithParameters<T, 1_usize, u8>` by reference
31+
error: passing `WithParameters<T, 1, u8>` by reference
3232
--> $DIR/rustc_pass_by_value_self.rs:51:17
3333
|
3434
LL | fn with_ref(&self) {}
35-
| ^^^^^ help: try passing by value: `WithParameters<T, 1_usize, u8>`
35+
| ^^^^^ help: try passing by value: `WithParameters<T, 1, u8>`
3636

3737
error: aborting due to 5 previous errors
3838

src/test/ui/array-slice-vec/match_arr_unknown_len.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/match_arr_unknown_len.rs:3:9
33
|
44
LL | [1, 2] => true,
5-
| ^^^^^^ expected `2_usize`, found `N`
5+
| ^^^^^^ expected `2`, found `N`
66
|
77
= note: expected array `[u32; 2]`
88
found array `[u32; N]`

src/test/ui/const-generics/associated-type-bound-fail.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
44
LL | type Assoc = u16;
55
| ^^^ the trait `Bar<N>` is not implemented for `u16`
66
|
7-
= help: the trait `Bar<3_usize>` is implemented for `u16`
7+
= help: the trait `Bar<3>` is implemented for `u16`
88
note: required by a bound in `Foo::Assoc`
99
--> $DIR/associated-type-bound-fail.rs:4:17
1010
|

src/test/ui/const-generics/defaults/generic-expr-default-concrete.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ error[E0308]: mismatched types
22
--> $DIR/generic-expr-default-concrete.rs:10:5
33
|
44
LL | Foo::<10, 12>
5-
| ^^^^^^^^^^^^^ expected `11_usize`, found `12_usize`
5+
| ^^^^^^^^^^^^^ expected `11`, found `12`
66
|
7-
= note: expected type `11_usize`
8-
found type `12_usize`
7+
= note: expected type `11`
8+
found type `12`
99

1010
error: aborting due to previous error
1111

Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
pub struct Example<const N: usize=13>;
2-
pub struct Example2<T=u32, const N: usize=13>(T);
3-
pub struct Example3<const N: usize=13, T=u32>(T);
4-
pub struct Example4<const N: usize=13, const M: usize=4>;
1+
pub struct Example<const N: usize = 13>;
2+
pub struct Example2<T = u32, const N: usize = 13>(T);
3+
pub struct Example3<const N: usize = 13, T = u32>(T);
4+
pub struct Example4<const N: usize = 13, const M: usize = 4>;
55

66
fn main() {
7-
let e: Example::<13> = ();
7+
let e: Example<13> = ();
88
//~^ Error: mismatched types
99
//~| expected struct `Example`
10-
let e: Example2::<u32, 13> = ();
10+
let e: Example2<u32, 13> = ();
1111
//~^ Error: mismatched types
1212
//~| expected struct `Example2`
13-
let e: Example3::<13, u32> = ();
13+
let e: Example3<13, u32> = ();
1414
//~^ Error: mismatched types
1515
//~| expected struct `Example3`
16-
let e: Example3::<7> = ();
16+
let e: Example3<7> = ();
1717
//~^ Error: mismatched types
18-
//~| expected struct `Example3<7_usize>`
19-
let e: Example4::<7> = ();
18+
//~| expected struct `Example3<7>`
19+
let e: Example4<7> = ();
2020
//~^ Error: mismatched types
21-
//~| expected struct `Example4<7_usize>`
21+
//~| expected struct `Example4<7>`
2222
}

src/test/ui/const-generics/defaults/mismatch.stderr

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
error[E0308]: mismatched types
2-
--> $DIR/mismatch.rs:7:28
2+
--> $DIR/mismatch.rs:7:26
33
|
4-
LL | let e: Example::<13> = ();
5-
| ------------- ^^ expected struct `Example`, found `()`
4+
LL | let e: Example<13> = ();
5+
| ----------- ^^ expected struct `Example`, found `()`
66
| |
77
| expected due to this
88
|
99
= note: expected struct `Example`
1010
found unit type `()`
1111

1212
error[E0308]: mismatched types
13-
--> $DIR/mismatch.rs:10:34
13+
--> $DIR/mismatch.rs:10:32
1414
|
15-
LL | let e: Example2::<u32, 13> = ();
16-
| ------------------- ^^ expected struct `Example2`, found `()`
15+
LL | let e: Example2<u32, 13> = ();
16+
| ----------------- ^^ expected struct `Example2`, found `()`
1717
| |
1818
| expected due to this
1919
|
2020
= note: expected struct `Example2`
2121
found unit type `()`
2222

2323
error[E0308]: mismatched types
24-
--> $DIR/mismatch.rs:13:34
24+
--> $DIR/mismatch.rs:13:32
2525
|
26-
LL | let e: Example3::<13, u32> = ();
27-
| ------------------- ^^ expected struct `Example3`, found `()`
26+
LL | let e: Example3<13, u32> = ();
27+
| ----------------- ^^ expected struct `Example3`, found `()`
2828
| |
2929
| expected due to this
3030
|
3131
= note: expected struct `Example3`
3232
found unit type `()`
3333

3434
error[E0308]: mismatched types
35-
--> $DIR/mismatch.rs:16:28
35+
--> $DIR/mismatch.rs:16:26
3636
|
37-
LL | let e: Example3::<7> = ();
38-
| ------------- ^^ expected struct `Example3`, found `()`
37+
LL | let e: Example3<7> = ();
38+
| ----------- ^^ expected struct `Example3`, found `()`
3939
| |
4040
| expected due to this
4141
|
42-
= note: expected struct `Example3<7_usize>`
42+
= note: expected struct `Example3<7>`
4343
found unit type `()`
4444

4545
error[E0308]: mismatched types
46-
--> $DIR/mismatch.rs:19:28
46+
--> $DIR/mismatch.rs:19:26
4747
|
48-
LL | let e: Example4::<7> = ();
49-
| ------------- ^^ expected struct `Example4`, found `()`
48+
LL | let e: Example4<7> = ();
49+
| ----------- ^^ expected struct `Example4`, found `()`
5050
| |
5151
| expected due to this
5252
|
53-
= note: expected struct `Example4<7_usize>`
53+
= note: expected struct `Example4<7>`
5454
found unit type `()`
5555

5656
error: aborting due to 5 previous errors

src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ trait Trait {}
44
impl<const N: u32> Trait for Uwu<N> {}
55

66
fn rawr() -> impl Trait {
7-
//~^ error: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
7+
//~^ error: the trait bound `Uwu<10, 12>: Trait` is not satisfied
88
Uwu::<10, 12>
99
}
1010

11-
trait Traitor<const N: u8 = 1, const M: u8 = N> { }
11+
trait Traitor<const N: u8 = 1, const M: u8 = N> {}
1212

1313
impl<const N: u8> Traitor<N, 2> for u32 {}
1414
impl Traitor<1, 2> for u64 {}
1515

16-
1716
fn uwu<const N: u8>() -> impl Traitor<N> {
1817
//~^ error: the trait bound `u32: Traitor<N>` is not satisfied
1918
1_u32

src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error[E0277]: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
1+
error[E0277]: the trait bound `Uwu<10, 12>: Trait` is not satisfied
22
--> $DIR/rp_impl_trait_fail.rs:6:14
33
|
44
LL | fn rawr() -> impl Trait {
5-
| ^^^^^^^^^^ the trait `Trait` is not implemented for `Uwu<10_u32, 12_u32>`
5+
| ^^^^^^^^^^ the trait `Trait` is not implemented for `Uwu<10, 12>`
66
LL |
77
LL | Uwu::<10, 12>
8-
| ------------- return type was inferred to be `Uwu<10_u32, 12_u32>` here
8+
| ------------- return type was inferred to be `Uwu<10, 12>` here
99
|
1010
= help: the trait `Trait` is implemented for `Uwu<N>`
1111

1212
error[E0277]: the trait bound `u32: Traitor<N>` is not satisfied
13-
--> $DIR/rp_impl_trait_fail.rs:17:26
13+
--> $DIR/rp_impl_trait_fail.rs:16:26
1414
|
1515
LL | fn uwu<const N: u8>() -> impl Traitor<N> {
1616
| ^^^^^^^^^^^^^^^ the trait `Traitor<N>` is not implemented for `u32`
@@ -19,11 +19,11 @@ LL | 1_u32
1919
| ----- return type was inferred to be `u32` here
2020
|
2121
= help: the following other types implement trait `Traitor<N, M>`:
22-
<u32 as Traitor<N, 2_u8>>
23-
<u64 as Traitor<1_u8, 2_u8>>
22+
<u32 as Traitor<N, 2>>
23+
<u64 as Traitor<1, 2>>
2424

2525
error[E0277]: the trait bound `u64: Traitor` is not satisfied
26-
--> $DIR/rp_impl_trait_fail.rs:22:13
26+
--> $DIR/rp_impl_trait_fail.rs:21:13
2727
|
2828
LL | fn owo() -> impl Traitor {
2929
| ^^^^^^^^^^^^ the trait `Traitor` is not implemented for `u64`
@@ -32,8 +32,8 @@ LL | 1_u64
3232
| ----- return type was inferred to be `u64` here
3333
|
3434
= help: the following other types implement trait `Traitor<N, M>`:
35-
<u32 as Traitor<N, 2_u8>>
36-
<u64 as Traitor<1_u8, 2_u8>>
35+
<u32 as Traitor<N, 2>>
36+
<u64 as Traitor<1, 2>>
3737

3838
error: aborting due to 3 previous errors
3939

src/test/ui/const-generics/defaults/trait_objects_fail.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait Traitor<const N: u8 = 1, const M: u8 = N> {
1616
}
1717
}
1818

19-
impl Traitor<2, 3> for bool { }
19+
impl Traitor<2, 3> for bool {}
2020

2121
fn bar<const N: u8>(arg: &dyn Traitor<N>) -> u8 {
2222
arg.owo()
@@ -26,5 +26,5 @@ fn main() {
2626
foo(&10_u32);
2727
//~^ error: the trait bound `u32: Trait` is not satisfied
2828
bar(&true);
29-
//~^ error: the trait bound `bool: Traitor<{_: u8}>` is not satisfied
29+
//~^ error: the trait bound `bool: Traitor<_>` is not satisfied
3030
}

src/test/ui/const-generics/defaults/trait_objects_fail.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ LL | foo(&10_u32);
66
| |
77
| required by a bound introduced by this call
88
|
9-
= help: the trait `Trait<2_u8>` is implemented for `u32`
9+
= help: the trait `Trait<2>` is implemented for `u32`
1010
= note: required for the cast from `u32` to the object type `dyn Trait`
1111

12-
error[E0277]: the trait bound `bool: Traitor<{_: u8}>` is not satisfied
12+
error[E0277]: the trait bound `bool: Traitor<_>` is not satisfied
1313
--> $DIR/trait_objects_fail.rs:28:9
1414
|
1515
LL | bar(&true);
16-
| --- ^^^^^ the trait `Traitor<{_: u8}>` is not implemented for `bool`
16+
| --- ^^^^^ the trait `Traitor<_>` is not implemented for `bool`
1717
| |
1818
| required by a bound introduced by this call
1919
|
20-
= help: the trait `Traitor<2_u8, 3_u8>` is implemented for `bool`
21-
= note: required for the cast from `bool` to the object type `dyn Traitor<{_: u8}>`
20+
= help: the trait `Traitor<2, 3>` is implemented for `bool`
21+
= note: required for the cast from `bool` to the object type `dyn Traitor<_>`
2222

2323
error: aborting due to 2 previous errors
2424

src/test/ui/const-generics/defaults/wfness.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ struct Ooopsies<const N: u8 = { u8::MAX + 1 }>;
33

44
trait Trait<const N: u8> {}
55
impl Trait<3> for () {}
6-
struct WhereClause<const N: u8 = 2> where (): Trait<N>;
7-
//~^ error: the trait bound `(): Trait<2_u8>` is not satisfied
6+
struct WhereClause<const N: u8 = 2>
7+
where
8+
(): Trait<N>;
9+
//~^ error: the trait bound `(): Trait<2>` is not satisfied
810

911
trait Traitor<T, const N: u8> {}
10-
struct WhereClauseTooGeneric<T = u32, const N: u8 = 2>(T) where (): Traitor<T, N>;
12+
struct WhereClauseTooGeneric<T = u32, const N: u8 = 2>(T)
13+
where
14+
(): Traitor<T, N>;
1115

1216
// no error on struct def
1317
struct DependentDefaultWfness<const N: u8 = 1, T = WhereClause<N>>(T);
1418
fn foo() -> DependentDefaultWfness {
15-
//~^ error: the trait bound `(): Trait<1_u8>` is not satisfied
19+
//~^ error: the trait bound `(): Trait<1>` is not satisfied
1620
loop {}
1721
}
1822

src/test/ui/const-generics/defaults/wfness.stderr

+15-12
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@ error[E0080]: evaluation of constant value failed
44
LL | struct Ooopsies<const N: u8 = { u8::MAX + 1 }>;
55
| ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow
66

7-
error[E0277]: the trait bound `(): Trait<2_u8>` is not satisfied
8-
--> $DIR/wfness.rs:6:47
7+
error[E0277]: the trait bound `(): Trait<2>` is not satisfied
8+
--> $DIR/wfness.rs:8:9
99
|
10-
LL | struct WhereClause<const N: u8 = 2> where (): Trait<N>;
11-
| ^^^^^^^^ the trait `Trait<2_u8>` is not implemented for `()`
10+
LL | (): Trait<N>;
11+
| ^^^^^^^^ the trait `Trait<2>` is not implemented for `()`
1212
|
13-
= help: the trait `Trait<3_u8>` is implemented for `()`
13+
= help: the trait `Trait<3>` is implemented for `()`
1414

15-
error[E0277]: the trait bound `(): Trait<1_u8>` is not satisfied
16-
--> $DIR/wfness.rs:14:13
15+
error[E0277]: the trait bound `(): Trait<1>` is not satisfied
16+
--> $DIR/wfness.rs:18:13
1717
|
1818
LL | fn foo() -> DependentDefaultWfness {
19-
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<1_u8>` is not implemented for `()`
19+
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<1>` is not implemented for `()`
2020
|
21-
= help: the trait `Trait<3_u8>` is implemented for `()`
21+
= help: the trait `Trait<3>` is implemented for `()`
2222
note: required by a bound in `WhereClause`
23-
--> $DIR/wfness.rs:6:47
23+
--> $DIR/wfness.rs:8:9
2424
|
25-
LL | struct WhereClause<const N: u8 = 2> where (): Trait<N>;
26-
| ^^^^^^^^ required by this bound in `WhereClause`
25+
LL | struct WhereClause<const N: u8 = 2>
26+
| ----------- required by a bound in this
27+
LL | where
28+
LL | (): Trait<N>;
29+
| ^^^^^^^^ required by this bound in `WhereClause`
2730

2831
error: aborting due to 3 previous errors
2932

src/test/ui/const-generics/different_generic_args.full.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ error[E0308]: mismatched types
22
--> $DIR/different_generic_args.rs:11:9
33
|
44
LL | u = ConstUsize::<4> {};
5-
| ^^^^^^^^^^^^^^^^^^ expected `3_usize`, found `4_usize`
5+
| ^^^^^^^^^^^^^^^^^^ expected `3`, found `4`
66
|
7-
= note: expected struct `ConstUsize<3_usize>`
8-
found struct `ConstUsize<4_usize>`
7+
= note: expected struct `ConstUsize<3>`
8+
found struct `ConstUsize<4>`
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)