Skip to content

update error E0450 to new format #36044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,32 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
}), ..}) => ty,
_ => expr_ty
}.ty_adt_def().unwrap();
let any_priv = def.struct_variant().fields.iter().any(|f| {
!f.vis.is_accessible_from(self.curitem, &self.tcx.map)
});
if any_priv {
span_err!(self.tcx.sess, expr.span, E0450,
"cannot invoke tuple struct constructor with private \
fields");

let private_indexes : Vec<_> = def.struct_variant().fields.iter().enumerate()
.filter(|&(_,f)| {
!f.vis.is_accessible_from(self.curitem, &self.tcx.map)
}).map(|(n,&_)|n).collect();

if !private_indexes.is_empty() {

let mut error = struct_span_err!(self.tcx.sess, expr.span, E0450,
"cannot invoke tuple struct constructor \
with private fields");
error.span_label(expr.span,
&format!("cannot construct with a private field"));

if let Some(def_id) = self.tcx.map.as_local_node_id(def.did) {
if let Some(hir::map::NodeItem(node)) = self.tcx.map.find(def_id) {
if let hir::Item_::ItemStruct(ref tuple_data, _) = node.node {

for i in private_indexes {
error.span_label(tuple_data.fields()[i].span,
&format!("private field declared here"));
}
}
}
}
error.emit();
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/test/compile-fail/E0450.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
// except according to those terms.

mod Bar {
pub struct Foo(isize);
pub struct Foo( bool, pub i32, f32, bool);
//~^ NOTE private field declared here
//~| NOTE private field declared here
//~| NOTE private field declared here
}

fn main() {
let f = Bar::Foo(0); //~ ERROR E0450
let f = Bar::Foo(false,1,0.1, true); //~ ERROR E0450
//~^ NOTE cannot construct with a private field
}