aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-06-03 13:26:26 +0100
committerJonas Schievink <[email protected]>2021-06-03 13:26:26 +0100
commit28e3e683b204050e532f49f84f2ec887f19cc91c (patch)
tree50df840065d230bce60b5d0b4065888a311aba57 /crates/hir_def
parentc7eb19ebf9d42cada8cb532c6b3cb0e11a531b93 (diff)
ItemTree: make variant fields inherit the enum's visibility
Diffstat (limited to 'crates/hir_def')
-rw-r--r--crates/hir_def/src/item_tree/lower.rs9
-rw-r--r--crates/hir_def/src/item_tree/tests.rs38
2 files changed, 43 insertions, 4 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 6208facd5..0e467d907 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -276,10 +276,11 @@ impl<'a> Ctx<'a> {
276 let visibility = self.lower_visibility(enum_); 276 let visibility = self.lower_visibility(enum_);
277 let name = enum_.name()?.as_name(); 277 let name = enum_.name()?.as_name();
278 let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_); 278 let generic_params = self.lower_generic_params(GenericsOwner::Enum, enum_);
279 let variants = match &enum_.variant_list() { 279 let variants =
280 Some(variant_list) => self.lower_variants(variant_list), 280 self.with_inherited_visibility(visibility, |this| match &enum_.variant_list() {
281 None => IdRange::new(self.next_variant_idx()..self.next_variant_idx()), 281 Some(variant_list) => this.lower_variants(variant_list),
282 }; 282 None => IdRange::new(this.next_variant_idx()..this.next_variant_idx()),
283 });
283 let ast_id = self.source_ast_id_map.ast_id(enum_); 284 let ast_id = self.source_ast_id_map.ast_id(enum_);
284 let res = Enum { name, visibility, generic_params, variants, ast_id }; 285 let res = Enum { name, visibility, generic_params, variants, ast_id };
285 Some(id(self.data().enums.alloc(res))) 286 Some(id(self.data().enums.alloc(res)))
diff --git a/crates/hir_def/src/item_tree/tests.rs b/crates/hir_def/src/item_tree/tests.rs
index b362add5c..57686dc6e 100644
--- a/crates/hir_def/src/item_tree/tests.rs
+++ b/crates/hir_def/src/item_tree/tests.rs
@@ -359,3 +359,41 @@ trait Tr<'a, T: 'a>: Super {}
359 "#]], 359 "#]],
360 ) 360 )
361} 361}
362
363#[test]
364fn inherit_visibility() {
365 check(
366 r#"
367pub(crate) enum En {
368 Var1(u8),
369 Var2 {
370 fld: u8,
371 },
372}
373
374pub(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}