Erase late bound regions to avoid ICE
This commit is contained in:
parent
6e2801c44e
commit
9adb462e6c
@ -11,7 +11,7 @@
|
||||
use rustc_hir::{ExprKind, ItemKind, Node};
|
||||
use rustc_infer::infer;
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_middle::ty::{self, Binder, Ty};
|
||||
use rustc_span::symbol::kw;
|
||||
|
||||
use std::iter;
|
||||
@ -487,6 +487,7 @@ pub(in super::super) fn suggest_missing_return_expr(
|
||||
let found = self.resolve_vars_with_obligations(found);
|
||||
if let hir::FnRetTy::Return(ty) = fn_decl.output {
|
||||
let ty = AstConv::ast_ty_to_ty(self, ty);
|
||||
let ty = self.tcx.erase_late_bound_regions(Binder::bind(ty));
|
||||
let ty = self.normalize_associated_types_in(expr.span, ty);
|
||||
if self.can_coerce(found, ty) {
|
||||
err.multipart_suggestion(
|
||||
|
24
src/test/ui/return/issue-82612-return-mutable-reference.rs
Normal file
24
src/test/ui/return/issue-82612-return-mutable-reference.rs
Normal file
@ -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() {}
|
@ -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`.
|
Loading…
Reference in New Issue
Block a user