Skip to content

Commit 461c5b2

Browse files
committed
Rustc, Adapter: Address PR comments
1 parent 2233393 commit 461c5b2

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

marker_adapter/src/lib.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
pub mod context;
88
mod loader;
99

10-
use std::{
11-
cell::{RefCell, RefMut},
12-
ops::ControlFlow,
13-
};
10+
use std::{cell::RefCell, ops::ControlFlow};
1411

1512
use loader::LintCrateRegistry;
1613
use marker_api::{
@@ -56,17 +53,13 @@ impl Adapter {
5653
}
5754

5855
pub fn process_krate<'ast>(&self, cx: &'ast AstContext<'ast>, krate: &Crate<'ast>) {
59-
// `RefMut::map` is used to get a *pure* mutable reference, which can
60-
// then be used in the visitor. It might not be super pretty, but it works :)
61-
RefMut::map(self.inner.borrow_mut(), |inner| {
62-
inner.external_lint_crates.set_ast_context(cx);
56+
let inner = &mut *self.inner.borrow_mut();
6357

64-
for item in krate.items() {
65-
visitor::traverse_item::<()>(cx, inner, *item);
66-
}
58+
inner.external_lint_crates.set_ast_context(cx);
6759

68-
inner
69-
});
60+
for item in krate.items() {
61+
visitor::traverse_item::<()>(cx, inner, *item);
62+
}
7063
}
7164
}
7265

marker_lints/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ marker_api::declare_lint!(
1818
);
1919

2020
#[derive(Debug, Default)]
21-
struct MarkerLintPass;
21+
struct MarkerLintsLintPass;
2222

23-
marker_api::export_lint_pass!(MarkerLintPass);
23+
marker_api::export_lint_pass!(MarkerLintsLintPass);
2424

25-
impl LintPass for MarkerLintPass {
25+
impl LintPass for MarkerLintsLintPass {
2626
fn info(&self) -> LintPassInfo {
2727
LintPassInfoBuilder::new(Box::new([DIAG_MSG_UPPERCASE_START])).build()
2828
}

marker_rustc_driver/src/lint_pass.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ thread_local! {
99
/// The [`Adapter`] loads the lint crates and is the general interface used
1010
/// by drivers to communicate with lint crates.
1111
///
12-
/// The lint crates have to be loaded before the instantiation of [`MarkerLintPass`]
12+
/// The lint crates have to be loaded before the instantiation of [`RustcLintPass`]
1313
/// to allow this driver to register the lints before the lint pass starts.
1414
/// (See [`super::MarkerCallback::config`]). Storing the `Adapter` in a `thread_local`
1515
/// cell is the easiest solution I could come up with. It should be fine performance
@@ -23,24 +23,24 @@ thread_local! {
2323
});
2424
}
2525

26-
pub struct MarkerLintPass;
26+
pub struct RustcLintPass;
2727

28-
impl MarkerLintPass {
28+
impl RustcLintPass {
2929
pub fn marker_lints() -> Vec<&'static Lint> {
3030
ADAPTER.with(|adapter| {
31-
let mut rustc_lints = vec![];
32-
for info in adapter.lint_pass_infos() {
33-
rustc_lints.extend_from_slice(info.lints());
34-
}
35-
36-
rustc_lints
31+
adapter
32+
.lint_pass_infos()
33+
.iter()
34+
.flat_map(marker_api::LintPassInfo::lints)
35+
.copied()
36+
.collect()
3737
})
3838
}
3939
}
4040

41-
rustc_lint_defs::impl_lint_pass!(MarkerLintPass => []);
41+
rustc_lint_defs::impl_lint_pass!(RustcLintPass => []);
4242

43-
impl<'tcx> rustc_lint::LateLintPass<'tcx> for MarkerLintPass {
43+
impl<'tcx> rustc_lint::LateLintPass<'tcx> for RustcLintPass {
4444
fn check_crate(&mut self, rustc_cx: &rustc_lint::LateContext<'tcx>) {
4545
ADAPTER.with(|adapter| {
4646
process_crate(rustc_cx, adapter);

marker_rustc_driver/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ impl rustc_driver::Callbacks for MarkerCallback {
6060
config.register_lints = Some(Box::new(|_sess, lint_store| {
6161
// Register lints from lint crates. This is required to have rustc track
6262
// the lint level correctly.
63-
let lints: Vec<_> = lint_pass::MarkerLintPass::marker_lints()
63+
let lints: Vec<_> = lint_pass::RustcLintPass::marker_lints()
6464
.into_iter()
6565
.map(RustcConverter::static_to_lint)
6666
.collect();
6767
lint_store.register_lints(&lints);
6868

69-
lint_store.register_late_pass(|_| Box::new(lint_pass::MarkerLintPass));
69+
lint_store.register_late_pass(|_| Box::new(lint_pass::RustcLintPass));
7070
}));
7171
}
7272
}

0 commit comments

Comments
 (0)