-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
tests/ui/suggestions/dont_suggest_raw_pointer_syntax-issue-127562.stderr
Outdated
Show resolved
Hide resolved
tests/ui/suggestions/dont_suggest_raw_pointer_syntax-issue-127562.stderr
Outdated
Show resolved
Hide resolved
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 @bors r+ rollup |
@bors r+ rollup |
… r=fee1-dead Remove invalid help diagnostics for const pointer Partially addresses rust-lang#127562
…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
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. I will have a dig on why the ill-type code suggestion comes out when span is remapped. |
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? |
Seems the document for this is at here:
so when the code logic is base on something like Err(SourceNotAvailable { filename: Real(Remapped { local_path: None, virtual_name: "$SRC_DIR/core/src/ptr/mod.rs" }) }) then the code flow changes... |
This new change will resolve this specific invalid suggestion in the UI test: @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. |
ffd14ba
to
3d85723
Compare
3d85723
to
7ff71e5
Compare
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! |
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. |
@chenyukang |
I think we could merge this PR first and create a new issue to track the test suite issue in #127675 (comment) ? |
cc @fee1-dead |
r? compiler |
sugg, | ||
Applicability::MachineApplicable, | ||
); | ||
if sugg.iter().all(|(span, _)| !self.infcx.tcx.sess.source_map().is_imported(*span)) |
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.
The source of the problem here is that the suggestion points inside a macro. This is IMO not something that should be fixed in this specific diagnostic, it affects all daignostics and thus needs a central fix.
I don't know the diagnostic system well enough though to suggest how this could be fixed.
Cc @rust-lang/wg-diagnostics
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.
The "suggestion points inside a macro" problem is generally hard to solve, which is why very often suggestions just bail on Span::from_expansion
. When this is not acceptable, then people sometimes use e.g.
- https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/span_encoding/struct.Span.html#method.find_ancestor_inside
- https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/span_encoding/struct.Span.html#method.find_ancestor_in_same_ctxt
- https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/span_encoding/struct.Span.html#method.find_ancestor_inside_same_ctxt
- https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/span_encoding/struct.Span.html#method.find_oldest_ancestor_in_same_ctxt
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.
Hm, that's not what this code does though?
I filed an issue for that: #131782 |
@bors r+ |
…iaskrgr Rollup of 12 pull requests Successful merges: - rust-lang#116863 (warn less about non-exhaustive in ffi) - rust-lang#127675 (Remove invalid help diagnostics for const pointer) - rust-lang#131772 (Remove `const_refs_to_static` TODO in proc_macro) - rust-lang#131789 (Make sure that outer opaques capture inner opaques's lifetimes even with precise capturing syntax) - rust-lang#131795 (Stop inverting expectation in normalization errors) - rust-lang#131920 (Add codegen test for branchy bool match) - rust-lang#131921 (replace STATX_ALL with (STATX_BASIC_STATS | STATX_BTIME) as former is deprecated) - rust-lang#131925 (Warn on redundant `--cfg` directive when revisions are used) - rust-lang#131931 (Remove unnecessary constness from `lower_generic_args_of_path`) - rust-lang#131932 (use tracked_path in rustc_fluent_macro) - rust-lang#131936 (feat(rustdoc-json-types): introduce rustc-hash feature) - rust-lang#131939 (Get rid of `OnlySelfBounds`) Failed merges: - rust-lang#131181 (Compiletest: Custom differ) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127675 - chenyukang:yukang-fix-127562-addr, r=petrochenkov Remove invalid help diagnostics for const pointer Partially addresses rust-lang#127562
This PR does not even fully solve the invalid diagnostic problem though: while fn main() {
let val = 2;
let ptr = &raw const val;
unsafe { *ptr = 3; }
} Error:
|
Yes, the original issue is not closed, this PR only remove this part, we should not suggest code change for any span which is not written by user: help: consider changing this to be a mutable pointer
--> /home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:2189:6
|
21| &mut raw const $place
| +++ |
Partially addresses #127562