From 5dcbf03d0f114cab1ae1748dd3c3632a52f6f52d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 9 Oct 2020 20:42:17 +0200 Subject: adt: correctly inherit field visibility from enum Previously, "find all references" on a variant field wouldn't find any references outside the defining module. This is because variant fields were incorrectly assumed to be private, like struct fields without explicit visibility, but they actually inherit the enum's visibility. --- crates/assists/src/handlers/fix_visibility.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'crates/assists') diff --git a/crates/assists/src/handlers/fix_visibility.rs b/crates/assists/src/handlers/fix_visibility.rs index 7cd76ea06..d505e9444 100644 --- a/crates/assists/src/handlers/fix_visibility.rs +++ b/crates/assists/src/handlers/fix_visibility.rs @@ -324,14 +324,14 @@ pub struct Foo { pub bar: () } #[test] fn fix_visibility_of_enum_variant_field() { - check_assist( + // Enum variants, as well as their fields, always get the enum's visibility. In fact, rustc + // rejects any visibility specifiers on them, so this assist should never fire on them. + check_assist_not_applicable( fix_visibility, r"mod foo { pub enum Foo { Bar { bar: () } } } fn main() { foo::Foo::Bar { <|>bar: () }; } ", - r"mod foo { pub enum Foo { Bar { $0pub(crate) bar: () } } } - fn main() { foo::Foo::Bar { bar: () }; } ", ); - check_assist( + check_assist_not_applicable( fix_visibility, r" //- /lib.rs @@ -339,8 +339,6 @@ mod foo; fn main() { foo::Foo::Bar { <|>bar: () }; } //- /foo.rs pub enum Foo { Bar { bar: () } } -", - r"pub enum Foo { Bar { $0pub(crate) bar: () } } ", ); check_assist_not_applicable( -- cgit v1.2.3