From 17073464ad9746995a733f87cf25b6d6eb3d9f35 Mon Sep 17 00:00:00 2001 From: beepster4096 <19316085+beepster4096@users.noreply.github.com> Date: Fri, 19 Apr 2024 16:50:46 -0700 Subject: [PATCH 1/4] remove optionality from MoveData::base_local --- compiler/rustc_borrowck/src/borrow_set.rs | 4 +--- compiler/rustc_mir_dataflow/src/move_paths/mod.rs | 15 +++++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index a38dd286be51b..ae6ac23c0f535 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -108,9 +108,7 @@ impl LocalsStateAtExit { has_storage_dead.visit_body(body); let mut has_storage_dead_or_moved = has_storage_dead.0; for move_out in &move_data.moves { - if let Some(index) = move_data.base_local(move_out.path) { - has_storage_dead_or_moved.insert(index); - } + has_storage_dead_or_moved.insert(move_data.base_local(move_out.path)); } LocalsStateAtExit::SomeAreInvalidated { has_storage_dead_or_moved } } diff --git a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs index 22cf3999239c1..830f44df5fb39 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/mod.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/mod.rs @@ -358,20 +358,15 @@ impl<'tcx> MoveData<'tcx> { builder::gather_moves(body, tcx, param_env, filter) } - /// For the move path `mpi`, returns the root local variable (if any) that starts the path. - /// (e.g., for a path like `a.b.c` returns `Some(a)`) - pub fn base_local(&self, mut mpi: MovePathIndex) -> Option { + /// For the move path `mpi`, returns the root local variable that starts the path. + /// (e.g., for a path like `a.b.c` returns `a`) + pub fn base_local(&self, mut mpi: MovePathIndex) -> Local { loop { let path = &self.move_paths[mpi]; if let Some(l) = path.place.as_local() { - return Some(l); - } - if let Some(parent) = path.parent { - mpi = parent; - continue; - } else { - return None; + return l; } + mpi = path.parent.expect("root move paths should be locals"); } } From 4284bca7209fc9eb03a8db5a388479ff723cc70d Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 28 Apr 2024 15:14:32 +0200 Subject: [PATCH 2/4] Add a note to the ArbitraryExpressionInPattern error --- compiler/rustc_ast_lowering/messages.ftl | 1 + compiler/rustc_ast_lowering/src/errors.rs | 2 ++ compiler/rustc_ast_lowering/src/pat.rs | 6 +++++- tests/ui/issues/issue-43250.stderr | 4 ++++ tests/ui/lowering/expr-in-pat-issue-99380.rs | 11 +++++++++++ tests/ui/lowering/expr-in-pat-issue-99380.stderr | 10 ++++++++++ tests/ui/macros/vec-macro-in-pattern.stderr | 1 + tests/ui/match/expr_before_ident_pat.stderr | 2 ++ tests/ui/pattern/issue-92074-macro-ice.stderr | 3 +++ 9 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/ui/lowering/expr-in-pat-issue-99380.rs create mode 100644 tests/ui/lowering/expr-in-pat-issue-99380.stderr diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index 73001c9990c8b..aa5a85b9c4ca2 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -5,6 +5,7 @@ ast_lowering_abi_specified_multiple_times = ast_lowering_arbitrary_expression_in_pattern = arbitrary expressions aren't allowed in patterns + .pattern_from_macro_note = the :expr fragment specifier forces the metavariable's content to be an expression ast_lowering_argument = argument diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index 6f70e135c72ac..02744d16b422f 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -368,6 +368,8 @@ pub struct NeverPatternWithGuard { pub struct ArbitraryExpressionInPattern { #[primary_span] pub span: Span, + #[note(ast_lowering_pattern_from_macro_note)] + pub pattern_from_macro_note: bool, } #[derive(Diagnostic)] diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index 118a7322fbdff..32de07a0755e2 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -339,7 +339,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ExprKind::Path(..) if allow_paths => {} ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {} _ => { - let guar = self.dcx().emit_err(ArbitraryExpressionInPattern { span: expr.span }); + let pattern_from_macro = expr.is_approximately_pattern(); + let guar = self.dcx().emit_err(ArbitraryExpressionInPattern { + span: expr.span, + pattern_from_macro_note: pattern_from_macro, + }); return self.arena.alloc(self.expr_err(expr.span, guar)); } } diff --git a/tests/ui/issues/issue-43250.stderr b/tests/ui/issues/issue-43250.stderr index f729c5cf10cea..01c22a9e79166 100644 --- a/tests/ui/issues/issue-43250.stderr +++ b/tests/ui/issues/issue-43250.stderr @@ -3,12 +3,16 @@ error: arbitrary expressions aren't allowed in patterns | LL | m!(y); | ^ + | + = note: the :expr fragment specifier forces the metavariable's content to be an expression error: arbitrary expressions aren't allowed in patterns --> $DIR/issue-43250.rs:11:8 | LL | m!(C); | ^ + | + = note: the :expr fragment specifier forces the metavariable's content to be an expression error: aborting due to 2 previous errors diff --git a/tests/ui/lowering/expr-in-pat-issue-99380.rs b/tests/ui/lowering/expr-in-pat-issue-99380.rs new file mode 100644 index 0000000000000..1d4a047f717f7 --- /dev/null +++ b/tests/ui/lowering/expr-in-pat-issue-99380.rs @@ -0,0 +1,11 @@ +macro_rules! foo { + ($p:expr) => { + if let $p = Some(42) { + return; + } + }; +} + +fn main() { + foo!(Some(3)); //~ ERROR arbitrary expressions aren't allowed in patterns +} diff --git a/tests/ui/lowering/expr-in-pat-issue-99380.stderr b/tests/ui/lowering/expr-in-pat-issue-99380.stderr new file mode 100644 index 0000000000000..7438bba270c72 --- /dev/null +++ b/tests/ui/lowering/expr-in-pat-issue-99380.stderr @@ -0,0 +1,10 @@ +error: arbitrary expressions aren't allowed in patterns + --> $DIR/expr-in-pat-issue-99380.rs:10:10 + | +LL | foo!(Some(3)); + | ^^^^^^^ + | + = note: the :expr fragment specifier forces the metavariable's content to be an expression + +error: aborting due to 1 previous error + diff --git a/tests/ui/macros/vec-macro-in-pattern.stderr b/tests/ui/macros/vec-macro-in-pattern.stderr index 447f5dcf8644f..7c87f3b7b8e6e 100644 --- a/tests/ui/macros/vec-macro-in-pattern.stderr +++ b/tests/ui/macros/vec-macro-in-pattern.stderr @@ -4,6 +4,7 @@ error: arbitrary expressions aren't allowed in patterns LL | Some(vec![43]) => {} | ^^^^^^^^ | + = note: the :expr fragment specifier forces the metavariable's content to be an expression = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error diff --git a/tests/ui/match/expr_before_ident_pat.stderr b/tests/ui/match/expr_before_ident_pat.stderr index 57a2d2b26cff0..2f59573b53f44 100644 --- a/tests/ui/match/expr_before_ident_pat.stderr +++ b/tests/ui/match/expr_before_ident_pat.stderr @@ -9,6 +9,8 @@ error: arbitrary expressions aren't allowed in patterns | LL | funny!(a, a); | ^ + | + = note: the :expr fragment specifier forces the metavariable's content to be an expression error: aborting due to 2 previous errors diff --git a/tests/ui/pattern/issue-92074-macro-ice.stderr b/tests/ui/pattern/issue-92074-macro-ice.stderr index b340afff010f7..bf53eb4bbcd47 100644 --- a/tests/ui/pattern/issue-92074-macro-ice.stderr +++ b/tests/ui/pattern/issue-92074-macro-ice.stderr @@ -7,6 +7,7 @@ LL | () => { force_expr!(Vec::new()) } LL | assert!(matches!(x, En::A(make_vec!()))); | ----------- in this macro invocation | + = note: the :expr fragment specifier forces the metavariable's content to be an expression = note: this error originates in the macro `make_vec` (in Nightly builds, run with -Z macro-backtrace for more info) error: arbitrary expressions aren't allowed in patterns @@ -18,6 +19,7 @@ LL | () => { force_pat!(get_usize(), get_usize()) } LL | assert!(matches!(5, make_pat!())); | ----------- in this macro invocation | + = note: the :expr fragment specifier forces the metavariable's content to be an expression = note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info) error: arbitrary expressions aren't allowed in patterns @@ -29,6 +31,7 @@ LL | () => { force_pat!(get_usize(), get_usize()) } LL | assert!(matches!(5, make_pat!())); | ----------- in this macro invocation | + = note: the :expr fragment specifier forces the metavariable's content to be an expression = note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors From c6e946d0f0405fb7641b7dd2cad2d9432e2313f8 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 29 Apr 2024 14:53:38 +0200 Subject: [PATCH 3/4] Change wording --- compiler/rustc_ast_lowering/messages.ftl | 2 +- tests/ui/issues/issue-43250.stderr | 4 ++-- tests/ui/lowering/expr-in-pat-issue-99380.stderr | 2 +- tests/ui/macros/vec-macro-in-pattern.stderr | 2 +- tests/ui/match/expr_before_ident_pat.stderr | 2 +- tests/ui/pattern/issue-92074-macro-ice.stderr | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_ast_lowering/messages.ftl b/compiler/rustc_ast_lowering/messages.ftl index aa5a85b9c4ca2..10efe6fba6550 100644 --- a/compiler/rustc_ast_lowering/messages.ftl +++ b/compiler/rustc_ast_lowering/messages.ftl @@ -5,7 +5,7 @@ ast_lowering_abi_specified_multiple_times = ast_lowering_arbitrary_expression_in_pattern = arbitrary expressions aren't allowed in patterns - .pattern_from_macro_note = the :expr fragment specifier forces the metavariable's content to be an expression + .pattern_from_macro_note = the `expr` fragment specifier forces the metavariable's content to be an expression ast_lowering_argument = argument diff --git a/tests/ui/issues/issue-43250.stderr b/tests/ui/issues/issue-43250.stderr index 01c22a9e79166..e74342b85adb3 100644 --- a/tests/ui/issues/issue-43250.stderr +++ b/tests/ui/issues/issue-43250.stderr @@ -4,7 +4,7 @@ error: arbitrary expressions aren't allowed in patterns LL | m!(y); | ^ | - = note: the :expr fragment specifier forces the metavariable's content to be an expression + = note: the `expr` fragment specifier forces the metavariable's content to be an expression error: arbitrary expressions aren't allowed in patterns --> $DIR/issue-43250.rs:11:8 @@ -12,7 +12,7 @@ error: arbitrary expressions aren't allowed in patterns LL | m!(C); | ^ | - = note: the :expr fragment specifier forces the metavariable's content to be an expression + = note: the `expr` fragment specifier forces the metavariable's content to be an expression error: aborting due to 2 previous errors diff --git a/tests/ui/lowering/expr-in-pat-issue-99380.stderr b/tests/ui/lowering/expr-in-pat-issue-99380.stderr index 7438bba270c72..29438c9b06360 100644 --- a/tests/ui/lowering/expr-in-pat-issue-99380.stderr +++ b/tests/ui/lowering/expr-in-pat-issue-99380.stderr @@ -4,7 +4,7 @@ error: arbitrary expressions aren't allowed in patterns LL | foo!(Some(3)); | ^^^^^^^ | - = note: the :expr fragment specifier forces the metavariable's content to be an expression + = note: the `expr` fragment specifier forces the metavariable's content to be an expression error: aborting due to 1 previous error diff --git a/tests/ui/macros/vec-macro-in-pattern.stderr b/tests/ui/macros/vec-macro-in-pattern.stderr index 7c87f3b7b8e6e..1a446b8c3edbc 100644 --- a/tests/ui/macros/vec-macro-in-pattern.stderr +++ b/tests/ui/macros/vec-macro-in-pattern.stderr @@ -4,7 +4,7 @@ error: arbitrary expressions aren't allowed in patterns LL | Some(vec![43]) => {} | ^^^^^^^^ | - = note: the :expr fragment specifier forces the metavariable's content to be an expression + = note: the `expr` fragment specifier forces the metavariable's content to be an expression = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 1 previous error diff --git a/tests/ui/match/expr_before_ident_pat.stderr b/tests/ui/match/expr_before_ident_pat.stderr index 2f59573b53f44..1657c51545cb2 100644 --- a/tests/ui/match/expr_before_ident_pat.stderr +++ b/tests/ui/match/expr_before_ident_pat.stderr @@ -10,7 +10,7 @@ error: arbitrary expressions aren't allowed in patterns LL | funny!(a, a); | ^ | - = note: the :expr fragment specifier forces the metavariable's content to be an expression + = note: the `expr` fragment specifier forces the metavariable's content to be an expression error: aborting due to 2 previous errors diff --git a/tests/ui/pattern/issue-92074-macro-ice.stderr b/tests/ui/pattern/issue-92074-macro-ice.stderr index bf53eb4bbcd47..025592116e511 100644 --- a/tests/ui/pattern/issue-92074-macro-ice.stderr +++ b/tests/ui/pattern/issue-92074-macro-ice.stderr @@ -7,7 +7,7 @@ LL | () => { force_expr!(Vec::new()) } LL | assert!(matches!(x, En::A(make_vec!()))); | ----------- in this macro invocation | - = note: the :expr fragment specifier forces the metavariable's content to be an expression + = note: the `expr` fragment specifier forces the metavariable's content to be an expression = note: this error originates in the macro `make_vec` (in Nightly builds, run with -Z macro-backtrace for more info) error: arbitrary expressions aren't allowed in patterns @@ -19,7 +19,7 @@ LL | () => { force_pat!(get_usize(), get_usize()) } LL | assert!(matches!(5, make_pat!())); | ----------- in this macro invocation | - = note: the :expr fragment specifier forces the metavariable's content to be an expression + = note: the `expr` fragment specifier forces the metavariable's content to be an expression = note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info) error: arbitrary expressions aren't allowed in patterns @@ -31,7 +31,7 @@ LL | () => { force_pat!(get_usize(), get_usize()) } LL | assert!(matches!(5, make_pat!())); | ----------- in this macro invocation | - = note: the :expr fragment specifier forces the metavariable's content to be an expression + = note: the `expr` fragment specifier forces the metavariable's content to be an expression = note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 3 previous errors From 982a58e900783a68f6a9b6bfea33f46b7be68386 Mon Sep 17 00:00:00 2001 From: David Koloski Date: Mon, 29 Apr 2024 17:00:03 +0000 Subject: [PATCH 4/4] Fix Fuchsia build broken by #124210 Fuchsia doesn't support dirfd although we have a symbol stubbed for it. --- library/std/src/sys/pal/unix/fs.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/sys/pal/unix/fs.rs b/library/std/src/sys/pal/unix/fs.rs index 5987996a3f167..f8fdc6369cdfb 100644 --- a/library/std/src/sys/pal/unix/fs.rs +++ b/library/std/src/sys/pal/unix/fs.rs @@ -894,6 +894,7 @@ impl Drop for Dir { target_os = "vita", target_os = "hurd", target_os = "espidf", + target_os = "fuchsia", )))] { let fd = unsafe { libc::dirfd(self.0) };