-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
compiletest: error when finding a trailing directive #123753
Conversation
Some changes occurred in src/tools/compiletest cc @jieyouxu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look mostly good to me, just some nitpicks and a question regarding if this would reject e.g. //@ revisions incremental
(without the :
).
#[test] | ||
fn test_not_trailing_directive() { | ||
let mut poisoned = false; | ||
run_path(&mut poisoned, Path::new("a.rs"), b"//@ revisions: incremental"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this reject //@ revisions incremental
? I want to say that the :
was not enforced in compiletest directive grammar when parsing directives...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also examples such as //@ revisions edition
(mostly the single word no-dash directives), but probably fine since I don't think anyone would write that in isolation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit: miss-read the question; yes it would be rejected!
No it would not be rejected, because it's currently used in tests/ui/invalid-compile-flags/fuel.rs
:
//@ revisions: incremental threads |
I also don't see a reason to reject it, since the :
is a delimiter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry let me clarify what I mean. I believe compiletest accepts both //@ revisions incremental
and //@ revisions: incremental
, would the logic in this PR (incorrectly) reject //@ revisions incremental
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, unfortunately,
//@ revisions incremental
fn main() {}
would get rejected
error: detected trailing compiletest test directive `incremental`
whereas
//@ revisions: incremental
fn main() {}
would get accepted. The thing here is that compiletest accepts both directive forms currently (unfortunate directive grammar strikes yet again)
EDIT: but it really should not silently accept it yet do nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, no, it's me. I read the question the wrong way round.
I believe compiletest accepts both
//@ revisions incremental
and//@ revisions: incremental
I just checked, and it doesn't seems to be the case. There is no revisions (also no errors).
would the logic in this PR (incorrectly) reject
//@ revisions incremental
?
Yes, it would be rejected by this PR; but I would also argue that it's not incorrect since the syntax is a nop and should probably be an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked, and it doesn't seems to be the case. There is no revisions (also no errors).
What
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah darn, I think it's because of a combination of things:
revisions
is a known compiletest directive- when we parse name-value directives, the directive name is required to have a trailing
colon
in order for the parse to succeed:rust/src/tools/compiletest/src/header.rs
Lines 1137 to 1146 in b14d8b2
pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> { let colon = directive.len(); if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') { let value = line[(colon + 1)..].to_owned(); debug!("{}: {}", directive, value); Some(expand_variables(value, self)) } else { None } }
However, the way compiletest directive parsing is setup right now means that if known directive check allows a directive but the corresponding name-value directive parsing logic fails, we silently accept the directive but it has no effect.
This is awful LOL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the colon is actually mandatory for name-value directives like revisions
, I think it's okay to reject things like //@ only-arch known-directive
because the trailing known-directive-looking-thing is very unlikely to be a directive commment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed an issue #123760 to make sure we know that this is a bug, but it's out of the scope for this PR. I'm happy to accept this PR as is.
@rustbot author |
0d9ee29
to
acd4e94
Compare
Changes look good to me and I think it's okay to reject Feel free to r=me after CI is green. @bors delegate+ |
@bors r+ rollup |
…ve, r=jieyouxu compiletest: error when finding a trailing directive This PR introduce a supplementary check that when checking for a compiletest directive, will also check that the next "word" after that directive is not also by itself a directive. This is done to avoid situations like this `//@ only-linux only-x86_64` where one might think that both directives are being taken into account while in fact the second in a comment, and so was ignored, until now. Related to rust-lang#123730 cc `@scottmcm` r? `@jieyouxu`
…iaskrgr Rollup of 3 pull requests Successful merges: - rust-lang#123490 (Refactor `panic_unwind/seh.rs` pointer use) - rust-lang#123704 (Tweak value suggestions in `borrowck` and `hir_analysis`) - rust-lang#123753 (compiletest: error when finding a trailing directive) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 2 pull requests Successful merges: - rust-lang#123704 (Tweak value suggestions in `borrowck` and `hir_analysis`) - rust-lang#123753 (compiletest: error when finding a trailing directive) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#123753 - Urgau:compiletest-trailing-directive, r=jieyouxu compiletest: error when finding a trailing directive This PR introduce a supplementary check that when checking for a compiletest directive, will also check that the next "word" after that directive is not also by itself a directive. This is done to avoid situations like this `//@ only-linux only-x86_64` where one might think that both directives are being taken into account while in fact the second in a comment, and so was ignored, until now. Related to rust-lang#123730 cc ``@scottmcm`` r? ``@jieyouxu``
This PR introduce a supplementary check that when checking for a compiletest directive, will also check that the next "word" after that directive is not also by itself a directive.
This is done to avoid situations like this
//@ only-linux only-x86_64
where one might think that both directives are being taken into account while in fact the second in a comment, and so was ignored, until now.Related to #123730
cc @scottmcm
r? @jieyouxu