clippy_utils::sugg

Trait DiagExt

Source
pub trait DiagExt<T: LintContext> {
    // Required methods
    fn suggest_item_with_attr<D: Display + ?Sized>(
        &mut self,
        cx: &T,
        item: Span,
        msg: &str,
        attr: &D,
        applicability: Applicability,
    );
    fn suggest_prepend_item(
        &mut self,
        cx: &T,
        item: Span,
        msg: &str,
        new_item: &str,
        applicability: Applicability,
    );
    fn suggest_remove_item(
        &mut self,
        cx: &T,
        item: Span,
        msg: &str,
        applicability: Applicability,
    );
}
Expand description

Convenience extension trait for Diag.

Required Methods§

Source

fn suggest_item_with_attr<D: Display + ?Sized>( &mut self, cx: &T, item: Span, msg: &str, attr: &D, applicability: Applicability, )

Suggests to add an attribute to an item.

Correctly handles indentation of the attribute and item.

§Example
diag.suggest_item_with_attr(cx, item, "#[derive(Default)]");
Source

fn suggest_prepend_item( &mut self, cx: &T, item: Span, msg: &str, new_item: &str, applicability: Applicability, )

Suggest to add an item before another.

The item should not be indented (except for inner indentation).

§Example
diag.suggest_prepend_item(cx, item,
"fn foo() {
    bar();
}");
Source

fn suggest_remove_item( &mut self, cx: &T, item: Span, msg: &str, applicability: Applicability, )

Suggest to completely remove an item.

This will remove an item and all following whitespace until the next non-whitespace character. This should work correctly if item is on the same indentation level as the following item.

§Example
diag.suggest_remove_item(cx, item, "remove this")

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: LintContext> DiagExt<T> for Diag<'_, ()>

Source§

fn suggest_item_with_attr<D: Display + ?Sized>( &mut self, cx: &T, item: Span, msg: &str, attr: &D, applicability: Applicability, )

Source§

fn suggest_prepend_item( &mut self, cx: &T, item: Span, msg: &str, new_item: &str, applicability: Applicability, )

Source§

fn suggest_remove_item( &mut self, cx: &T, item: Span, msg: &str, applicability: Applicability, )

Implementors§