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

Request textDocument/documentHighlight failed. #16141

Closed
ho-229 opened this issue Dec 18, 2023 · 1 comment · Fixed by #17151
Closed

Request textDocument/documentHighlight failed. #16141

ho-229 opened this issue Dec 18, 2023 · 1 comment · Fixed by #17151
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug I-panic

Comments

@ho-229
Copy link

ho-229 commented Dec 18, 2023

rust-analyzer version: 0.4.1773-standalone

rustc version: rustc 1.76.0-nightly (0e2dac837 2023-12-04)

relevant settings: none

Minimal reproducible examples:

struct Foo<T, #[cfg(feature = "a-feature")] A> {
    v: T,
    #[cfg(feature = "a-feature")]
    _p: std::marker::PhantomData<A>,
}

#[cfg(feature = "a-feature")]
macro_rules! boxed_foo {
    ($t:ident, $a:ident) => {
        Foo<$t, $a>
    };
}

#[cfg(not(feature = "a-feature"))]
macro_rules! boxed_foo {
    ($t:ident, $a:ident) => {
        Foo<$t>
    };
}

trait Bar {
    fn bar(&self);
}

impl<#[cfg(feature = "a-feature")] A> Bar for boxed_foo!(i32, A) {
    fn bar(&self) {
        println!("bar {}", self.v);
    }
}

fn main() {
    let f = Foo {
        v: 0i32,
        #[cfg(feature = "a-feature")]
        _p: std::marker::PhantomData::<()>,
    };

    f.bar();
}

a-feature is a declared feature in Cargo.toml, which is not enabled by default

rust analyzer server output:

thread 'Worker' panicked at /github/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/chalk-ir-0.95.0/src/lib.rs:2974:1:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_bounds_check
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:180:5
   3: hir_ty::infer::unify::InferenceTable::run_in_snapshot
   4: hir_ty::method_resolution::is_valid_candidate
   5: hir_ty::method_resolution::iterate_trait_method_candidates
   6: hir_ty::method_resolution::iterate_method_candidates_with_autoref::{{closure}}
   7: hir_ty::method_resolution::iterate_method_candidates_dyn
   8: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
   9: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr
  10: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_block
  11: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_expr_inner
  12: hir_ty::infer::expr::<impl hir_ty::infer::InferenceContext>::infer_return
  13: hir_ty::infer::infer_query
  14: salsa::Cycle::catch
  15: salsa::derived::slot::Slot<Q,MP>::execute
  16: salsa::derived::slot::Slot<Q,MP>::read
  17: <DB as hir_ty::db::HirDatabase>::infer_query::__shim
  18: hir_ty::db::infer_wait
  19: hir::source_analyzer::SourceAnalyzer::new_for_body
  20: hir::semantics::SemanticsImpl::analyze_impl
  21: hir::semantics::SemanticsImpl::type_of_binding_in_pat
  22: ide::inlay_hints::bind_pat::hints
  23: ide::inlay_hints::hints
  24: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  25: ide::inlay_hints::inlay_hints
  26: std::panicking::try
  27: rust_analyzer::handlers::request::handle_inlay_hints
  28: std::panicking::try
  29: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 2:04:13 PM] Request textDocument/inlayHint failed.
  Message: request handler panicked: index out of bounds: the len is 0 but the index is 0
  Code: -32603 
Panic context:
> 
version: 0.4.1773-standalone
request: textDocument/semanticTokens/range SemanticTokensRangeParams {
    work_done_progress_params: WorkDoneProgressParams {
        work_done_token: None,
    },
    partial_result_params: PartialResultParams {
        partial_result_token: None,
    },
    text_document: TextDocumentIdentifier {
        uri: Url {
            scheme: "file",
            cannot_be_a_base: false,
            username: "",
            password: None,
            host: None,
            port: None,
            path: "/run/media/ho229/Share/Project/rust/helloworld/src/main.rs",
            query: None,
            fragment: None,
        },
    },
    range: Range {
        start: Position {
            line: 0,
            character: 0,
        },
        end: Position {
            line: 36,
            character: 0,
        },
    },
}

