When using include!("foo.def")
in a project, rust-analyzer reports "failed to load file foo.def
". include_str!
works fine (though obviously gives a type error since I'm not expecting a string here). cargo build
compiles the project successfully, so it's definitely something with r-a. Any idea what's going on? Does r-a just not support include!
?
Simple reproduction:
Looks like this issue (or technically the one linked at the end).
opened 10:27AM - 27 Oct 21 UTC
A-macro
S-actionable
A-vfs
[`std::include!`](https://doc.rust-lang.org/std/macro.include.html) has 2 varian… ts depending on how it is used:
- Item variant `include!("bindings.rs")` often used in -sys crates.
- Expression variant `let value = include!("file.in")` used likely much less.
The item variant works well, but the expression variant always causes rust-analyzer to emit an error. The only negative effect of the error on rust-analyzer is that it doesn't infer the type of the variable. Specifying the type explicitly works.
Minimal reproduction:
```rust
fn main() {
let text_in = include!("text.in");
let text_rs = include!("text.rs");
println!("{} {}", text_in, text_rs);
}
```
With both `text.in` and `text.rs` being:
```
"Hello, world!"
```
Gives the following rust-analyzer errors:
```
main.rs
failed to load file `text.in` rust-analyzer(macro-error) [2, 16]
text.rs
Syntax Error: expected an item rust-analyzer(syntax-error) [1, 1]
file not included in module tree rust-analyzer(unlinked-file)
```
Also available at https://github.com/strohel/include-test-case as a complete Cargo crate.
Note that if the included file has `.rs` extension (`text.rs`), the errors are slightly different.
VSCodium 1.61.2
rust-analyzer v0.2.784 from https://open-vsx.org/extension/matklad/rust-analyzer/0.2.784
1 Like
Thanks! That was indeed the issue. Not sure why that thread didn't come up when I googled this before...