Trait clippy_utils::sugg::DiagnosticExt
source · pub trait DiagnosticExt<T: LintContext> {
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 Diagnostic
.
Required Methods
sourcefn suggest_item_with_attr<D: Display + ?Sized>(
&mut self,
cx: &T,
item: Span,
msg: &str,
attr: &D,
applicability: Applicability
)
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)]");
sourcefn suggest_prepend_item(
&mut self,
cx: &T,
item: Span,
msg: &str,
new_item: &str,
applicability: Applicability
)
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();
}");
sourcefn suggest_remove_item(
&mut self,
cx: &T,
item: Span,
msg: &str,
applicability: Applicability
)
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")