Skip to content

Commit 553ecbe

Browse files
committed
Auto merge of #109652 - matthiaskrgr:rollup-pbw3hi3, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #97506 (Stabilize `nonnull_slice_from_raw_parts`) - #98651 (Follow C-RW-VALUE in std::io::Cursor example) - #102742 (Remove unnecessary raw pointer in __rust_start_panic arg) - #109587 (Use an IndexVec to debug fingerprints.) - #109613 (fix type suggestions in match arms) - #109633 (Fix "Directly go to item in search if there is only one result" setting) - #109635 (debuginfo: Get pointer size/align from tcx.data_layout instead of layout_of) - #109641 (Don't elaborate non-obligations into obligations) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7a06007 + 6535e66 commit 553ecbe

File tree

37 files changed

+235
-181
lines changed

37 files changed

+235
-181
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,14 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
176176

177177
return_if_di_node_created_in_meantime!(cx, unique_type_id);
178178

179-
let (thin_pointer_size, thin_pointer_align) =
180-
cx.size_and_align_of(cx.tcx.mk_imm_ptr(cx.tcx.types.unit));
179+
let data_layout = &cx.tcx.data_layout;
181180
let ptr_type_debuginfo_name = compute_debuginfo_type_name(cx.tcx, ptr_type, true);
182181

