rustc_span::CharPos实现了Pos trait,这个trait提供了to_usize方法。需要将这个trait引入到当前作用域才能使用该方法。

·

1 min read

CharPos类型没有to_usize方法。但是提示也给出了,CharPos实现了Pos trait,这个trait提供了to_usize方法。你需要将这个trait引入到当前作用域才能使用它的方法。

error[E0599]: no method named `to_usize` found for struct `CharPos` in the current scope
    --> src/ptr_provenance.rs:1769:81
     |
1769 | ...                   location.file.name, location.line, location.col.to_usize() + 1
     |                                                                       ^^^^^^^^ method not found in `CharPos`
     |
     = help: items from traits can only be used if the trait is in scope
     = note: the following trait is implemented but not in scope; perhaps add a `use` for it:
             `use crate::rustc_span::Pos;`

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0599`.