Fixed issues raised in first review.

This commit is contained in:
Alexander Regueiro 2018-12-06 04:22:56 +00:00
parent 74f233388a
commit 6a2a7edc0b
7 changed files with 33 additions and 85 deletions

View File

@ -31,7 +31,7 @@ use std::collections::BTreeSet;
use std::iter;
use std::slice;
use super::{allow_type_alias_enum_variants};
use super::{check_type_alias_enum_variants_enabled};
pub trait AstConv<'gcx, 'tcx> {
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx>;
@ -1277,7 +1277,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
ref_id: ast::NodeId,
span: Span,
ty: Ty<'tcx>,
qself: &hir::Ty,
ty_path_def: Def,
item_segment: &hir::PathSegment)
-> (Ty<'tcx>, Def)
@ -1296,10 +1295,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
tcx.hygienic_eq(assoc_name, vd.ident, adt_def.did)
});
if let Some(variant_def) = variant_def {
if allow_type_alias_enum_variants(tcx, qself, span) {
let def = Def::Variant(variant_def.did);
return (ty, def);
}
check_type_alias_enum_variants_enabled(tcx, span);
let def = Def::Variant(variant_def.did);
tcx.check_stability(def.def_id(), Some(ref_id), span);
return (ty, def);
}
}
}
@ -1376,8 +1376,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
let item = tcx.associated_items(trait_did).find(|i| {
Namespace::from(i.kind) == Namespace::Type &&
i.ident.modern() == assoc_ident
})
.expect("missing associated type");
}).expect("missing associated type");
let ty = self.projected_ty_from_poly_trait_ref(span, item.def_id, bound);
let ty = self.normalize_ty(span, ty);
@ -1618,7 +1617,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
} else {
Def::Err
};
self.associated_path_def_to_ty(ast_ty.id, ast_ty.span, ty, qself, def, segment).0
self.associated_path_def_to_ty(ast_ty.id, ast_ty.span, ty, def, segment).0
}
hir::TyKind::Array(ref ty, ref length) => {
let length_def_id = tcx.hir().local_def_id(length.id);

View File

@ -25,7 +25,7 @@ use rustc::infer::{self, InferOk};
use syntax::ast;
use syntax_pos::Span;
use crate::{allow_type_alias_enum_variants};
use crate::{check_type_alias_enum_variants_enabled};
use self::probe::{IsSuggestion, ProbeScope};
pub fn provide(providers: &mut ty::query::Providers) {
@ -361,7 +361,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
span: Span,
method_name: ast::Ident,
self_ty: Ty<'tcx>,
qself: &hir::Ty,
expr_id: ast::NodeId)
-> Result<Def, MethodError<'tcx>> {
debug!("resolve_ufcs: method_name={:?} self_ty={:?} expr_id={:?}",
@ -379,10 +378,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
tcx.hygienic_eq(method_name, vd.ident, adt_def.did)
});
if let Some(variant_def) = variant_def {
if allow_type_alias_enum_variants(tcx, qself, span) {
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
return Ok(def);
}
check_type_alias_enum_variants_enabled(tcx, span);
let def = Def::VariantCtor(variant_def.did, variant_def.ctor_kind);
tcx.check_stability(def.def_id(), Some(expr_id), span);
return Ok(def);
}
}
}

View File

