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 u8)

🔬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