Use the correct BytePos for the opening brace position (#3742)

This commit is contained in:
Seiichi Uchida 2019-08-13 23:21:55 +09:00 committed by GitHub
parent ac150d016b
commit 4871d6467a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View file

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

View file

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

View file

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