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

Remove invalid help diagnostics for const pointer #127675

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chenyukang
Copy link
Member

@chenyukang chenyukang commented Jul 13, 2024

Partially addresses #127562

@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
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 Jul 13, 2024
LL | *ptr = 3;
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
|
help: consider specifying this binding's type
Copy link
Member Author

Choose a reason for hiding this comment

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

This diagnostic comes out only in UI test, but will not come out when run in command line, this is because of #127562 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

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

originally because span location here is remapped:
https://github.com/chenyukang/rust/blob/b44a48416d06524da2ea247f1d1973d85ef514f8/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs#L1133

$SRC_DIR/core/src/ptr/mod.rs:LL:COL (#4), location: bb0[4]

|
help: consider specifying this binding's type
|
LL | let ptr: *mut i32 = std::ptr::addr_of!(val);
Copy link
Member

Choose a reason for hiding this comment

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

This suggestion leads to ill-typed code so something is clearly still going wrong here.

@fee1-dead
Copy link
Member

fee1-dead commented Jul 15, 2024

I have edited the PR description so that merging this PR does not close that issue. The best diagnostic improvement in that case would be suggesting addr_of! to be changed to addr_of_mut!.

@bors r+ rollup

@fee1-dead
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jul 15, 2024

📌 Commit b44a484 has been approved by fee1-dead

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 Jul 15, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 15, 2024
… r=fee1-dead

Remove invalid help diagnostics for const pointer

Partially addresses rust-lang#127562
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 15, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#124921 (offset_from: always allow pointers to point to the same address)
 - rust-lang#127407 (Make parse error suggestions verbose and fix spans)
 - rust-lang#127675 (Remove invalid help diagnostics for const pointer)
 - rust-lang#127684 (consolidate miri-unleashed tests for mutable refs into one file)
 - rust-lang#127758 (coverage: Restrict `ExpressionUsed` simplification to `Code` mappings)

r? `@ghost`
`@rustbot` modify labels: rollup
@RalfJung
Copy link
Member

Wait but this still suggests ill-typed code, doesn't it?

@fee1-dead
Copy link
Member

Wait but this still suggests ill-typed code, doesn't it?

Huh. Hold on. The original issue doesn't even reproduce with latest nightly: https://rust.godbolt.org/z/c5vYcfY7d.

I'm less sure that this is actually fixing what it is supposed to be fixing.

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 15, 2024
@chenyukang
Copy link
Member Author

Wait but this still suggests ill-typed code, doesn't it?

Huh. Hold on. The original issue doesn't even reproduce with latest nightly: https://rust.godbolt.org/z/c5vYcfY7d.

I'm less sure that this is actually fixing what it is supposed to be fixing.

@bors r-

I think godbolt does some similar span remap with test UI framework.
We can reproduce the original issue on playground and nightly command line:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f0b69f8ac092cab9389293dffb523cba

I will have a dig on why the ill-type code suggestion comes out when span is remapped.

@RalfJung
Copy link
Member

It is also quite concerning that the ui test suite produces different results than playground... that's a disaster for testability of this bug. Is there an issue tracking that mismatch? Any idea how it can be fixed?

@chenyukang
Copy link
Member Author

chenyukang commented Jul 15, 2024

Seems the document for this is at here:
https://github.com/rust-lang/rustc-dev-guide/blob/d6e3a32a557db5902e714604def8015d6bb7e0f7/src/tests/ui.md#L114

The directory to the standard library source is replaced with $SRC_DIR. Example: /path/to/rust/library
Line and column numbers for paths in $SRC_DIR are replaced with LL:COL.
This helps ensure that changes to the layout of the standard library do not cause widespread changes to the .stderr files. Example: $SRC_DIR/alloc/src/sync.rs:53:46

so when the code logic is base on something like tcx.sess.source_map().span_to_snippet(span), it will return an Err:

Err(SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/core/src/ptr/mod.rs" }) })

then the code flow changes...

@chenyukang
Copy link
Member Author

chenyukang commented Jul 15, 2024

This new change will resolve this specific invalid suggestion in the UI test:
https://github.com/rust-lang/rust/pull/127675/files#diff-23edf23f7466b97eb3154b82f7b324983287c327937fd66e854b3df6759926ceR1149-R1154

@oli-obk told me we had several issues like this, I'm not sure whether we can get an more general to avoid different results between the UI test and playground.

@RalfJung
Copy link
Member

Seems the document for this is at here: https://github.com/rust-lang/rustc-dev-guide/blob/d6e3a32a557db5902e714604def8015d6bb7e0f7/src/tests/ui.md#L114

The directory to the standard library source is replaced with $SRC_DIR. Example: /path/to/rust/library
Line and column numbers for paths in $SRC_DIR are replaced with LL:COL.
This helps ensure that changes to the layout of the standard library do not cause widespread changes to the .stderr files. Example: $SRC_DIR/alloc/src/sync.rs:53:46

so when the code logic is base on something like tcx.sess.source_map().span_to_snippet(span), it will return an Err:

Err(SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/core/src/ptr/mod.rs" }) })

then the code flow changes...

No, that just does some post-processing of the output, so that can't be it.

@oli-obk do you understand what is going on here? We should definitely have an issue about this -- when I copy some code from the playground to a ui test, it should behave the same, otherwise we aren't even testing the thing that people will be using in the wild!

@oli-obk
Copy link
Contributor

oli-obk commented Jul 16, 2024

idk, we do try to actually do what happens outside of the test suite, but there are some corner cases around libstd that are not easy and no one felt like it's too important to actually work on it.

@lolbinarycat lolbinarycat added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants