middle: Derive Show impls
And change some uses of the `{:?}` format string to `{}`.
This commit is contained in:
parent
69ffcdcccf
commit
bdf5b6c3da
6 changed files with 35 additions and 21 deletions
|
@ -14,7 +14,7 @@ use syntax::ast_util::local_def;
|
||||||
|
|
||||||
use std::gc::Gc;
|
use std::gc::Gc;
|
||||||
|
|
||||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||||
pub enum Def {
|
pub enum Def {
|
||||||
DefFn(ast::DefId, ast::FnStyle),
|
DefFn(ast::DefId, ast::FnStyle),
|
||||||
DefStaticMethod(/* method */ ast::DefId, MethodProvenance, ast::FnStyle),
|
DefStaticMethod(/* method */ ast::DefId, MethodProvenance, ast::FnStyle),
|
||||||
|
@ -51,7 +51,7 @@ pub enum Def {
|
||||||
DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */),
|
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 {
|
pub enum MethodProvenance {
|
||||||
FromTrait(ast::DefId),
|
FromTrait(ast::DefId),
|
||||||
FromImpl(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.
|
// If this trait has builtin-kind supertraits, meet them.
|
||||||
let self_ty: ty::t = ty::node_id_to_type(cx.tcx, it.id);
|
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| {
|
check_builtin_bounds(cx, self_ty, trait_def.bounds, |missing| {
|
||||||
cx.tcx.sess.span_err(self_type.span,
|
cx.tcx.sess.span_err(self_type.span,
|
||||||
format!("the type `{}', which does not fulfill `{}`, cannot implement this \
|
format!("the type `{}', which does not fulfill `{}`, cannot implement this \
|
||||||
|
|
|
@ -15,6 +15,7 @@ use middle::ty_fold;
|
||||||
use middle::ty_fold::{TypeFoldable, TypeFolder};
|
use middle::ty_fold::{TypeFoldable, TypeFolder};
|
||||||
use util::ppaux::Repr;
|
use util::ppaux::Repr;
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::raw;
|
use std::raw;
|
||||||
use std::slice::{Items, MutItems};
|
use std::slice::{Items, MutItems};
|
||||||
|
@ -83,7 +84,7 @@ impl<T> HomogeneousTuple3<T> for (T, T, T) {
|
||||||
* space* (which indices where the parameter is defined; see
|
* space* (which indices where the parameter is defined; see
|
||||||
* `ParamSpace`).
|
* `ParamSpace`).
|
||||||
*/
|
*/
|
||||||
#[deriving(Clone, PartialEq, Eq, Hash)]
|
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
|
||||||
pub struct Substs {
|
pub struct Substs {
|
||||||
pub types: VecPerParamSpace<ty::t>,
|
pub types: VecPerParamSpace<ty::t>,
|
||||||
pub regions: RegionSubsts,
|
pub regions: RegionSubsts,
|
||||||
|
@ -93,7 +94,7 @@ pub struct Substs {
|
||||||
* Represents the values to use when substituting lifetime parameters.
|
* Represents the values to use when substituting lifetime parameters.
|
||||||
* If the value is `ErasedRegions`, then this subst is occurring during
|
* If the value is `ErasedRegions`, then this subst is occurring during
|
||||||
* trans, and all region parameters will be replaced with `ty::ReStatic`. */
|
* 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 {
|
pub enum RegionSubsts {
|
||||||
ErasedRegions,
|
ErasedRegions,
|
||||||
NonerasedRegions(VecPerParamSpace<ty::Region>)
|
NonerasedRegions(VecPerParamSpace<ty::Region>)
|
||||||
|
@ -275,6 +276,17 @@ pub struct VecPerParamSpace<T> {
|
||||||
content: Vec<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> {
|
impl<T:Clone> VecPerParamSpace<T> {
|
||||||
pub fn push_all(&mut self, space: ParamSpace, values: &[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).
|
// FIXME (#15435): slow; O(n^2); could enhance vec to make it O(n).
|
||||||
|
|
|
@ -124,7 +124,7 @@ impl Method {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, PartialEq, Eq, Hash)]
|
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
|
||||||
pub struct mt {
|
pub struct mt {
|
||||||
pub ty: t,
|
pub ty: t,
|
||||||
pub mutbl: ast::Mutability,
|
pub mutbl: ast::Mutability,
|
||||||
|
@ -138,7 +138,7 @@ pub enum TraitStore {
|
||||||
RegionTraitStore(Region, ast::Mutability),
|
RegionTraitStore(Region, ast::Mutability),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone, Show)]
|
||||||
pub struct field_ty {
|
pub struct field_ty {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub id: DefId,
|
pub id: DefId,
|
||||||
|
@ -394,6 +394,7 @@ pub enum tbox_flag {
|
||||||
|
|
||||||
pub type t_box = &'static t_box_;
|
pub type t_box = &'static t_box_;
|
||||||
|
|
||||||
|
#[deriving(Show)]
|
||||||
pub struct t_box_ {
|
pub struct t_box_ {
|
||||||
pub sty: sty,
|
pub sty: sty,
|
||||||
pub id: uint,
|
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 }
|
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 struct BareFnTy {
|
||||||
pub fn_style: ast::FnStyle,
|
pub fn_style: ast::FnStyle,
|
||||||
pub abi: abi::Abi,
|
pub abi: abi::Abi,
|
||||||
pub sig: FnSig,
|
pub sig: FnSig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, PartialEq, Eq, Hash)]
|
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
|
||||||
pub struct ClosureTy {
|
pub struct ClosureTy {
|
||||||
pub fn_style: ast::FnStyle,
|
pub fn_style: ast::FnStyle,
|
||||||
pub onceness: ast::Onceness,
|
pub onceness: ast::Onceness,
|
||||||
|
@ -472,7 +473,7 @@ pub struct FnSig {
|
||||||
pub variadic: bool
|
pub variadic: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, PartialEq, Eq, Hash)]
|
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
|
||||||
pub struct ParamTy {
|
pub struct ParamTy {
|
||||||
pub space: subst::ParamSpace,
|
pub space: subst::ParamSpace,
|
||||||
pub idx: uint,
|
pub idx: uint,
|
||||||
|
@ -712,7 +713,7 @@ mod primitives {
|
||||||
|
|
||||||
// NB: If you change this, you'll probably want to change the corresponding
|
// NB: If you change this, you'll probably want to change the corresponding
|
||||||
// AST structure in libsyntax/ast.rs as well.
|
// AST structure in libsyntax/ast.rs as well.
|
||||||
#[deriving(Clone, PartialEq, Eq, Hash)]
|
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
|
||||||
pub enum sty {
|
pub enum sty {
|
||||||
ty_nil,
|
ty_nil,
|
||||||
ty_bot,
|
ty_bot,
|
||||||
|
@ -741,14 +742,14 @@ pub enum sty {
|
||||||
// on non-useful type error messages)
|
// on non-useful type error messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone, PartialEq, Eq, Hash)]
|
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
|
||||||
pub struct TyTrait {
|
pub struct TyTrait {
|
||||||
pub def_id: DefId,
|
pub def_id: DefId,
|
||||||
pub substs: Substs,
|
pub substs: Substs,
|
||||||
pub bounds: BuiltinBounds
|
pub bounds: BuiltinBounds
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(PartialEq, Eq, Hash)]
|
#[deriving(PartialEq, Eq, Hash, Show)]
|
||||||
pub struct TraitRef {
|
pub struct TraitRef {
|
||||||
pub def_id: DefId,
|
pub def_id: DefId,
|
||||||
pub substs: Substs,
|
pub substs: Substs,
|
||||||
|
@ -808,7 +809,7 @@ pub enum type_err {
|
||||||
terr_variadic_mismatch(expected_found<bool>)
|
terr_variadic_mismatch(expected_found<bool>)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(PartialEq, Eq, Hash)]
|
#[deriving(PartialEq, Eq, Hash, Show)]
|
||||||
pub struct ParamBounds {
|
pub struct ParamBounds {
|
||||||
pub builtin_bounds: BuiltinBounds,
|
pub builtin_bounds: BuiltinBounds,
|
||||||
pub trait_bounds: Vec<Rc<TraitRef>>
|
pub trait_bounds: Vec<Rc<TraitRef>>
|
||||||
|
@ -948,7 +949,7 @@ impl fmt::Show for IntVarValue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone, Show)]
|
||||||
pub struct TypeParameterDef {
|
pub struct TypeParameterDef {
|
||||||
pub ident: ast::Ident,
|
pub ident: ast::Ident,
|
||||||
pub def_id: ast::DefId,
|
pub def_id: ast::DefId,
|
||||||
|
@ -958,7 +959,7 @@ pub struct TypeParameterDef {
|
||||||
pub default: Option<ty::t>
|
pub default: Option<ty::t>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deriving(Encodable, Decodable, Clone)]
|
#[deriving(Encodable, Decodable, Clone, Show)]
|
||||||
pub struct RegionParameterDef {
|
pub struct RegionParameterDef {
|
||||||
pub name: ast::Name,
|
pub name: ast::Name,
|
||||||
pub def_id: ast::DefId,
|
pub def_id: ast::DefId,
|
||||||
|
@ -968,7 +969,7 @@ pub struct RegionParameterDef {
|
||||||
|
|
||||||
/// Information about the type/lifetime parameters associated with an
|
/// Information about the type/lifetime parameters associated with an
|
||||||
/// item or method. Analogous to ast::Generics.
|
/// item or method. Analogous to ast::Generics.
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone, Show)]
|
||||||
pub struct Generics {
|
pub struct Generics {
|
||||||
pub types: VecPerParamSpace<TypeParameterDef>,
|
pub types: VecPerParamSpace<TypeParameterDef>,
|
||||||
pub regions: VecPerParamSpace<RegionParameterDef>,
|
pub regions: VecPerParamSpace<RegionParameterDef>,
|
||||||
|
@ -1014,7 +1015,7 @@ pub struct ParameterEnvironment {
|
||||||
/// - `generics`: the set of type parameters and their bounds
|
/// - `generics`: the set of type parameters and their bounds
|
||||||
/// - `ty`: the base types, which may reference the parameters defined
|
/// - `ty`: the base types, which may reference the parameters defined
|
||||||
/// in `generics`
|
/// in `generics`
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone, Show)]
|
||||||
pub struct Polytype {
|
pub struct Polytype {
|
||||||
pub generics: Generics,
|
pub generics: Generics,
|
||||||
pub ty: t
|
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)),
|
opt_lifetime.as_ref().map(|e| lifetime_to_string(e)),
|
||||||
r.repr(this.tcx()));
|
r.repr(this.tcx()));
|
||||||
|
|
||||||
|
@ -504,6 +504,7 @@ pub fn ast_ty_to_builtin_ty<AC:AstConv,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[deriving(Show)]
|
||||||
enum PointerTy {
|
enum PointerTy {
|
||||||
Box,
|
Box,
|
||||||
RPtr(ty::Region),
|
RPtr(ty::Region),
|
||||||
|
@ -565,7 +566,7 @@ fn mk_pointer<AC:AstConv,
|
||||||
constr: |ty::t| -> ty::t)
|
constr: |ty::t| -> ty::t)
|
||||||
-> ty::t {
|
-> ty::t {
|
||||||
let tcx = this.tcx();
|
let tcx = this.tcx();
|
||||||
debug!("mk_pointer(ptr_ty={:?})", ptr_ty);
|
debug!("mk_pointer(ptr_ty={})", ptr_ty);
|
||||||
|
|
||||||
match a_seq_ty.ty.node {
|
match a_seq_ty.ty.node {
|
||||||
ast::TyVec(ref ty) => {
|
ast::TyVec(ref ty) => {
|
||||||
|
|
|
@ -246,7 +246,7 @@ impl<'a> RegionVarBindings<'a> {
|
||||||
if self.in_snapshot() {
|
if self.in_snapshot() {
|
||||||
self.undo_log.borrow_mut().push(AddVar(vid));
|
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));
|
vid, origin.repr(self.tcx));
|
||||||
return vid;
|
return vid;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue