diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index 165051744641f..142c10677f005 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -1625,7 +1625,7 @@ pub(crate) fn fn_trait_to_string( } } -/// Used for generics args error extend. +/// Extra information for diagnostics of generics args error. pub enum GenericsArgsErrExtend<'tcx> { EnumVariant { qself: &'tcx hir::Ty<'tcx>, @@ -1652,87 +1652,65 @@ fn generics_args_err_extend<'a>( ) { match err_extend { GenericsArgsErrExtend::EnumVariant { qself, assoc_segment, adt_def } => { - err.note("enum variants can't have type parameters"); + err.note("variants of type-aliased enum can't have type parameters"); let type_name = tcx.item_name(adt_def.did()); - let msg = format!( - "you might have meant to specify type parameters on enum \ - `{type_name}`" - ); - let Some(args) = assoc_segment.args else { + let Some(variant_args) = assoc_segment.args else { return; }; // Get the span of the generics args *including* the leading `::`. // We do so by stretching args.span_ext to the left by 2. Earlier // it was done based on the end of assoc segment but that sometimes // led to impossible spans and caused issues like #116473 - let args_span = args.span_ext.with_lo(args.span_ext.lo() - BytePos(2)); + let variant_args_span = + variant_args.span_ext.with_lo(variant_args.span_ext.lo() - BytePos(2)); if tcx.generics_of(adt_def.did()).is_empty() { // FIXME(estebank): we could also verify that the arguments being // work for the `enum`, instead of just looking if it takes *any*. err.span_suggestion_verbose( - args_span, + variant_args_span, format!("{type_name} doesn't have generic parameters"), "", Applicability::MachineApplicable, ); return; } - let Ok(snippet) = tcx.sess.source_map().span_to_snippet(args_span) else { + let msg = "you might have meant to specify type parameters on the enum"; + let Ok(snippet) = tcx.sess.source_map().span_to_snippet(variant_args_span) else { + err.note(msg); + return; + }; + // If the path segment already has type params, we want to overwrite them. + let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = &qself.kind else { + err.note(msg); + return; + }; + // The last element of `path.segments` is the previous to last element + // on the path and would normally be the enum alias itself. + let Some(hir::PathSegment { + ident, + args: enum_args, + res: Res::SelfTyAlias { .. } | Res::Def(DefKind::TyAlias, _), + .. + }) = &path.segments.last() + else { err.note(msg); return; }; - let (qself_sugg_span, is_self) = - if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = &qself.kind { - // If the path segment already has type params, we want to overwrite - // them. - match &path.segments { - // `segment` is the previous to last element on the path, - // which would normally be the `enum` itself, while the last - // `_` `PathSegment` corresponds to the variant. - [ - .., - hir::PathSegment { - ident, args, res: Res::Def(DefKind::Enum, _), .. - }, - _, - ] => ( - // We need to include the `::` in `Type::Variant::` - // to point the span to `::`, not just ``. - ident - .span - .shrink_to_hi() - .to(args.map_or(ident.span.shrink_to_hi(), |a| a.span_ext)), - false, - ), - [segment] => { - ( - // We need to include the `::` in `Type::Variant::` - // to point the span to `::`, not just ``. - segment.ident.span.shrink_to_hi().to(segment - .args - .map_or(segment.ident.span.shrink_to_hi(), |a| a.span_ext)), - kw::SelfUpper == segment.ident.name, - ) - } - _ => { - err.note(msg); - return; - } - } - } else { - err.note(msg); - return; - }; let suggestion = vec![ - if is_self { + if path.segments.len() == 1 && kw::SelfUpper == ident.name { // Account for people writing `Self::Variant::`, where // `Self` is the enum, and suggest replacing `Self` with the // appropriate type: `Type::::Variant`. (qself.span, format!("{type_name}{snippet}")) } else { - (qself_sugg_span, snippet) + // We need to include the `::` in `Type::::Variants` + // to point the span to `::`, not just ``. + let enum_args_span = ident.span.shrink_to_hi().to(enum_args + .and_then(|a| a.span_ext()) + .unwrap_or(ident.span.shrink_to_hi())); + (enum_args_span, snippet) }, - (args_span, String::new()), + (variant_args_span, String::new()), ]; err.multipart_suggestion_verbose(msg, suggestion, Applicability::MaybeIncorrect); } diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 7f5397a7926da..4a82b54607171 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -422,10 +422,10 @@ fn report_unexpected_variant_res( let mut suggestion = vec![]; match tcx.parent_hir_node(expr.hir_id) { hir::Node::Expr(hir::Expr { - kind: hir::ExprKind::Call(..), + kind: hir::ExprKind::Call(callee, ..), span: call_span, .. - }) => { + }) if callee.hir_id == expr.hir_id => { suggestion.push((span.shrink_to_hi().with_hi(call_span.hi()), sugg)); } hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Binary(..), hir_id, .. }) => { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 024b9ee08c222..d4bc051e695aa 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1592,13 +1592,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let hir::Node::Stmt(&hir::Stmt { kind: hir::StmtKind::Semi(parent), .. }) | hir::Node::Expr(parent) = self.tcx.parent_hir_node(path_expr.hir_id) { - let replacement_span = - if let hir::ExprKind::Call(..) | hir::ExprKind::Struct(..) = parent.kind { - // We want to replace the parts that need to go, like `()` and `{}`. - span.with_hi(parent.span.hi()) - } else { - span - }; + // We want to also replace variant constructor part like `()` and `{}`. + let replacement_span = match parent.kind { + hir::ExprKind::Call(callee, ..) if callee.hir_id == path_expr.hir_id => { + if span.hi() == callee.span.hi() { + span.with_hi(parent.span.hi()) + } else { + // Bail if there are parens around the variant like `(A::B)()` + span + } + } + hir::ExprKind::Struct(..) => span.with_hi(parent.span.hi()), + _ => span, + }; match (variant.ctor, parent.kind) { (None, hir::ExprKind::Struct(..)) => { // We want a struct and we have a struct. We won't suggest changing @@ -1631,7 +1637,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ( Some((hir::def::CtorKind::Fn, def_id)), hir::ExprKind::Call(rcvr, args), - ) => { + ) if rcvr.hir_id == path_expr.hir_id => { let fn_sig = self.tcx.fn_sig(def_id).instantiate_identity(); let inputs = fn_sig.inputs().skip_binder(); // FIXME: reuse the logic for "change args" suggestion to account for types diff --git a/tests/crashes/130395.rs b/tests/crashes/130395.rs deleted file mode 100644 index c1d189c79badb..0000000000000 --- a/tests/crashes/130395.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ known-bug: #130395 -//@ needs-rustc-debug-assertions - -enum U { - B(isize, usize), -} - -fn main() { - let x = T::A(U::C); -} diff --git a/tests/ui/suggestions/incorrect-variant-in-arg.rs b/tests/ui/suggestions/incorrect-variant-in-arg.rs new file mode 100644 index 0000000000000..e05d44f743553 --- /dev/null +++ b/tests/ui/suggestions/incorrect-variant-in-arg.rs @@ -0,0 +1,57 @@ +// Regression test for #146586 + +//@ only-linux +//@ compile-flags: --error-format=human --color=always + +enum Enum { + Unit, + Tuple(i32), + Struct { x: i32 }, +} + +fn foo(_: Enum) {} + +fn main() { + foo(Enum::Unit); + foo(Enum::Tuple); + foo(Enum::Struct); // Suggestion was malformed + foo(Enum::Unit()); + foo(Enum::Tuple()); + foo(Enum::Struct()); + foo(Enum::Unit {}); + foo(Enum::Tuple {}); + foo(Enum::Struct {}); + foo(Enum::Unit(0)); + foo(Enum::Tuple(0)); + foo(Enum::Struct(0)); + foo(Enum::Unit { x: 0 }); + foo(Enum::Tuple { x: 0 }); + foo(Enum::Struct { x: 0 }); + foo(Enum::Unit(0, 0)); + foo(Enum::Tuple(0, 0)); + foo(Enum::Struct(0, 0)); + foo(Enum::Unit { x: 0, y: 0 }); + foo(Enum::Tuple { x: 0, y: 0 }); + foo(Enum::Struct { x: 0, y: 0 }); + foo(Enum::unit); // Suggestion was malformed + foo(Enum::tuple); // Suggestion is enhanced + foo(Enum::r#struct); // Suggestion was malformed + foo(Enum::unit()); + foo(Enum::tuple()); + foo(Enum::r#struct()); + foo(Enum::unit {}); // Suggestion could be enhanced + foo(Enum::tuple {}); // Suggestion could be enhanced + foo(Enum::r#struct {}); // Suggestion could be enhanced + foo(Enum::unit(0)); + foo(Enum::tuple(0)); + foo(Enum::r#struct(0)); + foo(Enum::unit { x: 0 }); // Suggestion could be enhanced + foo(Enum::tuple { x: 0 }); // Suggestion could be enhanced + foo(Enum::r#struct { x: 0 }); + foo(Enum::unit(0, 0)); + foo(Enum::tuple(0, 0)); + foo(Enum::r#struct(0, 0)); + foo(Enum::unit { x: 0, y: 0 }); // Suggestion could be enhanced + foo(Enum::tuple { x: 0, y: 0 }); // Suggestion could be enhanced + foo(Enum::r#struct { x: 0, y: 0 }); // Suggestion could be enhanced +} diff --git a/tests/ui/suggestions/incorrect-variant-in-arg.svg b/tests/ui/suggestions/incorrect-variant-in-arg.svg new file mode 100644 index 0000000000000..2fef9b817d3cc --- /dev/null +++ b/tests/ui/suggestions/incorrect-variant-in-arg.svg @@ -0,0 +1,1129 @@ + + + + + + + error[E0308]: mismatched types + + --> $DIR/incorrect-variant-in-arg.rs:16:9 + + | + + LL | Tuple(i32), + + | ----- `Tuple` defines an enum variant constructor here, which should be called + + ... + + LL | foo(Enum::Tuple); + + | --- ^^^^^^^^^^^ expected `Enum`, found enum constructor + + | | + + | arguments to this function are incorrect + + | + + = note: expected enum `Enum` + + found enum constructor `fn(i32) -> Enum {Enum::Tuple}` + + note: function defined here + + --> $DIR/incorrect-variant-in-arg.rs:12:4 + + | + + LL | fn foo(_: Enum) {} + + | ^^^ ------- + + help: use parentheses to construct this tuple variant + + | + + LL | foo(Enum::Tuple(/* i32 */)); + + | +++++++++++ + + + + error[E0533]: expected value, found struct variant `Enum::Struct` + + --> $DIR/incorrect-variant-in-arg.rs:17:9 + + | + + LL | foo(Enum::Struct); // Suggestion was malformed + + | ^^^^^^^^^^^^ not a value + + | + + help: you might have meant to create a new value of the struct + + | + + LL | foo(Enum::Struct { x: /* value */ }); // Suggestion was malformed + + | ++++++++++++++++++ + + + + error[E0618]: expected function, found enum variant `Enum::Unit` + + --> $DIR/incorrect-variant-in-arg.rs:18:9 + + | + + LL | Unit, + + | ---- enum variant `Enum::Unit` defined here + + ... + + LL | foo(Enum::Unit()); + + | ^^^^^^^^^^-- + + | | + + | call expression requires function + + | + + help: `Enum::Unit` is a unit enum variant, and does not take parentheses to be constructed + + | + + LL - foo(Enum::Unit()); + + LL + foo(Enum::Unit); + + | + + + + error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied + + --> $DIR/incorrect-variant-in-arg.rs:19:9 + + | + + LL | foo(Enum::Tuple()); + + | ^^^^^^^^^^^-- argument #1 of type `i32` is missing + + | + + note: tuple variant defined here + + --> $DIR/incorrect-variant-in-arg.rs:8:5 + + | + + LL | Tuple(i32), + + | ^^^^^ + + help: provide the argument + + | + + LL | foo(Enum::Tuple(/* i32 */)); + + | +++++++++ + + + + error[E0533]: expected value, found struct variant `Enum::Struct` + + --> $DIR/incorrect-variant-in-arg.rs:20:9 + + | + + LL | foo(Enum::Struct()); + + | ^^^^^^^^^^^^ not a value + + | + + help: you might have meant to create a new value of the struct + + | + + LL - foo(Enum::Struct()); + + LL + foo(Enum::Struct { x: /* value */ }); + + | + + + + error[E0063]: missing field `0` in initializer of `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:22:9 + + | + + LL | foo(Enum::Tuple {}); + + | ^^^^^^^^^^^ missing `0` + + + + error[E0063]: missing field `x` in initializer of `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:23:9 + + | + + LL | foo(Enum::Struct {}); + + | ^^^^^^^^^^^^ missing `x` + + + + error[E0618]: expected function, found `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:24:9 + + | + + LL | Unit, + + | ---- `Enum::Unit` defined here + + ... + + LL | foo(Enum::Unit(0)); + + | ^^^^^^^^^^--- + + | | + + | call expression requires function + + + + error[E0533]: expected value, found struct variant `Enum::Struct` + + --> $DIR/incorrect-variant-in-arg.rs:26:9 + + | + + LL | foo(Enum::Struct(0)); + + | ^^^^^^^^^^^^ not a value + + | + + help: you might have meant to create a new value of the struct + + | + + LL - foo(Enum::Struct(0)); + + LL + foo(Enum::Struct { x: /* value */ }); + + | + + + + error[E0559]: variant `Enum::Unit` has no field named `x` + + --> $DIR/incorrect-variant-in-arg.rs:27:22 + + | + + LL | foo(Enum::Unit { x: 0 }); + + | ^ `Enum::Unit` does not have this field + + | + + = note: all struct fields are already assigned + + + + error[E0559]: variant `Enum::Tuple` has no field named `x` + + --> $DIR/incorrect-variant-in-arg.rs:28:23 + + | + + LL | Tuple(i32), + + | ----- `Enum::Tuple` defined here + + ... + + LL | foo(Enum::Tuple { x: 0 }); + + | ^ field does not exist + + | + + help: `Enum::Tuple` is a tuple variant, use the appropriate syntax + + | + + LL - foo(Enum::Tuple { x: 0 }); + + LL + foo(Enum::Tuple(/* i32 */)); + + | + + + + error[E0618]: expected function, found `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:30:9 + + | + + LL | Unit, + + | ---- `Enum::Unit` defined here + + ... + + LL | foo(Enum::Unit(0, 0)); + + | ^^^^^^^^^^------ + + | | + + | call expression requires function + + + + error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied + + --> $DIR/incorrect-variant-in-arg.rs:31:9 + + | + + LL | foo(Enum::Tuple(0, 0)); + + | ^^^^^^^^^^^ - unexpected argument #2 of type `{integer}` + + | + + note: tuple variant defined here + + --> $DIR/incorrect-variant-in-arg.rs:8:5 + + | + + LL | Tuple(i32), + + | ^^^^^ + + help: remove the extra argument + + | + + LL - foo(Enum::Tuple(0, 0)); + + LL + foo(Enum::Tuple(0)); + + | + + + + error[E0533]: expected value, found struct variant `Enum::Struct` + + --> $DIR/incorrect-variant-in-arg.rs:32:9 + + | + + LL | foo(Enum::Struct(0, 0)); + + | ^^^^^^^^^^^^ not a value + + | + + help: you might have meant to create a new value of the struct + + | + + LL - foo(Enum::Struct(0, 0)); + + LL + foo(Enum::Struct { x: /* value */ }); + + | + + + + error[E0559]: variant `Enum::Unit` has no field named `x` + + --> $DIR/incorrect-variant-in-arg.rs:33:22 + + | + + LL | foo(Enum::Unit { x: 0, y: 0 }); + + | ^ `Enum::Unit` does not have this field + + | + + = note: all struct fields are already assigned + + + + error[E0559]: variant `Enum::Unit` has no field named `y` + + --> $DIR/incorrect-variant-in-arg.rs:33:28 + + | + + LL | foo(Enum::Unit { x: 0, y: 0 }); + + | ^ `Enum::Unit` does not have this field + + | + + = note: all struct fields are already assigned + + + + error[E0559]: variant `Enum::Tuple` has no field named `x` + + --> $DIR/incorrect-variant-in-arg.rs:34:23 + + | + + LL | Tuple(i32), + + | ----- `Enum::Tuple` defined here + + ... + + LL | foo(Enum::Tuple { x: 0, y: 0 }); + + | ^ field does not exist + + | + + help: `Enum::Tuple` is a tuple variant, use the appropriate syntax + + | + + LL - foo(Enum::Tuple { x: 0, y: 0 }); + + LL + foo(Enum::Tuple(/* i32 */)); + + | + + + + error[E0559]: variant `Enum::Tuple` has no field named `y` + + --> $DIR/incorrect-variant-in-arg.rs:34:29 + + | + + LL | Tuple(i32), + + | ----- `Enum::Tuple` defined here + + ... + + LL | foo(Enum::Tuple { x: 0, y: 0 }); + + | ^ field does not exist + + | + + help: `Enum::Tuple` is a tuple variant, use the appropriate syntax + + | + + LL - foo(Enum::Tuple { x: 0, y: 0 }); + + LL + foo(Enum::Tuple(/* i32 */)); + + | + + + + error[E0559]: variant `Enum::Struct` has no field named `y` + + --> $DIR/incorrect-variant-in-arg.rs:35:30 + + | + + LL | foo(Enum::Struct { x: 0, y: 0 }); + + | ^ `Enum::Struct` does not have this field + + | + + = note: all struct fields are already assigned + + + + error[E0599]: no variant or associated item named `unit` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:36:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `unit` not found for this enum + + ... + + LL | foo(Enum::unit); // Suggestion was malformed + + | ^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name (notice the capitalization) + + | + + LL - foo(Enum::unit); // Suggestion was malformed + + LL + foo(Enum::Unit); // Suggestion was malformed + + | + + + + error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:37:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `tuple` not found for this enum + + ... + + LL | foo(Enum::tuple); // Suggestion is enhanced + + | ^^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::tuple); // Suggestion is enhanced + + LL + foo(Enum::Tuple(/* i32 */)); // Suggestion is enhanced + + | + + + + error[E0599]: no variant or associated item named `r#struct` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:38:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `r#struct` not found for this enum + + ... + + LL | foo(Enum::r#struct); // Suggestion was malformed + + | ^^^^^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::r#struct); // Suggestion was malformed + + LL + foo(Enum::Struct { x: /* value */ }); // Suggestion was malformed + + | + + + + error[E0599]: no variant or associated item named `unit` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:39:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `unit` not found for this enum + + ... + + LL | foo(Enum::unit()); + + | ^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::unit()); + + LL + foo(Enum::Unit); + + | + + + + error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:40:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `tuple` not found for this enum + + ... + + LL | foo(Enum::tuple()); + + | ^^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::tuple()); + + LL + foo(Enum::Tuple(/* i32 */)); + + | + + + + error[E0599]: no variant or associated item named `r#struct` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:41:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `r#struct` not found for this enum + + ... + + LL | foo(Enum::r#struct()); + + | ^^^^^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::r#struct()); + + LL + foo(Enum::Struct { x: /* value */ }); + + | + + + + error[E0599]: no variant named `unit` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:42:15 + + | + + LL | enum Enum { + + | --------- variant `unit` not found here + + ... + + LL | foo(Enum::unit {}); // Suggestion could be enhanced + + | ^^^^ + + | + + help: there is a variant with a similar name (notice the capitalization) + + | + + LL - foo(Enum::unit {}); // Suggestion could be enhanced + + LL + foo(Enum::Unit {}); // Suggestion could be enhanced + + | + + + + error[E0599]: no variant named `tuple` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:43:15 + + | + + LL | enum Enum { + + | --------- variant `tuple` not found here + + ... + + LL | foo(Enum::tuple {}); // Suggestion could be enhanced + + | ^^^^^ + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::tuple {}); // Suggestion could be enhanced + + LL + foo(Enum::Tuple {}); // Suggestion could be enhanced + + | + + + + error[E0599]: no variant named `r#struct` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:44:15 + + | + + LL | enum Enum { + + | --------- variant `r#struct` not found here + + ... + + LL | foo(Enum::r#struct {}); // Suggestion could be enhanced + + | ^^^^^^^^ + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::r#struct {}); // Suggestion could be enhanced + + LL + foo(Enum::Struct {}); // Suggestion could be enhanced + + | + + + + error[E0599]: no variant or associated item named `unit` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:45:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `unit` not found for this enum + + ... + + LL | foo(Enum::unit(0)); + + | ^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::unit(0)); + + LL + foo(Enum::Unit); + + | + + + + error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:46:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `tuple` not found for this enum + + ... + + LL | foo(Enum::tuple(0)); + + | ^^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::tuple(0)); + + LL + foo(Enum::Tuple(0)); + + | + + + + error[E0599]: no variant or associated item named `r#struct` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:47:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `r#struct` not found for this enum + + ... + + LL | foo(Enum::r#struct(0)); + + | ^^^^^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::r#struct(0)); + + LL + foo(Enum::Struct { x: /* value */ }); + + | + + + + error[E0599]: no variant named `unit` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:48:15 + + | + + LL | enum Enum { + + | --------- variant `unit` not found here + + ... + + LL | foo(Enum::unit { x: 0 }); // Suggestion could be enhanced + + | ^^^^ + + | + + help: there is a variant with a similar name (notice the capitalization) + + | + + LL - foo(Enum::unit { x: 0 }); // Suggestion could be enhanced + + LL + foo(Enum::Unit { x: 0 }); // Suggestion could be enhanced + + | + + + + error[E0599]: no variant named `tuple` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:49:15 + + | + + LL | enum Enum { + + | --------- variant `tuple` not found here + + ... + + LL | foo(Enum::tuple { x: 0 }); // Suggestion could be enhanced + + | ^^^^^ + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::tuple { x: 0 }); // Suggestion could be enhanced + + LL + foo(Enum::Tuple { x: 0 }); // Suggestion could be enhanced + + | + + + + error[E0599]: no variant named `r#struct` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:50:15 + + | + + LL | enum Enum { + + | --------- variant `r#struct` not found here + + ... + + LL | foo(Enum::r#struct { x: 0 }); + + | ^^^^^^^^ + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::r#struct { x: 0 }); + + LL + foo(Enum::Struct { x: 0 }); + + | + + + + error[E0599]: no variant or associated item named `unit` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:51:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `unit` not found for this enum + + ... + + LL | foo(Enum::unit(0, 0)); + + | ^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::unit(0, 0)); + + LL + foo(Enum::Unit); + + | + + + + error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:52:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `tuple` not found for this enum + + ... + + LL | foo(Enum::tuple(0, 0)); + + | ^^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::tuple(0, 0)); + + LL + foo(Enum::Tuple(/* i32 */)); + + | + + + + error[E0599]: no variant or associated item named `r#struct` found for enum `Enum` in the current scope + + --> $DIR/incorrect-variant-in-arg.rs:53:15 + + | + + LL | enum Enum { + + | --------- variant or associated item `r#struct` not found for this enum + + ... + + LL | foo(Enum::r#struct(0, 0)); + + | ^^^^^^^^ variant or associated item not found in `Enum` + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::r#struct(0, 0)); + + LL + foo(Enum::Struct { x: /* value */ }); + + | + + + + error[E0599]: no variant named `unit` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:54:15 + + | + + LL | enum Enum { + + | --------- variant `unit` not found here + + ... + + LL | foo(Enum::unit { x: 0, y: 0 }); // Suggestion could be enhanced + + | ^^^^ + + | + + help: there is a variant with a similar name (notice the capitalization) + + | + + LL - foo(Enum::unit { x: 0, y: 0 }); // Suggestion could be enhanced + + LL + foo(Enum::Unit { x: 0, y: 0 }); // Suggestion could be enhanced + + | + + + + error[E0599]: no variant named `tuple` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:55:15 + + | + + LL | enum Enum { + + | --------- variant `tuple` not found here + + ... + + LL | foo(Enum::tuple { x: 0, y: 0 }); // Suggestion could be enhanced + + | ^^^^^ + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::tuple { x: 0, y: 0 }); // Suggestion could be enhanced + + LL + foo(Enum::Tuple { x: 0, y: 0 }); // Suggestion could be enhanced + + | + + + + error[E0599]: no variant named `r#struct` found for enum `Enum` + + --> $DIR/incorrect-variant-in-arg.rs:56:15 + + | + + LL | enum Enum { + + | --------- variant `r#struct` not found here + + ... + + LL | foo(Enum::r#struct { x: 0, y: 0 }); // Suggestion could be enhanced + + | ^^^^^^^^ + + | + + help: there is a variant with a similar name + + | + + LL - foo(Enum::r#struct { x: 0, y: 0 }); // Suggestion could be enhanced + + LL + foo(Enum::Struct { x: 0, y: 0 }); // Suggestion could be enhanced + + | + + + + error: aborting due to 40 previous errors + + + + Some errors have detailed explanations: E0061, E0063, E0308, E0533, E0559, E0599, E0618. + + For more information about an error, try `rustc --explain E0061`. + + + + + + diff --git a/tests/ui/suggestions/incorrect-variant-single-letter.rs b/tests/ui/suggestions/incorrect-variant-single-letter.rs new file mode 100644 index 0000000000000..5bd90f633b47a --- /dev/null +++ b/tests/ui/suggestions/incorrect-variant-single-letter.rs @@ -0,0 +1,31 @@ +// Regression test for #130395, #146261 and #146586 + +enum A { + B, + C(), + D(i32), + E {}, + F { x: i32 }, +} + +fn foo(_: A) -> impl Fn() { + || {} +} + +fn main() { + foo(A::b); //~ ERROR no variant or associated item named `b` found for enum `A` in the current scope [E0599] + foo(A::c); //~ ERROR no variant or associated item named `c` found for enum `A` in the current scope [E0599] + foo(A::d); //~ ERROR no variant or associated item named `d` found for enum `A` in the current scope [E0599] + foo(A::e); //~ ERROR no variant or associated item named `e` found for enum `A` in the current scope [E0599] + foo(A::f); //~ ERROR no variant or associated item named `f` found for enum `A` in the current scope [E0599] + (A::b)(); //~ ERROR no variant or associated item named `b` found for enum `A` in the current scope [E0599] + (A::c)(); //~ ERROR no variant or associated item named `c` found for enum `A` in the current scope [E0599] + (A::d)(); //~ ERROR no variant or associated item named `d` found for enum `A` in the current scope [E0599] + (A::e)(); //~ ERROR no variant or associated item named `e` found for enum `A` in the current scope [E0599] + (A::f)(); //~ ERROR no variant or associated item named `f` found for enum `A` in the current scope [E0599] + foo(A::b)(); //~ ERROR no variant or associated item named `b` found for enum `A` in the current scope [E0599] + foo(A::c)(); //~ ERROR no variant or associated item named `c` found for enum `A` in the current scope [E0599] + foo(A::d)(); //~ ERROR no variant or associated item named `d` found for enum `A` in the current scope [E0599] + foo(A::e)(); //~ ERROR no variant or associated item named `e` found for enum `A` in the current scope [E0599] + foo(A::f)(); //~ ERROR no variant or associated item named `f` found for enum `A` in the current scope [E0599] +} diff --git a/tests/ui/suggestions/incorrect-variant-single-letter.stderr b/tests/ui/suggestions/incorrect-variant-single-letter.stderr new file mode 100644 index 0000000000000..259f0eef5c699 --- /dev/null +++ b/tests/ui/suggestions/incorrect-variant-single-letter.stderr @@ -0,0 +1,228 @@ +error[E0599]: no variant or associated item named `b` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:16:12 + | +LL | enum A { + | ------ variant or associated item `b` not found for this enum +... +LL | foo(A::b); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::b); +LL + foo(A::B); + | + +error[E0599]: no variant or associated item named `c` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:17:12 + | +LL | enum A { + | ------ variant or associated item `c` not found for this enum +... +LL | foo(A::c); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::c); +LL + foo(A::C()); + | + +error[E0599]: no variant or associated item named `d` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:18:12 + | +LL | enum A { + | ------ variant or associated item `d` not found for this enum +... +LL | foo(A::d); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::d); +LL + foo(A::D(/* i32 */)); + | + +error[E0599]: no variant or associated item named `e` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:19:12 + | +LL | enum A { + | ------ variant or associated item `e` not found for this enum +... +LL | foo(A::e); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::e); +LL + foo(A::E {}); + | + +error[E0599]: no variant or associated item named `f` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:20:12 + | +LL | enum A { + | ------ variant or associated item `f` not found for this enum +... +LL | foo(A::f); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::f); +LL + foo(A::F { x: /* value */ }); + | + +error[E0599]: no variant or associated item named `b` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:21:9 + | +LL | enum A { + | ------ variant or associated item `b` not found for this enum +... +LL | (A::b)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - (A::b)(); +LL + (A::B)(); + | + +error[E0599]: no variant or associated item named `c` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:22:9 + | +LL | enum A { + | ------ variant or associated item `c` not found for this enum +... +LL | (A::c)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name (notice the capitalization) + | +LL - (A::c)(); +LL + (A::C)(); + | + +error[E0599]: no variant or associated item named `d` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:23:9 + | +LL | enum A { + | ------ variant or associated item `d` not found for this enum +... +LL | (A::d)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - (A::d)(); +LL + (A::D)(/* i32 */); + | + +error[E0599]: no variant or associated item named `e` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:24:9 + | +LL | enum A { + | ------ variant or associated item `e` not found for this enum +... +LL | (A::e)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - (A::e)(); +LL + (A::E {})(); + | + +error[E0599]: no variant or associated item named `f` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:25:9 + | +LL | enum A { + | ------ variant or associated item `f` not found for this enum +... +LL | (A::f)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - (A::f)(); +LL + (A::F { x: /* value */ })(); + | + +error[E0599]: no variant or associated item named `b` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:26:12 + | +LL | enum A { + | ------ variant or associated item `b` not found for this enum +... +LL | foo(A::b)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::b)(); +LL + foo(A::B)(); + | + +error[E0599]: no variant or associated item named `c` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:27:12 + | +LL | enum A { + | ------ variant or associated item `c` not found for this enum +... +LL | foo(A::c)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::c)(); +LL + foo(A::C())(); + | + +error[E0599]: no variant or associated item named `d` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:28:12 + | +LL | enum A { + | ------ variant or associated item `d` not found for this enum +... +LL | foo(A::d)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::d)(); +LL + foo(A::D(/* i32 */))(); + | + +error[E0599]: no variant or associated item named `e` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:29:12 + | +LL | enum A { + | ------ variant or associated item `e` not found for this enum +... +LL | foo(A::e)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::e)(); +LL + foo(A::E {})(); + | + +error[E0599]: no variant or associated item named `f` found for enum `A` in the current scope + --> $DIR/incorrect-variant-single-letter.rs:30:12 + | +LL | enum A { + | ------ variant or associated item `f` not found for this enum +... +LL | foo(A::f)(); + | ^ variant or associated item not found in `A` + | +help: there is a variant with a similar name + | +LL - foo(A::f)(); +LL + foo(A::F { x: /* value */ })(); + | + +error: aborting due to 15 previous errors + +For more information about this error, try `rustc --explain E0599`. diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args-in-submodule.rs b/tests/ui/type-alias-enum-variants/enum-variant-generic-args-in-submodule.rs new file mode 100644 index 0000000000000..57c632515585f --- /dev/null +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args-in-submodule.rs @@ -0,0 +1,66 @@ +// Regression test for #146706 +// Check that number of path segments of enum type and alias does not break +// suggestions for the error that variant of type-aliased enum cannot have +// generic type argument. + +mod foo { + pub enum Enum { TSVariant(T), SVariant { v: T }, UVariant } + pub type Alias = Enum; + pub type AliasFixed = Enum<()>; +} + +fn main() { + // Tuple struct variant + + foo::Enum::<()>::TSVariant::<()>(()); + //~^ ERROR type arguments are not allowed on tuple variant `TSVariant` [E0109] + + foo::Alias::TSVariant::<()>(()); + //~^ ERROR type arguments are not allowed on this type [E0109] + foo::Alias::<()>::TSVariant::<()>(()); + //~^ ERROR type arguments are not allowed on this type [E0109] + + foo::AliasFixed::TSVariant::<()>(()); + //~^ ERROR type arguments are not allowed on this type [E0109] + foo::AliasFixed::<()>::TSVariant(()); + //~^ ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + foo::AliasFixed::<()>::TSVariant::<()>(()); + //~^ ERROR type arguments are not allowed on this type [E0109] + //~| ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + + // Struct variant + + foo::Enum::<()>::SVariant::<()> { v: () }; + //~^ ERROR type arguments are not allowed on variant `SVariant` [E0109] + + foo::Alias::SVariant::<()> { v: () }; + //~^ ERROR type arguments are not allowed on this type [E0109] + foo::Alias::<()>::SVariant::<()> { v: () }; + //~^ ERROR type arguments are not allowed on this type [E0109] + + foo::AliasFixed::SVariant::<()> { v: () }; + //~^ ERROR type arguments are not allowed on this type [E0109] + foo::AliasFixed::<()>::SVariant { v: () }; + //~^ ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + foo::AliasFixed::<()>::SVariant::<()> { v: () }; + //~^ ERROR type arguments are not allowed on this type [E0109] + //~| ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + + // Unit variant + + foo::Enum::<()>::UVariant::<()>; + //~^ ERROR type arguments are not allowed on unit variant `UVariant` [E0109] + + foo::Alias::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + foo::Alias::<()>::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + + foo::AliasFixed::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + foo::AliasFixed::<()>::UVariant; + //~^ ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + foo::AliasFixed::<()>::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + //~| ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] +} diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args-in-submodule.stderr b/tests/ui/type-alias-enum-variants/enum-variant-generic-args-in-submodule.stderr new file mode 100644 index 0000000000000..894506692300d --- /dev/null +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args-in-submodule.stderr @@ -0,0 +1,257 @@ +error[E0109]: type arguments are not allowed on tuple variant `TSVariant` + --> $DIR/enum-variant-generic-args-in-submodule.rs:15:34 + | +LL | foo::Enum::<()>::TSVariant::<()>(()); + | --------- ^^ type argument not allowed + | | + | not allowed on tuple variant `TSVariant` + | + = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other +help: remove the generics arguments from one of the path segments + | +LL - foo::Enum::<()>::TSVariant::<()>(()); +LL + foo::Enum::<()>::TSVariant(()); + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:18:29 + | +LL | foo::Alias::TSVariant::<()>(()); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:20:35 + | +LL | foo::Alias::<()>::TSVariant::<()>(()); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:23:34 + | +LL | foo::AliasFixed::TSVariant::<()>(()); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-in-submodule.rs:25:10 + | +LL | foo::AliasFixed::<()>::TSVariant(()); + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-in-submodule.rs:9:14 + | +LL | pub type AliasFixed = Enum<()>; + | ^^^^^^^^^^ + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-in-submodule.rs:27:10 + | +LL | foo::AliasFixed::<()>::TSVariant::<()>(()); + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-in-submodule.rs:9:14 + | +LL | pub type AliasFixed = Enum<()>; + | ^^^^^^^^^^ + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:27:40 + | +LL | foo::AliasFixed::<()>::TSVariant::<()>(()); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on variant `SVariant` + --> $DIR/enum-variant-generic-args-in-submodule.rs:33:33 + | +LL | foo::Enum::<()>::SVariant::<()> { v: () }; + | -------- ^^ type argument not allowed + | | + | not allowed on variant `SVariant` + | + = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other +help: remove the generics arguments from one of the path segments + | +LL - foo::Enum::<()>::SVariant::<()> { v: () }; +LL + foo::Enum::<()>::SVariant { v: () }; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:36:28 + | +LL | foo::Alias::SVariant::<()> { v: () }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - foo::Alias::SVariant::<()> { v: () }; +LL + foo::Alias::<()>::SVariant { v: () }; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:38:34 + | +LL | foo::Alias::<()>::SVariant::<()> { v: () }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - foo::Alias::<()>::SVariant::<()> { v: () }; +LL + foo::Alias::<()>::SVariant { v: () }; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:41:33 + | +LL | foo::AliasFixed::SVariant::<()> { v: () }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - foo::AliasFixed::SVariant::<()> { v: () }; +LL + foo::AliasFixed::<()>::SVariant { v: () }; + | + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-in-submodule.rs:43:10 + | +LL | foo::AliasFixed::<()>::SVariant { v: () }; + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-in-submodule.rs:9:14 + | +LL | pub type AliasFixed = Enum<()>; + | ^^^^^^^^^^ + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-in-submodule.rs:45:10 + | +LL | foo::AliasFixed::<()>::SVariant::<()> { v: () }; + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-in-submodule.rs:9:14 + | +LL | pub type AliasFixed = Enum<()>; + | ^^^^^^^^^^ + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:45:39 + | +LL | foo::AliasFixed::<()>::SVariant::<()> { v: () }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - foo::AliasFixed::<()>::SVariant::<()> { v: () }; +LL + foo::AliasFixed::<()>::SVariant { v: () }; + | + +error[E0109]: type arguments are not allowed on unit variant `UVariant` + --> $DIR/enum-variant-generic-args-in-submodule.rs:51:33 + | +LL | foo::Enum::<()>::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on unit variant `UVariant` + | + = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other +help: remove the generics arguments from one of the path segments + | +LL - foo::Enum::<()>::UVariant::<()>; +LL + foo::Enum::<()>::UVariant; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:54:28 + | +LL | foo::Alias::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:56:34 + | +LL | foo::Alias::<()>::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:59:33 + | +LL | foo::AliasFixed::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-in-submodule.rs:61:10 + | +LL | foo::AliasFixed::<()>::UVariant; + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-in-submodule.rs:9:14 + | +LL | pub type AliasFixed = Enum<()>; + | ^^^^^^^^^^ + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-in-submodule.rs:63:10 + | +LL | foo::AliasFixed::<()>::UVariant::<()>; + | ^^^^^^^^^^------ help: remove the unnecessary generics + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-in-submodule.rs:9:14 + | +LL | pub type AliasFixed = Enum<()>; + | ^^^^^^^^^^ + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-in-submodule.rs:63:39 + | +LL | foo::AliasFixed::<()>::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error: aborting due to 21 previous errors + +Some errors have detailed explanations: E0107, E0109. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args-lifetime.rs b/tests/ui/type-alias-enum-variants/enum-variant-generic-args-lifetime.rs new file mode 100644 index 0000000000000..7844500f8a119 --- /dev/null +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args-lifetime.rs @@ -0,0 +1,104 @@ +// Regression test for #146706 +// Check that elided lifetime argument does not break suggestions for the error +// that variant of type-aliased enum cannot have generic type argument. + +use std::marker::PhantomData; + +enum Enum<'a, T> { + TSVariant(PhantomData<&'a T>), + SVariant { phantom: PhantomData<&'a T> }, + UVariant, +} +type Alias<'a, T> = Enum<'a, T>; +type AliasFixed<'a> = Enum<'a, ()>; + +impl<'a, T> Enum<'a, T> { + fn ts_variant() { + Self::TSVariant(PhantomData); + Self::TSVariant::<()>(PhantomData); + //~^ ERROR type arguments are not allowed on this type [E0109] + Self::<()>::TSVariant(PhantomData); + //~^ ERROR type arguments are not allowed on self type [E0109] + Self::<()>::TSVariant::<()>(PhantomData); + //~^ ERROR type arguments are not allowed on self type [E0109] + //~| ERROR type arguments are not allowed on this type [E0109] + } + + fn s_variant() { + Self::SVariant { phantom: PhantomData }; + Self::SVariant::<()> { phantom: PhantomData }; + //~^ ERROR type arguments are not allowed on this type [E0109] + Self::<()>::SVariant { phantom: PhantomData }; + //~^ ERROR type arguments are not allowed on self type [E0109] + Self::<()>::SVariant::<()> { phantom: PhantomData }; + //~^ ERROR type arguments are not allowed on self type [E0109] + //~| ERROR type arguments are not allowed on this type [E0109] + } + + fn u_variant() { + Self::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + Self::<()>::UVariant; + //~^ ERROR type arguments are not allowed on self type [E0109] + Self::<()>::UVariant::<()>; + //~^ ERROR type arguments are not allowed on self type [E0109] + //~| ERROR type arguments are not allowed on this type [E0109] + } +} + +fn main() { + // Tuple struct variant + + Enum::<()>::TSVariant::<()>(PhantomData); + //~^ ERROR type arguments are not allowed on tuple variant `TSVariant` [E0109] + + Alias::TSVariant::<()>(PhantomData); + //~^ ERROR type arguments are not allowed on this type [E0109] + Alias::<()>::TSVariant::<()>(PhantomData); + //~^ ERROR type arguments are not allowed on this type [E0109] + + AliasFixed::TSVariant::<()>(PhantomData); + //~^ ERROR type arguments are not allowed on this type [E0109] + AliasFixed::<()>::TSVariant(PhantomData); + //~^ ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + AliasFixed::<()>::TSVariant::<()>(PhantomData); + //~^ ERROR type arguments are not allowed on this type [E0109] + //~| ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + + // Struct variant + + Enum::<()>::SVariant::<()> { phantom: PhantomData }; + //~^ ERROR type arguments are not allowed on variant `SVariant` [E0109] + //~| ERROR enum takes 1 lifetime argument but 0 lifetime arguments were supplied [E0107] + + Alias::SVariant::<()> { phantom: PhantomData }; + //~^ ERROR type arguments are not allowed on this type [E0109] + Alias::<()>::SVariant::<()> { phantom: PhantomData }; + //~^ ERROR type arguments are not allowed on this type [E0109] + + AliasFixed::SVariant::<()> { phantom: PhantomData }; + //~^ ERROR type arguments are not allowed on this type [E0109] + AliasFixed::<()>::SVariant { phantom: PhantomData }; + //~^ ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + AliasFixed::<()>::SVariant::<()> { phantom: PhantomData }; + //~^ ERROR type arguments are not allowed on this type [E0109] + //~| ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + + // Unit variant + + Enum::<()>::UVariant::<()>; + //~^ ERROR type arguments are not allowed on unit variant `UVariant` [E0109] + + Alias::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + Alias::<()>::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + + AliasFixed::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + AliasFixed::<()>::UVariant; + //~^ ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] + AliasFixed::<()>::UVariant::<()>; + //~^ ERROR type arguments are not allowed on this type [E0109] + //~| ERROR type alias takes 0 generic arguments but 1 generic argument was supplied [E0107] +} diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args-lifetime.stderr b/tests/ui/type-alias-enum-variants/enum-variant-generic-args-lifetime.stderr new file mode 100644 index 0000000000000..70efbd70789ff --- /dev/null +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args-lifetime.stderr @@ -0,0 +1,468 @@ +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:18:27 + | +LL | Self::TSVariant::<()>(PhantomData); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on self type + --> $DIR/enum-variant-generic-args-lifetime.rs:20:16 + | +LL | Self::<()>::TSVariant(PhantomData); + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +note: `Self` is of type `Enum<'a, T>` + --> $DIR/enum-variant-generic-args-lifetime.rs:7:6 + | +LL | enum Enum<'a, T> { + | ^^^^ `Self` corresponds to this type +... +LL | impl<'a, T> Enum<'a, T> { + | ----------------------- `Self` is on type `Enum` in this `impl` +help: the `Self` type doesn't accept type parameters, use the concrete type's name `Enum` instead if you want to specify its type parameters + | +LL - Self::<()>::TSVariant(PhantomData); +LL + Enum::<()>::TSVariant(PhantomData); + | + +error[E0109]: type arguments are not allowed on self type + --> $DIR/enum-variant-generic-args-lifetime.rs:22:16 + | +LL | Self::<()>::TSVariant::<()>(PhantomData); + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +note: `Self` is of type `Enum<'a, T>` + --> $DIR/enum-variant-generic-args-lifetime.rs:7:6 + | +LL | enum Enum<'a, T> { + | ^^^^ `Self` corresponds to this type +... +LL | impl<'a, T> Enum<'a, T> { + | ----------------------- `Self` is on type `Enum` in this `impl` +help: the `Self` type doesn't accept type parameters, use the concrete type's name `Enum` instead if you want to specify its type parameters + | +LL - Self::<()>::TSVariant::<()>(PhantomData); +LL + Enum::<()>::TSVariant::<()>(PhantomData); + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:22:33 + | +LL | Self::<()>::TSVariant::<()>(PhantomData); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:29:26 + | +LL | Self::SVariant::<()> { phantom: PhantomData }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - Self::SVariant::<()> { phantom: PhantomData }; +LL + Enum::<()>::SVariant { phantom: PhantomData }; + | + +error[E0109]: type arguments are not allowed on self type + --> $DIR/enum-variant-generic-args-lifetime.rs:31:16 + | +LL | Self::<()>::SVariant { phantom: PhantomData }; + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +note: `Self` is of type `Enum<'a, T>` + --> $DIR/enum-variant-generic-args-lifetime.rs:7:6 + | +LL | enum Enum<'a, T> { + | ^^^^ `Self` corresponds to this type +... +LL | impl<'a, T> Enum<'a, T> { + | ----------------------- `Self` is on type `Enum` in this `impl` +help: the `Self` type doesn't accept type parameters, use the concrete type's name `Enum` instead if you want to specify its type parameters + | +LL - Self::<()>::SVariant { phantom: PhantomData }; +LL + Enum::<()>::SVariant { phantom: PhantomData }; + | + +error[E0109]: type arguments are not allowed on self type + --> $DIR/enum-variant-generic-args-lifetime.rs:33:16 + | +LL | Self::<()>::SVariant::<()> { phantom: PhantomData }; + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +note: `Self` is of type `Enum<'a, T>` + --> $DIR/enum-variant-generic-args-lifetime.rs:7:6 + | +LL | enum Enum<'a, T> { + | ^^^^ `Self` corresponds to this type +... +LL | impl<'a, T> Enum<'a, T> { + | ----------------------- `Self` is on type `Enum` in this `impl` +help: the `Self` type doesn't accept type parameters, use the concrete type's name `Enum` instead if you want to specify its type parameters + | +LL - Self::<()>::SVariant::<()> { phantom: PhantomData }; +LL + Enum::<()>::SVariant::<()> { phantom: PhantomData }; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:33:32 + | +LL | Self::<()>::SVariant::<()> { phantom: PhantomData }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - Self::<()>::SVariant::<()> { phantom: PhantomData }; +LL + Enum::<()>::SVariant { phantom: PhantomData }; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:39:26 + | +LL | Self::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on self type + --> $DIR/enum-variant-generic-args-lifetime.rs:41:16 + | +LL | Self::<()>::UVariant; + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +note: `Self` is of type `Enum<'a, T>` + --> $DIR/enum-variant-generic-args-lifetime.rs:7:6 + | +LL | enum Enum<'a, T> { + | ^^^^ `Self` corresponds to this type +... +LL | impl<'a, T> Enum<'a, T> { + | ----------------------- `Self` is on type `Enum` in this `impl` +help: the `Self` type doesn't accept type parameters, use the concrete type's name `Enum` instead if you want to specify its type parameters + | +LL - Self::<()>::UVariant; +LL + Enum::<()>::UVariant; + | + +error[E0109]: type arguments are not allowed on self type + --> $DIR/enum-variant-generic-args-lifetime.rs:43:16 + | +LL | Self::<()>::UVariant::<()>; + | ---- ^^ type argument not allowed + | | + | not allowed on self type + | +note: `Self` is of type `Enum<'a, T>` + --> $DIR/enum-variant-generic-args-lifetime.rs:7:6 + | +LL | enum Enum<'a, T> { + | ^^^^ `Self` corresponds to this type +... +LL | impl<'a, T> Enum<'a, T> { + | ----------------------- `Self` is on type `Enum` in this `impl` +help: the `Self` type doesn't accept type parameters, use the concrete type's name `Enum` instead if you want to specify its type parameters + | +LL - Self::<()>::UVariant::<()>; +LL + Enum::<()>::UVariant::<()>; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:43:32 + | +LL | Self::<()>::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on tuple variant `TSVariant` + --> $DIR/enum-variant-generic-args-lifetime.rs:52:29 + | +LL | Enum::<()>::TSVariant::<()>(PhantomData); + | --------- ^^ type argument not allowed + | | + | not allowed on tuple variant `TSVariant` + | + = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other +help: remove the generics arguments from one of the path segments + | +LL - Enum::<()>::TSVariant::<()>(PhantomData); +LL + Enum::<()>::TSVariant(PhantomData); + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:55:24 + | +LL | Alias::TSVariant::<()>(PhantomData); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:57:30 + | +LL | Alias::<()>::TSVariant::<()>(PhantomData); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:60:29 + | +LL | AliasFixed::TSVariant::<()>(PhantomData); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-lifetime.rs:62:5 + | +LL | AliasFixed::<()>::TSVariant(PhantomData); + | ^^^^^^^^^^ -- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-lifetime.rs:13:6 + | +LL | type AliasFixed<'a> = Enum<'a, ()>; + | ^^^^^^^^^^ + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-lifetime.rs:64:5 + | +LL | AliasFixed::<()>::TSVariant::<()>(PhantomData); + | ^^^^^^^^^^ -- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-lifetime.rs:13:6 + | +LL | type AliasFixed<'a> = Enum<'a, ()>; + | ^^^^^^^^^^ + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:64:35 + | +LL | AliasFixed::<()>::TSVariant::<()>(PhantomData); + | --------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: lifetime and type arguments are not allowed on variant `SVariant` + --> $DIR/enum-variant-generic-args-lifetime.rs:70:28 + | +LL | Enum::<()>::SVariant::<()> { phantom: PhantomData }; + | -------- ^^ + | | | + | | lifetime and type arguments not allowed + | not allowed on variant `SVariant` + | + = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other +help: remove the generics arguments from one of the path segments + | +LL - Enum::<()>::SVariant::<()> { phantom: PhantomData }; +LL + Enum::<()>::SVariant { phantom: PhantomData }; + | + +error[E0107]: enum takes 1 lifetime argument but 0 lifetime arguments were supplied + --> $DIR/enum-variant-generic-args-lifetime.rs:70:5 + | +LL | Enum::<()>::SVariant::<()> { phantom: PhantomData }; + | ^^^^ expected 1 lifetime argument + | +note: enum defined here, with 1 lifetime parameter: `'a` + --> $DIR/enum-variant-generic-args-lifetime.rs:7:6 + | +LL | enum Enum<'a, T> { + | ^^^^ -- +help: add missing lifetime argument + | +LL | Enum::<'a, ()>::SVariant::<()> { phantom: PhantomData }; + | +++ + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:74:23 + | +LL | Alias::SVariant::<()> { phantom: PhantomData }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - Alias::SVariant::<()> { phantom: PhantomData }; +LL + Alias::<()>::SVariant { phantom: PhantomData }; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:76:29 + | +LL | Alias::<()>::SVariant::<()> { phantom: PhantomData }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - Alias::<()>::SVariant::<()> { phantom: PhantomData }; +LL + Alias::<()>::SVariant { phantom: PhantomData }; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:79:28 + | +LL | AliasFixed::SVariant::<()> { phantom: PhantomData }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - AliasFixed::SVariant::<()> { phantom: PhantomData }; +LL + AliasFixed::<()>::SVariant { phantom: PhantomData }; + | + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-lifetime.rs:81:5 + | +LL | AliasFixed::<()>::SVariant { phantom: PhantomData }; + | ^^^^^^^^^^ -- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-lifetime.rs:13:6 + | +LL | type AliasFixed<'a> = Enum<'a, ()>; + | ^^^^^^^^^^ + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-lifetime.rs:83:5 + | +LL | AliasFixed::<()>::SVariant::<()> { phantom: PhantomData }; + | ^^^^^^^^^^ -- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-lifetime.rs:13:6 + | +LL | type AliasFixed<'a> = Enum<'a, ()>; + | ^^^^^^^^^^ + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:83:34 + | +LL | AliasFixed::<()>::SVariant::<()> { phantom: PhantomData }; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + | + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum + | +LL - AliasFixed::<()>::SVariant::<()> { phantom: PhantomData }; +LL + AliasFixed::<()>::SVariant { phantom: PhantomData }; + | + +error[E0109]: type arguments are not allowed on unit variant `UVariant` + --> $DIR/enum-variant-generic-args-lifetime.rs:89:28 + | +LL | Enum::<()>::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on unit variant `UVariant` + | + = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other +help: remove the generics arguments from one of the path segments + | +LL - Enum::<()>::UVariant::<()>; +LL + Enum::<()>::UVariant; + | + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:92:23 + | +LL | Alias::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:94:29 + | +LL | Alias::<()>::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:97:28 + | +LL | AliasFixed::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-lifetime.rs:99:5 + | +LL | AliasFixed::<()>::UVariant; + | ^^^^^^^^^^ -- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-lifetime.rs:13:6 + | +LL | type AliasFixed<'a> = Enum<'a, ()>; + | ^^^^^^^^^^ + +error[E0107]: type alias takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/enum-variant-generic-args-lifetime.rs:101:5 + | +LL | AliasFixed::<()>::UVariant::<()>; + | ^^^^^^^^^^ -- help: remove the unnecessary generic argument + | | + | expected 0 generic arguments + | +note: type alias defined here, with 0 generic parameters + --> $DIR/enum-variant-generic-args-lifetime.rs:13:6 + | +LL | type AliasFixed<'a> = Enum<'a, ()>; + | ^^^^^^^^^^ + +error[E0109]: type arguments are not allowed on this type + --> $DIR/enum-variant-generic-args-lifetime.rs:101:34 + | +LL | AliasFixed::<()>::UVariant::<()>; + | -------- ^^ type argument not allowed + | | + | not allowed on this type + +error: aborting due to 34 previous errors + +Some errors have detailed explanations: E0107, E0109. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr index 5039ae8f288ee..7764536a9fb02 100644 --- a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr @@ -116,8 +116,8 @@ LL | Self::SVariant::<()> { v: () }; | | | not allowed on this type | - = note: enum variants can't have type parameters -help: you might have meant to specify type parameters on enum `Enum` + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum | LL - Self::SVariant::<()> { v: () }; LL + Enum::<()>::SVariant { v: () }; @@ -199,8 +199,8 @@ LL | Self::<()>::SVariant::<()> { v: () }; | | | not allowed on this type | - = note: enum variants can't have type parameters -help: you might have meant to specify type parameters on enum `Enum` + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum | LL - Self::<()>::SVariant::<()> { v: () }; LL + Enum::<()>::SVariant { v: () }; @@ -376,8 +376,8 @@ LL | Alias::SVariant::<()> { v: () }; | | | not allowed on this type | - = note: enum variants can't have type parameters -help: you might have meant to specify type parameters on enum `Enum` + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum | LL - Alias::SVariant::<()> { v: () }; LL + Alias::<()>::SVariant { v: () }; @@ -391,8 +391,8 @@ LL | Alias::<()>::SVariant::<()> { v: () }; | | | not allowed on this type | - = note: enum variants can't have type parameters -help: you might have meant to specify type parameters on enum `Enum` + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum | LL - Alias::<()>::SVariant::<()> { v: () }; LL + Alias::<()>::SVariant { v: () }; @@ -406,8 +406,8 @@ LL | AliasFixed::SVariant::<()> { v: () }; | | | not allowed on this type | - = note: enum variants can't have type parameters -help: you might have meant to specify type parameters on enum `Enum` + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum | LL - AliasFixed::SVariant::<()> { v: () }; LL + AliasFixed::<()>::SVariant { v: () }; @@ -449,8 +449,8 @@ LL | AliasFixed::<()>::SVariant::<()> { v: () }; | | | not allowed on this type | - = note: enum variants can't have type parameters -help: you might have meant to specify type parameters on enum `Enum` + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum | LL - AliasFixed::<()>::SVariant::<()> { v: () }; LL + AliasFixed::<()>::SVariant { v: () }; diff --git a/tests/ui/typeck/issue-116473-ice-wrong-span-variant-args.stderr b/tests/ui/typeck/issue-116473-ice-wrong-span-variant-args.stderr index cb7666657ef4a..7a34f863cb21c 100644 --- a/tests/ui/typeck/issue-116473-ice-wrong-span-variant-args.stderr +++ b/tests/ui/typeck/issue-116473-ice-wrong-span-variant-args.stderr @@ -9,9 +9,9 @@ LL | ($variant:tt) => (if let EnumUnit::$variant:: {} = 5 { true } LL | recursive_tt!(); | --------------- in this macro invocation | - = note: enum variants can't have type parameters + = note: variants of type-aliased enum can't have type parameters = note: this error originates in the macro `recursive_tt` (in Nightly builds, run with -Z macro-backtrace for more info) -help: you might have meant to specify type parameters on enum `Enum` +help: you might have meant to specify type parameters on the enum | LL - ($variant:tt) => (if let EnumUnit::$variant:: {} = 5 { true } else { false }); LL + ($variant:tt) => (if let EnumUnit::::$variant {} = 5 { true } else { false }); @@ -43,9 +43,9 @@ LL | ($variant:ident) => (if let EnumUnit::$variant:: {} = 5 { tru LL | recursive_ident!(); | ------------------ in this macro invocation | - = note: enum variants can't have type parameters + = note: variants of type-aliased enum can't have type parameters = note: this error originates in the macro `recursive_ident` (in Nightly builds, run with -Z macro-backtrace for more info) -help: you might have meant to specify type parameters on enum `Enum` +help: you might have meant to specify type parameters on the enum | LL - ($variant:ident) => (if let EnumUnit::$variant:: {} = 5 { true } else { false }); LL + ($variant:ident) => (if let EnumUnit::::$variant {} = 5 { true } else { false }); @@ -78,9 +78,9 @@ LL | ($variant:tt) => (if let EnumUnit::$variant:: {} = 5 { true } LL | nested1_tt!(); | ------------- in this macro invocation | - = note: enum variants can't have type parameters + = note: variants of type-aliased enum can't have type parameters = note: this error originates in the macro `nested2_tt` which comes from the expansion of the macro `nested1_tt` (in Nightly builds, run with -Z macro-backtrace for more info) -help: you might have meant to specify type parameters on enum `Enum` +help: you might have meant to specify type parameters on the enum | LL - ($variant:tt) => (if let EnumUnit::$variant:: {} = 5 { true } else { false }); LL + ($variant:tt) => (if let EnumUnit::::$variant {} = 5 { true } else { false }); @@ -113,9 +113,9 @@ LL | ($variant:ident) => (if let EnumUnit::$variant:: {} = 5 { tru LL | nested1_ident!(); | ---------------- in this macro invocation | - = note: enum variants can't have type parameters + = note: variants of type-aliased enum can't have type parameters = note: this error originates in the macro `nested2_ident` which comes from the expansion of the macro `nested1_ident` (in Nightly builds, run with -Z macro-backtrace for more info) -help: you might have meant to specify type parameters on enum `Enum` +help: you might have meant to specify type parameters on the enum | LL - ($variant:ident) => (if let EnumUnit::$variant:: {} = 5 { true } else { false }); LL + ($variant:ident) => (if let EnumUnit::::$variant {} = 5 { true } else { false }); @@ -148,9 +148,9 @@ LL | ($arg1:tt, $arg2:tt) => (if let EnumUnit::VariantB::<$arg1, $arg2> {} LL | nested1_tt_args_in_first_macro!(); | --------------------------------- in this macro invocation | - = note: enum variants can't have type parameters + = note: variants of type-aliased enum can't have type parameters = note: this error originates in the macro `nested1_tt_args_in_first_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -help: you might have meant to specify type parameters on enum `Enum` +help: you might have meant to specify type parameters on the enum | LL - ($arg1:tt, $arg2:tt) => (if let EnumUnit::VariantB::<$arg1, $arg2> {} LL + ($arg1:tt, $arg2:tt) => (if let EnumUnit::<$arg1, $arg2>::VariantB {} @@ -183,9 +183,9 @@ LL | ($arg1:ident, $arg2:ident) => (if let EnumUnit::VariantB::<$arg1, $arg2 LL | nested1_ident_args_in_first_macro!(); | ------------------------------------ in this macro invocation | - = note: enum variants can't have type parameters + = note: variants of type-aliased enum can't have type parameters = note: this error originates in the macro `nested2_ident_args_in_first_macro` which comes from the expansion of the macro `nested1_ident_args_in_first_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -help: you might have meant to specify type parameters on enum `Enum` +help: you might have meant to specify type parameters on the enum | LL - ($arg1:ident, $arg2:ident) => (if let EnumUnit::VariantB::<$arg1, $arg2> {} LL + ($arg1:ident, $arg2:ident) => (if let EnumUnit::<$arg1, $arg2>::VariantB {} @@ -215,8 +215,8 @@ LL | if let EnumUnit::VariantB:: {} = 5 { true } else { false }; | | | not allowed on this type | - = note: enum variants can't have type parameters -help: you might have meant to specify type parameters on enum `Enum` + = note: variants of type-aliased enum can't have type parameters +help: you might have meant to specify type parameters on the enum | LL - if let EnumUnit::VariantB:: {} = 5 { true } else { false }; LL + if let EnumUnit::::VariantB {} = 5 { true } else { false };