Rollup merge of #138682 - Alexendoo:extra-symbols, r=fee1-dead
Allow drivers to supply a list of extra symbols to intern
Allows adding new symbols as `const`s in external drivers, desirable in Clippy so we can use them in patterns to replace code like 75530e9f72/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs (L66)
The Clippy change adds a couple symbols as a demo, the exact `clippy_utils` API and replacing other usages can be done on the Clippy side to minimise sync conflicts
---
try-job: aarch64-gnu
This commit is contained in:
commit
65105f1324
7 changed files with 33 additions and 6 deletions
|
|
@ -25,6 +25,7 @@ path = "src/driver.rs"
|
|||
[dependencies]
|
||||
clippy_config = { path = "clippy_config" }
|
||||
clippy_lints = { path = "clippy_lints" }
|
||||
clippy_utils = { path = "clippy_utils" }
|
||||
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
|
||||
tempfile = { version = "3.3", optional = true }
|
||||
termize = "0.1"
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use super::{Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR, unnecessary_clippy_cfg};
|
||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use clippy_utils::msrvs::{self, MsrvStack};
|
||||
use clippy_utils::sym;
|
||||
use rustc_ast::AttrStyle;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_lint::EarlyContext;
|
||||
use rustc_span::sym;
|
||||
|
||||
pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) {
|
||||
// check cfg_attr
|
||||
|
|
@ -18,7 +18,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &MsrvStack) {
|
|||
&& msrv.meets(msrvs::TOOL_ATTRIBUTES)
|
||||
// check for `rustfmt_skip` and `rustfmt::skip`
|
||||
&& let Some(skip_item) = &items[1].meta_item()
|
||||
&& (skip_item.has_name(sym!(rustfmt_skip))
|
||||
&& (skip_item.has_name(sym::rustfmt_skip)
|
||||
|| skip_item
|
||||
.path
|
||||
.segments
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ use super::USELESS_ATTRIBUTE;
|
|||
use super::utils::{is_lint_level, is_word, namespace_and_lint};
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
|
||||
use clippy_utils::sym;
|
||||
use rustc_ast::{Attribute, Item, ItemKind};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_lint::{EarlyContext, LintContext};
|
||||
use rustc_span::sym;
|
||||
|
||||
pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
|
||||
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]) {
|
|||
if is_word(lint, sym::unused_imports) && skip_unused_imports {
|
||||
return;
|
||||
}
|
||||
if is_word(lint, sym!(unused_extern_crates)) {
|
||||
if is_word(lint, sym::unused_extern_crates) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ pub fn check(
|
|||
// of all `#[test]` attributes in not ignored code examples
|
||||
fn check_code_sample(code: String, edition: Edition, ignore: bool) -> (bool, Vec<Range<usize>>) {
|
||||
rustc_driver::catch_fatal_errors(|| {
|
||||
rustc_span::create_session_globals_then(edition, None, || {
|
||||
rustc_span::create_session_globals_then(edition, &[], None, || {
|
||||
let mut test_attr_spans = vec![];
|
||||
let filename = FileName::anon_source_code(&code);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#![feature(f128)]
|
||||
#![feature(f16)]
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(macro_metavar_expr)]
|
||||
#![feature(macro_metavar_expr_concat)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(never_type)]
|
||||
|
|
@ -74,6 +75,7 @@ pub mod qualify_min_const_fn;
|
|||
pub mod source;
|
||||
pub mod str_utils;
|
||||
pub mod sugg;
|
||||
pub mod sym;
|
||||
pub mod ty;
|
||||
pub mod usage;
|
||||
pub mod visitors;
|
||||
|
|
@ -126,7 +128,7 @@ use rustc_middle::ty::{
|
|||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::symbol::{Ident, Symbol, kw};
|
||||
use rustc_span::{InnerSpan, Span, sym};
|
||||
use rustc_span::{InnerSpan, Span};
|
||||
use visitors::{Visitable, for_each_unconsumed_temporary};
|
||||
|
||||
use crate::consts::{ConstEvalCtxt, Constant, mir_to_const};
|
||||
|
|
|
|||
23
clippy_utils/src/sym.rs
Normal file
23
clippy_utils/src/sym.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#![allow(non_upper_case_globals)]
|
||||
|
||||
use rustc_span::symbol::{Symbol, PREDEFINED_SYMBOLS_COUNT};
|
||||
|
||||
pub use rustc_span::sym::*;
|
||||
|
||||
macro_rules! generate {
|
||||
($($sym:ident,)*) => {
|
||||
/// To be supplied to `rustc_interface::Config`
|
||||
pub const EXTRA_SYMBOLS: &[&str] = &[
|
||||
$(stringify!($sym),)*
|
||||
];
|
||||
|
||||
$(
|
||||
pub const $sym: Symbol = Symbol::new(PREDEFINED_SYMBOLS_COUNT + ${index()});
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
generate! {
|
||||
rustfmt_skip,
|
||||
unused_extern_crates,
|
||||
}
|
||||
|
|
@ -160,6 +160,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
|
|||
clippy_lints::register_lints(lint_store, conf);
|
||||
clippy_lints::register_pre_expansion_lints(lint_store, conf);
|
||||
}));
|
||||
config.extra_symbols = clippy_utils::sym::EXTRA_SYMBOLS.into();
|
||||
|
||||
// FIXME: #4825; This is required, because Clippy lints that are based on MIR have to be
|
||||
// run on the unoptimized MIR. On the other hand this results in some false negatives. If
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue