Skip to content

Commit 4ca5368

Browse files
committed
defer array len printing to const arg printing
1 parent e08b379 commit 4ca5368

31 files changed

+59
-66
lines changed

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

+4-20
Original file line numberDiff line numberDiff line change
@@ -854,24 +854,7 @@ pub trait PrettyPrinter<'tcx>:
854854
}
855855
p!("]");
856856
}
857-
ty::Array(ty, sz) => {
858-
p!("[", print(ty), "; ");
859-
if self.should_print_verbose() {
860-
p!(write("{:?}", sz));
861-
} else if let ty::ConstKind::Unevaluated(..) = sz.kind() {
862-
// Do not try to evaluate unevaluated constants. If we are const evaluating an
863-
// array length anon const, rustc will (with debug assertions) print the
864-
// constant's path. Which will end up here again.
865-
p!("_");
866-
} else if let Some(n) = sz.kind().try_to_bits(self.tcx().data_layout.pointer_size) {
867-
p!(write("{}", n));
868-
} else if let ty::ConstKind::Param(param) = sz.kind() {
869-
p!(print(param));
870-
} else {
871-
p!("_");
872-
}
873-
p!("]")
874-
}
857+
ty::Array(ty, sz) => p!("[", print(ty), "; ", print(sz), "]"),
875858
ty::Slice(ty) => p!("[", print(ty), "]"),
876859
}
877860

