1
Fork 0

Remove some more usages of guess_head_span

This commit is contained in:
Michael Goulet 2022-07-15 05:23:47 +00:00
parent 4b890f3474
commit fcfb3e92a0
3 changed files with 19 additions and 32 deletions

View file

@ -823,10 +823,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => { ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
let found_kind = self.closure_kind(closure_substs).unwrap(); let found_kind = self.closure_kind(closure_substs).unwrap();
let closure_span = let closure_span = self.tcx.def_span(closure_def_id);
self.tcx.sess.source_map().guess_head_span(
self.tcx.hir().span_if_local(closure_def_id).unwrap(),
);
let mut err = struct_span_err!( let mut err = struct_span_err!(
self.tcx.sess, self.tcx.sess,
closure_span, closure_span,
@ -951,9 +948,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
_ => None, _ => None,
}; };
let found_span = found_did let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did));
.and_then(|did| self.tcx.hir().span_if_local(did))
.map(|sp| self.tcx.sess.source_map().guess_head_span(sp)); // the sp could be a closure
if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) { if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
// We check closures twice, with obligations flowing in different directions, // We check closures twice, with obligations flowing in different directions,

View file

@ -1543,7 +1543,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ty::Generator(..) => "generator", ty::Generator(..) => "generator",
_ => "function", _ => "function",
}; };
let span = self.tcx.sess.source_map().guess_head_span(span);
let mut err = struct_span_err!( let mut err = struct_span_err!(
self.tcx.sess, self.tcx.sess,
span, span,

View file

@ -171,14 +171,7 @@ fn compare_predicate_entailment<'tcx>(
let trait_m_predicates = tcx.predicates_of(trait_m.def_id); let trait_m_predicates = tcx.predicates_of(trait_m.def_id);
// Check region bounds. // Check region bounds.
check_region_bounds_on_impl_item( check_region_bounds_on_impl_item(tcx, impl_m, trait_m, &trait_m_generics, &impl_m_generics)?;
tcx,
impl_m_span,
impl_m,
trait_m,
&trait_m_generics,
&impl_m_generics,
)?;
// Create obligations for each predicate declared by the impl // Create obligations for each predicate declared by the impl
// definition in the context of the trait's parameter // definition in the context of the trait's parameter
@ -410,7 +403,6 @@ fn compare_predicate_entailment<'tcx>(
fn check_region_bounds_on_impl_item<'tcx>( fn check_region_bounds_on_impl_item<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
span: Span,
impl_m: &ty::AssocItem, impl_m: &ty::AssocItem,
trait_m: &ty::AssocItem, trait_m: &ty::AssocItem,
trait_generics: &ty::Generics, trait_generics: &ty::Generics,
@ -436,23 +428,25 @@ fn check_region_bounds_on_impl_item<'tcx>(
// are zero. Since I don't quite know how to phrase things at // are zero. Since I don't quite know how to phrase things at
// the moment, give a kind of vague error message. // the moment, give a kind of vague error message.
if trait_params != impl_params { if trait_params != impl_params {
let item_kind = assoc_item_kind_str(impl_m); let span = tcx
let span = impl_m .hir()
.def_id .get_generics(impl_m.def_id.expect_local())
.as_local() .expect("expected impl item to have generics or else we can't compare them")
.and_then(|did| tcx.hir().get_generics(did)) .span;
.map_or(span, |g| g.span); let generics_span = if let Some(local_def_id) = trait_m.def_id.as_local() {
let generics_span = tcx.hir().span_if_local(trait_m.def_id).map(|sp| { Some(
trait_m tcx.hir()
.def_id .get_generics(local_def_id)
.as_local() .expect("expected trait item to have generics or else we can't compare them")
.and_then(|did| tcx.hir().get_generics(did)) .span,
.map_or(sp, |g| g.span) )
}); } else {
None
};
let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait { let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {
span, span,
item_kind, item_kind: assoc_item_kind_str(impl_m),
ident: impl_m.ident(tcx), ident: impl_m.ident(tcx),
generics_span, generics_span,
}); });
@ -1201,7 +1195,6 @@ fn compare_type_predicate_entailment<'tcx>(
check_region_bounds_on_impl_item( check_region_bounds_on_impl_item(
tcx, tcx,
impl_ty_span,
impl_ty, impl_ty,
trait_ty, trait_ty,
&trait_ty_generics, &trait_ty_generics,