Remove LastPrivate
This commit is contained in:
parent
ec0fdd5a4a
commit
8f32fdecfb
11 changed files with 43 additions and 372 deletions
|
|
@ -9,7 +9,6 @@
|
|||
// except according to those terms.
|
||||
|
||||
use middle::def_id::DefId;
|
||||
use middle::privacy::LastPrivate;
|
||||
use middle::subst::ParamSpace;
|
||||
use util::nodemap::NodeMap;
|
||||
use syntax::ast;
|
||||
|
|
@ -65,7 +64,6 @@ pub enum Def {
|
|||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct PathResolution {
|
||||
pub base_def: Def,
|
||||
pub last_private: LastPrivate,
|
||||
pub depth: usize
|
||||
}
|
||||
|
||||
|
|
@ -84,12 +82,10 @@ impl PathResolution {
|
|||
}
|
||||
|
||||
pub fn new(base_def: Def,
|
||||
last_private: LastPrivate,
|
||||
depth: usize)
|
||||
-> PathResolution {
|
||||
PathResolution {
|
||||
base_def: base_def,
|
||||
last_private: last_private,
|
||||
depth: depth,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@
|
|||
//! outside their scopes. This pass will also generate a set of exported items
|
||||
//! which are available for use externally when compiled as a library.
|
||||
|
||||
pub use self::PrivateDep::*;
|
||||
pub use self::ImportUse::*;
|
||||
pub use self::LastPrivate::*;
|
||||
|
||||
use middle::def_id::DefId;
|
||||
use util::nodemap::{DefIdSet, FnvHashMap};
|
||||
|
||||
use std::hash::Hash;
|
||||
|
|
@ -64,39 +59,3 @@ impl<Id: Hash + Eq> Default for AccessLevels<Id> {
|
|||
/// A set containing all exported definitions from external crates.
|
||||
/// The set does not contain any entries from local crates.
|
||||
pub type ExternalExports = DefIdSet;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum LastPrivate {
|
||||
LastMod(PrivateDep),
|
||||
// `use` directives (imports) can refer to two separate definitions in the
|
||||
// type and value namespaces. We record here the last private node for each
|
||||
// and whether the import is in fact used for each.
|
||||
// If the Option<PrivateDep> fields are None, it means there is no definition
|
||||
// in that namespace.
|
||||
LastImport{value_priv: Option<PrivateDep>,
|
||||
value_used: ImportUse,
|
||||
type_priv: Option<PrivateDep>,
|
||||
type_used: ImportUse},
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum PrivateDep {
|
||||
AllPublic,
|
||||
DependsOn(DefId),
|
||||
}
|
||||
|
||||
// How an import is used.
|
||||
#[derive(Copy, Clone, PartialEq, Debug)]
|
||||
pub enum ImportUse {
|
||||
Unused, // The import is not used.
|
||||
Used, // The import is used.
|
||||
}
|
||||
|
||||
impl LastPrivate {
|
||||
pub fn or(self, other: LastPrivate) -> LastPrivate {
|
||||
match (self, other) {
|
||||
(me, LastMod(AllPublic)) => me,
|
||||
(_, other) => other,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ use middle::ty::cast;
|
|||
use middle::const_qualif::ConstQualif;
|
||||
use middle::def::{self, Def};
|
||||
use middle::def_id::DefId;
|
||||
use middle::privacy::{AllPublic, LastMod};
|
||||
use middle::region;
|
||||
use middle::subst;
|
||||
use middle::ty::{self, Ty};
|
||||
|
|
@ -1161,8 +1160,6 @@ fn decode_side_tables(dcx: &DecodeContext,
|
|||
let def = decode_def(dcx, val_dsr);
|
||||
dcx.tcx.def_map.borrow_mut().insert(id, def::PathResolution {
|
||||
base_def: def,
|
||||
// This doesn't matter cross-crate.
|
||||
last_private: LastMod(AllPublic),
|
||||
depth: 0
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,6 @@ use rustc::lint;
|
|||
use rustc::middle::def::{self, Def};
|
||||
use rustc::middle::def_id::DefId;
|
||||
use rustc::middle::privacy::{AccessLevel, AccessLevels};
|
||||
use rustc::middle::privacy::ImportUse::*;
|
||||
use rustc::middle::privacy::LastPrivate::*;
|
||||
use rustc::middle::privacy::PrivateDep::*;
|
||||
use rustc::middle::privacy::ExternalExports;
|
||||
use rustc::middle::ty;
|
||||
use rustc::util::nodemap::{NodeMap, NodeSet};
|
||||
|
|
@ -718,7 +715,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
|||
source_did: Option<DefId>,
|
||||
msg: &str)
|
||||
-> CheckResult {
|
||||
use rustc_front::hir::Item_::ItemExternCrate;
|
||||
debug!("ensure_public(span={:?}, to_check={:?}, source_did={:?}, msg={:?})",
|
||||
span, to_check, source_did, msg);
|
||||
let def_privacy = self.def_privacy(to_check);
|
||||
|
|
@ -740,20 +736,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
|||
let def_id = source_did.unwrap_or(to_check);
|
||||
let node_id = self.tcx.map.as_local_node_id(def_id);
|
||||
|
||||
// Warn when using a inaccessible extern crate.
|
||||
if let Some(node_id) = self.tcx.map.as_local_node_id(to_check) {
|
||||
match self.tcx.map.get(node_id) {
|
||||
ast_map::Node::NodeItem(&hir::Item { node: ItemExternCrate(_), name, .. }) => {
|
||||
self.tcx.sess.add_lint(lint::builtin::INACCESSIBLE_EXTERN_CRATE,
|
||||
node_id,
|
||||
span,
|
||||
format!("extern crate `{}` is private", name));
|
||||
return None;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
let (err_span, err_msg) = if Some(id) == node_id {
|
||||
return Some((span, format!("{} is private", msg), None));
|
||||
} else {
|
||||
|
|
@ -842,90 +824,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
|||
name)));
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
// Checks that a method is in scope.
|
||||
fn check_method(&mut self, span: Span, method_def_id: DefId,
|
||||
name: ast::Name) {
|
||||
|
|
@ -1067,25 +965,6 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
|||
intravisit::walk_foreign_item(self, fi);
|
||||
self.in_foreign = false;
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &hir::Path, id: ast::NodeId) {
|
||||
if !path.segments.is_empty() {
|
||||
self.check_path(path.span, id, path.segments.last().unwrap().identifier.name);
|
||||
intravisit::walk_path(self, path);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) {
|
||||
let name = if let hir::PathListIdent { name, .. } = item.node {
|
||||
name
|
||||
} else if !prefix.segments.is_empty() {
|
||||
prefix.segments.last().unwrap().identifier.name
|
||||
} else {
|
||||
self.tcx.sess.bug("`self` import in an import list with empty prefix");
|
||||
};
|
||||
self.check_path(item.span, item.node.id(), name);
|
||||
intravisit::walk_path_list_item(self, prefix, item);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ use Resolver;
|
|||
use Namespace::{TypeNS, ValueNS};
|
||||
|
||||
use rustc::lint;
|
||||
use rustc::middle::privacy::{DependsOn, LastImport, Used, Unused};
|
||||
use syntax::ast;
|
||||
use syntax::codemap::{Span, DUMMY_SP};
|
||||
|
||||
|
|
@ -69,45 +68,6 @@ impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
|
|||
span,
|
||||
"unused import".to_string());
|
||||
}
|
||||
|
||||
let mut def_map = self.def_map.borrow_mut();
|
||||
let path_res = if let Some(r) = def_map.get_mut(&id) {
|
||||
r
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
let (v_priv, t_priv) = match path_res.last_private {
|
||||
LastImport { value_priv, type_priv, .. } => (value_priv, type_priv),
|
||||
_ => {
|
||||
panic!("we should only have LastImport for `use` directives")
|
||||
}
|
||||
};
|
||||
|
||||
let mut v_used = if self.used_imports.contains(&(id, ValueNS)) {
|
||||
Used
|
||||
} else {
|
||||
Unused
|
||||
};
|
||||
let t_used = if self.used_imports.contains(&(id, TypeNS)) {
|
||||
Used
|
||||
} else {
|
||||
Unused
|
||||
};
|
||||
|
||||
match (v_priv, t_priv) {
|
||||
// Since some items may be both in the value _and_ type namespaces (e.g., structs)
|
||||
// we might have two LastPrivates pointing at the same thing. There is no point
|
||||
// checking both, so lets not check the value one.
|
||||
(Some(DependsOn(def_v)), Some(DependsOn(def_t))) if def_v == def_t => v_used = Unused,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
path_res.last_private = LastImport {
|
||||
value_priv: v_priv,
|
||||
value_used: v_used,
|
||||
type_priv: t_priv,
|
||||
type_used: t_used,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ use rustc::middle::cstore::{CrateStore, DefLike, DlDef};
|
|||
use rustc::middle::def::*;
|
||||
use rustc::middle::def_id::DefId;
|
||||
use rustc::middle::pat_util::pat_bindings;
|
||||
use rustc::middle::privacy::*;
|
||||
use rustc::middle::privacy::ExternalExports;
|
||||
use rustc::middle::subst::{ParamSpace, FnSpace, TypeSpace};
|
||||
use rustc::middle::ty::{Freevar, FreevarMap, TraitMap, GlobMap};
|
||||
use rustc::util::nodemap::{NodeMap, DefIdSet, FnvHashMap};
|
||||
|
|
@ -757,8 +757,8 @@ enum AssocItemResolveResult {
|
|||
|
||||
#[derive(Copy, Clone)]
|
||||
enum BareIdentifierPatternResolution {
|
||||
FoundStructOrEnumVariant(Def, LastPrivate),
|
||||
FoundConst(Def, LastPrivate, Name),
|
||||
FoundStructOrEnumVariant(Def),
|
||||
FoundConst(Def, Name),
|
||||
BareIdentifierPatternUnresolved,
|
||||
}
|
||||
|
||||
|
|
@ -920,16 +920,6 @@ impl<'a> ModuleS<'a> {
|
|||
self.def.as_ref().map(Def::def_id)
|
||||
}
|
||||
|
||||
// This returns the DefId of the crate local item that controls this module's visibility.
|
||||
// It is only used to compute `LastPrivate` data, and it differs from `def_id` only for extern
|
||||
// crates, whose `def_id` is the external crate's root, not the local `extern crate` item.
|
||||
fn local_def_id(&self) -> Option<DefId> {
|
||||
match self.extern_crate_did {
|
||||
Some(def_id) => Some(def_id),
|
||||
None => self.def_id(),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_normal(&self) -> bool {
|
||||
match self.def {
|
||||
Some(Def::Mod(_)) | Some(Def::ForeignMod(_)) => true,
|
||||
|
|
@ -1040,14 +1030,6 @@ impl<'a> NameBinding<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn local_def_id(&self) -> Option<DefId> {
|
||||
match self.kind {
|
||||
NameBindingKind::Def(def) => Some(def.def_id()),
|
||||
NameBindingKind::Module(ref module) => module.local_def_id(),
|
||||
NameBindingKind::Import { binding, .. } => binding.local_def_id(),
|
||||
}
|
||||
}
|
||||
|
||||
fn defined_with(&self, modifiers: DefModifiers) -> bool {
|
||||
self.modifiers.contains(modifiers)
|
||||
}
|
||||
|
|
@ -1056,13 +1038,6 @@ impl<'a> NameBinding<'a> {
|
|||
self.defined_with(DefModifiers::PUBLIC)
|
||||
}
|
||||
|
||||
fn def_and_lp(&self) -> (Def, LastPrivate) {
|
||||
let def = self.def().unwrap();
|
||||
if let Def::Err = def { return (def, LastMod(AllPublic)) }
|
||||
let lp = if self.is_public() { AllPublic } else { DependsOn(self.local_def_id().unwrap()) };
|
||||
(def, LastMod(lp))
|
||||
}
|
||||
|
||||
fn is_extern_crate(&self) -> bool {
|
||||
self.module().and_then(|module| module.extern_crate_did).is_some()
|
||||
}
|
||||
|
|
@ -1313,9 +1288,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
module_: Module<'a>,
|
||||
module_path: &[Name],
|
||||
index: usize,
|
||||
span: Span,
|
||||
lp: LastPrivate)
|
||||
-> ResolveResult<(Module<'a>, LastPrivate)> {
|
||||
span: Span)
|
||||
-> ResolveResult<Module<'a>> {
|
||||
fn search_parent_externals(needle: Name, module: Module) -> Option<Module> {
|
||||
match module.resolve_name(needle, TypeNS, false) {
|
||||
Success(binding) if binding.is_extern_crate() => Some(module),
|
||||
|
|
@ -1331,7 +1305,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let mut search_module = module_;
|
||||
let mut index = index;
|
||||
let module_path_len = module_path.len();
|
||||
let mut closest_private = lp;
|
||||
|
||||
// Resolve the module part of the path. This does not involve looking
|
||||
// upward though scope chains; we simply resolve names directly in
|
||||
|
|
@ -1380,14 +1353,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// so, whether there is a module within.
|
||||
if let Some(module_def) = binding.module() {
|
||||
search_module = module_def;
|
||||
|
||||
// Keep track of the closest private module used
|
||||
// when resolving this import chain.
|
||||
if !binding.is_public() {
|
||||
if let Some(did) = search_module.local_def_id() {
|
||||
closest_private = LastMod(DependsOn(did));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let msg = format!("Not a module `{}`", name);
|
||||
return Failed(Some((span, msg)));
|
||||
|
|
@ -1398,7 +1363,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
index += 1;
|
||||
}
|
||||
|
||||
return Success((search_module, closest_private));
|
||||
return Success(search_module);
|
||||
}
|
||||
|
||||
/// Attempts to resolve the module part of an import directive or path
|
||||
|
|
@ -1411,9 +1376,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
module_path: &[Name],
|
||||
use_lexical_scope: UseLexicalScopeFlag,
|
||||
span: Span)
|
||||
-> ResolveResult<(Module<'a>, LastPrivate)> {
|
||||
-> ResolveResult<Module<'a>> {
|
||||
if module_path.len() == 0 {
|
||||
return Success((self.graph_root, LastMod(AllPublic))) // Use the crate root
|
||||
return Success(self.graph_root) // Use the crate root
|
||||
}
|
||||
|
||||
debug!("(resolving module path for import) processing `{}` rooted at `{}`",
|
||||
|
|
@ -1425,7 +1390,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
let search_module;
|
||||
let start_index;
|
||||
let last_private;
|
||||
match module_prefix_result {
|
||||
Failed(None) => {
|
||||
let mpath = names_to_string(module_path);
|
||||
|
|
@ -1459,7 +1423,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// resolution process at index zero.
|
||||
search_module = self.graph_root;
|
||||
start_index = 0;
|
||||
last_private = LastMod(AllPublic);
|
||||
}
|
||||
UseLexicalScope => {
|
||||
// This is not a crate-relative path. We resolve the
|
||||
|
|
@ -1478,7 +1441,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
Some(containing_module) => {
|
||||
search_module = containing_module;
|
||||
start_index = 1;
|
||||
last_private = LastMod(AllPublic);
|
||||
}
|
||||
None => return Failed(None),
|
||||
}
|
||||
|
|
@ -1489,16 +1451,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
Success(PrefixFound(ref containing_module, index)) => {
|
||||
search_module = containing_module;
|
||||
start_index = index;
|
||||
last_private = LastMod(DependsOn(containing_module.local_def_id()
|
||||
.unwrap()));
|
||||
}
|
||||
}
|
||||
|
||||
self.resolve_module_path_from_root(search_module,
|
||||
module_path,
|
||||
start_index,
|
||||
span,
|
||||
last_private)
|
||||
span)
|
||||
}
|
||||
|
||||
/// Invariant: This must only be called during main resolution, not during
|
||||
|
|
@ -1847,8 +1806,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
match self.resolve_crate_relative_path(prefix.span,
|
||||
&prefix.segments,
|
||||
TypeNS) {
|
||||
Some((def, lp)) =>
|
||||
self.record_def(item.id, PathResolution::new(def, lp, 0)),
|
||||
Some(def) =>
|
||||
self.record_def(item.id, PathResolution::new(def, 0)),
|
||||
None => {
|
||||
resolve_error(self,
|
||||
prefix.span,
|
||||
|
|
@ -2399,7 +2358,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
match self.resolve_bare_identifier_pattern(ident.unhygienic_name,
|
||||
pattern.span) {
|
||||
FoundStructOrEnumVariant(def, lp) if const_ok => {
|
||||
FoundStructOrEnumVariant(def) if const_ok => {
|
||||
debug!("(resolving pattern) resolving `{}` to struct or enum variant",
|
||||
renamed);
|
||||
|
||||
|
|
@ -2409,7 +2368,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
self.record_def(pattern.id,
|
||||
PathResolution {
|
||||
base_def: def,
|
||||
last_private: lp,
|
||||
depth: 0,
|
||||
});
|
||||
}
|
||||
|
|
@ -2422,18 +2380,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
);
|
||||
self.record_def(pattern.id, err_path_resolution());
|
||||
}
|
||||
FoundConst(def, lp, _) if const_ok => {
|
||||
FoundConst(def, _) if const_ok => {
|
||||
debug!("(resolving pattern) resolving `{}` to constant", renamed);
|
||||
|
||||
self.enforce_default_binding_mode(pattern, binding_mode, "a constant");
|
||||
self.record_def(pattern.id,
|
||||
PathResolution {
|
||||
base_def: def,
|
||||
last_private: lp,
|
||||
depth: 0,
|
||||
});
|
||||
}
|
||||
FoundConst(def, _, name) => {
|
||||
FoundConst(def, name) => {
|
||||
resolve_error(
|
||||
self,
|
||||
pattern.span,
|
||||
|
|
@ -2455,7 +2412,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
self.record_def(pattern.id,
|
||||
PathResolution {
|
||||
base_def: def,
|
||||
last_private: LastMod(AllPublic),
|
||||
depth: 0,
|
||||
});
|
||||
|
||||
|
|
@ -2673,10 +2629,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
// considered as not having a private component because
|
||||
// the lookup happened only within the current module.
|
||||
Some(def @ Def::Variant(..)) | Some(def @ Def::Struct(..)) => {
|
||||
return FoundStructOrEnumVariant(def, LastMod(AllPublic));
|
||||
return FoundStructOrEnumVariant(def);
|
||||
}
|
||||
Some(def @ Def::Const(..)) | Some(def @ Def::AssociatedConst(..)) => {
|
||||
return FoundConst(def, LastMod(AllPublic), name);
|
||||
return FoundConst(def, name);
|
||||
}
|
||||
Some(Def::Static(..)) => {
|
||||
resolve_error(self, span, ResolutionError::StaticVariableReference);
|
||||
|
|
@ -2757,7 +2713,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let span = path.span;
|
||||
let segments = &path.segments[..path.segments.len() - path_depth];
|
||||
|
||||
let mk_res = |(def, lp)| PathResolution::new(def, lp, path_depth);
|
||||
let mk_res = |def| PathResolution::new(def, path_depth);
|
||||
|
||||
if path.global {
|
||||
let def = self.resolve_crate_relative_path(span, segments, namespace);
|
||||
|
|
@ -2770,14 +2726,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let unqualified_def = self.resolve_identifier(last_ident, namespace, check_ribs, true);
|
||||
return unqualified_def.and_then(|def| self.adjust_local_def(def, span))
|
||||
.map(|def| {
|
||||
PathResolution::new(def, LastMod(AllPublic), path_depth)
|
||||
PathResolution::new(def, path_depth)
|
||||
});
|
||||
}
|
||||
|
||||
let unqualified_def = self.resolve_identifier(last_ident, namespace, check_ribs, false);
|
||||
let def = self.resolve_module_relative_path(span, segments, namespace);
|
||||
match (def, unqualified_def) {
|
||||
(Some((ref d, _)), Some(ref ud)) if *d == ud.def => {
|
||||
(Some(d), Some(ref ud)) if d == ud.def => {
|
||||
self.session
|
||||
.add_lint(lint::builtin::UNUSED_QUALIFICATIONS,
|
||||
id,
|
||||
|
|
@ -2923,7 +2879,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
span: Span,
|
||||
segments: &[hir::PathSegment],
|
||||
namespace: Namespace)
|
||||
-> Option<(Def, LastPrivate)> {
|
||||
-> Option<Def> {
|
||||
let module_path = segments.split_last()
|
||||
.unwrap()
|
||||
.1
|
||||
|
|
@ -2932,7 +2888,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
.collect::<Vec<_>>();
|
||||
|
||||
let containing_module;
|
||||
let last_private;
|
||||
let current_module = self.current_module;
|
||||
match self.resolve_module_path(current_module, &module_path, UseLexicalScope, span) {
|
||||
Failed(err) => {
|
||||
|
|
@ -2949,22 +2904,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
return None;
|
||||
}
|
||||
Indeterminate => return None,
|
||||
Success((resulting_module, resulting_last_private)) => {
|
||||
Success(resulting_module) => {
|
||||
containing_module = resulting_module;
|
||||
last_private = resulting_last_private;
|
||||
}
|
||||
}
|
||||
|
||||
let name = segments.last().unwrap().identifier.name;
|
||||
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
|
||||
let def = match result {
|
||||
Success(binding) => {
|
||||
let (def, lp) = binding.def_and_lp();
|
||||
(def, last_private.or(lp))
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
return Some(def);
|
||||
result.success().map(|binding| binding.def().unwrap())
|
||||
}
|
||||
|
||||
/// Invariant: This must be called only during main resolution, not during
|
||||
|
|
@ -2973,7 +2920,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
span: Span,
|
||||
segments: &[hir::PathSegment],
|
||||
namespace: Namespace)
|
||||
-> Option<(Def, LastPrivate)> {
|
||||
-> Option<Def> {
|
||||
let module_path = segments.split_last()
|
||||
.unwrap()
|
||||
.1
|
||||
|
|
@ -2984,12 +2931,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
let root_module = self.graph_root;
|
||||
|
||||
let containing_module;
|
||||
let last_private;
|
||||
match self.resolve_module_path_from_root(root_module,
|
||||
&module_path,
|
||||
0,
|
||||
span,
|
||||
LastMod(AllPublic)) {
|
||||
span) {
|
||||
Failed(err) => {
|
||||
let (span, msg) = match err {
|
||||
Some((span, msg)) => (span, msg),
|
||||
|
|
@ -3006,20 +2951,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
Indeterminate => return None,
|
||||
|
||||
Success((resulting_module, resulting_last_private)) => {
|
||||
Success(resulting_module) => {
|
||||
containing_module = resulting_module;
|
||||
last_private = resulting_last_private;
|
||||
}
|
||||
}
|
||||
|
||||
let name = segments.last().unwrap().identifier.name;
|
||||
match self.resolve_name_in_module(containing_module, name, namespace, false, true) {
|
||||
Success(binding) => {
|
||||
let (def, lp) = binding.def_and_lp();
|
||||
Some((def, last_private.or(lp)))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
let result = self.resolve_name_in_module(containing_module, name, namespace, false, true);
|
||||
result.success().map(|binding| binding.def().unwrap())
|
||||
}
|
||||
|
||||
fn resolve_identifier_in_local_ribs(&mut self,
|
||||
|
|
@ -3105,10 +3044,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
.and_then(NameBinding::module)
|
||||
}
|
||||
} else {
|
||||
match this.resolve_module_path(root, &name_path, UseLexicalScope, span) {
|
||||
Success((module, _)) => Some(module),
|
||||
_ => None,
|
||||
}
|
||||
this.resolve_module_path(root, &name_path, UseLexicalScope, span).success()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3420,7 +3356,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
self.record_def(expr.id,
|
||||
PathResolution {
|
||||
base_def: def,
|
||||
last_private: LastMod(AllPublic),
|
||||
depth: 0,
|
||||
})
|
||||
}
|
||||
|
|
@ -3613,12 +3548,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
|||
|
||||
fn record_def(&mut self, node_id: NodeId, resolution: PathResolution) {
|
||||
debug!("(recording def) recording {:?} for {}", resolution, node_id);
|
||||
assert!(match resolution.last_private {
|
||||
LastImport{..} => false,
|
||||
_ => true,
|
||||
},
|
||||
"Import should only be used for `use` directives");
|
||||
|
||||
if let Some(prev_res) = self.def_map.borrow_mut().insert(node_id, resolution) {
|
||||
let span = self.ast_map.opt_span(node_id).unwrap_or(codemap::DUMMY_SP);
|
||||
self.session.span_bug(span,
|
||||
|
|
@ -3756,7 +3685,6 @@ fn module_to_string(module: Module) -> String {
|
|||
fn err_path_resolution() -> PathResolution {
|
||||
PathResolution {
|
||||
base_def: Def::Err,
|
||||
last_private: LastMod(AllPublic),
|
||||
depth: 0,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ use build_reduced_graph;
|
|||
|
||||
use rustc::lint;
|
||||
use rustc::middle::def::*;
|
||||
use rustc::middle::privacy::*;
|
||||
|
||||
use syntax::ast::{NodeId, Name};
|
||||
use syntax::attr::AttrMetaMethods;
|
||||
|
|
@ -296,7 +295,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
&import_directive.module_path,
|
||||
UseLexicalScopeFlag::DontUseLexicalScope,
|
||||
import_directive.span)
|
||||
.and_then(|(containing_module, lp)| {
|
||||
.and_then(|containing_module| {
|
||||
// We found the module that the target is contained
|
||||
// within. Attempt to resolve the import within it.
|
||||
if let SingleImport(target, source) = import_directive.subclass {
|
||||
|
|
@ -304,10 +303,9 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
containing_module,
|
||||
target,
|
||||
source,
|
||||
import_directive,
|
||||
lp)
|
||||
import_directive)
|
||||
} else {
|
||||
self.resolve_glob_import(module_, containing_module, import_directive, lp)
|
||||
self.resolve_glob_import(module_, containing_module, import_directive)
|
||||
}
|
||||
})
|
||||
.and_then(|()| {
|
||||
|
|
@ -333,26 +331,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
target_module: Module<'b>,
|
||||
target: Name,
|
||||
source: Name,
|
||||
directive: &ImportDirective,
|
||||
lp: LastPrivate)
|
||||
directive: &ImportDirective)
|
||||
-> ResolveResult<()> {
|
||||
debug!("(resolving single import) resolving `{}` = `{}::{}` from `{}` id {}, last \
|
||||
private {:?}",
|
||||
debug!("(resolving single import) resolving `{}` = `{}::{}` from `{}` id {}",
|
||||
target,
|
||||
module_to_string(&target_module),
|
||||
source,
|
||||
module_to_string(module_),
|
||||
directive.id,
|
||||
lp);
|
||||
|
||||
let lp = match lp {
|
||||
LastMod(lp) => lp,
|
||||
LastImport {..} => {
|
||||
self.resolver
|
||||
.session
|
||||
.span_bug(directive.span, "not expecting Import here, must be LastMod")
|
||||
}
|
||||
};
|
||||
directive.id);
|
||||
|
||||
// If this is a circular import, we temporarily count it as determined so that
|
||||
// it fails (as opposed to being indeterminate) when nothing else can define it.
|
||||
|
|
@ -450,28 +436,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
module_.decrement_outstanding_references_for(target, ValueNS);
|
||||
module_.decrement_outstanding_references_for(target, TypeNS);
|
||||
|
||||
let def_and_priv = |binding: &NameBinding| {
|
||||
let last_private =
|
||||
if binding.is_public() { lp } else { DependsOn(binding.local_def_id().unwrap()) };
|
||||
(binding.def().unwrap(), last_private)
|
||||
let def = match type_result.success().and_then(NameBinding::def) {
|
||||
Some(def) => def,
|
||||
None => value_result.success().and_then(NameBinding::def).unwrap(),
|
||||
};
|
||||
let value_def_and_priv = value_result.success().map(&def_and_priv);
|
||||
let type_def_and_priv = type_result.success().map(&def_and_priv);
|
||||
|
||||
let import_lp = LastImport {
|
||||
value_priv: value_def_and_priv.map(|(_, p)| p),
|
||||
value_used: Used,
|
||||
type_priv: type_def_and_priv.map(|(_, p)| p),
|
||||
type_used: Used,
|
||||
};
|
||||
|
||||
let write_path_resolution = |(def, _)| {
|
||||
let path_resolution =
|
||||
PathResolution { base_def: def, last_private: import_lp, depth: 0 };
|
||||
self.resolver.def_map.borrow_mut().insert(directive.id, path_resolution);
|
||||
};
|
||||
value_def_and_priv.map(&write_path_resolution);
|
||||
type_def_and_priv.map(&write_path_resolution);
|
||||
let path_resolution = PathResolution { base_def: def, depth: 0 };
|
||||
self.resolver.def_map.borrow_mut().insert(directive.id, path_resolution);
|
||||
|
||||
debug!("(resolving single import) successfully resolved import");
|
||||
return Success(());
|
||||
|
|
@ -484,8 +454,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
fn resolve_glob_import(&mut self,
|
||||
module_: Module<'b>,
|
||||
target_module: Module<'b>,
|
||||
directive: &ImportDirective,
|
||||
lp: LastPrivate)
|
||||
directive: &ImportDirective)
|
||||
-> ResolveResult<()> {
|
||||
// We must bail out if the node has unresolved imports of any kind (including globs).
|
||||
if target_module.pub_count.get() > 0 {
|
||||
|
|
@ -521,7 +490,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
|
|||
self.resolver.def_map.borrow_mut().insert(directive.id,
|
||||
PathResolution {
|
||||
base_def: Def::Mod(did),
|
||||
last_private: lp,
|
||||
depth: 0,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ use middle::const_eval::EvalHint::UncheckedExprHint;
|
|||
use middle::def::{self, Def};
|
||||
use middle::def_id::DefId;
|
||||
use middle::resolve_lifetime as rl;
|
||||
use middle::privacy::{AllPublic, LastMod};
|
||||
use middle::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs, ParamSpace};
|
||||
use middle::traits;
|
||||
use middle::ty::{self, Ty, ToPredicate, TypeFoldable};
|
||||
|
|
@ -1650,7 +1649,6 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
// Create some fake resolution that can't possibly be a type.
|
||||
def::PathResolution {
|
||||
base_def: Def::Mod(tcx.map.local_def_id(ast::CRATE_NODE_ID)),
|
||||
last_private: LastMod(AllPublic),
|
||||
depth: path.segments.len()
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1674,7 +1672,6 @@ pub fn ast_ty_to_ty<'tcx>(this: &AstConv<'tcx>,
|
|||
// Write back the new resolution.
|
||||
tcx.def_map.borrow_mut().insert(ast_ty.id, def::PathResolution {
|
||||
base_def: def,
|
||||
last_private: path_res.last_private,
|
||||
depth: 0
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ use middle::def::{self, Def};
|
|||
use middle::infer::{self, TypeOrigin};
|
||||
use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding};
|
||||
use middle::pat_util::pat_is_resolved_const;
|
||||
use middle::privacy::{AllPublic, LastMod};
|
||||
use middle::subst::Substs;
|
||||
use middle::ty::{self, Ty, TypeFoldable, LvaluePreference};
|
||||
use check::{check_expr, check_expr_has_type, check_expr_with_expectation};
|
||||
|
|
@ -219,7 +218,6 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
|
|||
let sentinel = fcx.tcx().map.local_def_id(ast::CRATE_NODE_ID);
|
||||
def::PathResolution {
|
||||
base_def: Def::Mod(sentinel),
|
||||
last_private: LastMod(AllPublic),
|
||||
depth: path.segments.len()
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use astconv::AstConv;
|
|||
use check::FnCtxt;
|
||||
use middle::def::Def;
|
||||
use middle::def_id::DefId;
|
||||
use middle::privacy::{AllPublic, DependsOn, LastPrivate, LastMod};
|
||||
use middle::subst;
|
||||
use middle::traits;
|
||||
use middle::ty::{self, ToPredicate, ToPolyTraitRef, TraitRef, TypeFoldable};
|
||||
|
|
@ -334,18 +333,11 @@ pub fn resolve_ufcs<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
method_name: ast::Name,
|
||||
self_ty: ty::Ty<'tcx>,
|
||||
expr_id: ast::NodeId)
|
||||
-> Result<(Def, LastPrivate), MethodError<'tcx>>
|
||||
-> Result<Def, MethodError<'tcx>>
|
||||
{
|
||||
let mode = probe::Mode::Path;
|
||||
let pick = try!(probe::probe(fcx, span, mode, method_name, self_ty, expr_id));
|
||||
let def_result = pick.item.def();
|
||||
let mut lp = LastMod(AllPublic);
|
||||
if let probe::InherentImplPick = pick.kind {
|
||||
if pick.item.vis() != hir::Public {
|
||||
lp = LastMod(DependsOn(def_result.def_id()));
|
||||
}
|
||||
}
|
||||
Ok((def_result, lp))
|
||||
Ok(pick.item.def())
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,6 @@ use middle::def_id::DefId;
|
|||
use middle::infer;
|
||||
use middle::infer::{TypeOrigin, type_variable};
|
||||
use middle::pat_util::{self, pat_id_map};
|
||||
use middle::privacy::{AllPublic, LastMod};
|
||||
use middle::subst::{self, Subst, Substs, VecPerParamSpace, ParamSpace};
|
||||
use middle::traits::{self, report_fulfillment_errors};
|
||||
use middle::ty::{GenericPredicates, TypeScheme};
|
||||
|
|
@ -3364,7 +3363,6 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
|||
// Create some fake resolution that can't possibly be a type.
|
||||
def::PathResolution {
|
||||
base_def: Def::Mod(tcx.map.local_def_id(ast::CRATE_NODE_ID)),
|
||||
last_private: LastMod(AllPublic),
|
||||
depth: path.segments.len()
|
||||
}
|
||||
} else {
|
||||
|
|
@ -3803,12 +3801,11 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
|
|||
let item_segment = path.segments.last().unwrap();
|
||||
let item_name = item_segment.identifier.name;
|
||||
match method::resolve_ufcs(fcx, span, item_name, ty, node_id) {
|
||||
Ok((def, lp)) => {
|
||||
Ok(def) => {
|
||||
// Write back the new resolution.
|
||||
fcx.ccx.tcx.def_map.borrow_mut()
|
||||
.insert(node_id, def::PathResolution {
|
||||
base_def: def,
|
||||
last_private: path_res.last_private.or(lp),
|
||||
depth: 0
|
||||
});
|
||||
Some((Some(ty), slice::ref_slice(item_segment), def))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue