suggest #[derive(Default)]
to enums with #[default]
This commit is contained in:
parent
2557603f32
commit
eb80407d79
@ -1495,6 +1495,15 @@ impl<'a> Resolver<'a> {
|
|||||||
err.help("have you added the `#[macro_use]` on the module/import?");
|
err.help("have you added the `#[macro_use]` on the module/import?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ident.name == kw::Default
|
||||||
|
&& let ModuleKind::Def(DefKind::Enum, def_id, _) = parent_scope.module.kind
|
||||||
|
&& let Some(span) = self.opt_span(def_id)
|
||||||
|
{
|
||||||
|
err.span_help(
|
||||||
|
self.session.source_map().guess_head_span(span),
|
||||||
|
"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,
|
||||||
|
8
src/test/ui/enum/suggest-default-attribute.rs
Normal file
8
src/test/ui/enum/suggest-default-attribute.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
pub enum Test { //~ HELP consider adding `#[derive(Default)]` to this enum
|
||||||
|
#[default]
|
||||||
|
//~^ ERROR cannot find attribute `default` in this scope
|
||||||
|
First,
|
||||||
|
Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
14
src/test/ui/enum/suggest-default-attribute.stderr
Normal file
14
src/test/ui/enum/suggest-default-attribute.stderr
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
error: cannot find attribute `default` in this scope
|
||||||
|
--> $DIR/suggest-default-attribute.rs:2:7
|
||||||
|
|
|
||||||
|
LL | #[default]
|
||||||
|
| ^^^^^^^
|
||||||
|
|
|
||||||
|
help: consider adding `#[derive(Default)]` to this enum
|
||||||
|
--> $DIR/suggest-default-attribute.rs:1:1
|
||||||
|
|
|
||||||
|
LL | pub enum Test {
|
||||||
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user