Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f371952
Abstract `ProcThreadAttributeList` into its own struct
michaelvanstraten Apr 7, 2024
f3ac64a
Add test of closure vs jump precedence
dtolnay Dec 3, 2024
193d827
Squash closures and jumps into a single precedence level
dtolnay Dec 3, 2024
4df47a0
Add test of closure precedence with return type
dtolnay Dec 3, 2024
72ac961
Raise precedence of closure that has explicit return type
dtolnay Dec 3, 2024
fe06c5d
Never parenthesize `continue`
dtolnay Dec 3, 2024
cb88030
Arbitrary self types v2: niche deshadowing test
adetaylor Dec 19, 2024
fae7207
Arbitrary self types v2: no deshadow pre feature.
adetaylor Dec 19, 2024
05731af
Add `--doctest-compilation-args` option to allow passing arguments to…
GuillaumeGomez Aug 7, 2024
2bd8690
Add regression test for `--doctest-compilation-args`
GuillaumeGomez Aug 7, 2024
d3c970a
Add explanations about `--doctest-compilation-args` in rustdoc book
GuillaumeGomez Aug 7, 2024
b3cc9b9
Restrict `#[non_exaustive]` on structs with default field values
estebank Dec 20, 2024
24fafe7
Update `run-make/rustdoc-default-output` test
GuillaumeGomez Aug 19, 2024
cbb3df4
Split arguments from `--doctest-compilation-args` like a shell would
GuillaumeGomez Aug 28, 2024
55653a5
Add explanations on how arguments are split
GuillaumeGomez Dec 20, 2024
bc03e40
Move test into the `tests.rs` file
GuillaumeGomez Dec 20, 2024
2d914be
Add test to ensure passing `--doctest_compilation_args` multiple time…
GuillaumeGomez Dec 20, 2024
9965ad7
Also lint on option of function pointer comparisons
Urgau Dec 19, 2024
758ad53
Rollup merge of #123604 - michaelvanstraten:proc_thread_attribute_lis…
matthiaskrgr Dec 21, 2024
472bbb9
Rollup merge of #128780 - GuillaumeGomez:rustflags-doctests, r=rustdoc
matthiaskrgr Dec 21, 2024
f3b19f5
Rollup merge of #133782 - dtolnay:closuresjumps, r=spastorino,travisc…
matthiaskrgr Dec 21, 2024
aea7c1d
Rollup merge of #134509 - adetaylor:niche-deshadowing-tests, r=wesley…
matthiaskrgr Dec 21, 2024
3201fe9
Rollup merge of #134524 - adetaylor:getref, r=compiler-errors
matthiaskrgr Dec 21, 2024
fea6c4e
Rollup merge of #134539 - estebank:restrict-non_exhaustive, r=jieyouxu
matthiaskrgr Dec 21, 2024
b7ac8d7
Rollup merge of #134586 - Urgau:fn-ptr-lint-option, r=compiler-errors
matthiaskrgr Dec 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Raise precedence of closure that has explicit return type
  • Loading branch information
dtolnay committed Dec 3, 2024
commit 72ac961616f23401c54f08436006250fd1fcdb9e
10 changes: 8 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,15 @@ impl Expr {
}

pub fn precedence(&self) -> ExprPrecedence {
match self.kind {
match &self.kind {
ExprKind::Closure(closure) => {
match closure.fn_decl.output {
FnRetTy::Default(_) => ExprPrecedence::Jump,
FnRetTy::Ty(_) => ExprPrecedence::Unambiguous,
}
}

ExprKind::Break(..)
| ExprKind::Closure(..)
| ExprKind::Continue(..)
| ExprKind::Ret(..)
| ExprKind::Yield(..)
Expand Down
12 changes: 9 additions & 3 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,9 +1696,15 @@ pub struct Expr<'hir> {

impl Expr<'_> {
pub fn precedence(&self) -> ExprPrecedence {
match self.kind {
match &self.kind {
ExprKind::Closure(closure) => {
match closure.fn_decl.output {
FnRetTy::DefaultReturn(_) => ExprPrecedence::Jump,
FnRetTy::Return(_) => ExprPrecedence::Unambiguous,
}
}

ExprKind::Break(..)
| ExprKind::Closure { .. }
| ExprKind::Continue(..)
| ExprKind::Ret(..)
| ExprKind::Yield(..)
Expand Down Expand Up @@ -1741,7 +1747,7 @@ impl Expr<'_> {
| ExprKind::Type(..)
| ExprKind::Err(_) => ExprPrecedence::Unambiguous,

ExprKind::DropTemps(ref expr, ..) => expr.precedence(),
ExprKind::DropTemps(expr, ..) => expr.precedence(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui-fulldeps/pprust-parenthesis-insertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static EXPRS: &[&str] = &[
"|| return break 2",
"return break || 2",
// Closures with a return type have especially high precedence.
"(|| -> T { x }) + 1", // FIXME: no parenthesis needed.
"|| -> T { x } + 1",
"(|| { x }) + 1",
// These mean different things.
"if let _ = true && false {}",
Expand Down