Skip to content

Commit d7c0bcd

Browse files
committed
Rename and document span marking method
1 parent 8a47602 commit d7c0bcd

File tree

11 files changed

+78
-54
lines changed

11 files changed

+78
-54
lines changed

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
286286
segment_ident_span.find_ancestor_inside(path_span).unwrap_or(path_span)
287287
} else if generic_args.is_empty() {
288288
// If there are brackets, but not generic arguments, then use the opening bracket
289-
self.tcx.adjust_span(generic_args.span).with_hi(generic_args.span.lo() + BytePos(1))
289+
self.tcx
290+
.mark_span_for_resize(generic_args.span)
291+
.with_hi(generic_args.span.lo() + BytePos(1))
290292
} else {
291293
// Else use an empty span right after the opening bracket.
292294
self.tcx
293-
.adjust_span(generic_args.span)
295+
.mark_span_for_resize(generic_args.span)
294296
.with_lo(generic_args.span.lo() + BytePos(1))
295297
.shrink_to_lo()
296298
};

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,12 +2073,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20732073
Ok(string) => {
20742074
if string.starts_with("async ") {
20752075
let pos = args_span.lo() + BytePos(6);
2076-
(self.infcx.tcx.adjust_span(args_span).with_lo(pos).with_hi(pos), "move ")
2076+
(
2077+
self.infcx.tcx.mark_span_for_resize(args_span).with_lo(pos).with_hi(pos),
2078+
"move ",
2079+
)
20772080
} else if string.starts_with("async|") {
20782081
let pos = args_span.lo() + BytePos(5);
2079-
(self.infcx.tcx.adjust_span(args_span).with_lo(pos).with_hi(pos), " move")
2082+
(
2083+
self.infcx.tcx.mark_span_for_resize(args_span).with_lo(pos).with_hi(pos),
2084+
" move",
2085+
)
20802086
} else {
2081-
(self.infcx.tcx.adjust_span(args_span).shrink_to_lo(), "move ")
2087+
(self.infcx.tcx.mark_span_for_resize(args_span).shrink_to_lo(), "move ")
20822088
}
20832089
}
20842090
Err(_) => (args_span, "move |<args>| <body>"),

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
457457
match self.infcx.tcx.sess.source_map().span_to_snippet(span) {
458458
Ok(snippet) if snippet.starts_with('*') => {
459459
err.span_suggestion_verbose(
460-
self.infcx.tcx.adjust_span(span).with_hi(span.lo() + BytePos(1)),
460+
self.infcx.tcx.mark_span_for_resize(span).with_hi(span.lo() + BytePos(1)),
461461
"consider removing the dereference here",
462462
String::new(),
463463
Applicability::MaybeIncorrect,
464464
);
465465
}
466466
_ => {
467467
err.span_suggestion_verbose(
468-
self.infcx.tcx.adjust_span(span).shrink_to_lo(),
468+
self.infcx.tcx.mark_span_for_resize(span).shrink_to_lo(),
469469
"consider borrowing here",
470470
'&',
471471
Applicability::MaybeIncorrect,

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,15 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
256256
{
257257
let rhs_pos =
258258
span.lo() + BytePos::from_usize(eq_idx + 2 + rhs_idx);
259-
let rhs_span =
260-
tcx.adjust_span(span).with_lo(rhs_pos).with_hi(rhs_pos);
259+
let rhs_span = tcx
260+
.mark_span_for_resize(span)
261+
.with_lo(rhs_pos)
262+
.with_hi(rhs_pos);
261263
err.multipart_suggestion(
262264
"consider dereferencing here",
263265
vec![
264266
(
265-
tcx.adjust_span(span).shrink_to_lo(),
267+
tcx.mark_span_for_resize(span).shrink_to_lo(),
266268
deref.clone(),
267269
),
268270
(rhs_span, deref),

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,8 @@ fn compare_number_of_method_arguments<'tcx>(
13511351
if pos == 0 {
13521352
arg.span
13531353
} else {
1354-
tcx.adjust_span(arg.span).with_lo(trait_m_sig.decl.inputs[0].span.lo())
1354+
tcx.mark_span_for_resize(arg.span)
1355+
.with_lo(trait_m_sig.decl.inputs[0].span.lo())
13551356
}
13561357
})
13571358
})
@@ -1367,7 +1368,7 @@ fn compare_number_of_method_arguments<'tcx>(
13671368
if pos == 0 {
13681369
arg.span
13691370
} else {
1370-
tcx.adjust_span(arg.span).with_lo(impl_m_sig.decl.inputs[0].span.lo())
1371+
tcx.mark_span_for_resize(arg.span).with_lo(impl_m_sig.decl.inputs[0].span.lo())
13711372
}
13721373
})
13731374
.unwrap_or_else(|| tcx.def_span(impl_m.def_id));
@@ -1464,8 +1465,9 @@ fn compare_synthetic_generics<'tcx>(
14641465

