mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
ItemTree: make variant fields inherit the enum's visibility
This commit is contained in:
parent
c7eb19ebf9
commit
28e3e683b2
2 changed files with 43 additions and 4 deletions
|
@ -276,10 +276,11 @@ impl<'a> Ctx<'a> {
|
||||||
let visibility = self.lower_visibility(enum_);
|
let visibility = self.lower_visibility(enum_);
|
||||||
let name = enum_.name()?.as_name();
|
let name = enum_.name()?.as_name();
|
||||||
let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_);
|
let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_);
|
||||||
let variants = match &enum_.variant_list() {
|
let variants =
|
||||||
Some(variant_list) => self.lower_variants(variant_list),
|
self.with_inherited_visibility(visibility, |this| match &enum_.variant_list() {
|
||||||
None => IdRange::new(self.next_variant_idx()..self.next_variant_idx()),
|
Some(variant_list) => this.lower_variants(variant_list),
|
||||||
};
|
None => IdRange::new(this.next_variant_idx()..this.next_variant_idx()),
|
||||||
|
});
|
||||||
let ast_id = self.source_ast_id_map.ast_id(enum_);
|
let ast_id = self.source_ast_id_map.ast_id(enum_);
|
||||||
let res = Enum { name, visibility, generic_params, variants, ast_id };
|
let res = Enum { name, visibility, generic_params, variants, ast_id };
|
||||||
Some(id(self.data().enums.alloc(res)))
|
Some(id(self.data().enums.alloc(res)))
|
||||||
|
|
|
@ -359,3 +359,41 @@ trait Tr<'a, T: 'a>: Super {}
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn inherit_visibility() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
pub(crate) enum En {
|
||||||
|
Var1(u8),
|
||||||
|
Var2 {
|
||||||
|
fld: u8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) trait Tr {
|
||||||
|
fn f();
|
||||||
|
fn method(&self) {}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
pub(crate) enum En {
|
||||||
|
Var1(
|
||||||
|
pub(crate) 0: u8,
|
||||||
|
),
|
||||||
|
Var2 {
|
||||||
|
pub(crate) fld: u8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) trait Tr<Self> {
|
||||||
|
pub(crate) fn f() -> ();
|
||||||
|
|
||||||
|
// flags = 0x3
|
||||||
|
pub(crate) fn method(
|
||||||
|
_: &Self,
|
||||||
|
) -> ();
|
||||||
|
}
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue