Enum clippy_utils::sugg::Sugg [−][src]
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
Prepare a suggestion from an expression.
Convenience function around hir_opt for suggestions with a default
text.
pub 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
Unspecifiedwill 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
pub 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.
pub 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![].
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.
Prepare a suggestion from an expression.
Convenience method to create the <lhs> && <rhs> suggestion.
Convenience method to create the <lhs> & <rhs> suggestion.
Convenience method to create the <lhs> as <rhs> suggestion.
Convenience method to create the &*<expr> suggestion. Currently this
is needed because sugg.deref().addr() produces an unnecessary set of
parentheses around the deref.
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.
Convenience method to transform suggestion into a return call
Convenience method to transform suggestion into a block where the suggestion is a trailing expression
Convenience method to create the <lhs>..<rhs> or <lhs>...<rhs>
suggestion.
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Sugg<'a>
impl<'a> UnwindSafe for Sugg<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
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: 39 bytesMaybeParen: 39 bytesBinOp: 71 bytes
