Skip to content

Commit 9649706

Browse files
committed
Auto merge of #129809 - matthiaskrgr:rollup-cyygnxh, r=matthiaskrgr
Rollup of 15 pull requests Successful merges: - #120221 (Don't make statement nonterminals match pattern nonterminals) - #126183 (Separate core search logic with search ui) - #129123 (rustdoc-json: Add test for `Self` type) - #129366 (linker: Synchronize native library search in rustc and linker) - #129527 (Don't use `TyKind` in a lint) - #129534 (Deny `wasm_c_abi` lint to nudge the last 25%) - #129640 (Re-enable android tests/benches in alloc/core) - #129642 (Bump backtrace to 0.3.74~ish) - #129675 (allow BufReader::peek to be called on unsized types) - #129723 (Simplify some extern providers) - #129724 (Remove `Option<!>` return types.) - #129725 (Stop using `ty::GenericPredicates` for non-predicates_of queries) - #129731 (Allow running `./x.py test compiler`) - #129751 (interpret/visitor: make memory order iteration slightly more efficient) - #129754 (wasi: Fix sleeping for `Duration::MAX`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fa72f07 + 25e3b66 commit 9649706

File tree

55 files changed

+3941
-3801
lines changed

Some content is hidden

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

55 files changed

+3941
-3801
lines changed

compiler/rustc_ast/src/token.rs

+36-21
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ impl Token {
486486
}
487487

488488
/// Returns `true` if the token can appear at the start of an expression.
489+
///
490+
/// **NB**: Take care when modifying this function, since it will change
491+
/// the stable set of tokens that are allowed to match an expr nonterminal.
489492
pub fn can_begin_expr(&self) -> bool {
490493
match self.uninterpolate().kind {
491494
Ident(name, is_raw) =>
@@ -504,34 +507,46 @@ impl Token {
504507
PathSep | // global path
505508
Lifetime(..) | // labeled loop
506509
Pound => true, // expression attributes
507-
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
508-
NtExpr(..) |
509-
NtBlock(..) |
510-
NtPath(..)),
510+
Interpolated(ref nt) =>
511+
matches!(&**nt,
512+
NtBlock(..) |
513+
NtExpr(..) |
514+
NtLiteral(..) |
515+
NtPath(..)
516+
),
511517
_ => false,
512518
}
513519
}
514520

