1
Fork 0

Rollup merge of #126868 - bvanjoi:fix-126764, r=davidtwco

not use offset when there is not ends with brace

Fixes #126764
This commit is contained in:
Matthias Krüger 2024-06-25 18:02:59 +02:00 committed by GitHub
commit 52e6f9ce96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 56 additions and 5 deletions

View file

@ -211,11 +211,18 @@ fn missing_items_err(
.collect::<Vec<_>>()
.join("`, `");
// `Span` before impl block closing brace.
let hi = full_impl_span.hi() - BytePos(1);
// Point at the place right before the closing brace of the relevant `impl` to suggest
// adding the associated item at the end of its body.
let sugg_sp = full_impl_span.with_lo(hi).with_hi(hi);
let sugg_sp = if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(full_impl_span)
&& snippet.ends_with("}")
{
// `Span` before impl block closing brace.
let hi = full_impl_span.hi() - BytePos(1);
// Point at the place right before the closing brace of the relevant `impl` to suggest
// adding the associated item at the end of its body.
full_impl_span.with_lo(hi).with_hi(hi)
} else {
full_impl_span.shrink_to_hi()
};
// Obtain the level of indentation ending in `sugg_sp`.
let padding =
tcx.sess.source_map().indentation_before(sugg_sp).unwrap_or_else(|| String::new());