Skip to content

Commit 7637653

Browse files
committed
Auto merge of rust-lang#114368 - Nilstrieb:rollup-pgvm9cf, r=Nilstrieb
Rollup of 5 pull requests Successful merges: - rust-lang#114079 (Use `upvar_tys` in more places, make it return a list) - rust-lang#114166 (Add regression test for resolving `--extern libc=test.rlib`) - rust-lang#114321 (get auto traits for parallel rustc) - rust-lang#114335 (fix and extend ptr_comparison test) - rust-lang#114347 (x.py print more detailed format files and untracked files count) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d170833 + da2b237 commit 7637653

File tree

24 files changed

+120
-165
lines changed

24 files changed

+120
-165
lines changed

compiler/rustc_ast/src/format.rs

-6
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ pub struct FormatArguments {
6767
names: FxHashMap<Symbol, usize>,
6868
}
6969

70-
// FIXME: Rustdoc has trouble proving Send/Sync for this. See #106930.
71-
#[cfg(parallel_compiler)]
72-
unsafe impl Sync for FormatArguments {}
73-
#[cfg(parallel_compiler)]
74-
unsafe impl Send for FormatArguments {}
75-
7670
impl FormatArguments {
7771
pub fn new() -> Self {
7872
Self {

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
886886
.universal_regions()
887887
.defining_ty
888888
.upvar_tys()
889+
.iter()
889890
.position(|ty| self.any_param_predicate_mentions(&predicates, ty, region))
890891
{
891892
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(

compiler/rustc_borrowck/src/diagnostics/var_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
4343
fr: RegionVid,
4444
) -> Option<usize> {
4545
let upvar_index =
46-
self.universal_regions().defining_ty.upvar_tys().position(|upvar_ty| {
46+
self.universal_regions().defining_ty.upvar_tys().iter().position(|upvar_ty| {
4747
debug!("get_upvar_index_for_region: upvar_ty={upvar_ty:?}");
4848
tcx.any_free_region_meets(&upvar_ty, |r| {
4949
let r = r.as_var();
@@ -52,7 +52,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5252
})
5353
})?;
5454

55-
let upvar_ty = self.universal_regions().defining_ty.upvar_tys().nth(upvar_index);
55+
let upvar_ty = self.universal_regions().defining_ty.upvar_tys().get(upvar_index);
5656

5757
debug!(
5858
"get_upvar_index_for_region: found {fr:?} in upvar {upvar_index} which has type {upvar_ty:?}",

compiler/rustc_borrowck/src/type_check/mod.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -791,25 +791,20 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
791791
(adt_def.variant(FIRST_VARIANT), args)
792792
}
793793
ty::Closure(_, args) => {
794-
return match args
795-
.as_closure()
796-
.tupled_upvars_ty()
797-
.tuple_fields()
798-
.get(field.index())
799-
{
794+
return match args.as_closure().upvar_tys().get(field.index()) {
800795
Some(&ty) => Ok(ty),
801796
None => Err(FieldAccessError::OutOfRange {
802-
field_count: args.as_closure().upvar_tys().count(),
797+
field_count: args.as_closure().upvar_tys().len(),
803798
}),
804799
};
805800
}
806801
ty::Generator(_, args, _) => {
807802
// Only prefix fields (upvars and current state) are
808803
// accessible without a variant index.
809-
return match args.as_generator().prefix_tys().nth(field.index()) {
810-
Some(ty) => Ok(ty),
804+
return match args.as_generator().prefix_tys().get(field.index()) {
805+
Some(ty) => Ok(*ty),
811806
None => Err(FieldAccessError::OutOfRange {
812-
field_count: args.as_generator().prefix_tys().count(),
807+
field_count: args.as_generator().prefix_tys().len(),
813808
}),
814809
};
815810
}
@@ -1772,21 +1767,21 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17721767
}
17731768
}
17741769
AggregateKind::Closure(_, args) => {
1775-
match args.as_closure().upvar_tys().nth(field_index.as_usize()) {
1776-
Some(ty) => Ok(ty),
1770+
match args.as_closure().upvar_tys().get(field_index.as_usize()) {
1771+
Some(ty) => Ok(*ty),
17771772
None => Err(FieldAccessError::OutOfRange {
1778-
field_count: args.as_closure().upvar_tys().count(),
1773+
field_count: args.as_closure().upvar_tys().len(),
17791774
}),
17801775
}
17811776
}
17821777
AggregateKind::Generator(_, args, _) => {
17831778
// It doesn't make sense to look at a field beyond the prefix;
17841779
// these require a variant index, and are not initialized in
17851780
// aggregate rvalues.
1786-
match args.as_generator().prefix_tys().nth(field_index.as_usize()) {
1787-
Some(ty) => Ok(ty),
1781+
match args.as_generator().prefix_tys().get(field_index.as_usize()) {
1782+
Some(ty) => Ok(*ty),
17881783
None => Err(FieldAccessError::OutOfRange {
1789-
field_count: args.as_generator().prefix_tys().count(),
1784+
field_count: args.as_generator().prefix_tys().len(),
17901785
}),
17911786
}
17921787
}

compiler/rustc_borrowck/src/universal_regions.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//! The code in this file doesn't *do anything* with those results; it
1313
//! just returns them for other code to use.
1414
15-
use either::Either;
1615
use rustc_data_structures::fx::FxHashMap;
1716
use rustc_errors::Diagnostic;
1817
use rustc_hir as hir;
@@ -115,14 +114,12 @@ impl<'tcx> DefiningTy<'tcx> {
115114
/// not a closure or generator, there are no upvars, and hence it
116115
/// will be an empty list. The order of types in this list will
117116
/// match up with the upvar order in the HIR, typesystem, and MIR.
118-
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
117+
pub fn upvar_tys(self) -> &'tcx ty::List<Ty<'tcx>> {
119118
match self {
120-
DefiningTy::Closure(_, args) => Either::Left(args.as_closure().upvar_tys()),
121-
DefiningTy::Generator(_, args, _) => {
122-
Either::Right(Either::Left(args.as_generator().upvar_tys()))
123-
}
119+
DefiningTy::Closure(_, args) => args.as_closure().upvar_tys(),
120+
DefiningTy::Generator(_, args, _) => args.as_generator().upvar_tys(),
124121
DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => {
125-
Either::Right(Either::Right(iter::empty()))
122+
ty::List::empty()
126123
}
127124
}
128125
}

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -990,14 +990,8 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
990990
closure_or_generator_di_node: &'ll DIType,
991991
) -> SmallVec<&'ll DIType> {
992992
let (&def_id, up_var_tys) = match closure_or_generator_ty.kind() {
993-
ty::Generator(def_id, args, _) => {
994-
let upvar_tys: SmallVec<_> = args.as_generator().prefix_tys().collect();
995-
(def_id, upvar_tys)
996-
}
997-
ty::Closure(def_id, args) => {
998-
let upvar_tys: SmallVec<_> = args.as_closure().upvar_tys().collect();
999-
(def_id, upvar_tys)
1000-
}
993+
ty::Generator(def_id, args, _) => (def_id, args.as_generator().prefix_tys()),
994+
ty::Closure(def_id, args) => (def_id, args.as_closure().upvar_tys()),
1001995
_ => {
1002996
bug!(
1003997
"build_upvar_field_di_nodes() called with non-closure-or-generator-type: {:?}",
@@ -1007,9 +1001,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
10071001
};
10081002

10091003
debug_assert!(
1010-
up_var_tys
1011-
.iter()
1012-
.all(|&t| t == cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t))
1004+
up_var_tys.iter().all(|t| t == cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), t))
10131005
);
10141006

10151007
let capture_names = cx.tcx.closure_saved_names_of_captured_variables(def_id);

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
379379
// Fields that are common to all states
380380
let common_fields: SmallVec<_> = generator_args
381381
.prefix_tys()
382+
.iter()
382383
.zip(common_upvar_names)
383384
.enumerate()
384385
.map(|(index, (upvar_ty, upvar_name))| {

compiler/rustc_const_eval/src/transform/validate.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
630630
}
631631
ty::Closure(_, args) => {
632632
let args = args.as_closure();
633-
let Some(f_ty) = args.upvar_tys().nth(f.as_usize()) else {
633+
let Some(&f_ty) = args.upvar_tys().get(f.as_usize()) else {
634634
fail_out_of_bounds(self, location);
635635
return;
636636
};
@@ -667,7 +667,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
667667

668668
f_ty.ty
669669
} else {
670-
let Some(f_ty) = args.as_generator().prefix_tys().nth(f.index()) else {
670+
let Some(&f_ty) = args.as_generator().prefix_tys().get(f.index())
671+
else {
671672
fail_out_of_bounds(self, location);
672673
return;
673674
};

compiler/rustc_infer/src/infer/opaque_types.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,19 @@ where
448448
ty::Closure(_, ref args) => {
449449
// Skip lifetime parameters of the enclosing item(s)
450450

451-
args.as_closure().tupled_upvars_ty().visit_with(self);
451+
for upvar in args.as_closure().upvar_tys() {
452+
upvar.visit_with(self);
453+
}
452454
args.as_closure().sig_as_fn_ptr_ty().visit_with(self);
453455
}
454456

455457
ty::Generator(_, ref args, _) => {
456458
// Skip lifetime parameters of the enclosing item(s)
457459
// Also skip the witness type, because that has no free regions.
458460

459-
args.as_generator().tupled_upvars_ty().visit_with(self);
461+
for upvar in args.as_generator().upvar_tys() {
462+
upvar.visit_with(self);
463+
}
460464
args.as_generator().return_ty().visit_with(self);
461465
args.as_generator().yield_ty().visit_with(self);
462466
args.as_generator().resume_ty().visit_with(self);

compiler/rustc_middle/src/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ where
911911
if i == tag_field {
912912
return TyMaybeWithLayout::TyAndLayout(tag_layout(tag));
913913
}
914-
TyMaybeWithLayout::Ty(args.as_generator().prefix_tys().nth(i).unwrap())
914+
TyMaybeWithLayout::Ty(args.as_generator().prefix_tys()[i])
915915
}
916916
},
917917

compiler/rustc_middle/src/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ pub trait PrettyPrinter<'tcx>:
827827
if !args.as_generator().is_valid() {
828828
p!("unavailable");
829829
} else {
830-
self = self.comma_sep(args.as_generator().upvar_tys())?;
830+
self = self.comma_sep(args.as_generator().upvar_tys().iter())?;
831831
}
832832
p!(")");
833833

@@ -900,7 +900,7 @@ pub trait PrettyPrinter<'tcx>:
900900
print(args.as_closure().sig_as_fn_ptr_ty())
901901
);
902902
p!(" upvar_tys=(");
903-
self = self.comma_sep(args.as_closure().upvar_tys())?;
903+
self = self.comma_sep(args.as_closure().upvar_tys().iter())?;
904904
p!(")");
905905
}
906906
}

compiler/rustc_middle/src/ty/sty.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,13 @@ impl<'tcx> ClosureArgs<'tcx> {
296296
/// In case there was a type error in figuring out the types of the captured path, an
297297
/// empty iterator is returned.
298298
#[inline]
299-
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
299+
pub fn upvar_tys(self) -> &'tcx List<Ty<'tcx>> {
300300
match self.tupled_upvars_ty().kind() {
301-
TyKind::Error(_) => None,
302-
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
301+
TyKind::Error(_) => ty::List::empty(),
302+
TyKind::Tuple(..) => self.tupled_upvars_ty().tuple_fields(),
303303
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
304304
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
305305
}
306-
.into_iter()
307-
.flatten()
308306
}
309307

310308
/// Returns the tuple type representing the upvars for this closure.
@@ -436,15 +434,13 @@ impl<'tcx> GeneratorArgs<'tcx> {
436434
/// In case there was a type error in figuring out the types of the captured path, an
437435
/// empty iterator is returned.
438436
#[inline]
439-
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
437+
pub fn upvar_tys(self) -> &'tcx List<Ty<'tcx>> {
440438
match self.tupled_upvars_ty().kind() {
441-
TyKind::Error(_) => None,
442-
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
439+
TyKind::Error(_) => ty::List::empty(),
440+
TyKind::Tuple(..) => self.tupled_upvars_ty().tuple_fields(),
443441
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
444442
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
445443
}
446-
.into_iter()
447-
.flatten()
448444
}
449445

450446
/// Returns the tuple type representing the upvars for this generator.
@@ -576,7 +572,7 @@ impl<'tcx> GeneratorArgs<'tcx> {
576572
/// This is the types of the fields of a generator which are not stored in a
577573
/// variant.
578574
#[inline]
579-
pub fn prefix_tys(self) -> impl Iterator<Item = Ty<'tcx>> {
575+
pub fn prefix_tys(self) -> &'tcx List<Ty<'tcx>> {
580576
self.upvar_tys()
581577
}
582578
}
@@ -592,20 +588,18 @@ impl<'tcx> UpvarArgs<'tcx> {
592588
/// In case there was a type error in figuring out the types of the captured path, an
593589
/// empty iterator is returned.
594590
#[inline]
595-
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
591+
pub fn upvar_tys(self) -> &'tcx List<Ty<'tcx>> {
596592
let tupled_tys = match self {
597593
UpvarArgs::Closure(args) => args.as_closure().tupled_upvars_ty(),
598594
UpvarArgs::Generator(args) => args.as_generator().tupled_upvars_ty(),
599595
};
600596

601597
match tupled_tys.kind() {
602-
TyKind::Error(_) => None,
603-
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
598+
TyKind::Error(_) => ty::List::empty(),
599+
TyKind::Tuple(..) => self.tupled_upvars_ty().tuple_fields(),
604600
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
605601
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
606602
}
607-
.into_iter()
608-
.flatten()
609603
}
610604

611605
#[inline]

compiler/rustc_mir_dataflow/src/elaborate_drops.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -860,20 +860,14 @@ where
860860
fn open_drop(&mut self) -> BasicBlock {
861861
let ty = self.place_ty(self.place);
862862
match ty.kind() {
863-
ty::Closure(_, args) => {
864-
let tys: Vec<_> = args.as_closure().upvar_tys().collect();
865-
self.open_drop_for_tuple(&tys)
866-
}
863+
ty::Closure(_, args) => self.open_drop_for_tuple(&args.as_closure().upvar_tys()),
867864
// Note that `elaborate_drops` only drops the upvars of a generator,
868865
// and this is ok because `open_drop` here can only be reached
869866
// within that own generator's resume function.
870867
// This should only happen for the self argument on the resume function.
871868
// It effectively only contains upvars until the generator transformation runs.
872869
// See librustc_body/transform/generator.rs for more details.
873-
ty::Generator(_, args, _) => {
874-
let tys: Vec<_> = args.as_generator().upvar_tys().collect();
875-
self.open_drop_for_tuple(&tys)
876-
}
870+
ty::Generator(_, args, _) => self.open_drop_for_tuple(&args.as_generator().upvar_tys()),
877871
ty::Tuple(fields) => self.open_drop_for_tuple(fields),
878872
ty::Adt(def, args) => self.open_drop_for_adt(*def, args),
879873
ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),

compiler/rustc_mir_transform/src/generator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ fn sanitize_witness<'tcx>(
856856
tcx: TyCtxt<'tcx>,
857857
body: &Body<'tcx>,
858858
witness: Ty<'tcx>,
859-
upvars: Vec<Ty<'tcx>>,
859+
upvars: &'tcx ty::List<Ty<'tcx>>,
860860
layout: &GeneratorLayout<'tcx>,
861861
) {
862862
let did = body.source.def_id();
@@ -1471,7 +1471,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
14711471
let args = args.as_generator();
14721472
(
14731473
args.discr_ty(tcx),
1474-
args.upvar_tys().collect::<Vec<_>>(),
1474+
args.upvar_tys(),
14751475
args.witness(),
14761476
movability == hir::Movability::Movable,
14771477
)

compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
291291
return Err(NoSolution);
292292
}
293293

294-
constraints.outlives.extend(
295-
args.as_generator().upvar_tys().map(|t| -> ty::GenericArg<'tcx> { t.into() }),
296-
);
294+
constraints
295+
.outlives
296+
.extend(args.as_generator().upvar_tys().iter().map(ty::GenericArg::from));
297297
constraints.outlives.push(args.as_generator().resume_ty().into());
298298
}
299299

compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
21692169
let all = args
21702170
.as_generator()
21712171
.upvar_tys()
2172-
.chain(iter::once(args.as_generator().witness()))
2172+
.iter()
2173+
.chain([args.as_generator().witness()])
21732174
.collect::<Vec<_>>();
21742175
Where(obligation.predicate.rebind(all))
21752176
}
@@ -2210,7 +2211,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
22102211
// Not yet resolved.
22112212
Ambiguous
22122213
} else {
2213-
Where(obligation.predicate.rebind(args.as_closure().upvar_tys().collect()))
2214+
Where(obligation.predicate.rebind(args.as_closure().upvar_tys().to_vec()))
22142215
}
22152216
}
22162217

0 commit comments

Comments
 (0)