rustdoc: rework how default passes are chosen
This commit is contained in:
parent
46804ef0ce
commit
0db4317709
|
@ -373,6 +373,10 @@ pub fn main_args(args: &[String]) -> isize {
|
||||||
for &name in passes::DEFAULT_PASSES {
|
for &name in passes::DEFAULT_PASSES {
|
||||||
println!("{:>20}", name);
|
println!("{:>20}", name);
|
||||||
}
|
}
|
||||||
|
println!("\nPasses run with `--document-private-items`:");
|
||||||
|
for &name in passes::DEFAULT_PRIVATE_PASSES {
|
||||||
|
println!("{:>20}", name);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,21 +627,17 @@ fn rust_input<R, F>(cratefile: PathBuf,
|
||||||
where R: 'static + Send,
|
where R: 'static + Send,
|
||||||
F: 'static + Send + FnOnce(Output) -> R
|
F: 'static + Send + FnOnce(Output) -> R
|
||||||
{
|
{
|
||||||
let mut default_passes = !matches.opt_present("no-defaults");
|
let mut default_passes = if matches.opt_present("no-defaults") {
|
||||||
let mut passes = matches.opt_strs("passes");
|
passes::DefaultPassOption::None
|
||||||
|
} else if matches.opt_present("document-private-items") {
|
||||||
|
passes::DefaultPassOption::Private
|
||||||
|
} else {
|
||||||
|
passes::DefaultPassOption::Default
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut manual_passes = matches.opt_strs("passes");
|
||||||
let mut plugins = matches.opt_strs("plugins");
|
let mut plugins = matches.opt_strs("plugins");
|
||||||
|
|
||||||
// We hardcode in the passes here, as this is a new flag and we
|
|
||||||
// are generally deprecating passes.
|
|
||||||
if matches.opt_present("document-private-items") {
|
|
||||||
default_passes = false;
|
|
||||||
|
|
||||||
passes = vec![
|
|
||||||
String::from("collapse-docs"),
|
|
||||||
String::from("unindent-comments"),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
// First, parse the crate and extract all relevant information.
|
// First, parse the crate and extract all relevant information.
|
||||||
let mut paths = SearchPaths::new();
|
let mut paths = SearchPaths::new();
|
||||||
for s in &matches.opt_strs("L") {
|
for s in &matches.opt_strs("L") {
|
||||||
|
@ -706,13 +706,15 @@ where R: 'static + Send,
|
||||||
if attr.is_word() {
|
if attr.is_word() {
|
||||||
if name == Some("no_default_passes") {
|
if name == Some("no_default_passes") {
|
||||||
report_deprecated_attr("no_default_passes", &diag);
|
report_deprecated_attr("no_default_passes", &diag);
|
||||||
default_passes = false;
|
if default_passes == passes::DefaultPassOption::Default {
|
||||||
|
default_passes = passes::DefaultPassOption::None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if let Some(value) = attr.value_str() {
|
} else if let Some(value) = attr.value_str() {
|
||||||
let sink = match name {
|
let sink = match name {
|
||||||
Some("passes") => {
|
Some("passes") => {
|
||||||
report_deprecated_attr("passes = \"...\"", &diag);
|
report_deprecated_attr("passes = \"...\"", &diag);
|
||||||
&mut passes
|
&mut manual_passes
|
||||||
},
|
},
|
||||||
Some("plugins") => {
|
Some("plugins") => {
|
||||||
report_deprecated_attr("plugins = \"...\"", &diag);
|
report_deprecated_attr("plugins = \"...\"", &diag);
|
||||||
|
@ -726,20 +728,15 @@ where R: 'static + Send,
|
||||||
}
|
}
|
||||||
|
|
||||||
if attr.is_word() && name == Some("document_private_items") {
|
if attr.is_word() && name == Some("document_private_items") {
|
||||||
default_passes = false;
|
if default_passes == passes::DefaultPassOption::Default {
|
||||||
|
default_passes = passes::DefaultPassOption::Private;
|
||||||
passes = vec![
|
}
|
||||||
String::from("collapse-docs"),
|
|
||||||
String::from("unindent-comments"),
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if default_passes {
|
let mut passes: Vec<String> =
|
||||||
for name in passes::DEFAULT_PASSES.iter().rev() {
|
passes::defaults(default_passes).iter().map(|p| p.to_string()).collect();
|
||||||
passes.insert(0, name.to_string());
|
passes.extend(manual_passes);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !plugins.is_empty() {
|
if !plugins.is_empty() {
|
||||||
eprintln!("WARNING: --plugins no longer functions; see CVE-2018-1000622");
|
eprintln!("WARNING: --plugins no longer functions; see CVE-2018-1000622");
|
||||||
|
|
|
@ -63,6 +63,33 @@ pub const DEFAULT_PASSES: &'static [&'static str] = &[
|
||||||
"propagate-doc-cfg",
|
"propagate-doc-cfg",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pub const DEFAULT_PRIVATE_PASSES: &'static [&'static str] = &[
|
||||||
|
"strip-priv-imports",
|
||||||
|
"collapse-docs",
|
||||||
|
"unindent-comments",
|
||||||
|
"propagate-doc-cfg",
|
||||||
|
];
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||||
|
pub enum DefaultPassOption {
|
||||||
|
Default,
|
||||||
|
Private,
|
||||||
|
None,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn defaults(default_set: DefaultPassOption) -> &'static [&'static str] {
|
||||||
|
match default_set {
|
||||||
|
DefaultPassOption::Default => {
|
||||||
|
DEFAULT_PASSES
|
||||||
|
},
|
||||||
|
DefaultPassOption::Private => {
|
||||||
|
DEFAULT_PRIVATE_PASSES
|
||||||
|
},
|
||||||
|
DefaultPassOption::None => {
|
||||||
|
&[]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Stripper<'a> {
|
struct Stripper<'a> {
|
||||||
retained: &'a mut DefIdSet,
|
retained: &'a mut DefIdSet,
|
||||||
|
|
Loading…
Reference in New Issue