Skip to content

Commit 5607178

Browse files
rchaser53topecongiro
authored andcommitted
fix the bug add unwanted code to impl (#3601) (#3602)
1 parent e0459eb commit 5607178

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/items.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,8 @@ pub(crate) fn format_impl(
700700
option.allow_single_line();
701701
}
702702

703-
let misssing_span = mk_sp(self_ty.span.hi(), item.span.hi());
704-
let where_span_end = context.snippet_provider.opt_span_before(misssing_span, "{");
703+
let missing_span = mk_sp(self_ty.span.hi(), item.span.hi());
704+
let where_span_end = context.snippet_provider.opt_span_before(missing_span, "{");
705705
let where_clause_str = rewrite_where_clause(
706706
context,
707707
&generics.where_clause,
@@ -765,15 +765,15 @@ pub(crate) fn format_impl(
765765
}
766766

767767
result.push('{');
768-
769-
let snippet = context.snippet(item.span);
768+
// this is an impl body snippet(impl SampleImple { /* here */ })
769+
let snippet = context.snippet(mk_sp(item.span.hi(), self_ty.span.hi()));
770770
let open_pos = snippet.find_uncommented("{")? + 1;
771771

772772
if !items.is_empty() || contains_comment(&snippet[open_pos..]) {
773773
let mut visitor = FmtVisitor::from_context(context);
774774
let item_indent = offset.block_only().block_indent(context.config);
775775
visitor.block_indent = item_indent;
776-
visitor.last_pos = item.span.lo() + BytePos(open_pos as u32);
776+
visitor.last_pos = self_ty.span.hi() + BytePos(open_pos as u32);
777777

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

tests/target/issue-3601.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_generics)]
2+
3+
trait A {
4+
fn foo(&self);
5+
}
6+
7+
pub struct B<const N: usize>([usize; N]);
8+
9+
impl<const N: usize> A for B<{ N }> {
10+
fn foo(&self) {}
11+
}

0 commit comments

Comments
 (0)