Skip to content

Commit 6421705

Browse files
committed
Rename and document span marking method
1 parent d1606b1 commit 6421705

File tree

11 files changed

+77
-53
lines changed

11 files changed

+77
-53
lines changed

compiler/rustc_ast_lowering/src/path.rs

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

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,12 +2250,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22502250
Ok(string) => {
22512251
if string.starts_with("async ") {
22522252
let pos = args_span.lo() + BytePos(6);
2253-
(self.infcx.tcx.adjust_span(args_span).with_lo(pos).with_hi(pos), "move ")
2253+
(
2254+
self.infcx.tcx.mark_span_for_resize(args_span).with_lo(pos).with_hi(pos),
2255+
"move ",
2256+
)
22542257
} else if string.starts_with("async|") {
22552258
let pos = args_span.lo() + BytePos(5);
2256-
(self.infcx.tcx.adjust_span(args_span).with_lo(pos).with_hi(pos), " move")
2259+
(
2260+
self.infcx.tcx.mark_span_for_resize(args_span).with_lo(pos).with_hi(pos),
2261+
" move",
2262+
)
22572263
} else {
2258-
(self.infcx.tcx.adjust_span(args_span).shrink_to_lo(), "move ")
2264+
(self.infcx.tcx.mark_span_for_resize(args_span).shrink_to_lo(), "move ")
22592265
}
22602266
}
22612267
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
@@ -470,15 +470,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
470470
match self.infcx.tcx.sess.source_map().span_to_snippet(span) {
471471
Ok(snippet) if snippet.starts_with('*') => {
472472
err.span_suggestion_verbose(
473-
self.infcx.tcx.adjust_span(span).with_hi(span.lo() + BytePos(1)),
473+
self.infcx.tcx.mark_span_for_resize(span).with_hi(span.lo() + BytePos(1)),
474474
"consider removing the dereference here",
475475
String::new(),
476476
Applicability::MaybeIncorrect,
477477
);
478478
}
479479
_ => {
480480
err.span_suggestion_verbose(
481-
self.infcx.tcx.adjust_span(span).shrink_to_lo(),
481+
self.infcx.tcx.mark_span_for_resize(span).shrink_to_lo(),
482482
"consider borrowing here",
483483
'&',
484484
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
@@ -1355,7 +1355,8 @@ fn compare_number_of_method_arguments<'tcx>(
13551355
if pos == 0 {
13561356
arg.span
13571357
} else {
1358-
tcx.adjust_span(arg.span).with_lo(trait_m_sig.decl.inputs[0].span.lo())
1358+
tcx.mark_span_for_resize(arg.span)
1359+
.with_lo(trait_m_sig.decl.inputs[0].span.lo())
13591360
}
13601361
})
13611362
})
@@ -1371,7 +1372,7 @@ fn compare_number_of_method_arguments<'tcx>(
13711372
if pos == 0 {
13721373
arg.span
13731374
} else {
1374-
tcx.adjust_span(arg.span).with_lo(impl_m_sig.decl.inputs[0].span.lo())
1375+
tcx.mark_span_for_resize(arg.span).with_lo(impl_m_sig.decl.inputs[0].span.lo())
13751376
}
13761377
})
13771378
.unwrap_or_else(|| tcx.def_span(impl_m.def_id));
@@ -1468,8 +1469,9 @@ fn compare_synthetic_generics<'tcx>(
14681469

