Remove some more usages of guess_head_span

This commit is contained in:
Michael Goulet 2022-07-08 02:10:15 +00:00
parent 57f7618f62
commit 27b6ab9129
6 changed files with 20 additions and 22 deletions

View file

@ -18,20 +18,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
trait_item_def_id: DefId, trait_item_def_id: DefId,
requirement: &dyn fmt::Display, requirement: &dyn fmt::Display,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let msg = "impl has stricter requirements than trait"; let mut err = struct_span_err!(
let sp = self.tcx.sess.source_map().guess_head_span(error_span); self.tcx.sess,
error_span,
E0276,
"impl has stricter requirements than trait"
);
let mut err = struct_span_err!(self.tcx.sess, sp, E0276, "{}", msg); if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
if trait_item_def_id.is_local() {
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id()); let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
err.span_label( err.span_label(
self.tcx.def_span(trait_item_def_id), span,
format!("definition of `{}` from trait", item_name), format!("definition of `{}` from trait", item_name),
); );
} }
err.span_label(sp, format!("impl has extra requirement {}", requirement)); err.span_label(error_span, format!("impl has extra requirement {}", requirement));
err err
} }
@ -48,7 +50,6 @@ pub fn report_object_safety_error<'tcx>(
hir::Node::Item(item) => Some(item.ident.span), hir::Node::Item(item) => Some(item.ident.span),
_ => None, _ => None,
}); });
let span = tcx.sess.source_map().guess_head_span(span);
let mut err = struct_span_err!( let mut err = struct_span_err!(
tcx.sess, tcx.sess,
span, span,

View file

@ -694,9 +694,8 @@ pub trait LintContext: Sized {
} }
if let Some(span) = in_test_module { if let Some(span) = in_test_module {
let def_span = self.sess().source_map().guess_head_span(span);
db.span_help( db.span_help(
span.shrink_to_lo().to(def_span), self.sess().source_map().guess_head_span(span),
"consider adding a `#[cfg(test)]` to the containing module", "consider adding a `#[cfg(test)]` to the containing module",
); );
} }

View file

@ -139,13 +139,8 @@ impl<'tcx> ObligationCause<'tcx> {
ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: Default::default() } ObligationCause { span, body_id: hir::CRATE_HIR_ID, code: Default::default() }
} }
pub fn span(&self, tcx: TyCtxt<'tcx>) -> Span { pub fn span(&self, _tcx: TyCtxt<'tcx>) -> Span {
match *self.code() { match *self.code() {
ObligationCauseCode::CompareImplMethodObligation { .. }
| ObligationCauseCode::MainFunctionType
| ObligationCauseCode::StartFunctionType => {
tcx.sess.source_map().guess_head_span(self.span)
}
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause { ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
arm_span, arm_span,
.. ..

View file

@ -1759,8 +1759,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|| self.tcx.resolutions(()).has_pub_restricted || self.tcx.resolutions(()).has_pub_restricted
{ {
let descr = descr.to_string(); let descr = descr.to_string();
let vis_span = let vis_span = self.tcx.def_span(def_id);
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
if kind == "trait" { if kind == "trait" {
self.tcx.sess.emit_err(InPublicInterfaceTraits { self.tcx.sess.emit_err(InPublicInterfaceTraits {
span, span,

View file

@ -953,7 +953,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
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 an fn def .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,
@ -1089,7 +1089,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }), kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, .. }),
.. ..
}) => ( }) => (
sm.guess_head_span(fn_decl_span), fn_decl_span,
hir.body(body) hir.body(body)
.params .params
.iter() .iter()

View file

@ -31,8 +31,12 @@ LL | trait Trait: Sized {}
error[E0038]: the trait `Trait` cannot be made into an object error[E0038]: the trait `Trait` cannot be made into an object
--> $DIR/wf-unsafe-trait-obj-match.rs:25:25 --> $DIR/wf-unsafe-trait-obj-match.rs:25:25
| |
LL | let t: &dyn Trait = match opt() { LL | let t: &dyn Trait = match opt() {
| ^^^^^^^^^^^ `Trait` cannot be made into an object | _________________________^
LL | | Some(()) => &S,
LL | | None => &R,
LL | | };
| |_____^ `Trait` cannot be made into an object
| |
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> 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>
--> $DIR/wf-unsafe-trait-obj-match.rs:6:14 --> $DIR/wf-unsafe-trait-obj-match.rs:6:14