Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 28 pull requests #133490

Closed
wants to merge 66 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b910e97
CI: increase timeout from 4h to 6h
Kobzol Nov 4, 2024
584ec95
btree: add `{Entry,VacantEntry}::insert_entry`
cuviper Nov 14, 2024
e5f1555
Inline ExprPrecedence::order into Expr::precedence
dtolnay Nov 17, 2024
9148660
add convoluted test for issue 132920
lqd Nov 21, 2024
764e3e2
Revert "Remove less relevant info from diagnostic"
lqd Nov 21, 2024
ae9ac0e
Remove the `DefinitelyInitializedPlaces` analysis.
nnethercote Nov 22, 2024
c1707aa
Shorten the `MaybeUninit` `Debug` implementation
tgross35 Nov 21, 2024
b5fc3a1
No need to re-sort existential preds
compiler-errors Nov 23, 2024
898ccdb
Dont create object type when more than one principal is present
compiler-errors Nov 23, 2024
cfa8fcb
Dont create trait object if it has errors in it
compiler-errors Nov 23, 2024
28970a2
Simplify array length mismatch error reporting
compiler-errors Nov 23, 2024
6484420
the emscripten OS no longer exists on non-wasm targets
RalfJung Nov 24, 2024
5d42f64
target check_consistency: ensure target feature string makes some bas…
RalfJung Nov 24, 2024
f3ad32b
Added a doc test for std::path::strip_prefix
CromFr Nov 24, 2024
d26e29f
Tweak parameter mismatch explanation to not say unknown
compiler-errors Nov 25, 2024
98777b4
Merge `TokenTreesReader` into `StringReader`.
nnethercote Nov 14, 2024
593cf68
Split `Lexer::bump`.
nnethercote Nov 14, 2024
ba1a1dd
Fix some formatting.
nnethercote Nov 14, 2024
11c96cf
Improve `strip_shebang` testing.
nnethercote Nov 15, 2024
4cd2840
Clean up `c_or_byte_string`.
nnethercote Nov 15, 2024
16a39bb
Streamline `lex_token_trees` error handling.
nnethercote Nov 15, 2024
c9b56b9
miri: disable test_downgrade_observe test on macOS
RalfJung Nov 25, 2024
4a230bb
Support ranges in `<[T]>::get_many_mut()`
ChayimFriedman2 Nov 17, 2024
e8796c4
CI: split x86_64-msvc-ext job
marcoieni Nov 25, 2024
4301d02
Remove dead code stemming from the old effects desugaring (II)
fmease Nov 25, 2024
bf7d909
remove "onur-ozkan" from users_on_vacation
onur-ozkan Nov 25, 2024
d39afac
std: expose `const_io_error!` as `const_error!`
joboet Nov 25, 2024
57d5c6a
std: update internal uses of `io::const_error!`
joboet Nov 25, 2024
402bdd1
Update test expectations to accept LLVM 'initializes' attribute
zmodem Nov 25, 2024
9f1cfec
use ReadCache for archive loading
mustartt Nov 25, 2024
d0a45cf
Fix `Result` and `Option` not getting a jump to def link generated
GuillaumeGomez Nov 25, 2024
c839925
Add regression test for prelude types
GuillaumeGomez Nov 25, 2024
8bc8adb
std::thread: avoid leading whitespace in some panic messages
RalfJung Nov 25, 2024
b77d8fa
tests: Add recursive associated type bound regression tests
Enselic Nov 25, 2024
f62753f
compiletest: remove `pretty-expanded` directive and infra
jieyouxu Nov 25, 2024
95ff642
tests: remove `//@ pretty-expanded` usages
jieyouxu Nov 25, 2024
259020c
tests: Add regression test for recursive enum with Cow and Clone
Enselic Nov 25, 2024
3a42fd2
tests: disable `avr-rjmp-offset` on Windows for now
jieyouxu Nov 25, 2024
f1e21c6
Rollup merge of #132605 - Kobzol:ci-increase-timeout, r=Mark-Simulacrum
jhpratt Nov 26, 2024
84261f6
Rollup merge of #133042 - cuviper:btreemap-insert_entry, r=Amanieu
jhpratt Nov 26, 2024
3ff0332
Rollup merge of #133070 - nnethercote:lexer-tweaks, r=chenyukang
jhpratt Nov 26, 2024
5281f76
Rollup merge of #133136 - ChayimFriedman2:get-many-mut, r=Amanieu
jhpratt Nov 26, 2024
44a8d96
Rollup merge of #133140 - dtolnay:precedence, r=fmease
jhpratt Nov 26, 2024
2b56782
Rollup merge of #133248 - MarcoIeni:x86_64-msvc-ext-free, r=Kobzol
jhpratt Nov 26, 2024
d67d435
Rollup merge of #133282 - tgross35:maybe-uninit-debug, r=Amanieu
jhpratt Nov 26, 2024
0a0209b
Rollup merge of #133304 - lqd:issue-132920, r=estebank
jhpratt Nov 26, 2024
3e681e9
Rollup merge of #133326 - nnethercote:rm-DefinitelyInitializedPlaces,…
jhpratt Nov 26, 2024
4c36c4d
Rollup merge of #133362 - compiler-errors:existential-preds, r=BoxyUwU
jhpratt Nov 26, 2024
4a10997
Rollup merge of #133367 - compiler-errors:array-len-mismatch, r=BoxyUwU
jhpratt Nov 26, 2024
5a6f43e
Rollup merge of #133394 - compiler-errors:dyn-more-errors, r=lcnr
jhpratt Nov 26, 2024
af93a3b
Rollup merge of #133410 - RalfJung:target-feature-consistency, r=comp…
jhpratt Nov 26, 2024
7888d0b
Rollup merge of #133411 - RalfJung:emscripten-is-on-wasm, r=workingju…
jhpratt Nov 26, 2024
a1e2fd6
Rollup merge of #133419 - CromFr:add-path-strip_prefix-test-example, …
jhpratt Nov 26, 2024
07e3fa5
Rollup merge of #133430 - compiler-errors:param-mismatch, r=WaffleLapkin
jhpratt Nov 26, 2024
c010e8a
Rollup merge of #133435 - RalfJung:test_downgrade_observe, r=tgross35
jhpratt Nov 26, 2024
6935c94
Rollup merge of #133443 - fmease:rm-dead-eff-code-ii, r=compiler-errors
jhpratt Nov 26, 2024
293c0c6
Rollup merge of #133449 - joboet:io_const_error, r=tgross35
jhpratt Nov 26, 2024
deab7b5
Rollup merge of #133450 - onur-ozkan:update-triagebot, r=onur-ozkan
jhpratt Nov 26, 2024
fa2c1ab
Rollup merge of #133454 - zmodem:initializes_fix, r=nikic
jhpratt Nov 26, 2024
32443a8
Rollup merge of #133458 - GuillaumeGomez:fix-prelude-tys-links, r=not…
jhpratt Nov 26, 2024
265caaf
Rollup merge of #133462 - mustartt:aix-improve-bootstrap-loading, r=j…
jhpratt Nov 26, 2024
0414beb
Rollup merge of #133464 - RalfJung:whitespace-panic, r=joboet
jhpratt Nov 26, 2024
a9dfa49
Rollup merge of #133467 - Enselic:recurse-tests, r=lcnr
jhpratt Nov 26, 2024
8160668
Rollup merge of #133470 - jieyouxu:ugly, r=compiler-errors
jhpratt Nov 26, 2024
d974717
Rollup merge of #133473 - Enselic:cow, r=nnethercote
jhpratt Nov 26, 2024
478a4fb
Rollup merge of #133481 - jieyouxu:avr-jmp-linker, r=saethlin
jhpratt Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
defaults:
run:
shell: ${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}
timeout-minutes: 240
timeout-minutes: 360
env:
CI_JOB_NAME: ${{ matrix.image }}
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
Expand Down
112 changes: 66 additions & 46 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ pub use crate::format::*;
use crate::ptr::P;
use crate::token::{self, CommentKind, Delimiter};
use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream};
pub use crate::util::parser::ExprPrecedence;
use crate::util::parser::{
AssocOp, PREC_CLOSURE, PREC_JUMP, PREC_PREFIX, PREC_RANGE, PREC_UNAMBIGUOUS,
};

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

