Skip to content

Commit c4eb394

Browse files
committed
Auto merge of rust-lang#14969 - Veykril:inert-attrs, r=Veykril
Update builtin attribute list
2 parents 48f8799 + f9a9e40 commit c4eb394

File tree

4 files changed

+115
-62
lines changed

4 files changed

+115
-62
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[workspace]
22
members = ["xtask/", "lib/*", "crates/*"]
33
exclude = ["crates/proc-macro-test/imp"]
4+
resolver = "2"
45

56
[workspace.package]
67
rust-version = "1.66"

crates/hir-def/src/attr/builtin.rs

+104-62
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! The actual definitions were copied from rustc's `compiler/rustc_feature/src/builtin_attrs.rs`.
44
//!
5-
//! It was last synchronized with upstream commit c1a2db3372a4d6896744919284f3287650a38ab7.
5+
//! It was last synchronized with upstream commit e29821ff85a2a3000d226f99f62f89464028d5d6.
66
//!
77
//! The macros were adjusted to only expand to the attribute name, since that is all we need to do
88
//! name resolution, and `BUILTIN_ATTRIBUTES` is almost entirely unchanged from the original, to
@@ -108,7 +108,7 @@ macro_rules! experimental {
108108
};
109109
}
110110

111-
/// "Inert" built-in attributes that have a special meaning to rustc or rustdoc.
111+
/// Attributes that have a special meaning to rustc or rustdoc.
112112
#[rustfmt::skip]
113113
pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
114114
// ==========================================================================
@@ -123,7 +123,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
123123
ungated!(ignore, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing),
124124
ungated!(
125125
should_panic, Normal,
126-
template!(Word, List: r#"expected = "reason"#, NameValueStr: "reason"), FutureWarnFollowing,
126+
template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason"), FutureWarnFollowing,
127127
),
128128
// FIXME(Centril): This can be used on stable but shouldn't.
129129
ungated!(reexport_test_harness_main, CrateLevel, template!(NameValueStr: "name"), ErrorFollowing),
@@ -142,20 +142,24 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
142142

143143
// Lints:
144144
ungated!(
145-
warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
145+
warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
146+
DuplicatesOk, @only_local: true,
146147
),
147148
ungated!(
148-
allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
149+
allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
150+
DuplicatesOk, @only_local: true,
149151
),
150152
gated!(
151153
expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk,
152154
lint_reasons, experimental!(expect)
153155
),
154156
ungated!(
155-
forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
157+
forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
158+
DuplicatesOk, @only_local: true,
156159
),
157160
ungated!(
158-
deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
161+
deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
162+
DuplicatesOk, @only_local: true,
159163
),
160164
ungated!(must_use, Normal, template!(Word, NameValueStr: "reason"), FutureWarnFollowing),
161165
gated!(
@@ -181,16 +185,17 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
181185
// ABI, linking, symbols, and FFI
182186
ungated!(
183187
link, Normal,
184-
template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...""#),
188+
template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated""#),
185189
DuplicatesOk,
186190
),
187191
ungated!(link_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
188192
ungated!(no_link, Normal, template!(Word), WarnFollowing),
189-
ungated!(repr, Normal, template!(List: "C"), DuplicatesOk),
193+
ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, @only_local: true),
190194
ungated!(export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
191195
ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
192196
ungated!(no_mangle, Normal, template!(Word), WarnFollowing, @only_local: true),
193197
ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, @only_local: true),
198+
ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding),
194199

195200
// Limits:
196201
ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
@@ -205,6 +210,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
205210
),
206211

