Skip to content

Commit

Permalink
fix the bug add unwanted code to impl (#3601) (#3602)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaser53 authored and topecongiro committed Jun 6, 2019
1 parent e0459eb commit 5607178
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/items.rs
Expand Up @@ -700,8 +700,8 @@ pub(crate) fn format_impl(
option.allow_single_line();
}

let misssing_span = mk_sp(self_ty.span.hi(), item.span.hi());
let where_span_end = context.snippet_provider.opt_span_before(misssing_span, "{");
let missing_span = mk_sp(self_ty.span.hi(), item.span.hi());
let where_span_end = context.snippet_provider.opt_span_before(missing_span, "{");
let where_clause_str = rewrite_where_clause(
context,
&generics.where_clause,
Expand Down Expand Up @@ -765,15 +765,15 @@ pub(crate) fn format_impl(
}

result.push('{');

let snippet = context.snippet(item.span);
// this is an impl body snippet(impl SampleImple { /* here */ })
let snippet = context.snippet(mk_sp(item.span.hi(), self_ty.span.hi()));
let open_pos = snippet.find_uncommented("{")? + 1;

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

visitor.visit_attrs(&item.attrs, ast::AttrStyle::Inner);
visitor.visit_impl_items(items);
Expand Down
11 changes: 11 additions & 0 deletions tests/target/issue-3601.rs
@@ -0,0 +1,11 @@
#![feature(const_generics)]

trait A {
fn foo(&self);
}

pub struct B<const N: usize>([usize; N]);

impl<const N: usize> A for B<{ N }> {
fn foo(&self) {}
}

0 comments on commit 5607178

Please sign in to comment.