Skip to content

Commit 94ec239

Browse files
committed
Allow drivers to supply a list of extra symbols to intern
1 parent e85fcab commit 94ec239

File tree

7 files changed

+33
-6
lines changed

7 files changed

+33
-6
lines changed

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ path = "src/driver.rs"
2525
[dependencies]
2626
clippy_config = { path = "clippy_config" }
2727
clippy_lints = { path = "clippy_lints" }
28+
clippy_utils = { path = "clippy_utils" }
2829
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
2930
tempfile = { version = "3.3", optional = true }
3031
termize = "0.1"

Diff for: clippy_lints/src/attrs/deprecated_cfg_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use super::{Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR, unnecessary_clippy_cfg};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::msrvs::{self, MsrvStack};
4+
use clippy_utils::sym;
45
use rustc_ast::AttrStyle;
56
use rustc_errors::Applicability;
67
use rustc_lint::EarlyContext;
7-
use rustc_span::sym;
88

99
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) {
1010
// check cfg_attr
@@ -18,7 +18,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) {
1818
&& msrv.meets(msrvs::TOOL_ATTRIBUTES)
1919
// check for `rustfmt_skip` and `rustfmt::skip`
2020
&& let Some(skip_item) = &items[1].meta_item()
21-
&& (skip_item.has_name(sym!(rustfmt_skip))
21+
&& (skip_item.has_name(sym::rustfmt_skip)
2222
|| skip_item
2323
.path
2424
.segments

Diff for: clippy_lints/src/attrs/useless_attribute.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use super::USELESS_ATTRIBUTE;
22
use super::utils::{is_lint_level, is_word, namespace_and_lint};
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
5+
use clippy_utils::sym;
56
use rustc_ast::{Attribute, Item, ItemKind};
67
use rustc_errors::Applicability;
78
use rustc_lint::{EarlyContext, LintContext};
8-
use rustc_span::sym;
99

1010
pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
1111
let skip_unused_imports = attrs.iter().any(|attr| attr.has_name(sym::macro_use));
@@ -61,7 +61,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
6161
if is_word(lint, sym::unused_imports) && skip_unused_imports {
6262
return;
6363
}
64-
if is_word(lint, sym!(unused_extern_crates)) {
64+
if is_word(lint, sym::unused_extern_crates) {
6565
return;
6666
}
6767
},

Diff for: clippy_lints/src/doc/needless_doctest_main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn check(
3838
// of all `#[test]` attributes in not ignored code examples
3939
fn check_code_sample(code: String, edition: Edition, ignore: bool) -> (bool, Vec<Range<usize>>) {
4040
rustc_driver::catch_fatal_errors(|| {
41-
rustc_span::create_session_globals_then(edition, None, || {
41+
rustc_span::create_session_globals_then(edition, &[], None, || {
4242
let mut test_attr_spans = vec![];
4343
let filename = FileName::anon_source_code(&code);
4444

Diff for: clippy_utils/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(f128)]
44
#![feature(f16)]
55
#![feature(if_let_guard)]
6+
#![feature(macro_metavar_expr)]
67
#![feature(macro_metavar_expr_concat)]
78
#![feature(let_chains)]
89
#![feature(never_type)]
@@ -74,6 +75,7 @@ pub mod qualify_min_const_fn;
7475
pub mod source;
7576
pub mod str_utils;
7677
pub mod sugg;
78+
pub mod sym;
7779
pub mod ty;
7880
pub mod usage;
7981
pub mod visitors;
@@ -125,7 +127,7 @@ use rustc_middle::ty::{
125127
use rustc_span::hygiene::{ExpnKind, MacroKind};
126128
use rustc_span::source_map::SourceMap;
127129
use rustc_span::symbol::{Ident, Symbol, kw};
128-
use rustc_span::{InnerSpan, Span, sym};
130+
use rustc_span::{InnerSpan, Span};
129131
use visitors::{Visitable, for_each_unconsumed_temporary};
130132

131133
use crate::consts::{ConstEvalCtxt, Constant, mir_to_const};

Diff for: clippy_utils/src/sym.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![allow(non_upper_case_globals)]
2+
3+
use rustc_span::symbol::{Symbol, PREDEFINED_SYMBOLS_COUNT};
4+
5+
pub use rustc_span::sym::*;
6+
7+
macro_rules! generate {
8+
($($sym:ident,)*) => {
9+
/// To be supplied to `rustc_interface::Config`
10+
pub const EXTRA_SYMBOLS: &[&str] = &[
11+
$(stringify!($sym),)*
12+
];
13+
14+
$(
15+
pub const $sym: Symbol = Symbol::new(PREDEFINED_SYMBOLS_COUNT + ${index()});
16+
)*
17+
};
18+
}
19+
20+
generate! {
21+
rustfmt_skip,
22+
unused_extern_crates,
23+
}

Diff for: src/driver.rs

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
160160
clippy_lints::register_lints(lint_store, conf);
161161
clippy_lints::register_pre_expansion_lints(lint_store, conf);
162162
}));
163+
config.extra_symbols = clippy_utils::sym::EXTRA_SYMBOLS.into();
163164

164165
// FIXME: #4825; This is required, because Clippy lints that are based on MIR have to be
165166
// run on the unoptimized MIR. On the other hand this results in some false negatives. If

0 commit comments

Comments
 (0)