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

This commit is contained in:
rChaser53 2019-06-06 13:06:40 +09:00 committed by Seiichi Uchida
parent e0459eb3fe
commit 5607178d0a
2 changed files with 16 additions and 5 deletions

View File

@ -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,
@ -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);

View File

@ -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) {}
}