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 <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-07-26 11:42:27 +01:00
parent 1b8e4b9391
commit f5e005f0ca
5 changed files with 11 additions and 17 deletions

View File

@ -249,7 +249,7 @@ fn run_compiler(
if sopts.describe_lints {
let mut lint_store = rustc_lint::new_lint_store(
sopts.unstable_opts.no_interleave_lints,
compiler.session().unstable_options(),
compiler.session().enable_internal_lints(),
);
let registered_lints =
if let Some(register_lints) = compiler.register_lints() {

View File

@ -210,7 +210,7 @@ pub fn register_plugins<'a>(
let mut lint_store = rustc_lint::new_lint_store(
sess.opts.unstable_opts.no_interleave_lints,
sess.unstable_options(),
sess.enable_internal_lints(),
);
register_lints(sess, &mut lint_store);

View File

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

View File

@ -589,6 +589,14 @@ pub fn verbose(&self) -> bool {
pub fn time_passes(&self) -> bool {
self.opts.unstable_opts.time_passes || self.opts.unstable_opts.time
}
/// Returns `true` if internal lints should be added to the lint store - i.e. if
/// `-Zunstable-options` is provided and this isn't rustdoc (internal lints can trigger errors
/// to be emitted under rustdoc).
pub fn enable_internal_lints(&self) -> bool {
self.unstable_options() && !self.opts.actually_rustdoc
}
pub fn instrument_mcount(&self) -> bool {
self.opts.unstable_opts.instrument_mcount
}

View File

@ -788,7 +788,7 @@ fn main_options(options: config::Options) -> MainResult {
if sess.opts.describe_lints {
let mut lint_store = rustc_lint::new_lint_store(
sess.opts.unstable_opts.no_interleave_lints,
sess.unstable_options(),
sess.enable_internal_lints(),
);
let registered_lints = if let Some(register_lints) = compiler.register_lints() {
register_lints(sess, &mut lint_store);