Skip to content

add parentheses when unboxing suggestion needed #132944

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

linyihai
Copy link
Contributor

This PR tried to add parentheses when unboxing suggestion needed

Fixes #132924

@rustbot
Copy link
Collaborator

rustbot commented Nov 12, 2024

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Nov 12, 2024
@@ -2869,6 +2861,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return None;
}

if checked_ty.is_box() && self.is_need_parenthesize(expr) {
Copy link
Member

Choose a reason for hiding this comment

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

I presume due to the is_box(), the following code still leads to an invalid suggestion?

fn main() {
    let x = std::rc::Rc::new(Some(1)); 
    let test: Option<i32> = x as std::rc::Rc<Option<i32>>;
}

I guess you can remove that box check?

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 guess you can remove that box check?

Thank you. Updated.

@@ -2897,6 +2902,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false
}

fn is_need_parenthesize(&self, expr: &hir::Expr<'_>) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn is_need_parenthesize(&self, expr: &hir::Expr<'_>) -> bool {
fn needs_parentheses(&self, expr: &hir::Expr<'_>) -> bool {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@linyihai linyihai force-pushed the needing-parenthases-issue-132924 branch from 53c5c5d to 949cf61 Compare November 12, 2024 10:32
@chenyukang
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 18, 2024

📌 Commit 949cf61 has been approved by chenyukang

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 Nov 18, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2024
Rollup of 7 pull requests

Successful merges:

 - rust-lang#132795 (Check `use<..>` in RPITIT for refinement)
 - rust-lang#132944 (add parentheses when unboxing suggestion needed)
 - rust-lang#132993 (Make rustc consider itself a stable compiler when `RUSTC_BOOTSTRAP=-1`)
 - rust-lang#133130 (`suggest_borrow_generic_arg`: instantiate clauses properly)
 - rust-lang#133133 (rustdoc-search: add standalone trailing `::` test)
 - rust-lang#133143 (Diagnostics for let mut in item context)
 - rust-lang#133147 (Fixup some test directives)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c874121 into rust-lang:master Nov 18, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2024
Rollup merge of rust-lang#132944 - linyihai:needing-parenthases-issue-132924, r=chenyukang

add parentheses when unboxing suggestion needed

This PR tried to `add parentheses when unboxing suggestion needed`

Fixes rust-lang#132924
@linyihai linyihai deleted the needing-parenthases-issue-132924 branch November 19, 2024 00:59
# for free to join this conversation on GitHub. Already have an account? # 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.

Unboxing suggestion does not add parentheses where needed
5 participants