Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"method backtrace is not a member of trait StdError" #254

Closed
Berrysoft opened this issue Aug 11, 2022 · 6 comments
Closed

"method backtrace is not a member of trait StdError" #254

Berrysoft opened this issue Aug 11, 2022 · 6 comments

Comments

@Berrysoft
Copy link

In recent nightly std, the trait std::error::Error doesn't contain method backtrace, which makes anyhow fail to compile. Actually the rust-analyzer complains.

@dtolnay
Copy link
Owner

dtolnay commented Aug 11, 2022

Since you mentioned rust-analyzer, I'm guessing this is a duplicate of #250.

@dtolnay dtolnay closed this as completed Aug 11, 2022
@Berrysoft
Copy link
Author

Not exactly. It reports different error:

[ERROR rust_analyzer::lsp_utils] failed to run build scripts

error[E0407]: method `backtrace` is not a member of trait `StdError`
   --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\context.rs:127:5
    |
127 | /     fn backtrace(&self) -> Option<&Backtrace> {
128 | |         self.error.backtrace()
129 | |     }
    | |_____^ not a member of trait `StdError`


error[E0407]: method `backtrace` is not a member of trait `StdError`
   --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\context.rs:141:5
    |
141 | /     fn backtrace(&self) -> Option<&Backtrace> {
142 | |         Some(self.error.backtrace())
143 | |     }
    | |_____^ not a member of trait `StdError`


error[E0407]: method `backtrace` is not a member of trait `StdError`
   --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\error.rs:907:5
    |
907 | /     fn backtrace(&self) -> Option<&Backtrace> {
908 | |         Some(unsafe { ErrorImpl::backtrace(self.erase()) })
909 | |     }
    | |_____^ not a member of trait `StdError`


error[E0407]: method `backtrace` is not a member of trait `StdError`
  --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\wrapper.rs:71:5
   |
71 | /     fn backtrace(&self) -> Option<&crate::backtrace::Backtrace> {
72 | |         self.0.backtrace()
73 | |     }
   | |_____^ not a member of trait `StdError`


error[E0599]: no method named `backtrace` found for type parameter `E` in the current scope
  --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\backtrace.rs:41:20
   |
41 |         match $err.backtrace() {
   |                    ^^^^^^^^^ method not found in `E`
   |
  ::: C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\context.rs:19:10
   |
19 |     impl<E> StdError for E
   |          - method `backtrace` not found for this type parameter
...
27 |             let backtrace = backtrace_if_absent!(self);
   |                             -------------------------- in this macro invocation
   |
   = note: this error originates in the macro `backtrace_if_absent` (in Nightly builds, run with -Z macro-backtrace for more info)


error[E0599]: no method named `backtrace` found for type parameter `E` in the current scope
   --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\context.rs:128:20
    |
121 | impl<C, E> StdError for ContextError<C, E>
    |         - method `backtrace` not found for this type parameter
...
128 |         self.error.backtrace()
    |                    ^^^^^^^^^ method not found in `E`


error[E0599]: no method named `backtrace` found for type parameter `E` in the current scope
  --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\backtrace.rs:41:20
   |
41 |         match $err.backtrace() {
   |                    ^^^^^^^^^ method not found in `E`
   |
  ::: C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\error.rs:30:16
   |
30 |     pub fn new<E>(error: E) -> Self
   |                - method `backtrace` not found for this type parameter
...
34 |         let backtrace = backtrace_if_absent!(error);
   |                         --------------------------- in this macro invocation
   |
   = note: this error originates in the macro `backtrace_if_absent` (in Nightly builds, run with -Z macro-backtrace for more info)


error[E0599]: no method named `backtrace` found for type parameter `E` in the current scope
   --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\backtrace.rs:41:20
    |
41  |         match $err.backtrace() {
    |                    ^^^^^^^^^ method not found in `E`
    |
   ::: C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\error.rs:527:6
    |
527 | impl<E> From<E> for Error
    |      - method `backtrace` not found for this type parameter
...
533 |         let backtrace = backtrace_if_absent!(error);
    |                         --------------------------- in this macro invocation
    |
    = note: this error originates in the macro `backtrace_if_absent` (in Nightly builds, run with -Z macro-backtrace for more info)


error[E0599]: no method named `backtrace` found for reference `&(dyn std::error::Error + Send + Sync + 'static)` in the current scope
   --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\error.rs:889:42
    |
889 |                 return Self::error(this).backtrace();
    |                                          ^^^^^^^^^ method not found in `&(dyn std::error::Error + Send + Sync + 'static)`


error[E0599]: no method named `backtrace` found for struct `Box<(dyn std::error::Error + Send + Sync + 'static)>` in the current scope
   --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\backtrace.rs:41:20
    |
41  |         match $err.backtrace() {
    |                    ^^^^^^^^^ method not found in `Box<(dyn std::error::Error + Send + Sync + 'static)>`
    |
   ::: C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\kind.rs:113:25
    |
113 |         let backtrace = backtrace_if_absent!(error);
    |                         --------------------------- in this macro invocation
    |
    = note: this error originates in the macro `backtrace_if_absent` (in Nightly builds, run with -Z macro-backtrace for more info)


error[E0599]: no method named `backtrace` found for struct `Box<(dyn std::error::Error + Send + Sync + 'static)>` in the current scope
  --> C:\Users\Straw\.cargo\registry\src\github.jparrowsec.cn-1ecc6299db9ec823\anyhow-1.0.61\src\wrapper.rs:72:16
   |
72 |         self.0.backtrace()
   |                ^^^^^^^^^ method not found in `Box<(dyn std::error::Error + Send + Sync + 'static)>`


error: aborting due to 11 previous errors


Some errors have detailed explanations: E0407, E0599.

For more information about an error, try `rustc --explain E0407`.

error: could not compile `anyhow` due to 12 previous errors

@Berrysoft
Copy link
Author

@dtolnay
Copy link
Owner

dtolnay commented Aug 11, 2022

I still think it's the same issue. Rust-analyzer's RUSTC_WRAPPER improperly returns a success exit code on all compiler invocations, even where building should fail. This is rust-lang/rust-analyzer#12973. The exact output you get after this happens depends on whether the toolchain is stable or nightly, but that isn't the cause of the failure.

@dtolnay dtolnay changed the title Method backtrace not found in StdError in recent nightly. "method backtrace is not a member of trait StdError" Aug 11, 2022
@dtolnay
Copy link
Owner

dtolnay commented Aug 11, 2022

If it's the same issue, doing a cargo build outside of rust-analyzer should succeed.

@Berrysoft
Copy link
Author

You're right, cargo build succeeded.

Repository owner locked and limited conversation to collaborators Sep 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants