Skip to content

Suppress wrapper suggestion when expected and actual ty are the same adt and the variant is unresolved #145361

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

Merged
merged 2 commits into from
Aug 14, 2025

Conversation

xizheyin
Copy link
Member

@xizheyin xizheyin commented Aug 13, 2025

Fixes #145294

I initially tried the desired suggestion in this issue, but since that suggestion occurs in the expected type, it is inappropriate to suggest for expected expressions (see other suggest methods in the same file). I believe that suppressing the incorrect suggestion is the more appropriate choice here.

I opted for a slightly more general approach: when the expected type and actual type are the same ADT (e.g., both are Result in this example), we assume that code tend to compare the internal generic parameters(i.e. Option<&str> vs Option<String>, instead of E = _ vs Result<Option<String>>>). When E is an unresolved infer type in the expected type (_ in this example), we should not wrapp the actual type.

Two commits show the difference.

r? compiler

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
…adt and the variant is unresolved

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
@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 13, 2025
@compiler-errors
Copy link
Member

r=me when CI is green

@bors delegate+

@bors
Copy link
Collaborator

bors commented Aug 13, 2025

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

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

@xizheyin
Copy link
Member Author

@bors r=@compiler-errors

@bors
Copy link
Collaborator

bors commented Aug 13, 2025

📌 Commit e0cc2be 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 13, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 14, 2025
Suppress wrapper suggestion when expected and actual ty are the same adt and the variant is unresolved

Fixes rust-lang#145294

I initially tried the desired suggestion in this issue, but since that suggestion occurs in the expected type, it is inappropriate to suggest for expected expressions (see other suggest methods in the same file). I believe that suppressing the incorrect suggestion is the more appropriate choice here.

I opted for a slightly more general approach: when the expected type and actual type are the same ADT (e.g., both are Result in this example), we assume that code tend to compare the internal generic parameters(i.e. `Option<&str>` vs `Option<String>`, instead of `E = _` vs `Result<Option<String>>>`). When `E` is an unresolved infer type in the expected type (`_` in this example), we should not wrapp the actual type.

Two commits show the difference.

r? compiler
bors added a commit that referenced this pull request Aug 14, 2025
Rollup of 13 pull requests

Successful merges:

 - #122661 (Change the desugaring of `assert!` for better error output)
 - #142372 (Improve `--remap-path-prefix` documentation)
 - #143075 (compiler: Allow `extern "interrupt" fn() -> !`)
 - #145005 (strip prefix of temporary file names when it exceeds filesystem name length limit)
 - #145065 (resolve: Introduce `RibKind::Block`)
 - #145120 (llvm: Accept new LLVM lifetime format)
 - #145189 (Weekly `cargo update`)
 - #145261 (Improve tracing in bootstrap)
 - #145266 (Reduce some queries around associated items)
 - #145299 (doc test: fix mpsc.rs try_send doc test)
 - #145331 (Make std use the edition 2024 prelude)
 - #145353 (bootstrap: Fix jemalloc 64K page support for aarch64 tools)
 - #145361 (Suppress wrapper suggestion when expected and actual ty are the same adt and the variant is unresolved)

Failed merges:

 - #145324 (Rename and document `ONLY_HOSTS` in bootstrap)
 - #145372 (resolve: Miscellaneous cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Aug 14, 2025
Rollup of 13 pull requests

Successful merges:

 - #122661 (Change the desugaring of `assert!` for better error output)
 - #142372 (Improve `--remap-path-prefix` documentation)
 - #143075 (compiler: Allow `extern "interrupt" fn() -> !`)
 - #145005 (strip prefix of temporary file names when it exceeds filesystem name length limit)
 - #145065 (resolve: Introduce `RibKind::Block`)
 - #145120 (llvm: Accept new LLVM lifetime format)
 - #145189 (Weekly `cargo update`)
 - #145261 (Improve tracing in bootstrap)
 - #145266 (Reduce some queries around associated items)
 - #145299 (doc test: fix mpsc.rs try_send doc test)
 - #145331 (Make std use the edition 2024 prelude)
 - #145353 (bootstrap: Fix jemalloc 64K page support for aarch64 tools)
 - #145361 (Suppress wrapper suggestion when expected and actual ty are the same adt and the variant is unresolved)

Failed merges:

 - #145324 (Rename and document `ONLY_HOSTS` in bootstrap)
 - #145372 (resolve: Miscellaneous cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Aug 14, 2025
Rollup of 13 pull requests

Successful merges:

 - #140434 (rustdoc: Allow multiple references to a single footnote)
 - #142372 (Improve `--remap-path-prefix` documentation)
 - #142741 (Fix unsoundness in some tests)
 - #144515 (Implement `ptr_cast_array`)
 - #144727 (Add tracing to resolve-related functions)
 - #144959 (fix(unicode-table-generator): fix duplicated unique indices)
 - #145179 (Avoid abbreviating "numerator" as "numer", to allow catching typo "numer" elsewhere)
 - #145250 (Add regression test for a former ICE involving helper attributes containing interpolated tokens)
 - #145266 (Reduce some queries around associated items)
 - #145299 (doc test: fix mpsc.rs try_send doc test)
 - #145323 (Port the `#[linkage]` attribute to the new attribute system)
 - #145361 (Suppress wrapper suggestion when expected and actual ty are the same adt and the variant is unresolved)
 - #145372 (resolve: Miscellaneous cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 707e956 into rust-lang:master Aug 14, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 14, 2025
rust-timer added a commit that referenced this pull request Aug 14, 2025
Rollup merge of #145361 - xizheyin:145294, r=compiler-errors

Suppress wrapper suggestion when expected and actual ty are the same adt and the variant is unresolved

Fixes #145294

I initially tried the desired suggestion in this issue, but since that suggestion occurs in the expected type, it is inappropriate to suggest for expected expressions (see other suggest methods in the same file). I believe that suppressing the incorrect suggestion is the more appropriate choice here.

I opted for a slightly more general approach: when the expected type and actual type are the same ADT (e.g., both are Result in this example), we assume that code tend to compare the internal generic parameters(i.e. `Option<&str>` vs `Option<String>`, instead of `E = _` vs `Result<Option<String>>>`). When `E` is an unresolved infer type in the expected type (`_` in this example), we should not wrapp the actual type.

Two commits show the difference.

r? compiler
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 15, 2025
Rollup of 13 pull requests

Successful merges:

 - rust-lang/rust#140434 (rustdoc: Allow multiple references to a single footnote)
 - rust-lang/rust#142372 (Improve `--remap-path-prefix` documentation)
 - rust-lang/rust#142741 (Fix unsoundness in some tests)
 - rust-lang/rust#144515 (Implement `ptr_cast_array`)
 - rust-lang/rust#144727 (Add tracing to resolve-related functions)
 - rust-lang/rust#144959 (fix(unicode-table-generator): fix duplicated unique indices)
 - rust-lang/rust#145179 (Avoid abbreviating "numerator" as "numer", to allow catching typo "numer" elsewhere)
 - rust-lang/rust#145250 (Add regression test for a former ICE involving helper attributes containing interpolated tokens)
 - rust-lang/rust#145266 (Reduce some queries around associated items)
 - rust-lang/rust#145299 (doc test: fix mpsc.rs try_send doc test)
 - rust-lang/rust#145323 (Port the `#[linkage]` attribute to the new attribute system)
 - rust-lang/rust#145361 (Suppress wrapper suggestion when expected and actual ty are the same adt and the variant is unresolved)
 - rust-lang/rust#145372 (resolve: Miscellaneous cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
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.

try wrapping the expression suggests wrapping Result with an extra Err
5 participants