Skip to content

Commit 568b4a1

Browse files
committed
Auto merge of #152308 - JonathanBrouwer:rollup-3QU52Xc, r=JonathanBrouwer
Rollup of 7 pull requests Successful merges: - #151745 (Remove a couple of unnecessary flags and env vars in bootstrap) - #152217 (Convert to inline diagnostics in `rustc_lint`) - #152056 (RwLock: refine documentation to emphasize non-reentrancy guarantees) - #152261 (Introduce helper `ty::Generics::has_own_self`) - #152288 (Allow only a single accepter per attribute) - #152292 (Minor change for readability) - #152300 (Port `rustc_regions` to the new attribute parser)
2 parents c7f5f3e + 4230c3a commit 568b4a1

77 files changed

Lines changed: 1605 additions & 5712 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3888,19 +3888,6 @@ dependencies = [
38883888
"serde_json",
38893889
]
38903890

3891-
[[package]]
3892-
name = "rustc_fluent_macro"
3893-
version = "0.0.0"
3894-
dependencies = [
3895-
"annotate-snippets 0.11.5",
3896-
"fluent-bundle",
3897-
"fluent-syntax",
3898-
"proc-macro2",
3899-
"quote",
3900-
"syn 2.0.110",
3901-
"unic-langid",
3902-
]
3903-
39043891
[[package]]
39053892
name = "rustc_fs_util"
39063893
version = "0.0.0"
@@ -4143,7 +4130,6 @@ dependencies = [
41434130
"rustc_data_structures",
41444131
"rustc_errors",
41454132
"rustc_feature",
4146-
"rustc_fluent_macro",
41474133
"rustc_hir",
41484134
"rustc_index",
41494135
"rustc_infer",

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,22 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcLintQueryInstabilityParser {
219219
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintQueryInstability;
220220
}
221221

222+
pub(crate) struct RustcRegionsParser;
223+
224+
impl<S: Stage> NoArgsAttributeParser<S> for RustcRegionsParser {
225+
const PATH: &[Symbol] = &[sym::rustc_regions];
226+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
227+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
228+
Allow(Target::Fn),
229+
Allow(Target::Method(MethodKind::Inherent)),
230+
Allow(Target::Method(MethodKind::Trait { body: false })),
231+
Allow(Target::Method(MethodKind::Trait { body: true })),
232+
Allow(Target::Method(MethodKind::TraitImpl)),
233+
]);
234+
235+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcRegions;
236+
}
237+
222238
pub(crate) struct RustcLintUntrackedQueryInformationParser;
223239

224240
impl<S: Stage> NoArgsAttributeParser<S> for RustcLintUntrackedQueryInformationParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::cell::RefCell;
22
use std::collections::BTreeMap;
3+
use std::collections::btree_map::Entry;
34
use std::ops::{Deref, DerefMut};
45
use std::sync::LazyLock;
56

@@ -61,7 +62,7 @@ use crate::target_checking::AllowedTargets;
6162
type GroupType<S> = LazyLock<GroupTypeInner<S>>;
6263

6364
pub(super) struct GroupTypeInner<S: Stage> {
64-
pub(super) accepters: BTreeMap<&'static [Symbol], Vec<GroupTypeInnerAccept<S>>>,
65+
pub(super) accepters: BTreeMap<&'static [Symbol], GroupTypeInnerAccept<S>>,
6566
}
6667