515521
/// Returns `true` if the token can appear at the start of a pattern.
516522
///
517523
/// Shamelessly borrowed from `can_begin_expr`, only used for diagnostics right now.
518-
pub fn can_begin_pattern(&self) -> bool {
519-
match self.uninterpolate().kind {
520-
Ident(name, is_raw) =>
521-
ident_can_begin_expr(name, self.span, is_raw), // value name or keyword
522-
| OpenDelim(Delimiter::Bracket | Delimiter::Parenthesis) // tuple or array
523-
| Literal(..) // literal
524-
| BinOp(Minus) // unary minus
525-
| BinOp(And) // reference
526-
| AndAnd // double reference
527-
// DotDotDot is no longer supported
528-
| DotDot | DotDotDot | DotDotEq // ranges
529-
| Lt | BinOp(Shl) // associated path
530-
| PathSep => true, // global path
531-
Interpolated(ref nt) => matches!(&**nt, NtLiteral(..) |
532-
NtPat(..) |
533-
NtBlock(..) |
534-
NtPath(..)),
524+
pub fn can_begin_pattern(&self, pat_kind: NtPatKind) -> bool {
525+
match &self.uninterpolate().kind {
526+
// box, ref, mut, and other identifiers (can stricten)
527+
Ident(..) | NtIdent(..) |
528+
OpenDelim(Delimiter::Parenthesis) | // tuple pattern
529+
OpenDelim(Delimiter::Bracket) | // slice pattern
530+
BinOp(And) | // reference
531+
BinOp(Minus) | // negative literal
532+
AndAnd | // double reference
533+
Literal(_) | // literal
534+
DotDot | // range pattern (future compat)
535+
DotDotDot | // range pattern (future compat)
536+
PathSep | // path
537+
Lt | // path (UFCS constant)
538+
BinOp(Shl) => true, // path (double UFCS)
539+
// leading vert `|` or-pattern
540+
BinOp(Or) => matches!(pat_kind, PatWithOr),
541+
Interpolated(nt) =>
542+
matches!(&**nt,
543+
| NtExpr(..)
544+
| NtLiteral(..)
545+
| NtMeta(..)
546+
| NtPat(..)
547+
| NtPath(..)
548+
| NtTy(..)
549+
),
535550
_ => false,
536551
}
537552
}

compiler/rustc_codegen_ssa/src/back/link.rs

+15-46
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::BTreeSet;
22
use std::ffi::OsString;
33
use std::fs::{read, File, OpenOptions};
44
use std::io::{BufWriter, Write};
5-
use std::ops::Deref;
5+
use std::ops::{ControlFlow, Deref};
66
use std::path::{Path, PathBuf};
77
use std::process::{ExitStatus, Output, Stdio};
88
use std::{env, fmt, fs, io, mem, str};
@@ -18,8 +18,8 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
1818
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, FatalError};
1919
use rustc_fs_util::{fix_windows_verbatim_for_gcc, try_canonicalize};
2020
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
21-
use rustc_metadata::find_native_static_library;
2221
use rustc_metadata::fs::{copy_to_stdout, emit_wrapper_file, METADATA_FILENAME};
22+
use rustc_metadata::{find_native_static_library, walk_native_lib_search_dirs};
2323
use rustc_middle::bug;
2424
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
2525
use rustc_middle::middle::dependency_format::Linkage;
@@ -2110,50 +2110,19 @@ fn add_library_search_dirs(
21102110
return;
21112111
}
21122112

2113-
// Library search paths explicitly supplied by user (`-L` on the command line).
2114-
for search_path in sess.target_filesearch(PathKind::Native).cli_search_paths() {
2115-
cmd.include_path(&fix_windows_verbatim_for_gcc(&search_path.dir));
2116-
}
2117-
for search_path in sess.target_filesearch(PathKind::Framework).cli_search_paths() {
2118-
// Contrary to the `-L` docs only framework-specific paths are considered here.
2119-
if search_path.kind != PathKind::All {
2120-
cmd.framework_path(&search_path.dir);
2121-
}
2122-
}
2123-
2124-
// The toolchain ships some native library components and self-contained linking was enabled.
2125-
// Add the self-contained library directory to search paths.
2126-
if self_contained_components.intersects(
2127-
LinkSelfContainedComponents::LIBC
2128-
| LinkSelfContainedComponents::UNWIND
2129-
| LinkSelfContainedComponents::MINGW,
2130-
) {
2131-
let lib_path = sess.target_tlib_path.dir.join("self-contained");
2132-
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
2133-
}
2134-
2135-
// Toolchains for some targets may ship `libunwind.a`, but place it into the main sysroot
2136-
// library directory instead of the self-contained directories.
2137-
// Sanitizer libraries have the same issue and are also linked by name on Apple targets.
2138-
// The targets here should be in sync with `copy_third_party_objects` in bootstrap.
2139-
// FIXME: implement `-Clink-self-contained=+/-unwind,+/-sanitizers`, move the shipped libunwind
2140-
// and sanitizers to self-contained directory, and stop adding this search path.
2141-
if sess.target.vendor == "fortanix"
2142-
|| sess.target.os == "linux"
2143-
|| sess.target.os == "fuchsia"
2144-
|| sess.target.is_like_osx && !sess.opts.unstable_opts.sanitizer.is_empty()
2145-
{
2146-
cmd.include_path(&fix_windows_verbatim_for_gcc(&sess.target_tlib_path.dir));
2147-
}
2148-
2149-
// Mac Catalyst uses the macOS SDK, but to link to iOS-specific frameworks
2150-
// we must have the support library stubs in the library search path (#121430).
2151-
if let Some(sdk_root) = apple_sdk_root
2152-
&& sess.target.llvm_target.contains("macabi")
2153-
{
2154-
cmd.include_path(&sdk_root.join("System/iOSSupport/usr/lib"));
2155-
cmd.framework_path(&sdk_root.join("System/iOSSupport/System/Library/Frameworks"));
2156-
}
2113+
walk_native_lib_search_dirs(
2114+
sess,
2115+
self_contained_components,
2116+
apple_sdk_root,
2117+
|dir, is_framework| {
2118+
if is_framework {
2119+
cmd.framework_path(dir);
2120+
} else {
2121+
cmd.include_path(&fix_windows_verbatim_for_gcc(dir));
2122+
}
2123+
ControlFlow::<()>::Continue(())
2124+
},
2125+
);
21572126
}
21582127

21592128
/// Add options making relocation sections in the produced ELF files read-only

compiler/rustc_codegen_ssa/src/back/linker.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{env, iter, mem, str};
77

88
use cc::windows_registry;
99
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
10-
use rustc_metadata::find_native_static_library;
10+
use rustc_metadata::{find_native_static_library, try_find_native_static_library};
1111
use rustc_middle::bug;
1212
use rustc_middle::middle::dependency_format::Linkage;
1313
use rustc_middle::middle::exported_symbols;
@@ -891,9 +891,15 @@ impl<'a> Linker for MsvcLinker<'a> {
891891
}
892892

