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:
Yuki Okushi 2021-07-15 21:19:20 +09:00 committed by GitHub
commit 6d0d80e181
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 23 deletions

View File

@ -502,14 +502,14 @@ impl<'a> Resolver<'a> {
err
}
ResolutionError::SelfInTyParamDefault => {
ResolutionError::SelfInGenericParamDefault => {
let mut err = struct_span_err!(
self.session,
span,
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
}
ResolutionError::UnreachableLabel { name, definition_span, suggestion } => {

View File

@ -249,7 +249,7 @@ enum ResolutionError<'a> {
/// This error is only emitted when using `min_const_generics`.
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },
/// Error E0735: generic parameters with a default cannot use `Self`
SelfInTyParamDefault,
SelfInGenericParamDefault,
/// Error E0767: use of unreachable label
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 record_used {
let res_error = if rib_ident.name == kw::SelfUpper {
ResolutionError::SelfInTyParamDefault
ResolutionError::SelfInGenericParamDefault
} else {
ResolutionError::ForwardDeclaredGenericParam
};

View File

@ -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;
}

View File

@ -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`.

View File

@ -11,25 +11,25 @@
// compatibility concern.
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>) }
//~^ 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> }
//~^ 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
// on the defaults in cases like these.
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>) }
//~^ 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> }
//~^ ERROR type parameters cannot use `Self` in their defaults [E0735]
//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735]
fn demo_usages() {
// An ICE means you only get the error from the first line of the

View File

@ -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
|
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
|
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
|
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
|
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
|
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
|
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