pub enum Sugg<'a> {
NonParen(Cow<'a, str>),
MaybeParen(Cow<'a, str>),
BinOp(AssocOp, Cow<'a, str>, Cow<'a, str>),
}
Expand description
A helper type to build suggestion correctly handling parentheses.
Variants§
NonParen(Cow<'a, str>)
An expression that never needs parentheses such as 1337
or [0; 42]
.
MaybeParen(Cow<'a, str>)
An expression that does not fit in other variants.
BinOp(AssocOp, Cow<'a, str>, Cow<'a, str>)
A binary operator expression, including as
-casts and explicit type
coercion.
Implementations§
Source§impl<'a> Sugg<'a>
impl<'a> Sugg<'a>
Sourcepub fn hir_opt(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Self>
pub fn hir_opt(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Self>
Prepare a suggestion from an expression.
Sourcepub fn hir(cx: &LateContext<'_>, expr: &Expr<'_>, default: &'a str) -> Self
pub fn hir(cx: &LateContext<'_>, expr: &Expr<'_>, default: &'a str) -> Self
Convenience function around hir_opt
for suggestions with a default
text.
Sourcepub fn hir_with_applicability(
cx: &LateContext<'_>,
expr: &Expr<'_>,
default: &'a str,
applicability: &mut Applicability,
) -> Self
pub fn hir_with_applicability( cx: &LateContext<'_>, expr: &Expr<'_>, default: &'a str, applicability: &mut Applicability, ) -> Self
Same as hir
, but it adapts the applicability level by following rules:
- Applicability level
Unspecified
will never be changed. - If the span is inside a macro, change the applicability level to
MaybeIncorrect
. - If the default value is used and the applicability level is
MachineApplicable
, change it toHasPlaceholders
Sourcepub fn hir_with_context(
cx: &LateContext<'_>,
expr: &Expr<'_>,
ctxt: SyntaxContext,
default: &'a str,
applicability: &mut Applicability,
) -> Self
pub fn hir_with_context( cx: &LateContext<'_>, expr: &Expr<'_>, ctxt: SyntaxContext, default: &'a str, applicability: &mut Applicability, ) -> Self
Same as hir
, but first walks the span up to the given context. This will result in the
macro call, rather than the expansion, if the span is from a child context. If the span is
not from a child context, it will be used directly instead.
e.g. Given the expression &vec![]
, getting a snippet from the span for vec![]
as a HIR
node would result in box []
. If given the context of the address of expression, this
function will correctly get a snippet of vec![]
.
Sourcefn hir_from_snippet(
expr: &Expr<'_>,
get_snippet: impl FnMut(Span) -> Cow<'a, str>,
) -> Self
fn hir_from_snippet( expr: &Expr<'_>, get_snippet: impl FnMut(Span) -> Cow<'a, str>, ) -> Self
Generate a suggestion for an expression with the given snippet. This is used by the hir_*
function variants of Sugg
, since these use different snippet functions.
Sourcepub fn ast(
cx: &EarlyContext<'_>,
expr: &Expr,
default: &'a str,
ctxt: SyntaxContext,
app: &mut Applicability,
) -> Self
pub fn ast( cx: &EarlyContext<'_>, expr: &Expr, default: &'a str, ctxt: SyntaxContext, app: &mut Applicability, ) -> Self
Prepare a suggestion from an expression.
Sourcepub fn and(self, rhs: &Self) -> Sugg<'static>
pub fn and(self, rhs: &Self) -> Sugg<'static>
Convenience method to create the <lhs> && <rhs>
suggestion.
Sourcepub fn bit_and(self, rhs: &Self) -> Sugg<'static>
pub fn bit_and(self, rhs: &Self) -> Sugg<'static>
Convenience method to create the <lhs> & <rhs>
suggestion.
Sourcepub fn as_ty<R: Display>(self, rhs: R) -> Sugg<'static>
pub fn as_ty<R: Display>(self, rhs: R) -> Sugg<'static>
Convenience method to create the <lhs> as <rhs>
suggestion.
Sourcepub fn mut_addr(self) -> Sugg<'static>
pub fn mut_addr(self) -> Sugg<'static>
Convenience method to create the &mut <expr>
suggestion.
Sourcepub fn addr_deref(self) -> Sugg<'static>
pub fn addr_deref(self) -> Sugg<'static>
Convenience method to create the &*<expr>
suggestion. Currently this
is needed because sugg.deref().addr()
produces an unnecessary set of
parentheses around the deref.
Sourcepub fn mut_addr_deref(self) -> Sugg<'static>
pub fn mut_addr_deref(self) -> Sugg<'static>
Convenience method to create the &mut *<expr>
suggestion. Currently
this is needed because sugg.deref().mut_addr()
produces an unnecessary
set of parentheses around the deref.
Sourcepub fn make_return(self) -> Sugg<'static>
pub fn make_return(self) -> Sugg<'static>
Convenience method to transform suggestion into a return call
Sourcepub fn blockify(self) -> Sugg<'static>
pub fn blockify(self) -> Sugg<'static>
Convenience method to transform suggestion into a block where the suggestion is a trailing expression
Sourcepub fn asyncify(self) -> Sugg<'static>
pub fn asyncify(self) -> Sugg<'static>
Convenience method to prefix the expression with the async
keyword.
Can be used after blockify
to create an async block.
Sourcepub fn range(self, end: &Self, limit: RangeLimits) -> Sugg<'static>
pub fn range(self, end: &Self, limit: RangeLimits) -> Sugg<'static>
Convenience method to create the <lhs>..<rhs>
or <lhs>...<rhs>
suggestion.
Sourcepub fn maybe_par(self) -> Self
pub fn maybe_par(self) -> Self
Adds parentheses to any expression that might need them. Suitable to the
self
argument of a method call
(e.g., to build bar.foo()
or (1 + 2).foo()
).
pub fn into_string(self) -> String
Trait Implementations§
impl<'a> StructuralPartialEq for Sugg<'a>
Auto Trait Implementations§
impl<'a> Freeze for Sugg<'a>
impl<'a> RefUnwindSafe for Sugg<'a>
impl<'a> Send for Sugg<'a>
impl<'a> Sync for Sugg<'a>
impl<'a> Unpin for Sugg<'a>
impl<'a> UnwindSafe for Sugg<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 56 bytes
Size for each variant:
NonParen
: 32 bytesMaybeParen
: 32 bytesBinOp
: 56 bytes