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

target json file contains unused fields unaffected by -Dwarnings #91262

Open
ojeda opened this issue Nov 26, 2021 · 10 comments
Open

target json file contains unused fields unaffected by -Dwarnings #91262

ojeda opened this issue Nov 26, 2021 · 10 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ojeda
Copy link
Contributor

ojeda commented Nov 26, 2021

I tried this:

# t.json is a target spec file with an unknown field
$ cat t.json | grep foo
  "foo": "bar",
$ rustc -Dwarnings --target=t.json < /dev/null

I expected to see this happen: the warning: target json file contains unused fields: foo diagnostic to be an error.

Instead, this happened: the warning is still a warning, even with -Dwarnings.

If this is intended (i.e. if -Dwarnings is only intended for code-related diagnostics), then this issue would be a feature request: a way to control whether non-code warnings are (or not) errors for CI purposes.

Meta

Happens in both stable (1.56.1) and the latest nightly:

rustc 1.58.0-nightly (dd549dcab 2021-11-25)
binary: rustc
commit-hash: dd549dcab404ec4c7d07b5a83aca5bdd7171138f
commit-date: 2021-11-25
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
@ojeda ojeda added the C-bug Category: This is a bug. label Nov 26, 2021
ojeda added a commit to ojeda/linux that referenced this issue Nov 26, 2021
We were getting a warning on an unknown key in the target spec file
because there was a typo in the key. This warning should be an error,
but it seems `-Dwarnings` does not cover it (reported upstream:
rust-lang/rust#91262).

However, the value was also wrong: PowerPC does not support
the "kernel" machine model.

Given PPC_64 modules use the large model, use that value for the moment
for everything in PowerPC until we have proper target spec file generation
(at which point, we will need to pick the right model in each sitaution
for all architectures, properly).

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
ojeda added a commit to ojeda/linux that referenced this issue Nov 26, 2021
We were getting a warning on an unknown key in the target spec file
because there was a typo in the key. This warning should be an error,
but it seems `-Dwarnings` does not cover it (reported upstream:
rust-lang/rust#91262).

However, the value was also wrong: PowerPC does not support
the "kernel" machine model.

Given PPC_64 modules use the large model, use that value for the moment
for everything in PowerPC until we have proper target spec file generation
(at which point, we will need to pick the right model in each sitaution
for all architectures, properly).

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
@jyn514
Copy link
Member

jyn514 commented Nov 26, 2021

This happens because the code is using sess.warn instead of tcx.struct_span_lint_hir (presumably because tcx isn't available that early in compilation). I agree that this should be an error with -D warnings, but you could construe that as a breaking change for people who are running -D warnings currently. Could you open an MCP for changing this? I think it shouldn't be too hard to change in the diagnostic machinery, the compiler team just needs to decide it's a good idea.

@jyn514 jyn514 added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 26, 2021
@jyn514
Copy link
Member

jyn514 commented Nov 26, 2021

Relevant code:

pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
let emitter: Box<dyn Emitter + sync::Send> = match output {
config::ErrorOutputType::HumanReadable(kind) => {
let (short, color_config) = kind.unzip();
Box::new(EmitterWriter::stderr(color_config, None, short, false, None, false))
}
config::ErrorOutputType::Json { pretty, json_rendered } => {
Box::new(JsonEmitter::basic(pretty, json_rendered, None, false))
}
};
let handler = rustc_errors::Handler::with_emitter(true, None, emitter);
handler.struct_warn(msg).emit();

@ojeda
Copy link
Contributor Author

ojeda commented Nov 26, 2021

Could you open an MCP for changing this?

Thanks for the quick analysis -- will do!

@jyn514 jyn514 added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. labels Nov 26, 2021
@ojeda
Copy link
Contributor Author

ojeda commented Jun 9, 2022

If this is intended (i.e. if -Dwarnings is only intended for code-related diagnostics), then this issue would be a feature request: a way to control whether non-code warnings are (or not) errors for CI purposes.

From the MCP/Zulip discussion, -Dwarnings is not intended to cover all warnings and changing that could potentially break existing users. Thus the next step would be identifying:

  • Whether there are warnings that are not covered by -Dwarnings but should be (e.g. -D warnings should deny warnings from lint renames #94500).

  • For those that are not intended to be covered by -Dwarnings, whether new options to control their "level" may make sense, either as a group or individually.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 21, 2023

what "MCP/Zulip" discussion are you referring to?
edit: rust-lang/compiler-team#473

@ojeda
Copy link
Contributor Author

ojeda commented Jun 21, 2023

@jyn514
Copy link
Member

jyn514 commented Jun 21, 2023

From the MCP/Zulip discussion, -Dwarnings is not intended to cover all warnings and changing that could potentially break existing users.

that is not the conclusion i see in that MCP: rust-lang/compiler-team#473 (comment)

My understanding of the current consensus with nagisa is that this is fine for most warnings, but there are some warnings for unstable features that are explicitly warnings to avoid breaking people, which would change with this flag. To avoid a maintenance burden, nagisa is going to change those unstable features to give hard errors instead of warnings instead.

@ojeda
Copy link
Contributor Author

ojeda commented Jun 21, 2023

My message was written before the second part of the discussion took place -- thanks for updating this!

So, all warnings are intended to be covered, in the end? Are @nagisa's proposed hard errors in place now?

@jyn514
Copy link
Member

jyn514 commented Jun 21, 2023

i am not aware of any warnings being converted to hard errors. looking at the MCP, nagisa gave -C target-feature as an example of a diagnostic that should be converted to a hard error: https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/.60-Dwarnings.60.20to.20cover.20all.20warnings.20compiler-team.23473/near/286500509

@nagisa were there any other diagnostics you wanted to change? i do see in retrospect that this is for a stable flag - maybe we should be using the future-incompat machinery instead of either hard warnings or hard errors?

@nagisa
Copy link
Member

nagisa commented Jul 16, 2023

I’m… not sure. -Ctarget-feature doesn’t obviously scream to me like “definitely needs future-incompat” – we’ve been (unconditionally) warning about unknown or malformed features for a long time already, and I wouldn’t expect many build environment somehow set invalid features. While the wording of that warning is not particularly stern, it is an annoying warning nevertheless, in that majority of cargo build invocation will end up with more screenfuls of that warning than anything else.

(I also have no recollection on whether I went on to make -Ctarget-feature errors a hard error or not; I’d imagine that I didn’t, but I still would if I find time for general QoL contributions to rust-lang/*)


I don’t really have another example of a warning that should be an error instead. I was hoping for somebody to review warnings rustc can emit and summarize the list of those unaffected by the lint levels (as indicated earlier up thread in #91262 (comment).)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants