@@ -364,6 +364,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
364364 ..Options :: default ( )
365365 } ;
366366
367+ lazy_static ! {
368+ static ref EMPTY_MAP : FxHashSet <LocalDefId > = FxHashSet :: default ( ) ;
369+ }
367370 let config = interface:: Config {
368371 opts : sessopts,
369372 crate_cfg : interface:: parse_cfgspecs ( cfgs) ,
@@ -378,8 +381,13 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
378381 lint_caps,
379382 register_lints : None ,
380383 override_queries : Some ( |_sess, local_providers, external_providers| {
384+ // Most lints will require typechecking, so just don't run them.
381385 local_providers. lint_mod = |_, _| { } ;
382386 external_providers. lint_mod = |_, _| { } ;
387+ local_providers. typeck_item_bodies = |_, _| { } ;
388+ // hack so that `used_trait_imports` won't try to call typeck_tables_of
389+ local_providers. used_trait_imports = |_, _| & EMPTY_MAP ;
390+ // In case typeck does end up being called, don't ICE in case there were name resolution errors
383391 local_providers. typeck_tables_of = move |tcx, def_id| {
384392 // Closures' tables come from their outermost function,
385393 // as they are part of the same "inference environment".
@@ -439,6 +447,13 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
439447 let mut global_ctxt = abort_on_err ( queries. global_ctxt ( ) , sess) . take ( ) ;
440448
441449 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
454+ // (see `override_queries` in the `config`)
455+ let _ = rustc_typeck:: check_crate ( tcx) ;
456+ tcx. sess . abort_if_errors ( ) ;
442457 sess. time ( "missing_docs" , || {
443458 rustc_lint:: check_crate ( tcx, rustc_lint:: builtin:: MissingDoc :: new) ;
444459 } ) ;
0 commit comments