14691470
// in case there are no generics, take the spot between the function name
14701471
// and the opening paren of the argument list
1471-
let new_generics_span =
1472-
tcx.adjust_span(tcx.def_ident_span(impl_def_id)?).shrink_to_hi();
1472+
let new_generics_span = tcx
1473+
.mark_span_for_resize(tcx.def_ident_span(impl_def_id)?)
1474+
.shrink_to_hi();
14731475
// in case there are generics, just replace them
14741476
let generics_span =
14751477
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
@@ -200,7 +200,7 @@ fn missing_items_err(
200200
let hi = full_impl_span.hi() - BytePos(1);
201201
// Point at the place right before the closing brace of the relevant `impl` to suggest
202202
// adding the associated item at the end of its body.
203-
let sugg_sp = tcx.adjust_span(full_impl_span).with_lo(hi).with_hi(hi);
203+
let sugg_sp = tcx.mark_span_for_resize(full_impl_span).with_lo(hi).with_hi(hi);
204204
// Obtain the level of indentation ending in `sugg_sp`.
205205
let padding =
206206
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
@@ -648,7 +648,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
648648
),
649649
match &args[..] {
650650
[] => (
651-
self.tcx.adjust_span(base.span).shrink_to_hi().with_hi(deref.span.hi()),
651+
self.tcx
652+
.mark_span_for_resize(base.span)
653+
.shrink_to_hi()
654+
.with_hi(deref.span.hi()),
652655
")".to_string(),
653656
),
654657
[first, ..] => (base.span.between(first.span), ", ".to_string()),
@@ -774,8 +777,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
774777
"use `?` to coerce and return an appropriate `Err`, and wrap the resulting value \
775778
in `Ok` so the expression remains of type `Result`",
776779
vec![
777-
(self.tcx.adjust_span(expr.span).shrink_to_lo(), "Ok(".to_string()),
778-
(self.tcx.adjust_span(expr.span).shrink_to_hi(), "?)".to_string()),
780+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(), "Ok(".to_string()),
781+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(), "?)".to_string()),
779782
],
780783
Applicability::MaybeIncorrect,
781784
);
@@ -846,20 +849,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
846849
} else {
847850
return false;
848851
};
849-
if let Some(indent) = self
850-
.tcx
851-
.sess
852-
.source_map()
853-
.indentation_before(self.tcx.adjust_span(span).shrink_to_lo())
854-
{
852+
if let Some(indent) = self.tcx.sess.source_map().indentation_before(
853+
self.tcx.mark_span_for_resize(span).shrink_to_lo(),
854+
) {
855855
// Add a semicolon, except after `}`.
856856
let semicolon =
857857
match self.tcx.sess.source_map().span_to_snippet(span) {
858858
Ok(s) if s.ends_with('}') => "",
859859
_ => ";",
860860
};
861861
err.span_suggestions(
862-
self.tcx.adjust_span(span).shrink_to_hi(),
862+
self.tcx.mark_span_for_resize(span).shrink_to_hi(),
863863
"try adding an expression at the end of the block",
864864
return_suggestions
865865
.into_iter()
@@ -938,10 +938,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
938938

939939
vec![
940940
(
941-
self.tcx.adjust_span(expr.span).shrink_to_lo(),
941+
self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(),
942942
format!("{prefix}{variant}{open}"),
943943
),
944-
(self.tcx.adjust_span(expr.span).shrink_to_hi(), close.to_owned()),
944+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(), close.to_owned()),
945945
]
946946
};
947947

@@ -1025,8 +1025,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10251025
err.multipart_suggestion(
10261026
format!("consider calling `{s}::new`"),
10271027
vec![
1028-
(self.tcx.adjust_span(expr.span).shrink_to_lo(), format!("{path}::new(")),
1029-
(self.tcx.adjust_span(expr.span).shrink_to_hi(), format!("){unwrap}")),
1028+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(), format!("{path}::new(")),
1029+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(), format!("){unwrap}")),
10301030
],
10311031
Applicability::MaybeIncorrect,
10321032
);
@@ -1280,7 +1280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12801280
&& replace_prefix(&src, "\"", "b\"").is_some()
12811281
{
12821282
return Some((
1283-
self.tcx.adjust_span(sp).shrink_to_lo(),
1283+
self.tcx.mark_span_for_resize(sp).shrink_to_lo(),
12841284
"consider adding a leading `b`".to_string(),
12851285
"b".to_string(),
12861286
Applicability::MachineApplicable,
@@ -1477,7 +1477,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14771477
_ if sp == expr.span => {
14781478
if let Some(mut steps) = self.deref_steps(checked_ty, expected) {
14791479
let mut expr = expr.peel_blocks();
1480-
let mut prefix_span = self.tcx.adjust_span(expr.span).shrink_to_lo();
1480+
let mut prefix_span = self.tcx.mark_span_for_resize(expr.span).shrink_to_lo();
14811481
let mut remove = String::new();
14821482

14831483
// Try peeling off any existing `&` and `&mut` to reach our target type
@@ -1548,7 +1548,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15481548
return None;
15491549
} else if let Some(expr) = self.maybe_get_block_expr(expr) {
15501550
// prefix should be empty here..
1551-
(self.tcx.adjust_span(expr.span).shrink_to_lo(), "*".to_string())
1551+
(self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(), "*".to_string())
15521552
} else {
15531553
(prefix_span, format!("{}{}", prefix, "*".repeat(steps)))
15541554
};
@@ -1606,7 +1606,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16061606
if field.is_shorthand {
16071607
// This is a field literal
16081608
sugg.push((
1609-
self.tcx.adjust_span(field.ident.span).shrink_to_lo(),
1609+
self.tcx.mark_span_for_resize(field.ident.span).shrink_to_lo(),
16101610
format!("{}: ", field.ident),
16111611
));
16121612
} else {
@@ -1664,20 +1664,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16641664
);
16651665

16661666
let close_paren = if expr.precedence().order() < PREC_POSTFIX {
1667-
sugg.push((self.tcx.adjust_span(expr.span).shrink_to_lo(), "(".to_string()));
1667+
sugg.push((self.tcx.mark_span_for_resize(expr.span).shrink_to_lo(), "(".to_string()));
16681668
")"
16691669
} else {
16701670
""
16711671
};
16721672

16731673
let mut cast_suggestion = sugg.clone();
16741674
cast_suggestion.push((
1675-
self.tcx.adjust_span(expr.span).shrink_to_hi(),
1675+
self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(),
16761676
format!("{close_paren} as {expected_ty}"),
16771677
));
16781678
let mut into_suggestion = sugg.clone();
16791679
into_suggestion.push((
1680-
self.tcx.adjust_span(expr.span).shrink_to_hi(),
1680+
self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(),
16811681
format!("{close_paren}.into()"),
16821682
));
16831683
let mut suffix_suggestion = sugg.clone();
@@ -1734,17 +1734,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17341734
);
17351735
let suggestion = vec![
17361736
(
1737-
self.tcx.adjust_span(lhs_expr.span).shrink_to_lo(),
1737+
self.tcx.mark_span_for_resize(lhs_expr.span).shrink_to_lo(),
17381738
format!("{checked_ty}::from("),
17391739
),
1740-
(self.tcx.adjust_span(lhs_expr.span).shrink_to_hi(), ")".to_string()),
1740+
(
1741+
self.tcx.mark_span_for_resize(lhs_expr.span).shrink_to_hi(),
1742+
")".to_string(),
1743+
),
17411744
];
17421745
(msg, suggestion)
17431746
} else {
17441747
let msg = format!("{msg} and panic if the converted value doesn't fit");
17451748
let mut suggestion = sugg.clone();
17461749
suggestion.push((
1747-
self.tcx.adjust_span(expr.span).shrink_to_hi(),
1750+
self.tcx.mark_span_for_resize(expr.span).shrink_to_hi(),
17481751
format!("{close_paren}.try_into().unwrap()"),
17491752
));
17501753
(msg, suggestion)

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
496496
hir::ExprKind::MethodCall(path_segment, _, _, span) => {
497497
let ident_span = path_segment.ident.span;
498498
let ident_span = if let Some(args) = path_segment.args {
499-
self.tcx.adjust_span(ident_span).with_hi(args.span_ext.hi())
499+
self.tcx.mark_span_for_resize(ident_span).with_hi(args.span_ext.hi())
500500
} else {
501501
ident_span
502502
};
@@ -706,8 +706,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
706706
err.multipart_suggestion_verbose(
707707
"wrap these arguments in parentheses to construct a tuple",
708708
vec![
709-
(tcx.adjust_span(*lo).shrink_to_lo(), "(".to_string()),
710-
(tcx.adjust_span(*hi).shrink_to_hi(), ")".to_string()),
709+
(tcx.mark_span_for_resize(*lo).shrink_to_lo(), "(".to_string()),
710+
(tcx.mark_span_for_resize(*hi).shrink_to_hi(), ")".to_string()),
711711
],
712712
Applicability::MachineApplicable,
713713
);
@@ -1242,9 +1242,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12421242
if let Some(call_span) = full_call_span.find_ancestor_inside(error_span) {
12431243
(
12441244
"(".to_string(),
1245-
tcx.adjust_span(call_span)
1245+
tcx.mark_span_for_resize(call_span)
12461246
.shrink_to_hi()
1247-
.to(tcx.adjust_span(error_span).shrink_to_hi()),
1247+
.to(tcx.mark_span_for_resize(error_span).shrink_to_hi()),
12481248
)
12491249
} else {
12501250
(

0 commit comments

Comments
 (0)