review comments
This commit is contained in:
parent
da1360d981
commit
e6c56cda09
@ -606,12 +606,12 @@ pub(crate) fn report_mutability_error(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some((false, err_label_span, message)) => {
|
Some((false, err_label_span, message)) => {
|
||||||
struct V {
|
struct BindingFinder {
|
||||||
span: Span,
|
span: Span,
|
||||||
hir_id: Option<hir::HirId>,
|
hir_id: Option<hir::HirId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for V {
|
impl<'tcx> Visitor<'tcx> for BindingFinder {
|
||||||
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
|
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
|
||||||
if let hir::StmtKind::Local(local) = s.kind {
|
if let hir::StmtKind::Local(local) = s.kind {
|
||||||
if local.pat.span == self.span {
|
if local.pat.span == self.span {
|
||||||
@ -622,20 +622,23 @@ fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
let hir_map = self.infcx.tcx.hir();
|
let hir_map = self.infcx.tcx.hir();
|
||||||
let pat = loop {
|
let def_id = self.body.source.def_id();
|
||||||
// Poor man's try block
|
let hir_id = hir_map.local_def_id_to_hir_id(def_id.expect_local());
|
||||||
let def_id = self.body.source.def_id();
|
let node = hir_map.find(hir_id);
|
||||||
let hir_id =
|
let hir_id = if let Some(hir::Node::Item(item)) = node
|
||||||
hir_map.local_def_id_to_hir_id(def_id.as_local().unwrap());
|
&& let hir::ItemKind::Fn(.., body_id) = item.kind
|
||||||
let node = hir_map.find(hir_id);
|
{
|
||||||
let Some(hir::Node::Item(item)) = node else { break None; };
|
let body = hir_map.body(body_id);
|
||||||
let hir::ItemKind::Fn(.., body_id) = item.kind else { break None; };
|
let mut v = BindingFinder {
|
||||||
let body = self.infcx.tcx.hir().body(body_id);
|
span: err_label_span,
|
||||||
let mut v = V { span: err_label_span, hir_id: None };
|
hir_id: None,
|
||||||
|
};
|
||||||
v.visit_body(body);
|
v.visit_body(body);
|
||||||
break v.hir_id;
|
v.hir_id
|
||||||
|
} else {
|
||||||
|
None
|
||||||
};
|
};
|
||||||
if let Some(hir_id) = pat
|
if let Some(hir_id) = hir_id
|
||||||
&& let Some(hir::Node::Local(local)) = hir_map.find(hir_id)
|
&& let Some(hir::Node::Local(local)) = hir_map.find(hir_id)
|
||||||
{
|
{
|
||||||
let (changing, span, sugg) = match local.ty {
|
let (changing, span, sugg) = match local.ty {
|
||||||
|
Loading…
Reference in New Issue
Block a user