Skip to content

Commit 27b6ab9

Browse files
Remove some more usages of guess_head_span
1 parent 57f7618 commit 27b6ab9

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1818
trait_item_def_id: DefId,
1919
requirement: &dyn fmt::Display,
2020
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
21-
let msg = "impl has stricter requirements than trait";
22-
let sp = self.tcx.sess.source_map().guess_head_span(error_span);
21+
let mut err = struct_span_err!(
22+
self.tcx.sess,
23+
error_span,
24+
E0276,
25+
"impl has stricter requirements than trait"
26+
);
2327

24-
let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg);
25-
26-
if trait_item_def_id.is_local() {
28+
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
2729
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
2830
err.span_label(
29-
self.tcx.def_span(trait_item_def_id),
31+
span,
3032
format!("definition of `{}` from trait", item_name),
3133
);
3234
}
3335

34-
err.span_label(sp, format!("impl has extra requirement {}", requirement));
36+
err.span_label(error_span, format!("impl has extra requirement {}", requirement));
3537

3638
err
3739
}
@@ -48,7 +50,6 @@ pub fn report_object_safety_error<'tcx>(
4850
hir::Node::Item(item) => Some(item.ident.span),
4951
_ => None,
5052
});
51-
let span = tcx.sess.source_map().guess_head_span(span);
5253
let mut err = struct_span_err!(
5354
tcx.sess,
5455
span,

compiler/rustc_lint/src/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,8 @@ pub trait LintContext: Sized {
694694
}
695695

696696
if let Some(span) = in_test_module {
697-
let def_span = self.sess().source_map().guess_head_span(span);
698697
db.span_help(
699-
span.shrink_to_lo().to(def_span),
698+
self.sess().source_map().guess_head_span(span),
700699
"consider adding a `#[cfg(test)]` to the containing module",
701700
);
702701
}

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,8 @@ impl<'tcx> ObligationCause<'tcx> {
139139
ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: Default::default() }
140140
}
141141

142-
pub fn span(&self, tcx: TyCtxt<'tcx>) -> Span {
142+
pub fn span(&self, _tcx: TyCtxt<'tcx>) -> Span {
143143
match *self.code() {
144-
ObligationCauseCode::CompareImplMethodObligation { .. }
145-
| ObligationCauseCode::MainFunctionType
146-
| ObligationCauseCode::StartFunctionType => {
147-
tcx.sess.source_map().guess_head_span(self.span)
148-
}
149144
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
150145
arm_span,
151146
..

compiler/rustc_privacy/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,8 +1759,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
17591759
|| self.tcx.resolutions(()).has_pub_restricted
17601760
{
17611761
let descr = descr.to_string();
1762-
let vis_span =
1763-
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
1762+
let vis_span = self.tcx.def_span(def_id);
17641763
if kind == "trait" {
17651764
self.tcx.sess.emit_err(InPublicInterfaceTraits {
17661765
span,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
953953

954954
let found_span = found_did
955955
.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 an fn def
956+
.map(|sp| self.tcx.sess.source_map().guess_head_span(sp)); // the sp could be a closure
957957

958958
if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
959959
// We check closures twice, with obligations flowing in different directions,
@@ -1089,7 +1089,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
10891089
kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }),
10901090
..
10911091
}) => (
1092-
sm.guess_head_span(fn_decl_span),
1092+
fn_decl_span,
10931093
hir.body(body)
10941094
.params
10951095
.iter()

src/test/ui/wf/wf-unsafe-trait-obj-match.stderr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ LL | trait Trait: Sized {}
3131
error[E0038]: the trait `Trait` cannot be made into an object
3232
--> $DIR/wf-unsafe-trait-obj-match.rs:25:25
3333
|
34-
LL | let t: &dyn Trait = match opt() {
35-
| ^^^^^^^^^^^ `Trait` cannot be made into an object
34+
LL | let t: &dyn Trait = match opt() {
35+
| _________________________^
36+
LL | | Some(()) => &S,
37+
LL | | None => &R,
38+
LL | | };
39+
| |_____^ `Trait` cannot be made into an object
3640
|
3741
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
3842
--> $DIR/wf-unsafe-trait-obj-match.rs:6:14

0 commit comments

Comments
 (0)