expand: Mark some dead code in derive expansion as unreachable
This commit is contained in:
parent
cd2177f3de
commit
d575aa4d58
@ -407,13 +407,7 @@ impl<'a> TraitDef<'a> {
|
|||||||
_ => false,
|
_ => false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
_ => {
|
_ => unreachable!(),
|
||||||
// Non-ADT derive is an error, but it should have been
|
|
||||||
// set earlier; see
|
|
||||||
// librustc_expand/expand.rs:MacroExpander::fully_expand_fragment()
|
|
||||||
// librustc_expand/base.rs:Annotatable::derive_allowed()
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let container_id = cx.current_expansion.id.expn_data().parent;
|
let container_id = cx.current_expansion.id.expn_data().parent;
|
||||||
let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id);
|
let always_copy = has_no_type_params && cx.resolver.has_derive_copy(container_id);
|
||||||
@ -475,12 +469,7 @@ impl<'a> TraitDef<'a> {
|
|||||||
);
|
);
|
||||||
push(Annotatable::Item(P(ast::Item { attrs, ..(*newitem).clone() })))
|
push(Annotatable::Item(P(ast::Item { attrs, ..(*newitem).clone() })))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => unreachable!(),
|
||||||
// Non-Item derive is an error, but it should have been
|
|
||||||
// set earlier; see
|
|
||||||
// librustc_expand/expand.rs:MacroExpander::fully_expand_fragment()
|
|
||||||
// librustc_expand/base.rs:Annotatable::derive_allowed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,13 +98,7 @@ fn inject_impl_of_structural_trait(
|
|||||||
) {
|
) {
|
||||||
let item = match *item {
|
let item = match *item {
|
||||||
Annotatable::Item(ref item) => item,
|
Annotatable::Item(ref item) => item,
|
||||||
_ => {
|
_ => unreachable!(),
|
||||||
// Non-Item derive is an error, but it should have been
|
|
||||||
// set earlier; see
|
|
||||||
// librustc_expand/expand.rs:MacroExpander::fully_expand_fragment()
|
|
||||||
// librustc_expand/base.rs:Annotatable::derive_allowed()
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let generics = match item.kind {
|
let generics = match item.kind {
|
||||||
|
@ -767,9 +767,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||||||
InvocationKind::Derive { path, item } => match ext {
|
InvocationKind::Derive { path, item } => match ext {
|
||||||
SyntaxExtensionKind::Derive(expander)
|
SyntaxExtensionKind::Derive(expander)
|
||||||
| SyntaxExtensionKind::LegacyDerive(expander) => {
|
| SyntaxExtensionKind::LegacyDerive(expander) => {
|
||||||
if !item.derive_allowed() {
|
|
||||||
return ExpandResult::Ready(fragment_kind.dummy(span));
|
|
||||||
}
|
|
||||||
if let SyntaxExtensionKind::Derive(..) = ext {
|
if let SyntaxExtensionKind::Derive(..) = ext {
|
||||||
self.gate_proc_macro_input(&item);
|
self.gate_proc_macro_input(&item);
|
||||||
}
|
}
|
||||||
|
@ -75,38 +75,9 @@ impl MultiItemModifier for ProcMacroDerive {
|
|||||||
item: Annotatable,
|
item: Annotatable,
|
||||||
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
|
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
|
||||||
let item = match item {
|
let item = match item {
|
||||||
Annotatable::Arm(..)
|
Annotatable::Item(item) => token::NtItem(item),
|
||||||
| Annotatable::Field(..)
|
_ => unreachable!(),
|
||||||
| Annotatable::FieldPat(..)
|
|
||||||
| Annotatable::GenericParam(..)
|
|
||||||
| Annotatable::Param(..)
|
|
||||||
| Annotatable::StructField(..)
|
|
||||||
| Annotatable::Variant(..) => panic!("unexpected annotatable"),
|
|
||||||
Annotatable::Item(item) => item,
|
|
||||||
Annotatable::ImplItem(_)
|
|
||||||
| Annotatable::TraitItem(_)
|
|
||||||
| Annotatable::ForeignItem(_)
|
|
||||||
| Annotatable::Stmt(_)
|
|
||||||
| Annotatable::Expr(_) => {
|
|
||||||
ecx.span_err(
|
|
||||||
span,
|
|
||||||
"proc-macro derives may only be applied to a struct, enum, or union",
|
|
||||||
);
|
|
||||||
return ExpandResult::Ready(Vec::new());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
match item.kind {
|
|
||||||
ItemKind::Struct(..) | ItemKind::Enum(..) | ItemKind::Union(..) => {}
|
|
||||||
_ => {
|
|
||||||
ecx.span_err(
|
|
||||||
span,
|
|
||||||
"proc-macro derives may only be applied to a struct, enum, or union",
|
|
||||||
);
|
|
||||||
return ExpandResult::Ready(Vec::new());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let item = token::NtItem(item);
|
|
||||||
let input = if item.pretty_printing_compatibility_hack() {
|
let input = if item.pretty_printing_compatibility_hack() {
|
||||||
TokenTree::token(token::Interpolated(Lrc::new(item)), DUMMY_SP).into()
|
TokenTree::token(token::Interpolated(Lrc::new(item)), DUMMY_SP).into()
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user