From 929a64fd4c1ba210f47be6e10e28c43cf440f9fe Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Thu, 31 Dec 2020 13:52:39 +0100 Subject: [PATCH 1/7] Improve library tracking issue template --- .../ISSUE_TEMPLATE/library_tracking_issue.md | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/library_tracking_issue.md b/.github/ISSUE_TEMPLATE/library_tracking_issue.md index 3e42594c8280d..cbc4465fcfe38 100644 --- a/.github/ISSUE_TEMPLATE/library_tracking_issue.md +++ b/.github/ISSUE_TEMPLATE/library_tracking_issue.md @@ -33,21 +33,41 @@ For most library features, it'd be useful to include a summarized version of the --> ```rust -... +// core::magic + +pub struct Magic; + +impl Magic { + pub fn magic(self); +} ``` ### Steps / History -- [ ] Implementation: ... +- [ ] Implementation: #... +- [ ] Final commenting period (FCP) - [ ] Stabilization PR + + ### Unresolved Questions $DIR/issue-80607.rs:7:16 + | +LL | V1(i32), + | -- `Enum` defined here +... +LL | Enum::V1 { x } + | -------- ^ field does not exist + | | + | `Enum` is a tuple variant, use the appropriate syntax: `Enum(/* fields */)` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0559`. From e0300716efc88a0b11f7121f8a15f5f385265b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sat, 2 Jan 2021 11:06:30 +0100 Subject: [PATCH 7/7] Print actual enum variant --- compiler/rustc_typeck/src/check/expr.rs | 49 ++++++++++++++++++------- src/test/ui/issues/issue-80607.rs | 2 +- src/test/ui/issues/issue-80607.stderr | 4 +- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 8197d02ec594b..e84d813ffbcc0 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1381,19 +1381,42 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty, ); match variant.ctor_kind { - CtorKind::Fn => { - err.span_label(variant.ident.span, format!("`{adt}` defined here", adt = ty)); - err.span_label(field.ident.span, "field does not exist"); - err.span_label( - ty_span, - format!( - "`{adt}` is a tuple {kind_name}, \ - use the appropriate syntax: `{adt}(/* fields */)`", - adt = ty, - kind_name = kind_name - ), - ); - } + CtorKind::Fn => match ty.kind() { + ty::Adt(adt, ..) if adt.is_enum() => { + err.span_label( + variant.ident.span, + format!( + "`{adt}::{variant}` defined here", + adt = ty, + variant = variant.ident, + ), + ); + err.span_label(field.ident.span, "field does not exist"); + err.span_label( + ty_span, + format!( + "`{adt}::{variant}` is a tuple {kind_name}, \ + use the appropriate syntax: `{adt}::{variant}(/* fields */)`", + adt = ty, + variant = variant.ident, + kind_name = kind_name + ), + ); + } + _ => { + err.span_label(variant.ident.span, format!("`{adt}` defined here", adt = ty)); + err.span_label(field.ident.span, "field does not exist"); + err.span_label( + ty_span, + format!( + "`{adt}` is a tuple {kind_name}, \ + use the appropriate syntax: `{adt}(/* fields */)`", + adt = ty, + kind_name = kind_name + ), + ); + } + }, _ => { // prevent all specified fields from being suggested let skip_fields = skip_fields.iter().map(|ref x| x.ident.name); diff --git a/src/test/ui/issues/issue-80607.rs b/src/test/ui/issues/issue-80607.rs index 8bfda9a5c54b2..63f4df359b831 100644 --- a/src/test/ui/issues/issue-80607.rs +++ b/src/test/ui/issues/issue-80607.rs @@ -4,7 +4,7 @@ pub enum Enum { } pub fn foo(x: i32) -> Enum { - Enum::V1 { x } //~ ERROR field does not exist + Enum::V1 { x } //~ ERROR `Enum::V1` has no field named `x` } fn main() {} diff --git a/src/test/ui/issues/issue-80607.stderr b/src/test/ui/issues/issue-80607.stderr index cd405815c70df..5375478942b18 100644 --- a/src/test/ui/issues/issue-80607.stderr +++ b/src/test/ui/issues/issue-80607.stderr @@ -2,12 +2,12 @@ error[E0559]: variant `Enum::V1` has no field named `x` --> $DIR/issue-80607.rs:7:16 | LL | V1(i32), - | -- `Enum` defined here + | -- `Enum::V1` defined here ... LL | Enum::V1 { x } | -------- ^ field does not exist | | - | `Enum` is a tuple variant, use the appropriate syntax: `Enum(/* fields */)` + | `Enum::V1` is a tuple variant, use the appropriate syntax: `Enum::V1(/* fields */)` error: aborting due to previous error