Skip to content

Commit 16ca0cb

Browse files
committed
Auto merge of #142099 - matthiaskrgr:rollup-r9s3c35, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #125087 (Optimize `Seek::stream_len` impl for `File`) - #141982 (`tests/ui`: A New Order [5/N]) - #142012 (Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None) - #142044 (compiler: Document the offset invariant of `OperandValue::Pair`) - #142047 (Ensure stack in two places that affect s390x) - #142058 (Clean `rustc_attr_parsing/src/lib.rs` documentation) - #142067 (canon_abi: make to_erased_extern_abi just a detail in formatting) - #142072 (doc: Fix inverted meaning in E0783.md) - #142084 (add myself to rotation) - #142091 (Fix AIX build) - #142092 (rustdoc: Support middle::ty associated const equality predicates again) Failed merges: - #142042 (Make E0621 missing lifetime suggestion verbose) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d00435f + e12572f commit 16ca0cb

File tree

110 files changed

+651
-644
lines changed

Some content is hidden

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

110 files changed

+651
-644
lines changed

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,10 @@ pub enum CanonAbi {
5050

5151
impl fmt::Display for CanonAbi {
5252
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53-
self.to_erased_extern_abi().as_str().fmt(f)
54-
}
55-
}
56-
57-
impl CanonAbi {
58-
/// convert to the ExternAbi that *shares a string* with this CanonAbi
59-
///
60-
/// A target-insensitive mapping of CanonAbi to ExternAbi, convenient for "forwarding" impls.
61-
/// Importantly, the set of CanonAbi values is a logical *subset* of ExternAbi values,
62-
/// so this is injective: if you take an ExternAbi to a CanonAbi and back, you have lost data.
63-
const fn to_erased_extern_abi(self) -> ExternAbi {
64-
match self {
53+
// convert to the ExternAbi that *shares a string* with this CanonAbi.
54+
// FIXME: ideally we'd avoid printing `CanonAbi`, and preserve `ExternAbi` everywhere
55+
// that we need to generate error messages.
56+
let erased_abi = match self {
6557
CanonAbi::C => ExternAbi::C { unwind: false },
6658
CanonAbi::Rust => ExternAbi::Rust,
6759
CanonAbi::RustCold => ExternAbi::RustCold,
@@ -87,7 +79,8 @@ impl CanonAbi {
8779
X86Call::Vectorcall => ExternAbi::Vectorcall { unwind: false },
8880
X86Call::Win64 => ExternAbi::Win64 { unwind: false },
8981
},
90-
}
82+
};
83+
erased_abi.as_str().fmt(f)
9184
}
9285
}
9386

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
732732
span: Span,
733733
args: Option<&'hir hir::GenericArgs<'hir>>,
734734
) -> &'hir hir::Path<'hir> {
735-
let def_id = self.tcx.require_lang_item(lang_item, Some(span));
735+
let def_id = self.tcx.require_lang_item(lang_item, span);
736736
let def_kind = self.tcx.def_kind(def_id);
737737
let res = Res::Def(def_kind, def_id);
738738
self.arena.alloc(hir::Path {

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) trait AttributeParser: Default + 'static {
7474
pub(crate) trait SingleAttributeParser: 'static {
7575
const PATH: &'static [Symbol];
7676

77-
/// Caled when a duplicate attribute is found.
77+
/// Called when a duplicate attribute is found.
7878
///
7979
/// `first_span` is the span of the first occurrence of this attribute.
8080
// FIXME(jdonszelmann): default error

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
11
//! Centralized logic for parsing and attributes.
22
//!
3-
//! Part of a series of crates:
4-
//! - rustc_attr_data_structures: contains types that the parsers parse into
5-
//! - rustc_attr_parsing: this crate
6-
//! - (in the future): rustc_attr_validation
3+
//! ## Architecture
4+
//! This crate is part of a series of crates that handle attribute processing.
5+
//! - [rustc_attr_data_structures](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_data_structures/index.html): Defines the data structures that store parsed attributes
6+
//! - [rustc_attr_parsing](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html): This crate, handles the parsing of attributes
7+
//! - (planned) rustc_attr_validation: Will handle attribute validation
78
//!
8-
//! History: Check out [#131229](https://github.com/rust-lang/rust/issues/131229).
9-
//! There used to be only one definition of attributes in the compiler: `ast::Attribute`.
10-
//! These were then parsed or validated or both in places distributed all over the compiler.
11-
//! This was a mess...
9+
//! The separation between data structures and parsing follows the principle of separation of concerns.
10+
//! Data structures (`rustc_attr_data_structures`) define what attributes look like after parsing.
11+
//! This crate (`rustc_attr_parsing`) handles how to convert raw tokens into those structures.
12+
//! This split allows other parts of the compiler to use the data structures without needing
13+
//! the parsing logic, making the codebase more modular and maintainable.
1214
//!
13-
//! Attributes are markers on items.
14-
//! Many of them are actually attribute-like proc-macros, and are expanded to some other rust syntax.
15-
//! This could either be a user provided proc macro, or something compiler provided.
16-
//! `derive` is an example of one that the compiler provides.
17-
//! These are built-in, but they have a valid expansion to Rust tokens and are thus called "active".
18-
//! I personally like calling these *active* compiler-provided attributes, built-in *macros*,
19-
//! because they still expand, and this helps to differentiate them from built-in *attributes*.
20-
//! However, I'll be the first to admit that the naming here can be confusing.
15+
//! ## Background
16+
//! Previously, the compiler had a single attribute definition (`ast::Attribute`) with parsing and
17+
//! validation scattered throughout the codebase. This was reorganized for better maintainability
18+
//! (see [#131229](https://github.com/rust-lang/rust/issues/131229)).
2119
//!
22-
//! The alternative to active attributes, are inert attributes.
23-
//! These can occur in user code (proc-macro helper attributes).
24-
//! But what's important is, many built-in attributes are inert like this.
25-
//! There is nothing they expand to during the macro expansion process,
26-
//! sometimes because they literally cannot expand to something that is valid Rust.
27-
//! They are really just markers to guide the compilation process.
28-
//! An example is `#[inline(...)]` which changes how code for functions is generated.
20+
//! ## Types of Attributes
21+
//! In Rust, attributes are markers that can be attached to items. They come in two main categories.
22+
//!
23+
//! ### 1. Active Attributes
24+
//! These are attribute-like proc-macros that expand into other Rust code.
25+
//! They can be either user-defined or compiler-provided. Examples of compiler-provided active attributes:
26+
//! - `#[derive(...)]`: Expands into trait implementations
27+
//! - `#[cfg()]`: Expands based on configuration
28+
//! - `#[cfg_attr()]`: Conditional attribute application
29+
//!
30+
//! ### 2. Inert Attributes
31+
//! These are pure markers that don't expand into other code. They guide the compilation process.
32+
//! They can be user-defined (in proc-macro helpers) or built-in. Examples of built-in inert attributes:
33+
//! - `#[stable()]`: Marks stable API items
34+
//! - `#[inline()]`: Suggests function inlining
35+
//! - `#[repr()]`: Controls type representation
2936
//!
3037
//! ```text
3138
//! Active Inert
3239
//! ┌──────────────────────┬──────────────────────┐
3340
//! │ (mostly in) │ these are parsed │
3441
//! │ rustc_builtin_macros │ here! │
3542
//! │ │ │
36-
//! │ │ │
3743
//! │ #[derive(...)] │ #[stable()] │
3844
//! Built-in │ #[cfg()] │ #[inline()] │
3945
//! │ #[cfg_attr()] │ #[repr()] │
4046
//! │ │ │
41-
//! │ │ │
42-
//! │ │ │
4347
//! ├──────────────────────┼──────────────────────┤
4448
//! │ │ │
45-
//! │ │ │
4649
//! │ │ `b` in │
4750
//! │ │ #[proc_macro_derive( │
4851
//! User created │ #[proc_macro_attr()] │ a, │
4952
//! │ │ attributes(b) │
5053
//! │ │ ] │
51-
//! │ │ │
52-
//! │ │ │
53-
//! │ │ │
5454
//! └──────────────────────┴──────────────────────┘
5555
//! ```
5656
//!
57+
//! ## How This Crate Works
5758
//! In this crate, syntactical attributes (sequences of tokens that look like
5859
//! `#[something(something else)]`) are parsed into more semantic attributes, markers on items.
5960
//! Multiple syntactic attributes might influence a single semantic attribute. For example,
@@ -63,18 +64,17 @@
6364
//! and `#[unstable()]` syntactic attributes, and at the end produce a single
6465
//! [`AttributeKind::Stability`](rustc_attr_data_structures::AttributeKind::Stability).
6566
//!
66-
//! As a rule of thumb, when a syntactical attribute can be applied more than once, they should be
67-
//! combined into a single semantic attribute. For example:
67+
//! When multiple instances of the same attribute are allowed, they're combined into a single
68+
//! semantic attribute. For example:
6869
//!
69-
//! ```
70+
//! ```rust
7071
//! #[repr(C)]
7172
//! #[repr(packed)]
7273
//! struct Meow {}
7374
//! ```
7475
//!
75-
//! should result in a single `AttributeKind::Repr` containing a list of repr annotations, in this
76-
//! case `C` and `packed`. This is equivalent to writing `#[repr(C, packed)]` in a single
77-
//! syntactical annotation.
76+
//! This is equivalent to `#[repr(C, packed)]` and results in a single `AttributeKind::Repr`
77+
//! containing both `C` and `packed` annotations.
7878
7979
// tidy-alphabetical-start
8080
#![allow(internal_features)]

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
263263
// something that already has `Fn`-like bounds (or is a closure), so we can't
264264
// restrict anyways.
265265
} else {
266-
let copy_did = self.infcx.tcx.require_lang_item(LangItem::Copy, Some(span));
266+
let copy_did = self.infcx.tcx.require_lang_item(LangItem::Copy, span);
267267
self.suggest_adding_bounds(&mut err, ty, copy_did, span);
268268
}
269269

@@ -1915,7 +1915,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
19151915

19161916
let local_ty = self.body.local_decls[place.local].ty;
19171917
let typeck_results = tcx.typeck(self.mir_def_id());
1918-
let clone = tcx.require_lang_item(LangItem::Clone, Some(body.span));
1918+
let clone = tcx.require_lang_item(LangItem::Clone, body.span);
19191919
for expr in expr_finder.clones {
19201920
if let hir::ExprKind::MethodCall(_, rcvr, _, span) = expr.kind
19211921
&& let Some(rcvr_ty) = typeck_results.node_type_opt(rcvr.hir_id)

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
688688
if !self.unsized_feature_enabled() {
689689
let trait_ref = ty::TraitRef::new(
690690
tcx,
691-
tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
691+
tcx.require_lang_item(LangItem::Sized, self.last_span),
692692
[place_ty],
693693
);
694694
self.prove_trait_ref(
@@ -1010,7 +1010,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10101010
let ty = place.ty(self.body, tcx).ty;
10111011
let trait_ref = ty::TraitRef::new(
10121012
tcx,
1013-
tcx.require_lang_item(LangItem::Copy, Some(span)),
1013+
tcx.require_lang_item(LangItem::Copy, span),
10141014
[ty],
10151015
);
10161016

@@ -1025,11 +1025,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10251025
}
10261026

10271027
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
1028-
let trait_ref = ty::TraitRef::new(
1029-
tcx,
1030-
tcx.require_lang_item(LangItem::Sized, Some(span)),
1031-
[ty],
1032-
);
1028+
let trait_ref =
1029+
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, span), [ty]);
10331030

10341031
self.prove_trait_ref(
10351032
trait_ref,
@@ -1041,11 +1038,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
10411038
&Rvalue::NullaryOp(NullOp::UbChecks, _) => {}
10421039

10431040
Rvalue::ShallowInitBox(_operand, ty) => {
1044-
let trait_ref = ty::TraitRef::new(
1045-
tcx,
1046-
tcx.require_lang_item(LangItem::Sized, Some(span)),
1047-
[*ty],
1048-
);
1041+
let trait_ref =
1042+
ty::TraitRef::new(tcx, tcx.require_lang_item(LangItem::Sized, span), [*ty]);
10491043

10501044
self.prove_trait_ref(
10511045
trait_ref,
@@ -1222,7 +1216,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
12221216
let &ty = ty;
12231217
let trait_ref = ty::TraitRef::new(
12241218
tcx,
1225-
tcx.require_lang_item(LangItem::CoerceUnsized, Some(span)),
1219+
tcx.require_lang_item(LangItem::CoerceUnsized, span),
12261220
[op.ty(self.body, tcx), ty],
12271221
);
12281222

@@ -1811,7 +1805,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
18111805
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
18121806
let trait_ref = ty::TraitRef::new(
18131807
tcx,
1814-
tcx.require_lang_item(LangItem::Copy, Some(self.last_span)),
1808+
tcx.require_lang_item(LangItem::Copy, self.last_span),
18151809
[place_ty.ty],
18161810
);
18171811

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
544544
// (as it's created inside the body itself, not passed in from outside).
545545
if let DefiningTy::FnDef(def_id, _) = defining_ty {
546546
if self.infcx.tcx.fn_sig(def_id).skip_binder().c_variadic() {
547-
let va_list_did = self.infcx.tcx.require_lang_item(
548-
LangItem::VaList,
549-
Some(self.infcx.tcx.def_span(self.mir_def)),
550-
);
547+
let va_list_did = self
548+
.infcx
549+
.tcx
550+
.require_lang_item(LangItem::VaList, self.infcx.tcx.def_span(self.mir_def));
551551

552552
let reg_vid = self
553553
.infcx

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
380380
rustc_hir::LangItem::PanicBoundsCheck,
381381
&[index, len, location],
382382
*unwind,
383-
Some(source_info.span),
383+
source_info.span,
384384
);
385385
}
386386
AssertKind::MisalignedPointerDereference { ref required, ref found } => {
@@ -393,7 +393,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
393393
rustc_hir::LangItem::PanicMisalignedPointerDereference,
394394
&[required, found, location],
395395
*unwind,
396-
Some(source_info.span),
396+
source_info.span,
397397
);
398398
}
399399
AssertKind::NullPointerDereference => {
@@ -404,7 +404,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
404404
rustc_hir::LangItem::PanicNullPointerDereference,
405405
&[location],
406406
*unwind,
407-
Some(source_info.span),
407+
source_info.span,
408408
)
409409
}
410410
_ => {
@@ -415,7 +415,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
415415
msg.panic_function(),
416416
&[location],
417417
*unwind,
418-
Some(source_info.span),
418+
source_info.span,
419419
);
420420
}
421421
}
@@ -531,7 +531,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
531531
);
532532
}
533533
TerminatorKind::UnwindTerminate(reason) => {
534-
codegen_unwind_terminate(fx, Some(source_info.span), *reason);
534+
codegen_unwind_terminate(fx, source_info.span, *reason);
535535
}
536536
TerminatorKind::UnwindResume => {
537537
// FIXME implement unwinding
@@ -1074,7 +1074,7 @@ pub(crate) fn codegen_operand<'tcx>(
10741074
pub(crate) fn codegen_panic_nounwind<'tcx>(
10751075
fx: &mut FunctionCx<'_, '_, 'tcx>,
10761076
msg_str: &str,
1077-
span: Option<Span>,
1077+
span: Span,
10781078
) {
10791079
let msg_ptr = fx.anonymous_str(msg_str);
10801080
let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
@@ -1091,7 +1091,7 @@ pub(crate) fn codegen_panic_nounwind<'tcx>(
10911091

10921092
pub(crate) fn codegen_unwind_terminate<'tcx>(
10931093
fx: &mut FunctionCx<'_, '_, 'tcx>,
1094-
span: Option<Span>,
1094+
span: Span,
10951095
reason: UnwindTerminateReason,
10961096
) {
10971097
codegen_panic_inner(fx, reason.lang_item(), &[], UnwindAction::Unreachable, span);
@@ -1102,7 +1102,7 @@ fn codegen_panic_inner<'tcx>(
11021102
lang_item: rustc_hir::LangItem,
11031103
args: &[Value],
11041104
_unwind: UnwindAction,
1105-
span: Option<Span>,
1105+
span: Span,
11061106
) {
11071107
fx.bcx.set_cold_block(fx.bcx.current_block().unwrap());
11081108

compiler/rustc_codegen_cranelift/src/intrinsics/llvm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
7171
See https://github.com/rust-lang/rustc_codegen_cranelift/issues/171\n\
7272
Please open an issue at https://github.com/rust-lang/rustc_codegen_cranelift/issues"
7373
);
74-
crate::base::codegen_panic_nounwind(fx, &msg, None);
74+
crate::base::codegen_panic_nounwind(fx, &msg, span);
7575
return;
7676
}
7777
}

