|
21 | 21 | #![feature(rustc_private)]
|
22 | 22 | #![feature(staged_api)]
|
23 | 23 |
|
24 |
| -#[macro_use] extern crate log; |
| 24 | +extern crate rustc; |
25 | 25 | #[macro_use] extern crate syntax;
|
26 | 26 |
|
27 |
| -#[macro_use] extern crate rustc; |
28 |
| - |
29 |
| -use std::cmp; |
30 |
| -use std::mem::replace; |
31 |
| - |
32 |
| -use rustc::hir::{self, PatKind}; |
33 |
| -use rustc::hir::intravisit::{self, Visitor}; |
34 |
| - |
35 | 27 | use rustc::dep_graph::DepNode;
|
36 |
| -use rustc::lint; |
| 28 | +use rustc::hir::{self, PatKind}; |
37 | 29 | use rustc::hir::def::{self, Def};
|
38 | 30 | use rustc::hir::def_id::DefId;
|
| 31 | +use rustc::hir::intravisit::{self, Visitor}; |
| 32 | +use rustc::lint; |
39 | 33 | use rustc::middle::privacy::{AccessLevel, AccessLevels};
|
40 | 34 | use rustc::ty::{self, TyCtxt};
|
41 | 35 | use rustc::util::nodemap::NodeSet;
|
42 |
| -use rustc::hir::map as ast_map; |
43 |
| - |
44 | 36 | use syntax::ast;
|
45 | 37 | use syntax::codemap::Span;
|
46 | 38 |
|
47 |
| -pub mod diagnostics; |
48 |
| - |
49 |
| -type Context<'a, 'tcx> = (&'a ty::MethodMap<'tcx>, &'a def::ExportMap); |
| 39 | +use std::cmp; |
| 40 | +use std::mem::replace; |
50 | 41 |
|
51 |
| -/// Result of a checking operation - None => no errors were found. Some => an |
52 |
| -/// error and contains the span and message for reporting that error and |
53 |
| -/// optionally the same for a note about the error. |
54 |
| -type CheckResult = Option<(Span, String, Option<(Span, String)>)>; |
| 42 | +pub mod diagnostics; |
55 | 43 |
|
56 | 44 | ////////////////////////////////////////////////////////////////////////////////
|
57 | 45 | /// The embargo visitor, used to determine the exports of the ast
|
@@ -433,7 +421,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
433 | 421 | hir::ExprMethodCall(..) => {
|
434 | 422 | let method_call = ty::MethodCall::expr(expr.id);
|
435 | 423 | let method = self.tcx.tables.borrow().method_map[&method_call];
|
436 |
| - debug!("(privacy checking) checking impl method"); |
437 | 424 | self.check_method(expr.span, method.def_id);
|
438 | 425 | }
|
439 | 426 | hir::ExprStruct(..) => {
|
@@ -521,74 +508,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
521 | 508 | }
|
522 | 509 | }
|
523 | 510 |
|
524 |
| -//////////////////////////////////////////////////////////////////////////////// |
525 |
| -/// The privacy sanity check visitor, ensures unnecessary visibility isn't here |
526 |
| -//////////////////////////////////////////////////////////////////////////////// |
527 |
| - |
528 |
| -struct SanePrivacyVisitor<'a, 'tcx: 'a> { |
529 |
| - tcx: TyCtxt<'a, 'tcx, 'tcx>, |
530 |
| -} |
531 |
| - |
532 |
| -impl<'a, 'tcx, 'v> Visitor<'v> for SanePrivacyVisitor<'a, 'tcx> { |
533 |
| - fn visit_item(&mut self, item: &hir::Item) { |
534 |
| - self.check_sane_privacy(item); |
535 |
| - intravisit::walk_item(self, item); |
536 |
| - } |
537 |
| -} |
538 |
| - |
539 |
| -impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> { |
540 |
| - /// Validate that items that shouldn't have visibility qualifiers don't have them. |
541 |
| - /// Such qualifiers can be set by syntax extensions even if the parser doesn't allow them, |
542 |
| - /// so we check things like variant fields too. |
543 |
| - fn check_sane_privacy(&self, item: &hir::Item) { |
544 |
| - let check_inherited = |sp, vis: &hir::Visibility, note: &str| { |
545 |
| - if *vis != hir::Inherited { |
546 |
| - let mut err = struct_span_err!(self.tcx.sess, sp, E0449, |
547 |
| - "unnecessary visibility qualifier"); |
548 |
| - if !note.is_empty() { |
549 |
| - err.span_note(sp, note); |
550 |
| - } |
551 |
| - err.emit(); |
552 |
| - } |
553 |
| - }; |
554 |
| - |
555 |
| - match item.node { |
556 |
| - hir::ItemImpl(_, _, _, Some(..), _, ref impl_items) => { |
557 |
| - check_inherited(item.span, &item.vis, |
558 |
| - "visibility qualifiers have no effect on trait impls"); |
559 |
| - for impl_item in impl_items { |
560 |
| - check_inherited(impl_item.span, &impl_item.vis, |
561 |
| - "visibility qualifiers have no effect on trait impl items"); |
562 |
| - } |
563 |
| - } |
564 |
| - hir::ItemImpl(_, _, _, None, _, _) => { |
565 |
| - check_inherited(item.span, &item.vis, |
566 |
| - "place qualifiers on individual methods instead"); |
567 |
| - } |
568 |
| - hir::ItemDefaultImpl(..) => { |
569 |
| - check_inherited(item.span, &item.vis, |
570 |
| - "visibility qualifiers have no effect on trait impls"); |
571 |
| - } |
572 |
| - hir::ItemForeignMod(..) => { |
573 |
| - check_inherited(item.span, &item.vis, |
574 |
| - "place qualifiers on individual functions instead"); |
575 |
| - } |
576 |
| - hir::ItemEnum(ref def, _) => { |
577 |
| - for variant in &def.variants { |
578 |
| - for field in variant.node.data.fields() { |
579 |
| - check_inherited(field.span, &field.vis, |
580 |
| - "visibility qualifiers have no effect on variant fields"); |
581 |
| - } |
582 |
| - } |
583 |
| - } |
584 |
| - hir::ItemStruct(..) | hir::ItemTrait(..) | |
585 |
| - hir::ItemConst(..) | hir::ItemStatic(..) | hir::ItemFn(..) | |
586 |
| - hir::ItemMod(..) | hir::ItemExternCrate(..) | |
587 |
| - hir::ItemUse(..) | hir::ItemTy(..) => {} |
588 |
| - } |
589 |
| - } |
590 |
| -} |
591 |
| - |
592 | 511 | ///////////////////////////////////////////////////////////////////////////////
|
593 | 512 | /// Obsolete visitors for checking for private items in public interfaces.
|
594 | 513 | /// These visitors are supposed to be kept in frozen state and produce an
|
@@ -629,7 +548,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> {
|
629 | 548 | // .. and it corresponds to a private type in the AST (this returns
|
630 | 549 | // None for type parameters)
|
631 | 550 | match self.tcx.map.find(node_id) {
|
632 |
| - Some(ast_map::NodeItem(ref item)) => item.vis != hir::Public, |
| 551 | + Some(hir::map::NodeItem(ref item)) => item.vis != hir::Public, |
633 | 552 | Some(_) | None => false,
|
634 | 553 | }
|
635 | 554 | } else {
|
@@ -863,7 +782,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx>
|
863 | 782 | // any `visit_ty`'s will be called on things that are in
|
864 | 783 | // public signatures, i.e. things that we're interested in for
|
865 | 784 | // this visitor.
|
866 |
| - debug!("VisiblePrivateTypesVisitor entering item {:?}", item); |
867 | 785 | intravisit::walk_item(self, item);
|
868 | 786 | }
|
869 | 787 |
|
@@ -895,7 +813,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx>
|
895 | 813 | }
|
896 | 814 |
|
897 | 815 | fn visit_ty(&mut self, t: &hir::Ty) {
|
898 |
| - debug!("VisiblePrivateTypesVisitor checking ty {:?}", t); |
899 | 816 | if let hir::TyPath(..) = t.node {
|
900 | 817 | if self.path_is_private_type(t.id) {
|
901 | 818 | self.old_error_set.insert(t.id);
|
@@ -1180,10 +1097,6 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
1180 | 1097 |
|
1181 | 1098 | let krate = tcx.map.krate();
|
1182 | 1099 |
|
1183 |
| - // Sanity check to make sure that all privacy usage is reasonable. |
1184 |
| - let mut visitor = SanePrivacyVisitor { tcx: tcx }; |
1185 |
| - krate.visit_all_items(&mut visitor); |
1186 |
| - |
1187 | 1100 | // Use the parent map to check the privacy of everything
|
1188 | 1101 | let mut visitor = PrivacyVisitor {
|
1189 | 1102 | curitem: ast::DUMMY_NODE_ID,
|
|
0 commit comments