Skip to content

Commit

Permalink
Format error and typeof types (#4416)
Browse files Browse the repository at this point in the history
* Add a test for #4357

* Format error and typeof types
  • Loading branch information
topecongiro authored and calebcartwright committed Dec 20, 2020
1 parent c536d80 commit 0d022d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use rustc_span::{symbol::kw, BytePos, Pos, Span};
use crate::comment::{combine_strs_with_missing_comments, contains_comment};
use crate::config::lists::*;
use crate::config::{IndentStyle, TypeDensity, Version};
use crate::expr::{format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType};
use crate::expr::{
format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType,
};
use crate::lists::{
definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
};
Expand Down Expand Up @@ -797,7 +799,14 @@ impl Rewrite for ast::Ty {
})
}
ast::TyKind::CVarArgs => Some("...".to_owned()),
ast::TyKind::Err | ast::TyKind::Typeof(..) => unreachable!(),
ast::TyKind::Err => Some(context.snippet(self.span).to_owned()),
ast::TyKind::Typeof(ref anon_const) => rewrite_call(
context,
"typeof",
&[anon_const.value.clone()],
self.span,
shape,
),
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/source/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,9 @@ impl<T: ? const Trait> Foo<T> {
Self(t)
}
}

// #4357
type T = typeof(
1);
impl T for .. {
}
4 changes: 4 additions & 0 deletions tests/target/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,7 @@ impl<T: ?const Trait> Foo<T> {
Self(t)
}
}

// #4357
type T = typeof(1);
impl T for .. {}

0 comments on commit 0d022d0

Please sign in to comment.