From 9c83f8c4d1e562cd73a29a00828d68e2b520a086 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 25 Oct 2021 23:33:12 -0500 Subject: [PATCH 1/4] Simplify for loop desugar --- compiler/rustc_ast_lowering/src/expr.rs | 137 +++++------------- .../src/diagnostics/explain_borrow.rs | 13 +- .../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 ++ .../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 +- library/std/src/keyword_docs.rs | 5 +- src/test/incremental/hashes/for_loops.rs | 2 +- ...age_markers.main.RemoveStorageMarkers.diff | 115 ++++++--------- .../return-local-binding-from-desugaring.rs | 2 +- ...eturn-local-binding-from-desugaring.stderr | 4 +- ...for-loop-unconstrained-element-type.stderr | 6 +- src/test/ui/issues/issue-20261.stderr | 4 +- src/test/ui/issues/issue-33941.rs | 1 - src/test/ui/issues/issue-33941.stderr | 12 +- src/test/ui/nll/dont-print-desugared.stderr | 2 +- src/test/ui/nll/issue-53773.stderr | 4 +- .../ui/reachable/unreachable-loop-patterns.rs | 1 - .../unreachable-loop-patterns.stderr | 8 +- 26 files changed, 179 insertions(+), 254 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 405e9035c4c19..a0a63620c08a9 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