Remove some usages of guess_head_span from typeck
This commit is contained in:
parent
aad2334ecb
commit
57f7618f62
@ -1958,11 +1958,8 @@ pub fn associated_path_to_ty(
|
||||
);
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -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 @@ pub fn check_match(
|
||||
&cause,
|
||||
Some(&arm.body),
|
||||
arm_ty,
|
||||
Some(&mut |err: &mut Diagnostic| {
|
||||
Some(&mut |err| {
|
||||
let Some(ret) = self.ret_type_span else {
|
||||
return;
|
||||
};
|
||||
|
@ -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 {
|
||||
|
@ -183,8 +183,8 @@ pub fn suggest_deref_ref_or_into(
|
||||
} 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 =
|
||||
|
@ -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);
|
||||
|
@ -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`
|
||||
|
@ -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`
|
||||
|
Loading…
Reference in New Issue
Block a user