@@ -8,7 +8,7 @@ use clippy_utils::msrvs::{self, Msrv};
8
8
use clippy_utils:: source:: SpanRangeExt ;
9
9
use clippy_utils:: ty:: is_copy;
10
10
use clippy_utils:: visitors:: for_each_local_use_after_expr;
11
- use clippy_utils:: { get_parent_expr, higher, is_in_test, is_trait_method} ;
11
+ use clippy_utils:: { get_parent_expr, higher, is_in_test, is_trait_method, span_contains_comment } ;
12
12
use rustc_errors:: Applicability ;
13
13
use rustc_hir:: { BorrowKind , Expr , ExprKind , HirId , LetStmt , Mutability , Node , Pat , PatKind } ;
14
14
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -132,9 +132,19 @@ impl<'tcx> LateLintPass<'tcx> for UselessVec {
132
132
fn check_crate_post ( & mut self , cx : & LateContext < ' tcx > ) {
133
133
for ( span, lint_opt) in & self . span_to_lint_map {
134
134
if let Some ( ( hir_id, suggest_slice, snippet, applicability) ) = lint_opt {
135
- let help_msg = format ! ( "you can use {} directly" , suggest_slice. desc( ) , ) ;
135
+ let help_msg = format ! ( "you can use {} directly" , suggest_slice. desc( ) ) ;
136
136
span_lint_hir_and_then ( cx, USELESS_VEC , * hir_id, * span, "useless use of `vec!`" , |diag| {
137
- diag. span_suggestion ( * span, help_msg, snippet, * applicability) ;
137
+ // If the `vec!` macro contains comment, better not make the suggestion machine
138
+ // applicable as it would remove them.
139
+ let applicability = if * applicability != Applicability :: Unspecified
140
+ && let source_map = cx. tcx . sess . source_map ( )
141
+ && span_contains_comment ( source_map, * span)
142
+ {
143
+ Applicability :: Unspecified
144
+ } else {
145
+ * applicability
146
+ } ;
147
+ diag. span_suggestion ( * span, help_msg, snippet, applicability) ;
138
148
} ) ;
139
149
}
140
150
}
0 commit comments