Remove some more usages of guess_head_span
This commit is contained in:
parent
57f7618f62
commit
27b6ab9129
6 changed files with 20 additions and 22 deletions
|
@ -18,20 +18,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
trait_item_def_id: DefId,
|
||||
requirement: &dyn fmt::Display,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
let msg = "impl has stricter requirements than trait";
|
||||
let sp = self.tcx.sess.source_map().guess_head_span(error_span);
|
||||
let mut err = struct_span_err!(
|
||||
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 trait_item_def_id.is_local() {
|
||||
if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
|
||||
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
|
||||
err.span_label(
|
||||
self.tcx.def_span(trait_item_def_id),
|
||||
span,
|
||||
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
|
||||
}
|
||||
|
@ -48,7 +50,6 @@ pub fn report_object_safety_error<'tcx>(
|
|||
hir::Node::Item(item) => Some(item.ident.span),
|
||||
_ => None,
|
||||
});
|
||||
let span = tcx.sess.source_map().guess_head_span(span);
|
||||
let mut err = struct_span_err!(
|
||||
tcx.sess,
|
||||
span,
|
||||
|
|
|
@ -694,9 +694,8 @@ pub trait LintContext: Sized {
|
|||
}
|
||||
|
||||
if let Some(span) = in_test_module {
|
||||
let def_span = self.sess().source_map().guess_head_span(span);
|
||||
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",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -139,13 +139,8 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
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() {
|
||||
ObligationCauseCode::CompareImplMethodObligation { .. }
|
||||
| ObligationCauseCode::MainFunctionType
|
||||
| ObligationCauseCode::StartFunctionType => {
|
||||
tcx.sess.source_map().guess_head_span(self.span)
|
||||
}
|
||||
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
|
||||
arm_span,
|
||||
..
|
||||
|
|
|
@ -1759,8 +1759,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
|||
|| self.tcx.resolutions(()).has_pub_restricted
|
||||
{
|
||||
let descr = descr.to_string();
|
||||
let vis_span =
|
||||
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id));
|
||||
let vis_span = self.tcx.def_span(def_id);
|
||||
if kind == "trait" {
|
||||
self.tcx.sess.emit_err(InPublicInterfaceTraits {
|
||||
span,
|
||||
|
|
|
@ -953,7 +953,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
|
||||
let found_span = found_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)) {
|
||||
// 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, .. }),
|
||||
..
|
||||
}) => (
|
||||
sm.guess_head_span(fn_decl_span),
|
||||
fn_decl_span,
|
||||
hir.body(body)
|
||||
.params
|
||||
.iter()
|
||||
|
|
|
@ -31,8 +31,12 @@ LL | trait Trait: Sized {}
|
|||
error[E0038]: the trait `Trait` cannot be made into an object
|
||||
--> $DIR/wf-unsafe-trait-obj-match.rs:25:25
|
||||
|
|
||||
LL | let t: &dyn Trait = match opt() {
|
||||
| ^^^^^^^^^^^ `Trait` cannot be made into an object
|
||||
LL | let t: &dyn Trait = match opt() {
|
||||
| _________________________^
|
||||
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>
|
||||
--> $DIR/wf-unsafe-trait-obj-match.rs:6:14
|
||||
|
|
Loading…
Reference in a new issue