-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Erase late bound regions to avoid ICE
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
src/test/ui/return/issue-82612-return-mutable-reference.rs
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,24 @@ | ||
// Regression test for #82612. | ||
|
||
use std::marker::PhantomData; | ||
|
||
pub trait SparseSetIndex { | ||
fn sparse_set_index(&self) -> usize; | ||
} | ||
pub struct SparseArray<I, V = I> { | ||
values: Vec<Option<V>>, | ||
marker: PhantomData<I>, | ||
} | ||
|
||
impl<I: SparseSetIndex, V> SparseArray<I, V> { | ||
pub fn get_or_insert_with(&mut self, index: I, func: impl FnOnce() -> V) -> &mut V { | ||
let index = index.sparse_set_index(); | ||
if index < self.values.len() { | ||
let value = unsafe { self.values.get_unchecked_mut(index) }; | ||
value.get_or_insert_with(func) //~ ERROR mismatched types | ||
} | ||
unsafe { self.values.get_unchecked_mut(index).as_mut().unwrap() } | ||
} | ||
} | ||
|
||
fn main() {} |
28 changes: 28 additions & 0 deletions
28
src/test/ui/return/issue-82612-return-mutable-reference.stderr
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 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-82612-return-mutable-reference.rs:18:13 | ||
| | ||
LL | / if index < self.values.len() { | ||
LL | | let value = unsafe { self.values.get_unchecked_mut(index) }; | ||
LL | | value.get_or_insert_with(func) | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `&mut V` | ||
LL | | } | ||
| |_________- expected this to be `()` | ||
| | ||
= note: expected unit type `()` | ||
found mutable reference `&mut V` | ||
help: consider using a semicolon here | ||
| | ||
LL | value.get_or_insert_with(func); | ||
| ^ | ||
help: consider using a semicolon here | ||
| | ||
LL | }; | ||
| ^ | ||
help: you might have meant to return this value | ||
| | ||
LL | return value.get_or_insert_with(func); | ||
| ^^^^^^ ^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |