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>

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

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<'_>

§

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<'_>

§

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<'_>

§

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<'_>

§

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<'_>

§

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>

§

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

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

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

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

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

§

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<'_>

§

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<'_>

§

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<'_>

§

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> DynSend for Sugg<'a>

§

impl<'a> DynSync for Sugg<'a>

§

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> Aligned for T

source§

const ALIGN: Alignment = _

Alignment of Self.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

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, R> CollectAndApply<T, R> for T

source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

§

impl<T> Filterable for T

§

fn filterable( self, filter_name: &'static str ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<P> IntoQueryParam<P> for P

source§

impl<T> MaybeResult<T> for T

§

type Error = !

source§

fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

source§

fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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<'tcx, T> ToPredicate<'tcx, T> for T

source§

fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T

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

§

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

§

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<Tcx, T> Value<Tcx> for T
where Tcx: DepContext,

source§

default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed ) -> T

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

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: 24 bytes
  • MaybeParen: 24 bytes
  • BinOp: 56 bytes