-
Notifications
You must be signed in to change notification settings - Fork 931
Issue 2506 #2507
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
Issue 2506 #2507
Conversation
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.
Thank you for your contribution! I added some inline comments, please take a look.
src/types.rs
Outdated
@@ -616,7 +616,15 @@ impl Rewrite for ast::TraitRef { | |||
impl Rewrite for ast::Ty { | |||
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> { | |||
match self.node { | |||
ast::TyKind::TraitObject(ref bounds, ..) => bounds.rewrite(context, shape), | |||
ast::TyKind::TraitObject(ref bounds, tobj_syntax) => { | |||
let res = bounds.rewrite(context, shape)?; |
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.
Could you please add .offset_left(4)
when dyn
is used to make sure that we do not exceed max width with a long trait? For example, we need something like the following:
let shape = if tobj_syntax == ast::TraitObjectSyntax::Dyn {
// 4 = "dyn "
shape.offset_left(4)?
} else {
shape
};
And it would be nice if there is a test for this, though I cannot come up with a good example.
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 added, but it doesn't seem enough.
When trying to format this,
fn main() {
fn f3() -> Box<Very__________________________Long__________________Name____________________Trait>
{
}
}
rustfmt cause an error, error: line exceeded maximum width (maximum: 100, found: 101)
.
However, in this case,
fn main() {
fn f3() -> Box<dyn Very__________________________Long__________________Name____________________Trait>
{
}
}
rustfmt outputs
fn main() {
fn f3(
) -> Box<dyn Very__________________________Long__________________Name____________________Trait>
{
}
}
Edited:
However, just
fn f3() -> Box<dyn Very__________________________Long__________________Name____________________Trait>
{
}
cause error: line exceeded maximum width (maximum: 100, found: 101)
!
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 checked rustfmt formats
fn main() {
fn f3() -> Box<Very______________________________Long__________________Name____________________Trait>
{
}
}
into
fn main() {
fn f3(
) -> Box<Very______________________________Long__________________Name____________________Trait>
{
}
}
So, this odd formatting is not because of dyn
, but the length of trait name.
Though I'm not sure it's a bug, I think it's good to write tests after checking this is intended.
|
||
// checks if line wrap works correctly | ||
trait Very_______________________Long__________________Name____________________Trait | ||
{ |
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.
The opening bracket should not be indented, but I guess this is a seperate issue. So this is fine as is.
Thanks for your review. |
Thank you for the update and looking deeper to the underlying issue! Looks like that rustfmt cannot handle trait with a long name. That is a separate issue from #2506, so I am going to merge this PR. |
For #2506, added
dyn
check when rewriting TraitObject.I added 2 tests, but I'm not sure they're enough comprehensive.