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

Point at return type when it influences non-first match arm #114819

Merged
merged 4 commits into from
Aug 15, 2023

Conversation

estebank
Copy link
Contributor

When encountering code like

fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}

Point at the return type and not at the prior arm, as that arm has type ! which isn't influencing the arm corresponding to arm 2.

Fix #78124.

@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2023

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@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. labels Aug 14, 2023
@@ -402,7 +402,7 @@ pub enum ObligationCauseCode<'tcx> {
OpaqueReturnType(Option<(Ty<'tcx>, Span)>),

/// Block implicit return
BlockTailExpression(hir::HirId),
BlockTailExpression(hir::HirId, hir::HirId, hir::MatchSource),
Copy link
Member

Choose a reason for hiding this comment

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

Can you make these fields have names?

@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2023

Some changes might have occurred in exhaustiveness checking

cc @Nadrieril

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type
`!` which isn't influencing the arm corresponding to arm `2`.

Fix rust-lang#78124.
Copy link
Member

@compiler-errors compiler-errors 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 if ci passes

@@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> {
};

if true {
//~^ ERROR: this `if` has identical blocks
// FIXME: should emit "this `if` has identical blocks"
Copy link
Member

Choose a reason for hiding this comment

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

Do you know why this regressed?

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 15, 2023

📌 Commit 58aa903 has been approved by compiler-errors

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 Aug 15, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 15, 2023
…rrors

Point at return type when it influences non-first `match` arm

When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`.

Fix rust-lang#78124.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 15, 2023
…rrors

Point at return type when it influences non-first `match` arm

When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`.

Fix rust-lang#78124.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 15, 2023
…rrors

Point at return type when it influences non-first `match` arm

When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`.

Fix rust-lang#78124.
@@ -149,7 +149,7 @@ fn expr_search_pat(tcx: TyCtxt<'_>, e: &Expr<'_>) -> (Pat, Pat) {
(Pat::Str("for"), Pat::Str("}"))
},
ExprKind::Match(_, _, MatchSource::Normal) => (Pat::Str("match"), Pat::Str("}")),
ExprKind::Match(e, _, MatchSource::TryDesugar) => (expr_search_pat(tcx, e).0, Pat::Str("?")),
ExprKind::Match(e, _, MatchSource::TryDesugar(_)) => (expr_search_pat(tcx, e).0, Pat::Str("?")),
Copy link
Member

Choose a reason for hiding this comment

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

This might be the reason for the Clippy regression. Did the expression e that is stored in the ExprKind::Match change by any chance and that's why re-calling expr_search_pat leads to different results than before? 🤔

(Pretty wild guess)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take a look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing in #115122

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 15, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#114588 (Improve docs for impl Default for ExitStatus)
 - rust-lang#114619 (Fix pthread_attr_union layout on Wasi)
 - rust-lang#114644 (Point out expectation even if we have `TypeError::RegionsInsufficientlyPolymorphic`)
 - rust-lang#114668 (Deny `FnDef` in patterns)
 - rust-lang#114819 (Point at return type when it influences non-first `match` arm)
 - rust-lang#114826 (Fix typos)
 - rust-lang#114837 (add missing feature(error_in_core))
 - rust-lang#114853 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8db5a6d into rust-lang:master Aug 15, 2023
11 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Aug 15, 2023
estebank added a commit to estebank/rust that referenced this pull request Aug 23, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 23, 2023
Fix clippy lint for identical `if`/`else` contraining `?` expressions

Follow up to rust-lang#114819.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Aug 23, 2023
Fix clippy lint for identical `if`/`else` contraining `?` expressions

Follow up to rust-lang#114819.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 24, 2023
…rrors

Point at return type when it influences non-first `match` arm

When encountering code like

```rust
fn foo() -> i32 {
    match 0 {
        1 => return 0,
        2 => "",
        _ => 1,
    }
}
```

Point at the return type and not at the prior arm, as that arm has type `!` which isn't influencing the arm corresponding to arm `2`.

Fix rust-lang#78124.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misleading compile error message when checking match arm types.
7 participants