Auto merge of #103578 - petrochenkov:nofict, r=nagisa

Unreserve braced enum variants in value namespace

With this PR braced enum variants (`enum E { V { /*...*/ } }`) no longer take a slot in value namespace, so the special case mentioned in the note in https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md#braced-structs is removed.

Report - https://github.com/rust-lang/rust/pull/103578#issuecomment-1292594900.
This commit is contained in:
bors 2022-11-22 10:17:09 +00:00
commit b7463e8bdb
71 changed files with 364 additions and 642 deletions

View file

@ -276,7 +276,7 @@ fn build_struct(cx: &mut DocContext<'_>, did: DefId) -> clean::Struct {
let variant = cx.tcx.adt_def(did).non_enum_variant();
clean::Struct {
struct_type: variant.ctor_kind,
ctor_kind: variant.ctor_kind(),
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
fields: variant.fields.iter().map(|x| clean_middle_field(x, cx)).collect(),
}

View file

@ -1842,16 +1842,16 @@ pub(crate) fn clean_field_with_def_id(
}
pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocContext<'tcx>) -> Item {
let kind = match variant.ctor_kind {
CtorKind::Const => Variant::CLike(match variant.discr {
let kind = match variant.ctor_kind() {
Some(CtorKind::Const) => Variant::CLike(match variant.discr {
ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }),
ty::VariantDiscr::Relative(_) => None,
}),
CtorKind::Fn => Variant::Tuple(
Some(CtorKind::Fn) => Variant::Tuple(
variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
),
CtorKind::Fictive => Variant::Struct(VariantStruct {
struct_type: CtorKind::Fictive,
None => Variant::Struct(VariantStruct {
ctor_kind: None,
fields: variant.fields.iter().map(|field| clean_middle_field(field, cx)).collect(),
}),
};
@ -1865,7 +1865,7 @@ fn clean_variant_data<'tcx>(
) -> Variant {
match variant {
hir::VariantData::Struct(..) => Variant::Struct(VariantStruct {
struct_type: CtorKind::from_hir(variant),
ctor_kind: None,
fields: variant.fields().iter().map(|x| clean_field(x, cx)).collect(),
}),
hir::VariantData::Tuple(..) => {
@ -2060,7 +2060,7 @@ fn clean_maybe_renamed_item<'tcx>(
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
}),
ItemKind::Struct(ref variant_data, generics) => StructItem(Struct {
struct_type: CtorKind::from_hir(variant_data),
ctor_kind: variant_data.ctor_kind(),
generics: clean_generics(generics, cx),
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
}),

View file

@ -2081,7 +2081,7 @@ impl From<hir::PrimTy> for PrimitiveType {
#[derive(Clone, Debug)]
pub(crate) struct Struct {
pub(crate) struct_type: CtorKind,
pub(crate) ctor_kind: Option<CtorKind>,
pub(crate) generics: Generics,
pub(crate) fields: Vec<Item>,
}
@ -2109,7 +2109,7 @@ impl Union {
/// only as a variant in an enum.
#[derive(Clone, Debug)]
pub(crate) struct VariantStruct {
pub(crate) struct_type: CtorKind,
pub(crate) ctor_kind: Option<CtorKind>,
pub(crate) fields: Vec<Item>,
}

View file

@ -2280,12 +2280,12 @@ fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clea
let fields = get_struct_fields_name(&s.fields);
if !fields.is_empty() {
match s.struct_type {
CtorKind::Fictive => {
match s.ctor_kind {
None => {
print_sidebar_block(&mut sidebar, "fields", "Fields", fields.iter());
}
CtorKind::Fn => print_sidebar_title(&mut sidebar, "fields", "Tuple Fields"),
CtorKind::Const => {}
Some(CtorKind::Fn) => print_sidebar_title(&mut sidebar, "fields", "Tuple Fields"),
Some(CtorKind::Const) => {}
}
}

View file

@ -1232,7 +1232,7 @@ fn item_enum(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, e: &clean::
w,
v,
None,
s.struct_type,
s.ctor_kind,
&s.fields,
" ",
false,
@ -1458,7 +1458,7 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
wrap_into_item_decl(w, |w| {
wrap_item(w, "struct", |w| {
render_attributes_in_code(w, it);
render_struct(w, it, Some(&s.generics), s.struct_type, &s.fields, "", true, cx);
render_struct(w, it, Some(&s.generics), s.ctor_kind, &s.fields, "", true, cx);
});
});
@ -1472,14 +1472,14 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
_ => None,
})
.peekable();
if let CtorKind::Fictive | CtorKind::Fn = s.struct_type {
if let None | Some(CtorKind::Fn) = s.ctor_kind {
if fields.peek().is_some() {
write!(
w,
"<h2 id=\"fields\" class=\"fields small-section-header\">\
{}{}<a href=\"#fields\" class=\"anchor\"></a>\
</h2>",
if let CtorKind::Fictive = s.struct_type { "Fields" } else { "Tuple Fields" },
if s.ctor_kind.is_none() { "Fields" } else { "Tuple Fields" },
document_non_exhaustive_header(it)
);
document_non_exhaustive(w, it);
@ -1739,7 +1739,7 @@ fn render_struct(
w: &mut Buffer,
it: &clean::Item,
g: Option<&clean::Generics>,
ty: CtorKind,
ty: Option<CtorKind>,
fields: &[clean::Item],
tab: &str,
structhead: bool,
@ -1757,7 +1757,7 @@ fn render_struct(
write!(w, "{}", g.print(cx))
}
match ty {
CtorKind::Fictive => {
None => {
let where_diplayed = g.map(|g| print_where_clause_and_check(w, g, cx)).unwrap_or(false);
// If there wasn't a `where` clause, we add a whitespace.
@ -1799,7 +1799,7 @@ fn render_struct(
}
w.write_str("}");
}
CtorKind::Fn => {
Some(CtorKind::Fn) => {
w.write_str("(");
for (i, field) in fields.iter().enumerate() {
if i > 0 {
@ -1827,7 +1827,7 @@ fn render_struct(
w.write_str(";");
}
}
CtorKind::Const => {
Some(CtorKind::Const) => {
// Needed for PhantomData.
if let Some(g) = g {
write!(w, "{}", print_where_clause(g, cx, 0, Ending::NoNewline));

View file

@ -315,15 +315,15 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
impl FromWithTcx<clean::Struct> for Struct {
fn from_tcx(struct_: clean::Struct, tcx: TyCtxt<'_>) -> Self {
let fields_stripped = struct_.has_stripped_entries();
let clean::Struct { struct_type, generics, fields } = struct_;
let clean::Struct { ctor_kind, generics, fields } = struct_;
let kind = match struct_type {
CtorKind::Fn => StructKind::Tuple(ids_keeping_stripped(fields, tcx)),
CtorKind::Const => {
let kind = match ctor_kind {
Some(CtorKind::Fn) => StructKind::Tuple(ids_keeping_stripped(fields, tcx)),
Some(CtorKind::Const) => {
assert!(fields.is_empty());
StructKind::Unit
}
CtorKind::Fictive => StructKind::Plain { fields: ids(fields, tcx), fields_stripped },
None => StructKind::Plain { fields: ids(fields, tcx), fields_stripped },
};
Struct {

View file

@ -17,7 +17,7 @@ fn main() {
//~^ ERROR expected function, tuple struct or tuple variant, found struct `Empty1`
let e3 = E::Empty3; //~ ERROR expected value, found struct variant `E::Empty3`
let e3 = E::Empty3();
//~^ ERROR expected function, tuple struct or tuple variant, found struct variant `E::Empty3`
//~^ ERROR expected value, found struct variant `E::Empty3`
let xe1 = XEmpty1; //~ ERROR expected value, found struct `XEmpty1`
let xe1 = XEmpty1();

View file

@ -21,24 +21,6 @@ help: a unit struct with a similar name exists
LL | let e1 = XEmpty2;
| ~~~~~~~
error[E0423]: expected value, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-expr.rs:18:14
|
LL | Empty3 {}
| --------- `E::Empty3` defined here
...
LL | let e3 = E::Empty3;
| ^^^^^^^^^ help: use struct literal syntax instead: `E::Empty3 {}`
error[E0423]: expected function, tuple struct or tuple variant, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-expr.rs:19:14
|
LL | Empty3 {}
| --------- `E::Empty3` defined here
...
LL | let e3 = E::Empty3();
| ^^^^^^^^^^^ help: use struct literal syntax instead: `E::Empty3 {}`
error[E0423]: expected value, found struct `XEmpty1`
--> $DIR/empty-struct-braces-expr.rs:22:15
|
@ -84,6 +66,18 @@ help: a unit struct with a similar name exists
LL | let e1 = XEmpty2();
| ~~~~~~~
error[E0533]: expected value, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-expr.rs:18:14
|
LL | let e3 = E::Empty3;
| ^^^^^^^^^ not a value
error[E0533]: expected value, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-expr.rs:19:14
|
LL | let e3 = E::Empty3();
| ^^^^^^^^^ not a value
error[E0423]: expected function, tuple struct or tuple variant, found struct `XEmpty1`
--> $DIR/empty-struct-braces-expr.rs:23:15
|
@ -132,5 +126,5 @@ LL | XE::Empty1 {};
error: aborting due to 9 previous errors
Some errors have detailed explanations: E0423, E0599.
Some errors have detailed explanations: E0423, E0533, E0599.
For more information about an error, try `rustc --explain E0423`.

View file

@ -1,34 +1,15 @@
error[E0532]: expected unit struct, unit variant or constant, found struct variant `E::Empty3`
error[E0533]: expected unit struct, unit variant or constant, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-pat-1.rs:24:9
|
LL | Empty3 {}
| --------- `E::Empty3` defined here
...
LL | E::Empty3 => ()
| ^^^^^^^^^ help: use struct pattern syntax instead: `E::Empty3 {}`
| ^^^^^^^^^ not a unit struct, unit variant or constant
error[E0532]: expected unit struct, unit variant or constant, found struct variant `XE::XEmpty3`
error[E0533]: expected unit struct, unit variant or constant, found struct variant `XE::XEmpty3`
--> $DIR/empty-struct-braces-pat-1.rs:31:9
|
LL | XE::XEmpty3 => ()
| ^^^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:6:5
|
LL | XEmpty3 {},
| ------- `XE::XEmpty3` defined here
LL | XEmpty4,
| ------- similarly named unit variant `XEmpty4` defined here
|
help: use struct pattern syntax instead
|
LL | XE::XEmpty3 { /* fields */ } => ()
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: a unit variant with a similar name exists
|
LL | XE::XEmpty4 => ()
| ~~~~~~~
| ^^^^^^^^^^^ not a unit struct, unit variant or constant
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0532`.
For more information about this error, try `rustc --explain E0533`.

View file

@ -1,67 +1,27 @@
error[E0532]: expected tuple struct or tuple variant, found struct variant `E::Empty3`
error[E0164]: expected tuple struct or tuple variant, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-pat-3.rs:17:9
|
LL | Empty3 {}
| --------- `E::Empty3` defined here
...
LL | E::Empty3() => ()
| ^^^^^^^^^^^ help: use struct pattern syntax instead: `E::Empty3 {}`
| ^^^^^^^^^^^ not a tuple struct or tuple variant
error[E0532]: expected tuple struct or tuple variant, found struct variant `XE::XEmpty3`
error[E0164]: expected tuple struct or tuple variant, found struct variant `XE::XEmpty3`
--> $DIR/empty-struct-braces-pat-3.rs:21:9
|
LL | XE::XEmpty3() => ()
| ^^^^^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:6:5
|
LL | XEmpty3 {},
| ------- `XE::XEmpty3` defined here
LL | XEmpty4,
LL | XEmpty5(),
| ------- similarly named tuple variant `XEmpty5` defined here
|
help: use struct pattern syntax instead
|
LL | XE::XEmpty3 { /* fields */ } => ()
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: a tuple variant with a similar name exists
|
LL | XE::XEmpty5() => ()
| ~~~~~~~
| ^^^^^^^^^^^^^ not a tuple struct or tuple variant
error[E0532]: expected tuple struct or tuple variant, found struct variant `E::Empty3`
error[E0164]: expected tuple struct or tuple variant, found struct variant `E::Empty3`
--> $DIR/empty-struct-braces-pat-3.rs:25:9
|
LL | Empty3 {}
| --------- `E::Empty3` defined here
...
LL | E::Empty3(..) => ()
| ^^^^^^^^^^^^^ help: use struct pattern syntax instead: `E::Empty3 {}`
| ^^^^^^^^^^^^^ not a tuple struct or tuple variant
error[E0532]: expected tuple struct or tuple variant, found struct variant `XE::XEmpty3`
error[E0164]: expected tuple struct or tuple variant, found struct variant `XE::XEmpty3`
--> $DIR/empty-struct-braces-pat-3.rs:29:9
|
LL | XE::XEmpty3(..) => ()
| ^^^^^^^^^^^^^^^
|
::: $DIR/auxiliary/empty-struct.rs:6:5
|
LL | XEmpty3 {},
| ------- `XE::XEmpty3` defined here
LL | XEmpty4,
LL | XEmpty5(),
| ------- similarly named tuple variant `XEmpty5` defined here
|
help: use struct pattern syntax instead
|
LL | XE::XEmpty3 { /* fields */ } => ()
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: a tuple variant with a similar name exists
|
LL | XE::XEmpty5(..) => ()
| ~~~~~~~
| ^^^^^^^^^^^^^^^ not a tuple struct or tuple variant
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0532`.
For more information about this error, try `rustc --explain E0164`.

View file

@ -2,7 +2,7 @@ error[E0164]: expected tuple struct or tuple variant, found associated constant
--> $DIR/E0164.rs:9:9
|
LL | Foo::B(i) => i,
| ^^^^^^^^^ not a tuple variant or struct
| ^^^^^^^^^ not a tuple struct or tuple variant
error: aborting due to previous error

View file

@ -8,6 +8,6 @@ fn main() {
let f = FooB { x: 3, y: 4 };
match f {
FooB(a, b) => println!("{} {}", a, b),
//~^ ERROR expected tuple struct or tuple variant, found struct variant `FooB`
//~^ ERROR expected tuple struct or tuple variant, found variant `FooB`
}
}

View file

@ -1,4 +1,4 @@
error[E0532]: expected tuple struct or tuple variant, found struct variant `FooB`
error[E0532]: expected tuple struct or tuple variant, found variant `FooB`
--> $DIR/issue-19086.rs:10:9
|
LL | FooB { x: i32, y: i32 }

View file

@ -8,7 +8,7 @@ error[E0164]: expected tuple struct or tuple variant, found associated constant
--> $DIR/issue-28992-empty.rs:14:12
|
LL | if let S::C2(..) = 0 {}
| ^^^^^^^^^ not a tuple variant or struct
| ^^^^^^^^^ not a tuple struct or tuple variant
error: aborting due to 2 previous errors

View file

@ -8,7 +8,7 @@ error[E0164]: expected tuple struct or tuple variant, found self constructor `Se
--> $DIR/issue-56835.rs:4:12
|
LL | fn bar(Self(foo): Self) {}
| ^^^^^^^^^ not a tuple variant or struct
| ^^^^^^^^^ not a tuple struct or tuple variant
error: aborting due to 2 previous errors

View file

@ -7,15 +7,13 @@ LL | Tuple(i32),
LL | MyEnum::Tuple => "",
| ^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `MyEnum::Tuple(_)`
error[E0532]: expected unit struct, unit variant or constant, found struct variant `MyEnum::Struct`
error[E0533]: expected unit struct, unit variant or constant, found struct variant `MyEnum::Struct`
--> $DIR/issue-63983.rs:10:9
|
LL | Struct{ s: i32 },
| ---------------- `MyEnum::Struct` defined here
...
LL | MyEnum::Struct => "",
| ^^^^^^^^^^^^^^ help: use struct pattern syntax instead: `MyEnum::Struct { s }`
| ^^^^^^^^^^^^^^ not a unit struct, unit variant or constant
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0532`.
Some errors have detailed explanations: E0532, E0533.
For more information about an error, try `rustc --explain E0532`.

View file

@ -2,37 +2,37 @@ error[E0533]: expected unit struct, unit variant or constant, found associated f
--> $DIR/method-path-in-pattern.rs:15:9
|
LL | Foo::bar => {}
| ^^^^^^^^
| ^^^^^^^^ not a unit struct, unit variant or constant
error[E0533]: expected unit struct, unit variant or constant, found associated function `Foo::bar`
--> $DIR/method-path-in-pattern.rs:19:9
|
LL | <Foo>::bar => {}
| ^^^^^^^^^^
| ^^^^^^^^^^ not a unit struct, unit variant or constant
error[E0533]: expected unit struct, unit variant or constant, found associated function `Foo::trait_bar`
--> $DIR/method-path-in-pattern.rs:23:9
|
LL | <Foo>::trait_bar => {}
| ^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant
error[E0533]: expected unit struct, unit variant or constant, found associated function `Foo::bar`
--> $DIR/method-path-in-pattern.rs:26:12
|
LL | if let Foo::bar = 0u32 {}
| ^^^^^^^^
| ^^^^^^^^ not a unit struct, unit variant or constant
error[E0533]: expected unit struct, unit variant or constant, found associated function `Foo::bar`
--> $DIR/method-path-in-pattern.rs:28:12
|
LL | if let <Foo>::bar = 0u32 {}
| ^^^^^^^^^^
| ^^^^^^^^^^ not a unit struct, unit variant or constant
error[E0533]: expected unit struct, unit variant or constant, found associated function `Foo::trait_bar`
--> $DIR/method-path-in-pattern.rs:30:12
|
LL | if let Foo::trait_bar = 0u32 {}
| ^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^ not a unit struct, unit variant or constant
error: aborting due to 6 previous errors

View file

@ -97,13 +97,13 @@ mod m8 {
fn f78() {
check(m7::V{}); //~ ERROR c::Item
check(m7::V); //~ ERROR expected value, found struct variant `m7::V`
check(m7::V); //~ ERROR expected value, found type alias `m7::V`
check(m8::V{}); //~ ERROR c::E
check(m8::V); //~ ERROR c::Item
}
fn xf78() {
check(xm7::V{}); //~ ERROR c::Item
check(xm7::V); //~ ERROR expected value, found struct variant `xm7::V`
check(xm7::V); //~ ERROR expected value, found type alias `xm7::V`
check(xm8::V{}); //~ ERROR c::E
check(xm8::V); //~ ERROR c::Item
}

View file

@ -52,21 +52,16 @@ LL - check(xm1::S);
LL + check(S);
|
error[E0423]: expected value, found struct variant `m7::V`
error[E0423]: expected value, found type alias `m7::V`
--> $DIR/namespace-mix.rs:100:11
|
LL | V {},
| ---- `m7::V` defined here
LL | TV(),
| ---- similarly named tuple variant `TV` defined here
...
LL | check(m7::V);
| ^^^^^
|
help: use struct literal syntax instead
|
LL | check(m7::V {});
| ~~~~~~~~
= note: can't use a type alias as a constructor
help: a tuple variant with a similar name exists
|
LL | check(m7::TV);
@ -83,23 +78,18 @@ LL - check(m7::V);
LL + check(V);
|
error[E0423]: expected value, found struct variant `xm7::V`
error[E0423]: expected value, found type alias `xm7::V`
--> $DIR/namespace-mix.rs:106:11
|
LL | check(xm7::V);
| ^^^^^^
|
::: $DIR/auxiliary/namespace-mix.rs:6:9
::: $DIR/auxiliary/namespace-mix.rs:7:9
|
LL | V {},
| - `xm7::V` defined here
LL | TV(),
| -- similarly named tuple variant `TV` defined here
|
help: use struct literal syntax instead
|
LL | check(xm7::V { /* fields */ });
| ~~~~~~~~~~~~~~~~~~~~~~~
= note: can't use a type alias as a constructor
help: a tuple variant with a similar name exists
|
LL | check(xm7::TV);

View file

@ -14,14 +14,11 @@ LL - let x = Enum::Foo(a: 3, b: 4);
LL + let x = Enum::Foo(3, 4);
|
error[E0532]: expected tuple struct or tuple variant, found struct variant `Enum::Foo`
error[E0164]: expected tuple struct or tuple variant, found struct variant `Enum::Foo`
--> $DIR/recover-from-bad-variant.rs:10:9
|
LL | Foo { a: usize, b: usize },
| -------------------------- `Enum::Foo` defined here
...
LL | Enum::Foo(a, b) => {}
| ^^^^^^^^^^^^^^^ help: use struct pattern syntax instead: `Enum::Foo { a, b }`
| ^^^^^^^^^^^^^^^ not a tuple struct or tuple variant
error[E0769]: tuple variant `Enum::Bar` written as struct variant
--> $DIR/recover-from-bad-variant.rs:12:9
@ -36,5 +33,5 @@ LL | Enum::Bar(a, b) => {}
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0532, E0769.
For more information about an error, try `rustc --explain E0532`.
Some errors have detailed explanations: E0164, E0769.
For more information about an error, try `rustc --explain E0164`.

View file

@ -42,16 +42,11 @@ help: surround the struct literal with parentheses
LL | if x == (E::K { field: "" }) {}
| + +
error[E0423]: expected value, found struct variant `E::V`
error[E0533]: expected value, found struct variant `E::V`
--> $DIR/struct-literal-variant-in-if.rs:10:13
|
LL | if x == E::V { field } {}
| ^^^^ not a value
|
help: surround the struct literal with parentheses
|
LL | if x == (E::V { field }) {}
| + +
error[E0308]: mismatched types
--> $DIR/struct-literal-variant-in-if.rs:10:20
@ -72,5 +67,5 @@ LL | let y: usize = ();
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0308, E0423.
Some errors have detailed explanations: E0308, E0533.
For more information about an error, try `rustc --explain E0308`.

View file

@ -33,7 +33,7 @@ fn main() {
TupleVariant => {} //~ ERROR match bindings cannot shadow tuple variants
}
match doesnt_matter {
BracedVariant => {} //~ ERROR match bindings cannot shadow struct variants
BracedVariant => {} // OK, `BracedVariant` is a fresh binding
}
match CONST {
CONST => {} // OK, `CONST` is a const pattern
@ -50,7 +50,7 @@ fn main() {
let BracedStruct = doesnt_matter; // OK, `BracedStruct` is a fresh binding
let UnitVariant = UnitVariant; // OK, `UnitVariant` is a unit variant pattern
let TupleVariant = doesnt_matter; //~ ERROR let bindings cannot shadow tuple variants
let BracedVariant = doesnt_matter; //~ ERROR let bindings cannot shadow struct variants
let BracedVariant = doesnt_matter; // OK, `BracedVariant` is a fresh binding
let CONST = CONST; // OK, `CONST` is a const pattern
let STATIC = doesnt_matter; //~ ERROR let bindings cannot shadow statics
let function = doesnt_matter; // OK, `function` is a fresh binding

View file

@ -22,15 +22,6 @@ LL | TupleVariant => {}
| cannot be named the same as a tuple variant
| help: try specify the pattern arguments: `TupleVariant(..)`
error[E0530]: match bindings cannot shadow struct variants
--> $DIR/pattern-binding-disambiguation.rs:36:9
|
LL | use E::*;
| ---- the struct variant `BracedVariant` is imported here
...
LL | BracedVariant => {}
| ^^^^^^^^^^^^^ cannot be named the same as a struct variant
error[E0530]: match bindings cannot shadow statics
--> $DIR/pattern-binding-disambiguation.rs:42:9
|
@ -58,15 +49,6 @@ LL | use E::*;
LL | let TupleVariant = doesnt_matter;
| ^^^^^^^^^^^^ cannot be named the same as a tuple variant
error[E0530]: let bindings cannot shadow struct variants
--> $DIR/pattern-binding-disambiguation.rs:53:9
|
LL | use E::*;
| ---- the struct variant `BracedVariant` is imported here
...
LL | let BracedVariant = doesnt_matter;
| ^^^^^^^^^^^^^ cannot be named the same as a struct variant
error[E0530]: let bindings cannot shadow statics
--> $DIR/pattern-binding-disambiguation.rs:55:9
|
@ -76,6 +58,6 @@ LL | static STATIC: () = ();
LL | let STATIC = doesnt_matter;
| ^^^^^^ cannot be named the same as a static
error: aborting due to 8 previous errors
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0530`.

View file

@ -2,7 +2,7 @@ error[E0533]: expected unit struct, unit variant or constant, found associated f
--> $DIR/qualified-path-params.rs:20:9
|
LL | <S as Tr>::A::f::<u8> => {}
| ^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^ not a unit struct, unit variant or constant
error[E0029]: only `char` and numeric types are allowed in range patterns
--> $DIR/qualified-path-params.rs:22:15

View file

@ -4,5 +4,5 @@ enum Foo {
fn main() {
let f = Foo::Variant(42);
//~^ ERROR expected function, tuple struct or tuple variant, found struct variant `Foo::Variant`
//~^ ERROR expected value, found struct variant `Foo::Variant`
}

View file

@ -1,12 +1,9 @@
error[E0423]: expected function, tuple struct or tuple variant, found struct variant `Foo::Variant`
error[E0533]: expected value, found struct variant `Foo::Variant`
--> $DIR/issue-18252.rs:6:13
|
LL | Variant { x: usize }
| -------------------- `Foo::Variant` defined here
...
LL | let f = Foo::Variant(42);
| ^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `Foo::Variant { x: val }`
| ^^^^^^^^^^^^ not a value
error: aborting due to previous error
For more information about this error, try `rustc --explain E0423`.
For more information about this error, try `rustc --explain E0533`.

View file

@ -1,23 +1,15 @@
error[E0423]: expected value, found struct variant `Homura::Madoka`
error[E0533]: expected value, found struct variant `Homura::Madoka`
--> $DIR/issue-19452.rs:10:18
|
LL | Madoka { age: u32 }
| ------------------- `Homura::Madoka` defined here
...
LL | let homura = Homura::Madoka;
| ^^^^^^^^^^^^^^ help: use struct literal syntax instead: `Homura::Madoka { age: val }`
| ^^^^^^^^^^^^^^ not a value
error[E0423]: expected value, found struct variant `issue_19452_aux::Homura::Madoka`
error[E0533]: expected value, found struct variant `issue_19452_aux::Homura::Madoka`
--> $DIR/issue-19452.rs:13:18
|
LL | let homura = issue_19452_aux::Homura::Madoka;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `issue_19452_aux::Homura::Madoka { /* fields */ }`
|
::: $DIR/auxiliary/issue-19452-aux.rs:2:5
|
LL | Madoka { age: u32 }
| ------ `issue_19452_aux::Homura::Madoka` defined here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a value
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0423`.
For more information about this error, try `rustc --explain E0533`.

View file

@ -17,16 +17,12 @@ LL | | }
| |_^
help: you might have meant to use one of the following enum variants
|
LL | (A::Struct {}).foo();
| ~~~~~~~~~~~~~~
LL | (A::Tuple()).foo();
| ~~~~~~~~~~~~
LL | A::Unit.foo();
| ~~~~~~~
help: alternatively, the following enum variants are also available
help: alternatively, the following enum variant is available
|
LL | (A::StructWithFields { /* fields */ }).foo();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | (A::TupleWithFields(/* fields */)).foo();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -34,7 +30,7 @@ error[E0423]: expected value, found enum `B`
--> $DIR/issue-73427.rs:35:5
|
LL | B.foo();
| ^
| ^ help: the following enum variant is available: `(B::TupleWithFields(/* fields */))`
|
note: the enum is defined here
--> $DIR/issue-73427.rs:9:1
@ -44,12 +40,6 @@ LL | | StructWithFields { x: () },
LL | | TupleWithFields(()),
LL | | }
| |_^
help: the following enum variants are available
|
LL | (B::StructWithFields { /* fields */ }).foo();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | (B::TupleWithFields(/* fields */)).foo();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0423]: expected value, found enum `C`
--> $DIR/issue-73427.rs:37:5
@ -70,10 +60,8 @@ help: you might have meant to use the following enum variant
|
LL | C::Unit.foo();
| ~~~~~~~
help: alternatively, the following enum variants are also available
help: alternatively, the following enum variant is available
|
LL | (C::StructWithFields { /* fields */ }).foo();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LL | (C::TupleWithFields(/* fields */)).foo();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -130,7 +118,7 @@ error[E0532]: expected tuple struct or tuple variant, found enum `A`
LL | if let A(3) = x { }
| ^
|
= help: you might have meant to match against one of the enum's non-tuple variants
= help: you might have meant to match against the enum's non-tuple variant
note: the enum is defined here
--> $DIR/issue-73427.rs:1:1
|
@ -155,7 +143,7 @@ error[E0423]: expected function, tuple struct or tuple variant, found enum `A`
LL | let x = A(3);
| ^
|
= help: you might have meant to construct one of the enum's non-tuple variants
= help: you might have meant to construct the enum's non-tuple variant
note: the enum is defined here
--> $DIR/issue-73427.rs:1:1
|

View file

@ -19,12 +19,10 @@ help: you might have meant to use the following enum variant
|
LL | m::Z::Unit;
| ~~~~~~~~~~
help: alternatively, the following enum variants are also available
help: alternatively, the following enum variant is available
|
LL | (m::Z::Fn(/* fields */));
| ~~~~~~~~~~~~~~~~~~~~~~~~
LL | (m::Z::Struct { /* fields */ });
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0423]: expected value, found enum `Z`
--> $DIR/privacy-enum-ctor.rs:25:9
@ -47,23 +45,10 @@ help: you might have meant to use the following enum variant
|
LL | m::Z::Unit;
| ~~~~~~~~~~
help: alternatively, the following enum variants are also available
help: alternatively, the following enum variant is available
|
LL | (m::Z::Fn(/* fields */));
| ~~~~~~~~~~~~~~~~~~~~~~~~
LL | (m::Z::Struct { /* fields */ });
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0423]: expected value, found struct variant `Z::Struct`
--> $DIR/privacy-enum-ctor.rs:29:20
|
LL | / Struct {
LL | | s: u8,
LL | | },
| |_____________- `Z::Struct` defined here
...
LL | let _: Z = Z::Struct;
| ^^^^^^^^^ help: use struct literal syntax instead: `Z::Struct { s: val }`
error[E0423]: expected value, found enum `m::E`
--> $DIR/privacy-enum-ctor.rs:41:16
@ -89,12 +74,10 @@ help: you might have meant to use the following enum variant
|
LL | let _: E = E::Unit;
| ~~~~~~~
help: alternatively, the following enum variants are also available
help: alternatively, the following enum variant is available
|
LL | let _: E = (E::Fn(/* fields */));
| ~~~~~~~~~~~~~~~~~~~~~
LL | let _: E = (E::Struct { /* fields */ });
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: a function with a similar name exists
|
LL | let _: E = m::f;
@ -111,17 +94,6 @@ LL - let _: E = m::E;
LL + let _: E = E;
|
error[E0423]: expected value, found struct variant `m::E::Struct`
--> $DIR/privacy-enum-ctor.rs:45:16
|
LL | / Struct {
LL | | s: u8,
LL | | },
| |_________- `m::E::Struct` defined here
...
LL | let _: E = m::E::Struct;
| ^^^^^^^^^^^^ help: use struct literal syntax instead: `m::E::Struct { s: val }`
error[E0423]: expected value, found enum `E`
--> $DIR/privacy-enum-ctor.rs:49:16
|
@ -143,12 +115,10 @@ help: you might have meant to use the following enum variant
|
LL | let _: E = E::Unit;
| ~~~~~~~
help: alternatively, the following enum variants are also available
help: alternatively, the following enum variant is available
|
LL | let _: E = (E::Fn(/* fields */));
| ~~~~~~~~~~~~~~~~~~~~~
LL | let _: E = (E::Struct { /* fields */ });
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: consider importing one of these items instead
|
LL | use std::f32::consts::E;
@ -156,17 +126,6 @@ LL | use std::f32::consts::E;
LL | use std::f64::consts::E;
|
error[E0423]: expected value, found struct variant `E::Struct`
--> $DIR/privacy-enum-ctor.rs:53:16
|
LL | / Struct {
LL | | s: u8,
LL | | },
| |_________- `E::Struct` defined here
...
LL | let _: E = E::Struct;
| ^^^^^^^^^ help: use struct literal syntax instead: `E::Struct { s: val }`
error[E0412]: cannot find type `Z` in this scope
--> $DIR/privacy-enum-ctor.rs:57:12
|
@ -203,12 +162,10 @@ help: you might have meant to use the following enum variant
|
LL | let _: Z = m::Z::Unit;
| ~~~~~~~~~~
help: alternatively, the following enum variants are also available
help: alternatively, the following enum variant is available
|
LL | let _: Z = (m::Z::Fn(/* fields */));
| ~~~~~~~~~~~~~~~~~~~~~~~~
LL | let _: Z = (m::Z::Struct { /* fields */ });
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error[E0412]: cannot find type `Z` in this scope
--> $DIR/privacy-enum-ctor.rs:61:12
@ -240,17 +197,6 @@ note: enum `m::Z` exists but is inaccessible
LL | pub(in m) enum Z {
| ^^^^^^^^^^^^^^^^ not accessible
error[E0423]: expected value, found struct variant `m::n::Z::Struct`
--> $DIR/privacy-enum-ctor.rs:64:16
|
LL | / Struct {
LL | | s: u8,
LL | | },
| |_____________- `m::n::Z::Struct` defined here
...
LL | let _: Z = m::n::Z::Struct;
| ^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `m::n::Z::Struct { s: val }`
error[E0412]: cannot find type `Z` in this scope
--> $DIR/privacy-enum-ctor.rs:68:12
|
@ -332,6 +278,12 @@ help: use parentheses to construct this tuple variant
LL | let _: Z = Z::Fn(/* u8 */);
| ++++++++++
error[E0533]: expected value, found struct variant `Z::Struct`
--> $DIR/privacy-enum-ctor.rs:29:20
|
LL | let _: Z = Z::Struct;
| ^^^^^^^^^ not a value
error[E0618]: expected function, found enum variant `Z::Unit`
--> $DIR/privacy-enum-ctor.rs:31:17
|
@ -367,6 +319,12 @@ help: use parentheses to construct this tuple variant
LL | let _: E = m::E::Fn(/* u8 */);
| ++++++++++
error[E0533]: expected value, found struct variant `m::E::Struct`
--> $DIR/privacy-enum-ctor.rs:45:16
|
LL | let _: E = m::E::Struct;
| ^^^^^^^^^^^^ not a value
error[E0618]: expected function, found enum variant `m::E::Unit`
--> $DIR/privacy-enum-ctor.rs:47:16
|
@ -402,6 +360,12 @@ help: use parentheses to construct this tuple variant
LL | let _: E = E::Fn(/* u8 */);
| ++++++++++
error[E0533]: expected value, found struct variant `E::Struct`
--> $DIR/privacy-enum-ctor.rs:53:16
|
LL | let _: E = E::Struct;
| ^^^^^^^^^ not a value
error[E0618]: expected function, found enum variant `E::Unit`
--> $DIR/privacy-enum-ctor.rs:55:16
|
@ -419,7 +383,13 @@ LL - let _: E = E::Unit();
LL + let _: E = E::Unit;
|
error[E0533]: expected value, found struct variant `m::n::Z::Struct`
--> $DIR/privacy-enum-ctor.rs:64:16
|
LL | let _: Z = m::n::Z::Struct;
| ^^^^^^^^^^^^^^^ not a value
error: aborting due to 23 previous errors
Some errors have detailed explanations: E0308, E0412, E0423, E0603, E0618.
Some errors have detailed explanations: E0308, E0412, E0423, E0533, E0603, E0618.
For more information about an error, try `rustc --explain E0308`.

View file

@ -1,23 +1,3 @@
error[E0423]: expected value, found struct variant `E::B`
--> $DIR/fn-or-tuple-struct-without-args.rs:36:16
|
LL | A(usize),
| -------- similarly named tuple variant `A` defined here
LL | B { a: usize },
| -------------- `E::B` defined here
...
LL | let _: E = E::B;
| ^^^^
|
help: use struct literal syntax instead
|
LL | let _: E = E::B { a: val };
| ~~~~~~~~~~~~~~~
help: a tuple variant with a similar name exists
|
LL | let _: E = E::A;
| ~
error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:29:20
|
@ -144,6 +124,12 @@ help: use parentheses to construct this tuple variant
LL | let _: E = E::A(/* usize */);
| +++++++++++++
error[E0533]: expected value, found struct variant `E::B`
--> $DIR/fn-or-tuple-struct-without-args.rs:36:16
|
LL | let _: E = E::B;
| ^^^^ not a value
error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:37:20
|
@ -293,5 +279,5 @@ LL | let _: usize = closure();
error: aborting due to 17 previous errors
Some errors have detailed explanations: E0308, E0423, E0615.
Some errors have detailed explanations: E0308, E0533, E0615.
For more information about an error, try `rustc --explain E0308`.

View file

@ -7,15 +7,13 @@ LL | Cow,
LL | FarmAnimal::Cow(_) => "moo".to_string(),
| ^^^^^^^^^^^^^^^^^^ help: use this syntax instead: `FarmAnimal::Cow`
error[E0532]: expected tuple struct or tuple variant, found struct variant `FarmAnimal::Chicken`
error[E0164]: expected tuple struct or tuple variant, found struct variant `FarmAnimal::Chicken`
--> $DIR/issue-84700.rs:17:9
|
LL | Chicken { num_eggs: usize },
| --------------------------- `FarmAnimal::Chicken` defined here
...
LL | FarmAnimal::Chicken(_) => "cluck, cluck!".to_string(),
| ^^^^^^^^^^^^^^^^^^^^^^ help: use struct pattern syntax instead: `FarmAnimal::Chicken { num_eggs }`
| ^^^^^^^^^^^^^^^^^^^^^^ not a tuple struct or tuple variant
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0532`.
Some errors have detailed explanations: E0164, E0532.
For more information about an error, try `rustc --explain E0164`.

View file

@ -2,7 +2,7 @@ error[E0533]: expected unit struct, unit variant or constant, found tuple varian
--> $DIR/incorrect-variant-form-through-Self-issue-58006.rs:8:13
|
LL | Self::A => (),
| ^^^^^^^
| ^^^^^^^ not a unit struct, unit variant or constant
error: aborting due to previous error

View file

@ -6,7 +6,7 @@ type Alias = Enum;
fn main() {
Alias::Braced;
//~^ ERROR expected unit struct, unit variant or constant, found struct variant `Alias::Braced` [E0533]
//~^ ERROR expected value, found struct variant `Alias::Braced` [E0533]
let Alias::Braced = panic!();
//~^ ERROR expected unit struct, unit variant or constant, found struct variant `Alias::Braced` [E0533]
let Alias::Braced(..) = panic!();

View file

@ -1,20 +1,20 @@
error[E0533]: expected unit struct, unit variant or constant, found struct variant `Alias::Braced`
error[E0533]: expected value, found struct variant `Alias::Braced`
--> $DIR/incorrect-variant-form-through-alias-caught.rs:8:5
|
LL | Alias::Braced;
| ^^^^^^^^^^^^^
| ^^^^^^^^^^^^^ not a value
error[E0533]: expected unit struct, unit variant or constant, found struct variant `Alias::Braced`
--> $DIR/incorrect-variant-form-through-alias-caught.rs:10:9
|
LL | let Alias::Braced = panic!();
| ^^^^^^^^^^^^^
| ^^^^^^^^^^^^^ not a unit struct, unit variant or constant
error[E0164]: expected tuple struct or tuple variant, found struct variant `Alias::Braced`
--> $DIR/incorrect-variant-form-through-alias-caught.rs:12:9
|
LL | let Alias::Braced(..) = panic!();
| ^^^^^^^^^^^^^^^^^ not a tuple variant or struct
| ^^^^^^^^^^^^^^^^^ not a tuple struct or tuple variant
error[E0618]: expected function, found enum variant `Alias::Unit`
--> $DIR/incorrect-variant-form-through-alias-caught.rs:15:5
@ -37,7 +37,7 @@ error[E0164]: expected tuple struct or tuple variant, found unit variant `Alias:
--> $DIR/incorrect-variant-form-through-alias-caught.rs:17:9
|
LL | let Alias::Unit() = panic!();
| ^^^^^^^^^^^^^ not a tuple variant or struct
| ^^^^^^^^^^^^^ not a tuple struct or tuple variant
error: aborting due to 5 previous errors

View file

@ -65,14 +65,14 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
_ => return,
};
if arm.guard.is_none() {
missing_variants.retain(|e| e.ctor_def_id != Some(id));
missing_variants.retain(|e| e.ctor_def_id() != Some(id));
}
path
},
PatKind::TupleStruct(path, patterns, ..) => {
if let Some(id) = cx.qpath_res(path, pat.hir_id).opt_def_id() {
if arm.guard.is_none() && patterns.iter().all(|p| !is_refutable(cx, p)) {
missing_variants.retain(|e| e.ctor_def_id != Some(id));
missing_variants.retain(|e| e.ctor_def_id() != Some(id));
}
}
path
@ -122,11 +122,11 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>]) {
s
},
variant.name,
match variant.ctor_kind {
CtorKind::Fn if variant.fields.len() == 1 => "(_)",
CtorKind::Fn => "(..)",
CtorKind::Const => "",
CtorKind::Fictive => "{ .. }",
match variant.ctor_kind() {
Some(CtorKind::Fn) if variant.fields.len() == 1 => "(_)",
Some(CtorKind::Fn) => "(..)",
Some(CtorKind::Const) => "",
None => "{ .. }",
}
)
};

View file

@ -133,11 +133,11 @@ impl UnnecessaryDefPath {
let has_ctor = match cx.tcx.def_kind(def_id) {
DefKind::Struct => {
let variant = cx.tcx.adt_def(def_id).non_enum_variant();
variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
variant.ctor.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
},
DefKind::Variant => {
let variant = cx.tcx.adt_def(cx.tcx.parent(def_id)).variant_with_id(def_id);
variant.ctor_def_id.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
variant.ctor.is_some() && variant.fields.iter().all(|f| f.vis.is_public())
},
_ => false,
};