about summary refs log tree commit diff
diff options
context:
space:
mode:
authorStéphane Campinas <stephane.campinas@gmail.com>2019-05-17 00:23:37 +0200
committerGitHub <noreply@github.com>2019-05-17 00:23:37 +0200
commitc97aa152dac4b27e7cba692abed0fea2fcce2bd4 (patch)
tree4c29cc5714dcf763cf432b60dac3a30d657ead51
parent531b2d9136c41908a44c0e45da6fdf0635c3e680 (diff)
parent53142b486d847e2bf846fd82b02ad602bab85d41 (diff)
Merge pull request #3555 from rchaser53/issue-3554
fix `Const generics are handled incorrectly`
-rw-r--r--src/items.rs3
-rw-r--r--src/visitor.rs9
-rw-r--r--tests/target/issue-3554.rs4
3 files changed, 8 insertions, 8 deletions
diff --git a/src/items.rs b/src/items.rs
index 17e67b3f79f..202eb2cf117 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -664,7 +664,6 @@ pub(crate) fn format_impl(
     context: &RewriteContext<'_>,
     item: &ast::Item,
     offset: Indent,
-    where_span_end: Option<BytePos>,
 ) -> Option<String> {
     if let ast::ItemKind::Impl(_, _, _, ref generics, _, ref self_ty, ref items) = item.node {
         let mut result = String::with_capacity(128);
@@ -691,6 +690,8 @@ pub(crate) fn format_impl(
             option.compress_where();
         }
 
+        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 where_clause_str = rewrite_where_clause(
             context,
             &generics.where_clause,
diff --git a/src/visitor.rs b/src/visitor.rs
index f317e015423..5fdd0625dff 100644
--- a/src/visitor.rs
+++ b/src/visitor.rs
@@ -5,7 +5,7 @@ use syntax::source_map::{self, BytePos, Pos, SourceMap, Span};
 use syntax::{ast, visit};
 
 use crate::attr::*;
-use crate::comment::{CodeCharKind, CommentCodeSlices, FindUncommented};
+use crate::comment::{CodeCharKind, CommentCodeSlices};
 use crate::config::file_lines::FileName;
 use crate::config::{BraceStyle, Config, Version};
 use crate::expr::{format_expr, ExprType};
@@ -359,13 +359,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
             match item.node {
                 ast::ItemKind::Use(ref tree) => self.format_import(item, tree),
                 ast::ItemKind::Impl(..) => {
-                    let snippet = self.snippet(item.span);
-                    let where_span_end = snippet
-                        .find_uncommented("{")
-                        .map(|x| BytePos(x as u32) + source!(self, item.span).lo());
                     let block_indent = self.block_indent;
-                    let rw = self
-                        .with_context(|ctx| format_impl(&ctx, item, block_indent, where_span_end));
+                    let rw = self.with_context(|ctx| format_impl(&ctx, item, block_indent));
                     self.push_rewrite(item.span, rw);
                 }
                 ast::ItemKind::Trait(..) => {
diff --git a/tests/target/issue-3554.rs b/tests/target/issue-3554.rs
new file mode 100644
index 00000000000..4ece90403e1
--- /dev/null
+++ b/tests/target/issue-3554.rs
@@ -0,0 +1,4 @@
+#![feature(const_generics)]
+
+pub struct S<const N: usize>;
+impl S<{ 0 }> {}