Skip to content

tweak "make mut" spans when assigning to locals - #110583

Merged
bors merged 7 commits into
rust-lang:masterfrom
Ezrashaw:tweak-make-mut-spans
May 9, 2023
Merged

tweak "make mut" spans when assigning to locals#110583
bors merged 7 commits into
rust-lang:masterfrom
Ezrashaw:tweak-make-mut-spans

Conversation

@Ezrashaw

Copy link
Copy Markdown
Contributor

Work towards fixing #106857

This PR just cleans up a lot of spans which is helpful before properly fixing the issues. Best reviewed commit-by-commit.

r? @estebank

@rustbotrustbot 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 Apr 20, 2023
Comment threadtests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm going to leave this for a follow-up PR if that's OK with you?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As it is causing a clear visual regression I would prefer to investigate further and try to land the whole fix in a single PR (to avoid risking this slipping into beta by accident simply because we forgot to follow up).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is now fixed, right?

@rust-log-analyzer

This comment has been minimized.

@Ezrashaw
Ezrashawforce-pushed the tweak-make-mut-spans branch from fb690f8 to 57d603eCompareApril 20, 2023 07:14
Comment threadcompiler/rustc_borrowck/src/diagnostics/mutability_errors.rs Outdated
Comment on lines +1267 to +1271
} else if binding_exists {
// shrink the span to just after the `&` in `&variable`
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
(true, span, "mut ".to_owned())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the test presenting the small regression, can you check that you're actually falling into this branch?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah it does. The problem is that there is a call to is_error_in_trait after this function returns which overwrites the returned span (but not the string suggestion) to point to the trait (if local).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I've fixed it so that we call is_error_in_trait before all the suggestion logic and integrate the spans from that. See the latest commit.

@Ezrashaw

Ezrashaw commented Apr 21, 2023

Copy link
Copy Markdown
ContributorAuthor

@estebankI'm going to add some more commits and fix that regression. (EDIT: done, ready for review) I suspect there will still be a follow-up PR so this one doesn't get too big.

@rustbot author
@rustbot ready

@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 21, 2023
@rust-log-analyzer

This comment has been minimized.

@Ezrashaw
Ezrashawforce-pushed the tweak-make-mut-spans branch 2 times, most recently from 3430a3e to 1f5ef60CompareApril 22, 2023 08:54
@bors

bors commented May 3, 2023

Copy link
Copy Markdown
Collaborator

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

Comment on lines 9 to +10
LL | fn reborrow_mut<'a>(t: &'a mut &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy {
| ~~~~~~~~~~~~~~~~~~~
| +++

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Love the result!

@estebank

Copy link
Copy Markdown
Contributor

Sorry I didn't re-review before the merge conflict. r=me after rebase.

@estebankestebank added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 5, 2023
@Ezrashaw
Ezrashawforce-pushed the tweak-make-mut-spans branch from 1f5ef60 to 13288d8CompareMay 5, 2023 10:44
@rust-log-analyzer

This comment has been minimized.

@Ezrashaw
Ezrashawforce-pushed the tweak-make-mut-spans branch from 13288d8 to 3e64e98CompareMay 5, 2023 11:12
@Ezrashaw

Copy link
Copy Markdown
ContributorAuthor

@estebank Since I don't have those fun r= perms, it'd be great if you could do that :)

@cjgillot

Copy link
Copy Markdown
Contributor

@bors r=estebank

@bors

bors commented May 7, 2023

Copy link
Copy Markdown
Collaborator

📌 Commit 3e64e98 has been approved by estebank

It is now in the queue for this repository.

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 7, 2023
@Dylan-DPCDylan-DPC mentioned this pull request May 9, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request May 9, 2023
Rollup of 7 pull requests
Successful merges:
- rust-lang#110304 (Add GNU Property Note)
- rust-lang#110504 (Tweak borrow suggestion span)
- rust-lang#110583 (tweak "make mut" spans when assigning to locals)
- rust-lang#110694 (Implement builtin # syntax and use it for offset_of!(...))
- rust-lang#111120 (Suggest let for possible binding with ty)
- rust-lang#111252 (Min specialization improvements)
- rust-lang#111361 (Update books)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit ff30b8c into rust-lang:masterMay 9, 2023
@rustbotrustbot added this to the 1.71.0 milestone May 9, 2023
@Ezrashaw
Ezrashaw deleted the tweak-make-mut-spans branch May 13, 2024 10:34
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

6 participants

@Ezrashaw@rust-log-analyzer@bors@estebank@cjgillot@rustbot