Rollup merge of #87134 - BoxyUwU:cgd-self-ty-error, r=lcnr
Make SelfInTyParamDefault wording not be specific to type defaults r? ```@lcnr```
This commit is contained in:
commit
6d0d80e181
6 changed files with 60 additions and 23 deletions
|
@ -502,14 +502,14 @@ impl<'a> Resolver<'a> {
|
||||||
|
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
ResolutionError::SelfInTyParamDefault => {
|
ResolutionError::SelfInGenericParamDefault => {
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.session,
|
self.session,
|
||||||
span,
|
span,
|
||||||
E0735,
|
E0735,
|
||||||
"type parameters cannot use `Self` in their defaults"
|
"generic parameters cannot use `Self` in their defaults"
|
||||||
);
|
);
|
||||||
err.span_label(span, "`Self` in type parameter default".to_string());
|
err.span_label(span, "`Self` in generic parameter default".to_string());
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {
|
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {
|
||||||
|
|
|
@ -249,7 +249,7 @@ enum ResolutionError<'a> {
|
||||||
/// This error is only emitted when using `min_const_generics`.
|
/// This error is only emitted when using `min_const_generics`.
|
||||||
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },
|
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },
|
||||||
/// Error E0735: generic parameters with a default cannot use `Self`
|
/// Error E0735: generic parameters with a default cannot use `Self`
|
||||||
SelfInTyParamDefault,
|
SelfInGenericParamDefault,
|
||||||
/// 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> },
|
||||||
}
|
}
|
||||||
|
@ -2643,7 +2643,7 @@ impl<'a> Resolver<'a> {
|
||||||
if let ForwardGenericParamBanRibKind = all_ribs[rib_index].kind {
|
if let ForwardGenericParamBanRibKind = all_ribs[rib_index].kind {
|
||||||
if record_used {
|
if record_used {
|
||||||
let res_error = if rib_ident.name == kw::SelfUpper {
|
let res_error = if rib_ident.name == kw::SelfUpper {
|
||||||
ResolutionError::SelfInTyParamDefault
|
ResolutionError::SelfInGenericParamDefault
|
||||||
} else {
|
} else {
|
||||||
ResolutionError::ForwardDeclaredGenericParam
|
ResolutionError::ForwardDeclaredGenericParam
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
#![feature(const_generics_defaults)]
|
||||||
|
|
||||||
|
struct Struct<const N: usize = { Self; 10 }>;
|
||||||
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
|
enum Enum<const N: usize = { Self; 10 }> { }
|
||||||
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
|
union Union<const N: usize = { Self; 10 }> { not_empty: () }
|
||||||
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _: Struct;
|
||||||
|
let _: Enum;
|
||||||
|
let _: Union;
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
|
--> $DIR/default-const-param-cannot-reference-self.rs:3:34
|
||||||
|
|
|
||||||
|
LL | struct Struct<const N: usize = { Self; 10 }>;
|
||||||
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
|
--> $DIR/default-const-param-cannot-reference-self.rs:6:30
|
||||||
|
|
|
||||||
|
LL | enum Enum<const N: usize = { Self; 10 }> { }
|
||||||
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
|
error[E0735]: generic parameters cannot use `Self` in their defaults
|
||||||
|
--> $DIR/default-const-param-cannot-reference-self.rs:9:32
|
||||||
|
|
|
||||||
|
LL | union Union<const N: usize = { Self; 10 }> { not_empty: () }
|
||||||
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0735`.
|
|
@ -11,25 +11,25 @@
|
||||||
// compatibility concern.
|
// compatibility concern.
|
||||||
|
|
||||||
struct Snobound<'a, P = Self> { x: Option<&'a P> }
|
struct Snobound<'a, P = Self> { x: Option<&'a P> }
|
||||||
//~^ ERROR type parameters cannot use `Self` in their defaults [E0735]
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
enum Enobound<'a, P = Self> { A, B(Option<&'a P>) }
|
enum Enobound<'a, P = Self> { A, B(Option<&'a P>) }
|
||||||
//~^ ERROR type parameters cannot use `Self` in their defaults [E0735]
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
union Unobound<'a, P = Self> { x: i32, y: Option<&'a P> }
|
union Unobound<'a, P = Self> { x: i32, y: Option<&'a P> }
|
||||||
//~^ ERROR type parameters cannot use `Self` in their defaults [E0735]
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
// Disallowing `Self` in defaults sidesteps need to check the bounds
|
// Disallowing `Self` in defaults sidesteps need to check the bounds
|
||||||
// on the defaults in cases like these.
|
// on the defaults in cases like these.
|
||||||
|
|
||||||
struct Ssized<'a, P: Sized = [Self]> { x: Option<&'a P> }
|
struct Ssized<'a, P: Sized = [Self]> { x: Option<&'a P> }
|
||||||
//~^ ERROR type parameters cannot use `Self` in their defaults [E0735]
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
enum Esized<'a, P: Sized = [Self]> { A, B(Option<&'a P>) }
|
enum Esized<'a, P: Sized = [Self]> { A, B(Option<&'a P>) }
|
||||||
//~^ ERROR type parameters cannot use `Self` in their defaults [E0735]
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
union Usized<'a, P: Sized = [Self]> { x: i32, y: Option<&'a P> }
|
union Usized<'a, P: Sized = [Self]> { x: i32, y: Option<&'a P> }
|
||||||
//~^ ERROR type parameters cannot use `Self` in their defaults [E0735]
|
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
|
||||||
|
|
||||||
fn demo_usages() {
|
fn demo_usages() {
|
||||||
// An ICE means you only get the error from the first line of the
|
// An ICE means you only get the error from the first line of the
|
||||||
|
|
|
@ -1,38 +1,38 @@
|
||||||
error[E0735]: type 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: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 type parameter default
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
error[E0735]: type 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 type parameter default
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
error[E0735]: type 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 type parameter default
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
error[E0735]: type 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 type parameter default
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
error[E0735]: type 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 type parameter default
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
error[E0735]: type 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 type parameter default
|
| ^^^^ `Self` in generic parameter default
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue