@@ -91,15 +91,11 @@ declare_lint_pass!(SignificantDropInScrutinee => [SIGNIFICANT_DROP_IN_SCRUTINEE]
91
91
92
92
impl < ' tcx > LateLintPass < ' tcx > for SignificantDropInScrutinee {
93
93
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) {
95
95
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
+ } ) ;
103
99
}
104
100
}
105
101
}
@@ -153,13 +149,20 @@ fn set_diagnostic<'tcx>(diag: &mut Diagnostic, cx: &LateContext<'tcx>, expr: &'t
153
149
fn has_significant_drop_in_scrutinee < ' tcx , ' a > (
154
150
cx : & ' a LateContext < ' tcx > ,
155
151
expr : & ' tcx Expr < ' tcx > ,
156
- ) -> Option < Vec < FoundSigDrop > > {
152
+ ) -> Option < ( Vec < FoundSigDrop > , & ' static str ) > {
157
153
match expr. kind {
158
154
ExprKind :: Match ( match_expr, _, source) => {
159
155
match source {
160
156
MatchSource :: Normal | MatchSource :: ForLoopDesugar => {
161
157
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
+ } )
163
166
} ,
164
167
// MatchSource of TryDesugar or AwaitDesugar is out of scope for this lint
165
168
MatchSource :: TryDesugar | MatchSource :: AwaitDesugar => None ,
0 commit comments