Skip to content

Commit 4e4b1ed

Browse files
committed
Add test for old compiler ICE when using Borrow
1 parent 7b657d3 commit 4e4b1ed

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)