pub fn precedence(&self) -> ExprPrecedence {
pub fn precedence(&self) -> i8 {
match self.kind {
ExprKind::Array(_) => ExprPrecedence::Array,
ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock,
ExprKind::Call(..) => ExprPrecedence::Call,
ExprKind::MethodCall(..) => ExprPrecedence::MethodCall,
ExprKind::Tup(_) => ExprPrecedence::Tup,
ExprKind::Binary(op, ..) => ExprPrecedence::Binary(op.node),
ExprKind::Unary(..) => ExprPrecedence::Unary,
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) => ExprPrecedence::Lit,
ExprKind::Cast(..) => ExprPrecedence::Cast,
ExprKind::Let(..) => ExprPrecedence::Let,
ExprKind::If(..) => ExprPrecedence::If,
ExprKind::While(..) => ExprPrecedence::While,
ExprKind::ForLoop { .. } => ExprPrecedence::ForLoop,
ExprKind::Loop(..) => ExprPrecedence::Loop,
ExprKind::Match(_, _, MatchKind::Prefix) => ExprPrecedence::Match,
ExprKind::Match(_, _, MatchKind::Postfix) => ExprPrecedence::PostfixMatch,
ExprKind::Closure(..) => ExprPrecedence::Closure,
ExprKind::Block(..) => ExprPrecedence::Block,
ExprKind::TryBlock(..) => ExprPrecedence::TryBlock,
ExprKind::Gen(..) => ExprPrecedence::Gen,
ExprKind::Await(..) => ExprPrecedence::Await,
ExprKind::Assign(..) => ExprPrecedence::Assign,
ExprKind::AssignOp(..) => ExprPrecedence::AssignOp,
ExprKind::Field(..) => ExprPrecedence::Field,
ExprKind::Index(..) => ExprPrecedence::Index,
ExprKind::Range(..) => ExprPrecedence::Range,
ExprKind::Underscore => ExprPrecedence::Path,
ExprKind::Path(..) => ExprPrecedence::Path,
ExprKind::AddrOf(..) => ExprPrecedence::AddrOf,
ExprKind::Break(..) => ExprPrecedence::Break,
ExprKind::Continue(..) => ExprPrecedence::Continue,
ExprKind::Ret(..) => ExprPrecedence::Ret,
ExprKind::Struct(..) => ExprPrecedence::Struct,
ExprKind::Repeat(..) => ExprPrecedence::Repeat,
ExprKind::Paren(..) => ExprPrecedence::Paren,
ExprKind::Try(..) => ExprPrecedence::Try,
ExprKind::Yield(..) => ExprPrecedence::Yield,
ExprKind::Yeet(..) => ExprPrecedence::Yeet,
ExprKind::Become(..) => ExprPrecedence::Become,
ExprKind::InlineAsm(..)
| ExprKind::Type(..)
| ExprKind::OffsetOf(..)
ExprKind::Closure(..) => PREC_CLOSURE,

ExprKind::Break(..)
| ExprKind::Continue(..)
| ExprKind::Ret(..)
| ExprKind::Yield(..)
| ExprKind::Yeet(..)
| ExprKind::Become(..) => PREC_JUMP,

// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
// ensures that `pprust` will add parentheses in the right places to get the desired
// parse.
ExprKind::Range(..) => PREC_RANGE,

// Binop-like expr kinds, handled by `AssocOp`.
ExprKind::Binary(op, ..) => AssocOp::from_ast_binop(op.node).precedence() as i8,
ExprKind::Cast(..) => AssocOp::As.precedence() as i8,

ExprKind::Assign(..) |
ExprKind::AssignOp(..) => AssocOp::Assign.precedence() as i8,

// Unary, prefix
ExprKind::AddrOf(..)
// Here `let pats = expr` has `let pats =` as a "unary" prefix of `expr`.
// However, this is not exactly right. When `let _ = a` is the LHS of a binop we
// need parens sometimes. E.g. we can print `(let _ = a) && b` as `let _ = a && b`
// but we need to print `(let _ = a) < b` as-is with parens.
| ExprKind::Let(..)
| ExprKind::Unary(..) => PREC_PREFIX,

// Never need parens
ExprKind::Array(_)
| ExprKind::Await(..)
| ExprKind::Block(..)
| ExprKind::Call(..)
| ExprKind::ConstBlock(_)
| ExprKind::Field(..)
| ExprKind::ForLoop { .. }
| ExprKind::FormatArgs(..)
| ExprKind::MacCall(..) => ExprPrecedence::Mac,
ExprKind::Err(_) | ExprKind::Dummy => ExprPrecedence::Err,
| ExprKind::Gen(..)
| ExprKind::If(..)
| ExprKind::IncludedBytes(..)
| ExprKind::Index(..)
| ExprKind::InlineAsm(..)
| ExprKind::Lit(_)
| ExprKind::Loop(..)
| ExprKind::MacCall(..)
| ExprKind::Match(..)
| ExprKind::MethodCall(..)
| ExprKind::OffsetOf(..)
| ExprKind::Paren(..)
| ExprKind::Path(..)
| ExprKind::Repeat(..)
| ExprKind::Struct(..)
| ExprKind::Try(..)
| ExprKind::TryBlock(..)
| ExprKind::Tup(_)
| ExprKind::Type(..)
| ExprKind::Underscore
| ExprKind::While(..)
| ExprKind::Err(_)
| ExprKind::Dummy => PREC_UNAMBIGUOUS,
}
}

