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

Bad span when a root field is a map instead of a table #669

Closed
epage opened this issue Jan 31, 2024 · 0 comments · Fixed by #670
Closed

Bad span when a root field is a map instead of a table #669

epage opened this issue Jan 31, 2024 · 0 comments · Fixed by #670
Labels
A-parse Area: Parsing TOML C-bug Category: Things not working as expected

Comments

@epage
Copy link
Member

epage commented Jan 31, 2024

---
[dependencies]
toml = "*"
serde = { version = "*", features = ["derive"] }
---
use serde::Deserialize;

#[derive(Deserialize)]
struct Manifest {
    package: Package,
    bench: Vec<Bench>,
}

#[derive(Deserialize)]
struct Package {
}

#[derive(Deserialize)]
struct Bench {
}

fn main() {
    let raw = r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
[[bench.foo]]
"#;
    match toml::from_str::<Manifest>(raw) {
        Ok(manifest) => {},
        Err(err) => {
            println!("{err}");
        }
    }
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cd6a70687d41e3341a4f7898e55583a9

TOML parse error at line 1, column 1
  |
1 | 
  | ^
invalid type: map, expected a sequence

(the span is empty)

@epage epage added C-bug Category: Things not working as expected A-parse Area: Parsing TOML labels Jan 31, 2024
bors added a commit to rust-lang/cargo that referenced this issue Jan 31, 2024
fix(diagnostic): Don't panic on empty spans

### What does this PR try to resolve?

There is another level to this bug where we better point to where the
error occurs, see toml-rs/toml#669.

Fixes #13374

### How should we test and review this PR?

### Additional information
epage added a commit to epage/toml_edit that referenced this issue Jan 31, 2024
weihanglo pushed a commit to weihanglo/cargo that referenced this issue Feb 4, 2024
fix(diagnostic): Don't panic on empty spans

### What does this PR try to resolve?

There is another level to this bug where we better point to where the
error occurs, see toml-rs/toml#669.

Fixes rust-lang#13374

### How should we test and review this PR?

### Additional information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parse Area: Parsing TOML C-bug Category: Things not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant