diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 2fb922c3e52..3dce81df5f3 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -850,6 +850,8 @@ fn Resolver(session: Session, lang_items: LanguageItems, current_trait_refs: None, self_ident: special_idents::self_, + type_self_ident: special_idents::type_self, + primitive_type_table: @PrimitiveTypeTable(session. parse_sess.interner), @@ -905,6 +907,8 @@ struct Resolver { // The ident for the keyword "self". self_ident: ident, + // The ident for the non-keyword "Self". + type_self_ident: ident, // The idents for the primitive types. primitive_type_table: @PrimitiveTypeTable, @@ -3803,6 +3807,8 @@ impl Resolver { (*self.type_ribs).push(self_type_rib); self_type_rib.bindings.insert(self.self_ident, dl_def(def_self_ty(item.id))); + self_type_rib.bindings.insert(self.type_self_ident, + dl_def(def_self_ty(item.id))); // Create a new rib for the trait-wide type parameters. do self.with_type_parameter_rib diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 606247b8cbe..93c03063623 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -340,6 +340,7 @@ mod special_idents { const clownshoes_foreign_mod: ident = ident { repr: 33 }; const unnamed_field: ident = ident { repr: 34 }; const c_abi: ident = ident { repr: 35 }; + const type_self: ident = ident { repr: 36 }; // `Self` } struct ident_interner { @@ -379,15 +380,43 @@ fn mk_ident_interner() -> @ident_interner { // the indices here must correspond to the numbers in // special_idents. let init_vec = ~[ - @~"_", @~"anon", @~"drop", @~"", @~"unary", @~"!", - @~"[]", @~"unary-", @~"__extensions__", @~"self", - @~"item", @~"block", @~"stmt", @~"pat", @~"expr", - @~"ty", @~"ident", @~"path", @~"tt", @~"matchers", - @~"str", @~"TyVisitor", @~"arg", @~"descrim", - @~"__rust_abi", @~"__rust_stack_shim", @~"TyDesc", - @~"dtor", @~"main", @~"", @~"blk", @~"static", - @~"intrinsic", @~"__foreign_mod__", @~"__field__", - @~"C" + @~"_", // 0 + @~"anon", // 1 + @~"drop", // 2 + @~"", // 3 + @~"unary", // 4 + @~"!", // 5 + @~"[]", // 6 + @~"unary-", // 7 + @~"__extensions__", // 8 + @~"self", // 9 + @~"item", // 10 + @~"block", // 11 + @~"stmt", // 12 + @~"pat", // 13 + @~"expr", // 14 + @~"ty", // 15 + @~"ident", // 16 + @~"path", // 17 + @~"tt", // 18 + @~"matchers", // 19 + @~"str", // 20 + @~"TyVisitor", // 21 + @~"arg", // 22 + @~"descrim", // 23 + @~"__rust_abi", // 24 + @~"__rust_stack_shim", // 25 + @~"TyDesc", // 26 + @~"dtor", // 27 + @~"main", // 28 + @~"", // 29 + @~"blk", // 30 + @~"static", // 31 + @~"intrinsic", // 32 + @~"__foreign_mod__", // 33 + @~"__field__", // 34 + @~"C", // 35 + @~"Self", // 36 ]; let rv = @ident_interner { diff --git a/src/test/run-pass/self-type-param.rs b/src/test/run-pass/self-type-param.rs new file mode 100644 index 00000000000..ea42045fc46 --- /dev/null +++ b/src/test/run-pass/self-type-param.rs @@ -0,0 +1,16 @@ +trait MyTrait { + fn f(&self) -> Self; +} + +struct S { + x: int +} + +impl S : MyTrait { + fn f(&self) -> S { + S { x: 3 } + } +} + +fn main() {} +