Skip to content

Commit 23b48d3

Browse files
Merge #9127
9127: internal: make variant fields inherit the enum's visibility in the ItemTree r=jonas-schievink a=jonas-schievink No observable changes from what I can tell, but this is "more correct". bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents 48ea50b + 28e3e68 commit 23b48d3

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

crates/hir_def/src/item_tree/lower.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ impl<'a> Ctx<'a> {
276276
let visibility = self.lower_visibility(enum_);
277277
let name = enum_.name()?.as_name();
278278
let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_);
279-
let variants = match &enum_.variant_list() {
280-
Some(variant_list) => self.lower_variants(variant_list),
281-
None => IdRange::new(self.next_variant_idx()..self.next_variant_idx()),
282-
};
279+
let variants =
280+
self.with_inherited_visibility(visibility, |this| match &enum_.variant_list() {
281+
Some(variant_list) => this.lower_variants(variant_list),
282+
None => IdRange::new(this.next_variant_idx()..this.next_variant_idx()),
283+
});
283284
let ast_id = self.source_ast_id_map.ast_id(enum_);
284285
let res = Enum { name, visibility, generic_params, variants, ast_id };
285286
Some(id(self.data().enums.alloc(res)))

crates/hir_def/src/item_tree/tests.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,41 @@ trait Tr<'a, T: 'a>: Super {}
359359
"#]],
360360
)
361361
}
362+
363+
#[test]
364+
fn inherit_visibility() {
365+
check(
366+
r#"
367+
pub(crate) enum En {
368+
Var1(u8),
369+
Var2 {
370+
fld: u8,
371+
},
372+
}
373+
374+
pub(crate) trait Tr {
375+
fn f();
376+
fn method(&self) {}
377+
}
378+
"#,
379+
expect![[r#"
380+
pub(crate) enum En {
381+
Var1(
382+
pub(crate) 0: u8,
383+
),
384+
Var2 {
385+
pub(crate) fld: u8,
386+
},
387+
}
388+
389+
pub(crate) trait Tr<Self> {
390+
pub(crate) fn f() -> ();
391+
392+
// flags = 0x3
393+
pub(crate) fn method(
394+
_: &Self,
395+
) -> ();
396+
}
397+
"#]],
398+
)
399+
}

0 commit comments

Comments
 (0)