Expand Down
115 changes: 0 additions & 115 deletions compiler/rustc_ast/src/util/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,121 +237,6 @@ pub const PREC_PREFIX: i8 = 50;
pub const PREC_UNAMBIGUOUS: i8 = 60;
pub const PREC_FORCE_PAREN: i8 = 100;

#[derive(Debug, Clone, Copy)]
pub enum ExprPrecedence {
Closure,
Break,
Continue,
Ret,
Yield,
Yeet,
Become,

Range,

Binary(BinOpKind),

Cast,

Assign,
AssignOp,

AddrOf,
Let,
Unary,

Call,
MethodCall,
Field,
Index,
Try,
Mac,

Array,
Repeat,
Tup,
Lit,
Path,
Paren,
If,
While,
ForLoop,
Loop,
Match,
PostfixMatch,
ConstBlock,
Block,
TryBlock,
Struct,
Gen,
Await,
Err,
}

impl ExprPrecedence {
pub fn order(self) -> i8 {
match self {
ExprPrecedence::Closure => PREC_CLOSURE,

ExprPrecedence::Break
| ExprPrecedence::Continue
| ExprPrecedence::Ret
| ExprPrecedence::Yield
| ExprPrecedence::Yeet
| ExprPrecedence::Become => PREC_JUMP,

// `Range` claims to have higher precedence than `Assign`, but `x .. x = x` fails to
// parse, instead of parsing as `(x .. x) = x`. Giving `Range` a lower precedence
// ensures that `pprust` will add parentheses in the right places to get the desired
// parse.
ExprPrecedence::Range => PREC_RANGE,

// Binop-like expr kinds, handled by `AssocOp`.
ExprPrecedence::Binary(op) => AssocOp::from_ast_binop(op).precedence() as i8,
ExprPrecedence::Cast => AssocOp::As.precedence() as i8,

ExprPrecedence::Assign |
ExprPrecedence::AssignOp => AssocOp::Assign.precedence() as i8,

// Unary, prefix
ExprPrecedence::AddrOf
// Here `let pats = expr` has `let pats =` as a "unary" prefix of `expr`.
// However, this is not exactly right. When `let _ = a` is the LHS of a binop we
// need parens sometimes. E.g. we can print `(let _ = a) && b` as `let _ = a && b`
// but we need to print `(let _ = a) < b` as-is with parens.
| ExprPrecedence::Let
| ExprPrecedence::Unary => PREC_PREFIX,

// Never need parens
ExprPrecedence::Array
| ExprPrecedence::Await
| ExprPrecedence::Block
| ExprPrecedence::Call
| ExprPrecedence::ConstBlock
| ExprPrecedence::Field
| ExprPrecedence::ForLoop
| ExprPrecedence::Gen
| ExprPrecedence::If
| ExprPrecedence::Index
| ExprPrecedence::Lit
| ExprPrecedence::Loop
| ExprPrecedence::Mac
| ExprPrecedence::Match
| ExprPrecedence::MethodCall
| ExprPrecedence::Paren
| ExprPrecedence::Path
| ExprPrecedence::PostfixMatch
| ExprPrecedence::Repeat
| ExprPrecedence::Struct
| ExprPrecedence::Try
| ExprPrecedence::TryBlock
| ExprPrecedence::Tup
| ExprPrecedence::While
| ExprPrecedence::Err => PREC_UNAMBIGUOUS,
}
}
}

