getsentry / pdb

A parser for Microsoft PDB (Program Database) debugging information
https://docs.rs/pdb/
Apache License 2.0
385 stars 69 forks source link

Usage Example throws all kind of errors #84

Closed serak closed 4 years ago

serak commented 4 years ago

this are the errors its throwing and its very confusion for newbies

warning: unused import: `std::fs::File`
 --> src\main.rs:4:5
  |
4 | use std::fs::File;
  |     ^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  --> src\main.rs:7:16
   |
6  | / fn main() {
7  | |     let file = std::fs::File::open("fixtures/self/foo.pdb")?;
   | |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
8  | |     let mut pdb = pdb::PDB::open(file)?;
9  | |
...  |
21 | |     }
22 | | }
   | |_- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `std::ops::Try` is not implemented for `()`
   = note: required by `std::ops::Try::from_error`

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  --> src\main.rs:8:19
   |
6  | / fn main() {
7  | |     let file = std::fs::File::open("fixtures/self/foo.pdb")?;
8  | |     let mut pdb = pdb::PDB::open(file)?;
   | |                   ^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
9  | |
...  |
21 | |     }
22 | | }
   | |_- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `std::ops::Try` is not implemented for `()`
   = note: required by `std::ops::Try::from_error`

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  --> src\main.rs:10:24
   |
6  | / fn main() {
7  | |     let file = std::fs::File::open("fixtures/self/foo.pdb")?;
8  | |     let mut pdb = pdb::PDB::open(file)?;
9  | |
10 | |     let symbol_table = pdb.global_symbols()?;
   | |                        ^^^^^^^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
...  |
21 | |     }
22 | | }
   | |_- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `std::ops::Try` is not implemented for `()`
   = note: required by `std::ops::Try::from_error`

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  --> src\main.rs:13:30
   |
6  | / fn main() {
7  | |     let file = std::fs::File::open("fixtures/self/foo.pdb")?;
8  | |     let mut pdb = pdb::PDB::open(file)?;
9  | |
...  |
13 | |     while let Some(symbol) = symbols.next()? {
   | |                              ^^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
...  |
21 | |     }
22 | | }
   | |_- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `std::ops::Try` is not implemented for `()`
   = note: required by `std::ops::Try::from_error`

error[E0599]: no variant named `PublicSymbol` found for enum `pdb::SymbolData<'_>`
  --> src\main.rs:15:33
   |
15 |             Ok(pdb::SymbolData::PublicSymbol{function: true, segment, offset, ..}) => {
   |                                 ^^^^^^^^^^^^ variant not found in `pdb::SymbolData<'_>`

error[E0599]: no method named `name` found for struct `pdb::Symbol<'_>` in the current scope
  --> src\main.rs:17:71
   |
17 |                 println!("{:x}:{:08x} is {}", segment, offset, symbol.name()?);
   |                                                                       ^^^^ method not found in `pdb::Symbol<'_>`

error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
  --> src\main.rs:17:64
   |
6  | / fn main() {
7  | |     let file = std::fs::File::open("fixtures/self/foo.pdb")?;
8  | |     let mut pdb = pdb::PDB::open(file)?;
9  | |
...  |
17 | |                 println!("{:x}:{:08x} is {}", segment, offset, symbol.name()?);
   | |                                                                ^^^^^^^^^^^^^^ cannot use the `?` operator in a function that returns `()`
...  |
21 | |     }
22 | | }
   | |_- this function should return `Result` or `Option` to accept `?`
   |
   = help: the trait `std::ops::Try` is not implemented for `()`
   = note: required by `std::ops::Try::from_error`

error: aborting due to 7 previous errors

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `rustpro`.

To learn more, run the command again with --verbose.
jan-auer commented 4 years ago

Thanks for reporting this, @serak! The example is now synchronized with the one from the top-level library docs.