Skip to content

Commit f5e005f

Browse files
committed
session: disable internal lints for rustdoc
If an internal lint uses `typeck_results` or similar queries then that can result in rustdoc checking code that it shouldn't (e.g. from other platforms) and emit compilation errors. Signed-off-by: David Wood <[email protected]>
1 parent 1b8e4b9 commit f5e005f

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn run_compiler(
249249
if sopts.describe_lints {
250250
let mut lint_store = rustc_lint::new_lint_store(
251251
sopts.unstable_opts.no_interleave_lints,
252-
compiler.session().unstable_options(),
252+
compiler.session().enable_internal_lints(),
253253
);
254254
let registered_lints =
255255
if let Some(register_lints) = compiler.register_lints() {

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub fn register_plugins<'a>(
210210

211211
let mut lint_store = rustc_lint::new_lint_store(
212212
sess.opts.unstable_opts.no_interleave_lints,
213-
sess.unstable_options(),
213+
sess.enable_internal_lints(),
214214
);
215215
register_lints(sess, &mut lint_store);
216216

compiler/rustc_lint/src/internal.rs

-14
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ fn typeck_results_of_method_fn<'tcx>(
5151
cx: &LateContext<'tcx>,
5252
expr: &Expr<'_>,
5353
) -> Option<(Span, DefId, ty::subst::SubstsRef<'tcx>)> {
54-
// FIXME(rustdoc): Lints which use this function use typecheck results which can cause
55-
// `rustdoc` to error if there are resolution failures.
56-
//
57-
// As internal lints are currently always run if there are `unstable_options`, they are added
58-
// to the lint store of rustdoc. Internal lints are also not used via the `lint_mod` query.
59-
// Crate lints run outside of a query so rustdoc currently doesn't disable them.
60-
//
61-
// Instead of relying on this, either change crate lints to a query disabled by rustdoc, only
62-
// run internal lints if the user is explicitly opting in or figure out a different way to
63-
// avoid running lints for rustdoc.
64-
if cx.tcx.sess.opts.actually_rustdoc {
65-
return None;
66-
}
67-
6854
match expr.kind {
6955
ExprKind::MethodCall(segment, _, _)
7056
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) =>

compiler/rustc_session/src/session.rs

+8
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,14 @@ impl Session {
589589
pub fn time_passes(&self) -> bool {
590590
self.opts.unstable_opts.time_passes || self.opts.unstable_opts.time
591591
}
592+
593+
/// Returns `true` if internal lints should be added to the lint store - i.e. if
594+
/// `-Zunstable-options` is provided and this isn't rustdoc (internal lints can trigger errors
595+
/// to be emitted under rustdoc).
596+
pub fn enable_internal_lints(&self) -> bool {
597+
self.unstable_options() && !self.opts.actually_rustdoc
598+
}
599+
592600
pub fn instrument_mcount(&self) -> bool {
593601
self.opts.unstable_opts.instrument_mcount
594602
}

src/librustdoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ fn main_options(options: config::Options) -> MainResult {
788788
if sess.opts.describe_lints {
789789
let mut lint_store = rustc_lint::new_lint_store(
790790
sess.opts.unstable_opts.no_interleave_lints,
791-
sess.unstable_options(),
791+
sess.enable_internal_lints(),
792792
);
793793
let registered_lints = if let Some(register_lints) = compiler.register_lints() {
794794
register_lints(sess, &mut lint_store);

0 commit comments

Comments
 (0)