Skip to content

Commit 57f7618

Browse files
Remove some usages of guess_head_span from typeck
1 parent aad2334 commit 57f7618

File tree

7 files changed

+19
-21
lines changed

7 files changed

+19
-21
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,11 +1958,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19581958
);
19591959
}
19601960

1961-
if adt_def.did().is_local() {
1962-
err.span_label(
1963-
tcx.def_span(adt_def.did()),
1964-
format!("variant `{assoc_ident}` not found for this enum"),
1965-
);
1961+
if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) {
1962+
err.span_label(sp, format!("variant `{}` not found here", assoc_ident));
19661963
}
19671964

19681965
err.emit()

compiler/rustc_typeck/src/check/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::check::coercion::{AsCoercionSite, CoerceMany};
22
use crate::check::{Diverges, Expectation, FnCtxt, Needs};
3-
use rustc_errors::{Applicability, Diagnostic, MultiSpan};
3+
use rustc_errors::{Applicability, MultiSpan};
44
use rustc_hir::{self as hir, ExprKind};
55
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
66
use rustc_infer::traits::Obligation;
@@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
127127
&cause,
128128
Some(&arm.body),
129129
arm_ty,
130-
Some(&mut |err: &mut Diagnostic| {
130+
Some(&mut |err| {
131131
let Some(ret) = self.ret_type_span else {
132132
return;
133133
};

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,15 +437,17 @@ fn check_region_bounds_on_impl_item<'tcx>(
437437
// the moment, give a kind of vague error message.
438438
if trait_params != impl_params {
439439
let item_kind = assoc_item_kind_str(impl_m);
440-
let def_span = tcx.sess.source_map().guess_head_span(span);
441440
let span = impl_m
442441
.def_id
443442
.as_local()
444443
.and_then(|did| tcx.hir().get_generics(did))
445-
.map_or(def_span, |g| g.span);
446-
let generics_span = trait_m.def_id.as_local().map(|did| {
447-
let def_sp = tcx.def_span(did);
448-
tcx.hir().get_generics(did).map_or(def_sp, |g| g.span)
444+
.map_or(span, |g| g.span);
445+
let generics_span = tcx.hir().span_if_local(trait_m.def_id).map(|sp| {
446+
trait_m
447+
.def_id
448+
.as_local()
449+
.and_then(|did| tcx.hir().get_generics(did))
450+
.map_or(sp, |g| g.span)
449451
});
450452

451453
let reported = tcx.sess.emit_err(LifetimesOrBoundsMismatchOnTrait {

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
183183
} else if let (ty::FnDef(def_id, ..), true) =
184184
(&found.kind(), self.suggest_fn_call(err, expr, expected, found))
185185
{
186-
if def_id.is_local() {
187-
err.span_label(self.tcx.def_span(def_id), &format!("{} defined here", found));
186+
if let Some(sp) = self.tcx.hir().span_if_local(*def_id) {
187+
err.span_label(sp, format!("{found} defined here"));
188188
}
189189
} else if !self.check_for_cast(err, expr, found, expected, expected_ty_expr) {
190190
let is_struct_pat_shorthand_field =

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,8 @@ fn missing_items_err(
621621
// adding the associated item at the end of its body.
622622
let sugg_sp = full_impl_span.with_lo(hi).with_hi(hi);
623623
// Obtain the level of indentation ending in `sugg_sp`.
624-
let indentation = tcx.sess.source_map().span_to_margin(sugg_sp).unwrap_or(0);
625-
// Make the whitespace that will make the suggestion have the right indentation.
626-
let padding: String = " ".repeat(indentation);
624+
let padding =
625+
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());
627626

628627
for trait_item in missing_items {
629628
let snippet = suggestion_signature(trait_item, tcx);

src/test/ui/issues/issue-34209.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no variant named `B` found for enum `S`
22
--> $DIR/issue-34209.rs:7:12
33
|
44
LL | enum S {
5-
| ------ variant `B` not found for this enum
5+
| ------ variant `B` not found here
66
...
77
LL | S::B {} => {},
88
| ^ help: there is a variant with a similar name: `A`

src/test/ui/suggestions/suggest-variants.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0599]: no variant named `Squareee` found for enum `Shape`
22
--> $DIR/suggest-variants.rs:12:41
33
|
44
LL | enum Shape {
5-
| ---------- variant `Squareee` not found for this enum
5+
| ---------- variant `Squareee` not found here
66
...
77
LL | println!("My shape is {:?}", Shape::Squareee { size: 5});
88
| ^^^^^^^^ help: there is a variant with a similar name: `Square`
@@ -11,7 +11,7 @@ error[E0599]: no variant named `Circl` found for enum `Shape`
1111
--> $DIR/suggest-variants.rs:13:41
1212
|
1313
LL | enum Shape {
14-
| ---------- variant `Circl` not found for this enum
14+
| ---------- variant `Circl` not found here
1515
...
1616
LL | println!("My shape is {:?}", Shape::Circl { size: 5});
1717
| ^^^^^ help: there is a variant with a similar name: `Circle`
@@ -20,7 +20,7 @@ error[E0599]: no variant named `Rombus` found for enum `Shape`
2020
--> $DIR/suggest-variants.rs:14:41
2121
|
2222
LL | enum Shape {
23-
| ---------- variant `Rombus` not found for this enum
23+
| ---------- variant `Rombus` not found here
2424
...
2525
LL | println!("My shape is {:?}", Shape::Rombus{ size: 5});
2626
| ^^^^^^ variant not found in `Shape`

0 commit comments

Comments
 (0)