Skip to content
Merged
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
15 changes: 9 additions & 6 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,16 @@ impl<'tcx> ForbidParamUsesFolder<'tcx> {
diag.span_note(impl_.self_ty.span, "not a concrete type");
}
}
if matches!(self.context, ForbidParamContext::ConstArgument)
&& self.tcx.features().min_generic_const_args()
{
if !self.tcx.features().generic_const_args() {
diag.help("add `#![feature(generic_const_args)]` to allow generic expressions as the RHS of const items");
} else {
if matches!(self.context, ForbidParamContext::ConstArgument) {
if self.tcx.features().generic_const_args() {
diag.help("consider factoring the expression into a `type const` item and use it as the const argument instead");
} else if self.tcx.features().min_generic_const_args() {
diag.help("add `#![feature(generic_const_args)]` and extract the expression into a `type const` item");
} else if self.tcx.sess.is_nightly_build() {
diag.help(
"add `#![feature(generic_const_exprs)]` to allow generic const expressions",
);
diag.help("alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item");
}
}
diag.emit()
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ pub(crate) struct ParamInNonTrivialAnonConst {
"consider factoring the expression into a `type const` item and use it as the const argument instead"
)]
pub(crate) help_gca: bool,
#[help(
"alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item"
)]
pub(crate) help_suggest_gca: bool,
}

#[derive(Debug)]
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_resolve/src/error_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,9 +1288,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
span,
name,
param_kind: is_type,
help: self.tcx.sess.is_nightly_build(),
help: self.tcx.sess.is_nightly_build()
&& !self.tcx.features().min_generic_const_args(),
is_gca,
help_gca: is_gca,
help_suggest_gca: self.tcx.sess.is_nightly_build() && !is_gca,
})
}
ResolutionError::ParamInEnumDiscriminant { name, param_kind: is_type } => {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3983,9 +3983,12 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
span: lifetime_ref.ident.span,
name: lifetime_ref.ident.name,
param_kind: diagnostics::ParamKindInNonTrivialAnonConst::Lifetime,
help: self.r.tcx.sess.is_nightly_build(),
help: self.r.tcx.sess.is_nightly_build()
&& !self.r.features.min_generic_const_args(),
is_gca: self.r.features.generic_const_args(),
help_gca: self.r.features.generic_const_args(),
help_suggest_gca: self.r.tcx.sess.is_nightly_build()
&& !self.r.features.generic_const_args(),
})
.emit()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | let _array: [u32; <A as Foo>::Y];
|
= note: type parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: aborting due to 1 previous error

