Skip to content

Commit a65b5d8

Browse files
author
Alexander Regueiro
committed
Fixed issues raised in first review.
1 parent 3acef7a commit a65b5d8

File tree

7 files changed

+33
-85
lines changed

7 files changed

+33
-85
lines changed

src/librustc_typeck/astconv.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::collections::BTreeSet;
4141
use std::iter;
4242
use std::slice;
4343

44-
use super::{allow_type_alias_enum_variants};
44+
use super::{check_type_alias_enum_variants_enabled};
4545

4646
pub trait AstConv<'gcx, 'tcx> {
4747
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx>;
@@ -1263,7 +1263,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
12631263
ref_id: ast::NodeId,
12641264
span: Span,
12651265
ty: Ty<'tcx>,
1266-
qself: &hir::Ty,
12671266
ty_path_def: Def,
12681267
item_segment: &hir::PathSegment)
12691268
-> (Ty<'tcx>, Def)
@@ -1282,10 +1281,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
12821281
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
12831282
});
12841283
if let Some(variant_def) = variant_def {
1285-
if allow_type_alias_enum_variants(tcx, qself, span) {
1286-
let def = Def::Variant(variant_def.did);
1287-
return (ty, def);
1288-
}
1284+
check_type_alias_enum_variants_enabled(tcx, span);
1285+
1286+
let def = Def::Variant(variant_def.did);
1287+
tcx.check_stability(def.def_id(), Some(ref_id), span);
1288+
return (ty, def);
12891289
}
12901290
}
12911291
}
@@ -1362,8 +1362,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
13621362
let item = tcx.associated_items(trait_did).find(|i| {
13631363
Namespace::from(i.kind) == Namespace::Type &&
13641364
i.ident.modern() == assoc_ident
1365-
})
1366-
.expect("missing associated type");
1365+
}).expect("missing associated type");
13671366

13681367
let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, bound);
13691368
let ty = self.normalize_ty(span, ty);
@@ -1604,7 +1603,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
16041603
} else {
16051604
Def::Err
16061605
};
1607-
self.associated_path_def_to_ty(ast_ty.id, ast_ty.span, ty, qself, def, segment).0
1606+
self.associated_path_def_to_ty(ast_ty.id, ast_ty.span, ty, def, segment).0
16081607
}
16091608
hir::TyKind::Array(ref ty, ref length) => {
16101609
let length_def_id = tcx.hir().local_def_id(length.id);

src/librustc_typeck/check/method/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc::infer::{self, InferOk};
3535
use syntax::ast;
3636
use syntax_pos::Span;
3737

38-
use crate::{allow_type_alias_enum_variants};
38+
use crate::{check_type_alias_enum_variants_enabled};
3939
use self::probe::{IsSuggestion, ProbeScope};
4040

4141
pub fn provide(providers: &mut ty::query::Providers) {
@@ -370,7 +370,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
370370
span: Span,
371371
method_name: ast::Ident,
372372
self_ty: Ty<'tcx>,
373-
qself: &hir::Ty,
374373
expr_id: ast::NodeId)
375374
-> Result<Def, MethodError<'tcx>> {
376375
debug!("resolve_ufcs: method_name={:?} self_ty={:?} expr_id={:?}",
@@ -388,10 +387,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
388387
tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
389388
});
390389
if let Some(variant_def) = variant_def {
391-
if allow_type_alias_enum_variants(tcx, qself, span) {
392-
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
393-
return Ok(def);
394-
}
390+
check_type_alias_enum_variants_enabled(tcx, span);
391+
392+
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
393+
tcx.check_stability(def.def_id(), Some(expr_id), span);
394+
return Ok(def);
395395
}
396396
}
397397
}

src/librustc_typeck/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
653653
fn type_derefs_to_local(&self,
654654
span: Span,
655655
rcvr_ty: Ty<'tcx>,
656-
rcvr_expr: Option<&hir::Expr>) -> bool {
656+
source: SelfSource) -> bool {
657657
fn is_local(ty: Ty) -> bool {
658658
match ty.sty {
659659
ty::Adt(def, _) => def.did.is_local(),

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4458,7 +4458,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
44584458
Def::Err
44594459
};
44604460
let (ty, def) = AstConv::associated_path_def_to_ty(self, node_id, path_span,
4461-
ty, qself, def, segment);
4461+
ty, def, segment);
44624462

44634463
// Write back the new resolution.
44644464
let hir_id = self.tcx.hir().node_to_hir_id(node_id);
@@ -4494,7 +4494,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
44944494
return (*cached_def, Some(ty), slice::from_ref(&**item_segment))
44954495
}
44964496
let item_name = item_segment.ident;
4497-
let def = match self.resolve_ufcs(span, item_name, ty, qself, node_id) {
4497+
let def = match self.resolve_ufcs(span, item_name, ty, node_id) {
44984498
Ok(def) => def,
44994499
Err(error) => {
45004500
let def = match error {

src/librustc_typeck/lib.rs

+12-21
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ mod outlives;
114114
mod variance;
115115

116116
use hir::Node;
117-
use hir::def::Def;
118117
use rustc_target::spec::abi::Abi;
119118
use rustc::hir;
120119
use rustc::infer::InferOk;
@@ -140,28 +139,20 @@ pub struct TypeAndSubsts<'tcx> {
140139
ty: Ty<'tcx>,
141140
}
142141

143-
fn allow_type_alias_enum_variants<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
144-
qself: &hir::Ty,
145-
span: Span) -> bool {
146-
let allow_feature = tcx.features().type_alias_enum_variants;
147-
if !allow_feature {
148-
// Only print error if we know the type is an alias.
149-
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = qself.node {
150-
if let Def::TyAlias(_) = path.def {
151-
let mut err = tcx.sess.struct_span_err(
152-
span,
153-
"enum variants on type aliases are experimental"
154-
);
155-
if nightly_options::is_nightly_build() {
156-
help!(&mut err,
157-
"add `#![feature(type_alias_enum_variants)]` to the \
158-
crate attributes to enable");
159-
}
160-
err.emit();
161-
}
142+
fn check_type_alias_enum_variants_enabled<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
143+
span: Span) {
144+
if !tcx.features().type_alias_enum_variants {
145+
let mut err = tcx.sess.struct_span_err(
146+
span,
147+
"enum variants on type aliases are experimental"
148+
);
149+
if nightly_options::is_nightly_build() {
150+
help!(&mut err,
151+
"add `#![feature(type_alias_enum_variants)]` to the \
152+
crate attributes to enable");
162153
}
154+
err.emit();
163155
}
164-
allow_feature
165156
}
166157

167158
fn require_c_abi_if_variadic(tcx: TyCtxt,

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

-4
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

+4-42
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)