Skip to content

Commit 0c511ab

Browse files
committed
update help message
1 parent 6f5d8bf commit 0c511ab

7 files changed

+22
-13
lines changed

src/librustc_resolve/diagnostics.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,17 @@ impl<'a> Resolver<'a> {
442442
);
443443
err
444444
}
445-
ResolutionError::ParamInTyOfConstArg => {
445+
ResolutionError::ParamInTyOfConstArg(name) => {
446446
let mut err = struct_span_err!(
447447
self.session,
448448
span,
449449
E0770,
450450
"the type of const parameters must not depend on other generic parameters"
451451
);
452-
err.span_label(span, "const parameters must have a concrete type");
452+
err.span_label(
453+
span,
454+
format!("the type must not depend on the parameter `{}`", name),
455+
);
453456
err
454457
}
455458
ResolutionError::SelfInTyParamDefault => {

src/librustc_resolve/lib.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ enum ResolutionError<'a> {
215215
/// Error E0128: type parameters with a default cannot use forward-declared identifiers.
216216
ForwardDeclaredTyParam, // FIXME(const_generics:defaults)
217217
/// ERROR E0770: the type of const parameters must not depend on other generic parameters.
218-
ParamInTyOfConstArg,
218+
ParamInTyOfConstArg(Symbol),
219219
/// Error E0735: type parameters with a default cannot use `Self`
220220
SelfInTyParamDefault,
221221
/// Error E0767: use of unreachable label
@@ -2484,7 +2484,7 @@ impl<'a> Resolver<'a> {
24842484
}
24852485
ConstParamTyRibKind => {
24862486
if record_used {
2487-
self.report_error(span, ParamInTyOfConstArg);
2487+
self.report_error(span, ParamInTyOfConstArg(rib_ident.name));
24882488
}
24892489
return Res::Err;
24902490
}
@@ -2513,7 +2513,10 @@ impl<'a> Resolver<'a> {
25132513
FnItemRibKind => HasGenericParams::Yes,
25142514
ConstParamTyRibKind => {
25152515
if record_used {
2516-
self.report_error(span, ResolutionError::ParamInTyOfConstArg);
2516+
self.report_error(
2517+
span,
2518+
ResolutionError::ParamInTyOfConstArg(rib_ident.name),
2519+
);
25172520
}
25182521
return Res::Err;
25192522
}
@@ -2552,7 +2555,10 @@ impl<'a> Resolver<'a> {
25522555
FnItemRibKind => HasGenericParams::Yes,
25532556
ConstParamTyRibKind => {
25542557
if record_used {
2555-
self.report_error(span, ResolutionError::ParamInTyOfConstArg);
2558+
self.report_error(
2559+
span,
2560+
ResolutionError::ParamInTyOfConstArg(rib_ident.name),
2561+
);
25562562
}
25572563
return Res::Err;
25582564
}

src/test/ui/const-generics/const-param-type-depends-on-const-param.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error[E0770]: the type of const parameters must not depend on other generic para
22
--> $DIR/const-param-type-depends-on-const-param.rs:9:52
33
|
44
LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
5-
| ^ const parameters must have a concrete type
5+
| ^ the type must not depend on the parameter `N`
66

77
error[E0770]: the type of const parameters must not depend on other generic parameters
88
--> $DIR/const-param-type-depends-on-const-param.rs:12:40
99
|
1010
LL | pub struct SelfDependent<const N: [u8; N]>;
11-
| ^ const parameters must have a concrete type
11+
| ^ the type must not depend on the parameter `N`
1212

1313
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
1414
--> $DIR/const-param-type-depends-on-const-param.rs:1:12

src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
22
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22
33
|
44
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
5-
| ^ const parameters must have a concrete type
5+
| ^ the type must not depend on the parameter `T`
66

77
error[E0658]: const generics are unstable
88
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:19

src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
22
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
33
|
44
LL | pub struct Dependent<T, const X: T>([(); X]);
5-
| ^ const parameters must have a concrete type
5+
| ^ the type must not depend on the parameter `T`
66

77
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
88
--> $DIR/const-param-type-depends-on-type-param.rs:1:12

src/test/ui/const-generics/issues/issue-71381.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error[E0770]: the type of const parameters must not depend on other generic para
22
--> $DIR/issue-71381.rs:13:82
33
|
44
LL | pub fn call_me<Args: Sized, const IDX: usize, const FN: unsafe extern "C" fn(Args)>(&self) {
5-
| ^^^^ const parameters must have a concrete type
5+
| ^^^^ the type must not depend on the parameter `Args`
66

77
error[E0770]: the type of const parameters must not depend on other generic parameters
88
--> $DIR/issue-71381.rs:22:40
99
|
1010
LL | const FN: unsafe extern "C" fn(Args),
11-
| ^^^^ const parameters must have a concrete type
11+
| ^^^^ the type must not depend on the parameter `Args`
1212

1313
error: using function pointers as const generic parameters is forbidden
1414
--> $DIR/issue-71381.rs:13:61

src/test/ui/const-generics/issues/issue-71611.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0770]: the type of const parameters must not depend on other generic para
22
--> $DIR/issue-71611.rs:4:31
33
|
44
LL | fn func<A, const F: fn(inner: A)>(outer: A) {
5-
| ^ const parameters must have a concrete type
5+
| ^ the type must not depend on the parameter `A`
66

77
error: using function pointers as const generic parameters is forbidden
88
--> $DIR/issue-71611.rs:4:21

0 commit comments

Comments
 (0)