Skip to content

Commit c7aa957

Browse files
committed
fix visibilty check
1 parent d0e2f9e commit c7aa957

File tree

3 files changed

+57
-19
lines changed

3 files changed

+57
-19
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
356356
// of error recovery.
357357
field_indices.push((index, subindex));
358358

359+
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
360+
self.tcx.check_stability(field.did, Some(hir_id), span, None);
361+
} else {
362+
self.private_field_err(ident, container_def.did()).emit();
363+
}
364+
359365
if !last {
360366
let field_ty = self.field_ty(span, field, args);
361367

@@ -371,12 +377,6 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
371377
},
372378
);
373379

374-
if field.vis.is_accessible_from(sub_def_scope, self.tcx) {
375-
self.tcx.check_stability(field.did, Some(hir_id), span, None);
376-
} else {
377-
self.private_field_err(ident, container_def.did()).emit();
378-
}
379-
380380
current_container = field_ty;
381381
}
382382

@@ -396,6 +396,12 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
396396
// of error recovery.
397397
field_indices.push((FIRST_VARIANT, index));
398398

399+
if field.vis.is_accessible_from(def_scope, self.tcx) {
400+
self.tcx.check_stability(field.did, Some(hir_id), span, None);
401+
} else {
402+
self.private_field_err(ident, container_def.did()).emit();
403+
}
404+
399405
if !last {
400406
let field_ty = self.field_ty(span, field, args);
401407

@@ -416,13 +422,6 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
416422
// not.
417423
}
418424
}
419-
420-
if field.vis.is_accessible_from(def_scope, self.tcx) {
421-
self.tcx.check_stability(field.did, Some(hir_id), span, None);
422-
} else {
423-
self.private_field_err(ident, container_def.did()).emit();
424-
}
425-
426425
current_container = field_ty;
427426
}
428427

tests/ui/field_projections/deny-private-field.stderr renamed to tests/ui/field_projections/deny-private-field.next.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error[E0616]: field `a` of struct `A` is private
2-
--> $DIR/deny-private-field.rs:43:25
2+
--> $DIR/deny-private-field.rs:45:25
33
|
44
LL | let _: field_of!(A, a);
55
| ^ private field
66

77
error[E0616]: field `b` of struct `B` is private
8-
--> $DIR/deny-private-field.rs:45:27
8+
--> $DIR/deny-private-field.rs:47:27
99
|
1010
LL | let _: field_of!(A, b.b);
1111
| ^ private field
1212

1313
error[E0616]: field `c` of struct `C` is private
14-
--> $DIR/deny-private-field.rs:47:29
14+
--> $DIR/deny-private-field.rs:49:29
1515
|
1616
LL | let _: field_of!(A, b.c.c);
1717
| ^ private field
1818

1919
error[E0616]: field `d` of struct `D` is private
20-
--> $DIR/deny-private-field.rs:49:31
20+
--> $DIR/deny-private-field.rs:51:31
2121
|
2222
LL | let _: field_of!(A, b.c.d.d);
2323
| ^ private field
2424

2525
error[E0616]: field `e` of struct `E` is private
26-
--> $DIR/deny-private-field.rs:51:33
26+
--> $DIR/deny-private-field.rs:53:33
2727
|
2828
LL | let _: field_of!(A, b.c.d.e.e);
2929
| ^ private field
3030

3131
error[E0616]: field `f` of struct `F` is private
32-
--> $DIR/deny-private-field.rs:53:35
32+
--> $DIR/deny-private-field.rs:55:35
3333
|
3434
LL | let _: field_of!(A, b.c.d.e.f.f);
3535
| ^ private field
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0616]: field `a` of struct `A` is private
2+
--> $DIR/deny-private-field.rs:45:25
3+
|
4+
LL | let _: field_of!(A, a);
5+
| ^ private field
6+
7+
error[E0616]: field `b` of struct `B` is private
8+
--> $DIR/deny-private-field.rs:47:27
9+
|
10+
LL | let _: field_of!(A, b.b);
11+
| ^ private field
12+
13+
error[E0616]: field `c` of struct `C` is private
14+
--> $DIR/deny-private-field.rs:49:29
15+
|
16+
LL | let _: field_of!(A, b.c.c);
17+
| ^ private field
18+
19+
error[E0616]: field `d` of struct `D` is private
20+
--> $DIR/deny-private-field.rs:51:31
21+
|
22+
LL | let _: field_of!(A, b.c.d.d);
23+
| ^ private field
24+
25+
error[E0616]: field `e` of struct `E` is private
26+
--> $DIR/deny-private-field.rs:53:33
27+
|
28+
LL | let _: field_of!(A, b.c.d.e.e);
29+
| ^ private field
30+
31+
error[E0616]: field `f` of struct `F` is private
32+
--> $DIR/deny-private-field.rs:55:35
33+
|
34+
LL | let _: field_of!(A, b.c.d.e.f.f);
35+
| ^ private field
36+
37+
error: aborting due to 6 previous errors
38+
39+
For more information about this error, try `rustc --explain E0616`.

0 commit comments

Comments
 (0)