1
1
use crate :: command_prelude:: * ;
2
2
3
+ use cargo:: core:: features;
3
4
use cargo:: ops:: { self , DocOptions } ;
4
5
5
6
pub fn cli ( ) -> App {
@@ -23,6 +24,7 @@ pub fn cli() -> App {
23
24
"Document only the specified binary" ,
24
25
"Document all binaries" ,
25
26
)
27
+ . arg ( opt ( "check" , "Runs `rustdoc --check` (nightly only)" ) )
26
28
. arg_release ( "Build artifacts in release mode, with optimizations" )
27
29
. arg_profile ( "Build artifacts with the specified profile" )
28
30
. arg_features ( )
@@ -35,18 +37,54 @@ pub fn cli() -> App {
35
37
}
36
38
37
39
pub 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 {
38
71
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" ) ;
45
72
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 ,
48
81
compile_opts,
49
82
} ;
83
+
84
+ if !mode. is_check ( ) {
85
+ doc_opts. open_result = args. is_present ( "open" ) ;
86
+ }
87
+
50
88
ops:: doc ( & ws, & doc_opts) ?;
51
89
Ok ( ( ) )
52
90
}
0 commit comments