Disentangle ForwardGenericParamBan and ConstParamTy ribs
This commit is contained in:
parent
0998d4095b
commit
42773bfcac
29 changed files with 196 additions and 114 deletions
|
@ -153,9 +153,13 @@ resolve_extern_crate_self_requires_renaming =
|
||||||
`extern crate self;` requires renaming
|
`extern crate self;` requires renaming
|
||||||
.suggestion = rename the `self` crate to be able to import it
|
.suggestion = rename the `self` crate to be able to import it
|
||||||
|
|
||||||
|
resolve_forward_declared_generic_in_const_param_ty =
|
||||||
|
const parameter types cannot reference parameters before they are declared
|
||||||
|
.label = const parameter type cannot reference `{$param}` before it is declared
|
||||||
|
|
||||||
resolve_forward_declared_generic_param =
|
resolve_forward_declared_generic_param =
|
||||||
generic parameters with a default cannot use forward declared identifiers
|
generic parameter defaults cannot reference parameters before they are declared
|
||||||
.label = defaulted generic parameters cannot be forward declared
|
.label = cannot reference `{$param}` before it is declared
|
||||||
|
|
||||||
resolve_found_an_item_configured_out =
|
resolve_found_an_item_configured_out =
|
||||||
found an item that was configured out
|
found an item that was configured out
|
||||||
|
@ -377,9 +381,11 @@ resolve_self_imports_only_allowed_within_multipart_suggestion =
|
||||||
resolve_self_imports_only_allowed_within_suggestion =
|
resolve_self_imports_only_allowed_within_suggestion =
|
||||||
consider importing the module directly
|
consider importing the module directly
|
||||||
|
|
||||||
|
resolve_self_in_const_generic_ty =
|
||||||
|
cannot use `Self` in const parameter type
|
||||||
|
|
||||||
resolve_self_in_generic_param_default =
|
resolve_self_in_generic_param_default =
|
||||||
generic parameters cannot use `Self` in their defaults
|
generic parameters cannot use `Self` in their defaults
|
||||||
.label = `Self` in generic parameter default
|
|
||||||
|
|
||||||
resolve_similarly_named_defined_here =
|
resolve_similarly_named_defined_here =
|
||||||
similarly named {$candidate_descr} `{$candidate}` defined here
|
similarly named {$candidate_descr} `{$candidate}` defined here
|
||||||
|
|
|
@ -42,10 +42,10 @@ use crate::imports::{Import, ImportKind};
|
||||||
use crate::late::{PatternSource, Rib};
|
use crate::late::{PatternSource, Rib};
|
||||||
use crate::{
|
use crate::{
|
||||||
AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingError, BindingKey, Finalize,
|
AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingError, BindingKey, Finalize,
|
||||||
HasGenericParams, LexicalScopeBinding, MacroRulesScope, Module, ModuleKind,
|
ForwardGenericParamBanReason, HasGenericParams, LexicalScopeBinding, MacroRulesScope, Module,
|
||||||
ModuleOrUniformRoot, NameBinding, NameBindingKind, ParentScope, PathResult, PrivacyError,
|
ModuleKind, ModuleOrUniformRoot, NameBinding, NameBindingKind, ParentScope, PathResult,
|
||||||
ResolutionError, Resolver, Scope, ScopeSet, Segment, UseError, Used, VisResolutionError,
|
PrivacyError, ResolutionError, Resolver, Scope, ScopeSet, Segment, UseError, Used,
|
||||||
errors as errs, path_names_to_string,
|
VisResolutionError, errors as errs, path_names_to_string,
|
||||||
};
|
};
|
||||||
|
|
||||||
type Res = def::Res<ast::NodeId>;
|
type Res = def::Res<ast::NodeId>;
|
||||||
|
@ -887,9 +887,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
participle,
|
participle,
|
||||||
name,
|
name,
|
||||||
}),
|
}),
|
||||||
ResolutionError::ForwardDeclaredGenericParam => {
|
ResolutionError::ForwardDeclaredGenericParam(param, reason) => match reason {
|
||||||
self.dcx().create_err(errs::ForwardDeclaredGenericParam { span })
|
ForwardGenericParamBanReason::Default => {
|
||||||
}
|
self.dcx().create_err(errs::ForwardDeclaredGenericParam { param, span })
|
||||||
|
}
|
||||||
|
ForwardGenericParamBanReason::ConstParamTy => self
|
||||||
|
.dcx()
|
||||||
|
.create_err(errs::ForwardDeclaredGenericInConstParamTy { param, span }),
|
||||||
|
},
|
||||||
ResolutionError::ParamInTyOfConstParam { name } => {
|
ResolutionError::ParamInTyOfConstParam { name } => {
|
||||||
self.dcx().create_err(errs::ParamInTyOfConstParam { span, name })
|
self.dcx().create_err(errs::ParamInTyOfConstParam { span, name })
|
||||||
}
|
}
|
||||||
|
@ -908,9 +913,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
ResolutionError::ParamInEnumDiscriminant { name, param_kind: is_type } => self
|
ResolutionError::ParamInEnumDiscriminant { name, param_kind: is_type } => self
|
||||||
.dcx()
|
.dcx()
|
||||||
.create_err(errs::ParamInEnumDiscriminant { span, name, param_kind: is_type }),
|
.create_err(errs::ParamInEnumDiscriminant { span, name, param_kind: is_type }),
|
||||||
ResolutionError::SelfInGenericParamDefault => {
|
ResolutionError::ForwardDeclaredSelf(reason) => match reason {
|
||||||
self.dcx().create_err(errs::SelfInGenericParamDefault { span })
|
ForwardGenericParamBanReason::Default => {
|
||||||
}
|
self.dcx().create_err(errs::SelfInGenericParamDefault { span })
|
||||||
|
}
|
||||||
|
ForwardGenericParamBanReason::ConstParamTy => {
|
||||||
|
self.dcx().create_err(errs::SelfInConstGenericTy { span })
|
||||||
|
}
|
||||||
|
},
|
||||||
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {
|
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {
|
||||||
let ((sub_suggestion_label, sub_suggestion), sub_unreachable_label) =
|
let ((sub_suggestion_label, sub_suggestion), sub_unreachable_label) =
|
||||||
match suggestion {
|
match suggestion {
|
||||||
|
|
|
@ -338,6 +338,16 @@ pub(crate) struct ForwardDeclaredGenericParam {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
#[label]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
|
pub(crate) param: Symbol,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(resolve_forward_declared_generic_in_const_param_ty)]
|
||||||
|
pub(crate) struct ForwardDeclaredGenericInConstParamTy {
|
||||||
|
#[primary_span]
|
||||||
|
#[label]
|
||||||
|
pub(crate) span: Span,
|
||||||
|
pub(crate) param: Symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
@ -353,7 +363,13 @@ pub(crate) struct ParamInTyOfConstParam {
|
||||||
#[diag(resolve_self_in_generic_param_default, code = E0735)]
|
#[diag(resolve_self_in_generic_param_default, code = E0735)]
|
||||||
pub(crate) struct SelfInGenericParamDefault {
|
pub(crate) struct SelfInGenericParamDefault {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
#[label]
|
pub(crate) span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(resolve_self_in_const_generic_ty)]
|
||||||
|
pub(crate) struct SelfInConstGenericTy {
|
||||||
|
#[primary_span]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1117,13 +1117,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
debug!("validate_res_from_ribs({:?})", res);
|
debug!("validate_res_from_ribs({:?})", res);
|
||||||
let ribs = &all_ribs[rib_index + 1..];
|
let ribs = &all_ribs[rib_index + 1..];
|
||||||
|
|
||||||
// An invalid forward use of a generic parameter from a previous default.
|
// An invalid forward use of a generic parameter from a previous default
|
||||||
if let RibKind::ForwardGenericParamBan = all_ribs[rib_index].kind {
|
// or in a const param ty.
|
||||||
|
if let RibKind::ForwardGenericParamBan(reason) = all_ribs[rib_index].kind {
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
let res_error = if rib_ident.name == kw::SelfUpper {
|
let res_error = if rib_ident.name == kw::SelfUpper {
|
||||||
ResolutionError::SelfInGenericParamDefault
|
ResolutionError::ForwardDeclaredSelf(reason)
|
||||||
} else {
|
} else {
|
||||||
ResolutionError::ForwardDeclaredGenericParam
|
ResolutionError::ForwardDeclaredGenericParam(rib_ident.name, reason)
|
||||||
};
|
};
|
||||||
self.report_error(span, res_error);
|
self.report_error(span, res_error);
|
||||||
}
|
}
|
||||||
|
@ -1131,17 +1132,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
return Res::Err;
|
return Res::Err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let RibKind::ConstParamTy = all_ribs[rib_index].kind {
|
|
||||||
if let Some(span) = finalize {
|
|
||||||
self.report_error(
|
|
||||||
span,
|
|
||||||
ResolutionError::ParamInTyOfConstParam { name: rib_ident.name },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
assert_eq!(res, Res::Err);
|
|
||||||
return Res::Err;
|
|
||||||
}
|
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
Res::Local(_) => {
|
Res::Local(_) => {
|
||||||
use ResolutionError::*;
|
use ResolutionError::*;
|
||||||
|
@ -1153,7 +1143,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
| RibKind::FnOrCoroutine
|
| RibKind::FnOrCoroutine
|
||||||
| RibKind::Module(..)
|
| RibKind::Module(..)
|
||||||
| RibKind::MacroDefinition(..)
|
| RibKind::MacroDefinition(..)
|
||||||
| RibKind::ForwardGenericParamBan => {
|
| RibKind::ForwardGenericParamBan(_) => {
|
||||||
// Nothing to do. Continue.
|
// Nothing to do. Continue.
|
||||||
}
|
}
|
||||||
RibKind::Item(..) | RibKind::AssocItem => {
|
RibKind::Item(..) | RibKind::AssocItem => {
|
||||||
|
@ -1247,12 +1237,27 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
| RibKind::MacroDefinition(..)
|
| RibKind::MacroDefinition(..)
|
||||||
| RibKind::InlineAsmSym
|
| RibKind::InlineAsmSym
|
||||||
| RibKind::AssocItem
|
| RibKind::AssocItem
|
||||||
| RibKind::ConstParamTy
|
| RibKind::ForwardGenericParamBan(_) => {
|
||||||
| RibKind::ForwardGenericParamBan => {
|
|
||||||
// Nothing to do. Continue.
|
// Nothing to do. Continue.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RibKind::ConstParamTy => {
|
||||||
|
if !self.tcx.features().generic_const_parameter_types() {
|
||||||
|
if let Some(span) = finalize {
|
||||||
|
self.report_error(
|
||||||
|
span,
|
||||||
|
ResolutionError::ParamInTyOfConstParam {
|
||||||
|
name: rib_ident.name,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Res::Err;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RibKind::ConstantItem(trivial, _) => {
|
RibKind::ConstantItem(trivial, _) => {
|
||||||
if let ConstantHasGenerics::No(cause) = trivial {
|
if let ConstantHasGenerics::No(cause) = trivial {
|
||||||
// HACK(min_const_generics): If we encounter `Self` in an anonymous
|
// HACK(min_const_generics): If we encounter `Self` in an anonymous
|
||||||
|
@ -1325,8 +1330,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
| RibKind::MacroDefinition(..)
|
| RibKind::MacroDefinition(..)
|
||||||
| RibKind::InlineAsmSym
|
| RibKind::InlineAsmSym
|
||||||
| RibKind::AssocItem
|
| RibKind::AssocItem
|
||||||
| RibKind::ConstParamTy
|
| RibKind::ForwardGenericParamBan(_) => continue,
|
||||||
| RibKind::ForwardGenericParamBan => continue,
|
|
||||||
|
RibKind::ConstParamTy => {
|
||||||
|
if !self.tcx.features().generic_const_parameter_types() {
|
||||||
|
if let Some(span) = finalize {
|
||||||
|
self.report_error(
|
||||||
|
span,
|
||||||
|
ResolutionError::ParamInTyOfConstParam {
|
||||||
|
name: rib_ident.name,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Res::Err;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RibKind::ConstantItem(trivial, _) => {
|
RibKind::ConstantItem(trivial, _) => {
|
||||||
if let ConstantHasGenerics::No(cause) = trivial {
|
if let ConstantHasGenerics::No(cause) = trivial {
|
||||||
|
@ -1377,6 +1397,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ pub(crate) enum RibKind<'ra> {
|
||||||
/// All bindings in this rib are generic parameters that can't be used
|
/// All bindings in this rib are generic parameters that can't be used
|
||||||
/// from the default of a generic parameter because they're not declared
|
/// from the default of a generic parameter because they're not declared
|
||||||
/// before said generic parameter. Also see the `visit_generics` override.
|
/// before said generic parameter. Also see the `visit_generics` override.
|
||||||
ForwardGenericParamBan,
|
ForwardGenericParamBan(ForwardGenericParamBanReason),
|
||||||
|
|
||||||
/// We are inside of the type of a const parameter. Can't refer to any
|
/// We are inside of the type of a const parameter. Can't refer to any
|
||||||
/// parameters.
|
/// parameters.
|
||||||
|
@ -218,6 +218,12 @@ pub(crate) enum RibKind<'ra> {
|
||||||
InlineAsmSym,
|
InlineAsmSym,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
|
pub(crate) enum ForwardGenericParamBanReason {
|
||||||
|
Default,
|
||||||
|
ConstParamTy,
|
||||||
|
}
|
||||||
|
|
||||||
impl RibKind<'_> {
|
impl RibKind<'_> {
|
||||||
/// Whether this rib kind contains generic parameters, as opposed to local
|
/// Whether this rib kind contains generic parameters, as opposed to local
|
||||||
/// variables.
|
/// variables.
|
||||||
|
@ -232,7 +238,7 @@ impl RibKind<'_> {
|
||||||
RibKind::ConstParamTy
|
RibKind::ConstParamTy
|
||||||
| RibKind::AssocItem
|
| RibKind::AssocItem
|
||||||
| RibKind::Item(..)
|
| RibKind::Item(..)
|
||||||
| RibKind::ForwardGenericParamBan => true,
|
| RibKind::ForwardGenericParamBan(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +252,7 @@ impl RibKind<'_> {
|
||||||
| RibKind::Item(..)
|
| RibKind::Item(..)
|
||||||
| RibKind::ConstantItem(..)
|
| RibKind::ConstantItem(..)
|
||||||
| RibKind::Module(..)
|
| RibKind::Module(..)
|
||||||
| RibKind::ForwardGenericParamBan
|
| RibKind::ForwardGenericParamBan(_)
|
||||||
| RibKind::ConstParamTy
|
| RibKind::ConstParamTy
|
||||||
| RibKind::InlineAsmSym => true,
|
| RibKind::InlineAsmSym => true,
|
||||||
}
|
}
|
||||||
|
@ -1561,8 +1567,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
// provide previous type parameters as they're built. We
|
// provide previous type parameters as they're built. We
|
||||||
// put all the parameters on the ban list and then remove
|
// put all the parameters on the ban list and then remove
|
||||||
// them one by one as they are processed and become available.
|
// them one by one as they are processed and become available.
|
||||||
let mut forward_ty_ban_rib = Rib::new(RibKind::ForwardGenericParamBan);
|
let mut forward_ty_ban_rib =
|
||||||
let mut forward_const_ban_rib = Rib::new(RibKind::ForwardGenericParamBan);
|
Rib::new(RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::Default));
|
||||||
|
let mut forward_const_ban_rib =
|
||||||
|
Rib::new(RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::Default));
|
||||||
for param in params.iter() {
|
for param in params.iter() {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Type { .. } => {
|
GenericParamKind::Type { .. } => {
|
||||||
|
@ -1593,16 +1601,24 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
forward_ty_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err);
|
forward_ty_ban_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), Res::Err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: We use different ribs here not for a technical reason, but just
|
||||||
|
// for better diagnostics.
|
||||||
let mut forward_ty_ban_rib_const_param_ty = Rib {
|
let mut forward_ty_ban_rib_const_param_ty = Rib {
|
||||||
bindings: forward_ty_ban_rib.bindings.clone(),
|
bindings: forward_ty_ban_rib.bindings.clone(),
|
||||||
patterns_with_skipped_bindings: FxHashMap::default(),
|
patterns_with_skipped_bindings: FxHashMap::default(),
|
||||||
kind: RibKind::ConstParamTy,
|
kind: RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::ConstParamTy),
|
||||||
};
|
};
|
||||||
let mut forward_const_ban_rib_const_param_ty = Rib {
|
let mut forward_const_ban_rib_const_param_ty = Rib {
|
||||||
bindings: forward_const_ban_rib.bindings.clone(),
|
bindings: forward_const_ban_rib.bindings.clone(),
|
||||||
patterns_with_skipped_bindings: FxHashMap::default(),
|
patterns_with_skipped_bindings: FxHashMap::default(),
|
||||||
kind: RibKind::ConstParamTy,
|
kind: RibKind::ForwardGenericParamBan(ForwardGenericParamBanReason::ConstParamTy),
|
||||||
};
|
};
|
||||||
|
// We'll ban these with a `ConstParamTy` rib, so just clear these ribs for better
|
||||||
|
// diagnostics, so we don't mention anything about const param tys having generics at all.
|
||||||
|
if !self.r.tcx.features().generic_const_parameter_types() {
|
||||||
|
forward_ty_ban_rib_const_param_ty.bindings.clear();
|
||||||
|
forward_const_ban_rib_const_param_ty.bindings.clear();
|
||||||
|
}
|
||||||
|
|
||||||
self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
|
self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
|
||||||
for param in params {
|
for param in params {
|
||||||
|
@ -1628,9 +1644,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
// Allow all following defaults to refer to this type parameter.
|
// Allow all following defaults to refer to this type parameter.
|
||||||
let i = &Ident::with_dummy_span(param.ident.name);
|
let i = &Ident::with_dummy_span(param.ident.name);
|
||||||
forward_ty_ban_rib.bindings.remove(i);
|
forward_ty_ban_rib.bindings.remove(i);
|
||||||
if this.r.tcx.features().generic_const_parameter_types() {
|
forward_ty_ban_rib_const_param_ty.bindings.remove(i);
|
||||||
forward_ty_ban_rib_const_param_ty.bindings.remove(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
|
GenericParamKind::Const { ref ty, kw_span: _, ref default } => {
|
||||||
// Const parameters can't have param bounds.
|
// Const parameters can't have param bounds.
|
||||||
|
@ -1641,9 +1655,13 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
if this.r.tcx.features().generic_const_parameter_types() {
|
if this.r.tcx.features().generic_const_parameter_types() {
|
||||||
this.visit_ty(ty)
|
this.visit_ty(ty)
|
||||||
} else {
|
} else {
|
||||||
|
this.ribs[TypeNS].push(Rib::new(RibKind::ConstParamTy));
|
||||||
|
this.ribs[ValueNS].push(Rib::new(RibKind::ConstParamTy));
|
||||||
this.with_lifetime_rib(LifetimeRibKind::ConstParamTy, |this| {
|
this.with_lifetime_rib(LifetimeRibKind::ConstParamTy, |this| {
|
||||||
this.visit_ty(ty)
|
this.visit_ty(ty)
|
||||||
});
|
});
|
||||||
|
this.ribs[TypeNS].pop().unwrap();
|
||||||
|
this.ribs[ValueNS].pop().unwrap();
|
||||||
}
|
}
|
||||||
forward_const_ban_rib_const_param_ty = this.ribs[ValueNS].pop().unwrap();
|
forward_const_ban_rib_const_param_ty = this.ribs[ValueNS].pop().unwrap();
|
||||||
forward_ty_ban_rib_const_param_ty = this.ribs[TypeNS].pop().unwrap();
|
forward_ty_ban_rib_const_param_ty = this.ribs[TypeNS].pop().unwrap();
|
||||||
|
@ -1662,9 +1680,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||||
// Allow all following defaults to refer to this const parameter.
|
// Allow all following defaults to refer to this const parameter.
|
||||||
let i = &Ident::with_dummy_span(param.ident.name);
|
let i = &Ident::with_dummy_span(param.ident.name);
|
||||||
forward_const_ban_rib.bindings.remove(i);
|
forward_const_ban_rib.bindings.remove(i);
|
||||||
if this.r.tcx.features().generic_const_parameter_types() {
|
forward_const_ban_rib_const_param_ty.bindings.remove(i);
|
||||||
forward_const_ban_rib_const_param_ty.bindings.remove(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,10 @@ use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
|
||||||
use effective_visibilities::EffectiveVisibilitiesVisitor;
|
use effective_visibilities::EffectiveVisibilitiesVisitor;
|
||||||
use errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
|
use errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
|
||||||
use imports::{Import, ImportData, ImportKind, NameResolution};
|
use imports::{Import, ImportData, ImportKind, NameResolution};
|
||||||
use late::{HasGenericParams, PathSource, PatternSource, UnnecessaryQualification};
|
use late::{
|
||||||
|
ForwardGenericParamBanReason, HasGenericParams, PathSource, PatternSource,
|
||||||
|
UnnecessaryQualification,
|
||||||
|
};
|
||||||
use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
|
use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
|
||||||
use rustc_arena::{DroplessArena, TypedArena};
|
use rustc_arena::{DroplessArena, TypedArena};
|
||||||
use rustc_ast::expand::StrippedCfgItem;
|
use rustc_ast::expand::StrippedCfgItem;
|
||||||
|
@ -273,7 +276,7 @@ enum ResolutionError<'ra> {
|
||||||
shadowed_binding_span: Span,
|
shadowed_binding_span: Span,
|
||||||
},
|
},
|
||||||
/// Error E0128: generic parameters with a default cannot use forward-declared identifiers.
|
/// Error E0128: generic parameters with a default cannot use forward-declared identifiers.
|
||||||
ForwardDeclaredGenericParam,
|
ForwardDeclaredGenericParam(Symbol, ForwardGenericParamBanReason),
|
||||||
// FIXME(generic_const_parameter_types): This should give custom output specifying it's only
|
// FIXME(generic_const_parameter_types): This should give custom output specifying it's only
|
||||||
// problematic to use *forward declared* parameters when the feature is enabled.
|
// problematic to use *forward declared* parameters when the feature is enabled.
|
||||||
/// ERROR E0770: the type of const parameters must not depend on other generic parameters.
|
/// ERROR E0770: the type of const parameters must not depend on other generic parameters.
|
||||||
|
@ -287,7 +290,7 @@ enum ResolutionError<'ra> {
|
||||||
/// This error is emitted even with `generic_const_exprs`.
|
/// This error is emitted even with `generic_const_exprs`.
|
||||||
ParamInEnumDiscriminant { name: Symbol, param_kind: ParamKindInEnumDiscriminant },
|
ParamInEnumDiscriminant { name: Symbol, param_kind: ParamKindInEnumDiscriminant },
|
||||||
/// Error E0735: generic parameters with a default cannot use `Self`
|
/// Error E0735: generic parameters with a default cannot use `Self`
|
||||||
SelfInGenericParamDefault,
|
ForwardDeclaredSelf(ForwardGenericParamBanReason),
|
||||||
/// Error E0767: use of unreachable label
|
/// Error E0767: use of unreachable label
|
||||||
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
UnreachableLabel { name: Symbol, definition_span: Span, suggestion: Option<LabelSuggestion> },
|
||||||
/// Error E0323, E0324, E0325: mismatch between trait item and impl item.
|
/// Error E0323, E0324, E0325: mismatch between trait item and impl item.
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
// We may want to lift this restriction in the future.
|
// We may want to lift this restriction in the future.
|
||||||
|
|
||||||
pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
|
pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
|
||||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
//~^ ERROR the type of const parameters must not depend on other generic parameters
|
||||||
//[min]~^^ ERROR `[u8; N]` is forbidden
|
//[min]~^^ ERROR `[u8; N]` is forbidden as the type of a const generic parameter
|
||||||
|
|
||||||
pub struct SelfDependent<const N: [u8; N]>;
|
pub struct SelfDependent<const N: [u8; N]>;
|
||||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
//~^ ERROR the type of const parameters must not depend on other generic parameters
|
||||||
//[min]~^^ ERROR `[u8; N]` is forbidden
|
//[min]~^^ ERROR `[u8; N]` is forbidden as the type of a const generic parameter
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
#![feature(adt_const_params)]
|
||||||
|
|
||||||
|
trait Trait<const N: usize> {
|
||||||
|
fn foo<const M: [u8; N]>() {}
|
||||||
|
//~^ ERROR the type of const parameters must not depend on other generic parameters
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,9 @@
|
||||||
|
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||||
|
--> $DIR/const-param-type-depends-on-parent-param.rs:4:26
|
||||||
|
|
|
||||||
|
LL | fn foo<const M: [u8; N]>() {}
|
||||||
|
| ^ the type must not depend on the parameter `N`
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0770`.
|
|
@ -2,19 +2,19 @@ error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/default-const-param-cannot-reference-self.rs:1:34
|
--> $DIR/default-const-param-cannot-reference-self.rs:1:34
|
||||||
|
|
|
|
||||||
LL | struct Struct<const N: usize = { Self; 10 }>;
|
LL | struct Struct<const N: usize = { Self; 10 }>;
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error[E0735]: generic parameters cannot use `Self` in their defaults
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/default-const-param-cannot-reference-self.rs:4:30
|
--> $DIR/default-const-param-cannot-reference-self.rs:4:30
|
||||||
|
|
|
|
||||||
LL | enum Enum<const N: usize = { Self; 10 }> { }
|
LL | enum Enum<const N: usize = { Self; 10 }> { }
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error[E0735]: generic parameters cannot use `Self` in their defaults
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/default-const-param-cannot-reference-self.rs:7:32
|
--> $DIR/default-const-param-cannot-reference-self.rs:7:32
|
||||||
|
|
|
|
||||||
LL | union Union<const N: usize = { Self; 10 }> { not_empty: () }
|
LL | union Union<const N: usize = { Self; 10 }> { not_empty: () }
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
struct Foo<const N: usize = M, const M: usize = 10>;
|
struct Foo<const N: usize = M, const M: usize = 10>;
|
||||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
//~^ ERROR generic parameter defaults cannot reference parameters before they are declared
|
||||||
|
|
||||||
enum Bar<const N: usize = M, const M: usize = 10> {}
|
enum Bar<const N: usize = M, const M: usize = 10> {}
|
||||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
//~^ ERROR generic parameter defaults cannot reference parameters before they are declared
|
||||||
|
|
||||||
struct Foo2<const N: usize = N>;
|
struct Foo2<const N: usize = N>;
|
||||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
//~^ ERROR generic parameter defaults cannot reference parameters before they are declared
|
||||||
|
|
||||||
enum Bar2<const N: usize = N> {}
|
enum Bar2<const N: usize = N> {}
|
||||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
//~^ ERROR generic parameter defaults cannot reference parameters before they are declared
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/forward-declared.rs:1:29
|
--> $DIR/forward-declared.rs:1:29
|
||||||
|
|
|
|
||||||
LL | struct Foo<const N: usize = M, const M: usize = 10>;
|
LL | struct Foo<const N: usize = M, const M: usize = 10>;
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `M` before it is declared
|
||||||
|
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/forward-declared.rs:4:27
|
--> $DIR/forward-declared.rs:4:27
|
||||||
|
|
|
|
||||||
LL | enum Bar<const N: usize = M, const M: usize = 10> {}
|
LL | enum Bar<const N: usize = M, const M: usize = 10> {}
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `M` before it is declared
|
||||||
|
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/forward-declared.rs:7:30
|
--> $DIR/forward-declared.rs:7:30
|
||||||
|
|
|
|
||||||
LL | struct Foo2<const N: usize = N>;
|
LL | struct Foo2<const N: usize = N>;
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `N` before it is declared
|
||||||
|
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/forward-declared.rs:10:28
|
--> $DIR/forward-declared.rs:10:28
|
||||||
|
|
|
|
||||||
LL | enum Bar2<const N: usize = N> {}
|
LL | enum Bar2<const N: usize = N> {}
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `N` before it is declared
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
struct UsesConst<const N: [u8; M], const M: usize>;
|
struct UsesConst<const N: [u8; M], const M: usize>;
|
||||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
//~^ ERROR: const parameter types cannot reference parameters before they are declared
|
||||||
struct UsesType<const N: [T; 2], T>(PhantomData<T>);
|
struct UsesType<const N: [T; 2], T>(PhantomData<T>);
|
||||||
//~^ ERROR: the type of const parameters must not depend on other generic parameters
|
//~^ ERROR: const parameter types cannot reference parameters before they are declared
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
error: const parameter types cannot reference parameters before they are declared
|
||||||
--> $DIR/forward_declared_type.rs:6:32
|
--> $DIR/forward_declared_type.rs:6:32
|
||||||
|
|
|
|
||||||
LL | struct UsesConst<const N: [u8; M], const M: usize>;
|
LL | struct UsesConst<const N: [u8; M], const M: usize>;
|
||||||
| ^ the type must not depend on the parameter `M`
|
| ^ const parameter type cannot reference `M` before it is declared
|
||||||
|
|
||||||
error[E0770]: the type of const parameters must not depend on other generic parameters
|
error: const parameter types cannot reference parameters before they are declared
|
||||||
--> $DIR/forward_declared_type.rs:8:27
|
--> $DIR/forward_declared_type.rs:8:27
|
||||||
|
|
|
|
||||||
LL | struct UsesType<const N: [T; 2], T>(PhantomData<T>);
|
LL | struct UsesType<const N: [T; 2], T>(PhantomData<T>);
|
||||||
| ^ the type must not depend on the parameter `T`
|
| ^ const parameter type cannot reference `T` before it is declared
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0770`.
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ LL | type Assoc<const N: Self>;
|
||||||
= note: the only supported types are integers, `bool`, and `char`
|
= note: the only supported types are integers, `bool`, and `char`
|
||||||
|
|
||||||
error: anonymous constants referencing generics are not yet supported
|
error: anonymous constants referencing generics are not yet supported
|
||||||
--> $DIR/references-parent-generics.rs:14:21
|
--> $DIR/references-parent-generics.rs:15:21
|
||||||
|
|
|
|
||||||
LL | let x: T::Assoc<3>;
|
LL | let x: T::Assoc<3>;
|
||||||
| ^
|
| ^
|
||||||
|
|
|
@ -1,16 +1,9 @@
|
||||||
error: `Self` is forbidden as the type of a const generic parameter
|
error[E0770]: the type of const parameters must not depend on other generic parameters
|
||||||
--> $DIR/references-parent-generics.rs:7:25
|
--> $DIR/references-parent-generics.rs:7:25
|
||||||
|
|
|
|
||||||
LL | type Assoc<const N: Self>;
|
LL | type Assoc<const N: Self>;
|
||||||
| ^^^^
|
| ^^^^ the type must not depend on the parameter `Self`
|
||||||
|
|
|
||||||
= note: the only supported types are integers, `bool`, and `char`
|
|
||||||
|
|
||||||
error: anonymous constants referencing generics are not yet supported
|
error: aborting due to 1 previous error
|
||||||
--> $DIR/references-parent-generics.rs:14:21
|
|
||||||
|
|
|
||||||
LL | let x: T::Assoc<3>;
|
|
||||||
| ^
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0770`.
|
||||||
|
|
|
@ -5,14 +5,15 @@
|
||||||
|
|
||||||
trait Foo {
|
trait Foo {
|
||||||
type Assoc<const N: Self>;
|
type Assoc<const N: Self>;
|
||||||
//~^ ERROR `Self` is forbidden as the type of a const generic parameter
|
//[nofeat]~^ ERROR the type of const parameters must not depend on other generic parameters
|
||||||
|
//[feat]~^^ ERROR `Self` is forbidden as the type of a const generic parameter
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo<T: Foo>() {
|
fn foo<T: Foo>() {
|
||||||
// We used to end up feeding the type of this anon const to be `T`, but the anon const
|
// We used to end up feeding the type of this anon const to be `T`, but the anon const
|
||||||
// doesn't inherit the generics of `foo`, which led to index oob errors.
|
// doesn't inherit the generics of `foo`, which led to index oob errors.
|
||||||
let x: T::Assoc<3>;
|
let x: T::Assoc<3>;
|
||||||
//~^ ERROR anonymous constants referencing generics are not yet supported
|
//[feat]~^ ERROR anonymous constants referencing generics are not yet supported
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -4,11 +4,11 @@ error: generic parameters with a default must be trailing
|
||||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21
|
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21
|
||||||
|
|
|
|
||||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `N` before it is declared
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ LL | struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
|
||||||
= note: type parameters may not be used in const expressions
|
= note: type parameters may not be used in const expressions
|
||||||
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
= help: add `#![feature(generic_const_exprs)]` to allow generic const expressions
|
||||||
|
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21
|
--> $DIR/params-in-ct-in-ty-param-lazy-norm.rs:8:21
|
||||||
|
|
|
|
||||||
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
LL | struct Bar<T = [u8; N], const N: usize>(T);
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `N` before it is declared
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ struct Foo<T, U = [u8; std::mem::size_of::<T>()]>(T, U);
|
||||||
//[min]~^ ERROR generic parameters may not be used in const operations
|
//[min]~^ ERROR generic parameters may not be used in const operations
|
||||||
|
|
||||||
struct Bar<T = [u8; N], const N: usize>(T);
|
struct Bar<T = [u8; N], const N: usize>(T);
|
||||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
//~^ ERROR generic parameter defaults cannot reference parameters before they are declared
|
||||||
//~| ERROR generic parameters with a default
|
//~| ERROR generic parameters with a default
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/E0128.rs:1:14
|
--> $DIR/E0128.rs:1:14
|
||||||
|
|
|
|
||||||
LL | struct Foo<T=U, U=()> {
|
LL | struct Foo<T=U, U=()> {
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `U` before it is declared
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,6 @@ struct Vec<A = Heap, T>(A, T);
|
||||||
|
|
||||||
struct Foo<A, B = Vec<C>, C>(A, B, C);
|
struct Foo<A, B = Vec<C>, C>(A, B, C);
|
||||||
//~^ ERROR generic parameters with a default must be trailing
|
//~^ ERROR generic parameters with a default must be trailing
|
||||||
//~| ERROR generic parameters with a default cannot use
|
//~| ERROR generic parameter defaults cannot reference parameters before they are declared
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -10,11 +10,11 @@ error: generic parameters with a default must be trailing
|
||||||
LL | struct Foo<A, B = Vec<C>, C>(A, B, C);
|
LL | struct Foo<A, B = Vec<C>, C>(A, B, C);
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/generic-non-trailing-defaults.rs:6:23
|
--> $DIR/generic-non-trailing-defaults.rs:6:23
|
||||||
|
|
|
|
||||||
LL | struct Foo<A, B = Vec<C>, C>(A, B, C);
|
LL | struct Foo<A, B = Vec<C>, C>(A, B, C);
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `C` before it is declared
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Ensure that we get an error and not an ICE for this problematic case.
|
// Ensure that we get an error and not an ICE for this problematic case.
|
||||||
struct Foo<T = Option<U>, U = bool>(T, U);
|
struct Foo<T = Option<U>, U = bool>(T, U);
|
||||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
//~^ ERROR generic parameter defaults cannot reference parameters before they are declared
|
||||||
fn main() {
|
fn main() {
|
||||||
let x: Foo;
|
let x: Foo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/generic-type-params-forward-mention.rs:2:23
|
--> $DIR/generic-type-params-forward-mention.rs:2:23
|
||||||
|
|
|
|
||||||
LL | struct Foo<T = Option<U>, U = bool>(T, U);
|
LL | struct Foo<T = Option<U>, U = bool>(T, U);
|
||||||
| ^ defaulted generic parameters cannot be forward declared
|
| ^ cannot reference `U` before it is declared
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -2,37 +2,37 @@ error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:13:25
|
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:13:25
|
||||||
|
|
|
|
||||||
LL | struct Snobound<'a, P = Self> { x: Option<&'a P> }
|
LL | struct Snobound<'a, P = Self> { x: Option<&'a P> }
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error[E0735]: generic parameters cannot use `Self` in their defaults
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:16:23
|
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:16:23
|
||||||
|
|
|
|
||||||
LL | enum Enobound<'a, P = Self> { A, B(Option<&'a P>) }
|
LL | enum Enobound<'a, P = Self> { A, B(Option<&'a P>) }
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error[E0735]: generic parameters cannot use `Self` in their defaults
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:19:24
|
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:19:24
|
||||||
|
|
|
|
||||||
LL | union Unobound<'a, P = Self> { x: i32, y: Option<&'a P> }
|
LL | union Unobound<'a, P = Self> { x: i32, y: Option<&'a P> }
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error[E0735]: generic parameters cannot use `Self` in their defaults
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:25:31
|
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:25:31
|
||||||
|
|
|
|
||||||
LL | struct Ssized<'a, P: Sized = [Self]> { x: Option<&'a P> }
|
LL | struct Ssized<'a, P: Sized = [Self]> { x: Option<&'a P> }
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error[E0735]: generic parameters cannot use `Self` in their defaults
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:28:29
|
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:28:29
|
||||||
|
|
|
|
||||||
LL | enum Esized<'a, P: Sized = [Self]> { A, B(Option<&'a P>) }
|
LL | enum Esized<'a, P: Sized = [Self]> { A, B(Option<&'a P>) }
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error[E0735]: generic parameters cannot use `Self` in their defaults
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:31:30
|
--> $DIR/issue-61631-default-type-param-cannot-reference-self.rs:31:30
|
||||||
|
|
|
|
||||||
LL | union Usized<'a, P: Sized = [Self]> { x: i32, y: Option<&'a P> }
|
LL | union Usized<'a, P: Sized = [Self]> { x: i32, y: Option<&'a P> }
|
||||||
| ^^^^ `Self` in generic parameter default
|
| ^^^^
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/issue-18183.rs:1:20
|
--> $DIR/issue-18183.rs:1:20
|
||||||
|
|
|
|
||||||
LL | pub struct Foo<Bar=Bar>(Bar);
|
LL | pub struct Foo<Bar=Bar>(Bar);
|
||||||
| ^^^ defaulted generic parameters cannot be forward declared
|
| ^^^ cannot reference `Bar` before it is declared
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn avg<T=T::Item>(_: T) {}
|
fn avg<T=T::Item>(_: T) {}
|
||||||
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
|
//~^ ERROR generic parameter defaults cannot reference parameters before they are declared
|
||||||
//~| ERROR defaults for type parameters
|
//~| ERROR defaults for type parameters
|
||||||
//~| WARN previously accepted
|
//~| WARN previously accepted
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0128]: generic parameters with a default cannot use forward declared identifiers
|
error[E0128]: generic parameter defaults cannot reference parameters before they are declared
|
||||||
--> $DIR/issue-26812.rs:1:10
|
--> $DIR/issue-26812.rs:1:10
|
||||||
|
|
|
|
||||||
LL | fn avg<T=T::Item>(_: T) {}
|
LL | fn avg<T=T::Item>(_: T) {}
|
||||||
| ^^^^^^^ defaulted generic parameters cannot be forward declared
|
| ^^^^^^^ cannot reference `T` before it is declared
|
||||||
|
|
||||||
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
||||||
--> $DIR/issue-26812.rs:1:8
|
--> $DIR/issue-26812.rs:1:8
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue