Skip to content

Lint error from -Zlints didn't point to [lints] but rustc command line flags #12534

@weihanglo

Description

@weihanglo

Problem

The current implementation of -Zlints is just a transform from [lints] table to a series of rustc lint flags. When a lint error/warning is emitted, rustc report as if the lint rule were requested on the command line:

   Compiling bad-zlints-error v0.1.0 (/users/weihanglo/bad-zlints-error)
error: unknown lint: `new_lint`
 --> src/lib.rs:1:9
  |
1 | #[allow(new_lint)]
  |         ^^^^^^^^
  |
  = note: requested on the command line with `-D unknown-lints`

error: could not compile `bad-zlints-error` (lib) due to previous error

Steps

# Cargo.toml
[package]
name = "bad-zlints-error"
version = "0.1.0"
edition = "2021"

[lints.rust]
unknown_lints = "deny"
// src/lib.rs
#[allow(new_lint)]

And run cargo +nightly c -Zlints

Possible Solution(s)

Cargo hints rustc that these lint args are from [lints] table. However, this solution has some difficulties:

  • Rustc should know nothing about Cargo.
  • Even within Cargo, lint args may come from a variety of sources, for example, build.rustflags config, RUSTFLAGS, or cargo rustc -- <args>.

Notes

This is a known issue around rustflags in Cargo and shouldn't be a blocker for stabilization.

Version

cargo 1.73.0-nightly (7c3904d6c 2023-08-14)
release: 1.73.0-nightly
commit-hash: 7c3904d6c3ed54e8a413023519b55a536ad44d5b
commit-date: 2023-08-14

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lints-tableArea: [lints] tableA-rustflagsArea: rustflagsC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions