Skip to content

Commit bccff14

Browse files
committed
Simplify LifetimeBounds.
The `lifetimes` field is always empty. This commit removes it, and renames the type as `Bounds`.
1 parent 8e92f4f commit bccff14

File tree

13 files changed

+34
-52
lines changed

13 files changed

+34
-52
lines changed

src/librustc_builtin_macros/deriving/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn expand_deriving_copy(
1818
attributes: Vec::new(),
1919
path: path_std!(marker::Copy),
2020
additional_bounds: Vec::new(),
21-
generics: LifetimeBounds::empty(),
21+
generics: Bounds::empty(),
2222
is_unsafe: false,
2323
supports_unions: true,
2424
methods: Vec::new(),

src/librustc_builtin_macros/deriving/clone.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ pub fn expand_deriving_clone(
8080
attributes: Vec::new(),
8181
path: path_std!(clone::Clone),
8282
additional_bounds: bounds,
83-
generics: LifetimeBounds::empty(),
83+
generics: Bounds::empty(),
8484
is_unsafe: false,
8585
supports_unions: true,
8686
methods: vec![MethodDef {
8787
name: sym::clone,
88-
generics: LifetimeBounds::empty(),
88+
generics: Bounds::empty(),
8989
explicit_self: borrowed_explicit_self(),
9090
args: Vec::new(),
9191
ret_ty: Self_,

src/librustc_builtin_macros/deriving/cmp/eq.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub fn expand_deriving_eq(
2424
attributes: Vec::new(),
2525
path: path_std!(cmp::Eq),
2626
additional_bounds: Vec::new(),
27-
generics: LifetimeBounds::empty(),
27+
generics: Bounds::empty(),
2828
is_unsafe: false,
2929
supports_unions: true,
3030
methods: vec![MethodDef {
3131
name: sym::assert_receiver_is_total_eq,
32-
generics: LifetimeBounds::empty(),
32+
generics: Bounds::empty(),
3333
explicit_self: borrowed_explicit_self(),
3434
args: vec![],
3535
ret_ty: nil_ty(),
@@ -43,13 +43,7 @@ pub fn expand_deriving_eq(
4343
associated_types: Vec::new(),
4444
};
4545

46-
super::inject_impl_of_structural_trait(
47-
cx,
48-
span,
49-
item,
50-
path_std!(marker::StructuralEq),
51-
push,
52-
);
46+
super::inject_impl_of_structural_trait(cx, span, item, path_std!(marker::StructuralEq), push);
5347

5448
trait_def.expand_ext(cx, mitem, item, push, true)
5549
}

src/librustc_builtin_macros/deriving/cmp/ord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub fn expand_deriving_ord(
2222
attributes: Vec::new(),
2323
path: path_std!(cmp::Ord),
2424
additional_bounds: Vec::new(),
25-
generics: LifetimeBounds::empty(),
25+
generics: Bounds::empty(),
2626
is_unsafe: false,
2727
supports_unions: false,
2828
methods: vec![MethodDef {
2929
name: sym::cmp,
30-
generics: LifetimeBounds::empty(),
30+
generics: Bounds::empty(),
3131
explicit_self: borrowed_explicit_self(),
3232
args: vec![(borrowed_self(), "other")],
3333
ret_ty: Literal(path_std!(cmp::Ordering)),

src/librustc_builtin_macros/deriving/cmp/partial_eq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub fn expand_deriving_partial_eq(
6969
let attrs = vec![cx.attribute(inline)];
7070
MethodDef {
7171
name: $name,
72-
generics: LifetimeBounds::empty(),
72+
generics: Bounds::empty(),
7373
explicit_self: borrowed_explicit_self(),
7474
args: vec![(borrowed_self(), "other")],
7575
ret_ty: Literal(path_local!(bool)),
@@ -102,7 +102,7 @@ pub fn expand_deriving_partial_eq(
102102
attributes: Vec::new(),
103103
path: path_std!(cmp::PartialEq),
104104
additional_bounds: Vec::new(),
105-
generics: LifetimeBounds::empty(),
105+
generics: Bounds::empty(),
106106
is_unsafe: false,
107107
supports_unions: false,
108108
methods,

src/librustc_builtin_macros/deriving/cmp/partial_ord.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn expand_deriving_partial_ord(
2323
let attrs = vec![cx.attribute(inline)];
2424
MethodDef {
2525
name: $name,
26-
generics: LifetimeBounds::empty(),
26+
generics: Bounds::empty(),
2727
explicit_self: borrowed_explicit_self(),
2828
args: vec![(borrowed_self(), "other")],
2929
ret_ty: Literal(path_local!(bool)),
@@ -50,7 +50,7 @@ pub fn expand_deriving_partial_ord(
5050

5151
let partial_cmp_def = MethodDef {
5252
name: sym::partial_cmp,
53-
generics: LifetimeBounds::empty(),
53+
generics: Bounds::empty(),
5454
explicit_self: borrowed_explicit_self(),
5555
args: vec![(borrowed_self(), "other")],
5656
ret_ty,
@@ -82,7 +82,7 @@ pub fn expand_deriving_partial_ord(
8282
attributes: vec![],
8383
path: path_std!(cmp::PartialOrd),
8484
additional_bounds: vec![],
85-
generics: LifetimeBounds::empty(),
85+
generics: Bounds::empty(),
8686
is_unsafe: false,
8787
supports_unions: false,
8888
methods,

src/librustc_builtin_macros/deriving/debug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ pub fn expand_deriving_debug(
2525
attributes: Vec::new(),
2626
path: path_std!(fmt::Debug),
2727
additional_bounds: Vec::new(),
28-
generics: LifetimeBounds::empty(),
28+
generics: Bounds::empty(),
2929
is_unsafe: false,
3030
supports_unions: false,
3131
methods: vec![MethodDef {
3232
name: sym::fmt,
33-
generics: LifetimeBounds::empty(),
33+
generics: Bounds::empty(),
3434
explicit_self: borrowed_explicit_self(),
3535
args: vec![(fmtr, "f")],
3636
ret_ty: Literal(path_std!(fmt::Result)),

src/librustc_builtin_macros/deriving/decodable.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ pub fn expand_deriving_rustc_decodable(
2626
attributes: Vec::new(),
2727
path: Path::new_(vec![krate, "Decodable"], None, vec![], PathKind::Global),
2828
additional_bounds: Vec::new(),
29-
generics: LifetimeBounds::empty(),
29+
generics: Bounds::empty(),
3030
is_unsafe: false,
3131
supports_unions: false,
3232
methods: vec![MethodDef {
3333
name: sym::decode,
34-
generics: LifetimeBounds {
35-
lifetimes: Vec::new(),
34+
generics: Bounds {
3635
bounds: vec![(
3736
typaram,
3837
vec![Path::new_(vec![krate, "Decoder"], None, vec![], PathKind::Global)],

src/librustc_builtin_macros/deriving/default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ pub fn expand_deriving_default(
2323
attributes: Vec::new(),
2424
path: path_std!(default::Default),
2525
additional_bounds: Vec::new(),
26-
generics: LifetimeBounds::empty(),
26+
generics: Bounds::empty(),
2727
is_unsafe: false,
2828
supports_unions: false,
2929
methods: vec![MethodDef {
3030
name: kw::Default,
31-
generics: LifetimeBounds::empty(),
31+
generics: Bounds::empty(),
3232
explicit_self: None,
3333
args: Vec::new(),
3434
ret_ty: Self_,

src/librustc_builtin_macros/deriving/encodable.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,12 @@ pub fn expand_deriving_rustc_encodable(
110110
attributes: Vec::new(),
111111
path: Path::new_(vec![krate, "Encodable"], None, vec![], PathKind::Global),
112112
additional_bounds: Vec::new(),
113-
generics: LifetimeBounds::empty(),
113+
generics: Bounds::empty(),
114114
is_unsafe: false,
115115
supports_unions: false,
116116
methods: vec![MethodDef {
117117
name: sym::encode,
118-
generics: LifetimeBounds {
119-
lifetimes: Vec::new(),
118+
generics: Bounds {
120119
bounds: vec![(
121120
typaram,
122121
vec![Path::new_(vec![krate, "Encoder"], None, vec![], PathKind::Global)],

src/librustc_builtin_macros/deriving/generic/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ use rustc_span::source_map::respan;
191191
use rustc_span::symbol::{kw, sym, Ident, Symbol};
192192
use rustc_span::Span;
193193

194-
use ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
194+
use ty::{Bounds, Path, Ptr, PtrTy, Self_, Ty};
195195

196196
use crate::deriving;
197197

@@ -211,7 +211,7 @@ pub struct TraitDef<'a> {
211211
pub additional_bounds: Vec<Ty<'a>>,
212212

213213
/// Any extra lifetimes and/or bounds, e.g., `D: serialize::Decoder`
214-
pub generics: LifetimeBounds<'a>,
214+
pub generics: Bounds<'a>,
215215

216216
/// Is it an `unsafe` trait?
217217
pub is_unsafe: bool,
@@ -228,7 +228,7 @@ pub struct MethodDef<'a> {
228228
/// name of the method
229229
pub name: Symbol,
230230
/// List of generics, e.g., `R: rand::Rng`
231-
pub generics: LifetimeBounds<'a>,
231+
pub generics: Bounds<'a>,
232232

233233
/// Whether there is a self argument (outer Option) i.e., whether
234234
/// this is a static function, and whether it is a pointer (inner

src/librustc_builtin_macros/deriving/generic/ty.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,15 @@ fn mk_generics(params: Vec<ast::GenericParam>, span: Span) -> Generics {
223223
}
224224
}
225225

226-
/// Lifetimes and bounds on type parameters
226+
/// Bounds on type parameters.
227227
#[derive(Clone)]
228-
pub struct LifetimeBounds<'a> {
229-
pub lifetimes: Vec<(&'a str, Vec<&'a str>)>,
228+
pub struct Bounds<'a> {
230229
pub bounds: Vec<(&'a str, Vec<Path<'a>>)>,
231230
}
232231

233-
impl<'a> LifetimeBounds<'a> {
234-
pub fn empty() -> LifetimeBounds<'a> {
235-
LifetimeBounds { lifetimes: Vec::new(), bounds: Vec::new() }
232+
impl<'a> Bounds<'a> {
233+
pub fn empty() -> Bounds<'a> {
234+
Bounds { bounds: Vec::new() }
236235
}
237236
pub fn to_generics(
238237
&self,
@@ -242,18 +241,12 @@ impl<'a> LifetimeBounds<'a> {
242241
self_generics: &Generics,
243242
) -> Generics {
244243
let generic_params = self
245-
.lifetimes
244+
.bounds
246245
.iter()
247-
.map(|&(lt, ref bounds)| {
248-
let bounds = bounds
249-
.iter()
250-
.map(|b| ast::GenericBound::Outlives(cx.lifetime(span, Ident::from_str(b))));
251-
cx.lifetime_def(span, Ident::from_str(lt), vec![], bounds.collect())
252-
})
253-
.chain(self.bounds.iter().map(|t| {
246+
.map(|t| {
254247
let (name, ref bounds) = *t;
255248
mk_ty_param(cx, span, name, &[], &bounds, self_ty, self_generics)
256-
}))
249+
})
257250
.collect();
258251

259252
mk_generics(generic_params, span)

src/librustc_builtin_macros/deriving/hash.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ pub fn expand_deriving_hash(
2525
attributes: Vec::new(),
2626
path,
2727
additional_bounds: Vec::new(),
28-
generics: LifetimeBounds::empty(),
28+
generics: Bounds::empty(),
2929
is_unsafe: false,
3030
supports_unions: false,
3131
methods: vec![MethodDef {
3232
name: sym::hash,
33-
generics: LifetimeBounds {
34-
lifetimes: Vec::new(),
35-
bounds: vec![(typaram, vec![path_std!(hash::Hasher)])],
36-
},
33+
generics: Bounds { bounds: vec![(typaram, vec![path_std!(hash::Hasher)])] },
3734
explicit_self: borrowed_explicit_self(),
3835
args: vec![(Ptr(Box::new(Literal(arg)), Borrowed(None, Mutability::Mut)), "state")],
3936
ret_ty: nil_ty(),

0 commit comments

Comments
 (0)