Remove "type parameter depends on const parameter" error from resolution

This commit is contained in:
varkor 2019-10-20 18:18:24 +01:00
parent 133cd2cfaf
commit f0e6cd9f89
8 changed files with 21 additions and 72 deletions

View file

@ -367,16 +367,6 @@ impl<'a> Resolver<'a> {
span, "`Self` in type parameter default".to_string());
err
}
ResolutionError::ConstParamDependentOnTypeParam => {
let mut err = struct_span_err!(
self.session,
span,
E0671,
"const parameters cannot depend on type parameters"
);
err.span_label(span, format!("const parameter depends on type parameter"));
err
}
}
}

View file

@ -1880,13 +1880,14 @@ fn main() {
"##,
E0671: r##"
#### Note: this error code is no longer emitted by the compiler.
Const parameters cannot depend on type parameters.
The following is therefore invalid:
```compile_fail,E0671
```compile_fail,E0740
#![feature(const_generics)]
fn const_id<T, const N: T>() -> T { // error: const parameter
// depends on type parameter
fn const_id<T, const N: T>() -> T { // error
N
}
```

View file

@ -111,9 +111,6 @@ crate enum RibKind<'a> {
/// from the default of a type parameter because they're not declared
/// before said type parameter. Also see the `visit_generics` override.
ForwardTyParamBanRibKind,
/// We forbid the use of type parameters as the types of const parameters.
TyParamAsConstParamTy,
}
impl RibKind<'_> {
@ -128,8 +125,7 @@ impl RibKind<'_> {
| MacroDefinition(_) => false,
AssocItemRibKind
| ItemRibKind(_)
| ForwardTyParamBanRibKind
| TyParamAsConstParamTy => true,
| ForwardTyParamBanRibKind => true,
}
}
}
@ -483,18 +479,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
default_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err);
}
// We also ban access to type parameters for use as the types of const parameters.
let mut const_ty_param_ban_rib = Rib::new(TyParamAsConstParamTy);
const_ty_param_ban_rib.bindings.extend(generics.params.iter()
.filter(|param| {
if let GenericParamKind::Type { .. } = param.kind {
true
} else {
false
}
})
.map(|param| (Ident::with_dummy_span(param.ident.name), Res::Err)));
for param in &generics.params {
match param.kind {
GenericParamKind::Lifetime { .. } => self.visit_generic_param(param),
@ -513,15 +497,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LateResolutionVisitor<'a, '_> {
default_ban_rib.bindings.remove(&Ident::with_dummy_span(param.ident.name));
}
GenericParamKind::Const { ref ty } => {
self.ribs[TypeNS].push(const_ty_param_ban_rib);
for bound in &param.bounds {
self.visit_param_bound(bound);
}
self.visit_ty(ty);
const_ty_param_ban_rib = self.ribs[TypeNS].pop().unwrap();
}
}
}

View file

@ -215,8 +215,6 @@ enum ResolutionError<'a> {
ForwardDeclaredTyParam, // FIXME(const_generics:defaults)
/// Error E0735: type parameters with a default cannot use `Self`
SelfInTyParamDefault,
/// Error E0671: const parameter cannot depend on type parameter.
ConstParamDependentOnTypeParam,
}
// A minimal representation of a path segment. We use this in resolve because
@ -2169,15 +2167,6 @@ impl<'a> Resolver<'a> {
return Res::Err;
}
// An invalid use of a type parameter as the type of a const parameter.
if let TyParamAsConstParamTy = all_ribs[rib_index].kind {
if record_used {
self.report_error(span, ResolutionError::ConstParamDependentOnTypeParam);
}
assert_eq!(res, Res::Err);
return Res::Err;
}
match res {
Res::Local(_) => {
use ResolutionError::*;
@ -2186,7 +2175,7 @@ impl<'a> Resolver<'a> {
for rib in ribs {
match rib.kind {
NormalRibKind | ModuleRibKind(..) | MacroDefinition(..) |
ForwardTyParamBanRibKind | TyParamAsConstParamTy => {
ForwardTyParamBanRibKind => {
// Nothing to do. Continue.
}
ItemRibKind(_) | FnItemRibKind | AssocItemRibKind => {
@ -2220,7 +2209,7 @@ impl<'a> Resolver<'a> {
let has_generic_params = match rib.kind {
NormalRibKind | AssocItemRibKind |
ModuleRibKind(..) | MacroDefinition(..) | ForwardTyParamBanRibKind |
ConstantItemRibKind | TyParamAsConstParamTy => {
ConstantItemRibKind => {
// Nothing to do. Continue.
continue;
}

View file

@ -1,6 +1,6 @@
use std::marker::PhantomData;
struct B<T, const N: T>(PhantomData<[T; N]>); //~ ERROR const generics are unstable
//~^ ERROR const parameters cannot depend on type parameters
//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq`
fn main() {}

View file

@ -1,9 +1,3 @@
error[E0671]: const parameters cannot depend on type parameters
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22
|
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
| ^ const parameter depends on type parameter
error[E0658]: const generics are unstable
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:19
|
@ -13,7 +7,13 @@ LL | struct B<T, const N: T>(PhantomData<[T; N]>);
= note: for more information, see https://github.com/rust-lang/rust/issues/44580
= help: add `#![feature(const_generics)]` to the crate attributes to enable
error[E0740]: the types of const generic parameters must derive `PartialEq` and `Eq`
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22
|
LL | struct B<T, const N: T>(PhantomData<[T; N]>);
| ^ `T` doesn't derive both `PartialEq` and `Eq`
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0658, E0671.
Some errors have detailed explanations: E0658, E0740.
For more information about an error, try `rustc --explain E0658`.

View file

@ -7,7 +7,6 @@
// details.
pub struct Dependent<T, const X: T>([(); X]);
//~^ ERROR const parameters cannot depend on type parameters
//~^^ ERROR parameter `T` is never used
//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq`
fn main() {}

View file

@ -1,9 +1,3 @@
error[E0671]: const parameters cannot depend on type parameters
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
|
LL | pub struct Dependent<T, const X: T>([(); X]);
| ^ const parameter depends on type parameter
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-param-type-depends-on-type-param.rs:1:12
|
@ -12,15 +6,12 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default
error[E0392]: parameter `T` is never used
--> $DIR/const-param-type-depends-on-type-param.rs:9:22
error[E0740]: the types of const generic parameters must derive `PartialEq` and `Eq`
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
|
LL | pub struct Dependent<T, const X: T>([(); X]);
| ^ unused parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `std::marker::PhantomData`
| ^ `T` doesn't derive both `PartialEq` and `Eq`
error: aborting due to 2 previous errors
error: aborting due to previous error
Some errors have detailed explanations: E0392, E0671.
For more information about an error, try `rustc --explain E0392`.
For more information about this error, try `rustc --explain E0740`.