Skip to content

Commit 651e9cf

Browse files
committed
Auto merge of #140695 - Zalathar:rollup-i32gzbo, r=Zalathar
Rollup of 12 pull requests Successful merges: - #139550 (Fix `-Zremap-path-scope` rmeta handling) - #139764 (Consistent trait bounds for ExtractIf Debug impls) - #139773 (Implement `Iterator::last` for `vec::IntoIter`) - #140035 (Implement RFC 3503: frontmatters) - #140251 (coverage-dump: Resolve global file IDs to filenames) - #140393 (std: get rid of `sys_common::process`) - #140532 (Fix RustAnalyzer discovery of rustc's `stable_mir` crate) - #140598 (Steer docs to `utf8_chunks` and `Iterator::take`) - #140634 (Use more accurate ELF flags on MIPS) - #140673 (Clean rustdoc tests folder) - #140678 (Be a bit more relaxed about not yet constrained infer vars in closure upvar analysis) - #140687 (Update mdbook to 0.4.49) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7295b08 + 546c1c2 commit 651e9cf

File tree

559 files changed

+2324
-755
lines changed

Some content is hidden

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

559 files changed

+2324
-755
lines changed

Cargo.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ name = "coverage-dump"
777777
version = "0.1.0"
778778
dependencies = [
779779
"anyhow",
780+
"itertools",
780781
"leb128",
781782
"md-5",
782783
"miniz_oxide 0.7.4",
@@ -3604,13 +3605,13 @@ dependencies = [
36043605
"rustc_query_system",
36053606
"rustc_resolve",
36063607
"rustc_session",
3607-
"rustc_smir",
36083608
"rustc_span",
36093609
"rustc_target",
36103610
"rustc_trait_selection",
36113611
"rustc_ty_utils",
36123612
"serde_json",
36133613
"shlex",
3614+
"stable_mir",
36143615
"tracing",
36153616
"windows 0.59.0",
36163617
]

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
514514
gate_all!(contracts_internals, "contract internal machinery is for internal use only");
515515
gate_all!(where_clause_attrs, "attributes in `where` clause are unstable");
516516
gate_all!(super_let, "`super let` is experimental");
517+
gate_all!(frontmatter, "frontmatters are experimental");
517518

518519
if !visitor.features.never_patterns() {
519520
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_codegen_ssa/src/back/metadata.rs

+41-25
Original file line numberDiff line numberDiff line change
@@ -270,45 +270,61 @@ pub(super) fn elf_os_abi(sess: &Session) -> u8 {
270270

271271
pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
272272
match architecture {
273-
Architecture::Mips => {
274-
let arch = match sess.target.options.cpu.as_ref() {
275-
"mips1" => elf::EF_MIPS_ARCH_1,
276-
"mips2" => elf::EF_MIPS_ARCH_2,
273+
Architecture::Mips | Architecture::Mips64 | Architecture::Mips64_N32 => {
274+
// "N32" indicates an "ILP32" data model on a 64-bit MIPS CPU
275+
// like SPARC's "v8+", x86_64's "x32", or the watchOS "arm64_32".
276+
let is_32bit = architecture == Architecture::Mips;
277+
let mut e_flags = match sess.target.options.cpu.as_ref() {
278+
"mips1" if is_32bit => elf::EF_MIPS_ARCH_1,
279+
"mips2" if is_32bit => elf::EF_MIPS_ARCH_2,
277280
"mips3" => elf::EF_MIPS_ARCH_3,
278281
"mips4" => elf::EF_MIPS_ARCH_4,
279282
"mips5" => elf::EF_MIPS_ARCH_5,
280-
s if s.contains("r6") => elf::EF_MIPS_ARCH_32R6,
281-
_ => elf::EF_MIPS_ARCH_32R2,
283+
"mips32r2" if is_32bit => elf::EF_MIPS_ARCH_32R2,
284+
"mips32r6" if is_32bit => elf::EF_MIPS_ARCH_32R6,
285+
"mips64r2" if !is_32bit => elf::EF_MIPS_ARCH_64R2,
286+
"mips64r6" if !is_32bit => elf::EF_MIPS_ARCH_64R6,
287+
s if s.starts_with("mips32") && !is_32bit => {
288+
sess.dcx().fatal(format!("invalid CPU `{}` for 64-bit MIPS target", s))
289+
}
290+
s if s.starts_with("mips64") && is_32bit => {
291+
sess.dcx().fatal(format!("invalid CPU `{}` for 32-bit MIPS target", s))
292+
}
293+
_ if is_32bit => elf::EF_MIPS_ARCH_32R2,
294+
_ => elf::EF_MIPS_ARCH_64R2,
282295
};
283296

284-
let mut e_flags = elf::EF_MIPS_CPIC | arch;
285-
286-
// If the ABI is explicitly given, use it or default to O32.
287-
match sess.target.options.llvm_abiname.to_lowercase().as_str() {
288-
"n32" => e_flags |= elf::EF_MIPS_ABI2,
289-
"o32" => e_flags |= elf::EF_MIPS_ABI_O32,
290-
_ => e_flags |= elf::EF_MIPS_ABI_O32,
297+
// If the ABI is explicitly given, use it, or default to O32 on 32-bit MIPS,
298+
// which is the only "true" 32-bit option that LLVM supports.
299+
match sess.target.options.llvm_abiname.as_ref() {
300+
"o32" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
301+
"n32" if !is_32bit => e_flags |= elf::EF_MIPS_ABI2,
302+
"n64" if !is_32bit => {}
303+
"" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
304+
"" => sess.dcx().fatal("LLVM ABI must be specifed for 64-bit MIPS targets"),
305+
s if is_32bit => {
306+
sess.dcx().fatal(format!("invalid LLVM ABI `{}` for 32-bit MIPS target", s))
307+
}
308+
s => sess.dcx().fatal(format!("invalid LLVM ABI `{}` for 64-bit MIPS target", s)),
291309
};
292310

293311
if sess.target.options.relocation_model != RelocModel::Static {
294-
e_flags |= elf::EF_MIPS_PIC;
312+
// PIC means position-independent code. CPIC means "calls PIC".
313+
// CPIC was mutually exclusive with PIC according to
314+
// the SVR4 MIPS ABI https://refspecs.linuxfoundation.org/elf/mipsabi.pdf
315+
// and should have only appeared on static objects with dynamically calls.
316+
// At some point someone (GCC?) decided to set CPIC even for PIC.
317+
// Nowadays various things expect both set on the same object file
318+
// and may even error if you mix CPIC and non-CPIC object files,
319+
// despite that being the entire point of the CPIC ABI extension!
320+
// As we are in Rome, we do as the Romans do.
321+
e_flags |= elf::EF_MIPS_PIC | elf::EF_MIPS_CPIC;
295322
}
296323
if sess.target.options.cpu.contains("r6") {
297324
e_flags |= elf::EF_MIPS_NAN2008;
298325
}
299326
e_flags
300327
}
301-
Architecture::Mips64 => {
302-
// copied from `mips64el-linux-gnuabi64-gcc foo.c -c`
303-
let e_flags = elf::EF_MIPS_CPIC
304-
| elf::EF_MIPS_PIC
305-
| if sess.target.options.cpu.contains("r6") {
306-
elf::EF_MIPS_ARCH_64R6 | elf::EF_MIPS_NAN2008
307-
} else {
308-
elf::EF_MIPS_ARCH_64R2
309-
};
310-
e_flags
311-
}
312328
Architecture::Riscv32 | Architecture::Riscv64 => {
313329
// Source: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/079772828bd10933d34121117a222b4cc0ee2200/riscv-elf.adoc
314330
let mut e_flags: u32 = 0x0;

compiler/rustc_driver_impl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ rustc_privacy = { path = "../rustc_privacy" }
4444
rustc_query_system = { path = "../rustc_query_system" }
4545
rustc_resolve = { path = "../rustc_resolve" }
4646
rustc_session = { path = "../rustc_session" }
47-
rustc_smir = { path = "../rustc_smir" }
4847
rustc_span = { path = "../rustc_span" }
4948
rustc_target = { path = "../rustc_target" }
5049
rustc_trait_selection = { path = "../rustc_trait_selection" }
5150
rustc_ty_utils = { path = "../rustc_ty_utils" }
5251
serde_json = "1.0.59"
5352
shlex = "1.0"
53+
stable_mir = { path = "../stable_mir", features = ["rustc_internal"] }
5454
tracing = { version = "0.1.35" }
5555
# tidy-alphabetical-end
5656

compiler/rustc_driver_impl/src/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_middle::ty::{self, TyCtxt};
1010
use rustc_mir_build::thir::print::{thir_flat, thir_tree};
1111
use rustc_session::Session;
1212
use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
13-
use rustc_smir::rustc_internal::pretty::write_smir_pretty;
1413
use rustc_span::{FileName, Ident};
14+
use stable_mir::rustc_internal::pretty::write_smir_pretty;
1515
use tracing::debug;
1616
use {rustc_ast as ast, rustc_hir_pretty as pprust_hir};
1717

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ declare_features! (
510510
(incomplete, fn_delegation, "1.76.0", Some(118212)),
511511
/// Allows impls for the Freeze trait.
512512
(internal, freeze_impls, "1.78.0", Some(121675)),
513+
/// Frontmatter `---` blocks for use by external tools.
514+
(unstable, frontmatter, "CURRENT_RUSTC_VERSION", Some(136889)),
513515
/// Allows defining gen blocks and `gen fn`.
514516
(unstable, gen_blocks, "1.75.0", Some(117078)),
515517
/// Infer generic args for both consts and types.

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+19-30
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub trait TypeInformationCtxt<'tcx> {
158158

159159
fn resolve_vars_if_possible<T: TypeFoldable<TyCtxt<'tcx>>>(&self, t: T) -> T;
160160

161-
fn try_structurally_resolve_type(&self, span: Span, ty: Ty<'tcx>) -> Ty<'tcx>;
161+
fn structurally_resolve_type(&self, span: Span, ty: Ty<'tcx>) -> Ty<'tcx>;
162162

163163
fn report_bug(&self, span: Span, msg: impl ToString) -> Self::Error;
164164

@@ -191,8 +191,8 @@ impl<'tcx> TypeInformationCtxt<'tcx> for &FnCtxt<'_, 'tcx> {
191191
self.infcx.resolve_vars_if_possible(t)
192192
}
193193

194-
fn try_structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
195-
(**self).try_structurally_resolve_type(sp, ty)
194+
fn structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
195+
(**self).structurally_resolve_type(sp, ty)
196196
}
197197

198198
fn report_bug(&self, span: Span, msg: impl ToString) -> Self::Error {
@@ -236,7 +236,7 @@ impl<'tcx> TypeInformationCtxt<'tcx> for (&LateContext<'tcx>, LocalDefId) {
236236
self.0.maybe_typeck_results().expect("expected typeck results")
237237
}
238238

239-
fn try_structurally_resolve_type(&self, _span: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
239+
fn structurally_resolve_type(&self, _span: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
240240
// FIXME: Maybe need to normalize here.
241241
ty
242242
}
@@ -776,7 +776,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
776776

777777
// Select just those fields of the `with`
778778
// expression that will actually be used
779-
match self.cx.try_structurally_resolve_type(with_expr.span, with_place.place.ty()).kind() {
779+
match self.cx.structurally_resolve_type(with_expr.span, with_place.place.ty()).kind() {
780780
ty::Adt(adt, args) if adt.is_struct() => {
781781
// Consume those fields of the with expression that are needed.
782782
for (f_index, with_field) in adt.non_enum_variant().fields.iter_enumerated() {
@@ -1176,7 +1176,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
11761176
/// two operations: a dereference to reach the array data and then an index to
11771177
/// jump forward to the relevant item.
11781178
impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx, Cx, D> {
1179-
fn resolve_type_vars_or_bug(
1179+
fn expect_and_resolve_type(
11801180
&self,
11811181
id: HirId,
11821182
ty: Option<Ty<'tcx>>,
@@ -1185,12 +1185,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
11851185
Some(ty) => {
11861186
let ty = self.cx.resolve_vars_if_possible(ty);
11871187
self.cx.error_reported_in_ty(ty)?;
1188-
if ty.is_ty_var() {
1189-
debug!("resolve_type_vars_or_bug: infer var from {:?}", ty);
1190-
Err(self.cx.report_bug(self.cx.tcx().hir_span(id), "encountered type variable"))
1191-
} else {
1192-
Ok(ty)
1193-
}
1188+
Ok(ty)
11941189
}
11951190
None => {
11961191
// FIXME: We shouldn't be relying on the infcx being tainted.
@@ -1201,15 +1196,15 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
12011196
}
12021197

12031198
fn node_ty(&self, hir_id: HirId) -> Result<Ty<'tcx>, Cx::Error> {
1204-
self.resolve_type_vars_or_bug(hir_id, self.cx.typeck_results().node_type_opt(hir_id))
1199+
self.expect_and_resolve_type(hir_id, self.cx.typeck_results().node_type_opt(hir_id))
12051200
}
12061201

12071202
fn expr_ty(&self, expr: &hir::Expr<'_>) -> Result<Ty<'tcx>, Cx::Error> {
1208-
self.resolve_type_vars_or_bug(expr.hir_id, self.cx.typeck_results().expr_ty_opt(expr))
1203+
self.expect_and_resolve_type(expr.hir_id, self.cx.typeck_results().expr_ty_opt(expr))
12091204
}
12101205

12111206
fn expr_ty_adjusted(&self, expr: &hir::Expr<'_>) -> Result<Ty<'tcx>, Cx::Error> {
1212-
self.resolve_type_vars_or_bug(
1207+
self.expect_and_resolve_type(
12131208
expr.hir_id,
12141209
self.cx.typeck_results().expr_ty_adjusted_opt(expr),
12151210
)
@@ -1264,10 +1259,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
12641259
// a bind-by-ref means that the base_ty will be the type of the ident itself,
12651260
// but what we want here is the type of the underlying value being borrowed.
12661261
// So peel off one-level, turning the &T into T.
1267-
match self
1268-
.cx
1269-
.try_structurally_resolve_type(pat.span, base_ty)
1270-
.builtin_deref(false)
1262+
match self.cx.structurally_resolve_type(pat.span, base_ty).builtin_deref(false)
12711263
{
12721264
Some(ty) => Ok(ty),
12731265
None => {
@@ -1513,10 +1505,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
15131505
if node_ty != place_ty
15141506
&& self
15151507
.cx
1516-
.try_structurally_resolve_type(
1517-
self.cx.tcx().hir_span(base_place.hir_id),
1518-
place_ty,
1519-
)
1508+
.structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), place_ty)
15201509
.is_impl_trait()
15211510
{
15221511
projections.push(Projection { kind: ProjectionKind::OpaqueCast, ty: node_ty });
@@ -1538,7 +1527,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
15381527
let base_ty = self.expr_ty_adjusted(base)?;
15391528

15401529
let ty::Ref(region, _, mutbl) =
1541-
*self.cx.try_structurally_resolve_type(base.span, base_ty).kind()
1530+
*self.cx.structurally_resolve_type(base.span, base_ty).kind()
15421531
else {
15431532
span_bug!(expr.span, "cat_overloaded_place: base is not a reference");
15441533
};
@@ -1556,7 +1545,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
15561545
let base_curr_ty = base_place.place.ty();
15571546
let deref_ty = match self
15581547
.cx
1559-
.try_structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), base_curr_ty)
1548+
.structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), base_curr_ty)
15601549
.builtin_deref(true)
15611550
{
15621551
Some(ty) => ty,
@@ -1584,7 +1573,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
15841573
) -> Result<VariantIdx, Cx::Error> {
15851574
let res = self.cx.typeck_results().qpath_res(qpath, pat_hir_id);
15861575
let ty = self.cx.typeck_results().node_type(pat_hir_id);
1587-
let ty::Adt(adt_def, _) = self.cx.try_structurally_resolve_type(span, ty).kind() else {
1576+
let ty::Adt(adt_def, _) = self.cx.structurally_resolve_type(span, ty).kind() else {
15881577
return Err(self
15891578
.cx
15901579
.report_bug(span, "struct or tuple struct pattern not applied to an ADT"));
@@ -1616,7 +1605,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
16161605
span: Span,
16171606
) -> Result<usize, Cx::Error> {
16181607
let ty = self.cx.typeck_results().node_type(pat_hir_id);
1619-
match self.cx.try_structurally_resolve_type(span, ty).kind() {
1608+
match self.cx.structurally_resolve_type(span, ty).kind() {
16201609
ty::Adt(adt_def, _) => Ok(adt_def.variant(variant_index).fields.len()),
16211610
_ => {
16221611
self.cx
@@ -1631,7 +1620,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
16311620
/// Here `pat_hir_id` is the HirId of the pattern itself.
16321621
fn total_fields_in_tuple(&self, pat_hir_id: HirId, span: Span) -> Result<usize, Cx::Error> {
16331622
let ty = self.cx.typeck_results().node_type(pat_hir_id);
1634-
match self.cx.try_structurally_resolve_type(span, ty).kind() {
1623+
match self.cx.structurally_resolve_type(span, ty).kind() {
16351624
ty::Tuple(args) => Ok(args.len()),
16361625
_ => Err(self.cx.report_bug(span, "tuple pattern not applied to a tuple")),
16371626
}
@@ -1820,7 +1809,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
18201809
PatKind::Slice(before, ref slice, after) => {
18211810
let Some(element_ty) = self
18221811
.cx
1823-
.try_structurally_resolve_type(pat.span, place_with_id.place.ty())
1812+
.structurally_resolve_type(pat.span, place_with_id.place.ty())
18241813
.builtin_index()
18251814
else {
18261815
debug!("explicit index of non-indexable type {:?}", place_with_id);
@@ -1890,7 +1879,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
18901879
}
18911880

18921881
fn is_multivariant_adt(&self, ty: Ty<'tcx>, span: Span) -> bool {
1893-
if let ty::Adt(def, _) = self.cx.try_structurally_resolve_type(span, ty).kind() {
1882+
if let ty::Adt(def, _) = self.cx.structurally_resolve_type(span, ty).kind() {
18941883
// Note that if a non-exhaustive SingleVariant is defined in another crate, we need
18951884
// to assume that more cases will be added to the variant in the future. This mean
18961885
// that we should handle non-exhaustive SingleVariant the same way we would handle

compiler/rustc_lexer/src/cursor.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use std::str::Chars;
22

3+
pub enum FrontmatterAllowed {
4+
Yes,
5+
No,
6+
}
7+
38
/// Peekable iterator over a char sequence.
49
///
510
/// Next characters can be peeked via `first` method,
@@ -8,17 +13,19 @@ pub struct Cursor<'a> {
813
len_remaining: usize,
914
/// Iterator over chars. Slightly faster than a &str.
1015
chars: Chars<'a>,
16+
pub(crate) frontmatter_allowed: FrontmatterAllowed,
1117
#[cfg(debug_assertions)]
1218
prev: char,
1319
}
1420

1521
pub(crate) const EOF_CHAR: char = '\0';
1622

1723
impl<'a> Cursor<'a> {
18-
pub fn new(input: &'a str) -> Cursor<'a> {
24+
pub fn new(input: &'a str, frontmatter_allowed: FrontmatterAllowed) -> Cursor<'a> {
1925
Cursor {
2026
len_remaining: input.len(),
2127
chars: input.chars(),
28+
frontmatter_allowed,
2229
#[cfg(debug_assertions)]
2330
prev: EOF_CHAR,
2431
}
@@ -95,6 +102,11 @@ impl<'a> Cursor<'a> {
95102
Some(c)
96103
}
97104

105+
/// Moves to a substring by a number of bytes.
106+
pub(crate) fn bump_bytes(&mut self, n: usize) {
107+
self.chars = self.as_str()[n..].chars();
108+
}
109+
98110
/// Eats symbols while predicate returns true or until the end of file is reached.
99111
pub(crate) fn eat_while(&mut self, mut predicate: impl FnMut(char) -> bool) {
100112
// It was tried making optimized version of this for eg. line comments, but

0 commit comments

Comments
 (0)