Skip to content

Commit 6a2a7ed

Browse files
committed
Fixed issues raised in first review.
1 parent 74f2333 commit 6a2a7ed

File tree

7 files changed

+33
-85
lines changed

7 files changed

+33
-85
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::collections::BTreeSet;
3131
use std::iter;
3232
use std::slice;
3333

34-
use super::{allow_type_alias_enum_variants};
34+
use super::{check_type_alias_enum_variants_enabled};
3535

3636
pub trait AstConv<'gcx, 'tcx> {
3737
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx>;
@@ -1277,7 +1277,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
12771277
ref_id: ast::NodeId,
12781278
span: Span,
12791279
ty: Ty<'tcx>,
1280-
qself: &hir::Ty,
12811280
ty_path_def: Def,
12821281
item_segment: &hir::PathSegment)
12831282
-> (Ty<'tcx>, Def)
@@ -1296,10 +1295,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
12961295
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
12971296
});
12981297
if let Some(variant_def) = variant_def {
1299-
if allow_type_alias_enum_variants(tcx, qself, span) {
1300-
let def = Def::Variant(variant_def.did);
1301-
return (ty, def);
1302-
}
1298+
check_type_alias_enum_variants_enabled(tcx, span);
1299+
1300+
let def = Def::Variant(variant_def.did);
1301+
tcx.check_stability(def.def_id(), Some(ref_id), span);
1302+
return (ty, def);
13031303
}
13041304
}
13051305
}
@@ -1376,8 +1376,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
13761376
let item = tcx.associated_items(trait_did).find(|i| {
13771377
Namespace::from(i.kind) == Namespace::Type &&
13781378
i.ident.modern() == assoc_ident
1379-
})
1380-
.expect("missing associated type");
1379+
}).expect("missing associated type");
13811380

13821381
let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, bound);
13831382
let ty = self.normalize_ty(span, ty);
@@ -1618,7 +1617,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
16181617
} else {
16191618
Def::Err
16201619
};
1621-
self.associated_path_def_to_ty(ast_ty.id, ast_ty.span, ty, qself, def, segment).0
1620+
self.associated_path_def_to_ty(ast_ty.id, ast_ty.span, ty, def, segment).0
16221621
}
16231622
hir::TyKind::Array(ref ty, ref length) => {
16241623
let length_def_id = tcx.hir().local_def_id(length.id);

src/librustc_typeck/check/method/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc::infer::{self, InferOk};
2525
use syntax::ast;
2626
use syntax_pos::Span;
2727

28-
use crate::{allow_type_alias_enum_variants};
28+
use crate::{check_type_alias_enum_variants_enabled};
2929
use self::probe::{IsSuggestion, ProbeScope};
3030

3131
pub fn provide(providers: &mut ty::query::Providers) {
@@ -361,7 +361,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
361361
span: Span,
362362
method_name: ast::Ident,
363363
self_ty: Ty<'tcx>,
364-
qself: &hir::Ty,
365364
expr_id: ast::NodeId)
366365
-> Result<Def, MethodError<'tcx>> {
367366
debug!("resolve_ufcs: method_name={:?} self_ty={:?} expr_id={:?}",
@@ -379,10 +378,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
379378
tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
380379
});
381380
if let Some(variant_def) = variant_def {
382-
if allow_type_alias_enum_variants(tcx, qself, span) {
383-
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
384-
return Ok(def);
385-
}
381+
check_type_alias_enum_variants_enabled(tcx, span);
382+
383+
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
384+
tcx.check_stability(def.def_id(), Some(expr_id), span);
385+
return Ok(def);
386386
}
387387
}
388388
}

