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.

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 to HasPlaceholders

Same as hir, but will use the pre expansion span if the expr was in a macro.

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.

Convenience method to create the &mut <expr> suggestion.

Convenience method to create the *<expr> 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.

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()).

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after applying the - operator.

Performs the unary - operation. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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 bytes
  • MaybeParen: 39 bytes
  • BinOp: 71 bytes