Skip to content

Commit 7823bf0

Browse files
committed
Auto merge of #124537 - matthiaskrgr:rollup-zjv9gu8, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - #124185 (Remove optionality from MoveData::base_local) - #124488 (Add a note to the ArbitraryExpressionInPattern error) - #124530 (Fix Fuchsia build broken by #124210) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a8a1d3a + d94eaba commit 7823bf0

File tree

12 files changed

+46
-14
lines changed

12 files changed

+46
-14
lines changed

Diff for: compiler/rustc_ast_lowering/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ast_lowering_abi_specified_multiple_times =
55
66
ast_lowering_arbitrary_expression_in_pattern =
77
arbitrary expressions aren't allowed in patterns
8+
.pattern_from_macro_note = the `expr` fragment specifier forces the metavariable's content to be an expression
89
910
ast_lowering_argument = argument
1011

Diff for: compiler/rustc_ast_lowering/src/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ pub struct NeverPatternWithGuard {
368368
pub struct ArbitraryExpressionInPattern {
369369
#[primary_span]
370370
pub span: Span,
371+
#[note(ast_lowering_pattern_from_macro_note)]
372+
pub pattern_from_macro_note: bool,
371373
}
372374

373375
#[derive(Diagnostic)]

Diff for: compiler/rustc_ast_lowering/src/pat.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
339339
ExprKind::Path(..) if allow_paths => {}
340340
ExprKind::Unary(UnOp::Neg, inner) if matches!(inner.kind, ExprKind::Lit(_)) => {}
341341
_ => {
342-
let guar = self.dcx().emit_err(ArbitraryExpressionInPattern { span: expr.span });
342+
let pattern_from_macro = expr.is_approximately_pattern();
343+
let guar = self.dcx().emit_err(ArbitraryExpressionInPattern {
344+
span: expr.span,
345+
pattern_from_macro_note: pattern_from_macro,
346+
});
343347
return self.arena.alloc(self.expr_err(expr.span, guar));
344348
}
345349
}

Diff for: compiler/rustc_borrowck/src/borrow_set.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ impl LocalsStateAtExit {
109109
has_storage_dead.visit_body(body);
110110
let mut has_storage_dead_or_moved = has_storage_dead.0;
111111
for move_out in &move_data.moves {
112-
if let Some(index) = move_data.base_local(move_out.path) {
113-
has_storage_dead_or_moved.insert(index);
114-
}
112+
has_storage_dead_or_moved.insert(move_data.base_local(move_out.path));
115113
}
116114
LocalsStateAtExit::SomeAreInvalidated { has_storage_dead_or_moved }
117115
}

Diff for: compiler/rustc_mir_dataflow/src/move_paths/mod.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,15 @@ impl<'tcx> MoveData<'tcx> {
358358
builder::gather_moves(body, tcx, param_env, filter)
359359
}
360360

361-
/// For the move path `mpi`, returns the root local variable (if any) that starts the path.
362-
/// (e.g., for a path like `a.b.c` returns `Some(a)`)
363-
pub fn base_local(&self, mut mpi: MovePathIndex) -> Option<Local> {
361+
/// For the move path `mpi`, returns the root local variable that starts the path.
362+
/// (e.g., for a path like `a.b.c` returns `a`)
363+
pub fn base_local(&self, mut mpi: MovePathIndex) -> Local {
364364
loop {
365365
let path = &self.move_paths[mpi];
366366
if let Some(l) = path.place.as_local() {
367-
return Some(l);
368-
}
369-
if let Some(parent) = path.parent {
370-
mpi = parent;
371-
continue;
372-
} else {
373-
return None;
367+
return l;
374368
}
369+
mpi = path.parent.expect("root move paths should be locals");
375370
}
376371
}
377372

Diff for: library/std/src/sys/pal/unix/fs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ impl Drop for Dir {
894894
target_os = "vita",
895895
target_os = "hurd",
896896
target_os = "espidf",
897+
target_os = "fuchsia",
897898
)))]
898899
{
899900
let fd = unsafe { libc::dirfd(self.0) };

Diff for: tests/ui/issues/issue-43250.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ error: arbitrary expressions aren't allowed in patterns
33
|
44
LL | m!(y);
55
| ^
6+
|
7+
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
68

79
error: arbitrary expressions aren't allowed in patterns
810
--> $DIR/issue-43250.rs:11:8
911
|
1012
LL | m!(C);
1113
| ^
14+
|
15+
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
1216

1317
error: aborting due to 2 previous errors
1418

Diff for: tests/ui/lowering/expr-in-pat-issue-99380.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
macro_rules! foo {
2+
($p:expr) => {
3+
if let $p = Some(42) {
4+
return;
5+
}
6+
};
7+
}
8+
9+
fn main() {
10+
foo!(Some(3)); //~ ERROR arbitrary expressions aren't allowed in patterns
11+
}

Diff for: tests/ui/lowering/expr-in-pat-issue-99380.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: arbitrary expressions aren't allowed in patterns
2+
--> $DIR/expr-in-pat-issue-99380.rs:10:10
3+
|
4+
LL | foo!(Some(3));
5+
| ^^^^^^^
6+
|
7+
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
8+
9+
error: aborting due to 1 previous error
10+

Diff for: tests/ui/macros/vec-macro-in-pattern.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ error: arbitrary expressions aren't allowed in patterns
44
LL | Some(vec![43]) => {}
55
| ^^^^^^^^
66
|
7+
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
78
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)
89

910
error: aborting due to 1 previous error

Diff for: tests/ui/match/expr_before_ident_pat.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ error: arbitrary expressions aren't allowed in patterns
99
|
1010
LL | funny!(a, a);
1111
| ^
12+
|
13+
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
1214

1315
error: aborting due to 2 previous errors
1416

Diff for: tests/ui/pattern/issue-92074-macro-ice.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ LL | () => { force_expr!(Vec::new()) }
77
LL | assert!(matches!(x, En::A(make_vec!())));
88
| ----------- in this macro invocation
99
|
10+
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
1011
= note: this error originates in the macro `make_vec` (in Nightly builds, run with -Z macro-backtrace for more info)
1112

1213
error: arbitrary expressions aren't allowed in patterns
@@ -18,6 +19,7 @@ LL | () => { force_pat!(get_usize(), get_usize()) }
1819
LL | assert!(matches!(5, make_pat!()));
1920
| ----------- in this macro invocation
2021
|
22+
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
2123
= note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info)
2224

2325
error: arbitrary expressions aren't allowed in patterns
@@ -29,6 +31,7 @@ LL | () => { force_pat!(get_usize(), get_usize()) }
2931
LL | assert!(matches!(5, make_pat!()));
3032
| ----------- in this macro invocation
3133
|
34+
= note: the `expr` fragment specifier forces the metavariable's content to be an expression
3235
= note: this error originates in the macro `make_pat` (in Nightly builds, run with -Z macro-backtrace for more info)
3336

3437
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)