@@ -1303,10 +1286,10 @@ pub trait PrettyPrinter<'tcx>:
13031286
match ct.kind() {
13041287
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
13051288
match self.tcx().def_kind(def.did) {
1306-
DefKind::Static(..) | DefKind::Const | DefKind::AssocConst => {
1289+
DefKind::Const | DefKind::AssocConst => {
13071290
p!(print_value_path(def.did, substs))
13081291
}
1309-
_ => {
1292+
DefKind::AnonConst => {
13101293
if def.is_local() {
13111294
let span = self.tcx().def_span(def.did);
13121295
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) {
@@ -1318,6 +1301,7 @@ pub trait PrettyPrinter<'tcx>:
13181301
print_underscore!()
13191302
}
13201303
}
1304+
defkind => bug!("`{:?}` has unexpcted defkind {:?}", ct, defkind),
13211305
}
13221306
}
13231307
ty::ConstKind::Infer(infer_ct) => {

tests/ui/const-generics/const-param-type-depends-on-const-param.min.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
1010
LL | pub struct SelfDependent<const N: [u8; N]>;
1111
| ^ the type must not depend on the parameter `N`
1212

13-
error: `[u8; _]` is forbidden as the type of a const generic parameter
13+
error: `[u8; N]` is forbidden as the type of a const generic parameter
1414
--> $DIR/const-param-type-depends-on-const-param.rs:11:47
1515
|
1616
LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
@@ -19,7 +19,7 @@ LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
1919
= note: the only supported types are integers, `bool` and `char`
2020
= help: more complex types are supported with `#![feature(adt_const_params)]`
2121

22-
error: `[u8; _]` is forbidden as the type of a const generic parameter
22+
error: `[u8; N]` is forbidden as the type of a const generic parameter
2323
--> $DIR/const-param-type-depends-on-const-param.rs:15:35
2424
|
2525
LL | pub struct SelfDependent<const N: [u8; N]>;

tests/ui/const-generics/const-param-type-depends-on-const-param.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
1212
//~^ ERROR: the type of const parameters must not depend on other generic parameters
13-
//[min]~^^ ERROR `[u8; _]` is forbidden
13+
//[min]~^^ ERROR `[u8; N]` is forbidden
1414

1515
pub struct SelfDependent<const N: [u8; N]>;
1616
//~^ ERROR: the type of const parameters must not depend on other generic parameters
17-
//[min]~^^ ERROR `[u8; _]` is forbidden
17+
//[min]~^^ ERROR `[u8; N]` is forbidden
1818

1919
fn main() {}

tests/ui/const-generics/dont-evaluate-array-len-on-err-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0277]: the trait bound `[Adt; _]: Foo` is not satisfied
1+
error[E0277]: the trait bound `[Adt; std::mem::size_of::<Self::Assoc>()]: Foo` is not satisfied
22
--> $DIR/dont-evaluate-array-len-on-err-1.rs:15:9
33
|
44
LL | <[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar()
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; _]`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; std::mem::size_of::<Self::Assoc>()]`
66

77
error: aborting due to previous error
88

tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | ArrayHolder([0; Self::SIZE])
1515
| arguments to this struct are incorrect
1616
|
1717
= note: expected array `[u32; X]`
18-
found array `[u32; _]`
18+
found array `[u32; Self::SIZE]`
1919
note: tuple struct defined here
2020
--> $DIR/issue-62504.rs:14:8
2121
|

tests/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error[E0308]: mismatched types
22
--> $DIR/issue-79518-default_trait_method_normalization.rs:16:32
33
|
44
LL | Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()];
5-
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
5+
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); std::mem::size_of::<Self::Assoc>()]`
66
| |
77
| expected because this is `<Self as Foo>::Assoc`
88
|
99
= note: expected associated type `<Self as Foo>::Assoc`
10-
found array `[(); _]`
11-
= help: consider constraining the associated type `<Self as Foo>::Assoc` to `[(); _]` or calling a method that returns `<Self as Foo>::Assoc`
10+
found array `[(); std::mem::size_of::<Self::Assoc>()]`
11+
= help: consider constraining the associated type `<Self as Foo>::Assoc` to `[(); std::mem::size_of::<Self::Assoc>()]` or calling a method that returns `<Self as Foo>::Assoc`
1212
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
1313

1414
error: aborting due to previous error

tests/ui/const-generics/issues/issue-62878.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
44
LL | fn foo<const N: usize, const A: [u8; N]>() {}
55
| ^ the type must not depend on the parameter `N`
66

7-
error: `[u8; _]` is forbidden as the type of a const generic parameter
7+
error: `[u8; N]` is forbidden as the type of a const generic parameter
88
--> $DIR/issue-62878.rs:5:33
99
|
1010
LL | fn foo<const N: usize, const A: [u8; N]>() {}

tests/ui/const-generics/issues/issue-62878.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
fn foo<const N: usize, const A: [u8; N]>() {}
66
//~^ ERROR the type of const parameters must not
7-
//[min]~| ERROR `[u8; _]` is forbidden as the type of a const generic parameter
7+
//[min]~| ERROR `[u8; N]` is forbidden as the type of a const generic parameter
88

99
fn main() {
1010
foo::<_, { [1] }>();

tests/ui/const-generics/issues/issue-71169.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
44
LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
55
| ^^^ the type must not depend on the parameter `LEN`
66

7-
error: `[u8; _]` is forbidden as the type of a const generic parameter
7+
error: `[u8; LEN]` is forbidden as the type of a const generic parameter
88
--> $DIR/issue-71169.rs:5:38
99
|
1010
LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}

tests/ui/const-generics/issues/issue-71169.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
66
//~^ ERROR the type of const parameters must not
7-
//[min]~^^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
7+
//[min]~^^ ERROR `[u8; LEN]` is forbidden as the type of a const generic parameter
88
fn main() {
99
const DATA: [u8; 4] = *b"ABCD";
1010
foo::<4, DATA>();

tests/ui/const-generics/issues/issue-73491.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `[u32; _]` is forbidden as the type of a const generic parameter
1+
error: `[u32; LEN]` is forbidden as the type of a const generic parameter
22
--> $DIR/issue-73491.rs:8:19
33
|
44
LL | fn hoge<const IN: [u32; LEN]>() {}

tests/ui/const-generics/issues/issue-73491.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
const LEN: usize = 1024;
77

88
fn hoge<const IN: [u32; LEN]>() {}
9-
//[min]~^ ERROR `[u32; _]` is forbidden as the type of a const generic parameter
9+
//[min]~^ ERROR `[u32; LEN]` is forbidden as the type of a const generic parameter
1010

1111
fn main() {}

tests/ui/const-generics/issues/issue-74101.min.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `[u8; _]` is forbidden as the type of a const generic parameter
1+
error: `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
22
--> $DIR/issue-74101.rs:6:18
33
|
44
LL | fn test<const N: [u8; 1 + 2]>() {}
@@ -7,7 +7,7 @@ LL | fn test<const N: [u8; 1 + 2]>() {}
77
= note: the only supported types are integers, `bool` and `char`
88
= help: more complex types are supported with `#![feature(adt_const_params)]`
99

