clippy_utils::sugg

Enum 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>

source

pub fn hir_opt(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Self>

Prepare a suggestion from an expression.

source

pub fn hir(cx: &LateContext<'_>, expr: &Expr<'_>, default: &'a str) -> Self

Convenience function around hir_opt for suggestions with a default text.

source

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

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![].

source

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.

source

pub fn ast( cx: &EarlyContext<'_>, expr: &Expr, default: &'a str, ctxt: SyntaxContext, app: &mut Applicability, ) -> Self

Prepare a suggestion from an expression.

source

pub fn and(self, rhs: &Self) -> Sugg<'static>

Convenience method to create the <lhs> && <rhs> suggestion.

source

pub fn bit_and(self, rhs: &Self) -> Sugg<'static>

Convenience method to create the <lhs> & <rhs> suggestion.

source

pub fn as_ty<R: Display>(self, rhs: R) -> Sugg<'static>

Convenience method to create the <lhs> as <rhs> suggestion.

source

pub fn addr(self) -> Sugg<'static>

Convenience method to create the &<expr> suggestion.

source

pub fn mut_addr(self) -> Sugg<'static>

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

source

pub fn deref(self) -> Sugg<'static>

Convenience method to create the *<expr> suggestion.

source

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.

source

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.

source

pub fn make_return(self) -> Sugg<'static>

Convenience method to transform suggestion into a return call

source

pub fn blockify(self) -> Sugg<'static>

Convenience method to transform suggestion into a block where the suggestion is a trailing expression

source

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.

source

pub fn range(self, end: &Self, limit: RangeLimits) -> Sugg<'static>

Convenience method to create the <lhs>..<rhs> or <lhs>...<rhs> suggestion.

source

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

source

pub fn into_string(self) -> String

Trait Implementations§

source§

impl Add<&Sugg<'_>> for Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the + operator.
source§

fn add(self, other: &Sugg<'_>) -> Sugg<'static>

Performs the + operation. Read more
source§

impl Add<Sugg<'_>> for &Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the + operator.
source§

fn add(self, other: Sugg<'_>) -> Sugg<'static>

Performs the + operation. Read more
source§

impl Add for &Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &Sugg<'_>) -> Sugg<'static>

Performs the + operation. Read more
source§

impl Add for Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the + operator.
source§

fn add(self, other: Sugg<'_>) -> Sugg<'static>

Performs the + operation. Read more
source§

impl<'a> Clone for Sugg<'a>

source§

fn clone(&self) -> Sugg<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Sugg<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Sugg<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Neg for Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the - operator.
source§

fn neg(self) -> Sugg<'static>

Performs the unary - operation. Read more
source§

impl<'a> Not for Sugg<'a>

source§

type Output = Sugg<'a>

The resulting type after applying the ! operator.
source§

fn not(self) -> Sugg<'a>

Performs the unary ! operation. Read more
source§

impl<'a> PartialEq for Sugg<'a>

source§

fn eq(&self, other: &Sugg<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Sub<&Sugg<'_>> for Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Sugg<'_>) -> Sugg<'static>

Performs the - operation. Read more
source§

impl Sub<Sugg<'_>> for &Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the - operator.
source§

fn sub(self, other: Sugg<'_>) -> Sugg<'static>

Performs the - operation. Read more
source§

impl Sub for &Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &Sugg<'_>) -> Sugg<'static>

Performs the - operation. Read more
source§

impl Sub for Sugg<'_>

source§

type Output = Sugg<'static>

The resulting type after applying the - operator.
source§

fn sub(self, other: Sugg<'_>) -> Sugg<'static>

Performs the - operation. Read more
source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::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: 56 bytes

Size for each variant:

  • NonParen: 32 bytes
  • MaybeParen: 32 bytes
  • BinOp: 56 bytes