Enum clippy_utils::sugg::Sugg
source · 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_macro_callsite(
cx: &LateContext<'_>,
expr: &Expr<'_>,
default: &'a str
) -> Self
pub fn hir_with_macro_callsite(
cx: &LateContext<'_>,
expr: &Expr<'_>,
default: &'a str
) -> Self
Same as hir
, but will use the pre expansion span if the expr
was in a macro.
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 then 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 Fn(Span) -> Cow<'a, str>
) -> Self
fn hir_from_snippet(
expr: &Expr<'_>,
get_snippet: impl Fn(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.
Trait Implementations§
impl<'a> StructuralPartialEq for Sugg<'a>
Auto Trait Implementations§
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§
Layout§
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: 72 bytes
Size for each variant:
NonParen
: 32 bytesMaybeParen
: 32 bytesBinOp
: 72 bytes