@@ -2,6 +2,7 @@ use crate::rustc::hir::*;
22use crate :: rustc:: lint:: { LateContext , LateLintPass , LintArray , LintPass } ;
33use crate :: rustc:: { declare_tool_lint, lint_array} ;
44use crate :: utils:: { in_macro, implements_trait, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq } ;
5+ use crate :: rustc_errors:: Applicability ;
56
67/// **What it does:** Checks for equal operands to comparison, logical and
78/// bitwise, difference and division binary operators (`==`, `>`, etc., `&&`,
@@ -113,7 +114,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
113114 } else if lcpy && !rcpy && implements_trait ( cx, lty, trait_id, & [ cx. tables . expr_ty ( right) . into ( ) ] ) {
114115 span_lint_and_then ( cx, OP_REF , e. span , "needlessly taken reference of left operand" , |db| {
115116 let lsnip = snippet ( cx, l. span , "..." ) . to_string ( ) ;
116- db. span_suggestion ( left. span , "use the left value directly" , lsnip) ;
117+ db. span_suggestion_with_applicability (
118+ left. span ,
119+ "use the left value directly" ,
120+ lsnip,
121+ Applicability :: MachineApplicable , // snippet
122+ ) ;
117123 } )
118124 } else if !lcpy && rcpy && implements_trait ( cx, cx. tables . expr_ty ( left) , trait_id, & [ rty. into ( ) ] ) {
119125 span_lint_and_then (
@@ -123,7 +129,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
123129 "needlessly taken reference of right operand" ,
124130 |db| {
125131 let rsnip = snippet ( cx, r. span , "..." ) . to_string ( ) ;
126- db. span_suggestion ( right. span , "use the right value directly" , rsnip) ;
132+ db. span_suggestion_with_applicability (
133+ right. span ,
134+ "use the right value directly" ,
135+ rsnip,
136+ Applicability :: MachineApplicable , // snippet
137+ ) ;
127138 } ,
128139 )
129140 }
@@ -135,7 +146,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
135146 if ( requires_ref || lcpy) && implements_trait ( cx, lty, trait_id, & [ cx. tables . expr_ty ( right) . into ( ) ] ) {
136147 span_lint_and_then ( cx, OP_REF , e. span , "needlessly taken reference of left operand" , |db| {
137148 let lsnip = snippet ( cx, l. span , "..." ) . to_string ( ) ;
138- db. span_suggestion ( left. span , "use the left value directly" , lsnip) ;
149+ db. span_suggestion_with_applicability (
150+ left. span ,
151+ "use the left value directly" ,
152+ lsnip,
153+ Applicability :: MachineApplicable , // snippet
154+ ) ;
139155 } )
140156 }
141157 } ,
@@ -146,7 +162,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
146162 if ( requires_ref || rcpy) && implements_trait ( cx, cx. tables . expr_ty ( left) , trait_id, & [ rty. into ( ) ] ) {
147163 span_lint_and_then ( cx, OP_REF , e. span , "taken reference of right operand" , |db| {
148164 let rsnip = snippet ( cx, r. span , "..." ) . to_string ( ) ;
149- db. span_suggestion ( right. span , "use the right value directly" , rsnip) ;
165+ db. span_suggestion_with_applicability (
166+ right. span ,
167+ "use the right value directly" ,
168+ rsnip,
169+ Applicability :: MachineApplicable , // snippet
170+ ) ;
150171 } )
151172 }
152173 } ,
0 commit comments