Skip to content

Commit 38c8f5b

Browse files
committed
Provide error context if can't find or open Cargo.toml;
Prefer edition setting from Cargo.toml over book.toml; sadly, Cargo also overrides command line.
1 parent 248f490 commit 38c8f5b

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/book/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,11 @@ impl MDBook {
344344
.args(&library_args) // also need --extern for doctest to actually work
345345
.args(extern_args.get_args());
346346

347-
if let Some(edition) = self.config.rust.edition {
347+
// rustdoc edition from cargo manifest takes precedence over book.toml
348+
// bugbug but also takes precedence over command line flag -- that seems rude.
349+
if extern_args.edition != "" {
350+
cmd.args(["--edition", &extern_args.edition]);
351+
} else if let Some(edition) = self.config.rust.edition {
348352
match edition {
349353
RustEdition::E2015 => {
350354
cmd.args(["--edition", "2015"]);
@@ -361,6 +365,7 @@ impl MDBook {
361365
}
362366
}
363367

368+
// bugbug Why show color in hidden invocation of rustdoc?
364369
if color_output {
365370
cmd.args(["--color", "always"]);
366371
}

src/utils/extern_args.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ use std::process::Command;
4242
4343
#[derive(Debug)]
4444
pub struct ExternArgs {
45-
edition: String, // where default value of "" means arg wasn't specified
46-
crate_name: String,
45+
/// rust edition as specified in manifest
46+
pub edition: String, // where default value of "" means arg wasn't specified
47+
/// crate name as specified in manifest
48+
pub crate_name: String,
49+
// accumulated library path(s), as observed from live cargo run
4750
lib_list: Vec<String>,
51+
// explicit extern crates, as observed from live cargo run
4852
extern_list: Vec<String>,
4953
}
5054

@@ -65,11 +69,18 @@ impl ExternArgs {
6569
pub fn load(&mut self, cargo_path: &Path) -> Result<&Self> {
6670
// find Cargo.toml and determine the package name and lib or bin source file.
6771
let proj_root = cargo_path
68-
.canonicalize()?
72+
.canonicalize()
73+
.context(format!(
74+
"can't find cargo manifest {}",
75+
&cargo_path.to_string_lossy()
76+
))?
6977
.parent()
7078
.ok_or(anyhow!("can't find parent of {:?}", cargo_path))?
7179
.to_owned();
72-
let mut manifest = Manifest::from_path(&cargo_path)?;
80+
let mut manifest = Manifest::from_path(&cargo_path).context(format!(
81+
"can't open cargo manifest {}",
82+
&cargo_path.to_string_lossy()
83+
))?;
7384
manifest.complete_from_path(&proj_root)?; // try real hard to determine bin or lib
7485
let package = manifest
7586
.package
@@ -204,10 +215,6 @@ impl ExternArgs {
204215
/// provide the parsed external args used to invoke rustdoc (--edition, -L and --extern).
205216
pub fn get_args(&self) -> Vec<String> {
206217
let mut ret_val: Vec<String> = vec![];
207-
if self.edition != "" {
208-
ret_val.push("--edition".to_owned());
209-
ret_val.push(self.edition.clone());
210-
};
211218
for i in &self.lib_list {
212219
ret_val.push("-L".to_owned());
213220
ret_val.push(i.clone());

0 commit comments

Comments
 (0)