Skip to content

Commit 4b51892

Browse files
committed
librustc: Allow the type parameter version of Self to be spelled with a capital S
1 parent 3a5f146 commit 4b51892

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

src/librustc/middle/resolve.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,8 @@ fn Resolver(session: Session, lang_items: LanguageItems,
850850
current_trait_refs: None,
851851

852852
self_ident: special_idents::self_,
853+
type_self_ident: special_idents::type_self,
854+
853855
primitive_type_table: @PrimitiveTypeTable(session.
854856
parse_sess.interner),
855857

@@ -905,6 +907,8 @@ struct Resolver {
905907

906908
// The ident for the keyword "self".
907909
self_ident: ident,
910+
// The ident for the non-keyword "Self".
911+
type_self_ident: ident,
908912

909913
// The idents for the primitive types.
910914
primitive_type_table: @PrimitiveTypeTable,
@@ -3803,6 +3807,8 @@ impl Resolver {
38033807
(*self.type_ribs).push(self_type_rib);
38043808
self_type_rib.bindings.insert(self.self_ident,
38053809
dl_def(def_self_ty(item.id)));
3810+
self_type_rib.bindings.insert(self.type_self_ident,
3811+
dl_def(def_self_ty(item.id)));
38063812

38073813
// Create a new rib for the trait-wide type parameters.
38083814
do self.with_type_parameter_rib

src/libsyntax/parse/token.rs

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ mod special_idents {
340340
const clownshoes_foreign_mod: ident = ident { repr: 33 };
341341
const unnamed_field: ident = ident { repr: 34 };
342342
const c_abi: ident = ident { repr: 35 };
343+
const type_self: ident = ident { repr: 36 }; // `Self`
343344
}
344345

345346
struct ident_interner {
@@ -379,15 +380,43 @@ fn mk_ident_interner() -> @ident_interner {
379380
// the indices here must correspond to the numbers in
380381
// special_idents.
381382
let init_vec = ~[
382-
@~"_", @~"anon", @~"drop", @~"", @~"unary", @~"!",
383-
@~"[]", @~"unary-", @~"__extensions__", @~"self",
384-
@~"item", @~"block", @~"stmt", @~"pat", @~"expr",
385-
@~"ty", @~"ident", @~"path", @~"tt", @~"matchers",
386-
@~"str", @~"TyVisitor", @~"arg", @~"descrim",
387-
@~"__rust_abi", @~"__rust_stack_shim", @~"TyDesc",
388-
@~"dtor", @~"main", @~"<opaque>", @~"blk", @~"static",
389-
@~"intrinsic", @~"__foreign_mod__", @~"__field__",
390-
@~"C"
383+
@~"_", // 0
384+
@~"anon", // 1
385+
@~"drop", // 2
386+
@~"", // 3
387+
@~"unary", // 4
388+
@~"!", // 5
389+
@~"[]", // 6
390+
@~"unary-", // 7
391+
@~"__extensions__", // 8
392+
@~"self", // 9
393+
@~"item", // 10
394+
@~"block", // 11
395+
@~"stmt", // 12
396+
@~"pat", // 13
397+
@~"expr", // 14
398+
@~"ty", // 15
399+
@~"ident", // 16
400+
@~"path", // 17
401+
@~"tt", // 18
402+
@~"matchers", // 19
403+
@~"str", // 20
404+
@~"TyVisitor", // 21
405+
@~"arg", // 22
406+
@~"descrim", // 23
407+
@~"__rust_abi", // 24
408+
@~"__rust_stack_shim", // 25
409+
@~"TyDesc", // 26
410+
@~"dtor", // 27
411+
@~"main", // 28
412+
@~"<opaque>", // 29
413+
@~"blk", // 30
414+
@~"static", // 31
415+
@~"intrinsic", // 32
416+
@~"__foreign_mod__", // 33
417+
@~"__field__", // 34
418+
@~"C", // 35
419+
@~"Self", // 36
391420
];
392421

393422
let rv = @ident_interner {

src/test/run-pass/self-type-param.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait MyTrait {
2+
fn f(&self) -> Self;
3+
}
4+
5+
struct S {
6+
x: int
7+
}
8+
9+
impl S : MyTrait {
10+
fn f(&self) -> S {
11+
S { x: 3 }
12+
}
13+
}
14+
15+
fn main() {}
16+

0 commit comments

Comments
 (0)