6768
pub(super) struct GroupTypeInnerAccept<S: Stage> {
@@ -101,27 +102,32 @@ macro_rules! attribute_parsers {
101102
@[$stage: ty] pub(crate) static $name: ident = [$($names: ty),* $(,)?];
102103
) => {
103104
pub(crate) static $name: GroupType<$stage> = LazyLock::new(|| {
104-
let mut accepters = BTreeMap::<_, Vec<GroupTypeInnerAccept<$stage>>>::new();
105+
let mut accepters = BTreeMap::<_, GroupTypeInnerAccept<$stage>>::new();
105106
$(
106107
{
107108
thread_local! {
108109
static STATE_OBJECT: RefCell<$names> = RefCell::new(<$names>::default());
109110
};
110111

111112
for (path, template, accept_fn) in <$names>::ATTRIBUTES {
112-
accepters.entry(*path).or_default().push(GroupTypeInnerAccept {
113-
template: *template,
114-
accept_fn: Box::new(|cx, args| {
115-
STATE_OBJECT.with_borrow_mut(|s| {
116-
accept_fn(s, cx, args)
117-
})
118-
}),
119-
allowed_targets: <$names as crate::attributes::AttributeParser<$stage>>::ALLOWED_TARGETS,
120-
finalizer: Box::new(|cx| {
121-
let state = STATE_OBJECT.take();
122-
state.finalize(cx)
123-
}),
124-
});
113+
match accepters.entry(*path) {
114+
Entry::Vacant(e) => {
115+
e.insert(GroupTypeInnerAccept {
116+
template: *template,
117+
accept_fn: Box::new(|cx, args| {
118+
STATE_OBJECT.with_borrow_mut(|s| {
119+
accept_fn(s, cx, args)
120+
})
121+
}),
122+
allowed_targets: <$names as crate::attributes::AttributeParser<$stage>>::ALLOWED_TARGETS,
123+
finalizer: Box::new(|cx| {
124+
let state = STATE_OBJECT.take();
125+
state.finalize(cx)
126+
})
127+
});
128+
}
129+
Entry::Occupied(_) => panic!("Attribute {path:?} has multiple accepters"),
130+
}
125131
}
126132
}
127133
)*
@@ -278,6 +284,7 @@ attribute_parsers!(
278284
Single<WithoutArgs<RustcPassIndirectlyInNonRusticAbisParser>>,
279285
Single<WithoutArgs<RustcPreserveUbChecksParser>>,
280286
Single<WithoutArgs<RustcReallocatorParser>>,
287+
Single<WithoutArgs<RustcRegionsParser>>,
281288
Single<WithoutArgs<RustcShouldNotBeCalledOnConstItems>>,
282289
Single<WithoutArgs<RustcVarianceOfOpaquesParser>>,
283290
Single<WithoutArgs<RustcVarianceParser>>,

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
327327
let parts =
328328
n.item.path.segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>();
329329

330-
if let Some(accepts) = S::parsers().accepters.get(parts.as_slice()) {
330+
if let Some(accept) = S::parsers().accepters.get(parts.as_slice()) {
331331
let Some(args) = ArgParser::from_attr_args(
332332
args,
333333
&parts,
@@ -368,28 +368,26 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
368368
continue;
369369
}
370370

371-
for accept in accepts {
372-
let mut cx: AcceptContext<'_, 'sess, S> = AcceptContext {
373-
shared: SharedContext {
374-
cx: self,
375-
target_span,
376-
target,
377-
emit_lint: &mut emit_lint,
378-
},
379-
attr_span,
380-
inner_span: lower_span(n.item.span()),
381-
attr_style: attr.style,
382-
parsed_description: ParsedDescription::Attribute,
383-
template: &accept.template,
384-
attr_path: attr_path.clone(),
385-
};
386-
387-
(accept.accept_fn)(&mut cx, &args);
388-
finalizers.push(&accept.finalizer);
389-
390-
if !matches!(cx.stage.should_emit(), ShouldEmit::Nothing) {
391-
Self::check_target(&accept.allowed_targets, target, &mut cx);
392-
}
371+
let mut cx: AcceptContext<'_, 'sess, S> = AcceptContext {
372+
shared: SharedContext {
373+
cx: self,
374+
target_span,
375+
target,
376+
emit_lint: &mut emit_lint,
377+
},
378+
attr_span,
379+
inner_span: lower_span(n.item.span()),
380+
attr_style: attr.style,
381+
parsed_description: ParsedDescription::Attribute,
382+
template: &accept.template,
383+
attr_path: attr_path.clone(),
384+
};
385+
386+
(accept.accept_fn)(&mut cx, &args);
387+
finalizers.push(&accept.finalizer);
388+
389+
if !matches!(cx.stage.should_emit(), ShouldEmit::Nothing) {
390+
Self::check_target(&accept.allowed_targets, target, &mut cx);
393391
}
394392
} else {
395393
// If we're here, we must be compiling a tool attribute... Or someone

compiler/rustc_borrowck/src/nll.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::str::FromStr;
77

88
use polonius_engine::{Algorithm, AllFacts, Output};
99
use rustc_data_structures::frozen::Frozen;
10+
use rustc_hir::attrs::AttributeKind;
11+
use rustc_hir::find_attr;
1012
use rustc_index::IndexSlice;
1113
use rustc_middle::mir::pretty::PrettyPrintMirOptions;
1214
use rustc_middle::mir::{Body, MirDumper, PassWhere, Promoted};
@@ -15,7 +17,6 @@ use rustc_middle::ty::{self, TyCtxt};
1517
use rustc_mir_dataflow::move_paths::MoveData;
1618
use rustc_mir_dataflow::points::DenseLocationMap;
1719
use rustc_session::config::MirIncludeSpans;
18-
use rustc_span::sym;
1920
use tracing::{debug, instrument};
2021

2122
use crate::borrow_set::BorrowSet;
@@ -295,7 +296,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
295296
) {
296297
let tcx = infcx.tcx;
297298
let base_def_id = tcx.typeck_root_def_id(body.source.def_id());
298-
if !tcx.has_attr(base_def_id, sym::rustc_regions) {
299+
if !find_attr!(tcx.get_all_attrs(base_def_id), AttributeKind::RustcRegions) {
299300
return;
300301
}
301302

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ pub fn default_translator() -> Translator {
111111
Translator::with_fallback_bundle(DEFAULT_LOCALE_RESOURCES.to_vec(), false)
112112
}
113113

114-
pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
115-
// tidy-alphabetical-start
116-
rustc_lint::DEFAULT_LOCALE_RESOURCE,
117-
// tidy-alphabetical-end
118-
];
114+
pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[];
119115

120116
/// Exit status code used for successful compilation and help output.
121117
pub const EXIT_SUCCESS: i32 = 0;

compiler/rustc_fluent_macro/Cargo.toml

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)