Skip to content

Frequent error when working in lib.rs #4044

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

Closed
abrassel opened this issue Apr 19, 2020 · 2 comments · Fixed by #4057
Closed

Frequent error when working in lib.rs #4044

abrassel opened this issue Apr 19, 2020 · 2 comments · Fixed by #4057

Comments

@abrassel
Copy link

thread '' panicked at 'called Option::unwrap() on a None value', crates/ra_syntax/src/ast/make.rs:303:16
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/gb.xjqchip.workers.dev-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/gb.xjqchip.workers.dev-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:59
4: core::fmt::write
at src/libcore/fmt/mod.rs:1052
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1426
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:204
9: std::panicking::default_hook
at src/libstd/panicking.rs:224
10: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:472
11: rust_begin_unwind
at src/libstd/panicking.rs:380
12: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
13: core::panicking::panic
at src/libcore/panicking.rs:52
14: ra_syntax::ast::make::ast_from_text
15: ra_syntax::ast::make::path_unqualified
16: ra_syntax::ast::edit::::split_prefix::split_path_prefix
17: ra_syntax::ast::edit::::split_prefix
18: ra_assists::handlers::merge_imports::try_merge_trees
19: <core::iter::adapters::Copied as core::iter::traits::iterator::Iterator>::try_fold
20: ra_assists::handlers::merge_imports::merge_imports
21: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::next
22: <alloc::vec::Vec as alloc::vec::SpecExtend<T,I>>::from_iter
23: ra_assists::resolved_assists
24: ra_ide::assists::assists
25: std::panicking::try::do_call
26: __rust_maybe_catch_panic
at src/libpanic_unwind/lib.rs:86
27: ra_db::CheckCanceled::catch_canceled
28: ra_ide::Analysis::assists
29: rust_analyzer::main_loop::handlers::handle_code_action
30: ::call_box
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

@bjorn3
Copy link
Member

bjorn3 commented Apr 19, 2020

On what project does this happen?

@edwin0cheng
Copy link
Member

edwin0cheng commented Apr 19, 2020

Minimal reproduction :

use crate:::<|>::self;

By inserting : in the cursor position repeatedly.

bors bot added a commit that referenced this issue Apr 20, 2020
4057: Fix panic in split_imports assist r=matklad a=matklad

The fix is admittedly quit literally just papering over.

Long-term, I see two more principled approaches:

* we switch to a fully tree-based impl, without parse . to_string
  step; with this approach, there shouldn't be any panics. The results
  might be nonsensical, but so was the original input.

* we preserve the invariant that re-parsing constructed node is an
  identity, and make all the `make_xxx` method return an `Option`.

closes #4044



bors r+
🤖

Co-authored-by: Aleksey Kladov <[email protected]>
@bors bors bot closed this as completed in 8a04372 Apr 20, 2020
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants