-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
add parentheses when unboxing suggestion needed #132944
add parentheses when unboxing suggestion needed #132944
Conversation
r? @chenyukang rustbot has assigned @chenyukang. Use |
@@ -2869,6 +2861,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
return None; | |||
} | |||
|
|||
if checked_ty.is_box() && self.is_need_parenthesize(expr) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn is_need_parenthesize(&self, expr: &hir::Expr<'_>) -> bool { | |
fn needs_parentheses(&self, expr: &hir::Expr<'_>) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
53c5c5d
to
949cf61
Compare
@bors r+ rollup |
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
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
This PR tried to
add parentheses when unboxing suggestion needed
Fixes #132924