207212
// Entry point:
213+
gated!(unix_sigpipe, Normal, template!(Word, NameValueStr: "inherit|sig_ign|sig_dfl"), ErrorFollowing, experimental!(unix_sigpipe)),
208214
ungated!(start, Normal, template!(Word), WarnFollowing),
209215
ungated!(no_start, CrateLevel, template!(Word), WarnFollowing),
210216
ungated!(no_main, CrateLevel, template!(Word), WarnFollowing),
@@ -226,11 +232,15 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
226232
ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing, @only_local: true),
227233
ungated!(cold, Normal, template!(Word), WarnFollowing, @only_local: true),
228234
ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing),
229-
ungated!(target_feature, Normal, template!(List: r#"enable = "name""#), DuplicatesOk),
235+
ungated!(
236+
target_feature, Normal, template!(List: r#"enable = "name""#),
237+
DuplicatesOk, @only_local: true,
238+
),
230239
ungated!(track_caller, Normal, template!(Word), WarnFollowing),
240+
ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding),
231241
gated!(
232242
no_sanitize, Normal,
233-
template!(List: "address, memory, thread"), DuplicatesOk,
243+
template!(List: "address, kcfi, memory, thread"), DuplicatesOk,
234244
experimental!(no_sanitize)
235245
),
236246
gated!(no_coverage, Normal, template!(Word), WarnFollowing, experimental!(no_coverage)),
@@ -239,25 +249,23 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
239249
doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk
240250
),
241251

252+
// Debugging
253+
ungated!(
254+
debugger_visualizer, Normal,
255+
template!(List: r#"natvis_file = "...", gdb_script_file = "...""#), DuplicatesOk
256+
),
257+
242258
// ==========================================================================
243259
// Unstable attributes:
244260
// ==========================================================================
245261

246-
// RFC #3191: #[debugger_visualizer] support
247-
gated!(
248-
debugger_visualizer, Normal, template!(List: r#"natvis_file = "...", gdb_script_file = "...""#),
249-
DuplicatesOk, experimental!(debugger_visualizer)
250-
),
251-
252262
// Linking:
253-
gated!(naked, Normal, template!(Word), WarnFollowing, @only_local: true, naked_functions, experimental!(naked)),
254263
gated!(
255-
link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, raw_dylib,
256-
experimental!(link_ordinal)
264+
naked, Normal, template!(Word), WarnFollowing, @only_local: true,
265+
naked_functions, experimental!(naked)
257266
),
258267

259268
// Plugins:
260-
// XXX Modified for use in rust-analyzer
261269
// BuiltinAttribute {
262270
// name: sym::plugin,
263271
// only_local: false,
@@ -274,10 +282,6 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
274282
// cfg_fn!(plugin)
275283
// ),
276284
// },
277-
BuiltinAttribute {
278-
name: "plugin",
279-
template: template!(List: "name"),
280-
},
281285

282286
// Testing:
283287
gated!(
@@ -286,7 +290,8 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
286290
),
287291
// RFC #1268
288292
gated!(
289-
marker, Normal, template!(Word), WarnFollowing, marker_trait_attr, experimental!(marker)
293+
marker, Normal, template!(Word), WarnFollowing, @only_local: true,
294+
marker_trait_attr, experimental!(marker)
290295
),
291296
gated!(
292297
thread_local, Normal, template!(Word), WarnFollowing,
@@ -298,21 +303,12 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
298303
optimize, Normal, template!(List: "size|speed"), ErrorPreceding, optimize_attribute,
299304
experimental!(optimize),
300305
),
301-
// RFC 2867
302-
gated!(
303-
instruction_set, Normal, template!(List: "set"), ErrorPreceding,
304-
isa_attribute, experimental!(instruction_set)
305-
),
306306

307307
gated!(
308308
ffi_returns_twice, Normal, template!(Word), WarnFollowing, experimental!(ffi_returns_twice)
309309
),
310310
gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)),
311311
gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
312-
gated!(
313-
register_attr, CrateLevel, template!(List: "attr1, attr2, ..."), DuplicatesOk,
314-
experimental!(register_attr),
315-
),
316312
gated!(
317313
register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
318314
experimental!(register_tool),
@@ -325,7 +321,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
325321
// RFC 2632
326322
gated!(
327323
const_trait, Normal, template!(Word), WarnFollowing, const_trait_impl,
328-
"`const` is a temporary placeholder for marking a trait that is suitable for `const` \
324+
"`const_trait` is a temporary placeholder for marking a trait that is suitable for `const` \
329325
`impls` and all default bodies as `const`, which may be removed or renamed in the \
330326
future."
331327
),
@@ -335,22 +331,47 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
335331
experimental!(deprecated_safe),
336332
),
337333

334+
// `#[collapse_debuginfo]`
335+
gated!(
336+
collapse_debuginfo, Normal, template!(Word), WarnFollowing,
337+
experimental!(collapse_debuginfo)
338+
),
339+
340+
// RFC 2397
341+
gated!(do_not_recommend, Normal, template!(Word), WarnFollowing, experimental!(do_not_recommend)),
342+
343+
// `#[cfi_encoding = ""]`
344+
gated!(
345+
cfi_encoding, Normal, template!(NameValueStr: "encoding"), ErrorPreceding,
346+
experimental!(cfi_encoding)
347+
),
348+
338349
// ==========================================================================
339350
// Internal attributes: Stability, deprecation, and unsafe:
340351
// ==========================================================================
341352

342-
ungated!(feature, CrateLevel, template!(List: "name1, name2, ..."), DuplicatesOk),
353+
ungated!(
354+
feature, CrateLevel,
355+
template!(List: "name1, name2, ..."), DuplicatesOk, @only_local: true,
356+
),
343357
// DuplicatesOk since it has its own validation
344358
ungated!(
345-
stable, Normal, template!(List: r#"feature = "name", since = "version""#), DuplicatesOk,
359+
stable, Normal,
360+
template!(List: r#"feature = "name", since = "version""#), DuplicatesOk, @only_local: true,
346361
),
347362
ungated!(
348363
unstable, Normal,
349364
template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk,
350365
),
351366
ungated!(rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), DuplicatesOk),
352-
ungated!(rustc_const_stable, Normal, template!(List: r#"feature = "name""#), DuplicatesOk),
353-
ungated!(rustc_safe_intrinsic, Normal, template!(List: r#"feature = "name""#), DuplicatesOk),
367+
ungated!(
368+
rustc_const_stable, Normal,
369+
template!(List: r#"feature = "name""#), DuplicatesOk, @only_local: true,
370+
),
371+
ungated!(
372+
rustc_default_body_unstable, Normal,
373+
template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk
374+
),
354375
gated!(
355376
allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), DuplicatesOk,
356377
"allow_internal_unstable side-steps feature gating and stability checks",
@@ -364,6 +385,10 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
364385
allow_internal_unsafe, Normal, template!(Word), WarnFollowing,
365386
"allow_internal_unsafe side-steps the unsafe_code lint",
366387
),
388+
ungated!(rustc_safe_intrinsic, Normal, template!(Word), DuplicatesOk),
389+
rustc_attr!(rustc_allowed_through_unstable_modules, Normal, template!(Word), WarnFollowing,
390+
"rustc_allowed_through_unstable_modules special cases accidental stabilizations of stable items \
391+
through unstable paths"),
367392

368393
// ==========================================================================
369394
// Internal attributes: Type system related:
@@ -381,10 +406,9 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
381406

382407
rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
383408
rustc_attr!(rustc_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
384-
gated!(
385-
alloc_error_handler, Normal, template!(Word), WarnFollowing,
386-
experimental!(alloc_error_handler)
387-
),
409+
rustc_attr!(rustc_reallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
410+
rustc_attr!(rustc_deallocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
411+
rustc_attr!(rustc_allocator_zeroed, Normal, template!(Word), WarnFollowing, IMPL_DETAIL),
388412
gated!(
389413
default_lib_allocator, Normal, template!(Word), WarnFollowing, allocator_internals,
390414
experimental!(default_lib_allocator),
@@ -465,6 +489,12 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
465489
// Used by the `rustc::untranslatable_diagnostic` and `rustc::diagnostic_outside_of_impl` lints
466490
// to assist in changes to diagnostic APIs.
467491
rustc_attr!(rustc_lint_diagnostics, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
492+
// Used by the `rustc::bad_opt_access` lint to identify `DebuggingOptions` and `CodegenOptions`
493+
// types (as well as any others in future).
494+
rustc_attr!(rustc_lint_opt_ty, Normal, template!(Word), WarnFollowing, INTERNAL_UNSTABLE),
495+
// Used by the `rustc::bad_opt_access` lint on fields
496+
// types (as well as any others in future).
497+
rustc_attr!(rustc_lint_opt_deny_field_access, Normal, template!(List: "message"), WarnFollowing, INTERNAL_UNSTABLE),
468498

469499
// ==========================================================================
470500
// Internal attributes, Const related:
@@ -508,18 +538,25 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
508538
"language items are subject to change",
509539
),
510540
rustc_attr!(
511-
rustc_pass_by_value, Normal,
512-
template!(Word), ErrorFollowing,
541+
rustc_pass_by_value, Normal, template!(Word), ErrorFollowing,
513542
"#[rustc_pass_by_value] is used to mark types that must be passed by value instead of reference."
514543
),
515544
rustc_attr!(
516545
rustc_coherence_is_core, AttributeType::CrateLevel, template!(Word), ErrorFollowing, @only_local: true,
517546
"#![rustc_coherence_is_core] allows inherent methods on builtin types, only intended to be used in `core`."
518547
),
548+
rustc_attr!(
549+
rustc_coinductive, AttributeType::Normal, template!(Word), WarnFollowing, @only_local: true,
550+
"#![rustc_coinductive] changes a trait to be coinductive, allowing cycles in the trait solver."
551+
),
519552
rustc_attr!(
520553
rustc_allow_incoherent_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: true,
521554
"#[rustc_allow_incoherent_impl] has to be added to all impl items of an incoherent inherent impl."
522555
),
556+
rustc_attr!(
557+
rustc_deny_explicit_impl, AttributeType::Normal, template!(Word), ErrorFollowing, @only_local: false,
558+
"#[rustc_deny_explicit_impl] enforces that a trait can have no user-provided impls"
559+
),
523560
rustc_attr!(
524561
rustc_has_incoherent_inherent_impls, AttributeType::Normal, template!(Word), ErrorFollowing,
525562
"#[rustc_has_incoherent_inherent_impls] allows the addition of incoherent inherent impls for \
@@ -531,24 +568,20 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
531568
and it is only intended to be used in `alloc`."
532569
),
533570

534-
// modified for r-a
535-
// BuiltinAttribute {
536-
// name: sym::rustc_diagnostic_item,
537-
// // FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
538-
// only_local: false,
539-
// type_: Normal,
540-
// template: template!(NameValueStr: "name"),
541-
// duplicates: ErrorFollowing,
542-
// gate: Gated(
543-
// Stability::Unstable,
544-
// sym::rustc_attrs,
545-
// "diagnostic items compiler internal support for linting",
546-
// cfg_fn!(rustc_attrs),
547-
// ),
548-
// },
549571
BuiltinAttribute {
572+
// name: sym::rustc_diagnostic_item,
550573
name: "rustc_diagnostic_item",
574+
// FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
575+
// only_local: false,
576+
// type_: Normal,
551577
template: template!(NameValueStr: "name"),
578+
// duplicates: ErrorFollowing,
579+
// gate: Gated(
580+
// Stability::Unstable,
581+
// sym::rustc_attrs,
582+
// "diagnostic items compiler internal support for linting",
583+
// cfg_fn!(rustc_attrs),
584+
// ),
552585
},
553586
gated!(
554587
// Used in resolve:
@@ -572,7 +605,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
572605
for reserving for `for<T> From<!> for T` impl"
573606
),
574607
rustc_attr!(
575-
rustc_test_marker, Normal, template!(Word), WarnFollowing,
608+
rustc_test_marker, Normal, template!(NameValueStr: "name"), WarnFollowing,
576609
"the `#[rustc_test_marker]` attribute is used internally to track tests",
577610
),
578611
rustc_attr!(
@@ -598,11 +631,16 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
598631
definition of a trait, it's currently in experimental form and should be changed before \
599632
being exposed outside of the std"
600633
),
634+
rustc_attr!(
635+
rustc_doc_primitive, Normal, template!(NameValueStr: "primitive name"), ErrorFollowing,
636+
r#"`rustc_doc_primitive` is a rustc internal attribute"#,
637+
),
601638

602639
// ==========================================================================
603640
// Internal attributes, Testing:
604641
// ==========================================================================
605642

643+
rustc_attr!(TEST, rustc_effective_visibility, Normal, template!(Word), WarnFollowing),
606644
rustc_attr!(TEST, rustc_outlives, Normal, template!(Word), WarnFollowing),
607645
rustc_attr!(TEST, rustc_capture_analysis, Normal, template!(Word), WarnFollowing),
608646
rustc_attr!(TEST, rustc_insignificant_dtor, Normal, template!(Word), WarnFollowing),
@@ -643,6 +681,10 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
643681
rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word), WarnFollowing),
644682
rustc_attr!(TEST, rustc_def_path, Normal, template!(Word), WarnFollowing),
645683
rustc_attr!(TEST, rustc_mir, Normal, template!(List: "arg1, arg2, ..."), DuplicatesOk),
684+
gated!(
685+
custom_mir, Normal, template!(List: r#"dialect = "...", phase = "...""#),
686+
ErrorFollowing, "the `#[custom_mir]` attribute is just used for the Rust test suite",
687+
),
646688
rustc_attr!(TEST, rustc_dump_program_clauses, Normal, template!(Word), WarnFollowing),
647689
rustc_attr!(TEST, rustc_dump_env_program_clauses, Normal, template!(Word), WarnFollowing),
648690
rustc_attr!(TEST, rustc_object_lifetime_default, Normal, template!(Word), WarnFollowing),

crates/rust-analyzer/src/main_loop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ impl GlobalState {
798798
// so we run them on a latency sensitive thread.
799799
self.task_pool.handle.spawn(stdx::thread::ThreadIntent::LatencySensitive, move || {
800800
let _p = profile::span("publish_diagnostics");
801+
let _ctx = stdx::panic_context::enter("publish_diagnostics".to_owned());
801802
let diagnostics = subscriptions
802803
.into_iter()
803804
.filter_map(|file_id| {

0 commit comments

Comments
 (0)