Skip to content

Commit eb73b73

Browse files
committed
Suggest using as_ref on *const T
1 parent 7840a0b commit eb73b73

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/librustc_typeck/check/method/suggest.rs

+5
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
324324
);
325325
}
326326
}
327+
if let ty::RawPtr(_) = &actual.sty {
328+
err.note("try using `<*const T>::as_ref()` to get a reference to the \
329+
type behind the pointer: https://doc.rust-lang.org/std/\
330+
primitive.pointer.html#method.as_ref");
331+
}
327332
err
328333
}
329334
} else {

src/test/ui/issues/issue-21596.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
let x = 8u8;
3+
let z: *const u8 = &x;
4+
println!("{}", z.to_string()); //~ ERROR E0599
5+
}

src/test/ui/issues/issue-21596.stderr

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0599]: no method named `to_string` found for type `*const u8` in the current scope
2+
--> $DIR/issue-21596.rs:4:22
3+
|
4+
LL | println!("{}", z.to_string());
5+
| ^^^^^^^^^
6+
|
7+
= note: try using `<*const T>::as_ref()` to get a reference to the type behind the pointer: https://doc.rust-lang.org/std/primitive.pointer.html#method.as_ref
8+
= note: the method `to_string` exists but the following trait bounds were not satisfied:
9+
`*const u8 : std::string::ToString`
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)