Skip to content

Conversation

ShE3py
Copy link
Contributor

@ShE3py ShE3py commented Jan 14, 2024

#116715 added thir::PatKind::Error; this PR adds hir::PatKind::Err and ast::PatKind::Err (see #118625 (comment).)


@rustbot label +A-patterns
r? WaffleLapkin

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 14, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2024

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes might have occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added the A-patterns Relating to patterns and pattern matching label Jan 14, 2024
@fmease
Copy link
Member

fmease commented Jan 14, 2024

Btw, if you'd like to have another small side project, you can equip ast::ExprKind::Err with ErrorGuaranteed, too 😉
In a separate PR ofc.

@compiler-errors
Copy link
Member

Btw, if you'd like to have another small side project, you can equip ast::ExprKind::Err with ErrorGuaranteed, too

We use ast::ExprKind::Err as the "null" value for some places in the AST, so this is probably not possible without some work:

pub fn take(&mut self) -> Self {
mem::replace(
self,
Expr {
id: DUMMY_NODE_ID,
kind: ExprKind::Err,
span: DUMMY_SP,
attrs: AttrVec::new(),
tokens: None,
},
)
}

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with the comment removed

@@ -51,7 +51,8 @@ fn unary_pattern(pat: &Pat<'_>) -> bool {
| PatKind::Binding(..)
| PatKind::Wild
| PatKind::Never
| PatKind::Or(_) => false,
| PatKind::Or(_)
| PatKind::Err(_) => false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but I find this weird... Wild can match only a single thing if it's for a type like (), similarly 1..=1, similarly []....

@WaffleLapkin
Copy link
Member

@bors delegate+

@bors
Copy link
Collaborator

bors commented Jan 17, 2024

✌️ @ShE3py, you can now approve this pull request!

If @WaffleLapkin told you to "r=me" after making some further change, please make that change, then do @bors r=@WaffleLapkin

@fmease
Copy link
Member

fmease commented Jan 17, 2024

Might be worth mentioning that the impls of DummyAstNode for Expr, Ty and so on use Err but Wild for ast::Pat:

impl DummyAstNode for Expr {
fn dummy() -> Self {
Expr {
id: DUMMY_NODE_ID,
kind: ExprKind::Err,
span: Default::default(),
attrs: Default::default(),
tokens: Default::default(),
}
}
}
impl DummyAstNode for Ty {
fn dummy() -> Self {
Ty {
id: DUMMY_NODE_ID,
kind: TyKind::Err,
span: Default::default(),
tokens: Default::default(),
}
}
}
impl DummyAstNode for Pat {
fn dummy() -> Self {
Pat {
id: DUMMY_NODE_ID,
kind: PatKind::Wild,
span: Default::default(),
tokens: Default::default(),
}
}
}

@ShE3py
Copy link
Contributor Author

ShE3py commented Jan 17, 2024

Ty!
@bors r=WaffleLapkin


Btw, if you'd like to have another small side project, you can equip ast::ExprKind::Err with ErrorGuaranteed, too

We use ast::ExprKind::Err as the "null" value for some places in the AST, so this is probably not possible without some work

I looked a bit and at first glance it may be possible to add something like ast::ExprKind::Dummy and to lower it as:

ast::ExprKind::Err(guar) => hir::ExprKind::Err(*guar),
ast::ExprKind::Dummy => hir::ExprKind::Err(self.dcx().span_delayed_bug(e.span, "lowered ExprKind::Dummy")),

I might give it a try next week.

@bors
Copy link
Collaborator

bors commented Jan 17, 2024

📌 Commit 7889e99 has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 17, 2024
@compiler-errors
Copy link
Member

@ShE3py: Yeah, general approach of splitting it and adding a dummy variant for "ast::Expr::take" is probably the best one. Even better, you could make it span_bug!() if Dummy gets lowered. That should never happen, I think.

@fmease
Copy link
Member

fmease commented Jan 17, 2024

ast::Expr::take isn't actually used. I can compile rustc successfully without it (rustfmt and clippy don't seem to use it either). However, DummyAstNode would be really hard to get rid of. +1 to ast::ExprKind::Dummy.

