Skip to content

Commit c97aa15

Browse files
authored
Merge pull request rust-lang#3555 from rchaser53/issue-3554
fix `Const generics are handled incorrectly`
2 parents 531b2d9 + 53142b4 commit c97aa15

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/items.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ pub(crate) fn format_impl(
664664
context: &RewriteContext<'_>,
665665
item: &ast::Item,
666666
offset: Indent,
667-
where_span_end: Option<BytePos>,
668667
) -> Option<String> {
669668
if let ast::ItemKind::Impl(_, _, _, ref generics, _, ref self_ty, ref items) = item.node {
670669
let mut result = String::with_capacity(128);
@@ -691,6 +690,8 @@ pub(crate) fn format_impl(
691690
option.compress_where();
692691
}
693692

693+
let misssing_span = mk_sp(self_ty.span.hi(), item.span.hi());
694+
let where_span_end = context.snippet_provider.opt_span_before(misssing_span, "{");
694695
let where_clause_str = rewrite_where_clause(
695696
context,
696697
&generics.where_clause,

src/visitor.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use syntax::source_map::{self, BytePos, Pos, SourceMap, Span};
55
use syntax::{ast, visit};
66

77
use crate::attr::*;
8-
use crate::comment::{CodeCharKind, CommentCodeSlices, FindUncommented};
8+
use crate::comment::{CodeCharKind, CommentCodeSlices};
99
use crate::config::file_lines::FileName;
1010
use crate::config::{BraceStyle, Config, Version};
1111
use crate::expr::{format_expr, ExprType};
@@ -359,13 +359,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
359359
match item.node {
360360
ast::ItemKind::Use(ref tree) => self.format_import(item, tree),
361361
ast::ItemKind::Impl(..) => {
362-
let snippet = self.snippet(item.span);
363-
let where_span_end = snippet
364-
.find_uncommented("{")
365-
.map(|x| BytePos(x as u32) + source!(self, item.span).lo());
366362
let block_indent = self.block_indent;
367-
let rw = self
368-
.with_context(|ctx| format_impl(&ctx, item, block_indent, where_span_end));
363+
let rw = self.with_context(|ctx| format_impl(&ctx, item, block_indent));
369364
self.push_rewrite(item.span, rw);
370365
}
371366
ast::ItemKind::Trait(..) => {

tests/target/issue-3554.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(const_generics)]
2+
3+
pub struct S<const N: usize>;
4+
impl S<{ 0 }> {}

0 commit comments

Comments
 (0)