893893
fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) {
894-
let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" };
895-
let suffix = if verbatim { "" } else { ".lib" };
896-
self.link_arg(format!("{prefix}{name}{suffix}"));
894+
// On MSVC-like targets rustc supports static libraries using alternative naming
895+
// scheme (`libfoo.a`) unsupported by linker, search for such libraries manually.
896+
if let Some(path) = try_find_native_static_library(self.sess, name, verbatim) {
897+
self.link_staticlib_by_path(&path, whole_archive);
898+
} else {
899+
let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" };
900+
let suffix = if verbatim { "" } else { ".lib" };
901+
self.link_arg(format!("{prefix}{name}{suffix}"));
902+
}
897903
}
898904

899905
fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {

compiler/rustc_const_eval/src/interpret/visitor.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
2525
}
2626

2727
/// This function provides the chance to reorder the order in which fields are visited for
28-
/// `FieldsShape::Aggregate`: The order of fields will be
29-
/// `(0..num_fields).map(aggregate_field_order)`.
28+
/// `FieldsShape::Aggregate`.
3029
///
31-
/// The default means we iterate in source declaration order; alternative this can do an inverse
32-
/// lookup in `memory_index` to use memory field order instead.
30+
/// The default means we iterate in source declaration order; alternatively this can do some
31+
/// work with `memory_index` to iterate in memory order.
3332
#[inline(always)]
34-
fn aggregate_field_order(_memory_index: &IndexVec<FieldIdx, u32>, idx: usize) -> usize {
35-
idx
33+
fn aggregate_field_iter(
34+
memory_index: &IndexVec<FieldIdx, u32>,
35+
) -> impl Iterator<Item = FieldIdx> + 'static {
36+
memory_index.indices()
3637
}
3738

3839
// Recursive actions, ready to be overloaded.
@@ -172,9 +173,9 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized {
172173
&FieldsShape::Union(fields) => {
173174
self.visit_union(v, fields)?;
174175
}
175-
FieldsShape::Arbitrary { offsets, memory_index } => {
176-
for idx in 0..offsets.len() {
177-
let idx = Self::aggregate_field_order(memory_index, idx);
176+
FieldsShape::Arbitrary { memory_index, .. } => {
177+
for idx in Self::aggregate_field_iter(memory_index) {
178+
let idx = idx.as_usize();
178179
let field = self.ecx().project_field(v, idx)?;
179180
self.visit_field(v, idx, &field)?;
180181
}

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
420420
span: Span,
421421
def_id: LocalDefId,
422422
assoc_name: Ident,
423-
) -> ty::GenericPredicates<'tcx> {
423+
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
424424
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_name))
425425
}
426426

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+29-30
Original file line numberDiff line numberDiff line change
@@ -580,24 +580,24 @@ pub(super) fn explicit_predicates_of<'tcx>(
580580
/// Ensures that the super-predicates of the trait with a `DefId`
581581
/// of `trait_def_id` are lowered and stored. This also ensures that
582582
/// the transitive super-predicates are lowered.
583-
pub(super) fn explicit_super_predicates_of(
584-
tcx: TyCtxt<'_>,
583+
pub(super) fn explicit_super_predicates_of<'tcx>(
584+
tcx: TyCtxt<'tcx>,
585585
trait_def_id: LocalDefId,
586-
) -> ty::GenericPredicates<'_> {
586+
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
587587
implied_predicates_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly)
588588
}
589589

590-
pub(super) fn explicit_supertraits_containing_assoc_item(
591-
tcx: TyCtxt<'_>,
590+
pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>(
591+
tcx: TyCtxt<'tcx>,
592592
(trait_def_id, assoc_name): (DefId, Ident),
593-
) -> ty::GenericPredicates<'_> {
593+
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
594594
implied_predicates_with_filter(tcx, trait_def_id, PredicateFilter::SelfThatDefines(assoc_name))
595595
}
596596

