Skip to content

Commit c39826e

Browse files
committed
feat: omit suffixes in const generics (e.g. 1_i32)
Closes #99255
1 parent f858854 commit c39826e

Some content is hidden

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

43 files changed

+179
-170
lines changed

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

Lines changed: 1 addition & 1 deletion
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/ui/array-slice-vec/match_arr_unknown_len.stderr

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 11 additions & 11 deletions
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

Lines changed: 17 additions & 17 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

0 commit comments

Comments
 (0)