mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-18 03:25:55 +00:00
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
This commit is contained in:
commit
7823bf0412
@ -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
|
||||
|
||||
|
@ -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)]
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -109,9 +109,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 }
|
||||
}
|
||||
|
@ -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<Local> {
|
||||
/// 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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) };
|
||||
|
@ -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
|
||||
|
||||
|
11
tests/ui/lowering/expr-in-pat-issue-99380.rs
Normal file
11
tests/ui/lowering/expr-in-pat-issue-99380.rs
Normal file
@ -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
|
||||
}
|
10
tests/ui/lowering/expr-in-pat-issue-99380.stderr
Normal file
10
tests/ui/lowering/expr-in-pat-issue-99380.stderr
Normal file
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user