@@ -288,22 +288,23 @@ impl<'a> VecArgs<'a> {
288288 && is_expn_of ( fun. span , sym:: vec) . is_some ( )
289289 && let Some ( fun_def_id) = cx. qpath_res ( qpath, fun. hir_id ) . opt_def_id ( )
290290 {
291- return if cx. tcx . is_diagnostic_item ( sym:: vec_from_elem, fun_def_id) && args. len ( ) == 2 {
292- // `vec![elem; size]` case
293- Some ( VecArgs :: Repeat ( & args[ 0 ] , & args[ 1 ] ) )
294- } else if cx. tcx . is_diagnostic_item ( sym:: slice_into_vec, fun_def_id) && args. len ( ) == 1 {
295- // `vec![a, b, c]` case
296- if let ExprKind :: Call ( _, [ arg] ) = & args[ 0 ] . kind
297- && let ExprKind :: Array ( args) = arg. kind
298- {
299- Some ( VecArgs :: Vec ( args) )
300- } else {
301- None
302- }
303- } else if cx. tcx . is_diagnostic_item ( sym:: vec_new, fun_def_id) && args. is_empty ( ) {
304- Some ( VecArgs :: Vec ( & [ ] ) )
305- } else {
306- None
291+ return match ( cx. tcx . get_diagnostic_name ( fun_def_id) , args. len ( ) ) {
292+ ( Some ( sym:: vec_from_elem) , 2 ) => {
293+ // `vec![elem; size]` case
294+ Some ( VecArgs :: Repeat ( & args[ 0 ] , & args[ 1 ] ) )
295+ } ,
296+ ( Some ( sym:: slice_into_vec) , 1 ) => {
297+ // `vec![a, b, c]` case
298+ if let ExprKind :: Call ( _, [ arg] ) = & args[ 0 ] . kind
299+ && let ExprKind :: Array ( args) = arg. kind
300+ {
301+ Some ( VecArgs :: Vec ( args) )
302+ } else {
303+ None
304+ }
305+ } ,
306+ ( Some ( sym:: vec_new) , 0 ) => Some ( VecArgs :: Vec ( & [ ] ) ) ,
307+ _ => None ,
307308 } ;
308309 }
309310
0 commit comments