Skip to content

Commit e90c5fb

Browse files
committed
Auto merge of rust-lang#90836 - matthiaskrgr:rollup-ou6yrlw, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#90589 (rustc_llvm: update PassWrapper for recent LLVM) - rust-lang#90644 (Extend the const swap feature) - rust-lang#90704 (Unix ExitStatus comments and a tiny docs fix) - rust-lang#90761 (Shorten Span of unused macro lints) - rust-lang#90795 (Add more comments to explain the code to generate the search index) - rust-lang#90798 (Document `unreachable!` custom panic message) - rust-lang#90826 (rustc_feature: Convert `BuiltinAttribute` from tuple to a struct) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 220ed09 + 5e7c031 commit e90c5fb

File tree

21 files changed

+145
-121
lines changed

21 files changed

+145
-121
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
33
use rustc_ast::{AssocTyConstraint, AssocTyConstraintKind, NodeId};
44
use rustc_ast::{PatKind, RangeEnd, VariantData};
55
use rustc_errors::struct_span_err;
6-
use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
6+
use rustc_feature::{AttributeGate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
77
use rustc_feature::{Features, GateIssue};
88
use rustc_session::parse::{feature_err, feature_err_issue};
99
use rustc_session::Session;
@@ -301,11 +301,14 @@ impl<'a> PostExpansionVisitor<'a> {
301301

302302
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
303303
fn visit_attribute(&mut self, attr: &ast::Attribute) {
304-
let attr_info =
305-
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);
304+
let attr_info = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name));
306305
// Check feature gates for built-in attributes.
307-
if let Some((.., AttributeGate::Gated(_, name, descr, has_feature))) = attr_info {
308-
gate_feature_fn!(self, has_feature, attr.span, name, descr);
306+
if let Some(BuiltinAttribute {
307+
gate: AttributeGate::Gated(_, name, descr, has_feature),
308+
..
309+
}) = attr_info
310+
{
311+
gate_feature_fn!(self, has_feature, attr.span, *name, descr);
309312
}
310313
// Check unstable flavors of the `#[doc]` attribute.
311314
if attr.has_name(sym::doc) {

compiler/rustc_feature/src/builtin_attrs.rs

+41-24
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,26 @@ macro_rules! template {
115115

116116
macro_rules! ungated {
117117
($attr:ident, $typ:expr, $tpl:expr $(,)?) => {
118-
(sym::$attr, $typ, $tpl, Ungated)
118+
BuiltinAttribute { name: sym::$attr, type_: $typ, template: $tpl, gate: Ungated }
119119
};
120120
}
121121

122122
macro_rules! gated {
123123
($attr:ident, $typ:expr, $tpl:expr, $gate:ident, $msg:expr $(,)?) => {
124-
(sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate)))
124+
BuiltinAttribute {
125+
name: sym::$attr,
126+
type_: $typ,
127+
template: $tpl,
128+
gate: Gated(Stability::Unstable, sym::$gate, $msg, cfg_fn!($gate)),
129+
}
125130
};
126131
($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
127-
(sym::$attr, $typ, $tpl, Gated(Stability::Unstable, sym::$attr, $msg, cfg_fn!($attr)))
132+
BuiltinAttribute {
133+
name: sym::$attr,
134+
type_: $typ,
135+
template: $tpl,
136+
gate: Gated(Stability::Unstable, sym::$attr, $msg, cfg_fn!($attr)),
137+
}
128138
};
129139
}
130140

@@ -143,12 +153,12 @@ macro_rules! rustc_attr {
143153
)
144154
};
145155
($attr:ident, $typ:expr, $tpl:expr, $msg:expr $(,)?) => {
146-
(
147-
sym::$attr,
148-
$typ,
149-
$tpl,
150-
Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)),
151-
)
156+
BuiltinAttribute {
157+
name: sym::$attr,
158+
type_: $typ,
159+
template: $tpl,
160+
gate: Gated(Stability::Unstable, sym::rustc_attrs, $msg, cfg_fn!(rustc_attrs)),
161+
}
152162
};
153163
}
154164

@@ -161,7 +171,12 @@ macro_rules! experimental {
161171
const IMPL_DETAIL: &str = "internal implementation detail";
162172
const INTERNAL_UNSTABLE: &str = "this is an internal attribute that will never be stable";
163173

164-
pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate);
174+
pub struct BuiltinAttribute {
175+
pub name: Symbol,
176+
pub type_: AttributeType,
177+
pub template: AttributeTemplate,
178+
pub gate: AttributeGate,
179+
}
165180