2 changes: 2 additions & 0 deletions tests/ui/associated-consts/issue-47814.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ note: not a concrete type
|
LL | impl<'a> ArpIPv4<'a> {
| ^^^^^^^^^^^
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | links: [u32; A::LINKS], // Shouldn't suggest bounds already there.
|
= note: type parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | let x: &'b ();
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/index-oob-ice-83993.rs:18:17
Expand All @@ -15,6 +16,7 @@ LL | let _: &'b ();
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: aborting due to 2 previous errors

23 changes: 23 additions & 0 deletions tests/ui/const-generics/const-arg-in-const-arg.min.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | let _: [u8; foo::<T>()];
|
= note: type parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:16:23
Expand All @@ -15,6 +16,7 @@ LL | let _: [u8; bar::<N>()];
|
= help: const parameters may only be used as standalone arguments here, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:18:23
Expand All @@ -24,6 +26,7 @@ LL | let _: [u8; faz::<'a>(&())];
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:20:23
Expand All @@ -33,6 +36,7 @@ LL | let _: [u8; baz::<'a>(&())];
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:21:23
Expand All @@ -42,6 +46,7 @@ LL | let _: [u8; faz::<'b>(&())];
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:23:23
Expand All @@ -51,6 +56,7 @@ LL | let _: [u8; baz::<'b>(&())];
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:27:23
Expand All @@ -60,6 +66,7 @@ LL | let _ = [0; bar::<N>()];
|
= help: const parameters may only be used as standalone arguments here, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:29:23
Expand All @@ -69,6 +76,7 @@ LL | let _ = [0; faz::<'a>(&())];
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:31:23
Expand All @@ -78,6 +86,7 @@ LL | let _ = [0; baz::<'a>(&())];
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:32:23
Expand All @@ -87,6 +96,7 @@ LL | let _ = [0; faz::<'b>(&())];
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:34:23
Expand All @@ -96,6 +106,7 @@ LL | let _ = [0; baz::<'b>(&())];
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:35:24
Expand All @@ -105,6 +116,7 @@ LL | let _: Foo<{ foo::<T>() }>;
|
= note: type parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:36:24
Expand All @@ -114,6 +126,7 @@ LL | let _: Foo<{ bar::<N>() }>;
|
= help: const parameters may only be used as standalone arguments here, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:38:24
Expand All @@ -123,6 +136,7 @@ LL | let _: Foo<{ faz::<'a>(&()) }>;
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:40:24
Expand All @@ -132,6 +146,7 @@ LL | let _: Foo<{ baz::<'a>(&()) }>;
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:41:24
Expand All @@ -141,6 +156,7 @@ LL | let _: Foo<{ faz::<'b>(&()) }>;
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:43:24
Expand All @@ -150,6 +166,7 @@ LL | let _: Foo<{ baz::<'b>(&()) }>;
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:44:27
Expand All @@ -159,6 +176,7 @@ LL | let _ = Foo::<{ foo::<T>() }>;
|
= note: type parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:45:27
Expand All @@ -168,6 +186,7 @@ LL | let _ = Foo::<{ bar::<N>() }>;
|
= help: const parameters may only be used as standalone arguments here, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:47:27
Expand All @@ -177,6 +196,7 @@ LL | let _ = Foo::<{ faz::<'a>(&()) }>;
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:49:27
Expand All @@ -186,6 +206,7 @@ LL | let _ = Foo::<{ baz::<'a>(&()) }>;
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:50:27
Expand All @@ -195,6 +216,7 @@ LL | let _ = Foo::<{ faz::<'b>(&()) }>;
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/const-arg-in-const-arg.rs:52:27
Expand All @@ -204,6 +226,7 @@ LL | let _ = Foo::<{ baz::<'b>(&()) }>;
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error[E0747]: unresolved item provided when a constant was expected
--> $DIR/const-arg-in-const-arg.rs:16:23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | pad: [u8; is_zst::<T>()],
|
= note: type parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error[E0277]: the size for values of type `T` cannot be known at compilation time
--> $DIR/const-argument-if-length.rs:16:12
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | let _: &'a ();
|
= note: lifetime parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | struct Foo<const N: usize, const M: usize = { N + 1 }>;
|
= help: const parameters may only be used as standalone arguments here, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: generic parameters may not be used in const operations
--> $DIR/complex-generic-default-expr.rs:9:62
Expand All @@ -15,6 +16,7 @@ LL | struct Bar<T, const TYPE_SIZE: usize = { std::mem::size_of::<T>() }>(T);
|
= note: type parameters may not be used in const expressions
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LL | fn foo<const N: usize>() -> Foo<{ arg!{} arg!{} }> { loop {} }
|
= help: const parameters may only be used as standalone arguments here, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
= note: this error originates in the macro `arg` (in Nightly builds, run with -Z macro-backtrace for more info)

error: generic parameters may not be used in const operations
Expand All @@ -22,6 +23,7 @@ LL | fn foo<const N: usize>() -> Foo<{ arg!{} arg!{} }> { loop {} }
|
= help: const parameters may only be used as standalone arguments here, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item
= note: this error originates in the macro `arg` (in Nightly builds, run with -Z macro-backtrace for more info)

error: generic parameters may not be used in const operations
Expand All @@ -32,6 +34,7 @@ LL | fn bar<const N: usize>() -> [(); { empty!{}; N }] { loop {} }
|
= help: const parameters may only be used as standalone arguments here, i.e. `N`
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
= help: alternatively, you can use `#![feature(generic_const_args)]` and extract the expression into a `type const` item

error: aborting due to 3 previous errors

Loading
Loading