Rename def_span to guess_head_span

This commit is contained in:
Esteban Küber 2020-03-09 11:42:37 -07:00
parent 3c1d9adb3c
commit f18a6dcec0
28 changed files with 89 additions and 71 deletions

View File

@ -108,7 +108,9 @@ impl<'tcx> ObligationCause<'tcx> {
match self.code {
ObligationCauseCode::CompareImplMethodObligation { .. }
| ObligationCauseCode::MainFunctionType
| ObligationCauseCode::StartFunctionType => tcx.sess.source_map().def_span(self.span),
| ObligationCauseCode::StartFunctionType => {
tcx.sess.source_map().guess_head_span(self.span)
}
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
arm_span,
..

View File

@ -388,7 +388,7 @@ impl<'tcx> TyCtxt<'tcx> {
assert!(!stack.is_empty());
let fix_span = |span: Span, query: &Query<'tcx>| {
self.sess.source_map().def_span(query.default_span(self, span))
self.sess.source_map().guess_head_span(query.default_span(self, span))
};
// Disable naming impls with types in this path, since that
@ -456,7 +456,8 @@ impl<'tcx> TyCtxt<'tcx> {
query_info.info.query.describe(icx.tcx)
),
);
diag.span = icx.tcx.sess.source_map().def_span(query_info.info.span).into();
diag.span =
icx.tcx.sess.source_map().guess_head_span(query_info.info.span).into();
handler.force_print_diagnostic(diag);
current_query = query_info.job.parent;

View File

@ -402,7 +402,7 @@ impl<'a> AstValidator<'a> {
fn check_defaultness(&self, span: Span, defaultness: Defaultness) {
if let Defaultness::Default(def_span) = defaultness {
let span = self.session.source_map().def_span(span);
let span = self.session.source_map().guess_head_span(span);
self.err_handler()
.struct_span_err(span, "`default` is only allowed on items in `impl` definitions")
.span_label(def_span, "`default` because of this")
@ -517,7 +517,7 @@ impl<'a> AstValidator<'a> {
}
fn current_extern_span(&self) -> Span {
self.session.source_map().def_span(self.extern_mod.unwrap().span)
self.session.source_map().guess_head_span(self.extern_mod.unwrap().span)
}
/// An `fn` in `extern { ... }` cannot have qualfiers, e.g. `async fn`.

View File

@ -257,7 +257,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(
&self,
non_ascii_idents,
self.parse_sess.source_map().def_span(sp),
self.parse_sess.source_map().guess_head_span(sp),
"non-ascii idents are not fully supported"
);
}

View File

@ -198,7 +198,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro_derive]` must be `pub`"
};
self.handler.span_err(self.source_map.def_span(item.span), msg);
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
}
}
@ -217,7 +217,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro_attribute]` must be `pub`"
};
self.handler.span_err(self.source_map.def_span(item.span), msg);
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
}
}
@ -236,7 +236,7 @@ impl<'a> CollectProcMacros<'a> {
} else {
"functions tagged with `#[proc_macro]` must be `pub`"
};
self.handler.span_err(self.source_map.def_span(item.span), msg);
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
}
}
}
@ -247,7 +247,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
if self.is_proc_macro_crate && attr::contains_name(&item.attrs, sym::macro_export) {
let msg =
"cannot export macro_rules! macros from a `proc-macro` crate type currently";
self.handler.span_err(self.source_map.def_span(item.span), msg);
self.handler.span_err(self.source_map.guess_head_span(item.span), msg);
}
}
@ -298,7 +298,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
let attr = match found_attr {
None => {
self.check_not_pub_in_root(&item.vis, self.source_map.def_span(item.span));
self.check_not_pub_in_root(&item.vis, self.source_map.guess_head_span(item.span));
let prev_in_root = mem::replace(&mut self.in_root, false);
visit::walk_item(self, item);
self.in_root = prev_in_root;

View File

@ -326,7 +326,7 @@ fn generic_extension<'cx>(
let mut err = cx.struct_span_err(span, &parse_failure_msg(&token));
err.span_label(span, label);
if !def_span.is_dummy() && !cx.source_map().is_imported(def_span) {
err.span_label(cx.source_map().def_span(def_span), "when calling this macro");
err.span_label(cx.source_map().guess_head_span(def_span), "when calling this macro");
}
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`

View File

@ -200,7 +200,7 @@ fn msg_span_from_early_bound_and_free_regions(
};
let (prefix, span) = match *region {
ty::ReEarlyBound(ref br) => {
let mut sp = sm.def_span(tcx.hir().span(node));
let mut sp = sm.guess_head_span(tcx.hir().span(node));
if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
{
@ -209,7 +209,7 @@ fn msg_span_from_early_bound_and_free_regions(
(format!("the lifetime `{}` as defined on", br.name), sp)
}
ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => {
let mut sp = sm.def_span(tcx.hir().span(node));
let mut sp = sm.guess_head_span(tcx.hir().span(node));
if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
{
@ -223,7 +223,7 @@ fn msg_span_from_early_bound_and_free_regions(
}
_ => (
format!("the lifetime `{}` as defined on", region),
sm.def_span(tcx.hir().span(node)),
sm.guess_head_span(tcx.hir().span(node)),
),
},
_ => bug!(),

View File

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

View File

@ -76,7 +76,7 @@ impl EarlyLintPass for WhileTrue {
if let ast::LitKind::Bool(true) = lit.kind {
if !lit.span.from_expansion() {
let msg = "denote infinite loops with `loop { ... }`";
let condition_span = cx.sess.source_map().def_span(e.span);
let condition_span = cx.sess.source_map().guess_head_span(e.span);
cx.struct_span_lint(WHILE_TRUE, condition_span, |lint| {
lint.build(msg)
.span_suggestion_short(
@ -374,9 +374,13 @@ impl MissingDoc {
let has_doc = attrs.iter().any(|a| has_doc(a));
if !has_doc {
cx.struct_span_lint(MISSING_DOCS, cx.tcx.sess.source_map().def_span(sp), |lint| {
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
});
cx.struct_span_lint(
MISSING_DOCS,
cx.tcx.sess.source_map().guess_head_span(sp),
|lint| {
lint.build(&format!("missing documentation for {} {}", article, desc)).emit()
},
);
}
}
}
@ -406,7 +410,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
if !has_doc {
cx.struct_span_lint(
MISSING_DOCS,
cx.tcx.sess.source_map().def_span(macro_def.span),
cx.tcx.sess.source_map().guess_head_span(macro_def.span),
|lint| lint.build("missing documentation for macro").emit(),
);
}
@ -978,7 +982,7 @@ impl UnreachablePub {
if span.from_expansion() {
applicability = Applicability::MaybeIncorrect;
}
let def_span = cx.tcx.sess.source_map().def_span(span);
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
let mut err = lint.build(&format!("unreachable `pub` {}", what));
let replacement = if cx.tcx.features().crate_visibility_modifier {

View File

@ -565,14 +565,14 @@ fn is_enclosed(
}
fn report_unused_unsafe(tcx: TyCtxt<'_>, used_unsafe: &FxHashSet<hir::HirId>, id: hir::HirId) {
let span = tcx.sess.source_map().def_span(tcx.hir().span(id));
let span = tcx.sess.source_map().guess_head_span(tcx.hir().span(id));
tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, |lint| {
let msg = "unnecessary `unsafe` block";
let mut db = lint.build(msg);
db.span_label(span, msg);
if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) {
db.span_label(
tcx.sess.source_map().def_span(tcx.hir().span(id)),
tcx.sess.source_map().guess_head_span(tcx.hir().span(id)),
format!("because it's nested under this `unsafe` {}", kind),
);
}

View File

@ -123,7 +123,7 @@ fn check_fn_for_unconditional_recursion<'tcx>(
// recurs.
if !reached_exit_without_self_call && !self_call_locations.is_empty() {
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let sp = tcx.sess.source_map().def_span(tcx.hir().span(hir_id));
let sp = tcx.sess.source_map().guess_head_span(tcx.hir().span(hir_id));
tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, |lint| {
let mut db = lint.build("function cannot return without recursing");
db.span_label(sp, "cannot return without recursing");

View File

@ -907,7 +907,7 @@ impl<'a> Parser<'a> {
}
fn error_bad_item_kind<T>(&self, span: Span, kind: &ItemKind, ctx: &str) -> Option<T> {
let span = self.sess.source_map().def_span(span);
let span = self.sess.source_map().guess_head_span(span);
let msg = format!("{} is not supported in {}", kind.descr(), ctx);
self.struct_span_err(span, &msg).emit();
None

View File

@ -590,7 +590,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
// We should probably annotate ident.span with the macro
// context, but that's a larger change.
if item.span.source_callee().is_some() {
self.tcx.sess.source_map().def_span(item.span)
self.tcx.sess.source_map().guess_head_span(item.span)
} else {
item.ident.span
}
@ -663,7 +663,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
}
hir::ImplItemKind::Fn(_, body_id) => {
if !self.symbol_is_live(impl_item.hir_id) {
let span = self.tcx.sess.source_map().def_span(impl_item.span);
let span = self.tcx.sess.source_map().guess_head_span(impl_item.span);
self.warn_dead_code(
impl_item.hir_id,
span,

View File

@ -791,12 +791,12 @@ impl<'a> Resolver<'a> {
_ => Some(
self.session
.source_map()
.def_span(self.cstore().get_span_untracked(def_id, self.session)),
.guess_head_span(self.cstore().get_span_untracked(def_id, self.session)),
),
});
if let Some(span) = def_span {
err.span_label(
self.session.source_map().def_span(span),
self.session.source_map().guess_head_span(span),
&format!(
"similarly named {} `{}` defined here",
suggestion.res.descr(),
@ -986,7 +986,7 @@ impl<'a> Resolver<'a> {
which = if first { "" } else { " which" },
dots = if next_binding.is_some() { "..." } else { "" },
);
let def_span = self.session.source_map().def_span(binding.span);
let def_span = self.session.source_map().guess_head_span(binding.span);
let mut note_span = MultiSpan::from_span(def_span);
if !first && binding.vis == ty::Visibility::Public {
note_span.push_span_label(def_span, "consider importing it directly".into());

View File

@ -1441,7 +1441,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let enum_resolution = resolutions.get(&key).expect("resolution should exist");
let enum_span =
enum_resolution.borrow().binding.expect("binding should exist").span;
let enum_def_span = this.session.source_map().def_span(enum_span);
let enum_def_span = this.session.source_map().guess_head_span(enum_span);
let enum_def_snippet = this
.session
.source_map()

View File

@ -2517,7 +2517,8 @@ impl<'a> Resolver<'a> {
false => "defined",
};
let (name, span) = (ident.name, self.session.source_map().def_span(new_binding.span));
let (name, span) =
(ident.name, self.session.source_map().guess_head_span(new_binding.span));
if let Some(s) = self.name_already_seen.get(&name) {
if s == &span {
@ -2558,7 +2559,7 @@ impl<'a> Resolver<'a> {
err.span_label(span, format!("`{}` re{} here", name, new_participle));
err.span_label(
self.session.source_map().def_span(old_binding.span),
self.session.source_map().guess_head_span(old_binding.span),
format!("previous {} of the {} `{}` here", old_noun, old_kind, name),
);

View File

@ -733,7 +733,14 @@ impl SourceMap {
}
}
pub fn def_span(&self, sp: Span) -> Span {
/// Given a `Span`, return a span ending in the closest `{`. This is useful when you have a
/// `Span` enclosing a whole item but we need to point at only the head (usually the first
/// line) of that item.
///
/// *Only suitable for diagnostics.*
pub fn guess_head_span(&self, sp: Span) -> Span {
// FIXME: extend the AST items to have a head span, or replace callers with pointing at
// the item's ident when appropriate.
self.span_until_char(sp, '{')
}

View File

@ -482,11 +482,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
let found_kind = self.closure_kind(closure_substs).unwrap();
let closure_span = self
.tcx
.sess
.source_map()
.def_span(self.tcx.hir().span_if_local(closure_def_id).unwrap());
let closure_span =
self.tcx.sess.source_map().guess_head_span(
self.tcx.hir().span_if_local(closure_def_id).unwrap(),
);
let hir_id = self.tcx.hir().as_local_hir_id(closure_def_id).unwrap();
let mut err = struct_span_err!(
self.tcx.sess,
@ -580,7 +579,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().def_span(sp)); // the sp could be an fn def
.map(|sp| self.tcx.sess.source_map().guess_head_span(sp)); // the sp could be an fn def
if self.reported_closure_mismatch.borrow().contains(&(span, found_span)) {
// We check closures twice, with obligations flowing in different directions,
@ -680,7 +679,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
kind: hir::ExprKind::Closure(_, ref _decl, id, span, _),
..
}) => (
self.tcx.sess.source_map().def_span(span),
self.tcx.sess.source_map().guess_head_span(span),
self.tcx
.hir()
.body(id)
@ -723,7 +722,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
kind: hir::TraitItemKind::Fn(ref sig, _),
..
}) => (
self.tcx.sess.source_map().def_span(span),
self.tcx.sess.source_map().guess_head_span(span),
sig.decl
.inputs
.iter()
@ -741,7 +740,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
.ctor_hir_id()
.map(|hir_id| self.tcx.hir().span(hir_id))
.unwrap_or(DUMMY_SP);
let span = self.tcx.sess.source_map().def_span(span);
let span = self.tcx.sess.source_map().guess_head_span(span);
(span, vec![ArgKind::empty(); variant_data.fields().len()])
}
@ -1624,7 +1623,7 @@ pub fn recursive_type_with_infinite_size_error(
) -> DiagnosticBuilder<'tcx> {
assert!(type_def_id.is_local());
let span = tcx.hir().span_if_local(type_def_id).unwrap();
let span = tcx.sess.source_map().def_span(span);
let span = tcx.sess.source_map().guess_head_span(span);
let mut err = struct_span_err!(
tcx.sess,
span,

View File

@ -1381,7 +1381,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let msg = format!("required by `{}`", item_name);
if let Some(sp) = tcx.hir().span_if_local(item_def_id) {
let sp = tcx.sess.source_map().def_span(sp);
let sp = tcx.sess.source_map().guess_head_span(sp);
err.span_label(sp, &msg);
} else {
err.note(&msg);

View File

@ -325,7 +325,7 @@ pub(super) fn specialization_graph_provider(
if let Some(overlap) = overlap {
let impl_span =
tcx.sess.source_map().def_span(tcx.span_of_impl(impl_def_id).unwrap());
tcx.sess.source_map().guess_head_span(tcx.span_of_impl(impl_def_id).unwrap());
// Work to be done after we've built the DiagnosticBuilder. We have to define it
// now because the struct_lint methods don't return back the DiagnosticBuilder
@ -347,7 +347,7 @@ pub(super) fn specialization_graph_provider(
match tcx.span_of_impl(overlap.with_impl) {
Ok(span) => {
err.span_label(
tcx.sess.source_map().def_span(span),
tcx.sess.source_map().guess_head_span(span),
"first implementation here".to_string(),
);

View File

@ -186,7 +186,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
_ => (None, None),
};
let item_span = item.map(|i| tcx.sess.source_map().def_span(i.span));
let item_span = item.map(|i| tcx.sess.source_map().guess_head_span(i.span));
match pred {
ty::Predicate::Projection(proj) => {
// The obligation comes not from the current `impl` nor the `trait` being

View File

@ -2269,7 +2269,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}
if let Some(sp) = tcx.hir().span_if_local(adt_def.did) {
let sp = tcx.sess.source_map().def_span(sp);
let sp = tcx.sess.source_map().guess_head_span(sp);
err.span_label(sp, format!("variant `{}` not found here", assoc_ident));
}

View File

@ -332,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// | |_____^ expected integer, found `()`
// ```
if outer_sp.is_some() {
outer_sp = Some(self.tcx.sess.source_map().def_span(span));
outer_sp = Some(self.tcx.sess.source_map().guess_head_span(span));
}
else_expr.span
}

View File

@ -35,7 +35,7 @@ crate fn compare_impl_method<'tcx>(
) {
debug!("compare_impl_method(impl_trait_ref={:?})", impl_trait_ref);
let impl_m_span = tcx.sess.source_map().def_span(impl_m_span);
let impl_m_span = tcx.sess.source_map().guess_head_span(impl_m_span);
if let Err(ErrorReported) = compare_self_type(tcx, impl_m, impl_m_span, trait_m, impl_trait_ref)
{
@ -363,7 +363,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
// the moment, give a kind of vague error message.
if trait_params != impl_params {
let item_kind = assoc_item_kind_str(impl_m);
let def_span = tcx.sess.source_map().def_span(span);
let def_span = tcx.sess.source_map().guess_head_span(span);
let span = tcx.hir().get_generics(impl_m.def_id).map(|g| g.span).unwrap_or(def_span);
let mut err = struct_span_err!(
tcx.sess,
@ -375,7 +375,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
);
err.span_label(span, &format!("lifetimes do not match {} in trait", item_kind));
if let Some(sp) = tcx.hir().span_if_local(trait_m.def_id) {
let def_sp = tcx.sess.source_map().def_span(sp);
let def_sp = tcx.sess.source_map().guess_head_span(sp);
let sp = tcx.hir().get_generics(trait_m.def_id).map(|g| g.span).unwrap_or(def_sp);
err.span_label(
sp,

View File

@ -147,7 +147,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(note_span) = note_span {
// We have a span pointing to the method. Show note with snippet.
err.span_note(
self.tcx.sess.source_map().def_span(note_span),
self.tcx.sess.source_map().guess_head_span(note_span),
&note_str,
);
} else {
@ -189,8 +189,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Some(item) => item,
None => continue,
};
let item_span =
self.tcx.sess.source_map().def_span(self.tcx.def_span(item.def_id));
let item_span = self
.tcx
.sess
.source_map()
.guess_head_span(self.tcx.def_span(item.def_id));
let idx = if sources.len() > 1 {
let msg = &format!(
"candidate #{} is defined in the trait `{}`",
@ -397,7 +400,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(def) = actual.ty_adt_def() {
if let Some(full_sp) = tcx.hir().span_if_local(def.did) {
let def_sp = tcx.sess.source_map().def_span(full_sp);
let def_sp = tcx.sess.source_map().guess_head_span(full_sp);
err.span_label(
def_sp,
format!(
@ -537,8 +540,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let mut restrict_type_params = false;
if !unsatisfied_predicates.is_empty() {
let def_span =
|def_id| self.tcx.sess.source_map().def_span(self.tcx.def_span(def_id));
let def_span = |def_id| {
self.tcx.sess.source_map().guess_head_span(self.tcx.def_span(def_id))
};
let mut type_params = FxHashMap::default();
let mut bound_spans = vec![];
let mut collect_type_param_suggestions =
@ -1117,7 +1121,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let [trait_info] = &candidates[..] {
if let Some(span) = self.tcx.hir().span_if_local(trait_info.def_id) {
err.span_note(
self.tcx.sess.source_map().def_span(span),
self.tcx.sess.source_map().guess_head_span(span),
&format!(
"`{}` defines an item `{}`, perhaps you need to {} it",
self.tcx.def_path_str(trait_info.def_id),

View File

@ -1479,7 +1479,7 @@ fn check_fn<'a, 'tcx>(
}
}
} else {
let span = sess.source_map().def_span(span);
let span = sess.source_map().guess_head_span(span);
sess.span_err(span, "function should have one argument");
}
} else {
@ -1520,7 +1520,7 @@ fn check_fn<'a, 'tcx>(
}
}
} else {
let span = sess.source_map().def_span(span);
let span = sess.source_map().guess_head_span(span);
sess.span_err(span, "function should have one argument");
}
} else {
@ -1962,7 +1962,7 @@ fn check_impl_items_against_trait<'tcx>(
impl_trait_ref: ty::TraitRef<'tcx>,
impl_item_refs: &[hir::ImplItemRef<'_>],
) {
let impl_span = tcx.sess.source_map().def_span(full_impl_span);
let impl_span = tcx.sess.source_map().guess_head_span(full_impl_span);
// If the trait reference itself is erroneous (so the compilation is going
// to fail), skip checking the items here -- the `impl_item` table in `tcx`
@ -2508,7 +2508,7 @@ fn check_transparent(tcx: TyCtxt<'_>, sp: Span, def_id: DefId) {
if !adt.repr.transparent() {
return;
}
let sp = tcx.sess.source_map().def_span(sp);
let sp = tcx.sess.source_map().guess_head_span(sp);
if adt.is_union() && !tcx.features().transparent_unions {
feature_err(
@ -3875,7 +3875,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
}
if let Some(def_s) = def_span.map(|sp| tcx.sess.source_map().def_span(sp)) {
if let Some(def_s) = def_span.map(|sp| tcx.sess.source_map().guess_head_span(sp)) {
err.span_label(def_s, "defined here");
}
if sugg_unit {
@ -4966,7 +4966,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&found.kind, self.suggest_fn_call(err, expr, expected, found))
{
if let Some(sp) = self.tcx.hir().span_if_local(*def_id) {
let sp = self.sess().source_map().def_span(sp);
let sp = self.sess().source_map().guess_head_span(sp);
err.span_label(sp, &format!("{} defined here", found));
}
} else if !self.check_for_cast(err, expr, found, expected) {

View File

@ -20,7 +20,7 @@ mod unsafety;
/// Obtains the span of just the impl header of `impl_def_id`.
fn impl_header_span(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Span {
tcx.sess.source_map().def_span(tcx.span_of_impl(impl_def_id).unwrap())
tcx.sess.source_map().guess_head_span(tcx.span_of_impl(impl_def_id).unwrap())
}
fn check_impl(tcx: TyCtxt<'_>, impl_def_id: DefId, trait_ref: ty::TraitRef<'_>) {

View File

@ -34,7 +34,7 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap();
let trait_def_id = trait_ref.def_id;
let sm = self.tcx.sess.source_map();
let sp = sm.def_span(item.span);
let sp = sm.guess_head_span(item.span);
match traits::orphan_check(self.tcx, def_id) {
Ok(()) => {}
Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => {