Auto merge of #63982 - sam09:fix-63976, r=estebank
When accessing private field of union, do not misidentify it as a struct Fix incorrect error message when accessing private field of union. Fixes #63976.
This commit is contained in:
commit
4295eea903
3 changed files with 8 additions and 3 deletions
|
@ -1392,12 +1392,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
base_did: DefId,
|
||||
) {
|
||||
let struct_path = self.tcx().def_path_str(base_did);
|
||||
let kind_name = match self.tcx().def_kind(base_did) {
|
||||
Some(def_kind) => def_kind.descr(base_did),
|
||||
_ => " ",
|
||||
};
|
||||
let mut err = struct_span_err!(
|
||||
self.tcx().sess,
|
||||
expr.span,
|
||||
E0616,
|
||||
"field `{}` of struct `{}` is private",
|
||||
"field `{}` of {} `{}` is private",
|
||||
field,
|
||||
kind_name,
|
||||
struct_path
|
||||
);
|
||||
// Also check if an accessible method exists, which is often what is meant.
|
||||
|
|
|
@ -11,5 +11,5 @@ fn main() {
|
|||
|
||||
let a = u.a; // OK
|
||||
let b = u.b; // OK
|
||||
let c = u.c; //~ ERROR field `c` of struct `m::U` is private
|
||||
let c = u.c; //~ ERROR field `c` of union `m::U` is private
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
error[E0616]: field `c` of struct `m::U` is private
|
||||
error[E0616]: field `c` of union `m::U` is private
|
||||
--> $DIR/union-field-privacy-2.rs:14:13
|
||||
|
|
||||
LL | let c = u.c;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue