Deduplicate some matches that always panic in one arm
This commit is contained in:
parent
c0b532277b
commit
da182b6d95
4 changed files with 24 additions and 17 deletions
|
@ -1757,6 +1757,24 @@ impl AttrArgsEq {
|
|||
AttrArgsEq::Hir(lit) => lit.span,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unwrap_ast(&self) -> &Expr {
|
||||
match self {
|
||||
AttrArgsEq::Ast(p) => p,
|
||||
AttrArgsEq::Hir(lit) => {
|
||||
unreachable!("in literal form when getting inner tokens: {lit:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unwrap_ast_mut(&mut self) -> &mut P<Expr> {
|
||||
match self {
|
||||
AttrArgsEq::Ast(p) => p,
|
||||
AttrArgsEq::Hir(lit) => {
|
||||
unreachable!("in literal form when getting inner tokens: {lit:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AttrArgs {
|
||||
|
@ -1774,10 +1792,7 @@ impl AttrArgs {
|
|||
match self {
|
||||
AttrArgs::Empty => TokenStream::default(),
|
||||
AttrArgs::Delimited(args) => args.tokens.clone(),
|
||||
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => TokenStream::from_ast(expr),
|
||||
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
|
||||
unreachable!("in literal form when getting inner tokens: {:?}", lit)
|
||||
}
|
||||
AttrArgs::Eq { value, .. } => TokenStream::from_ast(value.unwrap_ast()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -451,13 +451,10 @@ fn visit_attr_args<T: MutVisitor>(vis: &mut T, args: &mut AttrArgs) {
|
|||
match args {
|
||||
AttrArgs::Empty => {}
|
||||
AttrArgs::Delimited(args) => visit_delim_args(vis, args),
|
||||
AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(expr) } => {
|
||||
vis.visit_expr(expr);
|
||||
AttrArgs::Eq { eq_span, value } => {
|
||||
vis.visit_expr(value.unwrap_ast_mut());
|
||||
vis.visit_span(eq_span);
|
||||
}
|
||||
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
|
||||
unreachable!("in literal form when visiting mac args eq: {:?}", lit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1273,10 +1273,7 @@ pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -
|
|||
match args {
|
||||
AttrArgs::Empty => {}
|
||||
AttrArgs::Delimited(_args) => {}
|
||||
AttrArgs::Eq { value: AttrArgsEq::Ast(expr), .. } => try_visit!(visitor.visit_expr(expr)),
|
||||
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
|
||||
unreachable!("in literal form when walking mac args eq: {:?}", lit)
|
||||
}
|
||||
AttrArgs::Eq { value, .. } => try_visit!(visitor.visit_expr(value.unwrap_ast())),
|
||||
}
|
||||
V::Result::output()
|
||||
}
|
||||
|
|
|
@ -889,7 +889,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
// This is an inert key-value attribute - it will never be visible to macros
|
||||
// after it gets lowered to HIR. Therefore, we can extract literals to handle
|
||||
// nonterminals in `#[doc]` (e.g. `#[doc = $e]`).
|
||||
&AttrArgs::Eq { eq_span, value: AttrArgsEq::Ast(ref expr) } => {
|
||||
&AttrArgs::Eq { eq_span, ref value } => {
|
||||
let expr = value.unwrap_ast();
|
||||
// In valid code the value always ends up as a single literal. Otherwise, a dummy
|
||||
// literal suffices because the error is handled elsewhere.
|
||||
let lit = if let ExprKind::Lit(token_lit) = expr.kind
|
||||
|
@ -907,9 +908,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
};
|
||||
AttrArgs::Eq { eq_span, value: AttrArgsEq::Hir(lit) }
|
||||
}
|
||||
AttrArgs::Eq { value: AttrArgsEq::Hir(lit), .. } => {
|
||||
unreachable!("in literal form when lowering mac args eq: {:?}", lit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue