Closed eholk closed 1 year ago
@rustbot label +C-bug +T-compiler +I-ICE +F-dyn_star +requires-nightly
A smaller sample that ICE's with the same message:
#![feature(dyn_star)]
#![allow(incomplete_features)]
use std::fmt::Display;
fn bug() -> impl Display {
// This reference seems to be evil.
// `1 as dyn* Display` compiles fine!
&1 as dyn* Display
}
fn main() {
let _ = bug();
}
The sample provided by DutchGhost compiles now, and the one that @eholk provided compiles with some slight modification (adding some '_
lifetimes so borrowck is happy):
#![feature(dyn_star)]
#![allow(incomplete_features)]
trait AddOne {
fn add1(&mut self) -> usize;
}
impl AddOne for usize {
fn add1(&mut self) -> usize {
*self += 1;
*self
}
}
impl AddOne for &mut usize {
fn add1(&mut self) -> usize {
(*self).add1()
}
}
fn add_one(mut i: dyn* AddOne + '_) -> usize {
i.add1()
}
fn main() {
let mut x = 42usize;
let y = &mut x as (dyn* AddOne + '_);
println!("{}", add_one(y));
}
Test case (playground:
This gives the following error message: