Skip to content

feat: omit suffixes in const generics (e.g. 1_i32) #99393

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
}

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

fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/const-generics/add-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Simd<T, const WIDTH: usize> {
inner: T,
}

// @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>'
// @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>'
impl Add for Simd<u8, 16> {
type Output = Self;

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/const-generics/const-generic-defaults.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_name = "foo"]

// @has foo/struct.Foo.html '//pre[@class="rust struct"]' \
// 'pub struct Foo<const M: usize = 10_usize, const N: usize = M, T = i32>(_);'
// 'pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(_);'
pub struct Foo<const M: usize = 10, const N: usize = M, T = i32>(T);
4 changes: 2 additions & 2 deletions src/test/rustdoc/const-generics/const-generics-docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub use extern_crate::WTrait;

// @has foo/trait.Trait.html '//pre[@class="rust trait"]' \
// 'pub trait Trait<const N: usize>'
// @has - '//*[@id="impl-Trait%3C1_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1_usize> for u8'
// @has - '//*[@id="impl-Trait%3C2_usize%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2_usize> for u8'
// @has - '//*[@id="impl-Trait%3C1%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<1> for u8'
// @has - '//*[@id="impl-Trait%3C2%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<2> for u8'
// @has - '//*[@id="impl-Trait%3C{1%20+%202}%3E-for-u8"]//h3[@class="code-header in-band"]' 'impl Trait<{1 + 2}> for u8'
// @has - '//*[@id="impl-Trait%3CN%3E-for-%5Bu8%3B%20N%5D"]//h3[@class="code-header in-band"]' \
// 'impl<const N: usize> Trait<N> for [u8; N]'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ struct WithParameters<T, const N: usize, M = u32> {
}

