Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6ce8a37

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 66 additions & 46 deletions
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

0 commit comments

Comments
 (0)