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 std::ptr::null if literal 0 is given to a raw pointer function argument #107553

Merged
merged 1 commit into from
Feb 6, 2023

Conversation

edward-shen
Copy link
Contributor

Implementation feels a little sus (we're parsing the span for a 0) but it seems to fall in line the string-expected-found-char condition right above this check, so I think it's fine.

Feedback appreciated on help text? I think it's consistent but it does sound a little awkward maybe?

Fixes #107517

@rustbot
Copy link
Collaborator

rustbot commented Feb 1, 2023

r? @WaffleLapkin

(rustbot has picked a reviewer for you, use r? to override)

@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 Feb 1, 2023
compiler/rustc_infer/src/infer/error_reporting/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_infer/src/infer/error_reporting/mod.rs Outdated Show resolved Hide resolved
tests/ui/suggest-null-ptr.rs Outdated Show resolved Hide resolved
@edward-shen edward-shen force-pushed the edward-shen/suggest-null-ptr branch from ea646ea to ff9415a Compare February 1, 2023 09:19
@edward-shen
Copy link
Contributor Author

edward-shen commented Feb 1, 2023

Changes:

  • Added run-runfix directive and a .fixed file
  • s/rustc_hir/hir/
  • Added suggestion for `_mut() variant.
  • Finished my actual comment in the test.

@edward-shen edward-shen force-pushed the edward-shen/suggest-null-ptr branch from ff9415a to cce8a76 Compare February 1, 2023 09:30
@workingjubilee
Copy link
Member

workingjubilee commented Feb 1, 2023

c_char is understood to mean i8 in some cases, it is surprising this suggestion would be limited to *const u8, etc.

@Noratrieb
Copy link
Member

The diagnostic fires for raw pointers no matter the type behind it.

@edward-shen
Copy link
Contributor Author

Yeah, I think the commit name is better, let me update the PR name to better reflect the changes. Sorry for the confusion.

@edward-shen edward-shen changed the title Suggest std::ptr::null if given 0 to *const uint arg Suggest std::ptr::null if literal 0 is given to a raw pointer function argument Feb 1, 2023
@workingjubilee
Copy link
Member

ferris clueless
Ope, my bad.

@edward-shen edward-shen force-pushed the edward-shen/suggest-null-ptr branch from cce8a76 to 3296729 Compare February 5, 2023 04:14
@edward-shen
Copy link
Contributor Author

Changes:

  • Moved logic into a new function that is called by FnCtxt::emit_type_mismatch_suggestions
  • Cleaned up logic now that we have information about the HIR
  • Used with_no_trimmed_paths to print the diagnostic item instead.

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

Thanks!

@WaffleLapkin
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 6, 2023

📌 Commit 3296729 has been approved by WaffleLapkin

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 Feb 6, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2023
Rollup of 5 pull requests

Successful merges:

 - rust-lang#107553 (Suggest std::ptr::null if literal 0 is given to a raw pointer function argument)
 - rust-lang#107580 (Recover from lifetimes with default lifetimes in generic args)
 - rust-lang#107669 (rustdoc: combine duplicate rules in ayu CSS)
 - rust-lang#107685 (Suggest adding a return type for async functions)
 - rust-lang#107687 (Adapt SROA MIR opt for aggregated MIR)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 496adf8 into rust-lang:master Feb 6, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 6, 2023
@edward-shen edward-shen deleted the edward-shen/suggest-null-ptr branch February 7, 2023 21:18
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.

Add help when trying to use literal 0 as raw pointer
7 participants