提交 bdf5b6c3 编写于 作者: B Ben Gamari

middle: Derive Show impls

And change some uses of the `{:?}` format string to `{}`.
上级 69ffcdcc
......@@ -14,7 +14,7 @@
use std::gc::Gc;
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum Def {
DefFn(ast::DefId, ast::FnStyle),
DefStaticMethod(/* method */ ast::DefId, MethodProvenance, ast::FnStyle),
......@@ -51,7 +51,7 @@ pub enum Def {
DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */),
}
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
pub enum MethodProvenance {
FromTrait(ast::DefId),
FromImpl(ast::DefId),
......
......@@ -121,7 +121,7 @@ fn check_impl_of_trait(cx: &mut Context, it: &Item, trait_ref: &TraitRef, self_t
// If this trait has builtin-kind supertraits, meet them.
let self_ty: ty::t = ty::node_id_to_type(cx.tcx, it.id);
debug!("checking impl with self type {:?}", ty::get(self_ty).sty);
debug!("checking impl with self type {}", ty::get(self_ty).sty);
check_builtin_bounds(cx, self_ty, trait_def.bounds, |missing| {
cx.tcx.sess.span_err(self_type.span,
format!("the type `{}', which does not fulfill `{}`, cannot implement this \
......
......@@ -15,6 +15,7 @@
use middle::ty_fold::{TypeFoldable, TypeFolder};
use util::ppaux::Repr;
use std::fmt;
use std::mem;
use std::raw;
use std::slice::{Items, MutItems};
......@@ -83,7 +84,7 @@ fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut T> {
* space* (which indices where the parameter is defined; see
* `ParamSpace`).
*/
#[deriving(Clone, PartialEq, Eq, Hash)]
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct Substs {
pub types: VecPerParamSpace<ty::t>,
pub regions: RegionSubsts,
......@@ -93,7 +94,7 @@ pub struct Substs {
* Represents the values to use when substituting lifetime parameters.
* If the value is `ErasedRegions`, then this subst is occurring during
* trans, and all region parameters will be replaced with `ty::ReStatic`. */
#[deriving(Clone, PartialEq, Eq, Hash)]
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub enum RegionSubsts {
ErasedRegions,
NonerasedRegions(VecPerParamSpace<ty::Region>)
......@@ -275,6 +276,17 @@ pub struct VecPerParamSpace<T> {
content: Vec<T>,
}
impl<T:fmt::Show> fmt::Show for VecPerParamSpace<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
try!(write!(fmt, "VecPerParamSpace {{"));
for space in ParamSpace::all().iter() {
try!(write!(fmt, "{}: {}, ", *space, self.get_slice(*space)));
}
try!(write!(fmt, "}}"));
Ok(())
}
}
impl<T:Clone> VecPerParamSpace<T> {
pub fn push_all(&mut self, space: ParamSpace, values: &[T]) {
// FIXME (#15435): slow; O(n^2); could enhance vec to make it O(n).
......
......@@ -124,7 +124,7 @@ pub fn container_id(&self) -> ast::DefId {
}
}
#[deriving(Clone, PartialEq, Eq, Hash)]
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct mt {
pub ty: t,
pub mutbl: ast::Mutability,
......@@ -138,7 +138,7 @@ pub enum TraitStore {
RegionTraitStore(Region, ast::Mutability),
}
#[deriving(Clone)]
#[deriving(Clone, Show)]
pub struct field_ty {
pub name: Name,
pub id: DefId,
......@@ -394,6 +394,7 @@ pub enum tbox_flag {
pub type t_box = &'static t_box_;
#[deriving(Show)]
pub struct t_box_ {
pub sty: sty,
pub id: uint,
......@@ -436,14 +437,14 @@ pub fn type_needs_infer(t: t) -> bool {
}
pub fn type_id(t: t) -> uint { get(t).id }
#[deriving(Clone, PartialEq, Eq, Hash)]
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct BareFnTy {
pub fn_style: ast::FnStyle,
pub abi: abi::Abi,
pub sig: FnSig,
}
#[deriving(Clone, PartialEq, Eq, Hash)]
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct ClosureTy {
pub fn_style: ast::FnStyle,
pub onceness: ast::Onceness,
......@@ -472,7 +473,7 @@ pub struct FnSig {
pub variadic: bool
}
#[deriving(Clone, PartialEq, Eq, Hash)]
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct ParamTy {
pub space: subst::ParamSpace,
pub idx: uint,
......@@ -712,7 +713,7 @@ mod primitives {
// NB: If you change this, you'll probably want to change the corresponding
// AST structure in libsyntax/ast.rs as well.
#[deriving(Clone, PartialEq, Eq, Hash)]
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub enum sty {
ty_nil,
ty_bot,
......@@ -741,14 +742,14 @@ pub enum sty {
// on non-useful type error messages)
}
#[deriving(Clone, PartialEq, Eq, Hash)]
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
pub struct TyTrait {
pub def_id: DefId,
pub substs: Substs,
pub bounds: BuiltinBounds
}
#[deriving(PartialEq, Eq, Hash)]
#[deriving(PartialEq, Eq, Hash, Show)]
pub struct TraitRef {
pub def_id: DefId,
pub substs: Substs,
......@@ -808,7 +809,7 @@ pub enum type_err {
terr_variadic_mismatch(expected_found<bool>)
}
#[deriving(PartialEq, Eq, Hash)]
#[deriving(PartialEq, Eq, Hash, Show)]
pub struct ParamBounds {
pub builtin_bounds: BuiltinBounds,
pub trait_bounds: Vec<Rc<TraitRef>>
......@@ -948,7 +949,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
}
#[deriving(Clone)]
#[deriving(Clone, Show)]
pub struct TypeParameterDef {
pub ident: ast::Ident,
pub def_id: ast::DefId,
......@@ -958,7 +959,7 @@ pub struct TypeParameterDef {
pub default: Option<ty::t>
}
#[deriving(Encodable, Decodable, Clone)]
#[deriving(Encodable, Decodable, Clone, Show)]
pub struct RegionParameterDef {
pub name: ast::Name,
pub def_id: ast::DefId,
......@@ -968,7 +969,7 @@ pub struct RegionParameterDef {
/// Information about the type/lifetime parameters associated with an
/// item or method. Analogous to ast::Generics.
#[deriving(Clone)]
#[deriving(Clone, Show)]
pub struct Generics {
pub types: VecPerParamSpace<TypeParameterDef>,
pub regions: VecPerParamSpace<RegionParameterDef>,
......@@ -1014,7 +1015,7 @@ pub struct ParameterEnvironment {
/// - `generics`: the set of type parameters and their bounds
/// - `ty`: the base types, which may reference the parameters defined
/// in `generics`
#[deriving(Clone)]
#[deriving(Clone, Show)]
pub struct Polytype {
pub generics: Generics,
pub ty: t
......
......@@ -141,7 +141,7 @@ pub fn opt_ast_region_to_region<AC:AstConv,RS:RegionScope>(
}
};
debug!("opt_ast_region_to_region(opt_lifetime={:?}) yields {}",
debug!("opt_ast_region_to_region(opt_lifetime={}) yields {}",
opt_lifetime.as_ref().map(|e| lifetime_to_string(e)),
r.repr(this.tcx()));
......@@ -504,6 +504,7 @@ pub fn ast_ty_to_builtin_ty<AC:AstConv,
}
}
#[deriving(Show)]
enum PointerTy {
Box,
RPtr(ty::Region),
......@@ -565,7 +566,7 @@ fn mk_pointer<AC:AstConv,
constr: |ty::t| -> ty::t)
-> ty::t {
let tcx = this.tcx();
debug!("mk_pointer(ptr_ty={:?})", ptr_ty);
debug!("mk_pointer(ptr_ty={})", ptr_ty);
match a_seq_ty.ty.node {
ast::TyVec(ref ty) => {
......
......@@ -246,7 +246,7 @@ pub fn new_region_var(&self, origin: RegionVariableOrigin) -> RegionVid {
if self.in_snapshot() {
self.undo_log.borrow_mut().push(AddVar(vid));
}
debug!("created new region variable {:?} with origin {:?}",
debug!("created new region variable {} with origin {}",
vid, origin.repr(self.tcx));
return vid;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册