Skip to content

Commit 25d26a6

Browse files
committed
add comments and LintGroup struct for more clarity
1 parent 84ef784 commit 25d26a6

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

compiler/rustc_lint/src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ pub struct LintStore {
6363
}
6464

6565
impl LintStoreMarker for LintStore {
66-
fn lint_groups(&self) -> Box<dyn Iterator<Item = (&'static str, Vec<LintId>, bool)> + '_> {
67-
Box::new(self.get_lint_groups())
66+
fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = rustc_session::LintGroup> + '_> {
67+
Box::new(self.get_lint_groups().map(|(name, lints, is_externally_loaded)| {
68+
rustc_session::LintGroup { name, lints, is_externally_loaded }
69+
}))
6870
}
6971
}
7072

compiler/rustc_middle/src/lint.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,27 @@ fn explain_lint_level_source(
217217
src: LintLevelSource,
218218
err: &mut Diag<'_, ()>,
219219
) {
220+
/// Find the name of the lint group that contains the given lint.
221+
/// Assumes the lint only belongs to one group.
220222
fn lint_group_name(
221223
lint: &'static Lint,
222224
sess: &Session,
223225
allow_external: bool,
224226
) -> Option<&'static str> {
225-
let mut lint_groups_iter = sess.lint_groups();
227+
let mut lint_groups_iter = sess.lint_groups_iter();
226228
let lint_id = LintId::of(lint);
227229
lint_groups_iter
228230
.find(|lint_group| {
229-
let lints = &lint_group.1;
230-
if !allow_external && lint_group.2 {
231+
if !allow_external && lint_group.is_externally_loaded {
231232
return false;
232233
}
233-
lints.iter().find(|lint_group_lint| **lint_group_lint == lint_id).is_some()
234+
lint_group
235+
.lints
236+
.iter()
237+
.find(|lint_group_lint| **lint_group_lint == lint_id)
238+
.is_some()
234239
})
235-
.map(|lint_group| lint_group.0)
240+
.map(|lint_group| lint_group.name)
236241
}
237242
let name = lint.name_lower();
238243
if let Level::Allow = level {

compiler/rustc_session/src/session.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ pub struct CompilerIO {
141141
}
142142

143143
pub trait LintStoreMarker: Any + DynSync + DynSend {
144-
fn lint_groups(&self) -> Box<dyn Iterator<Item = (&'static str, Vec<LintId>, bool)> + '_>;
144+
/// Provides a way to access lint groups without depending on `rustc_lint`
145+
fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = LintGroup> + '_>;
145146
}
146147

147148
/// Represents the data associated with a compilation
@@ -243,6 +244,12 @@ impl CodegenUnits {
243244
}
244245
}
245246

247+
pub struct LintGroup {
248+
pub name: &'static str,
249+
pub lints: Vec<LintId>,
250+
pub is_externally_loaded: bool,
251+
}
252+
246253
impl Session {
247254
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
248255
self.miri_unleashed_features.lock().push((span, feature_gate));
@@ -607,9 +614,9 @@ impl Session {
607614
}
608615
}
609616

610-
pub fn lint_groups(&self) -> Box<dyn Iterator<Item = (&'static str, Vec<LintId>, bool)> + '_> {
617+
pub fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = LintGroup> + '_> {
611618
match self.lint_store {
612-
Some(ref lint_store) => lint_store.lint_groups(),
619+
Some(ref lint_store) => lint_store.lint_groups_iter(),
613620
None => Box::new(std::iter::empty()),
614621
}
615622
}

0 commit comments

Comments
 (0)