Skip to content

Commit 2b3b115

Browse files
authored
Rollup merge of #72548 - rossmacarthur:add-mcve-for-50687, r=nikomatsakis
Add test for old compiler ICE when using `Borrow` The original issue was caused by implementing `Borrow` on a local type and using the tokio-reactor crate which had this impl: https://github.com/tokio-rs/tokio/blob/tokio-0.1.4/tokio-reactor/src/poll_evented.rs#L547-L577 This causes an ICE on Rust 1.27.0: ```console $ RUSTUP_TOOLCHAIN=1.27.0 rustc src/test/ui/issues/issue-50687-ice-on-borrow.rs error: internal compiler error: librustc/traits/structural_impls.rs:180: impossible case reached thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:554:9 note: Run with `RUST_BACKTRACE=1` for a backtrace. error: aborting due to previous error note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports note: rustc 1.27.0 (3eda71b 2018-06-19) running on x86_64-apple-darwin ``` Closes #50687
2 parents 8f95dc8 + 4e4b1ed commit 2b3b115

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This previously caused an ICE at:
2+
// librustc/traits/structural_impls.rs:180: impossible case reached
3+
4+
#![no_main]
5+
6+
use std::borrow::Borrow;
7+
use std::io;
8+
use std::io::Write;
9+
10+
trait Constraint {}
11+
12+
struct Container<T> {
13+
t: T,
14+
}
15+
16+
struct Borrowed;
17+
struct Owned;
18+
19+
impl<'a, T> Write for &'a Container<T>
20+
where
21+
T: Constraint,
22+
&'a T: Write,
23+
{
24+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
25+
Ok(buf.len())
26+
}
27+
28+
fn flush(&mut self) -> io::Result<()> {
29+
Ok(())
30+
}
31+
}
32+
33+
impl Borrow<Borrowed> for Owned {
34+
fn borrow(&self) -> &Borrowed {
35+
&Borrowed
36+
}
37+
}
38+
39+
fn func(owned: Owned) {
40+
let _: () = Borrow::borrow(&owned); //~ ERROR mismatched types
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-50687-ice-on-borrow.rs:40:17
3+
|
4+
LL | let _: () = Borrow::borrow(&owned);
5+
| -- ^^^^^^^^^^^^^^^^^^^^^^
6+
| | |
7+
| | expected `()`, found reference
8+
| | help: consider dereferencing the borrow: `*Borrow::borrow(&owned)`
9+
| expected due to this
10+
|
11+
= note: expected unit type `()`
12+
found reference `&_`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)