Skip to content

Commit 6ce8a37

Browse files
committed
Auto merge of rust-lang#133490 - jhpratt:rollup-f4ao5vz, r=jhpratt
Rollup of 28 pull requests Successful merges: - rust-lang#132605 (CI: increase timeout from 4h to 6h) - rust-lang#133042 (btree: add `{Entry,VacantEntry}::insert_entry`) - rust-lang#133070 (Lexer tweaks) - rust-lang#133136 (Support ranges in `<[T]>::get_many_mut()`) - rust-lang#133140 (Inline ExprPrecedence::order into Expr::precedence) - rust-lang#133248 (CI: split x86_64-msvc-ext job) - rust-lang#133282 (Shorten the `MaybeUninit` `Debug` implementation) - rust-lang#133304 (Revert diagnostics hack to fix ICE 132920) - rust-lang#133326 (Remove the `DefinitelyInitializedPlaces` analysis.) - rust-lang#133362 (No need to re-sort existential preds in relate impl) - rust-lang#133367 (Simplify array length mismatch error reporting (to not try to turn consts into target usizes)) - rust-lang#133394 (Bail on more errors in dyn ty lowering) - rust-lang#133410 (target check_consistency: ensure target feature string makes some basic sense) - rust-lang#133411 (the emscripten OS no longer exists on non-wasm targets) - rust-lang#133419 (Added a doc test for std::path::strip_prefix) - rust-lang#133430 (Tweak parameter mismatch explanation to not say `{unknown}`) - rust-lang#133435 (miri: disable test_downgrade_observe test on macOS) - rust-lang#133443 (Remove dead code stemming from the old effects desugaring (II)) - rust-lang#133449 (std: expose `const_io_error!` as `const_error!`) - rust-lang#133450 (remove "onur-ozkan" from users_on_vacation) - rust-lang#133454 (Update test expectations to accept LLVM 'initializes' attribute) - rust-lang#133458 (Fix `Result` and `Option` not getting a jump to def link generated) - rust-lang#133462 (Use ReadCache for archive reading in bootstrap) - rust-lang#133464 (std::thread: avoid leading whitespace in some panic messages) - rust-lang#133467 (tests: Add recursive associated type bound regression tests) - rust-lang#133470 (Cleanup: delete `//@ pretty-expanded` directive) - rust-lang#133473 (tests: Add regression test for recursive enum with Cow and Clone) - rust-lang#133481 (Disable `avr-rjmp-offset` on Windows for now) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f2abf82 + 478a4fb commit 6ce8a37

File tree

823 files changed

+1361
-2377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

823 files changed

+1361
-2377
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
defaults:
6666
run:
6767
shell: ${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}
68-
timeout-minutes: 240
68+
timeout-minutes: 360
6969
env:
7070
CI_JOB_NAME: ${{ matrix.image }}
7171
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

compiler/rustc_ast/src/ast.rs

+66-46
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ pub use crate::format::*;
3939
use crate::ptr::P;
4040
use crate::token::{self, CommentKind, Delimiter};
4141
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
42-
pub use crate::util::parser::ExprPrecedence;
42+
use crate::util::parser::{
43+
AssocOp, PREC_CLOSURE, PREC_JUMP, PREC_PREFIX, PREC_RANGE, PREC_UNAMBIGUOUS,
44+
};
4345

4446
/// A "Label" is an identifier of some point in sources,
4547
/// e.g. in the following code:
@@ -1314,53 +1316,71 @@ impl Expr {
13141316
Some(P(Ty { kind, id: self.id, span: self.span, tokens: None }))
13151317
}
13161318

