diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-09-15 00:51:46 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-10-27 22:20:25 +0300 |
| commit | 8a38928b44e26d4d7b9bdacb207a85878058cac8 (patch) | |
| tree | a5d81b3f1cfb8048be4233049b7b192fdec17e1d | |
| parent | eada951f9c302d531d6b9ad474e87faafea9a5d5 (diff) | |
| download | rust-8a38928b44e26d4d7b9bdacb207a85878058cac8.tar.gz rust-8a38928b44e26d4d7b9bdacb207a85878058cac8.zip | |
Address comments + Fix rebase
| -rw-r--r-- | src/librustc/util/ppaux.rs | 28 | ||||
| -rw-r--r-- | src/librustc_const_eval/pattern.rs | 2 | ||||
| -rw-r--r-- | src/librustc_typeck/astconv.rs | 16 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 10 | ||||
| -rw-r--r-- | src/test/compile-fail/struct-path-associated-type.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/struct-path-self-type-mismatch.rs | 38 | ||||
| -rw-r--r-- | src/test/compile-fail/struct-path-self.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/issue-22546.rs | 3 |
8 files changed, 58 insertions, 51 deletions
diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index c0b5969fa95..13202a454fe 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -802,34 +802,6 @@ impl<'tcx> fmt::Display for ty::TraitRef<'tcx> { } } -impl<'tcx> ty::TypeVariants<'tcx> { - pub fn descr(&self) -> &'static str { - match *self { - TyInt(..) | TyUint(..) | TyFloat(..) | - TyBool | TyChar | TyStr => "builtin type", - TyRawPtr(..) => "pointer", - TyRef(..) => "reference", - TyTuple(..) => "tuple", - TyFnDef(..) => "function type", - TyFnPtr(..) => "function pointer", - TyArray(..) => "array", - TySlice(..) => "slice", - TyParam(..) => "type parameter", - TyProjection(..) => "associated type", - TyTrait(..) => "trait type", - TyClosure(..) => "closure type", - TyBox(..) => "struct", - TyAdt(def, ..) => match def.adt_kind() { - ty::AdtKind::Struct => "struct", - ty::AdtKind::Union => "union", - ty::AdtKind::Enum => "enum", - }, - TyInfer(..) | TyAnon(..) | - TyNever | TyError => "type", - } - } -} - impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/src/librustc_const_eval/pattern.rs b/src/librustc_const_eval/pattern.rs index a6c886533c8..f4dedc184d9 100644 --- a/src/librustc_const_eval/pattern.rs +++ b/src/librustc_const_eval/pattern.rs @@ -436,7 +436,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> { } Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) | - Def::TyAlias(..) | Def::AssociatedTy(..) => { + Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => { PatternKind::Leaf { subpatterns: subpatterns } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 0c71b0424ae..8799050b1b9 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1520,17 +1520,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { // Convert "variant type" as if it were a real type. // The resulting `Ty` is type of the variant's enum for now. tcx.prohibit_type_params(base_segments.split_last().unwrap().1); - let mut ty = self.ast_path_to_ty(rscope, - span, - param_mode, - tcx.parent_def_id(did).unwrap(), - base_segments.last().unwrap()); - if ty.is_fn() { - // Tuple variants have fn type even in type namespace, - // extract true variant type from it. - ty = tcx.no_late_bound_regions(&ty.fn_ret()).unwrap(); - } - ty + self.ast_path_to_ty(rscope, + span, + param_mode, + tcx.parent_def_id(did).unwrap(), + base_segments.last().unwrap()) } Def::TyParam(did) => { tcx.prohibit_type_params(base_segments); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7f6c98efa4d..75a14bb3db9 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3216,9 +3216,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } pub fn check_struct_path(&self, - path: &hir::Path, - node_id: ast::NodeId) - -> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> { + path: &hir::Path, + node_id: ast::NodeId) + -> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> { let (def, ty) = self.finish_resolving_struct_path(path, node_id); let variant = match def { Def::Err => { @@ -3263,8 +3263,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Some((variant, ty)) } else { struct_span_err!(self.tcx.sess, path.span, E0071, - "expected struct, variant or union type, found {} `{}`", - ty.sty.descr(), ty) + "expected struct, variant or union type, found {}", + ty.sort_string(self.tcx)) .span_label(path.span, &format!("not a struct")) .emit(); None diff --git a/src/test/compile-fail/struct-path-associated-type.rs b/src/test/compile-fail/struct-path-associated-type.rs index 2f7330cb391..660ac44ce0b 100644 --- a/src/test/compile-fail/struct-path-associated-type.rs +++ b/src/test/compile-fail/struct-path-associated-type.rs @@ -20,13 +20,13 @@ impl Tr for S { fn f<T: Tr>() { let s = T::A {}; - //~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A` + //~^ ERROR expected struct, variant or union type, found associated type let z = T::A::<u8> {}; - //~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A` + //~^ ERROR expected struct, variant or union type, found associated type //~| ERROR type parameters are not allowed on this type match S { T::A {} => {} - //~^ ERROR expected struct, variant or union type, found associated type `<T as Tr>::A` + //~^ ERROR expected struct, variant or union type, found associated type } } diff --git a/src/test/compile-fail/struct-path-self-type-mismatch.rs b/src/test/compile-fail/struct-path-self-type-mismatch.rs new file mode 100644 index 00000000000..f694e7d277c --- /dev/null +++ b/src/test/compile-fail/struct-path-self-type-mismatch.rs @@ -0,0 +1,38 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct Foo<A> { inner: A } + +trait Bar { fn bar(); } + +impl Bar for Foo<i32> { + fn bar() { + Self { inner: 1.5f32 }; //~ ERROR mismatched types + //~^ NOTE expected i32, found f32 + } +} + +impl<T> Foo<T> { + fn new<U>(u: U) -> Foo<U> { + Self { + //~^ ERROR mismatched types + //~| expected type parameter, found a different type parameter + //~| expected type `Foo<U>` + //~| found type `Foo<T>` + inner: u + //~^ ERROR mismatched types + //~| expected type parameter, found a different type parameter + //~| expected type `T` + //~| found type `U` + } + } +} + +fn main() {} diff --git a/src/test/compile-fail/struct-path-self.rs b/src/test/compile-fail/struct-path-self.rs index d76b9fda8bf..067d6ac22dc 100644 --- a/src/test/compile-fail/struct-path-self.rs +++ b/src/test/compile-fail/struct-path-self.rs @@ -13,13 +13,13 @@ struct S; trait Tr { fn f() { let s = Self {}; - //~^ ERROR expected struct, variant or union type, found type parameter `Self` + //~^ ERROR expected struct, variant or union type, found Self let z = Self::<u8> {}; - //~^ ERROR expected struct, variant or union type, found type parameter `Self` + //~^ ERROR expected struct, variant or union type, found Self //~| ERROR type parameters are not allowed on this type match s { Self { .. } => {} - //~^ ERROR expected struct, variant or union type, found type parameter `Self` + //~^ ERROR expected struct, variant or union type, found Self } } } diff --git a/src/test/run-pass/issue-22546.rs b/src/test/run-pass/issue-22546.rs index fd9eb1f87c7..8516d344e1c 100644 --- a/src/test/run-pass/issue-22546.rs +++ b/src/test/run-pass/issue-22546.rs @@ -54,4 +54,7 @@ fn main() { if let None::<u8> { .. } = Some(8) { panic!(); } + if let Option::None::<u8> { .. } = Some(8) { + panic!(); + } } |
