Fix string for array access suggestion
This commit is contained in:
parent
d6969ac2fb
commit
030987481b
3 changed files with 15 additions and 1 deletions
|
|
@ -3372,7 +3372,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
len.assert_usize(self.tcx),
|
||||
field.as_str().parse::<u64>()
|
||||
) {
|
||||
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 help = "instead of using tuple indexing, use array indexing";
|
||||
let suggestion = format!("{}[{}]", base, field);
|
||||
let applicability = if len < user_index {
|
||||
|
|
|
|||
|
|
@ -5,4 +5,7 @@ struct Session {
|
|||
fn main() {
|
||||
let sess: &Session = &Session { opts: 0 };
|
||||
(sess as *const Session).opts; //~ ERROR no field `opts` on type `*const Session`
|
||||
|
||||
let x = [0u32];
|
||||
(x as [u32; 1]).0; //~ ERROR no field `0` on type `[u32; 1]`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,15 @@ 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[E0609]: no field `0` on type `[u32; 1]`
|
||||
--> $DIR/parenthesised-deref-suggestion.rs:10:21
|
||||
|
|
||||
LL | (x as [u32; 1]).0; //~ ERROR no field `0` on type `[u32; 1]`
|
||||
| ----------------^
|
||||
| |
|
||||
| help: instead of using tuple indexing, use array indexing: `(x as [u32; 1])[0]`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0609`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue