mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 20:03:37 +00:00
rustc: de-@ ty::ParamBounds.
This commit is contained in:
parent
1a76ac320c
commit
811bbfc782
@ -18,6 +18,7 @@
|
||||
|
||||
use middle::ty;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::str;
|
||||
use std::strbuf::StrBuf;
|
||||
use std::uint;
|
||||
@ -563,7 +564,7 @@ fn parse_type_param_def(st: &mut PState, conv: conv_did) -> ty::TypeParameterDef
|
||||
ty::TypeParameterDef {
|
||||
ident: parse_ident(st, ':'),
|
||||
def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
|
||||
bounds: @parse_bounds(st, |x,y| conv(x,y)),
|
||||
bounds: Rc::new(parse_bounds(st, |x,y| conv(x,y))),
|
||||
default: parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)))
|
||||
}
|
||||
}
|
||||
|
@ -376,6 +376,6 @@ fn enc_bounds(w: &mut MemWriter, cx: &ctxt, bs: &ty::ParamBounds) {
|
||||
|
||||
pub fn enc_type_param_def(w: &mut MemWriter, cx: &ctxt, v: &ty::TypeParameterDef) {
|
||||
mywrite!(w, "{}:{}|", token::get_ident(v.ident), (cx.ds)(v.def_id));
|
||||
enc_bounds(w, cx, v.bounds);
|
||||
enc_bounds(w, cx, &*v.bounds);
|
||||
enc_opt(w, v.default, |w, t| enc_ty(w, cx, t));
|
||||
}
|
||||
|
@ -833,7 +833,8 @@ pub enum type_err {
|
||||
#[deriving(Eq, TotalEq, Hash)]
|
||||
pub struct ParamBounds {
|
||||
pub builtin_bounds: BuiltinBounds,
|
||||
pub trait_bounds: Vec<@TraitRef> }
|
||||
pub trait_bounds: Vec<@TraitRef>
|
||||
}
|
||||
|
||||
pub type BuiltinBounds = EnumSet<BuiltinBound>;
|
||||
|
||||
@ -987,7 +988,7 @@ impl fmt::Show for IntVarValue {
|
||||
pub struct TypeParameterDef {
|
||||
pub ident: ast::Ident,
|
||||
pub def_id: ast::DefId,
|
||||
pub bounds: @ParamBounds,
|
||||
pub bounds: Rc<ParamBounds>,
|
||||
pub default: Option<ty::t>
|
||||
}
|
||||
|
||||
|
@ -342,10 +342,10 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
|
||||
new_type_param_defs.push(ty::TypeParameterDef {
|
||||
ident: special_idents::self_,
|
||||
def_id: dummy_defid,
|
||||
bounds: @ty::ParamBounds {
|
||||
bounds: Rc::new(ty::ParamBounds {
|
||||
builtin_bounds: ty::EmptyBuiltinBounds(),
|
||||
trait_bounds: vec!(self_trait_ref)
|
||||
},
|
||||
}),
|
||||
default: None
|
||||
});
|
||||
|
||||
@ -999,24 +999,24 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ty_generics_for_type(ccx: &CrateCtxt,
|
||||
generics: &ast::Generics)
|
||||
-> ty::Generics {
|
||||
fn ty_generics_for_type(ccx: &CrateCtxt,
|
||||
generics: &ast::Generics)
|
||||
-> ty::Generics {
|
||||
ty_generics(ccx, &generics.lifetimes, &generics.ty_params, 0)
|
||||
}
|
||||
|
||||
pub fn ty_generics_for_fn_or_method(ccx: &CrateCtxt,
|
||||
generics: &ast::Generics,
|
||||
base_index: uint)
|
||||
-> ty::Generics {
|
||||
fn ty_generics_for_fn_or_method(ccx: &CrateCtxt,
|
||||
generics: &ast::Generics,
|
||||
base_index: uint)
|
||||
-> ty::Generics {
|
||||
let early_lifetimes = resolve_lifetime::early_bound_lifetimes(generics);
|
||||
ty_generics(ccx, &early_lifetimes, &generics.ty_params, base_index)
|
||||
}
|
||||
|
||||
pub fn ty_generics(ccx: &CrateCtxt,
|
||||
lifetimes: &Vec<ast::Lifetime>,
|
||||
ty_params: &OwnedSlice<ast::TyParam>,
|
||||
base_index: uint) -> ty::Generics {
|
||||
fn ty_generics(ccx: &CrateCtxt,
|
||||
lifetimes: &Vec<ast::Lifetime>,
|
||||
ty_params: &OwnedSlice<ast::TyParam>,
|
||||
base_index: uint) -> ty::Generics {
|
||||
return ty::Generics {
|
||||
region_param_defs: Rc::new(lifetimes.iter().map(|l| {
|
||||
ty::RegionParameterDef { name: l.name,
|
||||
@ -1025,12 +1025,12 @@ pub fn ty_generics(ccx: &CrateCtxt,
|
||||
type_param_defs: Rc::new(ty_params.iter().enumerate().map(|(offset, param)| {
|
||||
let existing_def_opt = {
|
||||
let ty_param_defs = ccx.tcx.ty_param_defs.borrow();
|
||||
ty_param_defs.find(¶m.id).map(|&def| def)
|
||||
ty_param_defs.find(¶m.id).map(|def| def.clone())
|
||||
};
|
||||
existing_def_opt.unwrap_or_else(|| {
|
||||
let param_ty = ty::param_ty {idx: base_index + offset,
|
||||
def_id: local_def(param.id)};
|
||||
let bounds = @compute_bounds(ccx, param_ty, ¶m.bounds);
|
||||
let bounds = Rc::new(compute_bounds(ccx, param_ty, ¶m.bounds));
|
||||
let default = param.default.map(|path| {
|
||||
let ty = ast_ty_to_ty(ccx, &ExplicitRscope, path);
|
||||
let cur_idx = param_ty.idx;
|
||||
@ -1056,7 +1056,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
|
||||
default: default
|
||||
};
|
||||
debug!("def for param: {}", def.repr(ccx.tcx));
|
||||
ccx.tcx.ty_param_defs.borrow_mut().insert(param.id, def);
|
||||
ccx.tcx.ty_param_defs.borrow_mut().insert(param.id, def.clone());
|
||||
def
|
||||
})
|
||||
}).collect()),
|
||||
|
Loading…
Reference in New Issue
Block a user