Reduce use of local_def_id_to_hir_id.
This commit is contained in:
parent
ebcc847369
commit
67727aa7c3
39 changed files with 182 additions and 237 deletions
|
@ -217,10 +217,6 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
|
|||
ty::ClosureKind::FnOnce => {}
|
||||
}
|
||||
|
||||
// We won't be building MIR if the closure wasn't local
|
||||
let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
|
||||
let closure_span = tcx.hir().span(closure_hir_id);
|
||||
|
||||
let Some((capture_index, capture)) =
|
||||
find_capture_matching_projections(
|
||||
typeck_results,
|
||||
|
@ -228,6 +224,7 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
|
|||
closure_def_id,
|
||||
&from_builder.projection,
|
||||
) else {
|
||||
let closure_span = tcx.def_span(closure_def_id);
|
||||
if !enable_precise_capture(tcx, closure_span) {
|
||||
bug!(
|
||||
"No associated capture found for {:?}[{:#?}] even though \
|
||||
|
@ -244,6 +241,8 @@ fn to_upvars_resolved_place_builder<'a, 'tcx>(
|
|||
return Err(from_builder);
|
||||
};
|
||||
|
||||
// We won't be building MIR if the closure wasn't local
|
||||
let closure_hir_id = tcx.hir().local_def_id_to_hir_id(closure_def_id.expect_local());
|
||||
let closure_ty = typeck_results.node_type(closure_hir_id);
|
||||
|
||||
let substs = match closure_ty.kind() {
|
||||
|
|
|
@ -11,9 +11,8 @@ use std::ops::ControlFlow;
|
|||
|
||||
crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
|
||||
let def_id = body.source.def_id().expect_local();
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
|
||||
if let Some(fn_kind) = tcx.hir().get(hir_id).fn_kind() {
|
||||
if let Some(fn_kind) = tcx.hir().get_by_def_id(def_id).fn_kind() {
|
||||
if let FnKind::Closure = fn_kind {
|
||||
// closures can't recur, so they don't matter.
|
||||
return;
|
||||
|
|
|
@ -120,34 +120,32 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
|||
}
|
||||
|
||||
fn search_for_structural_match_violation(&self, ty: Ty<'tcx>) -> Option<String> {
|
||||
traits::search_for_structural_match_violation(self.id, self.span, self.tcx(), ty).map(
|
||||
|non_sm_ty| {
|
||||
with_no_trimmed_paths(|| match non_sm_ty {
|
||||
traits::NonStructuralMatchTy::Adt(adt) => self.adt_derive_msg(adt),
|
||||
traits::NonStructuralMatchTy::Dynamic => {
|
||||
"trait objects cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Opaque => {
|
||||
"opaque types cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Closure => {
|
||||
"closures cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Generator => {
|
||||
"generators cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Param => {
|
||||
bug!("use of a constant whose type is a parameter inside a pattern")
|
||||
}
|
||||
traits::NonStructuralMatchTy::Projection => {
|
||||
bug!("use of a constant whose type is a projection inside a pattern")
|
||||
}
|
||||
traits::NonStructuralMatchTy::Foreign => {
|
||||
bug!("use of a value of a foreign type inside a pattern")
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
traits::search_for_structural_match_violation(self.span, self.tcx(), ty).map(|non_sm_ty| {
|
||||
with_no_trimmed_paths(|| match non_sm_ty {
|
||||
traits::NonStructuralMatchTy::Adt(adt) => self.adt_derive_msg(adt),
|
||||
traits::NonStructuralMatchTy::Dynamic => {
|
||||
"trait objects cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Opaque => {
|
||||
"opaque types cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Closure => {
|
||||
"closures cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Generator => {
|
||||
"generators cannot be used in patterns".to_string()
|
||||
}
|
||||
traits::NonStructuralMatchTy::Param => {
|
||||
bug!("use of a constant whose type is a parameter inside a pattern")
|
||||
}
|
||||
traits::NonStructuralMatchTy::Projection => {
|
||||
bug!("use of a constant whose type is a projection inside a pattern")
|
||||
}
|
||||
traits::NonStructuralMatchTy::Foreign => {
|
||||
bug!("use of a value of a foreign type inside a pattern")
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn type_marked_structural(&self, ty: Ty<'tcx>) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue