@@ -91,15 +91,11 @@ declare_lint_pass!(SignificantDropInScrutinee => [SIGNIFICANT_DROP_IN_SCRUTINEE]
9191
9292impl < ' tcx > LateLintPass < ' tcx > for SignificantDropInScrutinee {
9393 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > ) {
94- if let Some ( suggestions) = has_significant_drop_in_scrutinee ( cx, expr) {
94+ if let Some ( ( suggestions, message ) ) = has_significant_drop_in_scrutinee ( cx, expr) {
9595 for found in suggestions {
96- span_lint_and_then (
97- cx,
98- SIGNIFICANT_DROP_IN_SCRUTINEE ,
99- found. found_span ,
100- "temporary with significant drop in match scrutinee" ,
101- |diag| set_diagnostic ( diag, cx, expr, found) ,
102- ) ;
96+ span_lint_and_then ( cx, SIGNIFICANT_DROP_IN_SCRUTINEE , found. found_span , message, |diag| {
97+ set_diagnostic ( diag, cx, expr, found) ;
98+ } ) ;
10399 }
104100 }
105101 }
@@ -153,13 +149,20 @@ fn set_diagnostic<'tcx>(diag: &mut Diagnostic, cx: &LateContext<'tcx>, expr: &'t
153149fn has_significant_drop_in_scrutinee < ' tcx , ' a > (
154150 cx : & ' a LateContext < ' tcx > ,
155151 expr : & ' tcx Expr < ' tcx > ,
156- ) -> Option < Vec < FoundSigDrop > > {
152+ ) -> Option < ( Vec < FoundSigDrop > , & ' static str ) > {
157153 match expr. kind {
158154 ExprKind :: Match ( match_expr, _, source) => {
159155 match source {
160156 MatchSource :: Normal | MatchSource :: ForLoopDesugar => {
161157 let mut helper = SigDropHelper :: new ( cx) ;
162- helper. find_sig_drop ( match_expr)
158+ helper. find_sig_drop ( match_expr) . map ( |drops| {
159+ let message = if source == MatchSource :: Normal {
160+ "temporary with significant drop in match scrutinee"
161+ } else {
162+ "temporary with significant drop in for loop"
163+ } ;
164+ ( drops, message)
165+ } )
163166 } ,
164167 // MatchSource of TryDesugar or AwaitDesugar is out of scope for this lint
165168 MatchSource :: TryDesugar | MatchSource :: AwaitDesugar => None ,
0 commit comments