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