I'm using the rust-analyzer vscode extension and it works for the src/lib.rs file, but not for the src/bin/foo.rs and src/bin/bar.rs files. Cargo check works on both of these files.
I'm very new to Rust so it's likely that I'm doing something wrong.
did you edit Cargo.toml outside vscode? try to press Ctrl P in vscode and run the command rust-analyzer: Reload workspace.
if it still doesn't work, try rust-analyzer: Restart server command.
PS: you don't need to list the targets in Cargo.toml if you stick with the directory structure naming convention used by cargo's target auto discovery feature.
in your example, src/bin/foo.rs and src/bin/bar.rs can be automatically discovered. the src/lib.rs though, will be discovered with the same name as the package, i.e. foobar, if you don't explicit specify the [lib] target in Cargo.toml.