From 4871d6467a4babe8968c1e72c0551adfb1c9d5c5 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Tue, 13 Aug 2019 23:21:55 +0900 Subject: [PATCH] Use the correct BytePos for the opening brace position (#3742) --- src/items.rs | 9 +++++---- tests/source/issue-3740.rs | 10 ++++++++++ tests/target/issue-3740.rs | 8 ++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/source/issue-3740.rs create mode 100644 tests/target/issue-3740.rs diff --git a/src/items.rs b/src/items.rs index 73b752dfe78..022fe4295a1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -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); diff --git a/tests/source/issue-3740.rs b/tests/source/issue-3740.rs new file mode 100644 index 00000000000..2769a8cc9b1 --- /dev/null +++ b/tests/source/issue-3740.rs @@ -0,0 +1,10 @@ +impl IntoNormalized for Vector + where + Vector: Div>, + for<'a> &'a Vector: IntoLength, +{ + type Output = Vector; + fn into_normalized(self) -> Self::Output { + + } +} diff --git a/tests/target/issue-3740.rs b/tests/target/issue-3740.rs new file mode 100644 index 00000000000..995a6bee352 --- /dev/null +++ b/tests/target/issue-3740.rs @@ -0,0 +1,8 @@ +impl IntoNormalized for Vector +where + Vector: Div>, + for<'a> &'a Vector: IntoLength, +{ + type Output = Vector; + fn into_normalized(self) -> Self::Output {} +}