Skip to content

Commit 4d78ae6

Browse files
committed
add comments and LintGroup struct for more clarity
1 parent 9f5c5c8 commit 4d78ae6

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
@@ -62,8 +62,10 @@ pub struct LintStore {
6262
}
6363

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

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
@@ -139,7 +139,8 @@ pub struct CompilerIO {
139139
}
140140

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

145146
/// Represents the data associated with a compilation
@@ -246,6 +247,12 @@ impl CodegenUnits {
246247
}
247248
}
248249

250+
pub struct LintGroup {
251+
pub name: &'static str,
252+
pub lints: Vec<LintId>,
253+
pub is_externally_loaded: bool,
254+
}
255+
249256
impl Session {
250257
pub fn miri_unleashed_feature(&self, span: Span, feature_gate: Option<Symbol>) {
251258
self.miri_unleashed_features.lock().push((span, feature_gate));
@@ -612,9 +619,9 @@ impl Session {
612619
}
613620
}
614621

615-
pub fn lint_groups(&self) -> Box<dyn Iterator<Item = (&'static str, Vec<LintId>, bool)> + '_> {
622+
pub fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = LintGroup> + '_> {
616623
match self.lint_store {
617-
Some(ref lint_store) => lint_store.lint_groups(),
624+
Some(ref lint_store) => lint_store.lint_groups_iter(),
618625
None => Box::new(std::iter::empty()),
619626
}
620627
}

0 commit comments

Comments
 (0)