3 ms·
I suggest you start reading the compiler error messages as they say exactly what trait is missing, no need to waste an hour. For example for this code: trai
by veber-alex 5y ago
I suggest you start reading the compiler error messages as they say exactly what trait is missing, no need to waste an hour.
For example for this code:
trait Foo {
fn foo(&self) {}
}
struct Bar;
impl Foo for Bar {}
mod test {
use super::Bar;
fn test() {
Bar.foo();
}
}
22 | Bar.foo();
| ^^^ method not found in `Bar`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
20 | use crate::Foo;
|
- camgunz 5y agoA less condescending way to say what you said is, "oh they're pretty clear in the compiler output, are they buried or something?" And then I would say that in the linter in Vim, you only get the "method not found in Bar" which could be all kinds of things.
- mplanchard 5y agoThis seems like you’re using a relatively uncommon tooling setup (no language server, some kind of inline vim errors rather than the command line), and expecting that to “just work.” As a user of arcane tools, it seems to me a slightly unreasonable expectation. If you’re not going to go down the “golden path” of using rust—analyzer, you’ll need to assume that your editor’s support for the language may be incomplete out of the gate and figure out how to supplement it. Even with rust-analyzer, the source of truth is always `cargo check` and friends, so I recommend getting super familiar with them on the command line, regardless of your editor setup.
- camgunz 5y agoYeah no you're definitely right, I'm definitely not in the golden path for Rust dev. I guess my quibbles (which I would cop to being quibbles... I think anyway) are: - I'm already using 'cargo check' as my linter (rustc doesn't understand modules, seemingly). - My setup works for JavaScript/React/Svelte, SQL, C/C++, Python, and Go. - It can't be the case that (Neo)Vim + Ale [0] is arcane. Also the link in "Tools" from rust-lang.org goes to the rust.vim repo, which defaults to Syntastic, which I'm pretty sure has the same issue. I don't necessarily think I should extrapolate from my experience to a broader "Rust is different for little/no gain" critique I've made in the past, but I sure want to haha. And to kind of anticipate a little, I wouldn't blame Ale here because--again--it works for everything else. But anyway, yeah I've mostly given up on linting and I just run 'cargo check' in a terminal buffer now. It's probably something as simple as adding a command-line argument to... idk cargo or rustc to make the additional "help" format a little more amenable to Ale? Maybe I'll take a crack at it when I get some time. [0]: https://github.com/dense-analysis/ale https://github.com/dense-analysis/ale
- estebank 5y agocargo/rustc can already provide all its output as structured json, including the appropriate byte position to apply substitutions suggested in help blocks.
- camgunz 5y agoI'm pretty sure that's already how it works yeah, then yeah maybe adding some smarts to ALE is the right thing to do here? Unclear without looking into it more.
- mplanchard 5y agoI haven’t used ALE in a while, and my colleague who uses vim uses CoC, but as far as I understand, rust-analyzer should “just work” with ALE. You may need to install rust-analyzer (via cargo) and tell ALE to use it, potentially? There’s an older and not well maintained language server called RLS. I would be surprised if ALE defaults to that one, but that could be part of why you aren’t getting great tooling out of the box if so. I did find this blog post, which seems to suggest there may be a bit of extra config required to get rust-analyzer going with ALE: https://petermalmgren.com/rc-batch-day-9/ https://petermalmgren.com/rc-batch-day-9/ Good luck!
- camgunz 5y agoYeah I think maybe I'll just come around to rust-analyzer? My experiences with language servers has been really spotty: they lose the state, eat CPU, want to autocomplete everything, etc. But idk, if it's a "this is the way" thing, I guess part of learning is adopting the customs. Just feels a little disappointing I can get by with like goimports/gofmt/go vet in Go, but there's no analog in Rust.
- mplanchard 5y agoHonestly I kind of thought ALE was exclusively a language server client, but it’s been a few years since I used it