Skip to content

Commit e188894

Browse files
committed
auto merge of #5426 : nikomatsakis/rust/issue-4846-lifetimes-in-expl-self, r=pcwalton
(this will be needed for snapshotting at some point) r? @pcwalton
2 parents a14ec73 + a6187c6 commit e188894

File tree

13 files changed

+166
-55
lines changed

13 files changed

+166
-55
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,10 @@ fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
631631
'v' => { return ast::sty_value; }
632632
'@' => { return ast::sty_box(get_mutability(string[1])); }
633633
'~' => { return ast::sty_uniq(get_mutability(string[1])); }
634-
'&' => { return ast::sty_region(get_mutability(string[1])); }
634+
'&' => {
635+
// FIXME(#4846) expl. region
636+
return ast::sty_region(None, get_mutability(string[1]));
637+
}
635638
_ => {
636639
fail!(fmt!("unknown self type code: `%c`", self_ty_kind as char));
637640
}

src/librustc/metadata/encoder.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -406,32 +406,47 @@ fn encode_self_type(ebml_w: writer::Encoder, self_type: ast::self_ty_) {
406406
ebml_w.start_tag(tag_item_trait_method_self_ty);
407407

408408
// Encode the base self type.
409-
let ch;
410409
match self_type {
411-
sty_static => { ch = 's' as u8; }
412-
sty_by_ref => { ch = 'r' as u8; }
413-
sty_value => { ch = 'v' as u8; }
414-
sty_region(_) => { ch = '&' as u8; }
415-
sty_box(_) => { ch = '@' as u8; }
416-
sty_uniq(_) => { ch = '~' as u8; }
417-
}
418-
ebml_w.writer.write(&[ ch ]);
419-
420-
// Encode mutability.
421-
match self_type {
422-
sty_static | sty_by_ref | sty_value => { /* No-op. */ }
423-
sty_region(m_imm) | sty_box(m_imm) | sty_uniq(m_imm) => {
424-
ebml_w.writer.write(&[ 'i' as u8 ]);
410+
sty_static => {
411+
ebml_w.writer.write(&[ 's' as u8 ]);
412+
}
413+
sty_by_ref => {
414+
ebml_w.writer.write(&[ 'r' as u8 ]);
415+
}
416+
sty_value => {
417+
ebml_w.writer.write(&[ 'v' as u8 ]);
418+
}
419+
sty_region(_, m) => {
420+
// FIXME(#4846) encode custom lifetime
421+
ebml_w.writer.write(&[ '&' as u8 ]);
422+
encode_mutability(ebml_w, m);
425423
}
426-
sty_region(m_mutbl) | sty_box(m_mutbl) | sty_uniq(m_mutbl) => {
427-
ebml_w.writer.write(&[ 'm' as u8 ]);
424+
sty_box(m) => {
425+
ebml_w.writer.write(&[ '@' as u8 ]);
426+
encode_mutability(ebml_w, m);
428427
}
429-
sty_region(m_const) | sty_box(m_const) | sty_uniq(m_const) => {
430-
ebml_w.writer.write(&[ 'c' as u8 ]);
428+
sty_uniq(m) => {
429+
ebml_w.writer.write(&[ '~' as u8 ]);
430+
encode_mutability(ebml_w, m);
431431
}
432432
}
433433

434434
ebml_w.end_tag();
435+
436+
fn encode_mutability(ebml_w: writer::Encoder,
437+
m: ast::mutability) {
438+
match m {
439+
m_imm => {
440+
ebml_w.writer.write(&[ 'i' as u8 ]);
441+
}
442+
m_mutbl => {
443+
ebml_w.writer.write(&[ 'm' as u8 ]);
444+
}
445+
m_const => {
446+
ebml_w.writer.write(&[ 'c' as u8 ]);
447+
}
448+
}
449+
}
435450
}
436451

437452
fn encode_method_sort(ebml_w: writer::Encoder, sort: char) {

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ fn visit_fn(fk: &visit::fn_kind,
472472
special_idents::self_,
473473
by_ref));
474474
}
475-
sty_value | sty_region(_) | sty_box(_) | sty_uniq(_) => {
475+
sty_value | sty_region(*) | sty_box(_) | sty_uniq(_) => {
476476
fn_maps.add_variable(Arg(method.self_id,
477477
special_idents::self_,
478478
by_copy));

src/librustc/middle/trans/meth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ pub fn trans_trait_callee(bcx: block,
589589
let llpair = self_datum.to_ref_llval(bcx);
590590
591591
let llpair = match explicit_self {
592-
ast::sty_region(_) => Load(bcx, llpair),
592+
ast::sty_region(*) => Load(bcx, llpair),
593593
ast::sty_static | ast::sty_by_ref | ast::sty_value |
594594
ast::sty_box(_) | ast::sty_uniq(_) => llpair
595595
};
@@ -658,7 +658,7 @@ pub fn trans_trait_callee_from_llval(bcx: block,
658658
bcx.tcx().sess.bug(~"methods with by-value self should not be \
659659
called on objects");
660660
}
661-
ast::sty_region(_) => {
661+
ast::sty_region(*) => {
662662
// As before, we need to pass a pointer to a pointer to the
663663
// payload.
664664
match store {

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ pub impl Reflector {
105105
v,
106106
ty::BoxTraitStore,
107107
ast::sty_region(
108+
None,
108109
ast::m_imm)),
109110
ArgVals(args), SaveIn(scratch.val), DontAutorefArg);
110111
let result = scratch.to_value_llval(bcx);

src/librustc/middle/typeck/check/method.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,12 @@ pub impl LookupContext/&self {
743743
sty_box(_) | sty_uniq(_) => {
744744
self_substs
745745
}
746-
sty_region(_) if self_substs.self_r.is_some() => {
746+
sty_region(*) if self_substs.self_r.is_some() => {
747+
// FIXME(#4846) ignoring expl lifetime here
747748
self_substs
748749
}
749-
sty_region(_) => {
750+
sty_region(*) => {
751+
// FIXME(#4846) ignoring expl lifetime here
750752
substs {
751753
self_r:
752754
Some(self.infcx().next_region_var(
@@ -1326,7 +1328,8 @@ pub fn transform_self_type_for_method(tcx: ty::ctxt,
13261328
sty_by_ref | sty_value => {
13271329
impl_ty
13281330
}
1329-
sty_region(mutability) => {
1331+
sty_region(_, mutability) => {
1332+
// FIXME(#4846) ignoring expl lifetime here
13301333
mk_rptr(tcx,
13311334
self_region.expect(~"self region missing for &self param"),
13321335
ty::mt { ty: impl_ty, mutbl: mutability })

src/librustc/middle/typeck/check/regionmanip.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ pub fn replace_bound_regions_in_fn_sig(
3030
isr: isr_alist,
3131
self_info: Option<SelfInfo>,
3232
fn_sig: &ty::FnSig,
33-
mapf: &fn(ty::bound_region) -> ty::Region) ->
34-
(isr_alist, Option<SelfInfo>, ty::FnSig) {
33+
mapf: &fn(ty::bound_region) -> ty::Region)
34+
-> (isr_alist, Option<SelfInfo>, ty::FnSig)
35+
{
3536
// Take self_info apart; the self_ty part is the only one we want
3637
// to update here.
3738
let self_ty = self_info.map(|s| s.self_ty);
@@ -41,8 +42,10 @@ pub fn replace_bound_regions_in_fn_sig(
4142

4243
match self_info {
4344
Some(SelfInfo {
44-
explicit_self: codemap::spanned { node: ast::sty_region(m),
45-
_}, _}) => {
45+
explicit_self: codemap::spanned {
46+
node: ast::sty_region(_, m),
47+
// FIXME(#4846) ------^ Use this lifetime instead of self
48+
_}, _}) => {
4649
let region = ty::re_bound(ty::br_self);
4750
let ty = ty::mk_rptr(tcx, region,
4851
ty::mt { ty: ty::mk_self(tcx), mutbl: m });
@@ -51,7 +54,6 @@ pub fn replace_bound_regions_in_fn_sig(
5154
_ => {}
5255
}
5356

54-
5557
for self_ty.each |t| { all_tys.push(*t) }
5658

5759
debug!("replace_bound_regions_in_fn_sig(self_info.self_ty=%?, fn_sig=%s, \

src/libsyntax/ast.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,18 +1001,18 @@ impl to_bytes::IterBytes for ret_style {
10011001
#[auto_decode]
10021002
#[deriving_eq]
10031003
pub enum self_ty_ {
1004-
sty_static, // no self: static method
1005-
sty_by_ref, // old by-reference self: ``
1006-
sty_value, // by-value self: `self`
1007-
sty_region(mutability), // by-region self: `&self`
1008-
sty_box(mutability), // by-managed-pointer self: `@self`
1009-
sty_uniq(mutability) // by-unique-pointer self: `~self`
1004+
sty_static, // no self
1005+
sty_by_ref, // ``
1006+
sty_value, // `self`
1007+
sty_region(Option<@Lifetime>, mutability), // `&'lt self`
1008+
sty_box(mutability), // `@self`
1009+
sty_uniq(mutability) // `~self`
10101010
}
10111011
10121012
impl self_ty_ {
10131013
fn is_borrowed(&self) -> bool {
10141014
match *self {
1015-
sty_region(_) => true,
1015+
sty_region(*) => true,
10161016
_ => false
10171017
}
10181018
}

src/libsyntax/ext/auto_encode.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,10 @@ fn mk_ser_method(
634634
ident: cx.ident_of(~"encode"),
635635
attrs: ~[],
636636
generics: ast_util::empty_generics(),
637-
self_ty: codemap::spanned { node: ast::sty_region(ast::m_imm),
638-
span: span },
637+
self_ty: codemap::spanned {
638+
node: ast::sty_region(None, ast::m_imm),
639+
span: span
640+
},
639641
purity: ast::impure_fn,
640642
decl: ser_decl,
641643
body: ser_body,

src/libsyntax/ext/deriving.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn create_eq_method(cx: @ext_ctxt,
220220
let body_block = build::mk_simple_block(cx, span, body);
221221

222222
// Create the method.
223-
let self_ty = spanned { node: sty_region(m_imm), span: span };
223+
let self_ty = spanned { node: sty_region(None, m_imm), span: span };
224224
@ast::method {
225225
ident: method_ident,
226226
attrs: ~[],
@@ -398,7 +398,7 @@ fn create_iter_bytes_method(cx: @ext_ctxt,
398398
let body_block = build::mk_block_(cx, span, statements);
399399

400400
// Create the method.
401-
let self_ty = spanned { node: sty_region(m_imm), span: span };
401+
let self_ty = spanned { node: sty_region(None, m_imm), span: span };
402402
let method_ident = cx.ident_of(~"iter_bytes");
403403
@ast::method {
404404
ident: method_ident,
@@ -448,7 +448,7 @@ fn create_clone_method(cx: @ext_ctxt,
448448
let body_block = build::mk_simple_block(cx, span, expr);
449449

450450
// Create the self type and method identifier.
451-
let self_ty = spanned { node: sty_region(m_imm), span: span };
451+
let self_ty = spanned { node: sty_region(None, m_imm), span: span };
452452
let method_ident = cx.ident_of(~"clone");
453453

454454
// Create the method.

0 commit comments

Comments
 (0)