impl<T> WithParameters<T, 1> {
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1_usize>` by reference
fn with_ref(&self) {} //~ ERROR passing `WithParameters<T, 1>` by reference
}

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

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ error: passing `Foo` by reference
LL | fn with_ref(&self) {}
| ^^^^^ help: try passing by value: `Foo`

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

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

error: aborting due to 5 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/array-slice-vec/match_arr_unknown_len.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/match_arr_unknown_len.rs:3:9
|
LL | [1, 2] => true,
| ^^^^^^ expected `2_usize`, found `N`
| ^^^^^^ expected `2`, found `N`
|
= note: expected array `[u32; 2]`
found array `[u32; N]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
LL | type Assoc = u16;
| ^^^ the trait `Bar<N>` is not implemented for `u16`
|
= help: the trait `Bar<3_usize>` is implemented for `u16`
= help: the trait `Bar<3>` is implemented for `u16`
note: required by a bound in `Foo::Assoc`
--> $DIR/associated-type-bound-fail.rs:4:17
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ error[E0308]: mismatched types
--> $DIR/generic-expr-default-concrete.rs:10:5
|
LL | Foo::<10, 12>
| ^^^^^^^^^^^^^ expected `11_usize`, found `12_usize`
| ^^^^^^^^^^^^^ expected `11`, found `12`
|
= note: expected type `11_usize`
found type `12_usize`
= note: expected type `11`
found type `12`

error: aborting due to previous error

Expand Down
22 changes: 11 additions & 11 deletions src/test/ui/const-generics/defaults/mismatch.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
pub struct Example<const N: usize=13>;
pub struct Example2<T=u32, const N: usize=13>(T);
pub struct Example3<const N: usize=13, T=u32>(T);
pub struct Example4<const N: usize=13, const M: usize=4>;
pub struct Example<const N: usize = 13>;
pub struct Example2<T = u32, const N: usize = 13>(T);
pub struct Example3<const N: usize = 13, T = u32>(T);
pub struct Example4<const N: usize = 13, const M: usize = 4>;

fn main() {
let e: Example::<13> = ();
let e: Example<13> = ();
//~^ Error: mismatched types
//~| expected struct `Example`
let e: Example2::<u32, 13> = ();
let e: Example2<u32, 13> = ();
//~^ Error: mismatched types
//~| expected struct `Example2`
let e: Example3::<13, u32> = ();
let e: Example3<13, u32> = ();
//~^ Error: mismatched types
//~| expected struct `Example3`
let e: Example3::<7> = ();
let e: Example3<7> = ();
//~^ Error: mismatched types
//~| expected struct `Example3<7_usize>`
let e: Example4::<7> = ();
//~| expected struct `Example3<7>`
let e: Example4<7> = ();
//~^ Error: mismatched types
//~| expected struct `Example4<7_usize>`
//~| expected struct `Example4<7>`
}
34 changes: 17 additions & 17 deletions src/test/ui/const-generics/defaults/mismatch.stderr
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
error[E0308]: mismatched types
--> $DIR/mismatch.rs:7:28
--> $DIR/mismatch.rs:7:26
|
LL | let e: Example::<13> = ();
| ------------- ^^ expected struct `Example`, found `()`
LL | let e: Example<13> = ();
| ----------- ^^ expected struct `Example`, found `()`
| |
| expected due to this
|
= note: expected struct `Example`
found unit type `()`

error[E0308]: mismatched types
--> $DIR/mismatch.rs:10:34
--> $DIR/mismatch.rs:10:32
|
LL | let e: Example2::<u32, 13> = ();
| ------------------- ^^ expected struct `Example2`, found `()`
LL | let e: Example2<u32, 13> = ();
| ----------------- ^^ expected struct `Example2`, found `()`
| |
| expected due to this
|
= note: expected struct `Example2`
found unit type `()`

error[E0308]: mismatched types
--> $DIR/mismatch.rs:13:34
--> $DIR/mismatch.rs:13:32
|
LL | let e: Example3::<13, u32> = ();
| ------------------- ^^ expected struct `Example3`, found `()`
LL | let e: Example3<13, u32> = ();
| ----------------- ^^ expected struct `Example3`, found `()`
| |
| expected due to this
|
= note: expected struct `Example3`
found unit type `()`

error[E0308]: mismatched types
--> $DIR/mismatch.rs:16:28
--> $DIR/mismatch.rs:16:26
|
LL | let e: Example3::<7> = ();
| ------------- ^^ expected struct `Example3`, found `()`
LL | let e: Example3<7> = ();
| ----------- ^^ expected struct `Example3`, found `()`
| |
| expected due to this
|
= note: expected struct `Example3<7_usize>`
= note: expected struct `Example3<7>`
found unit type `()`

error[E0308]: mismatched types
--> $DIR/mismatch.rs:19:28
--> $DIR/mismatch.rs:19:26
|
LL | let e: Example4::<7> = ();
| ------------- ^^ expected struct `Example4`, found `()`
LL | let e: Example4<7> = ();
| ----------- ^^ expected struct `Example4`, found `()`
| |
| expected due to this
|
= note: expected struct `Example4<7_usize>`
= note: expected struct `Example4<7>`
found unit type `()`

error: aborting due to 5 previous errors
Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/const-generics/defaults/rp_impl_trait_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ trait Trait {}
impl<const N: u32> Trait for Uwu<N> {}

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

trait Traitor<const N: u8 = 1, const M: u8 = N> { }
trait Traitor<const N: u8 = 1, const M: u8 = N> {}

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


fn uwu<const N: u8>() -> impl Traitor<N> {
//~^ error: the trait bound `u32: Traitor<N>` is not satisfied
1_u32
Expand Down
18 changes: 9 additions & 9 deletions src/test/ui/const-generics/defaults/rp_impl_trait_fail.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error[E0277]: the trait bound `Uwu<10_u32, 12_u32>: Trait` is not satisfied
error[E0277]: the trait bound `Uwu<10, 12>: Trait` is not satisfied
--> $DIR/rp_impl_trait_fail.rs:6:14
|
LL | fn rawr() -> impl Trait {
| ^^^^^^^^^^ the trait `Trait` is not implemented for `Uwu<10_u32, 12_u32>`
| ^^^^^^^^^^ the trait `Trait` is not implemented for `Uwu<10, 12>`
LL |
LL | Uwu::<10, 12>
| ------------- return type was inferred to be `Uwu<10_u32, 12_u32>` here
| ------------- return type was inferred to be `Uwu<10, 12>` here
|
= help: the trait `Trait` is implemented for `Uwu<N>`

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

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

error: aborting due to 3 previous errors

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/const-generics/defaults/trait_objects_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait Traitor<const N: u8 = 1, const M: u8 = N> {
}
}

impl Traitor<2, 3> for bool { }
impl Traitor<2, 3> for bool {}

fn bar<const N: u8>(arg: &dyn Traitor<N>) -> u8 {
arg.owo()
Expand All @@ -26,5 +26,5 @@ fn main() {
foo(&10_u32);
//~^ error: the trait bound `u32: Trait` is not satisfied
bar(&true);
//~^ error: the trait bound `bool: Traitor<{_: u8}>` is not satisfied
//~^ error: the trait bound `bool: Traitor<_>` is not satisfied
}
10 changes: 5 additions & 5 deletions src/test/ui/const-generics/defaults/trait_objects_fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ LL | foo(&10_u32);
| |
| required by a bound introduced by this call
|
= help: the trait `Trait<2_u8>` is implemented for `u32`
= help: the trait `Trait<2>` is implemented for `u32`
= note: required for the cast from `u32` to the object type `dyn Trait`

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

error: aborting due to 2 previous errors

Expand Down
12 changes: 8 additions & 4 deletions src/test/ui/const-generics/defaults/wfness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ struct Ooopsies<const N: u8 = { u8::MAX + 1 }>;

trait Trait<const N: u8> {}
impl Trait<3> for () {}
struct WhereClause<const N: u8 = 2> where (): Trait<N>;
//~^ error: the trait bound `(): Trait<2_u8>` is not satisfied
struct WhereClause<const N: u8 = 2>
where
(): Trait<N>;
//~^ error: the trait bound `(): Trait<2>` is not satisfied

trait Traitor<T, const N: u8> {}
struct WhereClauseTooGeneric<T = u32, const N: u8 = 2>(T) where (): Traitor<T, N>;
struct WhereClauseTooGeneric<T = u32, const N: u8 = 2>(T)
where
(): Traitor<T, N>;

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

Expand Down
27 changes: 15 additions & 12 deletions src/test/ui/const-generics/defaults/wfness.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ error[E0080]: evaluation of constant value failed
LL | struct Ooopsies<const N: u8 = { u8::MAX + 1 }>;
| ^^^^^^^^^^^ attempt to compute `u8::MAX + 1_u8`, which would overflow

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

error[E0277]: the trait bound `(): Trait<1_u8>` is not satisfied
--> $DIR/wfness.rs:14:13
error[E0277]: the trait bound `(): Trait<1>` is not satisfied
--> $DIR/wfness.rs:18:13
|
LL | fn foo() -> DependentDefaultWfness {
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<1_u8>` is not implemented for `()`
| ^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<1>` is not implemented for `()`
|
= help: the trait `Trait<3_u8>` is implemented for `()`
= help: the trait `Trait<3>` is implemented for `()`
note: required by a bound in `WhereClause`
--> $DIR/wfness.rs:6:47
--> $DIR/wfness.rs:8:9
|
LL | struct WhereClause<const N: u8 = 2> where (): Trait<N>;
| ^^^^^^^^ required by this bound in `WhereClause`
LL | struct WhereClause<const N: u8 = 2>
| ----------- required by a bound in this
LL | where
LL | (): Trait<N>;
| ^^^^^^^^ required by this bound in `WhereClause`

error: aborting due to 3 previous errors

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/const-generics/different_generic_args.full.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ error[E0308]: mismatched types
--> $DIR/different_generic_args.rs:11:9
|
LL | u = ConstUsize::<4> {};
| ^^^^^^^^^^^^^^^^^^ expected `3_usize`, found `4_usize`
| ^^^^^^^^^^^^^^^^^^ expected `3`, found `4`
|
= note: expected struct `ConstUsize<3_usize>`
found struct `ConstUsize<4_usize>`
= note: expected struct `ConstUsize<3>`
found struct `ConstUsize<4>`

error: aborting due to previous error

Expand Down
Loading