suggest adding a derive for #[default] applied to variants
This commit is contained in:
parent
8824d13161
commit
2f0ccdfbba
3 changed files with 15 additions and 9 deletions
|
@ -1499,11 +1499,17 @@ impl<'a> Resolver<'a> {
|
||||||
&& let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
|
&& let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
|
||||||
&& let Some(span) = self.opt_span(def_id)
|
&& let Some(span) = self.opt_span(def_id)
|
||||||
{
|
{
|
||||||
|
let source_map = self.session.source_map();
|
||||||
|
let head_span = source_map.guess_head_span(span);
|
||||||
|
if let Ok(head) = source_map.span_to_snippet(head_span) {
|
||||||
|
err.span_suggestion(head_span, "consider adding a derive", format!("#[derive(Default)]\n{head}"), Applicability::MaybeIncorrect);
|
||||||
|
} else {
|
||||||
err.span_help(
|
err.span_help(
|
||||||
self.session.source_map().guess_head_span(span),
|
head_span,
|
||||||
"consider adding `#[derive(Default)]` to this enum",
|
"consider adding `#[derive(Default)]` to this enum",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for ns in [Namespace::MacroNS, Namespace::TypeNS, Namespace::ValueNS] {
|
for ns in [Namespace::MacroNS, Namespace::TypeNS, Namespace::ValueNS] {
|
||||||
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
|
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
|
||||||
ident,
|
ident,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
pub enum Test { //~ HELP consider adding `#[derive(Default)]` to this enum
|
pub enum Test { //~ HELP consider adding a derive
|
||||||
#[default]
|
#[default]
|
||||||
//~^ ERROR cannot find attribute `default` in this scope
|
//~^ ERROR cannot find attribute `default` in this scope
|
||||||
First,
|
First,
|
||||||
|
|
|
@ -4,11 +4,11 @@ error: cannot find attribute `default` in this scope
|
||||||
LL | #[default]
|
LL | #[default]
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
|
||||||
help: consider adding `#[derive(Default)]` to this enum
|
help: consider adding a derive
|
||||||
--> $DIR/suggest-default-attribute.rs:1:1
|
|
|
||||||
|
LL + #[derive(Default)]
|
||||||
|
LL ~ pub enum Test {
|
||||||
|
|
|
|
||||||
LL | pub enum Test {
|
|
||||||
| ^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue