Skip to content

Commit

Permalink
Rollup merge of rust-lang#40636 - nikomatsakis:revert-39485, r=eddyb
Browse files Browse the repository at this point in the history
Revert rust-lang#39485, fixing type-inference regressions

This reverts PR rust-lang#39485, which should fix the immediate regressions. Eventually I'd like to land rust-lang#40224 -- or some variant of it -- which revisits the question fo dead-code and inference.

r? @eddyb
cc @canndrew
  • Loading branch information
frewsxcv authored Mar 24, 2017
2 parents 6cf5988 + 0f1eb8a commit b561d2b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4099,6 +4099,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// 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)
//~^ ERROR mismatched types
//~| expected type `isize`
//~| found type `(_, _)`
//~| expected isize, found tuple
}

fn main() {}
17 changes: 17 additions & 0 deletions src/test/compile-fail/issue-5500.rs
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 3 additions & 4 deletions src/test/run-pass/issue-15763.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)
})
Expand Down
21 changes: 21 additions & 0 deletions src/test/run-pass/issue-39984.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

// Regression test for issue #39984.
//
// The key here is that the error type of the `Ok` call ought to be
// constrained to `String`, even though it is dead-code.

fn main() {}

fn t() -> Result<(), String> {
return Err("".into());
Ok(())
}
4 changes: 1 addition & 3 deletions src/test/run-pass/project-defer-unification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b561d2b

Please sign in to comment.