src/librustc_typeck/check/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
645645
fn type_derefs_to_local(&self,
646646
span: Span,
647647
rcvr_ty: Ty<'tcx>,
648-
rcvr_expr: Option<&hir::Expr>) -> bool {
648+
source: SelfSource) -> bool {
649649
fn is_local(ty: Ty) -> bool {
650650
match ty.sty {
651651
ty::Adt(def, _) => def.did.is_local(),

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,7 +4539,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
45394539
Def::Err
45404540
};
45414541
let (ty, def) = AstConv::associated_path_def_to_ty(self, node_id, path_span,
4542-
ty, qself, def, segment);
4542+
ty, def, segment);
45434543

45444544
// Write back the new resolution.
45454545
let hir_id = self.tcx.hir().node_to_hir_id(node_id);
@@ -4575,7 +4575,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
45754575
return (*cached_def, Some(ty), slice::from_ref(&**item_segment))
45764576
}
45774577
let item_name = item_segment.ident;
4578-
let def = match self.resolve_ufcs(span, item_name, ty, qself, node_id) {
4578+
let def = match self.resolve_ufcs(span, item_name, ty, node_id) {
45794579
Ok(def) => def,
45804580
Err(error) => {
45814581
let def = match error {

src/librustc_typeck/lib.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ mod outlives;
105105
mod variance;
106106

107107
use hir::Node;
108-
use hir::def::Def;
109108
use rustc_target::spec::abi::Abi;
110109
use rustc::hir;
111110
use rustc::infer::InferOk;
@@ -131,28 +130,20 @@ pub struct TypeAndSubsts<'tcx> {
131130
ty: Ty<'tcx>,
132131
}
133132

134-
fn allow_type_alias_enum_variants<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
135-
qself: &hir::Ty,
136-
span: Span) -> bool {
137-
let allow_feature = tcx.features().type_alias_enum_variants;
138-
if !allow_feature {
139-
// Only print error if we know the type is an alias.
140-
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = qself.node {
141-
if let Def::TyAlias(_) = path.def {
142-
let mut err = tcx.sess.struct_span_err(
143-
span,
144-
"enum variants on type aliases are experimental"
145-
);
146-
if nightly_options::is_nightly_build() {
147-
help!(&mut err,
148-
"add `#![feature(type_alias_enum_variants)]` to the \
149-
crate attributes to enable");
150-
}
151-
err.emit();
152-
}
133+
fn check_type_alias_enum_variants_enabled<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
134+
span: Span) {
135+
if !tcx.features().type_alias_enum_variants {
136+
let mut err = tcx.sess.struct_span_err(
137+
span,
138+
"enum variants on type aliases are experimental"
139+
);
140+
if nightly_options::is_nightly_build() {
141+
help!(&mut err,
142+
"add `#![feature(type_alias_enum_variants)]` to the \
143+
crate attributes to enable");
153144
}
145+
err.emit();
154146
}
155-
allow_feature
156147
}
157148

158149
fn require_c_abi_if_variadic(tcx: TyCtxt,

src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,12 @@ type Alias = Foo;
1818
fn main() {
1919
let t = Alias::Bar(0);
2020
//~^ ERROR enum variants on type aliases are experimental
21-
//~^^ ERROR no variant named `Bar` found for type `Foo` in the current scope
2221
let t = Alias::Baz { i: 0 };
2322
//~^ ERROR enum variants on type aliases are experimental
24-
//~^^ ERROR ambiguous associated type
2523
match t {
2624
Alias::Bar(_i) => {}
2725
//~^ ERROR enum variants on type aliases are experimental
28-
//~^^ ERROR no variant named `Bar` found for type `Foo` in the current scope
2926
Alias::Baz { i: _i } => {}
3027
//~^ ERROR enum variants on type aliases are experimental
31-
//~^^ ERROR ambiguous associated type
3228
}
3329
}

src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,29 @@ LL | let t = Alias::Bar(0);
66
|
77
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
88

9-
error[E0599]: no variant named `Bar` found for type `Foo` in the current scope
10-
--> $DIR/feature-gate-type_alias_enum_variants.rs:19:20
11-
|
12-
LL | enum Foo {
13-
| -------- variant `Bar` not found here
14-
...
15-
LL | let t = Alias::Bar(0);
16-
| -------^^^
17-
| |
18-
| variant not found in `Foo`
19-
|
20-
= help: did you mean `Bar`?
21-
229
error: enum variants on type aliases are experimental
23-
--> $DIR/feature-gate-type_alias_enum_variants.rs:22:13
10+
--> $DIR/feature-gate-type_alias_enum_variants.rs:21:13
2411
|
2512
LL | let t = Alias::Baz { i: 0 };
2613
| ^^^^^^^^^^
2714
|
2815
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
2916

30-
error[E0223]: ambiguous associated type
31-
--> $DIR/feature-gate-type_alias_enum_variants.rs:22:13
32-
|
33-
LL | let t = Alias::Baz { i: 0 };
34-
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Foo as Trait>::Baz`
35-
3617
error: enum variants on type aliases are experimental
37-
--> $DIR/feature-gate-type_alias_enum_variants.rs:26:9
18+
--> $DIR/feature-gate-type_alias_enum_variants.rs:24:9
3819
|
3920
LL | Alias::Bar(_i) => {}
4021
| ^^^^^^^^^^^^^^
4122
|
4223
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
4324

44-
error[E0599]: no variant named `Bar` found for type `Foo` in the current scope
45-
--> $DIR/feature-gate-type_alias_enum_variants.rs:26:16
46-
|
47-
LL | enum Foo {
48-
| -------- variant `Bar` not found here
49-
...
50-
LL | Alias::Bar(_i) => {}
51-
| -------^^^---- variant not found in `Foo`
52-
|
53-
= help: did you mean `Bar`?
54-
5525
error: enum variants on type aliases are experimental
56-
--> $DIR/feature-gate-type_alias_enum_variants.rs:29:9
26+
--> $DIR/feature-gate-type_alias_enum_variants.rs:26:9
5727
|
5828
LL | Alias::Baz { i: _i } => {}
5929
| ^^^^^^^^^^
6030
|
6131
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
6232

63-
error[E0223]: ambiguous associated type
64-
--> $DIR/feature-gate-type_alias_enum_variants.rs:29:9
65-
|
66-
LL | Alias::Baz { i: _i } => {}
67-
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Foo as Trait>::Baz`
68-
69-
error: aborting due to 8 previous errors
33+
error: aborting due to 4 previous errors
7034

71-
Some errors occurred: E0223, E0599.
72-
For more information about an error, try `rustc --explain E0223`.

0 commit comments

Comments
 (0)