@@ -61,11 +61,13 @@ enum VecState {
6161pub struct UselessVec {
6262 too_large_for_stack : u64 ,
6363 msrv : Msrv ,
64- /// Maps from a `vec![]` source callsite invocation span to the "state" (i.e., whether we can emit a warning there or not).
64+ /// Maps from a `vec![]` source callsite invocation span to the "state" (i.e., whether we can
65+ /// emit a warning there or not).
6566 ///
66- /// The purpose of this is to buffer lints up until `check_expr_post` so that we can cancel a lint while visiting,
67- /// because a `vec![]` invocation span can appear multiple times when it is passed as a macro argument,
68- /// once in a context that doesn't require a `Vec<_>` and another time that does. Consider:
67+ /// The purpose of this is to buffer lints up until `check_expr_post` so that we can cancel a
68+ /// lint while visiting, because a `vec![]` invocation span can appear multiple times when
69+ /// it is passed as a macro argument, once in a context that doesn't require a `Vec<_>` and
70+ /// another time that does. Consider:
6971 /// ```
7072 /// macro_rules! m {
7173 /// ($v:expr) => {
@@ -75,8 +77,9 @@ pub struct UselessVec {
7577 /// }
7678 /// m!(vec![1, 2]);
7779 /// ```
78- /// The macro invocation expands to two `vec![1, 2]` invocations. If we eagerly suggest changing it to an array,
79- /// we get a false positive warning on the `$v.push(3)` which really requires `$v` to be a vector.
80+ /// The macro invocation expands to two `vec![1, 2]` invocations. If we eagerly suggest changing
81+ /// it to an array, we get a false positive warning on the `$v.push(3)` which really
82+ /// requires `$v` to be a vector.
8083 span_to_state : BTreeMap < Span , VecState > ,
8184 allow_in_test : bool ,
8285}
@@ -93,7 +96,8 @@ impl UselessVec {
9396}
9497
9598enum VecToArray {
96- /// Expression does not need to be a `Vec<_>` and its type can be changed to an array (or slice).
99+ /// Expression does not need to be a `Vec<_>` and its type can be changed to an array (or
100+ /// slice).
97101 Possible ,
98102 /// Expression must be a `Vec<_>`. Type cannot change.
99103 Impossible ,
@@ -102,7 +106,7 @@ enum VecToArray {
102106impl UselessVec {
103107 /// Checks if the surrounding environment requires this expression to actually be of type
104108 /// `Vec<_>`, or if it can be changed to `&[]`/`[]` without causing type errors.
105- fn expr_usage_requires_vec < ' tcx > ( & mut self , cx : & LateContext < ' _ > , expr : & ' tcx Expr < ' _ > ) -> VecToArray {
109+ fn expr_usage_requires_vec ( & mut self , cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> VecToArray {
106110 match cx. tcx . parent_hir_node ( expr. hir_id ) {
107111 // search for `let foo = vec![_]` expressions where all uses of `foo`
108112 // adjust to slices or call a method that exist on slices (e.g. len)
@@ -231,8 +235,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec {
231235 expr_hir_id,
232236 } = state
233237 {
234- let help_msg = format ! ( "you can use {} directly" , suggest_ty. desc( ) ) ;
235238 span_lint_hir_and_then ( cx, USELESS_VEC , expr_hir_id, span, "useless use of `vec!`" , |diag| {
239+ let help_msg = format ! ( "you can use {} directly" , suggest_ty. desc( ) ) ;
236240 // If the `vec!` macro contains comment, better not make the suggestion machine applicable as it
237241 // would remove them.
238242 let applicability = if span_contains_comment ( cx. tcx . sess . source_map ( ) , span) {
0 commit comments