14651466
// in case there are no generics, take the spot between the function name
14661467
// and the opening paren of the argument list
1467-
let new_generics_span =
1468-
tcx.adjust_span(tcx.def_ident_span(impl_def_id)?).shrink_to_hi();
1468+
let new_generics_span = tcx
1469+
.mark_span_for_resize(tcx.def_ident_span(impl_def_id)?)
1470+
.shrink_to_hi();
14691471
// in case there are generics, just replace them
14701472
let generics_span =
14711473
impl_m.generics.span.substitute_dummy(new_generics_span);

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn missing_items_err(
220220
let hi = full_impl_span.hi() - BytePos(1);
221221
// Point at the place right before the closing brace of the relevant `impl` to suggest
222222
// adding the associated item at the end of its body.
223-
let sugg_sp = tcx.adjust_span(full_impl_span).with_lo(hi).with_hi(hi);
223+
let sugg_sp = tcx.mark_span_for_resize(full_impl_span).with_lo(hi).with_hi(hi);
224224
// Obtain the level of indentation ending in `sugg_sp`.
225225
let padding =
226226
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());

compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,10 +610,13 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
610610

611611
AngleBrackets::Available => {
612612
let (sugg_span, is_first) = if self.num_provided_lifetime_args() == 0 {
613-
(self.tcx.adjust_span(self.gen_args.span().unwrap()).shrink_to_lo(), true)
613+
(
614+
self.tcx.mark_span_for_resize(self.gen_args.span().unwrap()).shrink_to_lo(),
615+
true,
616+
)
614617
} else {
615618
let last_lt = &self.gen_args.args[self.num_provided_lifetime_args() - 1];
616-
(self.tcx.adjust_span(last_lt.span()).shrink_to_hi(), false)
619+
(self.tcx.mark_span_for_resize(last_lt.span()).shrink_to_hi(), false)
617620
};
618621
let has_non_lt_args = self.num_provided_type_or_const_args() != 0;
619622
let has_bindings = !self.gen_args.bindings.is_empty();
@@ -658,14 +661,15 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
658661
);
659662
}
660663
AngleBrackets::Available => {
661-
let gen_args_span = self.tcx.adjust_span(self.gen_args.span().unwrap());
664+
let gen_args_span = self.tcx.mark_span_for_resize(self.gen_args.span().unwrap());
662665
let sugg_offset =
663666
self.get_lifetime_args_offset() + self.num_provided_type_or_const_args();
664667

665668
let (sugg_span, is_first) = if sugg_offset == 0 {
666-
(self.tcx.adjust_span(gen_args_span).shrink_to_lo(), true)
669+
(self.tcx.mark_span_for_resize(gen_args_span).shrink_to_lo(), true)
667670
} else {
668-
let arg_span = self.tcx.adjust_span(self.gen_args.args[sugg_offset - 1].span());
671+
let arg_span =
672+
self.tcx.mark_span_for_resize(self.gen_args.args[sugg_offset - 1].span());
669673
// If we came here then inferred lifetime's spans can only point
670674
// to either the opening bracket or to the space right after.
671675
// Both of these spans have an `hi` lower than or equal to the span
@@ -770,7 +774,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
770774
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
771775
let sugg = vec![
772776
(self.path_segment.ident.span, format!("{}::{}", snippet, self.path_segment.ident)),
773-
(self.tcx.adjust_span(span).with_lo(self.path_segment.ident.span.hi()), "".to_owned())
777+
(self.tcx.mark_span_for_resize(span).with_lo(self.path_segment.ident.span.hi()), "".to_owned())
774778
];
775779

776780
err.multipart_suggestion(
@@ -954,7 +958,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
954958
} else if remove_entire_generics {
955959
let span = self
956960
.tcx
957-
.adjust_span(self.path_segment.args.unwrap().span_ext().unwrap())
961+
.mark_span_for_resize(self.path_segment.args.unwrap().span_ext().unwrap())
958962
.with_lo(self.path_segment.ident.span.hi());
959963

960964
let msg = format!(

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624624
),
625625
match &args[..] {
626626
[] => (
627-
self.tcx.adjust_span(base.span).shrink_to_hi().with_hi(deref.span.hi()),
627+
self.tcx
628+
.mark_span_for_resize(base.span)
629+
.shrink_to_hi()
630+
.with_hi(deref.span.hi()),
628631
")".to_string(),
629632
),
630633
[first, ..] => (base.span.between(first.span), ", ".to_string()),
@@ -750,8 +753,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
750753
"use `?` to coerce and return an appropriate `Err`, and wrap the resulting value \
751754
in `Ok` so the expression remains of type `Result`",
752755
vec![
753-
(self.tcx.adjust_span(expr.span).shrink_to_lo(), "Ok(".to_string()),
754-
(self.tcx.adjust_span(expr.span).shrink_to_hi(), "?)".to_string()),
756+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(), "Ok(".to_string()),
757+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(), "?)".to_string()),
755758
],
756759
Applicability::MaybeIncorrect,
757760
);
@@ -822,20 +825,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
822825
} else {
823826
return false;
824827
};
825-
if let Some(indent) = self
826-
.tcx
827-
.sess
828-
.source_map()
829-
.indentation_before(self.tcx.adjust_span(span).shrink_to_lo())
830-
{
828+
if let Some(indent) = self.tcx.sess.source_map().indentation_before(
829+
self.tcx.mark_span_for_resize(span).shrink_to_lo(),
830+
) {
831831
// Add a semicolon, except after `}`.
832832
let semicolon =
833833
match self.tcx.sess.source_map().span_to_snippet(span) {
834834
Ok(s) if s.ends_with('}') => "",
835835
_ => ";",
836836
};
837837
err.span_suggestions(
838-
self.tcx.adjust_span(span).shrink_to_hi(),
838+
self.tcx.mark_span_for_resize(span).shrink_to_hi(),
839839
"try adding an expression at the end of the block",
840840
return_suggestions
841841
.into_iter()
@@ -914,10 +914,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
914914

915915
vec![
916916
(
917-
self.tcx.adjust_span(expr.span).shrink_to_lo(),
917+
self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(),
918918
format!("{prefix}{variant}{open}"),
919919
),
920-
(self.tcx.adjust_span(expr.span).shrink_to_hi(), close.to_owned()),
920+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(), close.to_owned()),
921921
]
922922
};
923923

@@ -1001,8 +1001,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10011001
err.multipart_suggestion(
10021002
format!("consider calling `{s}::new`"),
10031003
vec![
1004-
(self.tcx.adjust_span(expr.span).shrink_to_lo(), format!("{path}::new(")),
1005-
(self.tcx.adjust_span(expr.span).shrink_to_hi(), format!("){unwrap}")),
1004+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(), format!("{path}::new(")),
1005+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(), format!("){unwrap}")),
10061006
],
10071007
Applicability::MaybeIncorrect,
10081008
);
@@ -1256,7 +1256,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12561256
&& replace_prefix(&src, "\"", "b\"").is_some()
12571257
{
12581258
return Some((
1259-
self.tcx.adjust_span(sp).shrink_to_lo(),
1259+
self.tcx.mark_span_for_resize(sp).shrink_to_lo(),
12601260
"consider adding a leading `b`".to_string(),
12611261
"b".to_string(),
12621262
Applicability::MachineApplicable,
@@ -1453,7 +1453,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14531453
_ if sp == expr.span => {
14541454
if let Some(mut steps) = self.deref_steps(checked_ty, expected) {
14551455
let mut expr = expr.peel_blocks();
1456-
let mut prefix_span = self.tcx.adjust_span(expr.span).shrink_to_lo();
1456+
let mut prefix_span = self.tcx.mark_span_for_resize(expr.span).shrink_to_lo();
14571457
let mut remove = String::new();
14581458

14591459
// Try peeling off any existing `&` and `&mut` to reach our target type
@@ -1524,7 +1524,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15241524
return None;
15251525
} else if let Some(expr) = self.maybe_get_block_expr(expr) {
15261526
// prefix should be empty here..
1527-
(self.tcx.adjust_span(expr.span).shrink_to_lo(), "*".to_string())
1527+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(), "*".to_string())
15281528
} else {
15291529
(prefix_span, format!("{}{}", prefix, "*".repeat(steps)))
15301530
};
@@ -1582,7 +1582,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15821582
if field.is_shorthand {
15831583
// This is a field literal
15841584
sugg.push((
1585-
self.tcx.adjust_span(field.ident.span).shrink_to_lo(),
1585+
self.tcx.mark_span_for_resize(field.ident.span).shrink_to_lo(),
15861586
format!("{}: ", field.ident),
15871587
));
15881588
} else {
@@ -1640,20 +1640,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16401640
);
16411641

16421642
let close_paren = if expr.precedence().order() < PREC_POSTFIX {
1643-
sugg.push((self.tcx.adjust_span(expr.span).shrink_to_lo(), "(".to_string()));
1643+
sugg.push((self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(), "(".to_string()));
16441644
")"
16451645
} else {
16461646
""
16471647
};
16481648

16491649
let mut cast_suggestion = sugg.clone();
16501650
cast_suggestion.push((
1651-
self.tcx.adjust_span(expr.span).shrink_to_hi(),
1651+
self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(),
16521652
format!("{close_paren} as {expected_ty}"),
16531653
));
16541654
let mut into_suggestion = sugg.clone();
16551655
into_suggestion.push((
1656-
self.tcx.adjust_span(expr.span).shrink_to_hi(),
1656+
self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(),
16571657
format!("{close_paren}.into()"),
16581658
));
16591659
let mut suffix_suggestion = sugg.clone();
@@ -1710,17 +1710,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17101710
);
17111711
let suggestion = vec![
17121712
(
1713-
self.tcx.adjust_span(lhs_expr.span).shrink_to_lo(),
1713+
self.tcx.mark_span_for_resize(lhs_expr.span).shrink_to_lo(),
17141714
format!("{checked_ty}::from("),
17151715
),
1716-
(self.tcx.adjust_span(lhs_expr.span).shrink_to_hi(), ")".to_string()),
1716+
(
1717+
self.tcx.mark_span_for_resize(lhs_expr.span).shrink_to_hi(),
1718+
")".to_string(),
1719+
),
17171720
];
17181721
(msg, suggestion)
17191722
} else {
17201723
let msg = format!("{msg} and panic if the converted value doesn't fit");
17211724
let mut suggestion = sugg.clone();
17221725
suggestion.push((
1723-
self.tcx.adjust_span(expr.span).shrink_to_hi(),
1726+
self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(),
17241727
format!("{close_paren}.try_into().unwrap()"),
17251728
));
17261729
(msg, suggestion)

0 commit comments

Comments
 (0)