10-
error: `[u8; _]` is forbidden as the type of a const generic parameter
10+
error: `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
1111
--> $DIR/issue-74101.rs:9:21
1212
|
1313
LL | struct Foo<const N: [u8; 1 + 2]>;

tests/ui/const-generics/issues/issue-74101.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#![cfg_attr(full, allow(incomplete_features))]
55

66
fn test<const N: [u8; 1 + 2]>() {}
7-
//[min]~^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
7+
//[min]~^ ERROR `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
88

99
struct Foo<const N: [u8; 1 + 2]>;
10-
//[min]~^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
10+
//[min]~^ ERROR `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
1111

1212
fn main() {}

tests/ui/const-generics/issues/issue-75047.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `[u8; _]` is forbidden as the type of a const generic parameter
1+
error: `[u8; Bar::<u32>::value()]` is forbidden as the type of a const generic parameter
22
--> $DIR/issue-75047.rs:14:21
33
|
44
LL | struct Foo<const N: [u8; Bar::<u32>::value()]>;

tests/ui/const-generics/issues/issue-75047.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ impl<T> Bar<T> {
1212
}
1313

1414
struct Foo<const N: [u8; Bar::<u32>::value()]>;
15-
//[min]~^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
15+
//[min]~^ ERROR `[u8; Bar::<u32>::value()]` is forbidden as the type of a const generic parameter
1616

1717
fn main() {}

