Skip to content

Commit

Permalink
fix extraction of missing comments when rewriting an empty where clau…
Browse files Browse the repository at this point in the history
  • Loading branch information
scampi authored and topecongiro committed Jun 30, 2019
1 parent b6f7f24 commit 1f06a8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 =
Expand Down
5 changes: 5 additions & 0 deletions tests/source/issue-3639.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait Foo where {}
struct Bar where {}
struct Bax where;
struct Baz(String) where;
impl<> Foo<> for Bar<> where {}
5 changes: 5 additions & 0 deletions tests/target/issue-3639.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait Foo {}
struct Bar {}
struct Bax;
struct Baz(String);
impl Foo for Bar {}

0 comments on commit 1f06a8b

Please sign in to comment.