Use sugg::Sugg in transmute links

This commit is contained in:
mcarton
2016-07-04 02:22:57 +02:00
parent 9b79b1022c
commit c5e91e70d0
3 changed files with 24 additions and 11 deletions

View File

@@ -30,6 +30,7 @@ impl<'a> std::fmt::Display for Sugg<'a> {
}
}
#[allow(wrong_self_convention)] // ok, because of the function `as_ty` method
impl<'a> Sugg<'a> {
pub fn hir_opt(cx: &LateContext, expr: &hir::Expr) -> Option<Sugg<'a>> {
snippet_opt(cx, expr.span).map(|snippet| {
@@ -124,6 +125,11 @@ impl<'a> Sugg<'a> {
make_binop(ast::BinOpKind::And, &self, &rhs)
}
/// Convenience method to create the `<lhs> as <rhs>` suggestion.
pub fn as_ty(self, rhs: &str) -> Sugg<'static> {
make_assoc(AssocOp::As, &self, &Sugg::NonParen(rhs.into()))
}
/// Convenience method to create the `&<expr>` suggestion.
pub fn addr(self) -> Sugg<'static> {
make_unop("&", self)