thread 'Worker' panicked at crates/hir-ty/src/lower.rs:1581:56:
range start index 1 out of range for slice of length 0
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/panicking.rs:72:14
   2: core::slice::index::slice_start_index_len_fail_rt
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/slice/index.rs:52:5
   3: core::slice::index::slice_start_index_len_fail
             at /rustc/a28077b28a02b92985b3a3faecf92813155f1ea1/library/core/src/slice/index.rs:40:9
   4: hir_ty::lower::generic_predicates_query
   5: salsa::derived::slot::Slot<Q,MP>::execute
   6: salsa::derived::slot::Slot<Q,MP>::read
   7: <DB as hir_ty::db::HirDatabase>::generic_predicates::__shim
   8: hir_ty::chalk_db::trait_datum_query
   9: salsa::Cycle::catch
  10: salsa::derived::slot::Slot<Q,MP>::execute
  11: salsa::derived::slot::Slot<Q,MP>::read
  12: <DB as hir_ty::db::HirDatabase>::trait_datum::__shim
  13: <chalk_solve::clauses::env_elaborator::EnvElaborator<I> as chalk_ir::visit::TypeVisitor<I>>::visit_domain_goal
  14: chalk_ir::visit::boring_impls::<impl chalk_ir::visit::TypeSuperVisitable<I> for chalk_ir::ProgramClause<I>>::super_visit_with
  15: chalk_solve::clauses::env_elaborator::elaborate_env_clauses
  16: chalk_solve::clauses::program_clauses_for_env
  17: hir_ty::chalk_db::program_clauses_for_chalk_env_query
  18: salsa::Cycle::catch
  19: salsa::derived::slot::Slot<Q,MP>::execute
  20: salsa::derived::slot::Slot<Q,MP>::read
  21: <DB as hir_ty::db::HirDatabase>::program_clauses_for_chalk_env::__shim
  22: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  23: chalk_recursive::solve::SolveIteration::solve_iteration
  24: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  25: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
  26: hir_ty::traits::solve::{{closure}}
  27: hir_ty::traits::trait_solve_query
  28: std::panicking::try
  29: salsa::Cycle::catch
  30: salsa::derived::slot::Slot<Q,MP>::execute
  31: salsa::derived::slot::Slot<Q,MP>::read
  32: <DB as hir_ty::db::HirDatabase>::trait_solve_query::__shim
  33: <DB as hir_ty::db::HirDatabase>::trait_solve_query
  34: hir_ty::db::trait_solve_wait
  35: <DB as hir_ty::db::HirDatabase>::trait_solve
  36: hir_ty::infer::unify::InferenceTable::try_resolve_obligation
  37: hir_ty::infer::unify::InferenceTable::register_obligation_in_env
  38: hir_ty::callable_sig_from_fnonce
  39: hir::Type::as_callable
  40: ide::syntax_highlighting::highlight::highlight_def
  41: ide::syntax_highlighting::highlight::name_like
  42: ide::syntax_highlighting::traverse
  43: ide::syntax_highlighting::highlight
  44: salsa::Cancelled::catch
  45: ide::Analysis::highlight_range
  46: rust_analyzer::handlers::request::handle_semantic_tokens_range
  47: std::panicking::try
  48: core::ops::function::FnOnce::call_once{{vtable.shim}}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 2:04:13 PM] Request textDocument/semanticTokens/range failed.
  Message: request handler panicked: range start index 1 out of range for slice of length 0
  Code: -32603 
@ho-229 ho-229 added the C-bug Category: bug label Dec 18, 2023
@Veykril Veykril added A-ty type system / type inference / traits / method resolution I-panic labels Dec 18, 2023
@AsakuraMizu
Copy link

A smaller reproducible example:

trait Bar {
    fn bar<#[cfg(never)] T>() {}
}

bors added a commit that referenced this issue Apr 27, 2024
fix: Fix attributes on generic parameters colliding in item tree

Fixes #16141
bors added a commit that referenced this issue Apr 27, 2024
fix: Fix attributes on generic parameters colliding in item tree

Fixes #16141
bors added a commit that referenced this issue Apr 27, 2024
fix: Fix attributes on generic parameters colliding in item tree

Fixes #16141
@bors bors closed this as completed in e6f3399 Apr 27, 2024
lnicola pushed a commit to lnicola/rust that referenced this issue May 19, 2024
fix: Fix attributes on generic parameters colliding in item tree

Fixes rust-lang/rust-analyzer#16141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug I-panic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants