Fix string for raw pointer deref suggestion
This commit is contained in:
parent
c2402dca85
commit
d6969ac2fb
5 changed files with 33 additions and 5 deletions
|
|
@ -3386,11 +3386,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
ty::RawPtr(..) => {
|
||||
let base = self.tcx.hir().node_to_pretty_string(base.id);
|
||||
let base = self.tcx.sess.source_map()
|
||||
.span_to_snippet(base.span)
|
||||
.unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string(base.id));
|
||||
let msg = format!("`{}` is a raw pointer; try dereferencing it", base);
|
||||
let suggestion = format!("(*{}).{}", base, field);
|
||||
err.span_suggestion_with_applicability(
|
||||
field.span,
|
||||
expr.span,
|
||||
&msg,
|
||||
suggestion,
|
||||
Applicability::MaybeIncorrect,
|
||||
|
|
|
|||
|
|
@ -2,13 +2,17 @@ error[E0609]: no field `x` on type `*mut A`
|
|||
--> $DIR/issue-11004.rs:17:21
|
||||
|
|
||||
LL | let x : i32 = n.x; //~ no field `x` on type `*mut A`
|
||||
| ^ help: `n` is a raw pointer; try dereferencing it: `(*n).x`
|
||||
| --^
|
||||
| |
|
||||
| help: `n` is a raw pointer; try dereferencing it: `(*n).x`
|
||||
|
||||
error[E0609]: no field `y` on type `*mut A`
|
||||
--> $DIR/issue-11004.rs:18:21
|
||||
|
|
||||
LL | let y : f64 = n.y; //~ no field `y` on type `*mut A`
|
||||
| ^ help: `n` is a raw pointer; try dereferencing it: `(*n).y`
|
||||
| --^
|
||||
| |
|
||||
| help: `n` is a raw pointer; try dereferencing it: `(*n).y`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
8
src/test/ui/parenthesised-deref-suggestion.rs
Normal file
8
src/test/ui/parenthesised-deref-suggestion.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
struct Session {
|
||||
opts: u8,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sess: &Session = &Session { opts: 0 };
|
||||
(sess as *const Session).opts; //~ ERROR no field `opts` on type `*const Session`
|
||||
}
|
||||
12
src/test/ui/parenthesised-deref-suggestion.stderr
Normal file
12
src/test/ui/parenthesised-deref-suggestion.stderr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
error[E0609]: no field `opts` on type `*const Session`
|
||||
--> $DIR/parenthesised-deref-suggestion.rs:7:30
|
||||
|
|
||||
LL | (sess as *const Session).opts; //~ ERROR no field `opts` on type `*const Session`
|
||||
| ^^^^
|
||||
help: `(sess as *const Session)` is a raw pointer; try dereferencing it
|
||||
|
|
||||
LL | (*(sess as *const Session)).opts; //~ ERROR no field `opts` on type `*const Session`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0609`.
|
||||
|
|
@ -2,7 +2,9 @@ error[E0609]: no field `f` on type `*const Rec`
|
|||
--> $DIR/unsafe-fn-autoderef.rs:29:14
|
||||
|
|
||||
LL | return p.f; //~ ERROR no field `f` on type `*const Rec`
|
||||
| ^ help: `p` is a raw pointer; try dereferencing it: `(*p).f`
|
||||
| --^
|
||||
| |
|
||||
| help: `p` is a raw pointer; try dereferencing it: `(*p).f`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue