From 6a2a7edc0b3f3e296531a6b70a4d89a261bcfeb5 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Thu, 6 Dec 2018 04:22:56 +0000 Subject: [PATCH] Fixed issues raised in first review. --- src/librustc_typeck/astconv.rs | 17 ++++--- src/librustc_typeck/check/method/mod.rs | 12 ++--- src/librustc_typeck/check/method/suggest.rs | 2 +- src/librustc_typeck/check/mod.rs | 4 +- src/librustc_typeck/lib.rs | 33 +++++-------- .../feature-gate-type_alias_enum_variants.rs | 4 -- ...ature-gate-type_alias_enum_variants.stderr | 46 ++----------------- 7 files changed, 33 insertions(+), 85 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 67f330536b8..f15a27fbc8b 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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); diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 4c96d476caa..88814ae6a2d 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -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> { 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); } } } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index b368250b32d..98c425655d2 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -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(), diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 37739eb655f..b13c92c7f6e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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 { diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 8c0913a56b5..c55a1258ce9 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -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, diff --git a/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs b/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs index 2dcd0dcd243..8997c1824ca 100644 --- a/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs +++ b/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.rs @@ -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 } } diff --git a/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr b/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr index 7a49770d97a..cba643e18ca 100644 --- a/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr +++ b/src/test/ui/feature-gates/feature-gate-type_alias_enum_variants.stderr @@ -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: `::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: `::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`.