// 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;
#[derive(Copy, Clone, Debug)]
pub struct PathResolution {
pub base_def: Def,
- pub last_private: LastPrivate,
pub depth: usize
}
}
pub fn new(base_def: Def,
- last_private: LastPrivate,
depth: usize)
-> PathResolution {
PathResolution {
base_def: base_def,
- last_private: last_private,
depth: depth,
}
}
//! 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;
/// 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,
- }
- }
-}
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};
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
});
}
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};
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);
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 {
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) {
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);
- }
}
////////////////////////////////////////////////////////////////////////////////
use Namespace::{TypeNS, ValueNS};
use rustc::lint;
-use rustc::middle::privacy::{DependsOn, LastImport, Used, Unused};
use syntax::ast;
use syntax::codemap::{Span, DUMMY_SP};
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,
- };
}
}
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};
#[derive(Copy, Clone)]
enum BareIdentifierPatternResolution {
- FoundStructOrEnumVariant(Def, LastPrivate),
- FoundConst(Def, LastPrivate, Name),
+ FoundStructOrEnumVariant(Def),
+ FoundConst(Def, Name),
BareIdentifierPatternUnresolved,
}
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,
}
}
- 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)
}
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()
}
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),
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
// 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)));
index += 1;
}
- return Success((search_module, closest_private));
+ return Success(search_module);
}
/// Attempts to resolve the module part of an import directive or path
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 `{}`",
let search_module;
let start_index;
- let last_private;
match module_prefix_result {
Failed(None) => {
let mpath = names_to_string(module_path);
// 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
Some(containing_module) => {
search_module = containing_module;
start_index = 1;
- last_private = LastMod(AllPublic);
}
None => return Failed(None),
}
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
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,
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);
self.record_def(pattern.id,
PathResolution {
base_def: def,
- last_private: lp,
depth: 0,
});
}
);
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,
self.record_def(pattern.id,
PathResolution {
base_def: def,
- last_private: LastMod(AllPublic),
depth: 0,
});
// 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);
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);
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,
span: Span,
segments: &[hir::PathSegment],
namespace: Namespace)
- -> Option<(Def, LastPrivate)> {
+ -> Option<Def> {
let module_path = segments.split_last()
.unwrap()
.1
.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) => {
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
span: Span,
segments: &[hir::PathSegment],
namespace: Namespace)
- -> Option<(Def, LastPrivate)> {
+ -> Option<Def> {
let module_path = segments.split_last()
.unwrap()
.1
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),
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,
.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()
}
}
self.record_def(expr.id,
PathResolution {
base_def: def,
- last_private: LastMod(AllPublic),
depth: 0,
})
}
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,
fn err_path_resolution() -> PathResolution {
PathResolution {
base_def: Def::Err,
- last_private: LastMod(AllPublic),
depth: 0,
}
}
use rustc::lint;
use rustc::middle::def::*;
-use rustc::middle::privacy::*;
use syntax::ast::{NodeId, Name};
use syntax::attr::AttrMetaMethods;
&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 {
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(|()| {
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.
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 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);
+ let def = match type_result.success().and_then(NameBinding::def) {
+ Some(def) => def,
+ None => value_result.success().and_then(NameBinding::def).unwrap(),
};
- 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(());
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 {
self.resolver.def_map.borrow_mut().insert(directive.id,
PathResolution {
base_def: Def::Mod(did),
- last_private: lp,
depth: 0,
});
}
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};
// 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 {
// 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
});
}
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};
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 {
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};
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())
}
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};
// 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 {
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))