Skip to content

Commit ef834dd

Browse files
committed
Seed all configs with the default config
1 parent dc8c517 commit ef834dd

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
lines changed

src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Config {
120120
pub fn cargo(root_dir: impl Into<PathBuf>) -> Self {
121121
Self {
122122
program: CommandBuilder::cargo(),
123-
comment_defaults: Default::default(),
123+
comment_defaults: Comments::default(),
124124
mode: Mode::Fail {
125125
require_patterns: true,
126126
rustfix: RustfixMode::Disabled,

src/lib.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ pub fn test_command(mut config: Config, path: &Path) -> Result<Command> {
190190
config.fill_host_and_target()?;
191191
let extra_args = config.build_dependencies()?;
192192

193-
let comments =
194-
Comments::parse_file(path)?.map_err(|errors| color_eyre::eyre::eyre!("{errors:#?}"))?;
193+
let comments = Comments::parse_file(config.comment_defaults.clone(), path)?
194+
.map_err(|errors| color_eyre::eyre::eyre!("{errors:#?}"))?;
195195
let mut result = build_command(path, &config, "", &comments).unwrap();
196196
result.args(extra_args);
197197

@@ -434,7 +434,11 @@ fn parse_and_test_file(
434434
mut config: Config,
435435
file_contents: Vec<u8>,
436436
) -> Result<Vec<TestRun>, Errored> {
437-
let comments = parse_comments(&file_contents, status.path())?;
437+
let comments = parse_comments(
438+
&file_contents,
439+
config.comment_defaults.clone(),
440+
status.path(),
441+
)?;
438442
const EMPTY: &[String] = &[String::new()];
439443
// Run the test for all revisions
440444
let revisions = comments.revisions.as_deref().unwrap_or(EMPTY);
@@ -472,8 +476,12 @@ fn parse_and_test_file(
472476
.collect())
473477
}
474478

475-
fn parse_comments(file_contents: &[u8], file: &Path) -> Result<Comments, Errored> {
476-
match Comments::parse(file_contents, file) {
479+
fn parse_comments(
480+
file_contents: &[u8],
481+
comments: Comments,
482+
file: &Path,
483+
) -> Result<Comments, Errored> {
484+
match Comments::parse(file_contents, comments, file) {
477485
Ok(comments) => Ok(comments),
478486
Err(errors) => Err(Errored {
479487
command: Command::new("parse comments"),
@@ -501,7 +509,7 @@ fn build_command(
501509
{
502510
cmd.arg(arg);
503511
}
504-
let edition = comments.edition(revision, &config.comment_defaults)?;
512+
let edition = comments.edition(revision)?;
505513

506514
if let Some(edition) = edition {
507515
cmd.arg("--edition").arg(&*edition);
@@ -528,7 +536,7 @@ fn build_aux(
528536
stderr: err.to_string().into_bytes(),
529537
stdout: vec![],
530538
})?;
531-
let comments = parse_comments(&file_contents, aux_file)?;
539+
let comments = parse_comments(&file_contents, Comments::default(), aux_file)?;
532540
assert_eq!(
533541
comments.revisions, None,
534542
"aux builds cannot specify revisions"
@@ -878,7 +886,7 @@ fn run_rustfix(
878886
stdout: stdout.into(),
879887
})?;
880888

881-
let edition = comments.edition(revision, &config.comment_defaults)?.into();
889+
let edition = comments.edition(revision)?.into();
882890
let rustfix_comments = Comments {
883891
revisions: None,
884892
revisioned: std::iter::once((

src/parser.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,10 @@ impl Comments {
8888
})
8989
}
9090

91-
pub(crate) fn edition(
92-
&self,
93-
revision: &str,
94-
default: &Self,
95-
) -> Result<Option<Spanned<String>>, Errored> {
96-
let edition =
97-
self.find_one_for_revision(revision, "`edition` annotations", |r| r.edition.clone())?;
98-
let default = default
99-
.find_one_for_revision(revision, "`edition` annotations", |r| r.edition.clone())?;
100-
let edition = edition.into_inner().or(default.into_inner());
91+
pub(crate) fn edition(&self, revision: &str) -> Result<Option<Spanned<String>>, Errored> {
92+
let edition = self
93+
.find_one_for_revision(revision, "`edition` annotations", |r| r.edition.clone())?
94+
.into_inner();
10195
Ok(edition)
10296
}
10397

@@ -222,20 +216,24 @@ impl Condition {
222216
}
223217

224218
impl Comments {
225-
pub(crate) fn parse_file(path: &Path) -> Result<std::result::Result<Self, Vec<Error>>> {
219+
pub(crate) fn parse_file(
220+
comments: Comments,
221+
path: &Path,
222+
) -> Result<std::result::Result<Self, Vec<Error>>> {
226223
let content =
227224
std::fs::read(path).wrap_err_with(|| format!("failed to read {}", path.display()))?;
228-
Ok(Self::parse(&content, path))
225+
Ok(Self::parse(&content, comments, path))
229226
}
230227

231228
/// Parse comments in `content`.
232229
/// `path` is only used to emit diagnostics if parsing fails.
233230
pub(crate) fn parse(
234231
content: &(impl AsRef<[u8]> + ?Sized),
232+
comments: Comments,
235233
file: &Path,
236234
) -> std::result::Result<Self, Vec<Error>> {
237235
let mut parser = CommentParser {
238-
comments: Comments::default(),
236+
comments,
239237
errors: vec![],
240238
commands: CommentParser::<_>::commands(),
241239
};

src/parser/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address $HEX is unallocated)
1717
}
1818
";
19-
let comments = Comments::parse(s, Path::new("")).unwrap();
19+
let comments = Comments::parse(s, Comments::default(), Path::new("")).unwrap();
2020
println!("parsed comments: {:#?}", comments);
2121
assert_eq!(comments.revisioned.len(), 1);
2222
let revisioned = &comments.revisioned[&vec![]];
@@ -41,7 +41,7 @@ fn main() {
4141
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ encountered a dangling reference (address $HEX is unallocated)
4242
}
4343
";
44-
let errors = Comments::parse(s, Path::new("")).unwrap_err();
44+
let errors = Comments::parse(s, Comments::default(), Path::new("")).unwrap_err();
4545
println!("parsed comments: {:#?}", errors);
4646
assert_eq!(errors.len(), 1);
4747
match &errors[0] {
@@ -59,7 +59,7 @@ fn parse_slash_slash_at() {
5959
use std::mem;
6060
6161
";
62-
let comments = Comments::parse(s, Path::new("")).unwrap();
62+
let comments = Comments::parse(s, Comments::default(), Path::new("")).unwrap();
6363
println!("parsed comments: {:#?}", comments);
6464
assert_eq!(comments.revisioned.len(), 1);
6565
let revisioned = &comments.revisioned[&vec![]];
@@ -75,7 +75,7 @@ fn parse_regex_error_pattern() {
7575
use std::mem;
7676
7777
";
78-
let comments = Comments::parse(s, Path::new("")).unwrap();
78+
let comments = Comments::parse(s, Comments::default(), Path::new("")).unwrap();
7979
println!("parsed comments: {:#?}", comments);
8080
assert_eq!(comments.revisioned.len(), 1);
8181
let revisioned = &comments.revisioned[&vec![]];
@@ -91,7 +91,7 @@ fn parse_slash_slash_at_fail() {
9191
use std::mem;
9292
9393
";
94-
let errors = Comments::parse(s, Path::new("")).unwrap_err();
94+
let errors = Comments::parse(s, Comments::default(), Path::new("")).unwrap_err();
9595
println!("parsed comments: {:#?}", errors);
9696
assert_eq!(errors.len(), 2);
9797
match &errors[0] {
@@ -115,7 +115,7 @@ fn missing_colon_fail() {
115115
use std::mem;
116116
117117
";
118-
let errors = Comments::parse(s, Path::new("")).unwrap_err();
118+
let errors = Comments::parse(s, Comments::default(), Path::new("")).unwrap_err();
119119
println!("parsed comments: {:#?}", errors);
120120
assert_eq!(errors.len(), 1);
121121
match &errors[0] {
@@ -129,7 +129,7 @@ use std::mem;
129129
#[test]
130130
fn parse_x86_64() {
131131
let s = r"//@ only-target-x86_64-unknown-linux";
132-
let comments = Comments::parse(s, Path::new("")).unwrap();
132+
let comments = Comments::parse(s, Comments::default(), Path::new("")).unwrap();
133133
println!("parsed comments: {:#?}", comments);
134134
assert_eq!(comments.revisioned.len(), 1);
135135
let revisioned = &comments.revisioned[&vec![]];

src/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ fn main() {
2222
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address $HEX is unallocated)
2323
}
2424
";
25-
let comments = Comments::parse(s, Path::new("")).unwrap();
26-
let mut errors = vec![];
2725
let config = config();
26+
let comments = Comments::parse(s, config.comment_defaults.clone(), Path::new("")).unwrap();
27+
let mut errors = vec![];
2828
let messages = vec![
2929
vec![], vec![], vec![], vec![], vec![],
3030
vec![
@@ -61,8 +61,8 @@ fn main() {
6161
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address 0x10 is unallocated)
6262
}
6363
";
64-
let comments = Comments::parse(s, Path::new("")).unwrap();
6564
let config = config();
65+
let comments = Comments::parse(s, config.comment_defaults.clone(), Path::new("")).unwrap();
6666
{
6767
let messages = vec![vec![], vec![], vec![], vec![], vec![], vec![
6868
Message {
@@ -159,8 +159,8 @@ fn main() {
159159
//~^ ERROR: encountered a dangling reference (address 0x10 is unallocated)
160160
}
161161
";
162-
let comments = Comments::parse(s, Path::new("")).unwrap();
163162
let config = config();
163+
let comments = Comments::parse(s, config.comment_defaults.clone(), Path::new("")).unwrap();
164164
let messages = vec![
165165
vec![], vec![], vec![], vec![], vec![],
166166
vec![
@@ -197,8 +197,8 @@ fn main() {
197197
let _x: &i32 = unsafe { mem::transmute(16usize) }; //~ ERROR: encountered a dangling reference (address 0x10 is unallocated)
198198
}
199199
";
200-
let comments = Comments::parse(s, Path::new("")).unwrap();
201200
let config = config();
201+
let comments = Comments::parse(s, config.comment_defaults.clone(), Path::new("")).unwrap();
202202
let messages = vec![
203203
vec![], vec![], vec![], vec![], vec![],
204204
vec![
@@ -242,8 +242,8 @@ fn main() {
242242
//~^ WARN: cake
243243
}
244244
";
245-
let comments = Comments::parse(s, Path::new("")).unwrap();
246245
let config = config();
246+
let comments = Comments::parse(s, config.comment_defaults.clone(), Path::new("")).unwrap();
247247
let messages= vec![
248248
vec![],
249249
vec![],
@@ -306,8 +306,8 @@ fn main() {
306306
//~^ WARN: cake
307307
}
308308
";
309-
let comments = Comments::parse(s, Path::new("")).unwrap();
310309
let config = config();
310+
let comments = Comments::parse(s, config.comment_defaults.clone(), Path::new("")).unwrap();
311311
let messages = vec![
312312
vec![],
313313
vec![],

0 commit comments

Comments
 (0)