rust-lang / rust-lang/rust-analyzer
Expression variant of `include!` always produces errors
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
std::include! has 2 variants 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:
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the complete Cargo reproduction at strohel/include-test-case and the minimal main.rs example, then run rust-analyzer to reproduce the diagnostics for expression-form include!. Trace the handling of include! and verify that valid included expressions no longer produce erroneous diagnostics or prevent type inference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100