fix extraction of missing comments when rewriting an empty where clause (#3663)

This commit is contained in:
Stéphane Campinas 2019-06-30 05:19:24 +02:00 committed by Seiichi Uchida
parent b6f7f24915
commit 1f06a8b361
3 changed files with 14 additions and 2 deletions

View file

@ -859,7 +859,9 @@ pub(crate) fn rewrite_missing_comment(
) -> Option<String> {
let missing_snippet = context.snippet(span);
let trimmed_snippet = missing_snippet.trim();
if !trimmed_snippet.is_empty() {
// check the span starts with a comment
let pos = trimmed_snippet.find('/');
if !trimmed_snippet.is_empty() && pos.is_some() {
rewrite_comment(trimmed_snippet, false, shape, context.config)
} else {
Some(String::new())
@ -880,7 +882,7 @@ pub(crate) fn recover_missing_comment_in_span(
Some(String::new())
} else {
let missing_snippet = context.snippet(span);
let pos = missing_snippet.find('/').unwrap_or(0);
let pos = missing_snippet.find('/')?;
// 1 = ` `
let total_width = missing_comment.len() + used_width + 1;
let force_new_line_before_comment =

View file

@ -0,0 +1,5 @@
trait Foo where {}
struct Bar where {}
struct Bax where;
struct Baz(String) where;
impl<> Foo<> for Bar<> where {}

View file

@ -0,0 +1,5 @@
trait Foo {}
struct Bar {}
struct Bax;
struct Baz(String);
impl Foo for Bar {}