1317-
pub fn precedence(&self) -> ExprPrecedence {
1319+
pub fn precedence(&self) -> i8 {
13181320
match self.kind {
1319-
ExprKind::Array(_) => ExprPrecedence::Array,
1320-
ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock,
1321-
ExprKind::Call(..) => ExprPrecedence::Call,
1322-
ExprKind::MethodCall(..) => ExprPrecedence::MethodCall,
1323-
ExprKind::Tup(_) => ExprPrecedence::Tup,
1324-
ExprKind::Binary(op, ..) => ExprPrecedence::Binary(op.node),
1325-
ExprKind::Unary(..) => ExprPrecedence::Unary,
1326-
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) => ExprPrecedence::Lit,
1327-
ExprKind::Cast(..) => ExprPrecedence::Cast,
1328-
ExprKind::Let(..) => ExprPrecedence::Let,
1329-
ExprKind::If(..) => ExprPrecedence::If,
1330-
ExprKind::While(..) => ExprPrecedence::While,
1331-
ExprKind::ForLoop { .. } => ExprPrecedence::ForLoop,
1332-
ExprKind::Loop(..) => ExprPrecedence::Loop,
1333-
ExprKind::Match(_, _, MatchKind::Prefix) => ExprPrecedence::Match,
1334-
ExprKind::Match(_, _, MatchKind::Postfix) => ExprPrecedence::PostfixMatch,
1335-
ExprKind::Closure(..) => ExprPrecedence::Closure,
1336-
ExprKind::Block(..) => ExprPrecedence::Block,
1337-
ExprKind::TryBlock(..) => ExprPrecedence::TryBlock,
1338-
ExprKind::Gen(..) => ExprPrecedence::Gen,
1339-
ExprKind::Await(..) => ExprPrecedence::Await,
1340-
ExprKind::Assign(..) => ExprPrecedence::Assign,
1341-
ExprKind::AssignOp(..) => ExprPrecedence::AssignOp,
1342-
ExprKind::Field(..) => ExprPrecedence::Field,
1343-
ExprKind::Index(..) => ExprPrecedence::Index,
1344-
ExprKind::Range(..) => ExprPrecedence::Range,
1345-
ExprKind::Underscore => ExprPrecedence::Path,
1346-
ExprKind::Path(..) => ExprPrecedence::Path,
1347-
ExprKind::AddrOf(..) => ExprPrecedence::AddrOf,
1348-
ExprKind::Break(..) => ExprPrecedence::Break,
1349-
ExprKind::Continue(..) => ExprPrecedence::Continue,
1350-
ExprKind::Ret(..) => ExprPrecedence::Ret,
1351-
ExprKind::Struct(..) => ExprPrecedence::Struct,
1352-
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
1353-
ExprKind::Paren(..) => ExprPrecedence::Paren,
1354-
ExprKind::Try(..) => ExprPrecedence::Try,
1355-
ExprKind::Yield(..) => ExprPrecedence::Yield,
1356-
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
1357-
ExprKind::Become(..) => ExprPrecedence::Become,
1358-
ExprKind::InlineAsm(..)
1359-
| ExprKind::Type(..)
1360-
| ExprKind::OffsetOf(..)
1321+
ExprKind::Closure(..) => PREC_CLOSURE,
1322+
1323+
ExprKind::Break(..)
1324+
| ExprKind::Continue(..)
1325+
| ExprKind::Ret(..)
1326+
| ExprKind::Yield(..)
1327+
| ExprKind::Yeet(..)
1328+
| ExprKind::Become(..) => PREC_JUMP,
1329+
1330+
// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
1331+
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
1332+
// ensures that `pprust` will add parentheses in the right places to get the desired
1333+
// parse.
1334+
ExprKind::Range(..) => PREC_RANGE,
1335+
1336+
// Binop-like expr kinds, handled by `AssocOp`.
1337+
ExprKind::Binary(op, ..) => AssocOp::from_ast_binop(op.node).precedence() as i8,
1338+
ExprKind::Cast(..) => AssocOp::As.precedence() as i8,
1339+
1340+
ExprKind::Assign(..) |
1341+
ExprKind::AssignOp(..) => AssocOp::Assign.precedence() as i8,
1342+
1343+
// Unary, prefix
1344+
ExprKind::AddrOf(..)
1345+
// Here `let pats = expr` has `let pats =` as a "unary" prefix of `expr`.
1346+
// However, this is not exactly right. When `let _ = a` is the LHS of a binop we
1347+
// need parens sometimes. E.g. we can print `(let _ = a) && b` as `let _ = a && b`
1348+
// but we need to print `(let _ = a) < b` as-is with parens.
1349+
| ExprKind::Let(..)
1350+
| ExprKind::Unary(..) => PREC_PREFIX,
1351+
1352+
// Never need parens
1353+
ExprKind::Array(_)
1354+
| ExprKind::Await(..)
1355+
| ExprKind::Block(..)
1356+
| ExprKind::Call(..)
1357+
| ExprKind::ConstBlock(_)
1358+
| ExprKind::Field(..)
1359+
| ExprKind::ForLoop { .. }
13611360
| ExprKind::FormatArgs(..)
1362-
| ExprKind::MacCall(..) => ExprPrecedence::Mac,
1363-
ExprKind::Err(_) | ExprKind::Dummy => ExprPrecedence::Err,
1361+
| ExprKind::Gen(..)
1362+
| ExprKind::If(..)
1363+
| ExprKind::IncludedBytes(..)
1364+
| ExprKind::Index(..)
1365+
| ExprKind::InlineAsm(..)
1366+
| ExprKind::Lit(_)
1367+
| ExprKind::Loop(..)
1368+
| ExprKind::MacCall(..)
1369+
| ExprKind::Match(..)
1370+
| ExprKind::MethodCall(..)
1371+
| ExprKind::OffsetOf(..)
1372+
| ExprKind::Paren(..)
1373+
| ExprKind::Path(..)
1374+
| ExprKind::Repeat(..)
1375+
| ExprKind::Struct(..)
1376+
| ExprKind::Try(..)
1377+
| ExprKind::TryBlock(..)
1378+
| ExprKind::Tup(_)
1379+
| ExprKind::Type(..)
1380+
| ExprKind::Underscore
1381+
| ExprKind::While(..)
1382+
| ExprKind::Err(_)
1383+
| ExprKind::Dummy => PREC_UNAMBIGUOUS,
13641384
}
13651385
}
13661386

