@@ -26,7 +26,7 @@ use rustc_metadata::creader::CrateLoader;
26
26
use rustc_metadata:: cstore:: CStore ;
27
27
use rustc_target:: spec:: TargetTriple ;
28
28
29
- use syntax:: ast:: { self , Ident , Name , NodeId } ;
29
+ use syntax:: ast:: { self , Ident } ;
30
30
use syntax:: codemap;
31
31
use syntax:: edition:: Edition ;
32
32
use syntax:: feature_gate:: UnstableFeatures ;
@@ -45,8 +45,9 @@ use std::path::PathBuf;
45
45
46
46
use visit_ast:: RustdocVisitor ;
47
47
use clean;
48
- use clean:: { get_path_for_type, Clean , MAX_DEF_ID } ;
48
+ use clean:: { get_path_for_type, Clean , MAX_DEF_ID , AttributesExt } ;
49
49
use html:: render:: RenderInfo ;
50
+ use passes;
50
51
51
52
pub use rustc:: session:: config:: { Input , Options , CodegenOptions } ;
52
53
pub use rustc:: session:: search_paths:: SearchPaths ;
@@ -57,7 +58,6 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> {
57
58
pub tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
58
59
pub resolver : & ' a RefCell < resolve:: Resolver < ' rcx , ' cstore > > ,
59
60
/// The stack of module NodeIds up till this point
60
- pub mod_ids : RefCell < Vec < NodeId > > ,
61
61
pub crate_name : Option < String > ,
62
62
pub cstore : Rc < CStore > ,
63
63
pub populated_all_crate_impls : Cell < bool > ,
@@ -87,7 +87,6 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> {
87
87
pub all_fake_def_ids : RefCell < FxHashSet < DefId > > ,
88
88
/// Maps (type_id, trait_id) -> auto trait impl
89
89
pub generated_synthetics : RefCell < FxHashSet < ( DefId , DefId ) > > ,
90
- pub current_item_name : RefCell < Option < Name > > ,
91
90
pub all_traits : Vec < DefId > ,
92
91
}
93
92
@@ -322,7 +321,10 @@ pub fn run_core(search_paths: SearchPaths,
322
321
error_format : ErrorOutputType ,
323
322
cmd_lints : Vec < ( String , lint:: Level ) > ,
324
323
lint_cap : Option < lint:: Level > ,
325
- describe_lints : bool ) -> ( clean:: Crate , RenderInfo )
324
+ describe_lints : bool ,
325
+ mut manual_passes : Vec < String > ,
326
+ mut default_passes : passes:: DefaultPassOption )
327
+ -> ( clean:: Crate , RenderInfo , Vec < String > )
326
328
{
327
329
// Parse, resolve, and typecheck the given crate.
328
330
@@ -517,23 +519,86 @@ pub fn run_core(search_paths: SearchPaths,
517
519
ty_substs : Default :: default ( ) ,
518
520
lt_substs : Default :: default ( ) ,
519
521
impl_trait_bounds : Default :: default ( ) ,
520
- mod_ids : Default :: default ( ) ,
521
522
send_trait : send_trait,
522
523
fake_def_ids : RefCell :: new ( FxHashMap ( ) ) ,
523
524
all_fake_def_ids : RefCell :: new ( FxHashSet ( ) ) ,
524
525
generated_synthetics : RefCell :: new ( FxHashSet ( ) ) ,
525
- current_item_name : RefCell :: new ( None ) ,
526
526
all_traits : tcx. all_traits ( LOCAL_CRATE ) . to_vec ( ) ,
527
527
} ;
528
528
debug ! ( "crate: {:?}" , tcx. hir. krate( ) ) ;
529
529
530
- let krate = {
530
+ let mut krate = {
531
531
let mut v = RustdocVisitor :: new ( & ctxt) ;
532
532
v. visit ( tcx. hir . krate ( ) ) ;
533
533
v. clean ( & ctxt)
534
534
} ;
535
535
536
- ( krate, ctxt. renderinfo . into_inner ( ) )
536
+ fn report_deprecated_attr ( name : & str , diag : & errors:: Handler ) {
537
+ let mut msg = diag. struct_warn ( & format ! ( "the `#![doc({})]` attribute is \
538
+ considered deprecated", name) ) ;
539
+ msg. warn ( "please see https://github.com/rust-lang/rust/issues/44136" ) ;
540
+
541
+ if name == "no_default_passes" {
542
+ msg. help ( "you may want to use `#![doc(document_private_items)]`" ) ;
543
+ }
544
+
545
+ msg. emit ( ) ;
546
+ }
547
+
548
+ // Process all of the crate attributes, extracting plugin metadata along
549
+ // with the passes which we are supposed to run.
550
+ for attr in krate. module . as_ref ( ) . unwrap ( ) . attrs . lists ( "doc" ) {
551
+ let diag = ctxt. sess ( ) . diagnostic ( ) ;
552
+
553
+ let name = attr. name ( ) . map ( |s| s. as_str ( ) ) ;
554
+ let name = name. as_ref ( ) . map ( |s| & s[ ..] ) ;
555
+ if attr. is_word ( ) {
556
+ if name == Some ( "no_default_passes" ) {
557
+ report_deprecated_attr ( "no_default_passes" , diag) ;
558
+ if default_passes == passes:: DefaultPassOption :: Default {
559
+ default_passes = passes:: DefaultPassOption :: None ;
560
+ }
561
+ }
562
+ } else if let Some ( value) = attr. value_str ( ) {
563
+ let sink = match name {
564
+ Some ( "passes" ) => {
565
+ report_deprecated_attr ( "passes = \" ...\" " , diag) ;
566
+ & mut manual_passes
567
+ } ,
568
+ Some ( "plugins" ) => {
569
+ report_deprecated_attr ( "plugins = \" ...\" " , diag) ;
570
+ eprintln ! ( "WARNING: #![doc(plugins = \" ...\" )] no longer functions; \
571
+ see CVE-2018-1000622") ;
572
+ continue
573
+ } ,
574
+ _ => continue ,
575
+ } ;
576
+ for p in value. as_str ( ) . split_whitespace ( ) {
577
+ sink. push ( p. to_string ( ) ) ;
578
+ }
579
+ }
580
+
581
+ if attr. is_word ( ) && name == Some ( "document_private_items" ) {
582
+ if default_passes == passes:: DefaultPassOption :: Default {
583
+ default_passes = passes:: DefaultPassOption :: Private ;
584
+ }
585
+ }
586
+ }
587
+
588
+ let mut passes: Vec < String > =
589
+ passes:: defaults ( default_passes) . iter ( ) . map ( |p| p. to_string ( ) ) . collect ( ) ;
590
+ passes. extend ( manual_passes) ;
591
+
592
+ for pass in & passes {
593
+ // the "unknown pass" error will be reported when late passes are run
594
+ if let Some ( pass) = passes:: find_pass ( pass) . and_then ( |p| p. early_fn ( ) ) {
595
+ krate = pass ( krate, & ctxt) ;
596
+ }
597
+ }
598
+
599
+ ctxt. sess ( ) . abort_if_errors ( ) ;
600
+
601
+ ( krate, ctxt. renderinfo . into_inner ( ) , passes)
537
602
} ) , & sess)
538
603
} )
539
604
}
0 commit comments