Skip to content

Commit ce5d106

Browse files
committed
Merge branch 'selfgate' of https://github.com/petrochenkov/rust into rollup
2 parents fdd34c3 + 50ecee2 commit ce5d106

8 files changed

+52
-0
lines changed

src/librustc_typeck/check/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -3240,6 +3240,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32403240
}
32413241
Def::Struct(..) | Def::Union(..) | Def::TyAlias(..) |
32423242
Def::AssociatedTy(..) | Def::SelfTy(..) => {
3243+
match def {
3244+
Def::AssociatedTy(..) | Def::SelfTy(..)
3245+
if !self.tcx.sess.features.borrow().more_struct_aliases => {
3246+
emit_feature_err(&self.tcx.sess.parse_sess,
3247+
"more_struct_aliases", path.span, GateIssue::Language,
3248+
"`Self` and associated types in struct \
3249+
expressions and patterns are unstable");
3250+
}
3251+
_ => {}
3252+
}
32433253
match ty.sty {
32443254
ty::TyAdt(adt, substs) if !adt.is_enum() => {
32453255
Some((adt.struct_variant(), adt.did, substs))

src/libsyntax/feature_gate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ declare_features! (
312312

313313
// The #![windows_subsystem] attribute
314314
(active, windows_subsystem, "1.14.0", Some(37499)),
315+
316+
// Allows using `Self` and associated types in struct expressions and patterns.
317+
(active, more_struct_aliases, "1.14.0", Some(37544)),
315318
);
316319

317320
declare_features! (

src/test/compile-fail/struct-path-associated-type.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(more_struct_aliases)]
12+
1113
struct S;
1214

1315
trait Tr {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2016 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+
struct S;
12+
13+
trait Tr {
14+
type A;
15+
}
16+
17+
fn f<T: Tr<A = S>>() {
18+
let _ = T::A {};
19+
//~^ ERROR `Self` and associated types in struct expressions and patterns are unstable
20+
}
21+
22+
impl S {
23+
fn f() {
24+
let _ = Self {};
25+
//~^ ERROR `Self` and associated types in struct expressions and patterns are unstable
26+
}
27+
}
28+
29+
fn main() {}

src/test/compile-fail/struct-path-self-type-mismatch.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(more_struct_aliases)]
12+
1113
struct Foo<A> { inner: A }
1214

1315
trait Bar { fn bar(); }

src/test/compile-fail/struct-path-self.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(more_struct_aliases)]
12+
1113
struct S;
1214

1315
trait Tr {

src/test/run-pass/struct-path-associated-type.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(more_struct_aliases)]
12+
1113
struct S<T, U = u16> {
1214
a: T,
1315
b: U,

src/test/run-pass/struct-path-self.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(more_struct_aliases)]
12+
1113
use std::ops::Add;
1214

1315
struct S<T, U = u16> {

0 commit comments

Comments
 (0)