597-
pub(super) fn explicit_implied_predicates_of(
598-
tcx: TyCtxt<'_>,
597+
pub(super) fn explicit_implied_predicates_of<'tcx>(
598+
tcx: TyCtxt<'tcx>,
599599
trait_def_id: LocalDefId,
600-
) -> ty::GenericPredicates<'_> {
600+
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
601601
implied_predicates_with_filter(
602602
tcx,
603603
trait_def_id.to_def_id(),
@@ -612,11 +612,11 @@ pub(super) fn explicit_implied_predicates_of(
612612
/// Ensures that the super-predicates of the trait with a `DefId`
613613
/// of `trait_def_id` are lowered and stored. This also ensures that
614614
/// the transitive super-predicates are lowered.
615-
pub(super) fn implied_predicates_with_filter(
616-
tcx: TyCtxt<'_>,
615+
pub(super) fn implied_predicates_with_filter<'tcx>(
616+
tcx: TyCtxt<'tcx>,
617617
trait_def_id: DefId,
618618
filter: PredicateFilter,
619-
) -> ty::GenericPredicates<'_> {
619+
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
620620
let Some(trait_def_id) = trait_def_id.as_local() else {
621621
// if `assoc_name` is None, then the query should've been redirected to an
622622
// external provider
@@ -679,20 +679,16 @@ pub(super) fn implied_predicates_with_filter(
679679
_ => {}
680680
}
681681

682-
ty::GenericPredicates {
683-
parent: None,
684-
predicates: implied_bounds,
685-
effects_min_tys: ty::List::empty(),
686-
}
682+
ty::EarlyBinder::bind(implied_bounds)
687683
}
688684

689685
/// Returns the predicates defined on `item_def_id` of the form
690686
/// `X: Foo` where `X` is the type parameter `def_id`.
691687
#[instrument(level = "trace", skip(tcx))]
692-
pub(super) fn type_param_predicates(
693-
tcx: TyCtxt<'_>,
688+
pub(super) fn type_param_predicates<'tcx>(
689+
tcx: TyCtxt<'tcx>,
694690
(item_def_id, def_id, assoc_name): (LocalDefId, LocalDefId, Ident),
695-
) -> ty::GenericPredicates<'_> {
691+
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
696692
use rustc_hir::*;
697693
use rustc_middle::ty::Ty;
698694

@@ -713,18 +709,20 @@ pub(super) fn type_param_predicates(
713709
tcx.generics_of(item_def_id).parent.map(|def_id| def_id.expect_local())
714710
};
715711

716-
let mut result = parent
717-
.map(|parent| {
718-
let icx = ItemCtxt::new(tcx, parent);
719-
icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_name)
720-
})
721-
.unwrap_or_default();
712+
let result = if let Some(parent) = parent {
713+
let icx = ItemCtxt::new(tcx, parent);
714+
icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_name)
715+
} else {
716+
ty::EarlyBinder::bind(&[] as &[_])
717+
};
722718
let mut extend = None;
723719

724720
let item_hir_id = tcx.local_def_id_to_hir_id(item_def_id);
725721

726722
let hir_node = tcx.hir_node(item_hir_id);
727-
let Some(hir_generics) = hir_node.generics() else { return result };
723+
let Some(hir_generics) = hir_node.generics() else {
724+
return result;
725+
};
728726
if let Node::Item(item) = hir_node
729727
&& let ItemKind::Trait(..) = item.kind
730728
// Implied `Self: Trait` and supertrait bounds.
@@ -748,9 +746,10 @@ pub(super) fn type_param_predicates(
748746
_ => false,
749747
}),
750748
);
751-
result.predicates =
752-
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(extra_predicates));
753-
result
749+
750+
ty::EarlyBinder::bind(
751+
tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_predicates)),
752+
)
754753
}
755754

756755
impl<'tcx> ItemCtxt<'tcx> {

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
17611761
break Some((bound_vars.into_iter().collect(), assoc_item));
17621762
}
17631763
let predicates = tcx.explicit_supertraits_containing_assoc_item((def_id, assoc_name));
1764-
let obligations = predicates.predicates.iter().filter_map(|&(pred, _)| {
1764+
let obligations = predicates.iter_identity_copied().filter_map(|(pred, _)| {
17651765
let bound_predicate = pred.kind();
17661766
match bound_predicate.skip_binder() {
17671767
ty::ClauseKind::Trait(data) => {

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub trait HirTyLowerer<'tcx> {
136136
span: Span,
137137
def_id: LocalDefId,
138138
assoc_name: Ident,
139-
) -> ty::GenericPredicates<'tcx>;
139+
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]>;
140140

141141
/// Lower an associated type to a projection.
142142
///
@@ -831,13 +831,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
831831
debug!(?ty_param_def_id, ?assoc_name, ?span);
832832
let tcx = self.tcx();
833833

834-
let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_name).predicates;
834+
let predicates = &self.probe_ty_param_bounds(span, ty_param_def_id, assoc_name);
835835
debug!("predicates={:#?}", predicates);
836836

837837
self.probe_single_bound_for_assoc_item(
838838
|| {
839839
let trait_refs = predicates
840-
.iter()
840+
.iter_identity_copied()
841841
.filter_map(|(p, _)| Some(p.as_trait_clause()?.map_bound(|t| t.trait_ref)));
842842
traits::transitive_bounds_that_define_assoc_item(tcx, trait_refs, assoc_name)
843843
},

0 commit comments

Comments
 (0)