Skip to content

Commit 1ebb9ec

Browse files
improve error messages and documentation
1 parent 82a7b32 commit 1ebb9ec

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/doc/rustdoc/src/command-line-arguments.md

+21-13
Original file line numberDiff line numberDiff line change
@@ -359,26 +359,34 @@ This flag allows `rustdoc` to treat your rust code as the given edition. It will
359359
the given edition as well. As with `rustc`, the default edition that `rustdoc` will use is `2015`
360360
(the first edition).
361361

362-
## `theme`: add more themes to generated documentation
362+
## `--theme`: add a theme to the documentation output
363363

364-
By default, `rustdoc` only provides the "dark" and "light" themes. If you want to add new ones,
365-
you'll need to use this flag as follows:
364+
Using this flag looks like this:
366365

367366
```bash
368-
$ rustdoc src/lib.rs --theme /path/to/your/theme/file.css
367+
$ rustdoc src/lib.rs --theme /path/to/your/custom-theme.css
369368
```
370369

371-
Note that the theme's name will be the file name without its extension. So if you pass
372-
`/path/to/your/theme/file.css` as theme, then the theme's name will be `file`.
373-
374-
### `check-theme`: check if your themes implement all the required rules
370+
`rustdoc`'s default output includes two themes: `light` (the default) and
371+
`dark`. This flag allows you to add custom themes to the output. Giving a CSS
372+
file to this flag adds it to your documentation as an additional theme choice.
373+
The theme's name is determined by its filename; a theme file named
374+
`custom-theme.css` will add a theme named `custom-theme` to the documentation.
375375

376-
This flag allows you to check if your themes implement the necessary CSS rules. To put it more
377-
simply, when adding a new theme, it needs to implement all the CSS rules present in the "light"
378-
CSS theme.
376+
## `--check-theme`: verify custom themes against the default theme
379377

380-
You can use this flag like this:
378+
Using this flag looks like this:
381379

382380
```bash
383-
$ rustdoc --check-theme /path/to/your/theme/file.css
381+
$ rustdoc --check-theme /path/to/your/custom-theme.css
384382
```
383+
384+
While `rustdoc`'s HTML output is more-or-less consistent between versions, there
385+
is no guarantee that a theme file will have the same effect. The `--theme` flag
386+
will still allow you to add the theme to your documentation, but to ensure that
387+
your theme works as expected, you can use this flag to verify that it implements
388+
the same CSS rules as the official `light` theme.
389+
390+
`--check-theme` is a separate mode in `rustdoc`. When `rustdoc` sees the
391+
`--check-theme` flag, it discards all other flags and only performs the CSS rule
392+
comparison operation.

src/librustdoc/config.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,13 @@ impl Options {
367367
.iter()
368368
.map(|s| (PathBuf::from(&s), s.to_owned())) {
369369
if !theme_file.is_file() {
370-
diag.struct_err(&format!("invalid file: \"{}\"", theme_s))
371-
.help("option --theme arguments must all be files")
370+
diag.struct_err(&format!("invalid argument: \"{}\"", theme_s))
371+
.help("arguments to --theme must be files")
372372
.emit();
373373
return Err(1);
374374
}
375375
if theme_file.extension() != Some(OsStr::new("css")) {
376-
diag.struct_err(&format!("invalid file: \"{}\": expected CSS file", theme_s))
376+
diag.struct_err(&format!("invalid argument: \"{}\"", theme_s))
377377
.emit();
378378
return Err(1);
379379
}

0 commit comments

Comments
 (0)