compiler/rustc_ast/src/util/parser.rs

-115
Original file line numberDiff line numberDiff line change
@@ -237,121 +237,6 @@ pub const PREC_PREFIX: i8 = 50;
237237
pub const PREC_UNAMBIGUOUS: i8 = 60;
238238
pub const PREC_FORCE_PAREN: i8 = 100;
239239

240-
#[derive(Debug, Clone, Copy)]
241-
pub enum ExprPrecedence {
242-
Closure,
243-
Break,
244-
Continue,
245-
Ret,
246-
Yield,
247-
Yeet,
248-
Become,
249-
250-
Range,
251-
252-
Binary(BinOpKind),
253-
254-
Cast,
255-
256-
Assign,
257-
AssignOp,
258-
259-
AddrOf,
260-
Let,
261-
Unary,
262-
263-
Call,
264-
MethodCall,
265-
Field,
266-
Index,
267-
Try,
268-
Mac,
269-
270-
Array,
271-
Repeat,
272-
Tup,
273-
Lit,
274-
Path,
275-
Paren,
276-
If,
277-
While,
278-
ForLoop,
279-
Loop,
280-
Match,
281-
PostfixMatch,
282-
ConstBlock,
283-
Block,
284-
TryBlock,
285-
Struct,
286-
Gen,
287-
Await,
288-
Err,
289-
}
290-
291-
impl ExprPrecedence {
292-
pub fn order(self) -> i8 {
293-
match self {
294-
ExprPrecedence::Closure => PREC_CLOSURE,
295-
296-
ExprPrecedence::Break
297-
| ExprPrecedence::Continue
298-
| ExprPrecedence::Ret
299-
| ExprPrecedence::Yield
300-
| ExprPrecedence::Yeet
301-
| ExprPrecedence::Become => PREC_JUMP,
302-
303-
// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
304-
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
305-
// ensures that `pprust` will add parentheses in the right places to get the desired
306-
// parse.
307-
ExprPrecedence::Range => PREC_RANGE,
308-
309-
// Binop-like expr kinds, handled by `AssocOp`.
310-
ExprPrecedence::Binary(op) => AssocOp::from_ast_binop(op).precedence() as i8,
311-
ExprPrecedence::Cast => AssocOp::As.precedence() as i8,
312-
313-
ExprPrecedence::Assign |
314-
ExprPrecedence::AssignOp => AssocOp::Assign.precedence() as i8,
315-
316-
// Unary, prefix
317-
ExprPrecedence::AddrOf
318-
// Here `let pats = expr` has `let pats =` as a "unary" prefix of `expr`.
319-
// However, this is not exactly right. When `let _ = a` is the LHS of a binop we
320-
// need parens sometimes. E.g. we can print `(let _ = a) && b` as `let _ = a && b`
321-
// but we need to print `(let _ = a) < b` as-is with parens.
322-
| ExprPrecedence::Let
323-
| ExprPrecedence::Unary => PREC_PREFIX,
324-
325-
// Never need parens
326-
ExprPrecedence::Array
327-
| ExprPrecedence::Await
328-
| ExprPrecedence::Block
329-
| ExprPrecedence::Call
330-
| ExprPrecedence::ConstBlock
331-
| ExprPrecedence::Field
332-
| ExprPrecedence::ForLoop
333-
| ExprPrecedence::Gen
334-
| ExprPrecedence::If
335-
| ExprPrecedence::Index
336-
| ExprPrecedence::Lit
337-
| ExprPrecedence::Loop
338-
| ExprPrecedence::Mac
339-
| ExprPrecedence::Match
340-
| ExprPrecedence::MethodCall
341-
| ExprPrecedence::Paren
342-
| ExprPrecedence::Path
343-
| ExprPrecedence::PostfixMatch
344-
| ExprPrecedence::Repeat
345-
| ExprPrecedence::Struct
346-
| ExprPrecedence::Try
347-
| ExprPrecedence::TryBlock
348-
| ExprPrecedence::Tup
349-
| ExprPrecedence::While
350-
| ExprPrecedence::Err => PREC_UNAMBIGUOUS,
351-
}
352-
}
353-
}
354-
355240
/// In `let p = e`, operators with precedence `<=` this one requires parentheses in `e`.
356241
pub fn prec_let_scrutinee_needs_par() -> usize {
357242
AssocOp::LAnd.precedence()

compiler/rustc_ast_lowering/src/lib.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -2117,11 +2117,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21172117
hir::ConstArgKind::Anon(ct)
21182118
};
21192119

