Skip to content

Commit

Permalink
wip on constargkind::path for all paths
Browse files Browse the repository at this point in the history
lots of ICEs and other bad changes
  • Loading branch information
camelid committed Oct 20, 2024
1 parent 979edcd commit 507ada1
Show file tree
Hide file tree
Showing 20 changed files with 53 additions and 385 deletions.
9 changes: 1 addition & 8 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2334,14 +2334,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} else {
&anon.value
};
let maybe_res =
self.resolver.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res());
debug!("res={:?}", maybe_res);
// FIXME(min_generic_const_args): for now we only lower params to ConstArgKind::Path
if let Some(res) = maybe_res
&& let Res::Def(DefKind::ConstParam, _) = res
&& let ExprKind::Path(qself, path) = &expr.kind
{
if let ExprKind::Path(qself, path) = &expr.kind {
let qpath = self.lower_qpath(
expr.id,
qself,
Expand Down
37 changes: 28 additions & 9 deletions tests/ui/const-generics/bad-generic-in-copy-impl.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
error[E0308]: mismatched types
--> $DIR/bad-generic-in-copy-impl.rs:3:13
error: the constant `1` is not of type `usize`
--> $DIR/bad-generic-in-copy-impl.rs:3:8
|
LL | x: [u8; SIZE],
| ^^^^ expected `usize`, found `u32`
| ^^^^^^^^^^ expected `usize`, found `u32`

error[E0308]: mismatched types
--> $DIR/bad-generic-in-copy-impl.rs:3:13
error[E0204]: the trait `Copy` cannot be implemented for this type
--> $DIR/bad-generic-in-copy-impl.rs:1:10
|
LL | #[derive(Copy, Clone)]
| ^^^^
LL | pub struct Foo {
LL | x: [u8; SIZE],
| ^^^^ expected `usize`, found `u32`
| ------------- this field does not implement `Copy`
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
note: the `Copy` impl for `[u8; 1]` requires that `the constant `1` has type `usize``
--> $DIR/bad-generic-in-copy-impl.rs:3:8
|
LL | x: [u8; SIZE],
| ^^^^^^^^^^
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

error: the constant `1` is not of type `usize`
--> $DIR/bad-generic-in-copy-impl.rs:3:5
|
LL | #[derive(Copy, Clone)]
| ----- in this derive macro expansion
LL | pub struct Foo {
LL | x: [u8; SIZE],
| ^^^^^^^^^^^^^ expected `usize`, found `u32`
|
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0204`.
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,6 @@ LL | pub struct SelfDependent<const N: [u8; N]>;
|
= note: const parameters may not be used in the type of const parameters

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]);
| ^^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|

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]>;
| ^^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|

error: aborting due to 4 previous errors
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0770`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ error[E0741]: using function pointers as const generic parameters is forbidden
LL | struct Checked<const F: fn(usize) -> bool>;
| ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/fn-const-param-infer.rs:33:25
|
LL | let _ = Checked::<{ generic_arg::<u32> }>;
| ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
= note: expected fn pointer `fn(usize) -> _`
found fn item `fn(u32) -> _ {generic_arg::<u32>}`

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

Some errors have detailed explanations: E0308, E0741.
For more information about an error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0741`.
14 changes: 2 additions & 12 deletions tests/ui/const-generics/fn-const-param-infer.full.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ error[E0741]: using function pointers as const generic parameters is forbidden
LL | struct Checked<const F: fn(usize) -> bool>;
| ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/fn-const-param-infer.rs:33:25
|
LL | let _ = Checked::<{ generic_arg::<u32> }>;
| ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
= note: expected fn pointer `fn(usize) -> _`
found fn item `fn(u32) -> _ {generic_arg::<u32>}`

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

Some errors have detailed explanations: E0308, E0741.
For more information about an error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0741`.
12 changes: 1 addition & 11 deletions tests/ui/const-generics/fn-const-param-infer.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,5 @@ LL | struct Checked<const F: fn(usize) -> bool>;
|
= note: the only supported types are integers, `bool`, and `char`

error[E0308]: mismatched types
--> $DIR/fn-const-param-infer.rs:33:25
|
LL | let _ = Checked::<{ generic_arg::<u32> }>;
| ^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
= note: expected fn pointer `fn(usize) -> _`
found fn item `fn(u32) -> _ {generic_arg::<u32>}`

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
30 changes: 3 additions & 27 deletions tests/ui/const-generics/generic_const_exprs/error_in_ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@ LL | pub struct A<const z: [usize; x]> {}
| |
| similarly named const parameter `z` defined here

error: `[usize; x]` is forbidden as the type of a const generic parameter
--> $DIR/error_in_ty.rs:6:23
|
LL | pub struct A<const z: [usize; x]> {}
| ^^^^^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|

error[E0308]: mismatched types
--> $DIR/error_in_ty.rs:10:8
|
LL | impl A<2> {
| ^ expected `[usize; x]`, found integer

error[E0308]: mismatched types
--> $DIR/error_in_ty.rs:16:8
|
LL | impl A<2> {
| ^ expected `[usize; x]`, found integer

error[E0592]: duplicate definitions with name `B`
--> $DIR/error_in_ty.rs:12:5
|
Expand All @@ -39,7 +15,7 @@ LL | pub const fn B() {}
LL | pub const fn B() {}
| ---------------- other definition for `B`

error: aborting due to 5 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0308, E0425, E0592.
For more information about an error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0425, E0592.
For more information about an error, try `rustc --explain E0425`.
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
error[E0308]: mismatched types
--> $DIR/issue-62504.rs:18:21
|
LL | ArrayHolder([0; Self::SIZE])
| ^^^^^^^^^^^^^^^ expected `X`, found `Self::SIZE`
|
= note: expected constant `X`
found constant `Self::SIZE`

error: unconstrained generic constant
--> $DIR/issue-62504.rs:18:25
|
LL | ArrayHolder([0; Self::SIZE])
| ^^^^^^^^^^
|
help: try adding a `where` bound
|
LL | pub const fn new() -> Self where [(); Self::SIZE]: {
| +++++++++++++++++++++++

error[E0284]: type annotations needed for `ArrayHolder<_>`
--> $DIR/issue-62504.rs:26:9
|
Expand Down Expand Up @@ -52,7 +32,6 @@ help: consider giving `array` an explicit type, where the value of const paramet
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
| ++++++++++++++++

error: aborting due to 4 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0284, E0308.
For more information about an error, try `rustc --explain E0284`.
For more information about this error, try `rustc --explain E0284`.
29 changes: 2 additions & 27 deletions tests/ui/const-generics/generic_const_exprs/issue-62504.min.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
error: constant expression depends on a generic parameter
--> $DIR/issue-62504.rs:18:25
|
LL | ArrayHolder([0; Self::SIZE])
| ^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes

error[E0308]: mismatched types
--> $DIR/issue-62504.rs:18:21
|
LL | ArrayHolder([0; Self::SIZE])
| ----------- ^^^^^^^^^^^^^^^ expected `X`, found `Self::SIZE`
| |
| arguments to this struct are incorrect
|
= note: expected array `[u32; X]`
found array `[u32; Self::SIZE]`
note: tuple struct defined here
--> $DIR/issue-62504.rs:14:8
|
LL | struct ArrayHolder<const X: usize>([u32; X]);
| ^^^^^^^^^^^

error[E0284]: type annotations needed for `ArrayHolder<_>`
--> $DIR/issue-62504.rs:26:9
|
Expand Down Expand Up @@ -56,7 +32,6 @@ help: consider giving `array` an explicit type, where the value of const paramet
LL | let mut array: ArrayHolder<X> = ArrayHolder::new();
| ++++++++++++++++

error: aborting due to 4 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0284, E0308.
For more information about an error, try `rustc --explain E0284`.
For more information about this error, try `rustc --explain E0284`.
14 changes: 1 addition & 13 deletions tests/ui/const-generics/issues/issue-62878.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ LL | fn foo<const N: usize, const A: [u8; N]>() {}
|
= note: const parameters may not be used in the type of const parameters

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]>() {}
| ^^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|

error[E0747]: type provided when a constant was expected
--> $DIR/issue-62878.rs:10:11
|
Expand All @@ -30,7 +18,7 @@ help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable
LL + #![feature(generic_arg_infer)]
|

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0747, E0770.
For more information about an error, try `rustc --explain E0747`.
14 changes: 1 addition & 13 deletions tests/ui/const-generics/issues/issue-71169.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
|
= note: const parameters may not be used in the type of const parameters

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]>() {}
| ^^^^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
|
LL + #![feature(adt_const_params)]
|

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0770`.
25 changes: 1 addition & 24 deletions tests/ui/const-generics/not_wf_param_in_rpitit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ LL | trait Trait<const N: dyn Trait = bar> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/not_wf_param_in_rpitit.rs:3:22
|
LL | trait Trait<const N: dyn Trait = bar> {
| ^^^^^^^^^ `Trait` cannot be made into an object
|
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/not_wf_param_in_rpitit.rs:9:14
|
LL | trait Trait<const N: dyn Trait = bar> {
| ----- this trait cannot be made into an object...
...
LL | async fn a() {}
| ^ ...because associated function `a` has no `self` parameter
help: consider turning `a` into a method by giving it a `&self` argument
|
LL | async fn a(&self) {}
| +++++
help: alternatively, consider constraining `a` so it does not apply to trait objects
|
LL | async fn a() where Self: Sized {}
| +++++++++++++++++

error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/not_wf_param_in_rpitit.rs:3:13
|
Expand Down Expand Up @@ -88,7 +65,7 @@ help: alternatively, consider constraining `a` so it does not apply to trait obj
LL | async fn a() where Self: Sized {}
| +++++++++++++++++

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0038, E0391, E0425.
For more information about an error, try `rustc --explain E0038`.
6 changes: 0 additions & 6 deletions tests/ui/consts/const-len-underflow-separate-spans.old.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ error[E0080]: evaluation of constant value failed
LL | const LEN: usize = ONE - TWO;
| ^^^^^^^^^ attempt to compute `1_usize - 2_usize`, which would overflow

note: erroneous constant encountered
--> $DIR/const-len-underflow-separate-spans.rs:14:17
|
LL | let a: [i8; LEN] = unimplemented!();
| ^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
8 changes: 1 addition & 7 deletions tests/ui/consts/issue-39974.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ help: use a float literal
LL | const LENGTH: f64 = 2.0;
| ++

error[E0308]: mismatched types
--> $DIR/issue-39974.rs:5:19
|
LL | f: [[f64; 2]; LENGTH],
| ^^^^^^ expected `usize`, found `f64`

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
14 changes: 1 addition & 13 deletions tests/ui/extern/extern-static-size-overflow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,5 @@ error: extern static is too large for the target architecture
LL | static BAZ: [u8; max_size()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: extern static is too large for the target architecture
--> $DIR/extern-static-size-overflow.rs:21:5
|
LL | static UWU: [usize; usize::MAX];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: extern static is too large for the target architecture
--> $DIR/extern-static-size-overflow.rs:22:5
|
LL | static A: ReallyBig;
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors
error: aborting due to 1 previous error

Loading

0 comments on commit 507ada1

Please sign in to comment.