mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-02 11:44:28 +00:00
fix extraction of missing comments when rewriting an empty where clause (#3663)
This commit is contained in:
parent
b6f7f24915
commit
1f06a8b361
@ -859,7 +859,9 @@ pub(crate) fn rewrite_missing_comment(
|
|||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
let missing_snippet = context.snippet(span);
|
let missing_snippet = context.snippet(span);
|
||||||
let trimmed_snippet = missing_snippet.trim();
|
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)
|
rewrite_comment(trimmed_snippet, false, shape, context.config)
|
||||||
} else {
|
} else {
|
||||||
Some(String::new())
|
Some(String::new())
|
||||||
@ -880,7 +882,7 @@ pub(crate) fn recover_missing_comment_in_span(
|
|||||||
Some(String::new())
|
Some(String::new())
|
||||||
} else {
|
} else {
|
||||||
let missing_snippet = context.snippet(span);
|
let missing_snippet = context.snippet(span);
|
||||||
let pos = missing_snippet.find('/').unwrap_or(0);
|
let pos = missing_snippet.find('/')?;
|
||||||
// 1 = ` `
|
// 1 = ` `
|
||||||
let total_width = missing_comment.len() + used_width + 1;
|
let total_width = missing_comment.len() + used_width + 1;
|
||||||
let force_new_line_before_comment =
|
let force_new_line_before_comment =
|
||||||
|
5
tests/source/issue-3639.rs
Normal file
5
tests/source/issue-3639.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
trait Foo where {}
|
||||||
|
struct Bar where {}
|
||||||
|
struct Bax where;
|
||||||
|
struct Baz(String) where;
|
||||||
|
impl<> Foo<> for Bar<> where {}
|
5
tests/target/issue-3639.rs
Normal file
5
tests/target/issue-3639.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
trait Foo {}
|
||||||
|
struct Bar {}
|
||||||
|
struct Bax;
|
||||||
|
struct Baz(String);
|
||||||
|
impl Foo for Bar {}
|
Loading…
Reference in New Issue
Block a user