From 07aa5925041b415b2727cfbb0d23cc3997bd7ad7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 10 Nov 2022 23:54:34 +0000 Subject: [PATCH] Regression test for coercion of mut-ref to dyn-star --- src/test/ui/dyn-star/issue-102430.rs | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/test/ui/dyn-star/issue-102430.rs diff --git a/src/test/ui/dyn-star/issue-102430.rs b/src/test/ui/dyn-star/issue-102430.rs new file mode 100644 index 0000000000000..244ecda6626ae --- /dev/null +++ b/src/test/ui/dyn-star/issue-102430.rs @@ -0,0 +1,32 @@ +// check-pass + +#![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)); +}