Merge pull request #3126 from topecongiro/issue-3117

Use correct width when formatting type on local statement
This commit is contained in:
Nick Cameron
2018-10-23 10:35:32 +13:00
committed by GitHub
3 changed files with 54 additions and 4 deletions
+10 -4
View File
@@ -94,10 +94,16 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
if let Some(ref ty) = self.ty {
let separator = type_annotation_separator(context.config);
let indent = shape.indent + last_line_width(&result) + separator.len();
// 1 = ;
let budget = shape.width.checked_sub(indent.width() + 1)?;
let rewrite = ty.rewrite(context, Shape::legacy(budget, indent))?;
let ty_shape = if pat_str.contains('\n') {
shape.with_max_width(context.config)
} else {
shape
}
.offset_left(last_line_width(&result) + separator.len())?
// 2 = ` =`
.sub_width(2)?;
let rewrite = ty.rewrite(context, ty_shape)?;
infix.push_str(separator);
infix.push_str(&rewrite);
+22
View File
@@ -91,3 +91,25 @@ macro_rules! foo {
}
type Target = ( FooAPI ) + 'static;
// #3117
fn issue3117() {
{
{
{
{
{
{
{
{
let opt: &mut Option<MyLongTypeHere> =
unsafe { &mut *self.future.get() };
}
}
}
}
}
}
}
}
}
+22
View File
@@ -90,3 +90,25 @@ macro_rules! foo {
}
type Target = (FooAPI) + 'static;
// #3117
fn issue3117() {
{
{
{
{
{
{
{
{
let opt: &mut Option<MyLongTypeHere> =
unsafe { &mut *self.future.get() };
}
}
}
}
}
}
}
}
}