-impl LintPass for Pass {
- fn get_lints(&self) -> LintArray {
- lint_array!(TEMPORARY_ASSIGNMENT)
- }
-}
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
- fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
- if let ExprKind::Assign(ref target, _) = expr.node {
- if let ExprKind::Field(ref base, _) = target.node {
- if is_temporary(base) && !is_adjusted(cx, base) {
- span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary");
- }
+impl<'tcx> LateLintPass<'tcx> for TemporaryAssignment {
+ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
+ if let ExprKind::Assign(target, ..) = &expr.kind {
+ let mut base = target;
+ while let ExprKind::Field(f, _) | ExprKind::Index(f, _) = &base.kind {
+ base = f;
+ }
+ if is_temporary(base) && !is_adjusted(cx, base) {
+ span_lint(cx, TEMPORARY_ASSIGNMENT, expr.span, "assignment to temporary");