Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4871d64

Browse files
authored
Use the correct BytePos for the opening brace position (rust-lang#3742)
1 parent ac150d0 commit 4871d64

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/items.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Formatting top-level items - functions, structs, enums, traits, impls.
22

33
use std::borrow::Cow;
4-
use std::cmp::{min, Ordering};
4+
use std::cmp::{max, min, Ordering};
55

66
use regex::Regex;
77
use rustc_target::spec::abi;
@@ -733,15 +733,16 @@ pub(crate) fn format_impl(
733733
}
734734

735735
result.push('{');
736-
// this is an impl body snippet(impl SampleImple { /* here */ })
737-
let snippet = context.snippet(mk_sp(item.span.hi(), self_ty.span.hi()));
736+
// this is an impl body snippet(impl SampleImpl { /* here */ })
737+
let lo = max(self_ty.span.hi(), generics.where_clause.span.hi());
738+
let snippet = context.snippet(mk_sp(lo, item.span.hi()));
738739
let open_pos = snippet.find_uncommented("{")? + 1;
739740

740741
if !items.is_empty() || contains_comment(&snippet[open_pos..]) {
741742
let mut visitor = FmtVisitor::from_context(context);
742743
let item_indent = offset.block_only().block_indent(context.config);
743744
visitor.block_indent = item_indent;
744-
visitor.last_pos = self_ty.span.hi() + BytePos(open_pos as u32);
745+
visitor.last_pos = lo + BytePos(open_pos as u32);
745746

746747
visitor.visit_attrs(&item.attrs, ast::AttrStyle::Inner);
747748
visitor.visit_impl_items(items);

tests/source/issue-3740.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
impl<T, const SIZE: usize> IntoNormalized for Vector<T, { SIZE }>
2+
where
3+
Vector<T, { SIZE }>: Div<Vector<T, { SIZE }>>,
4+
for<'a> &'a Vector<T, { SIZE }>: IntoLength<Output = T>,
5+
{
6+
type Output = Vector<T, { SIZE }>;
7+
fn into_normalized(self) -> Self::Output {
8+
9+
}
10+
}

tests/target/issue-3740.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
impl<T, const SIZE: usize> IntoNormalized for Vector<T, { SIZE }>
2+
where
3+
Vector<T, { SIZE }>: Div<Vector<T, { SIZE }>>,
4+
for<'a> &'a Vector<T, { SIZE }>: IntoLength<Output = T>,
5+
{
6+
type Output = Vector<T, { SIZE }>;
7+
fn into_normalized(self) -> Self::Output {}
8+
}

0 commit comments

Comments
 (0)