Skip to content

fix the bug add unwanted code to impl (#3601) #3602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/items.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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) {}
}