/// In `let p = e`, operators with precedence `<=` this one requires parentheses in `e`.
pub fn prec_let_scrutinee_needs_par() -> usize {
AssocOp::LAnd.precedence()
Expand Down
18 changes: 3 additions & 15 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2117,11 +2117,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
hir::ConstArgKind::Anon(ct)
};

self.arena.alloc(hir::ConstArg {
hir_id: self.next_id(),
kind: ct_kind,
is_desugared_from_effects: false,
})
self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind })
}

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

return ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Path(qpath),
is_desugared_from_effects: false,
};
return ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath) };
}

let lowered_anon = self.lower_anon_const_to_anon_const(anon);
ConstArg {
hir_id: self.next_id(),
kind: hir::ConstArgKind::Anon(lowered_anon),
is_desugared_from_effects: false,
}
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Anon(lowered_anon) }
}

/// See [`hir::ConstArg`] for when to use this function vs
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'a> State<'a> {
}

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

/// Prints an expr using syntax that's acceptable in a condition position, such as the `cond` in
Expand Down Expand Up @@ -615,7 +615,7 @@ impl<'a> State<'a> {
expr,
// Parenthesize if required by precedence, or in the
// case of `break 'inner: loop { break 'inner 1 } + 1`
expr.precedence().order() < parser::PREC_JUMP
expr.precedence() < parser::PREC_JUMP
|| (opt_label.is_none() && classify::leading_labeled_expr(expr)),
fixup.subsequent_subexpression(),
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state/fixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,6 @@ impl FixupContext {
/// "let chain".
pub(crate) fn needs_par_as_let_scrutinee(self, expr: &Expr) -> bool {
self.parenthesize_exterior_struct_lit && parser::contains_exterior_struct_lit(expr)
|| parser::needs_par_as_let_scrutinee(expr.precedence().order())
|| parser::needs_par_as_let_scrutinee(expr.precedence())
}
}
Loading
Loading