compiler-errors added a commit to compiler-errors/rust that referenced this pull request Jan 17, 2024
Add `PatKind::Err` to AST/HIR

rust-lang#116715 added `thir::PatKind::Error`; this PR adds `hir::PatKind::Err` and `ast::PatKind::Err` (see rust-lang#118625 (comment).)

---

`@rustbot` label +A-patterns
r? WaffleLapkin
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 18, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#119172 (Detect `NulInCStr` error earlier.)
 - rust-lang#119833 (Make tcx optional from StableMIR run macro and extend it to accept closures)
 - rust-lang#119967 (Add `PatKind::Err` to AST/HIR)
 - rust-lang#119978 (Move async closure parameters into the resultant closure's future eagerly)
 - rust-lang#120021 (don't store const var origins for known vars)
 - rust-lang#120038 (Don't create a separate "basename" when naming and opening a MIR dump file)
 - rust-lang#120057 (Don't ICE when deducing future output if other errors already occurred)
 - rust-lang#120073 (Remove spastorino from users_on_vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 18, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#119172 (Detect `NulInCStr` error earlier.)
 - rust-lang#119833 (Make tcx optional from StableMIR run macro and extend it to accept closures)
 - rust-lang#119967 (Add `PatKind::Err` to AST/HIR)
 - rust-lang#119978 (Move async closure parameters into the resultant closure's future eagerly)
 - rust-lang#120021 (don't store const var origins for known vars)
 - rust-lang#120038 (Don't create a separate "basename" when naming and opening a MIR dump file)
 - rust-lang#120057 (Don't ICE when deducing future output if other errors already occurred)
 - rust-lang#120073 (Remove spastorino from users_on_vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1f93d2b into rust-lang:master Jan 18, 2024
@rustbot rustbot added this to the 1.77.0 milestone Jan 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 18, 2024
Rollup merge of rust-lang#119967 - ShE3py:patkind-err, r=WaffleLapkin

Add `PatKind::Err` to AST/HIR

rust-lang#116715 added `thir::PatKind::Error`; this PR adds `hir::PatKind::Err` and `ast::PatKind::Err` (see rust-lang#118625 (comment).)

---

``@rustbot`` label +A-patterns
r? WaffleLapkin
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2024
Add `ErrorGuaranteed` to `ast::ExprKind::Err`

See rust-lang#119967 for context
```
      \
       \
          _~^~^~_
      \) /  o o  \ (/
        '_   -   _'
        / '-----' \
```

r? fmease
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2024
Add `ErrorGuaranteed` to `ast::ExprKind::Err`

See rust-lang#119967 for context
```
      \
       \
          _~^~^~_
      \) /  o o  \ (/
        '_   -   _'
        / '-----' \
```

r? fmease
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2024
Add `ErrorGuaranteed` to `ast::ExprKind::Err`

See rust-lang#119967 for context
```
      \
       \
          _~^~^~_
      \) /  o o  \ (/
        '_   -   _'
        / '-----' \
```

r? fmease
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 7, 2024
Add `ErrorGuaranteed` to `ast::ExprKind::Err`

See rust-lang#119967 for context
```
      \
       \
          _~^~^~_
      \) /  o o  \ (/
        '_   -   _'
        / '-----' \
```

r? fmease
calebcartwright pushed a commit to calebcartwright/rust that referenced this pull request Jun 22, 2024
Add `ErrorGuaranteed` to `ast::ExprKind::Err`

See rust-lang#119967 for context
```
      \
       \
          _~^~^~_
      \) /  o o  \ (/
        '_   -   _'
        / '-----' \
```

r? fmease
@ShE3py ShE3py deleted the patkind-err branch May 3, 2025 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-patterns Relating to patterns and pattern matching S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants