Skip to content

Commit fcfb3e9

Browse files
Remove some more usages of guess_head_span
1 parent 4b890f3 commit fcfb3e9

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
823823

824824
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
825825
let found_kind = self.closure_kind(closure_substs).unwrap();
826-
let closure_span =
827-
self.tcx.sess.source_map().guess_head_span(
828-
self.tcx.hir().span_if_local(closure_def_id).unwrap(),
829-
);
826+
let closure_span = self.tcx.def_span(closure_def_id);
830827
let mut err = struct_span_err!(
831828
self.tcx.sess,
832829
closure_span,
@@ -951,9 +948,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
951948
_ => None,
952949
};
953950

954-
let found_span = found_did
955-
.and_then(|did| self.tcx.hir().span_if_local(did))
956-
.map(|sp| self.tcx.sess.source_map().guess_head_span(sp)); // the sp could be a closure
951+
let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did));
957952

958953
if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
959954
// We check closures twice, with obligations flowing in different directions,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
15431543
ty::Generator(..) => "generator",
15441544
_ => "function",
15451545
};
1546-
let span = self.tcx.sess.source_map().guess_head_span(span);
15471546
let mut err = struct_span_err!(
15481547
self.tcx.sess,
15491548
span,

compiler/rustc_typeck/src/check/compare_method.rs

+17-24
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,7 @@ fn compare_predicate_entailment<'tcx>(
171171
let trait_m_predicates = tcx.predicates_of(trait_m.def_id);
172172

173173
// Check region bounds.
174-
check_region_bounds_on_impl_item(
175-
tcx,
176-
impl_m_span,
177-
impl_m,
178-
trait_m,
179-
&trait_m_generics,
180-
&impl_m_generics,
181-
)?;
174+
check_region_bounds_on_impl_item(tcx, impl_m, trait_m, &trait_m_generics, &impl_m_generics)?;
182175

183176
// Create obligations for each predicate declared by the impl
184177
// definition in the context of the trait's parameter
@@ -410,7 +403,6 @@ fn compare_predicate_entailment<'tcx>(
410403

411404
fn check_region_bounds_on_impl_item<'tcx>(
412405
tcx: TyCtxt<'tcx>,
413-
span: Span,
414406
impl_m: &ty::AssocItem,
415407
trait_m: &ty::AssocItem,
416408
trait_generics: &ty::Generics,
@@ -436,23 +428,25 @@ fn check_region_bounds_on_impl_item<'tcx>(
436428
// are zero. Since I don't quite know how to phrase things at
437429
// the moment, give a kind of vague error message.
438430
if trait_params != impl_params {
439-
let item_kind = assoc_item_kind_str(impl_m);
440-
let span = impl_m
441-
.def_id
442-
.as_local()
443-
.and_then(|did| tcx.hir().get_generics(did))
444-
.map_or(span, |g| g.span);
445-
let generics_span = tcx.hir().span_if_local(trait_m.def_id).map(|sp| {
446-
trait_m
447-
.def_id
448-
.as_local()
449-
.and_then(|did| tcx.hir().get_generics(did))
450-
.map_or(sp, |g| g.span)
451-
});
431+
let span = tcx
432+
.hir()
433+
.get_generics(impl_m.def_id.expect_local())
434+
.expect("expected impl item to have generics or else we can't compare them")
435+
.span;
436+
let generics_span = if let Some(local_def_id) = trait_m.def_id.as_local() {
437+
Some(
438+
tcx.hir()
439+
.get_generics(local_def_id)
440+
.expect("expected trait item to have generics or else we can't compare them")
441+
.span,
442+
)
443+
} else {
444+
None
445+
};
452446

453447
let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {
454448
span,
455-
item_kind,
449+
item_kind: assoc_item_kind_str(impl_m),
456450
ident: impl_m.ident(tcx),
457451
generics_span,
458452
});
@@ -1201,7 +1195,6 @@ fn compare_type_predicate_entailment<'tcx>(
12011195

12021196
check_region_bounds_on_impl_item(
12031197
tcx,
1204-
impl_ty_span,
12051198
impl_ty,
12061199
trait_ty,
12071200
&trait_ty_generics,

0 commit comments

Comments
 (0)