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

suggest type annotation for local statement initialed by ref expression #102951

Merged
merged 1 commit into from
Oct 26, 2022

Conversation

SparrowLii
Copy link
Member

In a local statement with a type declaration, if a ref expression is used on the right side and not used on the left side, in addition to removing the & and &mut on the right side, we can add them on the left side alternatively
Fixes #102892

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 12, 2022
@rust-highfive
Copy link
Collaborator

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 12, 2022
let suggest_annotation = match expr.peel_drop_temps().kind {
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, _) => "&",
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, _) => "&mut ",
_ => return true,
Copy link
Member

Choose a reason for hiding this comment

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

This should return false, since we didn't actually suggest anything I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

The err.span_suggestion statement above has made some modifications to err, I guess that might be the reason why we should return true here as well?

Copy link
Member

Choose a reason for hiding this comment

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

oh, didn't even see that. yeah, makes sense. 👍

@bors
Copy link
Contributor

bors commented Oct 21, 2022

☔ The latest upstream changes (presumably #103310) made this pull request unmergeable. Please resolve the merge conflicts.

@estebank
Copy link
Contributor

r=me after rebasing

@SparrowLii
Copy link
Member Author

@estebank Done. But I don't have the privilege so it still needs you to r+

@SparrowLii
Copy link
Member Author

@bors r=estebank

@bors
Copy link
Contributor

bors commented Oct 24, 2022

@SparrowLii: 🔑 Insufficient privileges: Not in reviewers

@compiler-errors
Copy link
Member

@bors r=estebank

@bors
Copy link
Contributor

bors commented Oct 24, 2022

📌 Commit 0fca075 has been approved by estebank

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 Oct 24, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 25, 2022
…bank

suggest type annotation for local statement initialed by ref expression

In a local statement with a type declaration, if a ref expression is used on the right side and not used on the left side, in addition to removing the `&` and `&mut` on the right side, we can add them on the left side alternatively
Fixes rust-lang#102892
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Oct 25, 2022
…bank

suggest type annotation for local statement initialed by ref expression

In a local statement with a type declaration, if a ref expression is used on the right side and not used on the left side, in addition to removing the `&` and `&mut` on the right side, we can add them on the left side alternatively
Fixes rust-lang#102892
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 26, 2022
Rollup of 10 pull requests

Successful merges:

 - rust-lang#102951 (suggest type annotation for local statement initialed by ref expression)
 - rust-lang#103209 (Diagnostic derives: allow specifying multiple alternative suggestions)
 - rust-lang#103287 (Use a faster allocation size check in slice::from_raw_parts)
 - rust-lang#103416 (Name the `impl Trait` in region bound suggestions)
 - rust-lang#103430 (Workaround unstable stmt_expr_attributes for method receiver expressions)
 - rust-lang#103444 (Remove extra type error after missing semicolon error)
 - rust-lang#103520 (rustc_middle: Rearrange resolver outputs structures slightly)
 - rust-lang#103533 (Use &self instead of &mut self for cast methods)
 - rust-lang#103536 (Remove `rustc_driver::set_sigpipe_handler()`)
 - rust-lang#103542 (Pinning tests for some `macro_rules!` errors discussed in the lang meeting)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit bf6bfcd into rust-lang:master Oct 26, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 26, 2022
pietroalbini added a commit to ferrocene/sphinx-shared-resources that referenced this pull request Mar 22, 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.

vicious "add &" then "remove &" cycle of suggestions
6 participants