Skip to content

Commit

Permalink
Remove no longer necessary ctor checks in rustc_privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 28, 2017
1 parent 8b060e2 commit c9788fd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 69 deletions.
43 changes: 4 additions & 39 deletions src/librustc_privacy/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,45 +115,6 @@ pub enum Foo {
```
"##,

E0450: r##"
A tuple constructor was invoked while some of its fields are private. Erroneous
code example:
```compile_fail
mod Bar {
pub struct Foo(isize);
}
let f = Bar::Foo(0); // error: cannot invoke tuple struct constructor with
// private fields
```
To solve this issue, please ensure that all of the fields of the tuple struct
are public. Alternatively, provide a `new()` method to the tuple struct to
construct it from a given inner value. Example:
```
mod Bar {
pub struct Foo(pub isize); // we set its field to public
}
let f = Bar::Foo(0); // ok!
// or:
mod bar {
pub struct Foo(isize);
impl Foo {
pub fn new(x: isize) -> Foo {
Foo(x)
}
}
}
let f = bar::Foo::new(1);
```
"##,

E0451: r##"
A struct constructor with private fields was invoked. Erroneous code example:
Expand Down Expand Up @@ -204,3 +165,7 @@ let f = Bar::Foo::new(); // ok!
"##,

}

register_diagnostics! {
// E0450, moved into resolve
}
29 changes: 1 addition & 28 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern crate syntax_pos;

use rustc::dep_graph::DepNode;
use rustc::hir::{self, PatKind};
use rustc::hir::def::{self, Def, CtorKind};
use rustc::hir::def::{self, Def};
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::hir::itemlikevisit::DeepVisitor;
Expand Down Expand Up @@ -478,33 +478,6 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivacyVisitor<'a, 'tcx> {
}
}
}
hir::ExprPath(hir::QPath::Resolved(_, ref path)) => {
if let Def::StructCtor(_, CtorKind::Fn) = path.def {
let adt_def = self.tcx.expect_variant_def(path.def);
let private_indexes = adt_def.fields.iter().enumerate().filter(|&(_, field)| {
!field.vis.is_accessible_from(self.curitem, self.tcx)
}).map(|(i, _)| i).collect::<Vec<_>>();

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(node_id) = self.tcx.hir.as_local_node_id(adt_def.did) {
let node = self.tcx.hir.find(node_id);
if let Some(hir::map::NodeStructCtor(vdata)) = node {
for i in private_indexes {
error.span_label(vdata.fields()[i].span,
&format!("private field declared here"));
}
}
}
error.emit();
}
}
}
_ => {}
}

Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,6 @@ mod tests {
t("no_run", false, true, false, true, false, false, Vec::new());
t("test_harness", false, false, false, true, true, false, Vec::new());
t("compile_fail", false, true, false, true, false, true, Vec::new());
t("E0450", false, false, false, true, false, false,
vec!["E0450".to_owned()]);
t("{.no_run .example}", false, true, false, true, false, false, Vec::new());
t("{.sh .should_panic}", true, false, false, true, false, false, Vec::new());
t("{.example .rust}", false, false, false, true, false, false, Vec::new());
Expand Down

0 comments on commit c9788fd

Please sign in to comment.