-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Rework ptr-to-ref conversion suggestion for method calls #123007
Merged
bors
merged 3 commits into
rust-lang:master
from
kadiwa4:suggest_convert_ptr_to_mut_ref
Apr 11, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
fn main() { | ||
let mut x = 8u8; | ||
let z: *const u8 = &x; | ||
// issue #21596 | ||
println!("{}", z.to_string()); //~ ERROR E0599 | ||
|
||
let t: *mut u8 = &mut x; | ||
println!("{}", t.to_string()); //~ ERROR E0599 | ||
t.make_ascii_lowercase(); //~ ERROR E0599 | ||
|
||
// suggest `as_mut` simply because the name is similar | ||
let _ = t.as_mut_ref(); //~ ERROR E0599 | ||
let _ = t.as_ref_mut(); //~ ERROR E0599 | ||
|
||
// no ptr-to-ref suggestion | ||
z.make_ascii_lowercase(); //~ ERROR E0599 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
error[E0599]: `*const u8` doesn't implement `std::fmt::Display` | ||
--> $DIR/suggest-convert-ptr-to-ref.rs:5:22 | ||
| | ||
LL | println!("{}", z.to_string()); | ||
| ^^^^^^^^^ `*const u8` cannot be formatted with the default formatter | ||
| | ||
note: the method `to_string` exists on the type `&u8` | ||
--> $SRC_DIR/alloc/src/string.rs:LL:COL | ||
= note: you might want to use the unsafe method `<*const T>::as_ref` to get an optional reference to the value behind the pointer | ||
= note: read the documentation for `<*const T>::as_ref` and ensure you satisfy its safety preconditions before calling it to avoid undefined behavior: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref | ||
= note: the following trait bounds were not satisfied: | ||
`*const u8: std::fmt::Display` | ||
which is required by `*const u8: ToString` | ||
|
||
error[E0599]: `*mut u8` doesn't implement `std::fmt::Display` | ||
--> $DIR/suggest-convert-ptr-to-ref.rs:8:22 | ||
| | ||
LL | println!("{}", t.to_string()); | ||
| ^^^^^^^^^ `*mut u8` cannot be formatted with the default formatter | ||
| | ||
note: the method `to_string` exists on the type `&&mut u8` | ||
--> $SRC_DIR/alloc/src/string.rs:LL:COL | ||
= note: you might want to use the unsafe method `<*mut T>::as_ref` to get an optional reference to the value behind the pointer | ||
= note: read the documentation for `<*mut T>::as_ref` and ensure you satisfy its safety preconditions before calling it to avoid undefined behavior: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref-1 | ||
= note: the following trait bounds were not satisfied: | ||
`*mut u8: std::fmt::Display` | ||
which is required by `*mut u8: ToString` | ||
|
||
error[E0599]: no method named `make_ascii_lowercase` found for raw pointer `*mut u8` in the current scope | ||
--> $DIR/suggest-convert-ptr-to-ref.rs:9:7 | ||
| | ||
LL | t.make_ascii_lowercase(); | ||
| ^^^^^^^^^^^^^^^^^^^^ method not found in `*mut u8` | ||
| | ||
note: the method `make_ascii_lowercase` exists on the type `&mut u8` | ||
--> $SRC_DIR/core/src/num/mod.rs:LL:COL | ||
= note: you might want to use the unsafe method `<*mut T>::as_mut` to get an optional reference to the value behind the pointer | ||
= note: read the documentation for `<*mut T>::as_mut` and ensure you satisfy its safety preconditions before calling it to avoid undefined behavior: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_mut | ||
|
||
error[E0599]: no method named `as_mut_ref` found for raw pointer `*mut u8` in the current scope | ||
--> $DIR/suggest-convert-ptr-to-ref.rs:12:15 | ||
| | ||
LL | let _ = t.as_mut_ref(); | ||
| ^^^^^^^^^^ | ||
| | ||
help: there is a method `as_mut` with a similar name | ||
| | ||
LL | let _ = t.as_mut(); | ||
| ~~~~~~ | ||
|
||
error[E0599]: no method named `as_ref_mut` found for raw pointer `*mut u8` in the current scope | ||
--> $DIR/suggest-convert-ptr-to-ref.rs:13:15 | ||
| | ||
LL | let _ = t.as_ref_mut(); | ||
| ^^^^^^^^^^ | ||
| | ||
help: there is a method `as_mut` with a similar name | ||
| | ||
LL | let _ = t.as_mut(); | ||
| ~~~~~~ | ||
|
||
error[E0599]: no method named `make_ascii_lowercase` found for raw pointer `*const u8` in the current scope | ||
--> $DIR/suggest-convert-ptr-to-ref.rs:16:7 | ||
| | ||
LL | z.make_ascii_lowercase(); | ||
| ^^^^^^^^^^^^^^^^^^^^ method not found in `*const u8` | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't know if this is the right lifetime to use.