tests/ui/const-generics/nested-type.min.stderr

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
error: `[u8; _]` is forbidden as the type of a const generic parameter
1+
error: `[u8; {
2+
struct Foo<const N: usize>;
3+
4+
impl<const N: usize> Foo<N> {
5+
fn value() -> usize {
6+
N
7+
}
8+
}
9+
10+
Foo::<17>::value()
11+
}]` is forbidden as the type of a const generic parameter
212
--> $DIR/nested-type.rs:6:21
313
|
414
LL | struct Foo<const N: [u8; {

tests/ui/consts/const-size_of-cycle.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
1515
LL | bytes: [u8; std::mem::size_of::<Foo>()]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= note: ...which requires computing layout of `Foo`...
18-
= note: ...which requires computing layout of `[u8; _]`...
19-
= note: ...which requires normalizing `[u8; _]`...
18+
= note: ...which requires computing layout of `[u8; std::mem::size_of::<Foo>()]`...
19+
= note: ...which requires normalizing `[u8; std::mem::size_of::<Foo>()]`...
2020
= note: ...which again requires evaluating type-level constant, completing the cycle
2121
note: cycle used when checking that `Foo` is well-formed
2222
--> $DIR/const-size_of-cycle.rs:3:1

tests/ui/consts/issue-44415.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
1515
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= note: ...which requires computing layout of `Foo`...
18-
= note: ...which requires computing layout of `[u8; _]`...
19-
= note: ...which requires normalizing `[u8; _]`...
18+
= note: ...which requires computing layout of `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
19+
= note: ...which requires normalizing `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
2020
= note: ...which again requires evaluating type-level constant, completing the cycle
2121
note: cycle used when checking that `Foo` is well-formed
2222
--> $DIR/issue-44415.rs:5:1

tests/ui/consts/too_generic_eval_ice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ impl<A, B> Foo<A, B> {
77
[5; Self::HOST_SIZE] == [6; 0]
88
//~^ ERROR constant expression depends on a generic parameter
99
//~| ERROR constant expression depends on a generic parameter
10-
//~| ERROR can't compare `[{integer}; _]` with `[{integer}; 0]`
10+
//~| ERROR can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
1111
}
1212
}
1313

tests/ui/consts/too_generic_eval_ice.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ LL | [5; Self::HOST_SIZE] == [6; 0]
1414
|
1515
= note: this may fail depending on what value the parameter takes
1616

17-
error[E0277]: can't compare `[{integer}; _]` with `[{integer}; 0]`
17+
error[E0277]: can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
1818
--> $DIR/too_generic_eval_ice.rs:7:30
1919
|
2020
LL | [5; Self::HOST_SIZE] == [6; 0]
21-
| ^^ no implementation for `[{integer}; _] == [{integer}; 0]`
21+
| ^^ no implementation for `[{integer}; Self::HOST_SIZE] == [{integer}; 0]`
2222
|
23-
= help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; _]`
23+
= help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
2424
= help: the following other types implement trait `PartialEq<Rhs>`:
2525
<&[B] as PartialEq<[A; N]>>
2626
<&[T] as PartialEq<Vec<U, A>>>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: values of the type `[u8; SIZE]` are too big for the current architecture
1+
error: values of the type `[u8; usize::MAX]` are too big for the current architecture
22

33
error: aborting due to previous error
44

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: values of the type `[u8; SIZE]` are too big for the current architecture
1+
error: values of the type `[u8; usize::MAX]` are too big for the current architecture
22

33
error: aborting due to previous error
44

tests/ui/inference/issue-83606.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ fn foo<const N: usize>(_: impl std::fmt::Display) -> [usize; N] {
66

77
fn main() {
88
let _ = foo("foo");
9-
//~^ ERROR: type annotations needed for `[usize; _]`
9+
//~^ ERROR: type annotations needed for `[usize; N]`
1010
}

tests/ui/inference/issue-83606.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0282]: type annotations needed for `[usize; _]`
1+
error[E0282]: type annotations needed for `[usize; N]`
22
--> $DIR/issue-83606.rs:8:9
33
|
44
LL | let _ = foo("foo");
55
| ^
66
|
77
help: consider giving this pattern a type, where the the value of const parameter `N` is specified
88
|
9-
LL | let _: [usize; _] = foo("foo");
9+
LL | let _: [usize; N] = foo("foo");
1010
| ++++++++++++
1111

1212
error: aborting due to previous error

tests/ui/limits/issue-15919-64.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: values of the type `[usize; 18446744073709551615]` are too big for the current architecture
1+
error: values of the type `[usize; usize::MAX]` are too big for the current architecture
22
--> $DIR/issue-15919-64.rs:9:9
33
|
44
LL | let x = [0usize; 0xffff_ffff_ffff_ffff];

tests/ui/limits/issue-55878.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error[E0080]: values of the type `[u8; SIZE]` are too big for the current architecture
1+
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the current architecture
22
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
33
|
4-
note: inside `std::mem::size_of::<[u8; SIZE]>`
4+
note: inside `std::mem::size_of::<[u8; usize::MAX]>`
55
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
66
note: inside `main`
77
--> $DIR/issue-55878.rs:7:26

tests/ui/limits/issue-69485-var-size-diffs-too-large.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: values of the type `[u8; 18446744073709551615]` are too big for the current architecture
1+
error: values of the type `[u8; usize::MAX]` are too big for the current architecture
22
--> $DIR/issue-69485-var-size-diffs-too-large.rs:6:5
33
|
44
LL | Bug::V([0; !0]);

tests/ui/limits/issue-75158-64.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: values of the type `[u8; 18446744073709551615]` are too big for the current architecture
1+
error: values of the type `[u8; usize::MAX]` are too big for the current architecture
22

33
error: aborting due to previous error
44

tests/ui/symbol-names/impl2.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ trait Foo {
88
}
99

1010
impl Foo for [u8; 1 + 2] {
11-
#[rustc_def_path] //~ ERROR def-path(<[u8; _] as Foo>::baz)
12-
fn baz() { }
11+
#[rustc_def_path] //~ ERROR def-path(<[u8; 1 + 2] as Foo>::baz)
12+
fn baz() {}
1313
}
1414

15-
fn main() {
16-
}
15+
fn main() {}

tests/ui/symbol-names/impl2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: def-path(<[u8; _] as Foo>::baz)
1+
error: def-path(<[u8; 1 + 2] as Foo>::baz)
22
--> $DIR/impl2.rs:11:5
33
|
44
LL | #[rustc_def_path]

0 commit comments

Comments
 (0)