diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-03 13:27:57 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-06-03 13:27:57 +0100 |
| commit | 23b48d377d295c7ff5b59246788f0627d3726b5b (patch) | |
| tree | da6ad57db8b0b4d0a4994534883e380a6fa65efa /crates | |
| parent | 48ea50bf04a1bd12999bd9e27558ac31988c7228 (diff) | |
| parent | 28e3e683b204050e532f49f84f2ec887f19cc91c (diff) | |
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]>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 9 | ||||
| -rw-r--r-- | crates/hir_def/src/item_tree/tests.rs | 38 |
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] | ||
| 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 | } | ||
