Skip to content

Commit 2531164

Browse files
committed
fix(gctx): show list index in config-include error
1 parent 01277ac commit 2531164

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/cargo/util/context/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,16 +1397,18 @@ impl GlobalContext {
13971397
Some(CV::String(s, def)) => vec![ConfigInclude::new(s, def)],
13981398
Some(CV::List(list, _def)) => list
13991399
.into_iter()
1400-
.map(|cv| match cv {
1400+
.enumerate()
1401+
.map(|(idx, cv)| match cv {
14011402
CV::String(s, def) => Ok(ConfigInclude::new(s, def)),
14021403
other => bail!(
1403-
"`include` expected a string or list of strings, but found {} in list",
1404-
other.desc()
1404+
"expected a string, but found {} at `include[{idx}]` in `{}",
1405+
other.desc(),
1406+
other.definition(),
14051407
),
14061408
})
14071409
.collect::<CargoResult<Vec<_>>>()?,
14081410
Some(other) => bail!(
1409-
"`include` expected a string or list, but found {} in `{}`",
1411+
"expected a string or list of strings, but found {} at `include` in `{}",
14101412
other.desc(),
14111413
other.definition()
14121414
),

tests/testsuite/config_include.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ fn bad_format() {
412412
could not load Cargo configuration
413413
414414
Caused by:
415-
`include` expected a string or list, but found integer in `[ROOT]/.cargo/config.toml`
415+
expected a string or list of strings, but found integer at `include` in `[ROOT]/.cargo/config.toml
416416
"#]],
417417
);
418418
}
@@ -530,7 +530,7 @@ fn inline_table_style() {
530530
could not load Cargo configuration
531531
532532
Caused by:
533-
`include` expected a string or list of strings, but found table in list
533+
expected a string, but found table at `include[1]` in `[ROOT]/.cargo/config.toml
534534
"#]],
535535
);
536536
}
@@ -575,7 +575,7 @@ fn array_of_tables_style() {
575575
could not load Cargo configuration
576576
577577
Caused by:
578-
`include` expected a string or list of strings, but found table in list
578+
expected a string, but found table at `include[0]` in `[ROOT]/.cargo/config.toml
579579
"#]],
580580
);
581581
}
@@ -610,7 +610,7 @@ fn table_with_unknown_fields() {
610610
could not load Cargo configuration
611611
612612
Caused by:
613-
`include` expected a string or list of strings, but found table in list
613+
expected a string, but found table at `include[0]` in `[ROOT]/.cargo/config.toml
614614
"#]],
615615
);
616616
}
@@ -636,7 +636,7 @@ fn table_missing_required_field() {
636636
could not load Cargo configuration
637637
638638
Caused by:
639-
`include` expected a string or list of strings, but found table in list
639+
expected a string, but found table at `include[0]` in `[ROOT]/.cargo/config.toml
640640
"#]],
641641
);
642642
}

0 commit comments

Comments
 (0)