Skip to content

Commit

Permalink
Use the correct BytePos for the opening brace position (rust-lang#3742)
Browse files Browse the repository at this point in the history
  • Loading branch information
topecongiro authored Aug 13, 2019
1 parent ac150d0 commit 4871d64
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/items.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Formatting top-level items - functions, structs, enums, traits, impls.

use std::borrow::Cow;
use std::cmp::{min, Ordering};
use std::cmp::{max, min, Ordering};

use regex::Regex;
use rustc_target::spec::abi;
Expand Down Expand Up @@ -733,15 +733,16 @@ pub(crate) fn format_impl(
}

result.push('{');
// this is an impl body snippet(impl SampleImple { /* here */ })
let snippet = context.snippet(mk_sp(item.span.hi(), self_ty.span.hi()));
// this is an impl body snippet(impl SampleImpl { /* here */ })
let lo = max(self_ty.span.hi(), generics.where_clause.span.hi());
let snippet = context.snippet(mk_sp(lo, item.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 = self_ty.span.hi() + BytePos(open_pos as u32);
visitor.last_pos = lo + BytePos(open_pos as u32);

visitor.visit_attrs(&item.attrs, ast::AttrStyle::Inner);
visitor.visit_impl_items(items);
Expand Down
10 changes: 10 additions & 0 deletions tests/source/issue-3740.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
impl<T, const SIZE: usize> IntoNormalized for Vector<T, { SIZE }>
where
Vector<T, { SIZE }>: Div<Vector<T, { SIZE }>>,
for<'a> &'a Vector<T, { SIZE }>: IntoLength<Output = T>,
{
type Output = Vector<T, { SIZE }>;
fn into_normalized(self) -> Self::Output {

}
}
8 changes: 8 additions & 0 deletions tests/target/issue-3740.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
impl<T, const SIZE: usize> IntoNormalized for Vector<T, { SIZE }>
where
Vector<T, { SIZE }>: Div<Vector<T, { SIZE }>>,
for<'a> &'a Vector<T, { SIZE }>: IntoLength<Output = T>,
{
type Output = Vector<T, { SIZE }>;
fn into_normalized(self) -> Self::Output {}
}

0 comments on commit 4871d64

Please # to comment.