183182
match fat_pointer_kind(cx, pointee_type) {
184183
None => {
185184
// This is a thin pointer. Create a regular pointer type and give it the correct name.
186185
debug_assert_eq!(
187-
(thin_pointer_size, thin_pointer_align),
186+
(data_layout.pointer_size, data_layout.pointer_align.abi),
188187
cx.size_and_align_of(ptr_type),
189188
"ptr_type={}, pointee_type={}",
190189
ptr_type,
@@ -195,8 +194,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
195194
llvm::LLVMRustDIBuilderCreatePointerType(
196195
DIB(cx),
197196
pointee_type_di_node,
198-
thin_pointer_size.bits(),
199-
thin_pointer_align.bits() as u32,
197+
data_layout.pointer_size.bits(),
198+
data_layout.pointer_align.abi.bits() as u32,
200199
0, // Ignore DWARF address space.
201200
ptr_type_debuginfo_name.as_ptr().cast(),
202201
ptr_type_debuginfo_name.len(),

compiler/rustc_hir_analysis/src/astconv/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1427,13 +1427,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14271427
for (base_trait_ref, span, constness) in regular_traits_refs_spans {
14281428
assert_eq!(constness, ty::BoundConstness::NotConst);
14291429

1430-
for obligation in traits::elaborate_trait_ref(tcx, base_trait_ref) {
1431-
debug!(
1432-
"conv_object_ty_poly_trait_ref: observing object predicate `{:?}`",
1433-
obligation.predicate
1434-
);
1430+
for pred in traits::elaborate_trait_ref(tcx, base_trait_ref) {
1431+
debug!("conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", pred);
14351432

1436-
let bound_predicate = obligation.predicate.kind();
1433+
let bound_predicate = pred.kind();
14371434
match bound_predicate.skip_binder() {
14381435
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => {
14391436
let pred = bound_predicate.rebind(pred);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1912,14 +1912,13 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
19121912
// Check elaborated bounds.
19131913
let implied_obligations = traits::elaborate_predicates_with_span(tcx, predicates_with_span);
19141914

1915-
for obligation in implied_obligations {
1915+
for (pred, obligation_span) in implied_obligations {
19161916
// We lower empty bounds like `Vec<dyn Copy>:` as
19171917
// `WellFormed(Vec<dyn Copy>)`, which will later get checked by
19181918
// regular WF checking
1919-
if let ty::PredicateKind::WellFormed(..) = obligation.predicate.kind().skip_binder() {
1919+
if let ty::PredicateKind::WellFormed(..) = pred.kind().skip_binder() {
19201920
continue;
19211921
}
1922-
let pred = obligation.predicate;
19231922
// Match the existing behavior.
19241923
if pred.is_global() && !pred.has_late_bound_vars() {
19251924
let pred = self.normalize(span, None, pred);
@@ -1930,8 +1929,6 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
19301929
if let Some(hir::Generics { predicates, .. }) =
19311930
hir_node.and_then(|node| node.generics())
19321931
{
1933-
let obligation_span = obligation.cause.span();
1934-
19351932
span = predicates
19361933
.iter()
19371934
// There seems to be no better way to find out which predicate we are in

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,9 @@ pub(super) fn item_bounds(
130130
tcx: TyCtxt<'_>,
131131
def_id: DefId,
132132
) -> ty::EarlyBinder<&'_ ty::List<ty::Predicate<'_>>> {
133-
let bounds = tcx.mk_predicates_from_iter(
134-
util::elaborate_predicates(
135-
tcx,
136-
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
137-
)
138-
.map(|obligation| obligation.predicate),
139-
);
133+
let bounds = tcx.mk_predicates_from_iter(util::elaborate_predicates(
134+
tcx,
135+
tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound),
136+
));
140137
ty::EarlyBinder(bounds)
141138
}

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+13-21
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,8 @@ fn check_predicates<'tcx>(
318318
span: Span,
319319
) {
320320
let instantiated = tcx.predicates_of(impl1_def_id).instantiate(tcx, impl1_substs);
321-
let impl1_predicates: Vec<_> = traits::elaborate_predicates_with_span(
322-
tcx,
323-
std::iter::zip(
324-
instantiated.predicates,
325-
// Don't drop predicates (unsound!) because `spans` is too short
326-
instantiated.spans.into_iter().chain(std::iter::repeat(span)),
327-
),
328-
)
329-
.map(|obligation| (obligation.predicate, obligation.cause.span))
330-
.collect();
321+
let impl1_predicates: Vec<_> =
322+
traits::elaborate_predicates_with_span(tcx, instantiated.into_iter()).collect();
331323

332324
let mut impl2_predicates = if impl2_node.is_from_trait() {
333325
// Always applicable traits have to be always applicable without any
@@ -341,7 +333,6 @@ fn check_predicates<'tcx>(
341333
.predicates
342334
.into_iter(),
343335
)
344-
.map(|obligation| obligation.predicate)
345336
.collect()
346337
};
347338
debug!(?impl1_predicates, ?impl2_predicates);
@@ -361,12 +352,16 @@ fn check_predicates<'tcx>(
361352
// which is sound because we forbid impls like the following
362353
//
363354
// impl<D: Debug> AlwaysApplicable for D { }
364-
let always_applicable_traits = impl1_predicates.iter().copied().filter(|&(predicate, _)| {
365-
matches!(
366-
trait_predicate_kind(tcx, predicate),
367-
Some(TraitSpecializationKind::AlwaysApplicable)
368-
)
369-
});
355+
let always_applicable_traits = impl1_predicates
356+
.iter()
357+
.copied()
358+
.filter(|&(predicate, _)| {
359+
matches!(
360+
trait_predicate_kind(tcx, predicate),
361+
Some(TraitSpecializationKind::AlwaysApplicable)
362+
)
363+
})
364+
.map(|(pred, _span)| pred);
370365

371366
// Include the well-formed predicates of the type parameters of the impl.
372367
for arg in tcx.impl_trait_ref(impl1_def_id).unwrap().subst_identity().substs {
@@ -380,10 +375,7 @@ fn check_predicates<'tcx>(
380375
traits::elaborate_obligations(tcx, obligations).map(|obligation| obligation.predicate),
381376
)
382377
}
383-
impl2_predicates.extend(
384-
traits::elaborate_predicates_with_span(tcx, always_applicable_traits)
385-
.map(|obligation| obligation.predicate),
386-
);
378+
impl2_predicates.extend(traits::elaborate_predicates(tcx, always_applicable_traits));
387379

388380
for (predicate, span) in impl1_predicates {
389381
if !impl2_predicates.iter().any(|pred2| trait_predicates_eq(tcx, predicate, *pred2, span)) {

compiler/rustc_hir_typeck/src/closure.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
204204
let mut expected_sig = None;
205205
let mut expected_kind = None;
206206

207-
for obligation in traits::elaborate_predicates_with_span(
207+
for (pred, span) in traits::elaborate_predicates_with_span(
208208
self.tcx,
209209
// Reverse the obligations here, since `elaborate_*` uses a stack,
210210
// and we want to keep inference generally in the same order of
211211
// the registered obligations.
212212
predicates.rev(),
213213
) {
214-
debug!(?obligation.predicate);
215-
let bound_predicate = obligation.predicate.kind();
214+
debug!(?pred);
215+
let bound_predicate = pred.kind();
216216

217217
// Given a Projection predicate, we can potentially infer
218218
// the complete signature.
219219
if expected_sig.is_none()
220220
&& let ty::PredicateKind::Clause(ty::Clause::Projection(proj_predicate)) = bound_predicate.skip_binder()
221221
{
222222
let inferred_sig = self.normalize(
223-
obligation.cause.span,
223+
span,
224224
self.deduce_sig_from_projection(
225-
Some(obligation.cause.span),
225+
Some(span),
226226
bound_predicate.rebind(proj_predicate),
227227
),
228228
);

compiler/rustc_hir_typeck/src/method/confirm.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -576,17 +576,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
576576

577577
traits::elaborate_predicates(self.tcx, predicates.predicates.iter().copied())
578578
// We don't care about regions here.
579-
.filter_map(|obligation| match obligation.predicate.kind().skip_binder() {
579+
.filter_map(|pred| match pred.kind().skip_binder() {
580580
ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred))
581581
if trait_pred.def_id() == sized_def_id =>
582582
{
583583
let span = predicates
584584
.iter()
585-
.find_map(
586-
|(p, span)| {
587-
if p == obligation.predicate { Some(span) } else { None }
588-
},
589-
)
585+
.find_map(|(p, span)| if p == pred { Some(span) } else { None })
590586
.unwrap_or(rustc_span::DUMMY_SP);
591587
Some((trait_pred, span))
592588
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1942,7 +1942,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19421942
escaped
19431943
}
19441944
let mut err = struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str);
1945-
if let Some((expected, found)) = trace.values.ty() {
1945+
let values = self.resolve_vars_if_possible(trace.values);
1946+
if let Some((expected, found)) = values.ty() {
19461947
match (expected.kind(), found.kind()) {
19471948
(ty::Tuple(_), ty::Tuple(_)) => {}
19481949
// If a tuple of length one was expected and the found expression has

compiler/rustc_infer/src/traits/util.rs

+43-35
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,58 @@ pub struct Elaborator<'tcx> {
7474
pub fn elaborate_trait_ref<'tcx>(
7575
tcx: TyCtxt<'tcx>,
7676
trait_ref: ty::PolyTraitRef<'tcx>,
77-
) -> Elaborator<'tcx> {
77+
) -> impl Iterator<Item = ty::Predicate<'tcx>> {
7878
elaborate_predicates(tcx, std::iter::once(trait_ref.without_const().to_predicate(tcx)))
7979
}
8080

8181
pub fn elaborate_trait_refs<'tcx>(
8282
tcx: TyCtxt<'tcx>,
8383
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
84-
) -> Elaborator<'tcx> {
85-
let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate(tcx));
84+
) -> impl Iterator<Item = ty::Predicate<'tcx>> {
85+
let predicates = trait_refs.map(move |trait_ref| trait_ref.without_const().to_predicate(tcx));
8686
elaborate_predicates(tcx, predicates)
8787
}
8888

8989
pub fn elaborate_predicates<'tcx>(
9090
tcx: TyCtxt<'tcx>,
9191
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
92-
) -> Elaborator<'tcx> {
93-
let obligations = predicates
94-
.map(|predicate| {
95-
predicate_obligation(predicate, ty::ParamEnv::empty(), ObligationCause::dummy())
96-
})
97-
.collect();
98-
elaborate_obligations(tcx, obligations)
92+
) -> impl Iterator<Item = ty::Predicate<'tcx>> {
93+
elaborate_obligations(
94+
tcx,
95+
predicates
96+
.map(|predicate| {
97+
Obligation::new(
98+
tcx,
99+
// We'll dump the cause/param-env later
100+
ObligationCause::dummy(),
101+
ty::ParamEnv::empty(),
102+
predicate,
103+
)
104+
})
105+
.collect(),
106+
)
107+
.map(|obl| obl.predicate)
99108
}
100109

101110
pub fn elaborate_predicates_with_span<'tcx>(
102111
tcx: TyCtxt<'tcx>,
103112
predicates: impl Iterator<Item = (ty::Predicate<'tcx>, Span)>,
104-
) -> Elaborator<'tcx> {
105-
let obligations = predicates
106-
.map(|(predicate, span)| {
107-
predicate_obligation(
108-
predicate,
109-
ty::ParamEnv::empty(),
110-
ObligationCause::dummy_with_span(span),
111-
)
112-
})
113-
.collect();
114-
elaborate_obligations(tcx, obligations)
113+
) -> impl Iterator<Item = (ty::Predicate<'tcx>, Span)> {
114+
elaborate_obligations(
115+
tcx,
116+
predicates
117+
.map(|(predicate, span)| {
118+
Obligation::new(
119+
tcx,
120+
// We'll dump the cause/param-env later
121+
ObligationCause::dummy_with_span(span),
122+
ty::ParamEnv::empty(),
123+
predicate,
124+
)
125+
})
126+
.collect(),
127+
)
128+
.map(|obl| (obl.predicate, obl.cause.span))
115129
}
116130

117131
pub fn elaborate_obligations<'tcx>(
@@ -141,10 +155,6 @@ impl<'tcx> Elaborator<'tcx> {
141155
self.stack.extend(obligations.into_iter().filter(|o| self.visited.insert(o.predicate)));
142156
}
143157

144-
pub fn filter_to_traits(self) -> FilterToTraits<Self> {
145-
FilterToTraits::new(self)
146-
}
147-
148158
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
149159
let tcx = self.visited.tcx;
150160

@@ -325,20 +335,18 @@ impl<'tcx> Iterator for Elaborator<'tcx> {
325335
// Supertrait iterator
326336
///////////////////////////////////////////////////////////////////////////
327337

328-
pub type Supertraits<'tcx> = FilterToTraits<Elaborator<'tcx>>;
329-
330338
pub fn supertraits<'tcx>(
331339
tcx: TyCtxt<'tcx>,
332340
trait_ref: ty::PolyTraitRef<'tcx>,
333-
) -> Supertraits<'tcx> {
334-
elaborate_trait_ref(tcx, trait_ref).filter_to_traits()
341+
) -> impl Iterator<Item = ty::PolyTraitRef<'tcx>> {
342+
FilterToTraits::new(elaborate_trait_ref(tcx, trait_ref))
335343
}
336344

337345
pub fn transitive_bounds<'tcx>(
338346
tcx: TyCtxt<'tcx>,
339-
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
340-
) -> Supertraits<'tcx> {
341-
elaborate_trait_refs(tcx, bounds).filter_to_traits()
347+
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
348+
) -> impl Iterator<Item = ty::PolyTraitRef<'tcx>> {
349+
FilterToTraits::new(elaborate_trait_refs(tcx, trait_refs))
342350
}
343351

344352
/// A specialized variant of `elaborate_trait_refs` that only elaborates trait references that may
@@ -393,12 +401,12 @@ impl<I> FilterToTraits<I> {
393401
}
394402
}
395403

396-
impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToTraits<I> {
404+
impl<'tcx, I: Iterator<Item = ty::Predicate<'tcx>>> Iterator for FilterToTraits<I> {
397405
type Item = ty::PolyTraitRef<'tcx>;
398406

399407
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
400-
while let Some(obligation) = self.base_iterator.next() {
401-
if let Some(data) = obligation.predicate.to_opt_poly_trait_pred() {
408+
while let Some(pred) = self.base_iterator.next() {
409+
if let Some(data) = pred.to_opt_poly_trait_pred() {
402410
return Some(data.map_bound(|t| t.trait_ref));
403411
}
404412
}

compiler/rustc_lint/src/unused.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
258258
cx.tcx,
259259
cx.tcx.explicit_item_bounds(def).iter().cloned(),
260260
)
261-
.find_map(|obligation| {
261+
.find_map(|(pred, _span)| {
262262
// We only look at the `DefId`, so it is safe to skip the binder here.
263263
if let ty::PredicateKind::Clause(ty::Clause::Trait(
264264
ref poly_trait_predicate,
265-
)) = obligation.predicate.kind().skip_binder()
265+
)) = pred.kind().skip_binder()
266266
{
267267
let def_id = poly_trait_predicate.trait_ref.def_id;
268268

compiler/rustc_mir_transform/src/const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
117117
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
118118
if traits::impossible_predicates(
119119
tcx,
120-
traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(),
120+
traits::elaborate_predicates(tcx, predicates).collect(),
121121
) {
122122
trace!("ConstProp skipped for {:?}: found unsatisfiable predicates", def_id);
123123
return;

compiler/rustc_mir_transform/src/const_prop_lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'tcx> MirLint<'tcx> for ConstProp {
9393
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
9494
if traits::impossible_predicates(
9595
tcx,
96-
traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(),
96+
traits::elaborate_predicates(tcx, predicates).collect(),
9797
) {
9898
trace!("ConstProp skipped for {:?}: found unsatisfiable predicates", def_id);
9999
return;

0 commit comments

Comments
 (0)