@ -645,7 +645,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn type_derefs_to_local(&self,
span: Span,
rcvr_ty: Ty<'tcx>,
rcvr_expr: Option<&hir::Expr>) -> bool {
source: SelfSource) -> bool {
fn is_local(ty: Ty) -> bool {
match ty.sty {
ty::Adt(def, _) => def.did.is_local(),

View File

@ -4539,7 +4539,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Def::Err
};
let (ty, def) = AstConv::associated_path_def_to_ty(self, node_id, path_span,
ty, qself, def, segment);
ty, def, segment);
// Write back the new resolution.
let hir_id = self.tcx.hir().node_to_hir_id(node_id);
@ -4575,7 +4575,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
return (*cached_def, Some(ty), slice::from_ref(&**item_segment))
}
let item_name = item_segment.ident;
let def = match self.resolve_ufcs(span, item_name, ty, qself, node_id) {
let def = match self.resolve_ufcs(span, item_name, ty, node_id) {
Ok(def) => def,
Err(error) => {
let def = match error {

View File

@ -105,7 +105,6 @@ mod outlives;
mod variance;
use hir::Node;
use hir::def::Def;
use rustc_target::spec::abi::Abi;
use rustc::hir;
use rustc::infer::InferOk;
@ -131,28 +130,20 @@ pub struct TypeAndSubsts<'tcx> {
ty: Ty<'tcx>,
}
fn allow_type_alias_enum_variants<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
qself: &hir::Ty,
span: Span) -> bool {
let allow_feature = tcx.features().type_alias_enum_variants;
if !allow_feature {
// Only print error if we know the type is an alias.
if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = qself.node {
if let Def::TyAlias(_) = path.def {
let mut err = tcx.sess.struct_span_err(
span,
"enum variants on type aliases are experimental"
);
if nightly_options::is_nightly_build() {
help!(&mut err,
"add `#![feature(type_alias_enum_variants)]` to the \
crate attributes to enable");
}
err.emit();
}
fn check_type_alias_enum_variants_enabled<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
span: Span) {
if !tcx.features().type_alias_enum_variants {
let mut err = tcx.sess.struct_span_err(
span,
"enum variants on type aliases are experimental"
);
if nightly_options::is_nightly_build() {
help!(&mut err,
"add `#![feature(type_alias_enum_variants)]` to the \
crate attributes to enable");
}
err.emit();
}
allow_feature
}
fn require_c_abi_if_variadic(tcx: TyCtxt,

View File

@ -18,16 +18,12 @@ type Alias = Foo;
fn main() {
let t = Alias::Bar(0);
//~^ ERROR enum variants on type aliases are experimental
//~^^ ERROR no variant named `Bar` found for type `Foo` in the current scope
let t = Alias::Baz { i: 0 };
//~^ ERROR enum variants on type aliases are experimental
//~^^ ERROR ambiguous associated type
match t {
Alias::Bar(_i) => {}
//~^ ERROR enum variants on type aliases are experimental
//~^^ ERROR no variant named `Bar` found for type `Foo` in the current scope
Alias::Baz { i: _i } => {}
//~^ ERROR enum variants on type aliases are experimental
//~^^ ERROR ambiguous associated type
}
}

View File

@ -6,67 +6,29 @@ LL | let t = Alias::Bar(0);
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
error[E0599]: no variant named `Bar` found for type `Foo` in the current scope
--> $DIR/feature-gate-type_alias_enum_variants.rs:19:20
|
LL | enum Foo {
| -------- variant `Bar` not found here
...
LL | let t = Alias::Bar(0);
| -------^^^
| |
| variant not found in `Foo`
|
= help: did you mean `Bar`?
error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:22:13
--> $DIR/feature-gate-type_alias_enum_variants.rs:21:13
|
LL | let t = Alias::Baz { i: 0 };
| ^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
error[E0223]: ambiguous associated type
--> $DIR/feature-gate-type_alias_enum_variants.rs:22:13
|
LL | let t = Alias::Baz { i: 0 };
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Foo as Trait>::Baz`
error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:26:9
--> $DIR/feature-gate-type_alias_enum_variants.rs:24:9
|
LL | Alias::Bar(_i) => {}
| ^^^^^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
error[E0599]: no variant named `Bar` found for type `Foo` in the current scope
--> $DIR/feature-gate-type_alias_enum_variants.rs:26:16
|
LL | enum Foo {
| -------- variant `Bar` not found here
...
LL | Alias::Bar(_i) => {}
| -------^^^---- variant not found in `Foo`
|
= help: did you mean `Bar`?
error: enum variants on type aliases are experimental
--> $DIR/feature-gate-type_alias_enum_variants.rs:29:9
--> $DIR/feature-gate-type_alias_enum_variants.rs:26:9
|
LL | Alias::Baz { i: _i } => {}
| ^^^^^^^^^^
|
= help: add `#![feature(type_alias_enum_variants)]` to the crate attributes to enable
error[E0223]: ambiguous associated type
--> $DIR/feature-gate-type_alias_enum_variants.rs:29:9
|
LL | Alias::Baz { i: _i } => {}
| ^^^^^^^^^^ help: use fully-qualified syntax: `<Foo as Trait>::Baz`
error: aborting due to 4 previous errors
error: aborting due to 8 previous errors
Some errors occurred: E0223, E0599.
For more information about an error, try `rustc --explain E0223`.