Skip to content

Commit

Permalink
Rollup merge of rust-lang#87134 - BoxyUwU:cgd-self-ty-error, r=lcnr
Browse files Browse the repository at this point in the history
Make SelfInTyParamDefault wording not be specific to type defaults

r? ``@lcnr``
  • Loading branch information
JohnTitor authored Jul 15, 2021
2 parents 63db307 + b3b6b66 commit 50eeef4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 23 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> },
}
Expand Down Expand Up @@ -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
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 50eeef4

Please sign in to comment.