-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix whitespace handling after where clause #98256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="docblock item-decl"><pre class="rust enum"><code>pub enum Cow<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a> <span class="where fmt-newline">where<br />    B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>>, </span>{ | ||
Borrowed(<a class="primitive" href="{{channel}}/std/primitive.reference.html">&'a </a>B), | ||
Whatever(<a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>), | ||
}</code></pre></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="docblock item-decl"><pre class="rust enum"><code>pub enum Cow2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + 'a> { | ||
Borrowed(<a class="primitive" href="{{channel}}/std/primitive.reference.html">&'a </a>B), | ||
Whatever(<a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>), | ||
}</code></pre></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// This test ensures there is no whitespace before the first brace of | ||
// trait, enum, struct and union items when they have a where clause. | ||
|
||
#![crate_name = "foo"] | ||
|
||
// @has 'foo/trait.ToOwned.html' | ||
// @snapshot trait - '//*[@class="docblock item-decl"]' | ||
pub trait ToOwned<T> | ||
where T: Clone | ||
{ | ||
type Owned; | ||
fn to_owned(&self) -> Self::Owned; | ||
fn whatever(&self) -> T; | ||
} | ||
|
||
// @has 'foo/trait.ToOwned2.html' | ||
// @snapshot trait2 - '//*[@class="docblock item-decl"]' | ||
// There should be a whitespace before `{` in this case! | ||
pub trait ToOwned2<T: Clone> { | ||
type Owned; | ||
fn to_owned(&self) -> Self::Owned; | ||
fn whatever(&self) -> T; | ||
} | ||
|
||
// @has 'foo/enum.Cow.html' | ||
// @snapshot enum - '//*[@class="docblock item-decl"]' | ||
pub enum Cow<'a, B: ?Sized + 'a> | ||
where | ||
B: ToOwned<Clone>, | ||
{ | ||
Borrowed(&'a B), | ||
Whatever(u32), | ||
} | ||
|
||
// @has 'foo/enum.Cow2.html' | ||
// @snapshot enum2 - '//*[@class="docblock item-decl"]' | ||
// There should be a whitespace before `{` in this case! | ||
pub enum Cow2<'a, B: ?Sized + ToOwned<Clone> + 'a> { | ||
Borrowed(&'a B), | ||
Whatever(u32), | ||
} | ||
|
||
// @has 'foo/struct.Struct.html' | ||
// @snapshot struct - '//*[@class="docblock item-decl"]' | ||
pub struct Struct<'a, B: ?Sized + 'a> | ||
where | ||
B: ToOwned<Clone>, | ||
{ | ||
pub a: &'a B, | ||
pub b: u32, | ||
} | ||
|
||
// @has 'foo/struct.Struct2.html' | ||
// @snapshot struct2 - '//*[@class="docblock item-decl"]' | ||
// There should be a whitespace before `{` in this case! | ||
pub struct Struct2<'a, B: ?Sized + ToOwned<Clone> + 'a> { | ||
pub a: &'a B, | ||
pub b: u32, | ||
} | ||
|
||
// @has 'foo/union.Union.html' | ||
// @snapshot union - '//*[@class="docblock item-decl"]' | ||
pub union Union<'a, B: ?Sized + 'a> | ||
where | ||
B: ToOwned<Clone>, | ||
{ | ||
a: &'a B, | ||
b: u32, | ||
} | ||
|
||
// @has 'foo/union.Union2.html' | ||
// @snapshot union2 - '//*[@class="docblock item-decl"]' | ||
// There should be a whitespace before `{` in this case! | ||
pub union Union2<'a, B: ?Sized + ToOwned<Clone> + 'a> { | ||
a: &'a B, | ||
b: u32, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="docblock item-decl"><pre class="rust struct"><code>pub struct Struct<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a> <span class="where fmt-newline">where<br />    B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>>, </span>{ | ||
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&'a </a>B, | ||
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>, | ||
}</code></pre></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="docblock item-decl"><pre class="rust struct"><code>pub struct Struct2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + 'a> { | ||
pub a: <a class="primitive" href="{{channel}}/std/primitive.reference.html">&'a </a>B, | ||
pub b: <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a>, | ||
}</code></pre></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="docblock item-decl"><pre class="rust trait"><code>pub trait ToOwned<T> <span class="where fmt-newline">where<br />    T: <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>, </span>{ | ||
type <a href="#associatedtype.Owned" class="associatedtype">Owned</a>; | ||
|
||
fn <a href="#tymethod.to_owned" class="fnname">to_owned</a>(&self) -> Self::<a class="associatedtype" href="trait.ToOwned.html#associatedtype.Owned" title="type foo::ToOwned::Owned">Owned</a>; | ||
<span class="item-spacer" /> fn <a href="#tymethod.whatever" class="fnname">whatever</a>(&self) -> T; | ||
}</code></pre></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="docblock item-decl"><pre class="rust trait"><code>pub trait ToOwned2<T: <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> { | ||
type <a href="#associatedtype.Owned" class="associatedtype">Owned</a>; | ||
|
||
fn <a href="#tymethod.to_owned" class="fnname">to_owned</a>(&self) -> Self::<a class="associatedtype" href="trait.ToOwned2.html#associatedtype.Owned" title="type foo::ToOwned2::Owned">Owned</a>; | ||
<span class="item-spacer" /> fn <a href="#tymethod.whatever" class="fnname">whatever</a>(&self) -> T; | ||
}</code></pre></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="docblock item-decl"><pre class="rust union"><code>pub union Union<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + 'a> <span class="where fmt-newline">where<br />    B: <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>>, </span>{ | ||
/* private fields */ | ||
}</code></pre></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="docblock item-decl"><pre class="rust union"><code>pub union Union2<'a, B: ?<a class="trait" href="{{channel}}/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="trait.ToOwned.html" title="trait foo::ToOwned">ToOwned</a><dyn <a class="trait" href="{{channel}}/core/clone/trait.Clone.html" title="trait core::clone::Clone">Clone</a>> + 'a> { | ||
/* private fields */ | ||
}</code></pre></div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to make this whitespace emitted by
print_where_clause
. Then the role ofprint_where_clause
is simple to explain and self contained. It either (a) prints a newline, a where clause, and another newline, or (b) prints a whitespace.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me give it a try then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately it cannot work for cases like:
If we handle the whitespace directly into
print_where_clause
, it'll need to be handled manually in these cases to "counter" the effect.