Remove some usages of guess_head_span from typeck

This commit is contained in:
Michael Goulet 2022-07-07 06:52:27 +00:00
parent aad2334ecb
commit 57f7618f62
7 changed files with 19 additions and 21 deletions

View file

@ -1958,11 +1958,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
);
}
if adt_def.did().is_local() {
err.span_label(
tcx.def_span(adt_def.did()),
format!("variant `{assoc_ident}` not found for this enum"),
);
if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) {
err.span_label(sp, format!("variant `{}` not found here", assoc_ident));
}
err.emit()

View file

@ -1,6 +1,6 @@
use crate::check::coercion::{AsCoercionSite, CoerceMany};
use crate::check::{Diverges, Expectation, FnCtxt, Needs};
use rustc_errors::{Applicability, Diagnostic, MultiSpan};
use rustc_errors::{Applicability, MultiSpan};
use rustc_hir::{self as hir, ExprKind};
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::traits::Obligation;
@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&cause,
Some(&arm.body),
arm_ty,
Some(&mut |err: &mut Diagnostic| {
Some(&mut |err| {
let Some(ret) = self.ret_type_span else {
return;
};

View file

@ -437,15 +437,17 @@ 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().guess_head_span(span);
let span = impl_m
.def_id
.as_local()
.and_then(|did| tcx.hir().get_generics(did))
.map_or(def_span, |g| g.span);
let generics_span = trait_m.def_id.as_local().map(|did| {
let def_sp = tcx.def_span(did);
tcx.hir().get_generics(did).map_or(def_sp, |g| g.span)
.map_or(span, |g| g.span);
let generics_span = tcx.hir().span_if_local(trait_m.def_id).map(|sp| {
trait_m
.def_id
.as_local()
.and_then(|did| tcx.hir().get_generics(did))
.map_or(sp, |g| g.span)
});
let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {

View file

@ -183,8 +183,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
} else if let (ty::FnDef(def_id, ..), true) =
(&found.kind(), self.suggest_fn_call(err, expr, expected, found))
{
if def_id.is_local() {
err.span_label(self.tcx.def_span(def_id), &format!("{} defined here", found));
if let Some(sp) = self.tcx.hir().span_if_local(*def_id) {
err.span_label(sp, format!("{found} defined here"));
}
} else if !self.check_for_cast(err, expr, found, expected, expected_ty_expr) {
let is_struct_pat_shorthand_field =

View file

@ -621,9 +621,8 @@ fn missing_items_err(
// adding the associated item at the end of its body.
let sugg_sp = full_impl_span.with_lo(hi).with_hi(hi);
// Obtain the level of indentation ending in `sugg_sp`.
let indentation = tcx.sess.source_map().span_to_margin(sugg_sp).unwrap_or(0);
// Make the whitespace that will make the suggestion have the right indentation.
let padding: String = " ".repeat(indentation);
let padding =
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());
for trait_item in missing_items {
let snippet = suggestion_signature(trait_item, tcx);

View file

@ -2,7 +2,7 @@ error[E0599]: no variant named `B` found for enum `S`
--> $DIR/issue-34209.rs:7:12
|
LL | enum S {
| ------ variant `B` not found for this enum
| ------ variant `B` not found here
...
LL | S::B {} => {},
| ^ help: there is a variant with a similar name: `A`

View file

@ -2,7 +2,7 @@ error[E0599]: no variant named `Squareee` found for enum `Shape`
--> $DIR/suggest-variants.rs:12:41
|
LL | enum Shape {
| ---------- variant `Squareee` not found for this enum
| ---------- variant `Squareee` not found here
...
LL | println!("My shape is {:?}", Shape::Squareee { size: 5});
| ^^^^^^^^ help: there is a variant with a similar name: `Square`
@ -11,7 +11,7 @@ error[E0599]: no variant named `Circl` found for enum `Shape`
--> $DIR/suggest-variants.rs:13:41
|
LL | enum Shape {
| ---------- variant `Circl` not found for this enum
| ---------- variant `Circl` not found here
...
LL | println!("My shape is {:?}", Shape::Circl { size: 5});
| ^^^^^ help: there is a variant with a similar name: `Circle`
@ -20,7 +20,7 @@ error[E0599]: no variant named `Rombus` found for enum `Shape`
--> $DIR/suggest-variants.rs:14:41
|
LL | enum Shape {
| ---------- variant `Rombus` not found for this enum
| ---------- variant `Rombus` not found here
...
LL | println!("My shape is {:?}", Shape::Rombus{ size: 5});
| ^^^^^^ variant not found in `Shape`