2120-
self.arena.alloc(hir::ConstArg {
2121-
hir_id: self.next_id(),
2122-
kind: ct_kind,
2123-
is_desugared_from_effects: false,
2124-
})
2120+
self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind })
21252121
}
21262122

21272123
/// See [`hir::ConstArg`] for when to use this function vs
@@ -2163,19 +2159,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21632159
None,
21642160
);
21652161

2166-
return ConstArg {
2167-
hir_id: self.next_id(),
2168-
kind: hir::ConstArgKind::Path(qpath),
2169-
is_desugared_from_effects: false,
2170-
};
2162+
return ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath) };
21712163
}
21722164

21732165
let lowered_anon = self.lower_anon_const_to_anon_const(anon);
2174-
ConstArg {
2175-
hir_id: self.next_id(),
2176-
kind: hir::ConstArgKind::Anon(lowered_anon),
2177-
is_desugared_from_effects: false,
2178-
}
2166+
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Anon(lowered_anon) }
21792167
}
21802168

21812169
/// See [`hir::ConstArg`] for when to use this function vs

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'a> State<'a> {
5959
}
6060

6161
fn print_expr_maybe_paren(&mut self, expr: &ast::Expr, prec: i8, fixup: FixupContext) {
62-
self.print_expr_cond_paren(expr, expr.precedence().order() < prec, fixup);
62+
self.print_expr_cond_paren(expr, expr.precedence() < prec, fixup);
6363
}
6464

6565
/// Prints an expr using syntax that's acceptable in a condition position, such as the `cond` in
@@ -615,7 +615,7 @@ impl<'a> State<'a> {
615615
expr,
616616
// Parenthesize if required by precedence, or in the
617617
// case of `break 'inner: loop { break 'inner 1 } + 1`
618-
expr.precedence().order() < parser::PREC_JUMP
618+
expr.precedence() < parser::PREC_JUMP
619619
|| (opt_label.is_none() && classify::leading_labeled_expr(expr)),
620620
fixup.subsequent_subexpression(),
621621
);

compiler/rustc_ast_pretty/src/pprust/state/fixup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,6 @@ impl FixupContext {
191191
/// "let chain".
192192
pub(crate) fn needs_par_as_let_scrutinee(self, expr: &Expr) -> bool {
193193
self.parenthesize_exterior_struct_lit && parser::contains_exterior_struct_lit(expr)
194-
|| parser::needs_par_as_let_scrutinee(expr.precedence().order())
194+
|| parser::needs_par_as_let_scrutinee(expr.precedence())
195195
}
196196
}

0 commit comments

Comments
 (0)