compiler/rustc_codegen_cranelift/src/intrinsics/llvm_aarch64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ pub(super) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
512512
See https://github.com/rust-lang/rustc_codegen_cranelift/issues/171\n\
513513
Please open an issue at https://github.com/rust-lang/rustc_codegen_cranelift/issues"
514514
);
515-
crate::base::codegen_panic_nounwind(fx, &msg, None);
515+
crate::base::codegen_panic_nounwind(fx, &msg, fx.mir.span);
516516
return;
517517
}
518518
}

compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ pub(super) fn codegen_x86_llvm_intrinsic_call<'tcx>(
13211321
See https://github.com/rust-lang/rustc_codegen_cranelift/issues/171\n\
13221322
Please open an issue at https://github.com/rust-lang/rustc_codegen_cranelift/issues"
13231323
);
1324-
crate::base::codegen_panic_nounwind(fx, &msg, None);
1324+
crate::base::codegen_panic_nounwind(fx, &msg, span);
13251325
return;
13261326
}
13271327
}

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
785785
}
786786
})
787787
});
788-
crate::base::codegen_panic_nounwind(fx, &msg_str, Some(source_info.span));
788+
crate::base::codegen_panic_nounwind(fx, &msg_str, source_info.span);
789789
return Ok(());
790790
}
791791
}
@@ -884,7 +884,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
884884
crate::base::codegen_panic_nounwind(
885885
fx,
886886
"128bit atomics not yet supported",
887-
None,
887+
source_info.span,
888888
);
889889
return Ok(());
890890
} else {
@@ -919,7 +919,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
919919
crate::base::codegen_panic_nounwind(
920920
fx,
921921
"128bit atomics not yet supported",
922-
None,
922+
source_info.span,
923923
);
924924
return Ok(());
925925
} else {

0 commit comments

Comments
 (0)