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

"no field on type" error diagnostic, but field does exist correctly #16814

Closed
DerickEddington opened this issue Mar 11, 2024 · 3 comments
Closed
Labels
A-ty type system / type inference / traits / method resolution C-bug Category: bug

Comments

@DerickEddington
Copy link

DerickEddington commented Mar 11, 2024

summary: rust-analyzer gives a diagnostic with severity of Error that a struct field doesn't exist at a point of use of the field, but the field does in fact exist, and the use is correct, and building the crate with cargo build or cargo check succeeds without issue.

rust-analyzer version: (03d2d90 2024-03-11) or 1.76.0 (07dca48 2024-02-04)

rustc version: 1.76.0 (07dca489a 2024-02-04)

repository link: https://github.com/DerickEddington/sailce/blob/71aaaa2dafeccab8a5b7cd9fe00f4fffee4c1fdd/crates/data_model/src/group/area/of_interest.rs#L59

code snippet to reproduce:

I tried to make a simpler reproduction but didn't find one. The bug seems to be triggered by the specific nature of what I did in my crate. My crate is relatively simple already and doesn't have dependencies.

In the below, the issue at hand is the Diagnostic with message: "no field `namespace_id` on type `&Entry<N, S, Pe, D>`".

$ git clone https://github.com/DerickEddington/sailce.git \
  && cd sailce \
  && git switch --detach tool-bug/rust-analyzer/1

$ rust-analyzer --version               # Or, it also happens with: 1.76.0 (07dca48 2024-02-04)
rust-analyzer 0.0.0 (03d2d90 2024-03-11)

$ rust-analyzer diagnostics .
processing crate: basic, module: /home/vagrant/zone/sailce/crates/data_model/tests/basic/main.rs
processing crate: basic, module: /home/vagrant/zone/sailce/crates/data_model/tests/basic/entry.rs
processing crate: basic, module: /home/vagrant/zone/sailce/crates/data_model/tests/basic/group/range.rs
processing crate: basic, module: /home/vagrant/zone/sailce/crates/data_model/tests/basic/group/range/least.rs
Diagnostic { code: Ra("inactive-code", WeakWarning), message: "code is inactive due to #[cfg] directives: feature = \"alloc\" is disabled", range: FileRange { file_id: FileId(1414), range: 563..841 }, severity: WeakWarning, unused: true, experimental: false, fixes: None, main_node: None }
processing crate: basic, module: /home/vagrant/zone/sailce/crates/data_model/tests/basic/group/range/three_dim.rs
processing crate: basic, module: /home/vagrant/zone/sailce/crates/data_model/tests/basic/path.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/lib.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/store.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/entry.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/entry/auth.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/path.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/group.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/group/area.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/group/area/of_interest.rs
Diagnostic { code: RustcHardError("E0559"), message: "no field `namespace_id` on type `&Entry<N, S, Pe, D>`", range: FileRange { file_id: FileId(1404), range: 1928..1940 }, severity: Error, unused: false, experimental: true, fixes: Some([Assist { id: AssistId("add-field-to-record-struct", QuickFix), label: "Add field to Record Struct", group: None, target: 1922..1940, source_change: Some(SourceChange { source_file_edits: {FileId(1411): (TextEdit { indels: [Indel { insert: ",\n    pub(crate) namespace_id: ()", delete: 1100..1100 }] }, None)}, file_system_edits: [], is_snippet: false }), trigger_signature_help: false }]), main_node: None }
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/group/range.rs
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/group/range/least.rs
Diagnostic { code: Ra("inactive-code", WeakWarning), message: "code is inactive due to #[cfg] directives: feature = \"alloc\" is disabled", range: FileRange { file_id: FileId(1406), range: 1995..2121 }, severity: WeakWarning, unused: true, experimental: false, fixes: None, main_node: None }
processing crate: sailce_data_model, module: /home/vagrant/zone/sailce/crates/data_model/src/group/range/three_dim.rs

diagnostic scan complete

Error: diagnostic error detected

Stack backtrace:
   0: anyhow::error::<impl anyhow::Error>::msg
   1: anyhow::__private::format_err
   2: rust_analyzer::cli::diagnostics::<impl rust_analyzer::cli::flags::Diagnostics>::run
   3: rust_analyzer::actual_main
   4: rust_analyzer::main
   5: core::ops::function::FnOnce::call_once
   6: std::sys_common::backtrace::__rust_begin_short_backtrace
   7: std::rt::lang_start::{{closure}}
   8: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:284:13
   9: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  10: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  11: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  12: std::rt::lang_start_internal::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:48
  13: std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
  14: std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
  15: std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
  16: std::rt::lang_start_internal
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:20
  17: std::rt::lang_start
  18: main
  19: __libc_start_call_main
             at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  20: __libc_start_main_impl
             at ./csu/../csu/libc-start.c:360:3
  21: _start

(When I'd first encountered this bug, it was not with the rust-analyzer diagnostics CLI, it was with using rust-analyzer normally as an LSP server with my editor (Emacs with lsp-mode) where it shows the same diagnostic error message.)

@DerickEddington DerickEddington added the C-bug Category: bug label Mar 11, 2024
@DerickEddington DerickEddington changed the title "no field on type" error, but field does exist correctly "no field on type" error diagnostic, but field does exist correctly Mar 11, 2024
@lnicola lnicola added the A-ty type system / type inference / traits / method resolution label Mar 14, 2024
@lnicola
Copy link
Member

lnicola commented Mar 14, 2024

You can work around this by writing let entry: &Entry<N, S, Pe, D> = entry.borrow();, which is a little surprising since we already show that as an inlay hint.

Might be related to #5514.

@flodiebold
Copy link
Member

Yes, probably #5514, and it's just looking like it knows the type because it's inferred afterwards.

@lnicola
Copy link
Member

lnicola commented Mar 14, 2024

#13761 is also similar, we can probably close this. I wonder how the new trait solver is doing...

@lnicola lnicola closed this as completed Mar 14, 2024
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
Projects
None yet
Development

No branches or pull requests

3 participants