mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 19:53:46 +00:00
Simplify LifetimeBounds
.
The `lifetimes` field is always empty. This commit removes it, and renames the type as `Bounds`.
This commit is contained in:
parent
8e92f4fb91
commit
bccff14a20
@ -18,7 +18,7 @@ pub fn expand_deriving_copy(
|
||||
attributes: Vec::new(),
|
||||
path: path_std!(marker::Copy),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: true,
|
||||
methods: Vec::new(),
|
||||
|
@ -80,12 +80,12 @@ pub fn expand_deriving_clone(
|
||||
attributes: Vec::new(),
|
||||
path: path_std!(clone::Clone),
|
||||
additional_bounds: bounds,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: true,
|
||||
methods: vec![MethodDef {
|
||||
name: sym::clone,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
explicit_self: borrowed_explicit_self(),
|
||||
args: Vec::new(),
|
||||
ret_ty: Self_,
|
||||
|
@ -24,12 +24,12 @@ pub fn expand_deriving_eq(
|
||||
attributes: Vec::new(),
|
||||
path: path_std!(cmp::Eq),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: true,
|
||||
methods: vec![MethodDef {
|
||||
name: sym::assert_receiver_is_total_eq,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
explicit_self: borrowed_explicit_self(),
|
||||
args: vec![],
|
||||
ret_ty: nil_ty(),
|
||||
@ -43,13 +43,7 @@ pub fn expand_deriving_eq(
|
||||
associated_types: Vec::new(),
|
||||
};
|
||||
|
||||
super::inject_impl_of_structural_trait(
|
||||
cx,
|
||||
span,
|
||||
item,
|
||||
path_std!(marker::StructuralEq),
|
||||
push,
|
||||
);
|
||||
super::inject_impl_of_structural_trait(cx, span, item, path_std!(marker::StructuralEq), push);
|
||||
|
||||
trait_def.expand_ext(cx, mitem, item, push, true)
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ pub fn expand_deriving_ord(
|
||||
attributes: Vec::new(),
|
||||
path: path_std!(cmp::Ord),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: false,
|
||||
methods: vec![MethodDef {
|
||||
name: sym::cmp,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
explicit_self: borrowed_explicit_self(),
|
||||
args: vec![(borrowed_self(), "other")],
|
||||
ret_ty: Literal(path_std!(cmp::Ordering)),
|
||||
|
@ -69,7 +69,7 @@ pub fn expand_deriving_partial_eq(
|
||||
let attrs = vec![cx.attribute(inline)];
|
||||
MethodDef {
|
||||
name: $name,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
explicit_self: borrowed_explicit_self(),
|
||||
args: vec![(borrowed_self(), "other")],
|
||||
ret_ty: Literal(path_local!(bool)),
|
||||
@ -102,7 +102,7 @@ pub fn expand_deriving_partial_eq(
|
||||
attributes: Vec::new(),
|
||||
path: path_std!(cmp::PartialEq),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: false,
|
||||
methods,
|
||||
|
@ -23,7 +23,7 @@ pub fn expand_deriving_partial_ord(
|
||||
let attrs = vec![cx.attribute(inline)];
|
||||
MethodDef {
|
||||
name: $name,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
explicit_self: borrowed_explicit_self(),
|
||||
args: vec![(borrowed_self(), "other")],
|
||||
ret_ty: Literal(path_local!(bool)),
|
||||
@ -50,7 +50,7 @@ pub fn expand_deriving_partial_ord(
|
||||
|
||||
let partial_cmp_def = MethodDef {
|
||||
name: sym::partial_cmp,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
explicit_self: borrowed_explicit_self(),
|
||||
args: vec![(borrowed_self(), "other")],
|
||||
ret_ty,
|
||||
@ -82,7 +82,7 @@ pub fn expand_deriving_partial_ord(
|
||||
attributes: vec![],
|
||||
path: path_std!(cmp::PartialOrd),
|
||||
additional_bounds: vec![],
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: false,
|
||||
methods,
|
||||
|
@ -25,12 +25,12 @@ pub fn expand_deriving_debug(
|
||||
attributes: Vec::new(),
|
||||
path: path_std!(fmt::Debug),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: false,
|
||||
methods: vec![MethodDef {
|
||||
name: sym::fmt,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
explicit_self: borrowed_explicit_self(),
|
||||
args: vec![(fmtr, "f")],
|
||||
ret_ty: Literal(path_std!(fmt::Result)),
|
||||
|
@ -26,13 +26,12 @@ pub fn expand_deriving_rustc_decodable(
|
||||
attributes: Vec::new(),
|
||||
path: Path::new_(vec![krate, "Decodable"], None, vec![], PathKind::Global),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: false,
|
||||
methods: vec![MethodDef {
|
||||
name: sym::decode,
|
||||
generics: LifetimeBounds {
|
||||
lifetimes: Vec::new(),
|
||||
generics: Bounds {
|
||||
bounds: vec![(
|
||||
typaram,
|
||||
vec![Path::new_(vec![krate, "Decoder"], None, vec![], PathKind::Global)],
|
||||
|
@ -23,12 +23,12 @@ pub fn expand_deriving_default(
|
||||
attributes: Vec::new(),
|
||||
path: path_std!(default::Default),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: false,
|
||||
methods: vec![MethodDef {
|
||||
name: kw::Default,
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
explicit_self: None,
|
||||
args: Vec::new(),
|
||||
ret_ty: Self_,
|
||||
|
@ -110,13 +110,12 @@ pub fn expand_deriving_rustc_encodable(
|
||||
attributes: Vec::new(),
|
||||
path: Path::new_(vec![krate, "Encodable"], None, vec![], PathKind::Global),
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: false,
|
||||
methods: vec![MethodDef {
|
||||
name: sym::encode,
|
||||
generics: LifetimeBounds {
|
||||
lifetimes: Vec::new(),
|
||||
generics: Bounds {
|
||||
bounds: vec![(
|
||||
typaram,
|
||||
vec![Path::new_(vec![krate, "Encoder"], None, vec![], PathKind::Global)],
|
||||
|
@ -191,7 +191,7 @@ use rustc_span::source_map::respan;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
use ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
|
||||
use ty::{Bounds, Path, Ptr, PtrTy, Self_, Ty};
|
||||
|
||||
use crate::deriving;
|
||||
|
||||
@ -211,7 +211,7 @@ pub struct TraitDef<'a> {
|
||||
pub additional_bounds: Vec<Ty<'a>>,
|
||||
|
||||
/// Any extra lifetimes and/or bounds, e.g., `D: serialize::Decoder`
|
||||
pub generics: LifetimeBounds<'a>,
|
||||
pub generics: Bounds<'a>,
|
||||
|
||||
/// Is it an `unsafe` trait?
|
||||
pub is_unsafe: bool,
|
||||
@ -228,7 +228,7 @@ pub struct MethodDef<'a> {
|
||||
/// name of the method
|
||||
pub name: Symbol,
|
||||
/// List of generics, e.g., `R: rand::Rng`
|
||||
pub generics: LifetimeBounds<'a>,
|
||||
pub generics: Bounds<'a>,
|
||||
|
||||
/// Whether there is a self argument (outer Option) i.e., whether
|
||||
/// this is a static function, and whether it is a pointer (inner
|
||||
|
@ -223,16 +223,15 @@ fn mk_generics(params: Vec<ast::GenericParam>, span: Span) -> Generics {
|
||||
}
|
||||
}
|
||||
|
||||
/// Lifetimes and bounds on type parameters
|
||||
/// Bounds on type parameters.
|
||||
#[derive(Clone)]
|
||||
pub struct LifetimeBounds<'a> {
|
||||
pub lifetimes: Vec<(&'a str, Vec<&'a str>)>,
|
||||
pub struct Bounds<'a> {
|
||||
pub bounds: Vec<(&'a str, Vec<Path<'a>>)>,
|
||||
}
|
||||
|
||||
impl<'a> LifetimeBounds<'a> {
|
||||
pub fn empty() -> LifetimeBounds<'a> {
|
||||
LifetimeBounds { lifetimes: Vec::new(), bounds: Vec::new() }
|
||||
impl<'a> Bounds<'a> {
|
||||
pub fn empty() -> Bounds<'a> {
|
||||
Bounds { bounds: Vec::new() }
|
||||
}
|
||||
pub fn to_generics(
|
||||
&self,
|
||||
@ -242,18 +241,12 @@ impl<'a> LifetimeBounds<'a> {
|
||||
self_generics: &Generics,
|
||||
) -> Generics {
|
||||
let generic_params = self
|
||||
.lifetimes
|
||||
.bounds
|
||||
.iter()
|
||||
.map(|&(lt, ref bounds)| {
|
||||
let bounds = bounds
|
||||
.iter()
|
||||
.map(|b| ast::GenericBound::Outlives(cx.lifetime(span, Ident::from_str(b))));
|
||||
cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds.collect())
|
||||
})
|
||||
.chain(self.bounds.iter().map(|t| {
|
||||
.map(|t| {
|
||||
let (name, ref bounds) = *t;
|
||||
mk_ty_param(cx, span, name, &[], &bounds, self_ty, self_generics)
|
||||
}))
|
||||
})
|
||||
.collect();
|
||||
|
||||
mk_generics(generic_params, span)
|
||||
|
@ -25,15 +25,12 @@ pub fn expand_deriving_hash(
|
||||
attributes: Vec::new(),
|
||||
path,
|
||||
additional_bounds: Vec::new(),
|
||||
generics: LifetimeBounds::empty(),
|
||||
generics: Bounds::empty(),
|
||||
is_unsafe: false,
|
||||
supports_unions: false,
|
||||
methods: vec![MethodDef {
|
||||
name: sym::hash,
|
||||
generics: LifetimeBounds {
|
||||
lifetimes: Vec::new(),
|
||||
bounds: vec![(typaram, vec![path_std!(hash::Hasher)])],
|
||||
},
|
||||
generics: Bounds { bounds: vec![(typaram, vec![path_std!(hash::Hasher)])] },
|
||||
explicit_self: borrowed_explicit_self(),
|
||||
args: vec![(Ptr(Box::new(Literal(arg)), Borrowed(None, Mutability::Mut)), "state")],
|
||||
ret_ty: nil_ty(),
|
||||
|
Loading…
Reference in New Issue
Block a user