Skip to content

Commit 191df20

Browse files
committed
Auto merge of #139996 - matthiaskrgr:rollup-0nka2hw, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #138528 (deref patterns: implement implicit deref patterns) - #139393 (rustdoc-json: Output target feature information) - #139553 (sync::mpsc: prevent double free on `Drop`) - #139615 (Remove `name_or_empty`) - #139853 (Disable combining LLD with external llvm-config) - #139913 (rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions)) - #139942 (Ignore aix for tests/ui/erros/pic-linker.rs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6a0bd27 + 8cb57ed commit 191df20

File tree

114 files changed

+1819
-622
lines changed

Some content is hidden

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

114 files changed

+1819
-622
lines changed

Diff for: compiler/rustc_ast/src/attr/mod.rs

+22-11
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ impl MetaItem {
305305
if let [PathSegment { ident, .. }] = self.path.segments[..] { Some(ident) } else { None }
306306
}
307307

308-
pub fn name_or_empty(&self) -> Symbol {
309-
self.ident().unwrap_or_else(Ident::empty).name
308+
pub fn name(&self) -> Option<Symbol> {
309+
self.ident().map(|ident| ident.name)
310310
}
311311

312312
pub fn has_name(&self, name: Symbol) -> bool {
@@ -511,13 +511,14 @@ impl MetaItemInner {
511511
}
512512
}
513513

514-
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
514+
/// For a single-segment meta item, returns its identifier; otherwise, returns `None`.
515515
pub fn ident(&self) -> Option<Ident> {
516516
self.meta_item().and_then(|meta_item| meta_item.ident())
517517
}
518518

519-
pub fn name_or_empty(&self) -> Symbol {
520-
self.ident().unwrap_or_else(Ident::empty).name
519+
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
520+
pub fn name(&self) -> Option<Symbol> {
521+
self.ident().map(|ident| ident.name)
521522
}
522523

523524
/// Returns `true` if this list item is a MetaItem with a name of `name`.
@@ -738,9 +739,9 @@ pub trait AttributeExt: Debug {
738739
fn id(&self) -> AttrId;
739740

740741
/// For a single-segment attribute (i.e., `#[attr]` and not `#[path::atrr]`),
741-
/// return the name of the attribute, else return the empty identifier.
742-
fn name_or_empty(&self) -> Symbol {
743-
self.ident().unwrap_or_else(Ident::empty).name
742+
/// return the name of the attribute; otherwise, returns `None`.
743+
fn name(&self) -> Option<Symbol> {
744+
self.ident().map(|ident| ident.name)
744745
}
745746

746747
/// Get the meta item list, `#[attr(meta item list)]`
@@ -752,7 +753,7 @@ pub trait AttributeExt: Debug {
752753
/// Gets the span of the value literal, as string, when using `#[attr = value]`
753754
fn value_span(&self) -> Option<Span>;
754755

755-
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
756+
/// For a single-segment attribute, returns its ident; otherwise, returns `None`.
756757
fn ident(&self) -> Option<Ident>;
757758

758759
/// Checks whether the path of this attribute matches the name.
@@ -770,6 +771,11 @@ pub trait AttributeExt: Debug {
770771
self.ident().map(|x| x.name == name).unwrap_or(false)
771772
}
772773

774+
#[inline]
775+
fn has_any_name(&self, names: &[Symbol]) -> bool {
776+
names.iter().any(|&name| self.has_name(name))
777+
}
778+
773779
/// get the span of the entire attribute
774780
fn span(&self) -> Span;
775781

@@ -813,8 +819,8 @@ impl Attribute {
813819
AttributeExt::id(self)
814820
}
815821

816-
pub fn name_or_empty(&self) -> Symbol {
817-
AttributeExt::name_or_empty(self)
822+
pub fn name(&self) -> Option<Symbol> {
823+
AttributeExt::name(self)
818824
}
819825

820826
pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
@@ -846,6 +852,11 @@ impl Attribute {
846852
AttributeExt::has_name(self, name)
847853
}
848854

855+
#[inline]
856+
pub fn has_any_name(&self, names: &[Symbol]) -> bool {
857+
AttributeExt::has_any_name(self, names)
858+
}
859+
849860
pub fn span(&self) -> Span {
850861
AttributeExt::span(self)
851862
}

Diff for: compiler/rustc_ast_lowering/src/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13101310
// create a fake body so that the entire rest of the compiler doesn't have to deal with
13111311
// this as a special case.
13121312
return self.lower_fn_body(decl, contract, |this| {
1313-
if attrs.iter().any(|a| a.name_or_empty() == sym::rustc_intrinsic) {
1313+
if attrs.iter().any(|a| a.has_name(sym::rustc_intrinsic)) {
13141314
let span = this.lower_span(span);
13151315
let empty_block = hir::Block {
13161316
hir_id: this.next_id(),

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'a> AstValidator<'a> {
347347
sym::forbid,
348348
sym::warn,
349349
];
350-
!arr.contains(&attr.name_or_empty()) && rustc_attr_parsing::is_builtin_attr(*attr)
350+
!attr.has_any_name(&arr) && rustc_attr_parsing::is_builtin_attr(*attr)
351351
})
352352
.for_each(|attr| {
353353
if attr.is_doc_comment() {
@@ -947,8 +947,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
947947
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
948948
self.check_defaultness(item.span, *defaultness);
949949

950-
let is_intrinsic =
951-
item.attrs.iter().any(|a| a.name_or_empty() == sym::rustc_intrinsic);
950+
let is_intrinsic = item.attrs.iter().any(|a| a.has_name(sym::rustc_intrinsic));
952951
if body.is_none() && !is_intrinsic {
953952
self.dcx().emit_err(errors::FnWithoutBody {
954953
span: item.span,

Diff for: compiler/rustc_attr_parsing/src/attributes/cfg.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn eval_condition(
102102
};
103103

104104
match &cfg.kind {
105-
MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
105+
MetaItemKind::List(mis) if cfg.has_name(sym::version) => {
106106
try_gate_cfg(sym::version, cfg.span, sess, features);
107107
let (min_version, span) = match &mis[..] {
108108
[MetaItemInner::Lit(MetaItemLit { kind: LitKind::Str(sym, ..), span, .. })] => {
@@ -149,26 +149,26 @@ pub fn eval_condition(
149149

150150
// The unwraps below may look dangerous, but we've already asserted
151151
// that they won't fail with the loop above.
152-
match cfg.name_or_empty() {
153-
sym::any => mis
152+
match cfg.name() {
153+
Some(sym::any) => mis
154154
.iter()
155155
// We don't use any() here, because we want to evaluate all cfg condition
156156
// as eval_condition can (and does) extra checks
157157
.fold(false, |res, mi| res | eval_condition(mi, sess, features, eval)),
158-
sym::all => mis
158+
Some(sym::all) => mis
159159
.iter()
160160
// We don't use all() here, because we want to evaluate all cfg condition
161161
// as eval_condition can (and does) extra checks
162162
.fold(true, |res, mi| res & eval_condition(mi, sess, features, eval)),
163-
sym::not => {
163+
Some(sym::not) => {
164164
let [mi] = mis.as_slice() else {
165165
dcx.emit_err(session_diagnostics::ExpectedOneCfgPattern { span: cfg.span });
166166
return false;
167167
};
168168

169169
!eval_condition(mi, sess, features, eval)
170170
}
171-
sym::target => {
171+
Some(sym::target) => {
172172
if let Some(features) = features
173173
&& !features.cfg_target_compact()
174174
{

Diff for: compiler/rustc_attr_parsing/src/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'sess> AttributeParser<'sess> {
222222
// if we're only looking for a single attribute,
223223
// skip all the ones we don't care about
224224
if let Some(expected) = self.parse_only {
225-
if attr.name_or_empty() != expected {
225+
if !attr.has_name(expected) {
226226
continue;
227227
}
228228
}
@@ -232,7 +232,7 @@ impl<'sess> AttributeParser<'sess> {
232232
// that's expanded right? But no, sometimes, when parsing attributes on macros,
233233
// we already use the lowering logic and these are still there. So, when `omit_doc`
234234
// is set we *also* want to ignore these
235-
if omit_doc == OmitDoc::Skip && attr.name_or_empty() == sym::doc {
235+
if omit_doc == OmitDoc::Skip && attr.has_name(sym::doc) {
236236
continue;
237237
}
238238

@@ -250,7 +250,7 @@ impl<'sess> AttributeParser<'sess> {
250250
}))
251251
}
252252
// // FIXME: make doc attributes go through a proper attribute parser
253-
// ast::AttrKind::Normal(n) if n.name_or_empty() == sym::doc => {
253+
// ast::AttrKind::Normal(n) if n.has_name(sym::doc) => {
254254
// let p = GenericMetaItemParser::from_attr(&n, self.dcx());
255255
//
256256
// attributes.push(Attribute::Parsed(AttributeKind::DocComment {

Diff for: compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,14 @@ impl<'a> TraitDef<'a> {
527527
item.attrs
528528
.iter()
529529
.filter(|a| {
530-
[
530+
a.has_any_name(&[
531531
sym::allow,
532532
sym::warn,
533533
sym::deny,
534534
sym::forbid,
535535
sym::stable,
536536
sym::unstable,
537-
]
538-
.contains(&a.name_or_empty())
537+
])
539538
})
540539
.cloned(),
541540
);

Diff for: compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -346,20 +346,26 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
346346
no_sanitize_span = Some(attr.span());
347347
if let Some(list) = attr.meta_item_list() {
348348
for item in list.iter() {
349-
match item.name_or_empty() {
350-
sym::address => {
349+
match item.name() {
350+
Some(sym::address) => {
351351
codegen_fn_attrs.no_sanitize |=
352352
SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS
353353
}
354-
sym::cfi => codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI,
355-
sym::kcfi => codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI,
356-
sym::memory => codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY,
357-
sym::memtag => codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG,
358-
sym::shadow_call_stack => {
354+
Some(sym::cfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::CFI,
355+
Some(sym::kcfi) => codegen_fn_attrs.no_sanitize |= SanitizerSet::KCFI,
356+
Some(sym::memory) => {
357+
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY
358+
}
359+
Some(sym::memtag) => {
360+
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMTAG
361+
}
362+
Some(sym::shadow_call_stack) => {
359363
codegen_fn_attrs.no_sanitize |= SanitizerSet::SHADOWCALLSTACK
360364
}
361-
sym::thread => codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD,
362-
sym::hwaddress => {
365+
Some(sym::thread) => {
366+
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD
367+
}
368+
Some(sym::hwaddress) => {
363369
codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS
364370
}
365371
_ => {
@@ -420,9 +426,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
420426
continue;
421427
};
422428

423-
let attrib_to_write = match meta_item.name_or_empty() {
424-
sym::prefix_nops => &mut prefix,
425-
sym::entry_nops => &mut entry,
429+
let attrib_to_write = match meta_item.name() {
430+
Some(sym::prefix_nops) => &mut prefix,
431+
Some(sym::entry_nops) => &mut entry,
426432
_ => {
427433
tcx.dcx().emit_err(errors::UnexpectedParameterName {
428434
span: item.span(),
@@ -786,8 +792,7 @@ impl<'a> MixedExportNameAndNoMangleState<'a> {
786792
fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
787793
let attrs = tcx.get_attrs(id, sym::rustc_autodiff);
788794

789-
let attrs =
790-
attrs.filter(|attr| attr.name_or_empty() == sym::rustc_autodiff).collect::<Vec<_>>();
795+
let attrs = attrs.filter(|attr| attr.has_name(sym::rustc_autodiff)).collect::<Vec<_>>();
791796

792797
// check for exactly one autodiff attribute on placeholder functions.
793798
// There should only be one, since we generate a new placeholder per ad macro.

Diff for: compiler/rustc_expand/src/base.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,10 @@ impl SyntaxExtension {
824824
return Err(item.span);
825825
}
826826

827-
match item.name_or_empty() {
828-
sym::no => Ok(CollapseMacroDebuginfo::No),
829-
sym::external => Ok(CollapseMacroDebuginfo::External),
830-
sym::yes => Ok(CollapseMacroDebuginfo::Yes),
827+
match item.name() {
828+
Some(sym::no) => Ok(CollapseMacroDebuginfo::No),
829+
Some(sym::external) => Ok(CollapseMacroDebuginfo::External),
830+
Some(sym::yes) => Ok(CollapseMacroDebuginfo::Yes),
831831
_ => Err(item.path.span),
832832
}
833833
}

Diff for: compiler/rustc_expand/src/expand.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2053,8 +2053,8 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
20532053
) -> Node::OutputTy {
20542054
loop {
20552055
return match self.take_first_attr(&mut node) {
2056-
Some((attr, pos, derives)) => match attr.name_or_empty() {
2057-
sym::cfg => {
2056+
Some((attr, pos, derives)) => match attr.name() {
2057+
Some(sym::cfg) => {
20582058
let (res, meta_item) = self.expand_cfg_true(&mut node, attr, pos);
20592059
if res {
20602060
continue;
@@ -2071,7 +2071,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
20712071
}
20722072
Default::default()
20732073
}
2074-
sym::cfg_attr => {
2074+
Some(sym::cfg_attr) => {
20752075
self.expand_cfg_attr(&mut node, &attr, pos);
20762076
continue;
20772077
}
@@ -2144,8 +2144,8 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
21442144
) {
21452145
loop {
21462146
return match self.take_first_attr(node) {
2147-
Some((attr, pos, derives)) => match attr.name_or_empty() {
2148-
sym::cfg => {
2147+
Some((attr, pos, derives)) => match attr.name() {
2148+
Some(sym::cfg) => {
21492149
let span = attr.span;
21502150
if self.expand_cfg_true(node, attr, pos).0 {
21512151
continue;
@@ -2154,7 +2154,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
21542154
node.expand_cfg_false(self, pos, span);
21552155
continue;
21562156
}
2157-
sym::cfg_attr => {
2157+
Some(sym::cfg_attr) => {
21582158
self.expand_cfg_attr(node, &attr, pos);
21592159
continue;
21602160
}

Diff for: compiler/rustc_hir/src/hir.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1237,7 +1237,7 @@ impl AttributeExt for Attribute {
12371237
Attribute::Parsed(AttributeKind::DocComment { kind, comment, .. }) => {
12381238
Some((*comment, *kind))
12391239
}
1240-
Attribute::Unparsed(_) if self.name_or_empty() == sym::doc => {
1240+
Attribute::Unparsed(_) if self.has_name(sym::doc) => {
12411241
self.value_str().map(|s| (s, CommentKind::Line))
12421242
}
12431243
_ => None,
@@ -1262,8 +1262,8 @@ impl Attribute {
12621262
}
12631263

12641264
#[inline]
1265-
pub fn name_or_empty(&self) -> Symbol {
1266-
AttributeExt::name_or_empty(self)
1265+
pub fn name(&self) -> Option<Symbol> {
1266+
AttributeExt::name(self)
12671267
}
12681268

12691269
#[inline]
@@ -1301,6 +1301,11 @@ impl Attribute {
13011301
AttributeExt::has_name(self, name)
13021302
}
13031303

1304+
#[inline]
1305+
pub fn has_any_name(&self, names: &[Symbol]) -> bool {
1306+
AttributeExt::has_any_name(self, names)
1307+
}
1308+
13041309
#[inline]
13051310
pub fn span(&self) -> Span {
13061311
AttributeExt::span(self)

Diff for: compiler/rustc_hir_analysis/src/autoderef.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use rustc_infer::infer::InferCtxt;
22
use rustc_infer::traits::PredicateObligations;
33
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
44
use rustc_session::Limit;
5-
use rustc_span::Span;
65
use rustc_span::def_id::{LOCAL_CRATE, LocalDefId};
6+
use rustc_span::{ErrorGuaranteed, Span};
77
use rustc_trait_selection::traits::ObligationCtxt;
88
use tracing::{debug, instrument};
99

@@ -259,7 +259,11 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
259259
}
260260
}
261261

262-
pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
262+
pub fn report_autoderef_recursion_limit_error<'tcx>(
263+
tcx: TyCtxt<'tcx>,
264+
span: Span,
265+
ty: Ty<'tcx>,
266+
) -> ErrorGuaranteed {
263267
// We've reached the recursion limit, error gracefully.
264268
let suggested_limit = match tcx.recursion_limit() {
265269
Limit(0) => Limit(2),
@@ -270,5 +274,5 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
270274
ty,
271275
suggested_limit,
272276
crate_name: tcx.crate_name(LOCAL_CRATE),
273-
});
277+
})
274278
}

0 commit comments

Comments
 (0)