Skip to content

Commit 80ec474

Browse files
committed
---
yaml --- r: 44989 b: refs/heads/master c: 704cd64 h: refs/heads/master i: 44987: eb36ec6 v: v3
1 parent f9cb9ca commit 80ec474

File tree

12 files changed

+97
-43
lines changed

12 files changed

+97
-43
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 8bb537e68daf2a2794bacfe4bd39ac7fad6314fa
2+
refs/heads/master: 704cd648ac1160c5f02291e505697a6cf7e20945
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a6d9689399d091c3265f00434a69c551a61c28dc
55
refs/heads/try: ef355f6332f83371e4acf04fc4eb940ab41d78d3

trunk/src/librustc/front/test.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,14 @@ fn is_test_fn(i: @ast::item) -> bool {
178178

179179
fn has_test_signature(i: @ast::item) -> bool {
180180
match &i.node {
181-
&ast::item_fn(ref decl, _, ref tps, _) => {
181+
&ast::item_fn(ref decl, _, ref generics, _) => {
182182
let no_output = match decl.output.node {
183183
ast::ty_nil => true,
184184
_ => false
185185
};
186-
decl.inputs.is_empty() && no_output && tps.is_empty()
186+
decl.inputs.is_empty()
187+
&& no_output
188+
&& !generics.is_parameterized()
187189
}
188190
_ => false
189191
}

trunk/src/librustc/metadata/encoder.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,16 @@ fn encode_type(ecx: @EncodeContext, ebml_w: writer::Encoder, typ: ty::t) {
228228

229229
fn encode_symbol(ecx: @EncodeContext, ebml_w: writer::Encoder, id: node_id) {
230230
ebml_w.start_tag(tag_items_data_item_symbol);
231-
let sym = match ecx.item_symbols.find(&id) {
232-
Some(ref x) => (/*bad*/copy *x),
233-
None => {
234-
ecx.diag.handler().bug(
235-
fmt!("encode_symbol: id not found %d", id));
236-
}
237-
};
238-
ebml_w.writer.write(str::to_bytes(sym));
231+
match ecx.item_symbols.find(&id) {
232+
Some(ref x) => {
233+
debug!("encode_symbol(id=%?, str=%s)", id, *x);
234+
ebml_w.writer.write(str::to_bytes(*x));
235+
}
236+
None => {
237+
ecx.diag.handler().bug(
238+
fmt!("encode_symbol: id not found %d", id));
239+
}
240+
}
239241
ebml_w.end_tag();
240242
}
241243

@@ -264,6 +266,8 @@ fn encode_enum_variant_info(ecx: @EncodeContext, ebml_w: writer::Encoder,
264266
path: &[ast_map::path_elt],
265267
index: @mut ~[entry<int>],
266268
generics: &ast::Generics) {
269+
debug!("encode_enum_variant_info(id=%?)", id);
270+
267271
let mut disr_val = 0;
268272
let mut i = 0;
269273
let vi = ty::enum_variants(ecx.tcx,

trunk/src/librustc/middle/trans/base.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,15 +2079,15 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) {
20792079
_ => fail!(~"trans_item"),
20802080
};
20812081
match /*bad*/copy item.node {
2082-
ast::item_fn(ref decl, purity, ref tps, ref body) => {
2082+
ast::item_fn(ref decl, purity, ref generics, ref body) => {
20832083
if purity == ast::extern_fn {
20842084
let llfndecl = get_item_val(ccx, item.id);
20852085
foreign::trans_foreign_fn(ccx,
20862086
vec::append(
20872087
/*bad*/copy *path,
20882088
~[path_name(item.ident)]),
20892089
decl, body, llfndecl, item.id);
2090-
} else if tps.is_empty() {
2090+
} else if !generics.is_type_parameterized() {
20912091
let llfndecl = get_item_val(ccx, item.id);
20922092
trans_fn(ccx,
20932093
vec::append(/*bad*/copy *path, ~[path_name(item.ident)]),
@@ -2111,8 +2111,8 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) {
21112111
ast::item_mod(ref m) => {
21122112
trans_mod(ccx, m);
21132113
}
2114-
ast::item_enum(ref enum_definition, ref tps) => {
2115-
if tps.is_empty() {
2114+
ast::item_enum(ref enum_definition, ref generics) => {
2115+
if !generics.is_type_parameterized() {
21162116
let degen = (*enum_definition).variants.len() == 1u;
21172117
let vi = ty::enum_variants(ccx.tcx, local_def(item.id));
21182118
let mut i = 0;
@@ -2128,8 +2128,8 @@ pub fn trans_item(ccx: @CrateContext, item: ast::item) {
21282128
};
21292129
foreign::trans_foreign_mod(ccx, foreign_mod, abi);
21302130
}
2131-
ast::item_struct(struct_def, tps) => {
2132-
if tps.is_empty() {
2131+
ast::item_struct(struct_def, generics) => {
2132+
if !generics.is_type_parameterized() {
21332133
trans_struct_def(ccx, struct_def, path, item.id);
21342134
}
21352135
}

trunk/src/librustc/middle/typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: @ast::item)
861861
// like "foo<X>". This is because otherwise ty_to_str will
862862
// print the name as merely "foo", as it has no way to
863863
// reconstruct the value of X.
864-
if !generics.is_empty() { t0 } else {
864+
if generics.is_parameterized() { t0 } else {
865865
ty::mk_with_id(tcx, t0, def_id)
866866
}
867867
};

trunk/src/librustc/middle/typeck/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fn check_main_fn_ty(ccx: @mut CrateCtxt,
315315
Some(ast_map::node_item(it,_)) => {
316316
match it.node {
317317
ast::item_fn(_, _, ref ps, _)
318-
if !ps.is_empty() => {
318+
if ps.is_parameterized() => {
319319
tcx.sess.span_err(
320320
main_span,
321321
~"main function is not allowed \

trunk/src/libsyntax/ast.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ pub struct Lifetime {
105105
ident: ident
106106
}
107107
108-
// a "Path" is essentially Rust's notion of a name;
109-
// for instance: core::cmp::Eq . It's represented
110-
// as a sequence of identifiers, along with a bunch
111-
// of supporting information.
112108
#[auto_encode]
113109
#[auto_decode]
114110
#[deriving_eq]
@@ -165,8 +161,14 @@ pub struct Generics {
165161
}
166162
167163
pub impl Generics {
168-
fn is_empty(&self) -> bool {
169-
self.lifetimes.len() + self.ty_params.len() == 0
164+
fn is_parameterized(&self) -> bool {
165+
self.lifetimes.len() + self.ty_params.len() > 0
166+
}
167+
fn is_lt_parameterized(&self) -> bool {
168+
self.lifetimes.len() > 0
169+
}
170+
fn is_type_parameterized(&self) -> bool {
171+
self.ty_params.len() > 0
170172
}
171173
}
172174

trunk/src/libsyntax/ext/tt/transcribe.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct TtFrame {
3636
pub struct TtReader {
3737
sp_diag: span_handler,
3838
interner: @ident_interner,
39-
// the unzipped tree:
4039
cur: @mut TtFrame,
4140
/* for MBE-style macro transcription */
4241
interpolations: std::oldmap::HashMap<ident, @named_match>,

trunk/src/libsyntax/parse/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ pub impl Parser {
119119
id: self.get_id() })
120120
}
121121

122+
fn parse_value_ident(&self) -> ast::ident {
123+
return self.parse_ident();
124+
}
125+
122126
// consume token 'tok' if it exists. Returns true if the given
123127
// token was present, false otherwise.
124128
fn eat(&self, tok: &token::Token) -> bool {

trunk/src/libsyntax/parse/parser.rs

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ pub impl Parser {
457457
let pur = p.parse_fn_purity();
458458
// NB: at the moment, trait methods are public by default; this
459459
// could change.
460-
let ident = p.parse_ident();
460+
let ident = p.parse_method_name();
461461
462462
let generics = p.parse_generics();
463463
@@ -893,9 +893,16 @@ pub impl Parser {
893893
codemap::spanned { node: lit, span: mk_sp(lo, self.last_span.hi) }
894894
}
895895

896-
// parse a path that doesn't have type parameters attached
897-
fn parse_path_without_tps(&self)
898-
-> @ast::path {
896+
fn parse_path_without_tps(&self) -> @path {
897+
self.parse_path_without_tps_(|p| p.parse_ident(),
898+
|p| p.parse_ident())
899+
}
900+
901+
fn parse_path_without_tps_(
902+
&self,
903+
parse_ident: fn(&Parser) -> ident,
904+
parse_last_ident: fn(&Parser) -> ident
905+
) -> @path {
899906
maybe_whole!(self, nt_path);
900907
let lo = self.span.lo;
901908
let global = self.eat(&token::MOD_SEP);
@@ -906,10 +913,10 @@ pub impl Parser {
906913
&& self.look_ahead(1u) == token::MOD_SEP;
907914

908915
if is_not_last {
909-
ids.push(self.parse_ident());
916+
ids.push(parse_ident(self));
910917
self.expect(&token::MOD_SEP);
911918
} else {
912-
ids.push(self.parse_ident());
919+
ids.push(parse_last_ident(self));
913920
break;
914921
}
915922
}
@@ -920,7 +927,12 @@ pub impl Parser {
920927
types: ~[] }
921928
}
922929

923-
fn parse_path_with_tps(&self, colons: bool) -> @ast::path {
930+
fn parse_value_path(&self) -> @path {
931+
self.parse_path_without_tps_(|p| p.parse_ident(),
932+
|p| p.parse_value_ident())
933+
}
934+
935+
fn parse_path_with_tps(&self, colons: bool) -> @path {
924936
debug!("parse_path_with_tps(colons=%b)", colons);
925937

926938
maybe_whole!(self, nt_path);
@@ -2102,7 +2114,11 @@ pub impl Parser {
21022114
}
21032115

21042116
let lo1 = self.last_span.lo;
2105-
let fieldname = self.parse_ident();
2117+
let fieldname = if self.look_ahead(1u) == token::COLON {
2118+
self.parse_ident()
2119+
} else {
2120+
self.parse_value_ident()
2121+
};
21062122
let hi1 = self.last_span.lo;
21072123
let fieldpath = ast_util::ident_to_path(mk_sp(lo1, hi1),
21082124
fieldname);
@@ -2266,7 +2282,7 @@ pub impl Parser {
22662282
}
22672283

22682284
if is_plain_ident(&*self.token) && cannot_be_enum_or_struct {
2269-
let name = self.parse_path_without_tps();
2285+
let name = self.parse_value_path();
22702286
let sub;
22712287
if self.eat(&token::AT) {
22722288
sub = Some(self.parse_pat(refutable));
@@ -2339,7 +2355,7 @@ pub impl Parser {
23392355
*self.last_span,
23402356
~"expected identifier, found path");
23412357
}
2342-
let name = self.parse_path_without_tps();
2358+
let name = self.parse_value_path();
23432359
let sub = if self.eat(&token::AT) {
23442360
Some(self.parse_pat(refutable))
23452361
} else { None };
@@ -2437,7 +2453,7 @@ pub impl Parser {
24372453

24382454
// Potential trouble: if we allow macros with paths instead of
24392455
// idents, we'd need to look ahead past the whole path here...
2440-
let pth = self.parse_path_without_tps();
2456+
let pth = self.parse_value_path();
24412457
self.bump();
24422458

24432459
let id = if *self.token == token::LPAREN {
@@ -2942,7 +2958,7 @@ pub impl Parser {
29422958
}
29432959

29442960
fn parse_fn_header(&self) -> (ident, ast::Generics) {
2945-
let id = self.parse_ident();
2961+
let id = self.parse_value_ident();
29462962
let generics = self.parse_generics();
29472963
(id, generics)
29482964
}
@@ -2965,6 +2981,10 @@ pub impl Parser {
29652981
(ident, item_fn(decl, purity, generics, body), Some(inner_attrs))
29662982
}
29672983

2984+
fn parse_method_name(&self) -> ident {
2985+
self.parse_value_ident()
2986+
}
2987+
29682988
fn parse_method(&self) -> @method {
29692989
let attrs = self.parse_outer_attributes();
29702990
let lo = self.span.lo;
@@ -2974,7 +2994,7 @@ pub impl Parser {
29742994

29752995
let visa = self.parse_visibility();
29762996
let pur = self.parse_fn_purity();
2977-
let ident = self.parse_ident();
2997+
let ident = self.parse_method_name();
29782998
let generics = self.parse_generics();
29792999
let (self_ty, decl) = do self.parse_fn_decl_with_self() |p| {
29803000
p.parse_arg()
@@ -3098,7 +3118,7 @@ pub impl Parser {
30983118
}
30993119

31003120
fn parse_item_struct(&self) -> item_info {
3101-
let class_name = self.parse_ident();
3121+
let class_name = self.parse_value_ident();
31023122
self.parse_region_param();
31033123
let generics = self.parse_generics();
31043124
if self.eat(&token::COLON) {
@@ -3326,7 +3346,7 @@ pub impl Parser {
33263346
}
33273347

33283348
fn parse_item_const(&self) -> item_info {
3329-
let id = self.parse_ident();
3349+
let id = self.parse_value_ident();
33303350
self.expect(&token::COLON);
33313351
let ty = self.parse_ty(false);
33323352
self.expect(&token::EQ);
@@ -3724,7 +3744,7 @@ pub impl Parser {
37243744
kind = enum_variant_kind(nested_enum_def);
37253745
needs_comma = false;
37263746
} else {
3727-
ident = self.parse_ident();
3747+
ident = self.parse_value_ident();
37283748
if self.eat(&token::LBRACE) {
37293749
// Parse a struct variant.
37303750
all_nullary = false;

trunk/src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ pub fn print_item(s: @ps, &&item: @ast::item) {
567567
568568
ast::item_impl(ref generics, opt_trait, ty, ref methods) => {
569569
head(s, visibility_qualified(item.vis, ~"impl"));
570-
if !generics.is_empty() {
570+
if generics.is_parameterized() {
571571
print_generics(s, generics);
572572
space(s.s);
573573
}

trunk/src/test/run-pass/issue-5243.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that merely have lifetime parameters is not
12+
// enough for trans to consider this as non-monomorphic,
13+
// which led to various assertions and failures in turn.
14+
15+
struct S<'self> {
16+
v: &'self int
17+
}
18+
19+
fn f<'lt>(_s: &S<'lt>) {}
20+
21+
fn main() {
22+
f(& S { v: &42 });
23+
}

0 commit comments

Comments
 (0)