@@ -377,18 +377,26 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
377
377
crate_name,
378
378
lint_caps,
379
379
register_lints : None ,
380
- override_queries : Some ( |_sess, local_providers, external_providers| {
381
- lazy_static ! {
382
- static ref EMPTY_SET : FxHashSet <LocalDefId > = FxHashSet :: default ( ) ;
383
- }
380
+ override_queries : Some ( |_sess, providers, _external_providers| {
384
381
// Most lints will require typechecking, so just don't run them.
385
- local_providers . lint_mod = |_, _| { } ;
386
- external_providers . lint_mod = |_ , _| { } ;
387
- local_providers . typeck_item_bodies = |_, _| { } ;
382
+ providers . lint_mod = |_, _| { } ;
383
+ // Prevent `rustc_typeck::check_crate` from calling `typeck_tables_of` on all bodies.
384
+ providers . typeck_item_bodies = |_, _| { } ;
388
385
// hack so that `used_trait_imports` won't try to call typeck_tables_of
389
- local_providers. used_trait_imports = |_, _| & EMPTY_SET ;
386
+ providers. used_trait_imports = |_, _| {
387
+ lazy_static ! {
388
+ static ref EMPTY_SET : FxHashSet <LocalDefId > = FxHashSet :: default ( ) ;
389
+ }
390
+ & EMPTY_SET
391
+ } ;
390
392
// In case typeck does end up being called, don't ICE in case there were name resolution errors
391
- local_providers. typeck_tables_of = move |tcx, def_id| {
393
+ providers. typeck_tables_of = move |tcx, def_id| {
394
+ thread_local ! ( static DEFAULT_TYPECK : for <' tcx> fn ( TyCtxt <' tcx>, LocalDefId ) -> & ' tcx ty:: TypeckTables <' tcx> = {
395
+ let mut providers = ty:: query:: Providers :: default ( ) ;
396
+ rustc_typeck:: provide( & mut providers) ;
397
+ providers. typeck_tables_of
398
+ } ) ;
399
+
392
400
// Closures' tables come from their outermost function,
393
401
// as they are part of the same "inference environment".
394
402
// This avoids emitting errors for the parent twice (see similar code in `typeck_tables_of_with_fallback`)
@@ -447,10 +455,11 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
447
455
let mut global_ctxt = abort_on_err ( queries. global_ctxt ( ) , sess) . take ( ) ;
448
456
449
457
global_ctxt. enter ( |tcx| {
450
- // Some queries require that they only run on valid types:
451
- // https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425
452
- // Therefore typecheck this crate before running lints.
453
- // NOTE: this does not typeck item bodies or run the default rustc lints
458
+ // Certain queries assume that some checks were run elsewhere
459
+ // (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),
460
+ // so type-check everything other than function bodies in this crate before running lints.
461
+ // NOTE: this does not call `tcx.analysis()` so that we won't
462
+ // typeck function bodies or run the default rustc lints.
454
463
// (see `override_queries` in the `config`)
455
464
let _ = rustc_typeck:: check_crate ( tcx) ;
456
465
tcx. sess . abort_if_errors ( ) ;
@@ -607,12 +616,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
607
616
} )
608
617
}
609
618
610
- thread_local ! ( static DEFAULT_TYPECK : for <' tcx> fn ( TyCtxt <' tcx>, LocalDefId ) -> & ' tcx ty:: TypeckTables <' tcx> = {
611
- let mut providers = ty:: query:: Providers :: default ( ) ;
612
- rustc_typeck:: provide( & mut providers) ;
613
- providers. typeck_tables_of
614
- } ) ;
615
-
616
619
/// Due to https://github.com/rust-lang/rust/pull/73566,
617
620
/// the name resolution pass may find errors that are never emitted.
618
621
/// If typeck is called after this happens, then we'll get an ICE:
0 commit comments