From 45bad64ab43bd5af4ef6d540294c81e6bb4f89be Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 17 Nov 2023 15:21:00 -0500 Subject: [PATCH 1/2] rustc_lint: remove superfluous assertion `Option::unwrap` is called on the next line. --- compiler/rustc_lint/src/late.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 551fe23f9f19b..b47b3d41b12b9 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -33,7 +33,6 @@ use std::cell::Cell; /// Extract the `LintStore` from the query context. /// This function exists because we've erased `LintStore` as `dyn Any` in the session. pub fn unerased_lint_store(sess: &Session) -> &LintStore { - assert!(sess.lint_store.is_some()); let store: &Lrc<_> = sess.lint_store.as_ref().unwrap(); let store: &dyn Any = &**store; store.downcast_ref().unwrap() From 55393b6eca0c203b03b76447e42af0bd1d06204d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Fri, 17 Nov 2023 15:24:55 -0500 Subject: [PATCH 2/2] rustc_session: implement latent TODO --- compiler/rustc_lint/src/context.rs | 4 +++- compiler/rustc_lint/src/late.rs | 5 +++-- compiler/rustc_lint/src/lib.rs | 1 + compiler/rustc_session/src/session.rs | 7 +++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index fbcb49b1df5c0..9bc9f88d3f72b 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -36,7 +36,7 @@ use rustc_middle::ty::{self, print::Printer, GenericArg, RegisteredTools, Ty, Ty use rustc_session::config::ExpectedValues; use rustc_session::lint::{BuiltinLintDiagnostics, LintExpectationId}; use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId}; -use rustc_session::Session; +use rustc_session::{LintStoreMarker, Session}; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::{BytePos, Span}; @@ -77,6 +77,8 @@ pub struct LintStore { lint_groups: FxHashMap<&'static str, LintGroup>, } +impl LintStoreMarker for LintStore {} + /// The target of the `by_name` map, which accounts for renaming/deprecation. #[derive(Debug)] enum TargetLint { diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index b47b3d41b12b9..4f0cf5c52542b 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -30,8 +30,9 @@ use rustc_span::Span; use std::any::Any; use std::cell::Cell; -/// Extract the `LintStore` from the query context. -/// This function exists because we've erased `LintStore` as `dyn Any` in the session. +/// Extract the [`LintStore`] from [`Session`]. +/// +/// This function exists because [`Session::lint_store`] is type-erased. pub fn unerased_lint_store(sess: &Session) -> &LintStore { let store: &Lrc<_> = sess.lint_store.as_ref().unwrap(); let store: &dyn Any = &**store; diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index a48a8bd71b9ab..6585d4a6281f3 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -39,6 +39,7 @@ #![feature(min_specialization)] #![feature(never_type)] #![feature(rustc_attrs)] +#![cfg_attr(bootstrap, feature(trait_upcasting))] #![recursion_limit = "256"] #![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::diagnostic_outside_of_impl)] diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index efd75ce61518b..20a67d6d036c7 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -139,6 +139,8 @@ pub struct CompilerIO { pub temps_dir: Option, } +pub trait LintStoreMarker: Any + DynSync + DynSend {} + /// Represents the data associated with a compilation /// session for a single crate. pub struct Session { @@ -171,10 +173,7 @@ pub struct Session { pub jobserver: Client, /// This only ever stores a `LintStore` but we don't want a dependency on that type here. - /// - /// FIXME(Centril): consider `dyn LintStoreMarker` once - /// we can upcast to `Any` for some additional type safety. - pub lint_store: Option>, + pub lint_store: Option>, /// Should be set if any lints are registered in `lint_store`. pub registered_lints: bool,