]> git.lizzy.rs Git - rust.git/commitdiff
Address comments + Fix rebase
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Wed, 14 Sep 2016 21:51:46 +0000 (00:51 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Thu, 27 Oct 2016 19:20:25 +0000 (22:20 +0300)
src/librustc/util/ppaux.rs
src/librustc_const_eval/pattern.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/mod.rs
src/test/compile-fail/struct-path-associated-type.rs
src/test/compile-fail/struct-path-self-type-mismatch.rs [new file with mode: 0644]
src/test/compile-fail/struct-path-self.rs
src/test/run-pass/issue-22546.rs

index c0b5969fa95986e10e8a9c14815da177023e2e8a..13202a454fe55a02f24c11c57adc6d8c386b4ccc 100644 (file)
@@ -802,34 +802,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-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 {
index a6c886533c86cba73fa6b770a9d5b091c43b9306..f4dedc184d96a6258b2f34224f9d2bff40dcd048 100644 (file)
@@ -436,7 +436,7 @@ fn lower_variant_or_leaf(
             }
 
             Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
-            Def::TyAlias(..) | Def::AssociatedTy(..) => {
+            Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => {
                 PatternKind::Leaf { subpatterns: subpatterns }
             }
 
index 0c71b0424ae6d08cf40ec37493c640bc64a97ab9..8799050b1b999058b31213ca74f418abba88ba77 100644 (file)
@@ -1520,17 +1520,11 @@ fn base_def_to_ty(&self,
                 // 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);
index 7f6c98efa4d47d9967286eff3708f23e7f303cd7..75a14bb3db9224ea5c367819a96362d8a6e966df 100644 (file)
@@ -3216,9 +3216,9 @@ fn check_struct_fields_on_error(&self,
     }
 
     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 @@ pub fn check_struct_path(&self,
             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
index 2f7330cb391b252b0136109049ed4e961226479f..660ac44ce0b53c07130fa71b89f73afac155d9d7 100644 (file)
@@ -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 (file)
index 0000000..f694e7d
--- /dev/null
@@ -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() {}
index d76b9fda8bf8207d565c190da7f51e45d8b714e9..067d6ac22dc6fb35a3a7e06fdb98c6be84487de7 100644 (file)
 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
         }
     }
 }
index fd9eb1f87c7433bee6b9bad525cfce1b06f65327..8516d344e1cdc41115c48335b24c017e712d972e 100644 (file)
@@ -54,4 +54,7 @@ fn main() {
     if let None::<u8> { .. } = Some(8) {
         panic!();
     }
+    if let Option::None::<u8> { .. } = Some(8) {
+        panic!();
+    }
 }