提交 ae8ba884 编写于 作者: N Nick Cameron

Mostly non-behaviour-changing changes (style, etc.)

上级 397dda8a
......@@ -435,7 +435,7 @@ pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
}
// Something that a name can resolve to.
#[deriving(Clone)]
#[deriving(Clone,Show)]
pub enum DefLike {
DlDef(def::Def),
DlImpl(ast::DefId),
......
......@@ -108,7 +108,7 @@ impl Copy for binding_info {}
pub struct Export2 {
pub name: String, // The name of the target.
pub def_id: DefId, // The definition of the target.
pub def_id: DefId, // The definition of the target.
}
// This set contains all exported definitions from external crates. The set does
......@@ -314,7 +314,7 @@ impl<'a> Copy for TypeParameters<'a> {}
// The rib kind controls the translation of local
// definitions (`DefLocal`) to upvars (`DefUpvar`).
#[deriving(Show)]
enum RibKind {
// No translation needs to be applied.
NormalRibKind,
......@@ -340,6 +340,7 @@ enum RibKind {
impl Copy for RibKind {}
// Methods can be required or provided. RequiredMethod methods only occur in traits.
#[deriving(Show)]
enum MethodSort {
RequiredMethod,
ProvidedMethod(NodeId)
......@@ -414,6 +415,7 @@ enum DuplicateCheckingMode {
impl Copy for DuplicateCheckingMode {}
/// One local scope.
#[deriving(Show)]
struct Rib {
bindings: HashMap<Name, DefLike>,
kind: RibKind,
......@@ -728,8 +730,11 @@ fn set_module_kind(&self,
let type_def = self.type_def.borrow().clone();
match type_def {
None => {
let module = Module::new(parent_link, def_id, kind,
external, is_public);
let module = Module::new(parent_link,
def_id,
kind,
external,
is_public);
*self.type_def.borrow_mut() = Some(TypeNsDef {
modifiers: modifiers,
module_def: Some(Rc::new(module)),
......@@ -774,9 +779,9 @@ fn define_type(&self, def: Def, sp: Span, modifiers: DefModifiers) {
}
Some(type_def) => {
*self.type_def.borrow_mut() = Some(TypeNsDef {
module_def: type_def.module_def,
type_def: Some(def),
type_span: Some(sp),
module_def: type_def.module_def,
modifiers: modifiers,
});
}
......@@ -1286,7 +1291,7 @@ fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
}
fn get_parent_link(&mut self, parent: ReducedGraphParent, name: Name)
-> ParentLink {
-> ParentLink {
match parent {
ModuleReducedGraphParent(module_) => {
return ModuleParentLink(module_.downgrade(), name);
......@@ -1578,14 +1583,14 @@ fn build_reduced_graph_for_item(&mut self,
ItemImpl(_, Some(_), _, _) => parent,
ItemTrait(_, _, _, ref methods) => {
ItemTrait(_, _, _, ref items) => {
let name_bindings =
self.add_child(name,
parent.clone(),
ForbidDuplicateTypesAndModules,
sp);
// Add all the methods within to a new module.
// Add all the items within to a new module.
let parent_link = self.get_parent_link(parent.clone(), name);
name_bindings.define_module(parent_link,
Some(local_def(item.id)),
......@@ -1598,13 +1603,12 @@ fn build_reduced_graph_for_item(&mut self,
let def_id = local_def(item.id);
// Add the names of all the methods to the trait info.
for method in methods.iter() {
let (name, kind) = match *method {
// Add the names of all the items to the trait info.
for trait_item in items.iter() {
let (name, kind) = match *trait_item {
ast::RequiredMethod(_) |
ast::ProvidedMethod(_) => {
let ty_m =
ast_util::trait_item_to_ty_method(method);
let ty_m = ast_util::trait_item_to_ty_method(trait_item);
let name = ty_m.ident.name;
......@@ -3353,7 +3357,7 @@ fn resolve_module_path(&mut self,
use_lexical_scope: UseLexicalScopeFlag,
span: Span,
name_search_type: NameSearchType)
-> ResolveResult<(Rc<Module>, LastPrivate)> {
-> ResolveResult<(Rc<Module>, LastPrivate)> {
let module_path_len = module_path.len();
assert!(module_path_len > 0);
......@@ -3382,7 +3386,9 @@ fn resolve_module_path(&mut self,
mpath.slice_to(idx - 1));
return Failed(Some((span, msg)));
},
None => return Failed(None),
None => {
return Failed(None)
}
}
}
Failed(err) => return Failed(err),
......@@ -3575,8 +3581,7 @@ fn resolve_module_in_lexical_scope(&mut self,
-> ResolveResult<Rc<Module>> {
// If this module is an anonymous module, resolve the item in the
// lexical scope. Otherwise, resolve the item from the crate root.
let resolve_result = self.resolve_item_in_lexical_scope(
module_, name, TypeNS);
let resolve_result = self.resolve_item_in_lexical_scope(module_, name, TypeNS);
match resolve_result {
Success((target, _)) => {
let bindings = &*target.bindings;
......@@ -5327,15 +5332,15 @@ fn resolve_path(&mut self,
// resolve a single identifier (used as a varref)
fn resolve_identifier(&mut self,
identifier: Ident,
namespace: Namespace,
check_ribs: bool,
span: Span)
-> Option<(Def, LastPrivate)> {
identifier: Ident,
namespace: Namespace,
check_ribs: bool,
span: Span)
-> Option<(Def, LastPrivate)> {
if check_ribs {
match self.resolve_identifier_in_local_ribs(identifier,
namespace,
span) {
namespace,
span) {
Some(def) => {
return Some((def, LastMod(AllPublic)));
}
......@@ -5353,7 +5358,7 @@ fn resolve_definition_of_name_in_module(&mut self,
containing_module: Rc<Module>,
name: Name,
namespace: Namespace)
-> NameDefinition {
-> NameDefinition {
// First, search children.
self.populate_module_if_necessary(&containing_module);
......@@ -5423,9 +5428,9 @@ fn resolve_definition_of_name_in_module(&mut self,
// resolve a "module-relative" path, e.g. a::b::c
fn resolve_module_relative_path(&mut self,
path: &Path,
namespace: Namespace)
-> Option<(Def, LastPrivate)> {
path: &Path,
namespace: Namespace)
-> Option<(Def, LastPrivate)> {
let module_path = path.segments.init().iter()
.map(|ps| ps.identifier.name)
.collect::<Vec<_>>();
......@@ -5442,9 +5447,8 @@ fn resolve_module_relative_path(&mut self,
let (span, msg) = match err {
Some((span, msg)) => (span, msg),
None => {
let msg = format!("Use of undeclared module `{}`",
self.names_to_string(
module_path.as_slice()));
let msg = format!("Use of undeclared type or module `{}`",
self.names_to_string(module_path.as_slice()));
(path.span, msg)
}
};
......@@ -5538,10 +5542,10 @@ fn resolve_crate_relative_path(&mut self,
}
fn resolve_identifier_in_local_ribs(&mut self,
ident: Ident,
namespace: Namespace,
span: Span)
-> Option<Def> {
ident: Ident,
namespace: Namespace,
span: Span)
-> Option<Def> {
// Check the local set of ribs.
let search_result = match namespace {
ValueNS => {
......
......@@ -112,7 +112,7 @@ pub fn has_regions_escaping_depth(&self, depth: uint) -> bool {
}
}
pub fn self_ty(&self) -> Option<Ty<'tcx>> {
pub fn self_ty(&self) -> Option<Ty<'tcx>> {
self.types.get_self().map(|&t| t)
}
......
......@@ -139,7 +139,7 @@ fn next(&mut self) -> Option<Rc<ty::TraitRef<'tcx>>> {
}
// determine the `self` type, using fresh variables for all variables
// declared on the impl declaration e.g., `impl<A,B> for ~[(A,B)]`
// declared on the impl declaration e.g., `impl<A,B> for Box<[(A,B)]>`
// would return ($0, $1) where $0 and $1 are freshly instantiated type
// variables.
pub fn fresh_substs_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
......
......@@ -1613,7 +1613,7 @@ pub struct RegionParameterDef {
pub bounds: Vec<ty::Region>,
}
/// Information about the type/lifetime parameters associated with an
/// Information about the formal type/lifetime parameters associated with an
/// item or method. Analogous to ast::Generics.
#[deriving(Clone, Show)]
pub struct Generics<'tcx> {
......
......@@ -522,16 +522,6 @@ fn convert_parenthesized_parameters<'tcx,AC>(this: &AC,
vec![input_ty, output]
}
pub fn instantiate_poly_trait_ref<'tcx,AC,RS>(
this: &AC,
rscope: &RS,
ast_trait_ref: &ast::PolyTraitRef,
self_ty: Option<Ty<'tcx>>)
-> Rc<ty::TraitRef<'tcx>>
where AC: AstConv<'tcx>, RS: RegionScope
{
instantiate_trait_ref(this, rscope, &ast_trait_ref.trait_ref, self_ty)
}
/// Instantiates the path for the given trait reference, assuming that it's bound to a valid trait
/// type. Returns the def_id for the defining trait. Fails if the type is a type other than a trait
......@@ -637,7 +627,6 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
rscope,
did,
&generics,
None,
path);
let ty = decl_ty.subst(tcx, &substs);
TypeAndSubsts { substs: substs, ty: ty }
......@@ -678,7 +667,7 @@ pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>(
Substs::new(VecPerParamSpace::params_from_type(type_params),
VecPerParamSpace::params_from_type(region_params))
} else {
ast_path_substs_for_ty(this, rscope, did, &generics, None, path)
ast_path_substs_for_ty(this, rscope, did, &generics, path)
};
let ty = decl_ty.subst(tcx, &substs);
......@@ -777,7 +766,7 @@ fn ast_ty_to_trait_ref<'tcx,AC,RS>(this: &AC,
}
}
_ => {
span_err!(this.tcx().sess, ty.span, E0171,
span_err!(this.tcx().sess, ty.span, E0178,
"expected a path on the left-hand side of `+`, not `{}`",
pprust::ty_to_string(ty));
match ty.node {
......@@ -788,8 +777,7 @@ fn ast_ty_to_trait_ref<'tcx,AC,RS>(this: &AC,
pprust::ty_to_string(&*mut_ty.ty),
pprust::bounds_to_string(bounds));
}
ast::TyRptr(Some(ref lt), ref mut_ty) => {
ast::TyRptr(Some(ref lt), ref mut_ty) => {
span_note!(this.tcx().sess, ty.span,
"perhaps you meant `&{} {}({} +{})`? (per RFC 248)",
pprust::lifetime_to_string(lt),
......@@ -806,7 +794,6 @@ fn ast_ty_to_trait_ref<'tcx,AC,RS>(this: &AC,
Err(ErrorReported)
}
}
}
fn trait_ref_to_object_type<'tcx,AC,RS>(this: &AC,
......
......@@ -1020,7 +1020,7 @@ fn get_method_index<'tcx>(tcx: &ty::ctxt<'tcx>,
// iterating down the supertraits of the object's trait until
// we find the trait the method came from, counting up the
// methods from them.
let mut method_count = 0;
let mut method_count = n_method;
ty::each_bound_trait_and_supertraits(tcx, &[subtrait], |bound_ref| {
if bound_ref.def_id == trait_ref.def_id {
false
......@@ -1035,7 +1035,7 @@ fn get_method_index<'tcx>(tcx: &ty::ctxt<'tcx>,
true
}
});
method_count + n_method
method_count
}
impl<'tcx> Candidate<'tcx> {
......
......@@ -5355,6 +5355,7 @@ fn push_explicit_angle_bracketed_parameters_from_segment_to_substs<'a, 'tcx>(
region_count,
data.lifetimes.len());
substs.mut_regions().truncate(space, 0);
break;
}
}
}
......
......@@ -663,48 +663,43 @@ fn is_associated_type_valid_for_param(ty: Ty,
fn find_associated_type_in_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
span: Span,
ty: Option<Ty<'tcx>>,
self_ty: Option<Ty<'tcx>>,
associated_type_id: ast::DefId,
generics: &ty::Generics<'tcx>)
-> Ty<'tcx>
-> Option<Ty<'tcx>>
{
debug!("find_associated_type_in_generics(ty={}, associated_type_id={}, generics={}",
ty.repr(tcx), associated_type_id.repr(tcx), generics.repr(tcx));
self_ty.repr(tcx), associated_type_id.repr(tcx), generics.repr(tcx));
let ty = match ty {
let self_ty = match self_ty {
None => {
tcx.sess.span_bug(span,
"find_associated_type_in_generics(): no self \
type")
return None;
}
Some(ty) => ty,
};
match ty.sty {
match self_ty.sty {
ty::ty_param(ref param_ty) => {
/*let type_parameter = generics.types.get(param_ty.space,
param_ty.idx);
let param_id = type_parameter.def_id;*/
let param_id = param_ty.def_id;
for type_parameter in generics.types.iter() {
if type_parameter.def_id == associated_type_id
&& type_parameter.associated_with == Some(param_id) {
return ty::mk_param_from_def(tcx, type_parameter);
return Some(ty::mk_param_from_def(tcx, type_parameter));
}
}
tcx.sess.span_err(
span,
format!("no suitable bound on `{}`",
ty.user_string(tcx))[]);
ty::mk_err()
self_ty.user_string(tcx))[]);
Some(ty::mk_err())
}
_ => {
tcx.sess.span_err(
span,
"it is currently unsupported to access associated types except \
through a type parameter; this restriction will be lifted in time");
ty::mk_err()
Some(ty::mk_err())
}
}
}
......@@ -762,16 +757,16 @@ fn associated_types_of_trait_are_valid(&self,
fn associated_type_binding(&self,
span: Span,
ty: Option<Ty<'tcx>>,
self_ty: Option<Ty<'tcx>>,
trait_id: ast::DefId,
associated_type_id: ast::DefId)
-> Ty<'tcx>
-> Option<Ty<'tcx>>
{
let trait_def = ty::lookup_trait_def(self.tcx(), trait_id);
match self.opt_trait_ref_id {
// It's an associated type on the trait that we're
// implementing.
Some(trait_ref_id) if trait_ref_id == trait_id => {
// It's an associated type on the trait that we're
// implementing.
let trait_def = ty::lookup_trait_def(self.tcx(), trait_id);
assert!(trait_def.generics.types
.get_slice(subst::AssocSpace)
.iter()
......@@ -801,7 +796,7 @@ fn associated_type_binding(&self,
// our bounds.
find_associated_type_in_generics(self.ccx.tcx,
span,
ty,
self_ty,
associated_type_id,
self.impl_generics)
}
......@@ -840,17 +835,17 @@ fn associated_types_of_trait_are_valid(&self,
fn associated_type_binding(&self,
span: Span,
ty: Option<Ty<'tcx>>,
self_ty: Option<Ty<'tcx>>,
_: ast::DefId,
associated_type_id: ast::DefId)
-> Ty<'tcx> {
-> Option<Ty<'tcx>> {
debug!("collect::FnCtxt::associated_type_binding()");
// The ID should map to an associated type on one of the traits in
// our bounds.
find_associated_type_in_generics(self.ccx.tcx,
span,
ty,
self_ty,
associated_type_id,
self.generics)
}
......@@ -887,17 +882,17 @@ fn associated_types_of_trait_are_valid(&self,
fn associated_type_binding(&self,
span: Span,
ty: Option<Ty<'tcx>>,
self_ty: Option<Ty<'tcx>>,
_: ast::DefId,
associated_type_id: ast::DefId)
-> Ty<'tcx> {
-> Option<Ty<'tcx>> {
debug!("collect::ImplMethodCtxt::associated_type_binding()");
// The ID should map to an associated type on one of the traits in
// our bounds.
find_associated_type_in_generics(self.ccx.tcx,
span,
ty,
self_ty,
associated_type_id,
self.method_generics)
}
......@@ -979,7 +974,7 @@ fn associated_type_binding(&self,
// our bounds.
find_associated_type_in_generics(self.ccx.tcx,
span,
ty,
self_ty,
associated_type_id,
self.method_generics)
}
......@@ -1020,17 +1015,17 @@ fn associated_types_of_trait_are_valid(&self,
fn associated_type_binding(&self,
span: Span,
ty: Option<Ty<'tcx>>,
self_ty: Option<Ty<'tcx>>,
_: ast::DefId,
associated_type_id: ast::DefId)
-> Ty<'tcx> {
-> Option<Ty<'tcx>> {
debug!("collect::GenericsCtxt::associated_type_binding()");
// The ID should map to an associated type on one of the traits in
// our bounds.
find_associated_type_in_generics(self.chain.tcx(),
span,
ty,
self_ty,
associated_type_id,
self.associated_types_generics)
}
......@@ -1364,8 +1359,12 @@ pub fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let self_param_ty = ty::ParamTy::for_self(def_id);
let bounds = compute_bounds(ccx, token::SELF_KEYWORD_NAME, self_param_ty,
bounds.as_slice(), unbound, it.span,
let bounds = compute_bounds(ccx,
token::SELF_KEYWORD_NAME,
self_param_ty,
bounds.as_slice(),
unbound,
it.span,
&generics.where_clause);
let substs = mk_item_substs(ccx, &ty_generics);
......@@ -1791,7 +1790,7 @@ fn ty_generics<'tcx,AC>(this: &AC,
return result;
fn create_type_parameters_for_associated_types<'tcx,AC>(
fn create_type_parameters_for_associated_types<'tcx, AC>(
this: &AC,
space: subst::ParamSpace,
types: &[ast::TyParam],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册