166181
/// Attributes that have a special meaning to rustc or rustdoc.
167182
#[rustfmt::skip]
@@ -290,18 +305,20 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
290305
),
291306

292307
// Plugins:
293-
(
294-
sym::plugin, CrateLevel, template!(List: "name"),
295-
Gated(
308+
BuiltinAttribute {
309+
name: sym::plugin,
310+
type_: CrateLevel,
311+
template: template!(List: "name"),
312+
gate: Gated(
296313
Stability::Deprecated(
297314
"https://github.com/rust-lang/rust/pull/64675",
298315
Some("may be removed in a future compiler version"),
299316
),
300317
sym::plugin,
301318
"compiler plugins are deprecated",
302319
cfg_fn!(plugin)
303-
)
304-
),
320+
),
321+
},
305322

306323
// Testing:
307324
gated!(allow_fail, Normal, template!(Word), experimental!(allow_fail)),
@@ -497,17 +514,17 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
497514
lang, Normal, template!(NameValueStr: "name"), lang_items,
498515
"language items are subject to change",
499516
),
500-
(
501-
sym::rustc_diagnostic_item,
502-
Normal,
503-
template!(NameValueStr: "name"),
504-
Gated(
517+
BuiltinAttribute {
518+
name: sym::rustc_diagnostic_item,
519+
type_: Normal,
520+
template: template!(NameValueStr: "name"),
521+
gate: Gated(
505522
Stability::Unstable,
506523
sym::rustc_attrs,
507524
"diagnostic items compiler internal support for linting",
508525
cfg_fn!(rustc_attrs),
509526
),
510-
),
527+
},
511528
gated!(
512529
// Used in resolve:
513530
prelude_import, Normal, template!(Word),
@@ -601,7 +618,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
601618
];
602619

603620
pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> {
604-
BUILTIN_ATTRIBUTES.iter().filter(|(.., gate)| gate.is_deprecated()).collect()
621+
BUILTIN_ATTRIBUTES.iter().filter(|attr| attr.gate.is_deprecated()).collect()
605622
}
606623

607624
pub fn is_builtin_attr_name(name: Symbol) -> bool {
@@ -612,8 +629,8 @@ pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &BuiltinAttribute>>
612629
SyncLazy::new(|| {
613630
let mut map = FxHashMap::default();
614631
for attr in BUILTIN_ATTRIBUTES.iter() {
615-
if map.insert(attr.0, attr).is_some() {
616-
panic!("duplicate builtin attribute `{}`", attr.0);
632+
if map.insert(attr.name, attr).is_some() {
633+
panic!("duplicate builtin attribute `{}`", attr.name);
617634
}
618635
}
619636
map

compiler/rustc_lint/src/builtin.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ use rustc_ast_pretty::pprust::{self, expr_to_string};
3232
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3333
use rustc_data_structures::stack::ensure_sufficient_stack;
3434
use rustc_errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
35-
use rustc_feature::{deprecated_attributes, AttributeGate, AttributeTemplate, AttributeType};
36-
use rustc_feature::{GateIssue, Stability};
35+
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
3736
use rustc_hir as hir;
3837
use rustc_hir::def::{DefKind, Res};
3938
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
@@ -959,7 +958,7 @@ impl EarlyLintPass for AnonymousParameters {
959958
pub struct DeprecatedAttr {
960959
// This is not free to compute, so we want to keep it around, rather than
961960
// compute it for every attribute.
962-
depr_attrs: Vec<&'static (Symbol, AttributeType, AttributeTemplate, AttributeGate)>,
961+
depr_attrs: Vec<&'static BuiltinAttribute>,
963962
}
964963

965964
impl_lint_pass!(DeprecatedAttr => []);
@@ -990,14 +989,14 @@ fn lint_deprecated_attr(
990989

991990
impl EarlyLintPass for DeprecatedAttr {
992991
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
993-
for &&(n, _, _, ref g) in &self.depr_attrs {
994-
if attr.ident().map(|ident| ident.name) == Some(n) {
992+
for BuiltinAttribute { name, gate, .. } in &self.depr_attrs {
993+
if attr.ident().map(|ident| ident.name) == Some(*name) {
995994
if let &AttributeGate::Gated(
996995
Stability::Deprecated(link, suggestion),
997996
name,
998997
reason,
999998
_,
1000-
) = g
999+
) = gate
10011000
{
10021001
let msg =
10031002
format!("use of deprecated attribute `{}`: {}. See {}", name, reason, link);

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -889,15 +889,17 @@ LLVMRustOptimizeWithNewPassManager(
889889
OptimizerLastEPCallbacks.push_back(
890890
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
891891
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
892-
MPM.addPass(ModuleAddressSanitizerPass(
893-
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));
894892
#if LLVM_VERSION_GE(14, 0)
895-
AddressSanitizerOptions opts(/*CompileKernel=*/false,
896-
SanitizerOptions->SanitizeAddressRecover,
897-
/*UseAfterScope=*/true,
898-
AsanDetectStackUseAfterReturnMode::Runtime);
899-
MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass(opts)));
893+
AddressSanitizerOptions opts = AddressSanitizerOptions{
894+
/*CompileKernel=*/false,
895+
SanitizerOptions->SanitizeAddressRecover,
896+
/*UseAfterScope=*/true,
897+
AsanDetectStackUseAfterReturnMode::Runtime,
898+
};
899+
MPM.addPass(ModuleAddressSanitizerPass(opts));
900900
#else
901+
MPM.addPass(ModuleAddressSanitizerPass(
902+
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));
901903
MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass(
902904
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover,
903905
/*UseAfterScope=*/true)));

compiler/rustc_parse/src/validate_attr.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::parse_in;
55
use rustc_ast::tokenstream::{DelimSpan, TokenTree};
66
use rustc_ast::{self as ast, Attribute, MacArgs, MacDelimiter, MetaItem, MetaItemKind};
77
use rustc_errors::{Applicability, FatalError, PResult};
8-
use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP};
8+
use rustc_feature::{AttributeTemplate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
99
use rustc_session::lint::builtin::ILL_FORMED_ATTRIBUTE_INPUT;
1010
use rustc_session::parse::ParseSess;
1111
use rustc_span::{sym, Symbol};
@@ -15,14 +15,13 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) {
1515
return;
1616
}
1717

18-
let attr_info =
19-
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);
18+
let attr_info = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name));
2019

2120
// Check input tokens for built-in and key-value attributes.
2221
match attr_info {
2322
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
24-
Some((name, _, template, _)) if name != sym::rustc_dummy => {
25-
check_builtin_attribute(sess, attr, name, template)
23+
Some(BuiltinAttribute { name, template, .. }) if *name != sym::rustc_dummy => {
24+
check_builtin_attribute(sess, attr, *name, *template)
2625
}
2726
_ if let MacArgs::Eq(..) = attr.get_normal_item().args => {
2827
// All key-value attributes are restricted to meta-item syntax.
@@ -168,7 +167,7 @@ pub fn emit_fatal_malformed_builtin_attribute(
168167
attr: &Attribute,
169168
name: Symbol,
170169
) -> ! {
171-
let template = BUILTIN_ATTRIBUTE_MAP.get(&name).expect("builtin attr defined").2;
170+
let template = BUILTIN_ATTRIBUTE_MAP.get(&name).expect("builtin attr defined").template;
172171
emit_malformed_attribute(sess, attr, name, template);
173172
// This is fatal, otherwise it will likely cause a cascade of other errors
174173
// (and an error here is expected to be very rare).

compiler/rustc_passes/src/check_attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt;
1111
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, NestedMetaItem};
1212
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1313
use rustc_errors::{pluralize, struct_span_err, Applicability};
14-
use rustc_feature::{AttributeType, BUILTIN_ATTRIBUTE_MAP};
14+
use rustc_feature::{AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
1515
use rustc_hir as hir;
1616
use rustc_hir::def_id::LocalDefId;
1717
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
@@ -148,7 +148,7 @@ impl CheckAttrVisitor<'tcx> {
148148
}
149149

150150
if hir_id != CRATE_HIR_ID {
151-
if let Some((_, AttributeType::CrateLevel, ..)) =
151+
if let Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) =
152152
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name))
153153
{
154154
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {

compiler/rustc_resolve/src/build_reduced_graph.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -1194,15 +1194,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11941194
// Mark the given macro as unused unless its name starts with `_`.
11951195
// Macro uses will remove items from this set, and the remaining
11961196
// items will be reported as `unused_macros`.
1197-
fn insert_unused_macro(
1198-
&mut self,
1199-
ident: Ident,
1200-
def_id: LocalDefId,
1201-
node_id: NodeId,
1202-
span: Span,
1203-
) {
1197+
fn insert_unused_macro(&mut self, ident: Ident, def_id: LocalDefId, node_id: NodeId) {
12041198
if !ident.as_str().starts_with('_') {
1205-
self.r.unused_macros.insert(def_id, (node_id, span));
1199+
self.r.unused_macros.insert(def_id, (node_id, ident));
12061200
}
12071201
}
12081202

@@ -1246,7 +1240,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12461240
self.r.define(module, ident, MacroNS, (res, vis, span, expansion, IsMacroExport));
12471241
} else {
12481242
self.r.check_reserved_macro_name(ident, res);
1249-
self.insert_unused_macro(ident, def_id, item.id, span);
1243+
self.insert_unused_macro(ident, def_id, item.id);
12501244
}
12511245
self.r.visibilities.insert(def_id, vis);
12521246
self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Binding(
@@ -1267,7 +1261,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12671261
_ => self.resolve_visibility(&item.vis),
12681262
};
12691263
if vis != ty::Visibility::Public {
1270-
self.insert_unused_macro(ident, def_id, item.id, span);
1264+
self.insert_unused_macro(ident, def_id, item.id);
12711265
}
12721266
self.r.define(module, ident, MacroNS, (res, vis, span, expansion));
12731267
self.r.visibilities.insert(def_id, vis);

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<'a> Resolver<'a> {
731731
suggestions.extend(
732732
BUILTIN_ATTRIBUTES
733733
.iter()
734-
.map(|(name, ..)| TypoSuggestion::typo_from_res(*name, res)),
734+
.map(|attr| TypoSuggestion::typo_from_res(attr.name, res)),
735735
);
736736
}
737737
}

compiler/rustc_resolve/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ pub struct Resolver<'a> {
988988
non_macro_attr: Lrc<SyntaxExtension>,
989989
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'a>>,
990990
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'a>>,
991-
unused_macros: FxHashMap<LocalDefId, (NodeId, Span)>,
991+
unused_macros: FxHashMap<LocalDefId, (NodeId, Ident)>,
992992
proc_macro_stubs: FxHashSet<LocalDefId>,
993993
/// Traces collected during macro resolution and validated when it's complete.
994994
single_segment_macro_resolutions:

compiler/rustc_resolve/src/macros.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,13 @@ impl<'a> ResolverExpand for Resolver<'a> {
315315
}
316316

317317
fn check_unused_macros(&mut self) {
318-
for (_, &(node_id, span)) in self.unused_macros.iter() {
319-
self.lint_buffer.buffer_lint(UNUSED_MACROS, node_id, span, "unused macro definition");
318+
for (_, &(node_id, ident)) in self.unused_macros.iter() {
319+
self.lint_buffer.buffer_lint(
320+
UNUSED_MACROS,
321+
node_id,
322+
ident.span,
323+
&format!("unused macro definition: `{}`", ident.as_str()),
324+
);
320325
}
321326
}
322327

library/core/src/macros/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,10 @@ macro_rules! writeln {
554554
///
555555
/// # Panics
556556
///
557-
/// This will always [`panic!`].
557+
/// This will always [`panic!`] because `unreachable!` is just a shorthand for `panic!` with a
558+
/// fixed, specific message.
559+
///
560+
/// Like `panic!`, this macro has a second form for displaying custom values.
558561
///
559562
/// # Examples
560563
///
@@ -581,7 +584,7 @@ macro_rules! writeln {
581584
/// if 3*i < i { panic!("u32 overflow"); }
582585
/// if x < 3*i { return i-1; }
583586
/// }
584-
/// unreachable!();
587+
/// unreachable!("The loop should always return");
585588
/// }
586589
/// ```
587590
#[macro_export]

library/core/src/ptr/mut_ptr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,9 @@ impl<T: ?Sized> *mut T {
10921092
///
10931093
/// [`ptr::swap`]: crate::ptr::swap()
10941094
#[stable(feature = "pointer_methods", since = "1.26.0")]
1095+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
10951096
#[inline(always)]
1096-
pub unsafe fn swap(self, with: *mut T)
1097+
pub const unsafe fn swap(self, with: *mut T)
10971098
where
10981099
T: Sized,
10991100
{

library/core/src/slice/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,9 @@ impl<T> [T] {
558558
/// assert!(v == ["a", "b", "e", "d", "c"]);
559559
/// ```
560560
#[stable(feature = "rust1", since = "1.0.0")]
561+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
561562
#[inline]
562-
pub fn swap(&mut self, a: usize, b: usize) {
563+
pub const fn swap(&mut self, a: usize, b: usize) {
563564
let _ = &self[a];
564565
let _ = &self[b];
565566

@@ -595,7 +596,8 @@ impl<T> [T] {
595596
/// [`swap`]: slice::swap
596597
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
597598
#[unstable(feature = "slice_swap_unchecked", issue = "88539")]
598-
pub unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
599+
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
600+
pub const unsafe fn swap_unchecked(&mut self, a: usize, b: usize) {
599601
#[cfg(debug_assertions)]
600602
{
601603
let _ = &self[a];

0 commit comments

Comments
 (0)