Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

try! example panics when fixing docs.rs #30

Closed
jyn514 opened this issue Nov 13, 2019 · 5 comments
Closed

try! example panics when fixing docs.rs #30

jyn514 opened this issue Nov 13, 2019 · 5 comments

Comments

@jyn514
Copy link
Contributor

jyn514 commented Nov 13, 2019

I'm trying to run rerast on https://github.com/rust-lang/docs.rs/, but it panics when I run the command. I'm not sure what I'm doing wrong and I don't understand the error message. I'm using the try! example directly from COOKBOOK.md.

$ cargo +nightly rerast --rules_file=rules.rs --force
thread 'rustc' panicked at 'Bad substitutions: [
    CodeSubstitution {
        span: src/__rerast_rules.rs:2:25: 2:26,
        new_code: "initialize_package_in_database(&conn, metadata_pkg)",
        needs_parenthesis: false,
        code_is_single_tree: false,
    },
    CodeSubstitution {
        span: src/__rerast_rules.rs:2:26: 2:27,
        new_code: "err",
        needs_parenthesis: false,
        code_is_single_tree: false,
    },
    CodeSubstitution {
        span: src/__rerast_rules.rs:2:26: 2:27,
        new_code: "err",
        needs_parenthesis: false,
        code_is_single_tree: false,
    },
    CodeSubstitution {
        span: src/__rerast_rules.rs:2:25: 2:27,
        new_code: "val",
        needs_parenthesis: false,
        code_is_single_tree: false,
    },
    CodeSubstitution {
        span: src/__rerast_rules.rs:2:25: 2:27,
        new_code: "val",
        needs_parenthesis: false,
        code_is_single_tree: false,
    },
]
For source: SourceChunk { source: "r?", start_pos: BytePos(214288) }', /home/joshua/.cargo/registry/src/github.com-1ecc6299db9ec823/rerast-0.1.73/src/code_substitution.rs:146:13

Rewrite file:

fn rule1<T,E,X: From<E>>(r: Result<T,E>) -> Result<T,X> {
    replace!(try!(r) => r?);
    unreachable!()
}
Backtrace
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1030
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:188
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:205
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:464
  11: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:373
  12: std::panicking::begin_panic_fmt
             at src/libstd/panicking.rs:328
  13: rerast::code_substitution::CodeSubstitution<syntax_pos::span_encoding::Span>::apply_with_source_map
  14: rerast::rule_matcher::substitions_for_matches
  15: rustc::ty::context::tls::enter_global
  16: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  17: rustc_interface::passes::create_global_ctxt::{{closure}}
  18: <rerast::RerastCompilerCallbacks as rustc_driver::Callbacks>::after_analysis
  19: rustc_interface::interface::run_compiler_in_existing_thread_pool
  20: std::thread::local::LocalKey<T>::with
  21: scoped_tls::ScopedKey<T>::set
  22: syntax::with_globals
@davidlattimore
Copy link
Contributor

Thanks for the report. Looks like matching of try! is broken completely. Still looking into why. I did go back and check a couple of older versions. Looks like it was already broken in August, however when I went back to May it works.

So if you want a workaround, you can do:

rustup toolchain install --force nightly-2019-05-13
cargo +nightly-2019-05-13 install --force rerast --version 0.1.49

@davidlattimore
Copy link
Contributor

Turns out matching of try! was OK, but when the replacement was the question mark operator, it was getting confused by some of the variables that try! / ? declared in the expansion and thinking that those variables were placeholders. Should be fixed with the next release. Thanks again for reporting.

@jyn514
Copy link
Contributor Author

jyn514 commented Nov 24, 2019

Thanks for the quick work! Is there a way to try out rerast from the master branch? I tried cloning and running with cargo +nightly run but I got This binary is intended to be run as cargo rerast not run directly.

Whoops, I just had to link it into ~/.cargo/bin. Ignore me, sorry :)

jyn514 added a commit to jyn514/docs.rs that referenced this issue Nov 24, 2019
@jugglerchris
Copy link
Contributor

I have a project which has moved to the 2018 edition and has had rustfix applied to replace try!(...) with r#try!(...). Should rerast work converting those to ?? I tried with the latest release, master, and the nightly-2019-05-13 version mentioned above; in all cases the diff is empty and --force has no effect.

@jyn514
Copy link
Contributor Author

jyn514 commented Dec 1, 2019

You would need to change the rules file. Can you open a new issue instead of bumping an old one?

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

3 participants