Skip to content

rustc silently ignores a class of errors in flexible target json files #24384

Closed
@ghost

Description

Currently rustc will allow for extra fields to be added to flexible target json without notifying the user, even with --verbose. For example, the following is accepted:

{
    "THIS-IS-INCORRECT": "but rustc will silently accept it anyway",
    "data-layout": "e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32",
    "llvm-target": "i686-unknown-linux-gnu",
    "target-endian": "little",
    "target-pointer-width": "32",
    "arch": "x86",
    "os": "linux",
    "morestack": "false",
    "pre-link-args": "-nostdlib",
    "dynamic_linking": false
}
  • dynamic_linking has a underscore separator instead of a hyphen.
  • morestack is of type bool, but a string was provided
  • pre-link-args takes an array of strings, but a string was provided

The last three entries have errors that could be easy to miss. This is worrying, because for all the optional fields, simple errors such as misspellings will cause those fields to be discarded and the default values to be used instead. To the programmer it could seem as if the configuration is in place when in reality the compiler simply went with the default value.

I had one of these happen to me earlier and I almost missed it completely. I think that this should at the very least trigger a warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-target-specsArea: Compile-target specificationsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions