mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
defer array len printing to const arg printing
This commit is contained in:
parent
e08b379d5d
commit
4ca5368a12
@ -854,24 +854,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
}
|
||||
p!("]");
|
||||
}
|
||||
ty::Array(ty, sz) => {
|
||||
p!("[", print(ty), "; ");
|
||||
if self.should_print_verbose() {
|
||||
p!(write("{:?}", sz));
|
||||
} else if let ty::ConstKind::Unevaluated(..) = sz.kind() {
|
||||
// Do not try to evaluate unevaluated constants. If we are const evaluating an
|
||||
// array length anon const, rustc will (with debug assertions) print the
|
||||
// constant's path. Which will end up here again.
|
||||
p!("_");
|
||||
} else if let Some(n) = sz.kind().try_to_bits(self.tcx().data_layout.pointer_size) {
|
||||
p!(write("{}", n));
|
||||
} else if let ty::ConstKind::Param(param) = sz.kind() {
|
||||
p!(print(param));
|
||||
} else {
|
||||
p!("_");
|
||||
}
|
||||
p!("]")
|
||||
}
|
||||
ty::Array(ty, sz) => p!("[", print(ty), "; ", print(sz), "]"),
|
||||
ty::Slice(ty) => p!("[", print(ty), "]"),
|
||||
}
|
||||
|
||||
@ -1303,10 +1286,10 @@ pub trait PrettyPrinter<'tcx>:
|
||||
match ct.kind() {
|
||||
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => {
|
||||
match self.tcx().def_kind(def.did) {
|
||||
DefKind::Static(..) | DefKind::Const | DefKind::AssocConst => {
|
||||
DefKind::Const | DefKind::AssocConst => {
|
||||
p!(print_value_path(def.did, substs))
|
||||
}
|
||||
_ => {
|
||||
DefKind::AnonConst => {
|
||||
if def.is_local() {
|
||||
let span = self.tcx().def_span(def.did);
|
||||
if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) {
|
||||
@ -1318,6 +1301,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
print_underscore!()
|
||||
}
|
||||
}
|
||||
defkind => bug!("`{:?}` has unexpcted defkind {:?}", ct, defkind),
|
||||
}
|
||||
}
|
||||
ty::ConstKind::Infer(infer_ct) => {
|
||||
|
@ -10,7 +10,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
||||
LL | pub struct SelfDependent<const N: [u8; N]>;
|
||||
| ^ the type must not depend on the parameter `N`
|
||||
|
||||
error: `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u8; N]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/const-param-type-depends-on-const-param.rs:11:47
|
||||
|
|
||||
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]);
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
||||
|
||||
error: `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u8; N]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/const-param-type-depends-on-const-param.rs:15:35
|
||||
|
|
||||
LL | pub struct SelfDependent<const N: [u8; N]>;
|
||||
|
@ -10,10 +10,10 @@
|
||||
|
||||
pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
|
||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
||||
//[min]~^^ ERROR `[u8; _]` is forbidden
|
||||
//[min]~^^ ERROR `[u8; N]` is forbidden
|
||||
|
||||
pub struct SelfDependent<const N: [u8; N]>;
|
||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
||||
//[min]~^^ ERROR `[u8; _]` is forbidden
|
||||
//[min]~^^ ERROR `[u8; N]` is forbidden
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0277]: the trait bound `[Adt; _]: Foo` is not satisfied
|
||||
error[E0277]: the trait bound `[Adt; std::mem::size_of::<Self::Assoc>()]: Foo` is not satisfied
|
||||
--> $DIR/dont-evaluate-array-len-on-err-1.rs:15:9
|
||||
|
|
||||
LL | <[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar()
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; _]`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; std::mem::size_of::<Self::Assoc>()]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -15,7 +15,7 @@ LL | ArrayHolder([0; Self::SIZE])
|
||||
| arguments to this struct are incorrect
|
||||
|
|
||||
= note: expected array `[u32; X]`
|
||||
found array `[u32; _]`
|
||||
found array `[u32; Self::SIZE]`
|
||||
note: tuple struct defined here
|
||||
--> $DIR/issue-62504.rs:14:8
|
||||
|
|
||||
|
@ -2,13 +2,13 @@ error[E0308]: mismatched types
|
||||
--> $DIR/issue-79518-default_trait_method_normalization.rs:16:32
|
||||
|
|
||||
LL | Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()];
|
||||
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); _]`
|
||||
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); std::mem::size_of::<Self::Assoc>()]`
|
||||
| |
|
||||
| expected because this is `<Self as Foo>::Assoc`
|
||||
|
|
||||
= note: expected associated type `<Self as Foo>::Assoc`
|
||||
found array `[(); _]`
|
||||
= help: consider constraining the associated type `<Self as Foo>::Assoc` to `[(); _]` or calling a method that returns `<Self as Foo>::Assoc`
|
||||
found array `[(); std::mem::size_of::<Self::Assoc>()]`
|
||||
= 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`
|
||||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -4,7 +4,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
||||
LL | fn foo<const N: usize, const A: [u8; N]>() {}
|
||||
| ^ the type must not depend on the parameter `N`
|
||||
|
||||
error: `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u8; N]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/issue-62878.rs:5:33
|
||||
|
|
||||
LL | fn foo<const N: usize, const A: [u8; N]>() {}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
fn foo<const N: usize, const A: [u8; N]>() {}
|
||||
//~^ ERROR the type of const parameters must not
|
||||
//[min]~| ERROR `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
//[min]~| ERROR `[u8; N]` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {
|
||||
foo::<_, { [1] }>();
|
||||
|
@ -4,7 +4,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
|
||||
LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
|
||||
| ^^^ the type must not depend on the parameter `LEN`
|
||||
|
||||
error: `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u8; LEN]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/issue-71169.rs:5:38
|
||||
|
|
||||
LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
|
||||
//~^ ERROR the type of const parameters must not
|
||||
//[min]~^^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
//[min]~^^ ERROR `[u8; LEN]` is forbidden as the type of a const generic parameter
|
||||
fn main() {
|
||||
const DATA: [u8; 4] = *b"ABCD";
|
||||
foo::<4, DATA>();
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: `[u32; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u32; LEN]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/issue-73491.rs:8:19
|
||||
|
|
||||
LL | fn hoge<const IN: [u32; LEN]>() {}
|
||||
|
@ -6,6 +6,6 @@
|
||||
const LEN: usize = 1024;
|
||||
|
||||
fn hoge<const IN: [u32; LEN]>() {}
|
||||
//[min]~^ ERROR `[u32; _]` is forbidden as the type of a const generic parameter
|
||||
//[min]~^ ERROR `[u32; LEN]` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/issue-74101.rs:6:18
|
||||
|
|
||||
LL | fn test<const N: [u8; 1 + 2]>() {}
|
||||
@ -7,7 +7,7 @@ LL | fn test<const N: [u8; 1 + 2]>() {}
|
||||
= note: the only supported types are integers, `bool` and `char`
|
||||
= help: more complex types are supported with `#![feature(adt_const_params)]`
|
||||
|
||||
error: `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/issue-74101.rs:9:21
|
||||
|
|
||||
LL | struct Foo<const N: [u8; 1 + 2]>;
|
||||
|
@ -4,9 +4,9 @@
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
|
||||
fn test<const N: [u8; 1 + 2]>() {}
|
||||
//[min]~^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
//[min]~^ ERROR `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
|
||||
|
||||
struct Foo<const N: [u8; 1 + 2]>;
|
||||
//[min]~^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
//[min]~^ ERROR `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u8; Bar::<u32>::value()]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/issue-75047.rs:14:21
|
||||
|
|
||||
LL | struct Foo<const N: [u8; Bar::<u32>::value()]>;
|
||||
|
@ -12,6 +12,6 @@ impl<T> Bar<T> {
|
||||
}
|
||||
|
||||
struct Foo<const N: [u8; Bar::<u32>::value()]>;
|
||||
//[min]~^ ERROR `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
//[min]~^ ERROR `[u8; Bar::<u32>::value()]` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,14 @@
|
||||
error: `[u8; _]` is forbidden as the type of a const generic parameter
|
||||
error: `[u8; {
|
||||
struct Foo<const N: usize>;
|
||||
|
||||
impl<const N: usize> Foo<N> {
|
||||
fn value() -> usize {
|
||||
N
|
||||
}
|
||||
}
|
||||
|
||||
Foo::<17>::value()
|
||||
}]` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/nested-type.rs:6:21
|
||||
|
|
||||
LL | struct Foo<const N: [u8; {
|
||||
|
@ -15,8 +15,8 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
|
||||
LL | bytes: [u8; std::mem::size_of::<Foo>()]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which requires computing layout of `Foo`...
|
||||
= note: ...which requires computing layout of `[u8; _]`...
|
||||
= note: ...which requires normalizing `[u8; _]`...
|
||||
= note: ...which requires computing layout of `[u8; std::mem::size_of::<Foo>()]`...
|
||||
= note: ...which requires normalizing `[u8; std::mem::size_of::<Foo>()]`...
|
||||
= note: ...which again requires evaluating type-level constant, completing the cycle
|
||||
note: cycle used when checking that `Foo` is well-formed
|
||||
--> $DIR/const-size_of-cycle.rs:3:1
|
||||
|
@ -15,8 +15,8 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
|
||||
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: ...which requires computing layout of `Foo`...
|
||||
= note: ...which requires computing layout of `[u8; _]`...
|
||||
= note: ...which requires normalizing `[u8; _]`...
|
||||
= note: ...which requires computing layout of `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
|
||||
= note: ...which requires normalizing `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
|
||||
= note: ...which again requires evaluating type-level constant, completing the cycle
|
||||
note: cycle used when checking that `Foo` is well-formed
|
||||
--> $DIR/issue-44415.rs:5:1
|
||||
|
@ -7,7 +7,7 @@ impl<A, B> Foo<A, B> {
|
||||
[5; Self::HOST_SIZE] == [6; 0]
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
//~| ERROR constant expression depends on a generic parameter
|
||||
//~| ERROR can't compare `[{integer}; _]` with `[{integer}; 0]`
|
||||
//~| ERROR can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,13 +14,13 @@ LL | [5; Self::HOST_SIZE] == [6; 0]
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error[E0277]: can't compare `[{integer}; _]` with `[{integer}; 0]`
|
||||
error[E0277]: can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
|
||||
--> $DIR/too_generic_eval_ice.rs:7:30
|
||||
|
|
||||
LL | [5; Self::HOST_SIZE] == [6; 0]
|
||||
| ^^ no implementation for `[{integer}; _] == [{integer}; 0]`
|
||||
| ^^ no implementation for `[{integer}; Self::HOST_SIZE] == [{integer}; 0]`
|
||||
|
|
||||
= help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; _]`
|
||||
= help: the trait `PartialEq<[{integer}; 0]>` is not implemented for `[{integer}; Self::HOST_SIZE]`
|
||||
= help: the following other types implement trait `PartialEq<Rhs>`:
|
||||
<&[B] as PartialEq<[A; N]>>
|
||||
<&[T] as PartialEq<Vec<U, A>>>
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: values of the type `[u8; SIZE]` are too big for the current architecture
|
||||
error: values of the type `[u8; usize::MAX]` are too big for the current architecture
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: values of the type `[u8; SIZE]` are too big for the current architecture
|
||||
error: values of the type `[u8; usize::MAX]` are too big for the current architecture
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -6,5 +6,5 @@ fn foo<const N: usize>(_: impl std::fmt::Display) -> [usize; N] {
|
||||
|
||||
fn main() {
|
||||
let _ = foo("foo");
|
||||
//~^ ERROR: type annotations needed for `[usize; _]`
|
||||
//~^ ERROR: type annotations needed for `[usize; N]`
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error[E0282]: type annotations needed for `[usize; _]`
|
||||
error[E0282]: type annotations needed for `[usize; N]`
|
||||
--> $DIR/issue-83606.rs:8:9
|
||||
|
|
||||
LL | let _ = foo("foo");
|
||||
@ -6,7 +6,7 @@ LL | let _ = foo("foo");
|
||||
|
|
||||
help: consider giving this pattern a type, where the the value of const parameter `N` is specified
|
||||
|
|
||||
LL | let _: [usize; _] = foo("foo");
|
||||
LL | let _: [usize; N] = foo("foo");
|
||||
| ++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: values of the type `[usize; 18446744073709551615]` are too big for the current architecture
|
||||
error: values of the type `[usize; usize::MAX]` are too big for the current architecture
|
||||
--> $DIR/issue-15919-64.rs:9:9
|
||||
|
|
||||
LL | let x = [0usize; 0xffff_ffff_ffff_ffff];
|
||||
|
@ -1,7 +1,7 @@
|
||||
error[E0080]: values of the type `[u8; SIZE]` are too big for the current architecture
|
||||
error[E0080]: values of the type `[u8; usize::MAX]` are too big for the current architecture
|
||||
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
||||
|
|
||||
note: inside `std::mem::size_of::<[u8; SIZE]>`
|
||||
note: inside `std::mem::size_of::<[u8; usize::MAX]>`
|
||||
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
||||
note: inside `main`
|
||||
--> $DIR/issue-55878.rs:7:26
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: values of the type `[u8; 18446744073709551615]` are too big for the current architecture
|
||||
error: values of the type `[u8; usize::MAX]` are too big for the current architecture
|
||||
--> $DIR/issue-69485-var-size-diffs-too-large.rs:6:5
|
||||
|
|
||||
LL | Bug::V([0; !0]);
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: values of the type `[u8; 18446744073709551615]` are too big for the current architecture
|
||||
error: values of the type `[u8; usize::MAX]` are too big for the current architecture
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -8,9 +8,8 @@ trait Foo {
|
||||
}
|
||||
|
||||
impl Foo for [u8; 1 + 2] {
|
||||
#[rustc_def_path] //~ ERROR def-path(<[u8; _] as Foo>::baz)
|
||||
fn baz() { }
|
||||
#[rustc_def_path] //~ ERROR def-path(<[u8; 1 + 2] as Foo>::baz)
|
||||
fn baz() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
fn main() {}
|
||||
|
@ -1,4 +1,4 @@
|
||||
error: def-path(<[u8; _] as Foo>::baz)
|
||||
error: def-path(<[u8; 1 + 2] as Foo>::baz)
|
||||
--> $DIR/impl2.rs:11:5
|
||||
|
|
||||
LL | #[rustc_def_path]
|
||||
|
Loading…
Reference in New Issue
Block a user