resolve: Introduce a separate NonMacroAttrKind
for legacy derive helpers
This commit is contained in:
parent
e7ee4d66ce
commit
69894ce9ac
3 changed files with 21 additions and 20 deletions
|
@ -39,6 +39,9 @@ pub enum NonMacroAttrKind {
|
||||||
Tool,
|
Tool,
|
||||||
/// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`).
|
/// Single-segment custom attribute registered by a derive macro (`#[serde(default)]`).
|
||||||
DeriveHelper,
|
DeriveHelper,
|
||||||
|
/// Single-segment custom attribute registered by a derive macro
|
||||||
|
/// but used before that derive macro was expanded (deprecated).
|
||||||
|
DeriveHelperCompat,
|
||||||
/// Single-segment custom attribute registered with `#[register_attr]`.
|
/// Single-segment custom attribute registered with `#[register_attr]`.
|
||||||
Registered,
|
Registered,
|
||||||
}
|
}
|
||||||
|
@ -370,7 +373,9 @@ impl NonMacroAttrKind {
|
||||||
match self {
|
match self {
|
||||||
NonMacroAttrKind::Builtin => "built-in attribute",
|
NonMacroAttrKind::Builtin => "built-in attribute",
|
||||||
NonMacroAttrKind::Tool => "tool attribute",
|
NonMacroAttrKind::Tool => "tool attribute",
|
||||||
NonMacroAttrKind::DeriveHelper => "derive helper attribute",
|
NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => {
|
||||||
|
"derive helper attribute"
|
||||||
|
}
|
||||||
NonMacroAttrKind::Registered => "explicitly registered attribute",
|
NonMacroAttrKind::Registered => "explicitly registered attribute",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -385,7 +390,9 @@ impl NonMacroAttrKind {
|
||||||
/// Users of some attributes cannot mark them as used, so they are considered always used.
|
/// Users of some attributes cannot mark them as used, so they are considered always used.
|
||||||
pub fn is_used(self) -> bool {
|
pub fn is_used(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
NonMacroAttrKind::Tool | NonMacroAttrKind::DeriveHelper => true,
|
NonMacroAttrKind::Tool
|
||||||
|
| NonMacroAttrKind::DeriveHelper
|
||||||
|
| NonMacroAttrKind::DeriveHelperCompat => true,
|
||||||
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered => false,
|
NonMacroAttrKind::Builtin | NonMacroAttrKind::Registered => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -609,7 +609,7 @@ impl<'a> Resolver<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Scope::DeriveHelpersCompat => {
|
Scope::DeriveHelpersCompat => {
|
||||||
let res = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper);
|
let res = Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat);
|
||||||
if filter_fn(res) {
|
if filter_fn(res) {
|
||||||
for derive in parent_scope.derives {
|
for derive in parent_scope.derives {
|
||||||
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
|
let parent_scope = &ParentScope { derives: &[], ..*parent_scope };
|
||||||
|
|
|
@ -568,10 +568,9 @@ impl<'a> Resolver<'a> {
|
||||||
struct Flags: u8 {
|
struct Flags: u8 {
|
||||||
const MACRO_RULES = 1 << 0;
|
const MACRO_RULES = 1 << 0;
|
||||||
const MODULE = 1 << 1;
|
const MODULE = 1 << 1;
|
||||||
const DERIVE_HELPER_COMPAT = 1 << 2;
|
const MISC_SUGGEST_CRATE = 1 << 2;
|
||||||
const MISC_SUGGEST_CRATE = 1 << 3;
|
const MISC_SUGGEST_SELF = 1 << 3;
|
||||||
const MISC_SUGGEST_SELF = 1 << 4;
|
const MISC_FROM_PRELUDE = 1 << 4;
|
||||||
const MISC_FROM_PRELUDE = 1 << 5;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -646,14 +645,11 @@ impl<'a> Resolver<'a> {
|
||||||
) {
|
) {
|
||||||
Ok((Some(ext), _)) => {
|
Ok((Some(ext), _)) => {
|
||||||
if ext.helper_attrs.contains(&ident.name) {
|
if ext.helper_attrs.contains(&ident.name) {
|
||||||
let binding = (
|
result = ok(
|
||||||
Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper),
|
Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat),
|
||||||
ty::Visibility::Public,
|
|
||||||
derive.span,
|
derive.span,
|
||||||
ExpnId::root(),
|
this.arenas,
|
||||||
)
|
);
|
||||||
.to_name_binding(this.arenas);
|
|
||||||
result = Ok((binding, Flags::DERIVE_HELPER_COMPAT));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -799,17 +795,15 @@ impl<'a> Resolver<'a> {
|
||||||
let (res, innermost_res) = (binding.res(), innermost_binding.res());
|
let (res, innermost_res) = (binding.res(), innermost_binding.res());
|
||||||
if res != innermost_res {
|
if res != innermost_res {
|
||||||
let builtin = Res::NonMacroAttr(NonMacroAttrKind::Builtin);
|
let builtin = Res::NonMacroAttr(NonMacroAttrKind::Builtin);
|
||||||
let is_derive_helper_compat = |res, flags: Flags| {
|
let derive_helper_compat =
|
||||||
res == Res::NonMacroAttr(NonMacroAttrKind::DeriveHelper)
|
Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat);
|
||||||
&& flags.contains(Flags::DERIVE_HELPER_COMPAT)
|
|
||||||
};
|
|
||||||
|
|
||||||
let ambiguity_error_kind = if is_import {
|
let ambiguity_error_kind = if is_import {
|
||||||
Some(AmbiguityKind::Import)
|
Some(AmbiguityKind::Import)
|
||||||
} else if innermost_res == builtin || res == builtin {
|
} else if innermost_res == builtin || res == builtin {
|
||||||
Some(AmbiguityKind::BuiltinAttr)
|
Some(AmbiguityKind::BuiltinAttr)
|
||||||
} else if is_derive_helper_compat(innermost_res, innermost_flags)
|
} else if innermost_res == derive_helper_compat
|
||||||
|| is_derive_helper_compat(res, flags)
|
|| res == derive_helper_compat
|
||||||
{
|
{
|
||||||
Some(AmbiguityKind::DeriveHelper)
|
Some(AmbiguityKind::DeriveHelper)
|
||||||
} else if innermost_flags.contains(Flags::MACRO_RULES)
|
} else if innermost_flags.contains(Flags::MACRO_RULES)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue