From c43d981a7f6dbb9739403733110c59e6be066827 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Tue, 1 Oct 2024 00:55:23 -0400 Subject: [PATCH] Use `ConstArgKind::Path` for all paths Like in the previous commit, (most of) these changes to error output are not desired. They are merely committed temporarily to make it easier to see what's changed. --- compiler/rustc_ast_lowering/src/lib.rs | 3 +- .../bad-generic-in-copy-impl.stderr | 37 ++++++++++++++----- .../type-alias-bounds.neg.stderr | 14 +------ ...st-len-underflow-separate-spans.old.stderr | 6 --- tests/ui/consts/issue-39974.stderr | 8 +--- 5 files changed, 31 insertions(+), 37 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 98970e55251f0..8f3e59266e266 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -2396,9 +2396,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { 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 Res::Def(DefKind::ConstParam | DefKind::Const, _) = res && let ExprKind::Path(qself, path) = &expr.kind { let qpath = self.lower_qpath( diff --git a/tests/ui/const-generics/bad-generic-in-copy-impl.stderr b/tests/ui/const-generics/bad-generic-in-copy-impl.stderr index fbd546d42fb52..145658d99c2f4 100644 --- a/tests/ui/const-generics/bad-generic-in-copy-impl.stderr +++ b/tests/ui/const-generics/bad-generic-in-copy-impl.stderr @@ -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`. diff --git a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr index fa12dd14753f9..0fcb4a64d218b 100644 --- a/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr +++ b/tests/ui/const-generics/generic_const_exprs/type-alias-bounds.neg.stderr @@ -1,15 +1,3 @@ -error[E0277]: the trait bound `String: Copy` is not satisfied - --> $DIR/type-alias-bounds.rs:23:12 - | -LL | let _: AliasConstUnused; - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` - | -note: required by a bound in `ct_unused_0::AliasConstUnused` - --> $DIR/type-alias-bounds.rs:20:30 - | -LL | type AliasConstUnused = (T, I32<{ DATA }>); - | ^^^^ required by this bound in `AliasConstUnused` - error[E0277]: the trait bound `String: Copy` is not satisfied --> $DIR/type-alias-bounds.rs:31:12 | @@ -58,6 +46,6 @@ note: required by a bound in `AliasFnUsed` LL | type AliasFnUsed = I32<{ code::() }>; | ^^^^ required by this bound in `AliasFnUsed` -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/consts/const-len-underflow-separate-spans.old.stderr b/tests/ui/consts/const-len-underflow-separate-spans.old.stderr index bd2a81f514830..59fb30400dc0b 100644 --- a/tests/ui/consts/const-len-underflow-separate-spans.old.stderr +++ b/tests/ui/consts/const-len-underflow-separate-spans.old.stderr @@ -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`. diff --git a/tests/ui/consts/issue-39974.stderr b/tests/ui/consts/issue-39974.stderr index a371ea5709e1b..928c2e33ad4b1 100644 --- a/tests/ui/consts/issue-39974.stderr +++ b/tests/ui/consts/issue-39974.stderr @@ -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`.