forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR rust-lang#17603 introduced bottom type fallback but did it a bit too eagerly. This patch makes the fallback lazy so that `typeck` can run its cause and detect as many type errors as possible with regard to diverging types. Closes rust-lang#21878
- Loading branch information
Showing
6 changed files
with
100 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2015 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. | ||
|
||
// Make sure that bottom type fallback doesn't introduce type system | ||
// holes. See issue #21878 for more details. | ||
|
||
trait Foo {} | ||
impl Foo for () {} | ||
impl Foo for i32 {} | ||
|
||
struct Error; | ||
impl Error { | ||
fn foo(&self) -> ! { loop {} } | ||
} | ||
|
||
fn bar<T: Foo>() -> Result<T, Error> { loop {} } | ||
|
||
fn main() { | ||
let _ = bar().unwrap_or_else(|e| e.foo()); //~ ERROR unable to infer enough type information | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2015 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. | ||
|
||
// Make sure that bottom type fallback doesn't introduce type system | ||
// holes. See issue #21878 for more details. | ||
|
||
trait Foo {} | ||
impl Foo for () {} | ||
impl Foo for i32 {} | ||
|
||
struct Error; | ||
impl Error { | ||
fn foo(&self) -> ! { loop {} } | ||
} | ||
|
||
fn bar<T: Foo>() -> Result<T, Error> { loop {} } | ||
|
||
fn main() { | ||
let _: u8 = bar().unwrap_or_else(|e| e.foo()); | ||
//~^ ERROR the trait `Foo` is not implemented for the type `u8` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2015 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. | ||
|
||
// Make sure that bottom type fallback doesn't introduce type system | ||
// holes. See issue #21878 for more details. | ||
|
||
// error-pattern:explicit panic | ||
|
||
trait Foo {} | ||
impl Foo for () {} | ||
impl Foo for i32 {} | ||
|
||
struct Error; | ||
impl Error { | ||
fn foo(&self) -> ! { panic!() } | ||
} | ||
|
||
fn bar<T: Foo>() -> Result<T, Error> { panic!() } | ||
|
||
fn main() { | ||
let _: i32 = bar().unwrap_or_else(|e| e.foo()); | ||
} |