|
| 1 | +#![deny(rustc::untranslatable_diagnostic)] |
| 2 | +#![deny(rustc::diagnostic_outside_of_impl)] |
| 3 | +use crate::lints::{ArrayIntoIterDiag, ArrayIntoIterDiagSub}; |
1 | 4 | use crate::{LateContext, LateLintPass, LintContext};
|
2 |
| -use rustc_errors::{fluent, Applicability}; |
3 | 5 | use rustc_hir as hir;
|
4 | 6 | use rustc_middle::ty;
|
5 | 7 | use rustc_middle::ty::adjustment::{Adjust, Adjustment};
|
@@ -118,41 +120,23 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
|
118 | 120 | // to an array or to a slice.
|
119 | 121 | _ => bug!("array type coerced to something other than array or slice"),
|
120 | 122 | };
|
121 |
| - cx.struct_span_lint( |
| 123 | + let sub = if self.for_expr_span == expr.span { |
| 124 | + Some(ArrayIntoIterDiagSub::RemoveIntoIter { |
| 125 | + span: receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()), |
| 126 | + }) |
| 127 | + } else if receiver_ty.is_array() { |
| 128 | + Some(ArrayIntoIterDiagSub::UseExplicitIntoIter { |
| 129 | + start_span: expr.span.shrink_to_lo(), |
| 130 | + end_span: receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()), |
| 131 | + }) |
| 132 | + } else { |
| 133 | + None |
| 134 | + }; |
| 135 | + cx.emit_spanned_lint( |
122 | 136 | ARRAY_INTO_ITER,
|
123 | 137 | call.ident.span,
|
124 |
| - fluent::lint_array_into_iter, |
125 |
| - |diag| { |
126 |
| - diag.set_arg("target", target); |
127 |
| - diag.span_suggestion( |
128 |
| - call.ident.span, |
129 |
| - fluent::use_iter_suggestion, |
130 |
| - "iter", |
131 |
| - Applicability::MachineApplicable, |
132 |
| - ); |
133 |
| - if self.for_expr_span == expr.span { |
134 |
| - diag.span_suggestion( |
135 |
| - receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()), |
136 |
| - fluent::remove_into_iter_suggestion, |
137 |
| - "", |
138 |
| - Applicability::MaybeIncorrect, |
139 |
| - ); |
140 |
| - } else if receiver_ty.is_array() { |
141 |
| - diag.multipart_suggestion( |
142 |
| - fluent::use_explicit_into_iter_suggestion, |
143 |
| - vec![ |
144 |
| - (expr.span.shrink_to_lo(), "IntoIterator::into_iter(".into()), |
145 |
| - ( |
146 |
| - receiver_arg.span.shrink_to_hi().to(expr.span.shrink_to_hi()), |
147 |
| - ")".into(), |
148 |
| - ), |
149 |
| - ], |
150 |
| - Applicability::MaybeIncorrect, |
151 |
| - ); |
152 |
| - } |
153 |
| - diag |
154 |
| - }, |
155 |
| - ) |
| 138 | + ArrayIntoIterDiag { target, suggestion: call.ident.span, sub }, |
| 139 | + ); |
156 | 140 | }
|
157 | 141 | }
|
158 | 142 | }
|
0 commit comments