Skip to content

Commit f0e6cd9

Browse files
committed
Remove "type parameter depends on const parameter" error from resolution
1 parent 133cd2c commit f0e6cd9

8 files changed

+21
-72
lines changed

src/librustc_resolve/diagnostics.rs

-10
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,6 @@ impl<'a> Resolver<'a> {
367367
span, "`Self` in type parameter default".to_string());
368368
err
369369
}
370-
ResolutionError::ConstParamDependentOnTypeParam => {
371-
let mut err = struct_span_err!(
372-
self.session,
373-
span,
374-
E0671,
375-
"const parameters cannot depend on type parameters"
376-
);
377-
err.span_label(span, format!("const parameter depends on type parameter"));
378-
err
379-
}
380370
}
381371
}
382372

src/librustc_resolve/error_codes.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1880,13 +1880,14 @@ fn main() {
18801880
"##,
18811881

18821882
E0671: r##"
1883+
#### Note: this error code is no longer emitted by the compiler.
1884+
18831885
Const parameters cannot depend on type parameters.
18841886
The following is therefore invalid:
1885-
```compile_fail,E0671
1887+
```compile_fail,E0740
18861888
#![feature(const_generics)]
18871889
1888-
fn const_id<T, const N: T>() -> T { // error: const parameter
1889-
// depends on type parameter
1890+
fn const_id<T, const N: T>() -> T { // error
18901891
N
18911892
}
18921893
```

src/librustc_resolve/late.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ crate enum RibKind<'a> {
111111
/// from the default of a type parameter because they're not declared
112112
/// before said type parameter. Also see the `visit_generics` override.
113113
ForwardTyParamBanRibKind,
114-
115-
/// We forbid the use of type parameters as the types of const parameters.
116-
TyParamAsConstParamTy,
117114
}
118115

119116
impl RibKind<'_> {
@@ -128,8 +125,7 @@ impl RibKind<'_> {
128125
| MacroDefinition(_) => false,
129126
AssocItemRibKind
130127
| ItemRibKind(_)
131-
| ForwardTyParamBanRibKind
132-
| TyParamAsConstParamTy => true,
128+
| ForwardTyParamBanRibKind => true,
133129
}
134130
}
135131
}
@@ -483,18 +479,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
483479
default_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err);
484480
}
485481

486-
// We also ban access to type parameters for use as the types of const parameters.
487-
let mut const_ty_param_ban_rib = Rib::new(TyParamAsConstParamTy);
488-
const_ty_param_ban_rib.bindings.extend(generics.params.iter()
489-
.filter(|param| {
490-
if let GenericParamKind::Type { .. } = param.kind {
491-
true
492-
} else {
493-
false
494-
}
495-
})
496-
.map(|param| (Ident::with_dummy_span(param.ident.name), Res::Err)));
497-
498482
for param in &generics.params {
499483
match param.kind {
500484
GenericParamKind::Lifetime { .. } => self.visit_generic_param(param),
@@ -513,15 +497,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
513497
default_ban_rib.bindings.remove(&Ident::with_dummy_span(param.ident.name));
514498
}
515499
GenericParamKind::Const { ref ty } => {
516-
self.ribs[TypeNS].push(const_ty_param_ban_rib);
517-
518500
for bound in &param.bounds {
519501
self.visit_param_bound(bound);
520502
}
521-
522503
self.visit_ty(ty);
523-
524-
const_ty_param_ban_rib = self.ribs[TypeNS].pop().unwrap();
525504
}
526505
}
527506
}

src/librustc_resolve/lib.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ enum ResolutionError<'a> {
215215
ForwardDeclaredTyParam, // FIXME(const_generics:defaults)
216216
/// Error E0735: type parameters with a default cannot use `Self`
217217
SelfInTyParamDefault,
218-
/// Error E0671: const parameter cannot depend on type parameter.
219-
ConstParamDependentOnTypeParam,
220218
}
221219

222220
// A minimal representation of a path segment. We use this in resolve because
@@ -2169,15 +2167,6 @@ impl<'a> Resolver<'a> {
21692167
return Res::Err;
21702168
}
21712169

2172-
// An invalid use of a type parameter as the type of a const parameter.
2173-
if let TyParamAsConstParamTy = all_ribs[rib_index].kind {
2174-
if record_used {
2175-
self.report_error(span, ResolutionError::ConstParamDependentOnTypeParam);
2176-
}
2177-
assert_eq!(res, Res::Err);
2178-
return Res::Err;
2179-
}
2180-
21812170
match res {
21822171
Res::Local(_) => {
21832172
use ResolutionError::*;
@@ -2186,7 +2175,7 @@ impl<'a> Resolver<'a> {
21862175
for rib in ribs {
21872176
match rib.kind {
21882177
NormalRibKind | ModuleRibKind(..) | MacroDefinition(..) |
2189-
ForwardTyParamBanRibKind | TyParamAsConstParamTy => {
2178+
ForwardTyParamBanRibKind => {
21902179
// Nothing to do. Continue.
21912180
}
21922181
ItemRibKind(_) | FnItemRibKind | AssocItemRibKind => {
@@ -2220,7 +2209,7 @@ impl<'a> Resolver<'a> {
22202209
let has_generic_params = match rib.kind {
22212210
NormalRibKind | AssocItemRibKind |
22222211
ModuleRibKind(..) | MacroDefinition(..) | ForwardTyParamBanRibKind |
2223-
ConstantItemRibKind | TyParamAsConstParamTy => {
2212+
ConstantItemRibKind => {
22242213
// Nothing to do. Continue.
22252214
continue;
22262215
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::marker::PhantomData;
22

33
struct B<T, const N: T>(PhantomData<[T; N]>); //~ ERROR const generics are unstable
4-
//~^ ERROR const parameters cannot depend on type parameters
4+
//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq`
55

66
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error[E0671]: const parameters cannot depend on type parameters
2-
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22
3-
|
4-
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
5-
| ^ const parameter depends on type parameter
6-
71
error[E0658]: const generics are unstable
82
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:19
93
|
@@ -13,7 +7,13 @@ LL | struct B<T, const N: T>(PhantomData<[T; N]>);
137
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
148
= help: add `#![feature(const_generics)]` to the crate attributes to enable
159

10+
error[E0740]: the types of const generic parameters must derive `PartialEq` and `Eq`
11+
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22
12+
|
13+
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
14+
| ^ `T` doesn't derive both `PartialEq` and `Eq`
15+
1616
error: aborting due to 2 previous errors
1717

18-
Some errors have detailed explanations: E0658, E0671.
18+
Some errors have detailed explanations: E0658, E0740.
1919
For more information about an error, try `rustc --explain E0658`.

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// details.
88

99
pub struct Dependent<T, const X: T>([(); X]);
10-
//~^ ERROR const parameters cannot depend on type parameters
11-
//~^^ ERROR parameter `T` is never used
10+
//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq`
1211

1312
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error[E0671]: const parameters cannot depend on type parameters
2-
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
3-
|
4-
LL | pub struct Dependent<T, const X: T>([(); X]);
5-
| ^ const parameter depends on type parameter
6-
71
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
82
--> $DIR/const-param-type-depends-on-type-param.rs:1:12
93
|
@@ -12,15 +6,12 @@ LL | #![feature(const_generics)]
126
|
137
= note: `#[warn(incomplete_features)]` on by default
148

15-
error[E0392]: parameter `T` is never used
16-
--> $DIR/const-param-type-depends-on-type-param.rs:9:22
9+
error[E0740]: the types of const generic parameters must derive `PartialEq` and `Eq`
10+
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
1711
|
1812
LL | pub struct Dependent<T, const X: T>([(); X]);
19-
| ^ unused parameter
20-
|
21-
= help: consider removing `T`, referring to it in a field, or using a marker such as `std::marker::PhantomData`
13+
| ^ `T` doesn't derive both `PartialEq` and `Eq`
2214

23-
error: aborting due to 2 previous errors
15+
error: aborting due to previous error
2416

25-
Some errors have detailed explanations: E0392, E0671.
26-
For more information about an error, try `rustc --explain E0392`.
17+
For more information about this error, try `rustc --explain E0740`.

0 commit comments

Comments
 (0)