From a632bada94a62b99843fd0e412a39d9ccb2ad6d8 Mon Sep 17 00:00:00 2001 From: phi-go Date: Mon, 17 Apr 2023 16:24:03 +0200 Subject: [PATCH] redo frontend work This commit is a port of the changes done by @semtexzv, as described in this comment: https://github.com/rust-lang/rfcs/pull/1888#issuecomment-1186593662 All locations that need further work are marked with: FIXME(explicit_tail_calls) --- compiler/rustc_ast/src/ast.rs | 3 ++ compiler/rustc_ast/src/mut_visit.rs | 3 ++ compiler/rustc_ast/src/visit.rs | 3 ++ compiler/rustc_ast_lowering/src/expr.rs | 4 +++ compiler/rustc_ast_passes/src/feature_gate.rs | 4 +++ .../rustc_ast_pretty/src/pprust/state/expr.rs | 5 +++ .../src/assert/context.rs | 1 + compiler/rustc_feature/src/active.rs | 2 ++ compiler/rustc_hir/src/hir.rs | 5 +++ compiler/rustc_hir/src/intravisit.rs | 3 ++ compiler/rustc_hir_pretty/src/lib.rs | 12 +++++-- compiler/rustc_hir_typeck/src/expr.rs | 24 +++++++++++++ .../rustc_hir_typeck/src/expr_use_visitor.rs | 4 +++ .../drop_ranges/cfg_build.rs | 2 ++ .../src/mem_categorization.rs | 1 + compiler/rustc_middle/src/thir.rs | 4 +++ compiler/rustc_middle/src/thir/visit.rs | 1 + .../src/build/expr/as_place.rs | 1 + .../src/build/expr/as_rvalue.rs | 1 + .../src/build/expr/category.rs | 3 +- .../rustc_mir_build/src/build/expr/into.rs | 4 +++ .../rustc_mir_build/src/check_unsafety.rs | 1 + compiler/rustc_mir_build/src/thir/cx/expr.rs | 1 + compiler/rustc_mir_build/src/thir/print.rs | 9 +++++ compiler/rustc_parse/src/parser/expr.rs | 11 ++++++ compiler/rustc_passes/src/hir_stats.rs | 4 +-- compiler/rustc_passes/src/liveness.rs | 7 ++++ compiler/rustc_passes/src/naked_functions.rs | 1 + compiler/rustc_span/src/symbol.rs | 1 + compiler/rustc_ty_utils/src/consts.rs | 4 +++ .../language-features/explicit-tail-calls.md | 34 +++++++++++++++++++ .../clippy_lints/src/loops/never_loop.rs | 6 ++++ .../matches/significant_drop_in_scrutinee.rs | 1 + .../clippy/clippy_lints/src/utils/author.rs | 5 +++ .../clippy/clippy_utils/src/eager_or_lazy.rs | 1 + .../clippy/clippy_utils/src/hir_utils.rs | 3 ++ src/tools/clippy/clippy_utils/src/sugg.rs | 2 ++ src/tools/clippy/clippy_utils/src/visitors.rs | 4 +++ src/tools/rustfmt/src/expr.rs | 3 ++ src/tools/rustfmt/src/utils.rs | 1 + src/tools/tidy/src/ui_tests.rs | 2 +- .../explicit-tail-calls/closure-disallowed.rs | 14 ++++++++ tests/ui/explicit-tail-calls/wrong-expr.rs | 10 ++++++ .../ui/explicit-tail-calls/wrong-expr.stderr | 7 ++++ tests/ui/explicit-tail-calls/wrong-type.rs | 14 ++++++++ .../feature-gate-explicit_tail_calls.rs | 7 ++++ .../feature-gate-explicit_tail_calls.stderr | 12 +++++++ 47 files changed, 248 insertions(+), 7 deletions(-) create mode 100644 src/doc/unstable-book/src/language-features/explicit-tail-calls.md create mode 100644 tests/ui/explicit-tail-calls/closure-disallowed.rs create mode 100644 tests/ui/explicit-tail-calls/wrong-expr.rs create mode 100644 tests/ui/explicit-tail-calls/wrong-expr.stderr create mode 100644 tests/ui/explicit-tail-calls/wrong-type.rs create mode 100644 tests/ui/feature-gates/feature-gate-explicit_tail_calls.rs create mode 100644 tests/ui/feature-gates/feature-gate-explicit_tail_calls.stderr diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index ab0409efb3b29..71609979d435a 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1270,6 +1270,7 @@ impl Expr { ExprKind::Break(..) => ExprPrecedence::Break, ExprKind::Continue(..) => ExprPrecedence::Continue, ExprKind::Ret(..) => ExprPrecedence::Ret, + ExprKind::Become(..) => ExprPrecedence::Ret, ExprKind::InlineAsm(..) => ExprPrecedence::InlineAsm, ExprKind::MacCall(..) => ExprPrecedence::Mac, ExprKind::Struct(..) => ExprPrecedence::Struct, @@ -1465,6 +1466,8 @@ pub enum ExprKind { Continue(Option