rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.69k stars 12.64k forks source link

compiletest silently fails on a name-value directive with a known name but missing colon but does not report an error #123760

Open jieyouxu opened 6 months ago

jieyouxu commented 6 months ago

compiletest expects that a name-value directive, like //@ revisions: foo, to have the colon :

https://github.com/rust-lang/rust/blob/b14d8b2ef20c64c1002e2c6c724025c3d0846b91/src/tools/compiletest/src/header.rs#L1137-L1146

If the name-value directive contains a known directive name like revisions but does not have the colon (i.e. //@ revisions foo), then:

compiletest should not silently fail here because it's very surprising and a pain to debug unless you know exactly what's wrong.

jieyouxu commented 6 months ago

I think an actual ui test has this problem?

https://github.com/rust-lang/rust/blob/b14d8b2ef20c64c1002e2c6c724025c3d0846b91/tests/ui/precondition-checks/cfg-ub-checks-default.rs#L2

jieyouxu commented 6 months ago

Wait if I change it to //@ revisions: YES NO which actually enables the compile-flags directives, this test still passes. What is this test actually checking then? Maybe it just doesn't actually need the compile-flags?

fmease commented 6 months ago

Wait if I change it to //@ revisions: YES NO which actually enables the compile-flags directives, this test still passes. What is this test actually checking then? Maybe it just doesn't actually need the compile-flags?

Well, the test “needs” the compile-flags because it's checking that cfg ub_checks is equivalent to cfg debug_assertions for all values of debug_assertions, i.e., yes and no (under the assumption that -Zub-checks wasn't passed which holds). If you remove the flags the test covers fewer cases.

cc #123411 &

https://github.com/rust-lang/rust/blob/b3bd7058c139e71bae0862ef8f8ac936208873e9/compiler/rustc_session/src/options.rs#L1997

jieyouxu commented 6 months ago

Yeah, I talked to Saethlin, makes sense. It's just compiletest silently failing here is awful 😆

jieyouxu commented 6 months ago

I briefly looked at this, the easy fix is trivial, but the error handling is entirely not maintainable and involves propagating a poisoned: &mut bool status bool through many callsites. The easy fix is like

8mg8j6

I think the directive parsing is long past due for a rework. The error handling needs to not rely on passing a &mut bool around everywhere.