- // Checks that a path is in scope.
- fn check_path(&mut self, span: Span, path_id: ast::NodeId, last: ast::Name) {
- debug!("privacy - path {}", self.nodestr(path_id));
- let path_res = *self.tcx.def_map.borrow().get(&path_id).unwrap();
- let ck = |tyname: &str| {
- let ck_public = |def: DefId| {
- debug!("privacy - ck_public {:?}", def);
- let origdid = path_res.def_id();
- self.ensure_public(span,
- def,
- Some(origdid),
- &format!("{} `{}`", tyname, last))
- };
-
- match path_res.last_private {
- LastMod(AllPublic) => {},
- LastMod(DependsOn(def)) => {
- self.report_error(ck_public(def));
- },
- LastImport { value_priv,
- value_used: check_value,
- type_priv,
- type_used: check_type } => {
- // This dance with found_error is because we don't want to
- // report a privacy error twice for the same directive.
- let found_error = match (type_priv, check_type) {
- (Some(DependsOn(def)), Used) => {
- !self.report_error(ck_public(def))
- },
- _ => false,
- };
- if !found_error {
- match (value_priv, check_value) {
- (Some(DependsOn(def)), Used) => {
- self.report_error(ck_public(def));
- },
- _ => {},
- }
- }
- // If an import is not used in either namespace, we still
- // want to check that it could be legal. Therefore we check
- // in both namespaces and only report an error if both would
- // be illegal. We only report one error, even if it is
- // illegal to import from both namespaces.
- match (value_priv, check_value, type_priv, check_type) {
- (Some(p), Unused, None, _) |
- (None, _, Some(p), Unused) => {
- let p = match p {
- AllPublic => None,
- DependsOn(def) => ck_public(def),
- };
- if p.is_some() {
- self.report_error(p);
- }
- },
- (Some(v), Unused, Some(t), Unused) => {
- let v = match v {
- AllPublic => None,
- DependsOn(def) => ck_public(def),
- };
- let t = match t {
- AllPublic => None,
- DependsOn(def) => ck_public(def),
- };
- if let (Some(_), Some(t)) = (v, t) {
- self.report_error(Some(t));
- }
- },
- _ => {},
- }
- },
- }
- };
- // FIXME(#12334) Imports can refer to definitions in both the type and
- // value namespaces. The privacy information is aware of this, but the
- // def map is not. Therefore the names we work out below will not always
- // be accurate and we can get slightly wonky error messages (but type
- // checking is always correct).
- let def = path_res.full_def();
- if def != Def::Err {
- ck(def.kind_name());
- }
- }
-