From 9c83f8c4d1e562cd73a29a00828d68e2b520a086 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 25 Oct 2021 23:33:12 -0500 Subject: Simplify for loop desugar --- compiler/rustc_ast_lowering/src/expr.rs | 137 ++++++--------------- .../src/diagnostics/explain_borrow.rs | 13 +- compiler/rustc_borrowck/src/diagnostics/mod.rs | 12 +- .../src/diagnostics/mutability_errors.rs | 24 ++-- compiler/rustc_hir/src/hir.rs | 2 - compiler/rustc_hir/src/pat_util.rs | 11 ++ .../src/infer/error_reporting/need_type_info.rs | 24 +++- compiler/rustc_middle/src/lint.rs | 2 +- .../src/thir/pattern/check_match.rs | 21 ++-- compiler/rustc_span/src/hygiene.rs | 11 +- compiler/rustc_span/src/lib.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 - .../src/traits/error_reporting/suggestions.rs | 7 +- 13 files changed, 118 insertions(+), 149 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 405e9035c4c..a0a63620c08 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -13,7 +13,7 @@ use rustc_session::parse::feature_err; use rustc_span::hygiene::ExpnId; use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned}; use rustc_span::symbol::{sym, Ident, Symbol}; -use rustc_span::{hygiene::ForLoopLoc, DUMMY_SP}; +use rustc_span::DUMMY_SP; impl<'hir> LoweringContext<'_, 'hir> { fn lower_exprs(&mut self, exprs: &[AstP]) -> &'hir [hir::Expr<'hir>] { @@ -1308,16 +1308,13 @@ impl<'hir> LoweringContext<'_, 'hir> { /// Desugar `ExprForLoop` from: `[opt_ident]: for in ` into: /// ```rust /// { - /// let result = match ::std::iter::IntoIterator::into_iter() { + /// let result = match IntoIterator::into_iter() { /// mut iter => { /// [opt_ident]: loop { - /// let mut __next; - /// match ::std::iter::Iterator::next(&mut iter) { - /// ::std::option::Option::Some(val) => __next = val, - /// ::std::option::Option::None => break + /// match Iterator::next(&mut iter) { + /// None => break, + /// Some() => , /// }; - /// let = __next; - /// StmtKind::Expr(); /// } /// } /// }; @@ -1332,133 +1329,75 @@ impl<'hir> LoweringContext<'_, 'hir> { body: &Block, opt_label: Option