Remove HirId -> LocalDefId
map from HIR.
This commit is contained in:
parent
92c4f1e2d9
commit
3e32533cc2
@ -778,20 +778,20 @@ fn walk_parents<'tcx>(
|
|||||||
|
|
||||||
Node::Expr(parent) if parent.span.ctxt() == ctxt => match parent.kind {
|
Node::Expr(parent) if parent.span.ctxt() == ctxt => match parent.kind {
|
||||||
ExprKind::Ret(_) => {
|
ExprKind::Ret(_) => {
|
||||||
let owner_id = cx.tcx.hir().body_owner(cx.enclosing_body.unwrap());
|
let owner_id = cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap());
|
||||||
Some(
|
Some(
|
||||||
if let Node::Expr(
|
if let Node::Expr(
|
||||||
closure_expr @ Expr {
|
closure_expr @ Expr {
|
||||||
kind: ExprKind::Closure(closure),
|
kind: ExprKind::Closure(closure),
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
) = cx.tcx.hir().get(owner_id)
|
) = cx.tcx.hir().get_by_def_id(owner_id)
|
||||||
{
|
{
|
||||||
closure_result_position(cx, closure, cx.typeck_results().expr_ty(closure_expr), precedence)
|
closure_result_position(cx, closure, cx.typeck_results().expr_ty(closure_expr), precedence)
|
||||||
} else {
|
} else {
|
||||||
let output = cx
|
let output = cx
|
||||||
.tcx
|
.tcx
|
||||||
.erase_late_bound_regions(cx.tcx.fn_sig(cx.tcx.hir().local_def_id(owner_id)).subst_identity().output());
|
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id).subst_identity().output());
|
||||||
ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)
|
ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -157,7 +157,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
|||||||
&& def.variants.len() > 1
|
&& def.variants.len() > 1
|
||||||
{
|
{
|
||||||
let mut iter = def.variants.iter().filter_map(|v| {
|
let mut iter = def.variants.iter().filter_map(|v| {
|
||||||
(matches!(v.data, hir::VariantData::Unit(..))
|
(matches!(v.data, hir::VariantData::Unit(_, _))
|
||||||
&& v.ident.as_str().starts_with('_')
|
&& v.ident.as_str().starts_with('_')
|
||||||
&& is_doc_hidden(cx.tcx.hir().attrs(v.hir_id)))
|
&& is_doc_hidden(cx.tcx.hir().attrs(v.hir_id)))
|
||||||
.then_some((v.def_id, v.span))
|
.then_some((v.def_id, v.span))
|
||||||
|
@ -11,8 +11,7 @@
|
|||||||
pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>) {
|
pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, count_recv: &hir::Expr<'_>, map_arg: &hir::Expr<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if is_trait_method(cx, count_recv, sym::Iterator);
|
if is_trait_method(cx, count_recv, sym::Iterator);
|
||||||
let closure = expr_or_init(cx, map_arg);
|
if let hir::ExprKind::Closure(closure) = expr_or_init(cx, map_arg).kind;
|
||||||
if let hir::ExprKind::Closure(closure) = closure.kind;
|
|
||||||
let closure_body = cx.tcx.hir().body(closure.body);
|
let closure_body = cx.tcx.hir().body(closure.body);
|
||||||
if !cx.typeck_results().expr_ty(closure_body.value).is_unit();
|
if !cx.typeck_results().expr_ty(closure_body.value).is_unit();
|
||||||
then {
|
then {
|
||||||
|
@ -1119,9 +1119,8 @@ fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
|
|||||||
self.captures.entry(l).and_modify(|e| *e |= cap).or_insert(cap);
|
self.captures.entry(l).and_modify(|e| *e |= cap).or_insert(cap);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ExprKind::Closure { .. } => {
|
ExprKind::Closure(closure) => {
|
||||||
let closure_id = self.cx.tcx.hir().local_def_id(e.hir_id);
|
for capture in self.cx.typeck_results().closure_min_captures_flattened(closure.def_id) {
|
||||||
for capture in self.cx.typeck_results().closure_min_captures_flattened(closure_id) {
|
|
||||||
let local_id = match capture.place.base {
|
let local_id = match capture.place.base {
|
||||||
PlaceBase::Local(id) => id,
|
PlaceBase::Local(id) => id,
|
||||||
PlaceBase::Upvar(var) => var.var_path.hir_id,
|
PlaceBase::Upvar(var) => var.var_path.hir_id,
|
||||||
@ -1584,8 +1583,7 @@ pub fn return_ty<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId) -> Ty<'t
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience function to get the nth argument type of a function.
|
/// Convenience function to get the nth argument type of a function.
|
||||||
pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_item: hir::HirId, nth: usize) -> Ty<'tcx> {
|
pub fn nth_arg<'tcx>(cx: &LateContext<'tcx>, fn_def_id: hir::OwnerId, nth: usize) -> Ty<'tcx> {
|
||||||
let fn_def_id = cx.tcx.hir().local_def_id(fn_item);
|
|
||||||
let arg = cx.tcx.fn_sig(fn_def_id).subst_identity().input(nth);
|
let arg = cx.tcx.fn_sig(fn_def_id).subst_identity().input(nth);
|
||||||
cx.tcx.erase_late_bound_regions(arg)
|
cx.tcx.erase_late_bound_regions(arg)
|
||||||
}
|
}
|
||||||
|
@ -809,7 +809,7 @@ pub struct DerefClosure {
|
|||||||
///
|
///
|
||||||
/// note: this only works on single line immutable closures with exactly one input parameter.
|
/// note: this only works on single line immutable closures with exactly one input parameter.
|
||||||
pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Option<DerefClosure> {
|
pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Option<DerefClosure> {
|
||||||
if let hir::ExprKind::Closure(&Closure { fn_decl, body, .. }) = closure.kind {
|
if let hir::ExprKind::Closure(&Closure { fn_decl, def_id, body, .. }) = closure.kind {
|
||||||
let closure_body = cx.tcx.hir().body(body);
|
let closure_body = cx.tcx.hir().body(body);
|
||||||
// is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
|
// is closure arg a type annotated double reference (i.e.: `|x: &&i32| ...`)
|
||||||
// a type annotation is present if param `kind` is different from `TyKind::Infer`
|
// a type annotation is present if param `kind` is different from `TyKind::Infer`
|
||||||
@ -829,10 +829,8 @@ pub fn deref_closure_args(cx: &LateContext<'_>, closure: &hir::Expr<'_>) -> Opti
|
|||||||
applicability: Applicability::MachineApplicable,
|
applicability: Applicability::MachineApplicable,
|
||||||
};
|
};
|
||||||
|
|
||||||
let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id);
|
|
||||||
let infcx = cx.tcx.infer_ctxt().build();
|
let infcx = cx.tcx.infer_ctxt().build();
|
||||||
ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
|
ExprUseVisitor::new(&mut visitor, &infcx, def_id, cx.param_env, cx.typeck_results()).consume_body(closure_body);
|
||||||
.consume_body(closure_body);
|
|
||||||
|
|
||||||
if !visitor.suggestion_start.is_empty() {
|
if !visitor.suggestion_start.is_empty() {
|
||||||
return Some(DerefClosure {
|
return Some(DerefClosure {
|
||||||
|
Loading…
Reference in New Issue
Block a user