11use crate :: command_prelude:: * ;
22
3+ use cargo:: core:: features;
34use cargo:: ops:: { self , DocOptions } ;
45
56pub fn cli ( ) -> App {
@@ -23,6 +24,7 @@ pub fn cli() -> App {
2324 "Document only the specified binary" ,
2425 "Document all binaries" ,
2526 )
27+ . arg ( opt ( "check" , "Runs `rustdoc --check` (nightly only)" ) )
2628 . arg_release ( "Build artifacts in release mode, with optimizations" )
2729 . arg_profile ( "Build artifacts with the specified profile" )
2830 . arg_features ( )
@@ -35,18 +37,54 @@ pub fn cli() -> App {
3537}
3638
3739pub fn exec ( config : & mut Config , args : & ArgMatches < ' _ > ) -> CliResult {
40+ if args. is_present ( "check" ) {
41+ if !features:: nightly_features_allowed ( ) {
42+ Err ( CliError :: new (
43+ anyhow:: format_err!( "This option is only available in nightly" ) ,
44+ 1 ,
45+ ) ) ?;
46+ }
47+ exec_doc (
48+ config,
49+ args,
50+ CompileMode :: DocCheck ,
51+ ProfileChecking :: Unchecked ,
52+ )
53+ } else {
54+ exec_doc (
55+ config,
56+ args,
57+ CompileMode :: Doc {
58+ deps : !args. is_present ( "no-deps" ) ,
59+ } ,
60+ ProfileChecking :: Checked ,
61+ )
62+ }
63+ }
64+
65+ pub fn exec_doc (
66+ config : & mut Config ,
67+ args : & ArgMatches < ' _ > ,
68+ mode : CompileMode ,
69+ profile : ProfileChecking ,
70+ ) -> CliResult {
3871 let ws = args. workspace ( config) ?;
39- let mode = CompileMode :: Doc {
40- deps : !args. is_present ( "no-deps" ) ,
41- } ;
42- let mut compile_opts =
43- args. compile_options ( config, mode, Some ( & ws) , ProfileChecking :: Checked ) ?;
44- compile_opts. rustdoc_document_private_items = args. is_present ( "document-private-items" ) ;
4572
46- let doc_opts = DocOptions {
47- open_result : args. is_present ( "open" ) ,
73+ let mut compile_opts = args. compile_options ( config, mode, Some ( & ws) , profile) ?;
74+
75+ if !mode. is_check ( ) {
76+ compile_opts. rustdoc_document_private_items = args. is_present ( "document-private-items" ) ;
77+ }
78+
79+ let mut doc_opts = DocOptions {
80+ open_result : false ,
4881 compile_opts,
4982 } ;
83+
84+ if !mode. is_check ( ) {
85+ doc_opts. open_result = args. is_present ( "open" ) ;
86+ }
87+
5088 ops:: doc ( & ws, & doc_opts) ?;
5189 Ok ( ( ) )
5290}
0 commit comments