From da189d95146fb6c567aef10f1be400dfd9f43862 Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 14 Jul 2021 19:22:32 +0100 Subject: [PATCH 1/2] Change type param -> generic param --- compiler/rustc_resolve/src/diagnostics.rs | 6 ++--- compiler/rustc_resolve/src/lib.rs | 4 ++-- ...fault-const-param-cannot-reference-self.rs | 16 +++++++++++++ ...t-const-param-cannot-reference-self.stderr | 21 ++++++++++++++++ ...efault-type-param-cannot-reference-self.rs | 12 +++++----- ...lt-type-param-cannot-reference-self.stderr | 24 +++++++++---------- 6 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs create mode 100644 src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 03d94f43897ba..7439cd9a0fe3d 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -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 } => { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 4d12415215194..fb2eb749e118f 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -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 }, } @@ -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 }; diff --git a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs new file mode 100644 index 0000000000000..9af84439252c7 --- /dev/null +++ b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.rs @@ -0,0 +1,16 @@ +#![feature(const_generics_defaults)] + +struct Struct; +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] + +enum Enum { } +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] + +union Union { not_empty: () } +//~^ ERROR generic parameters cannot use `Self` in their defaults [E0735] + +fn main() { + let _: Struct; + let _: Enum; + let _: Union; +} diff --git a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr new file mode 100644 index 0000000000000..3cc56e51807bd --- /dev/null +++ b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr @@ -0,0 +1,21 @@ +error[E0735]: generic parameters cannot use `Self` in their defaults + --> $DIR/default-const-param-cannot-reference-self.rs:3:36 + | +LL | struct Snobound; + | ^^^^ `Self` in generic parameter default + +error[E0735]: generic parameters cannot use `Self` in their defaults + --> $DIR/default-const-param-cannot-reference-self.rs:6:34 + | +LL | enum Enobound { } + | ^^^^ `Self` in generic parameter default + +error[E0735]: generic parameters cannot use `Self` in their defaults + --> $DIR/default-const-param-cannot-reference-self.rs:9:35 + | +LL | union Unobound { not_empty: () } + | ^^^^ `Self` in generic parameter default + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0735`. diff --git a/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs b/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs index b560cc2ce7060..12db143e47449 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs +++ b/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.rs @@ -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 diff --git a/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.stderr b/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.stderr index 689ffbd0febc2..f3a550801b9bd 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.stderr +++ b/src/test/ui/generics/issue-61631-default-type-param-cannot-reference-self.stderr @@ -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 From b3b6b66815ed20531a7a32e9c400a8d40692f9bf Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 14 Jul 2021 19:38:58 +0100 Subject: [PATCH 2/2] OOPS --- ...lt-const-param-cannot-reference-self.stderr | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr index 3cc56e51807bd..5dfec2fcb736f 100644 --- a/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr +++ b/src/test/ui/const-generics/defaults/default-const-param-cannot-reference-self.stderr @@ -1,20 +1,20 @@ error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:3:36 + --> $DIR/default-const-param-cannot-reference-self.rs:3:34 | -LL | struct Snobound; - | ^^^^ `Self` in generic parameter default +LL | struct Struct; + | ^^^^ `Self` in generic parameter default error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:6:34 + --> $DIR/default-const-param-cannot-reference-self.rs:6:30 | -LL | enum Enobound { } - | ^^^^ `Self` in generic parameter default +LL | enum Enum { } + | ^^^^ `Self` in generic parameter default error[E0735]: generic parameters cannot use `Self` in their defaults - --> $DIR/default-const-param-cannot-reference-self.rs:9:35 + --> $DIR/default-const-param-cannot-reference-self.rs:9:32 | -LL | union Unobound { not_empty: () } - | ^^^^ `Self` in generic parameter default +LL | union Union { not_empty: () } + | ^^^^ `Self` in generic parameter default error: aborting due to 3 previous errors