]> git.lizzy.rs Git - rust.git/commitdiff
Revert "Auto merge of #39485 - canndrew:inference-fix-39297, r=nikomatsakis"
authorNiko Matsakis <niko@alum.mit.edu>
Sat, 18 Mar 2017 16:24:42 +0000 (12:24 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 22 Mar 2017 15:13:09 +0000 (11:13 -0400)
This reverts commit dc0bb3f2839c13ab42feacd423f728fbfd2f2f7a, reversing
changes made to e879aa43ef63962f8e4d797292194a9f40a22a13.

This is a temporary step intended to fix regressions. A more
comprehensive fix for type inference and dead-code is in the works.

src/librustc_typeck/check/mod.rs
src/test/compile-fail/issue-10176.rs [new file with mode: 0644]
src/test/compile-fail/issue-5500.rs [new file with mode: 0644]
src/test/run-pass/inference-changes-39485.rs [deleted file]
src/test/run-pass/issue-15763.rs
src/test/run-pass/project-defer-unification.rs

index c857388106d5ad6c2fe89e628c3f3b657b158e3e..9c62fd486d45a6f7574133a2e5fa387767e27a50 100644 (file)
@@ -4099,6 +4099,17 @@ fn check_block_with_expected(&self,
             };
 
             if self.diverges.get().always() {
+                if let ExpectHasType(ety) = expected {
+                    // Avoid forcing a type (only `!` for now) in unreachable code.
+                    // FIXME(aburka) do we need this special case? and should it be is_uninhabited?
+                    if !ety.is_never() {
+                        if let Some(ref e) = blk.expr {
+                            // Coerce the tail expression to the right type.
+                            self.demand_coerce(e, ty, ety);
+                        }
+                    }
+                }
+
                 ty = self.next_diverging_ty_var(TypeVariableOrigin::DivergingBlockExpr(blk.span));
             } else if let ExpectHasType(ety) = expected {
                 if let Some(ref e) = blk.expr {
diff --git a/src/test/compile-fail/issue-10176.rs b/src/test/compile-fail/issue-10176.rs
new file mode 100644 (file)
index 0000000..434b795
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2014 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.
+
+fn f() -> isize {
+    (return 1, return 2)
+//~^ ERROR mismatched types
+//~| expected type `isize`
+//~| found type `(_, _)`
+//~| expected isize, found tuple
+}
+
+fn main() {}
diff --git a/src/test/compile-fail/issue-5500.rs b/src/test/compile-fail/issue-5500.rs
new file mode 100644 (file)
index 0000000..1cbb758
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2013 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.
+
+fn main() {
+    &panic!()
+    //~^ ERROR mismatched types
+    //~| expected type `()`
+    //~| found type `&_`
+    //~| expected (), found reference
+}
diff --git a/src/test/run-pass/inference-changes-39485.rs b/src/test/run-pass/inference-changes-39485.rs
deleted file mode 100644 (file)
index 193c66b..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2014 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.
-
-fn g() {
-    &panic!()
-}
-
-fn f() -> isize {
-    (return 1, return 2)
-}
-
-fn main() {}
index f77888c29554db81c6ab7ba84eb6d245d9712403..0baaaac26768571ca91c8d118794d0bb2a4d5c50 100644 (file)
@@ -8,8 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![allow(unused_features)]
-#![allow(unreachable_code)]
+#![allow(unknown_features)]
 #![feature(box_syntax)]
 
 #[derive(PartialEq, Debug)]
@@ -29,14 +28,14 @@ struct Foo {
 }
 
 fn foo() -> Result<Foo, isize> {
-    return Ok::<Foo, isize>(Foo {
+    return Ok(Foo {
         x: Bar { x: 22 },
         a: return Err(32)
     });
 }
 
 fn baz() -> Result<Foo, isize> {
-    Ok::<Foo, isize>(Foo {
+    Ok(Foo {
         x: Bar { x: 22 },
         a: return Err(32)
     })
index 8e008c639b30eb6cc00d1977f5ce1f2a6fa156be..9a6ea2272fea7c5ca453595a1c0f3343eed99212 100644 (file)
@@ -11,8 +11,6 @@
 // A regression test extracted from image-0.3.11. The point of
 // failure was in `index_colors` below.
 
-#![allow(unused)]
-
 use std::ops::{Deref, DerefMut};
 
 #[derive(Copy, Clone)]
@@ -94,7 +92,7 @@ pub fn index_colors<Pix>(image: &ImageBuffer<Pix, Vec<u8>>)
                          -> ImageBuffer<Luma<u8>, Vec<u8>>
 where Pix: Pixel<Subpixel=u8> + 'static,
 {
-    let mut indices: ImageBuffer<Luma<u8>, Vec<u8>> = loop { };
+    let mut indices: ImageBuffer<_,Vec<_>> = loop { };
     for (pixel, idx) in image.pixels().zip(indices.pixels_mut()) {
         // failured occurred here ^^ because we were requiring that we
         // could project Pixel or Subpixel from `T_indices` (type of