Skip to content

Commit db5704f

Browse files
committed
Auto merge of rust-lang#129024 - matthiaskrgr:rollup-uj1pd0x, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#128712 (Normalize struct tail properly for `dyn` ptr-to-ptr casting in new solver) - rust-lang#128912 (Store `do_not_recommend`-ness in impl header) - rust-lang#129000 (bootstrap: clear miri ui-test deps when miri sysroot gets rebuilt) - rust-lang#129013 (Remove unused script from run-make tests) - rust-lang#129017 (Replace `std::fmt:FormatterFn` with `std::fmt::from_fn`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 91376f4 + 522d436 commit db5704f

File tree

27 files changed

+174
-94
lines changed

27 files changed

+174
-94
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_middle::mir::ConstraintCategory;
77
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, Upcast};
88
use rustc_span::def_id::DefId;
99
use rustc_span::Span;
10+
use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
1011
use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput};
1112
use rustc_trait_selection::traits::ObligationCause;
1213

@@ -165,6 +166,52 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
165166
result.unwrap_or(value)
166167
}
167168

169+
#[instrument(skip(self), level = "debug")]
170+
pub(super) fn struct_tail(
171+
&mut self,
172+
ty: Ty<'tcx>,
173+
location: impl NormalizeLocation,
174+
) -> Ty<'tcx> {
175+
let tcx = self.tcx();
176+
if self.infcx.next_trait_solver() {
177+
let body = self.body;
178+
let param_env = self.param_env;
179+
self.fully_perform_op(
180+
location.to_locations(),
181+
ConstraintCategory::Boring,
182+
CustomTypeOp::new(
183+
|ocx| {
184+
let structurally_normalize = |ty| {
185+
ocx.structurally_normalize(
186+
&ObligationCause::misc(
187+
location.to_locations().span(body),
188+
body.source.def_id().expect_local(),
189+
),
190+
param_env,
191+
ty,
192+
)
193+
.unwrap_or_else(|_| bug!("struct tail should have been computable, since we computed it in HIR"))
194+
};
195+
196+
let tail = tcx.struct_tail_raw(
197+
ty,
198+
structurally_normalize,
199+
|| {},
200+
);
201+
202+
Ok(tail)
203+
},
204+
"normalizing struct tail",
205+
),
206+
)
207+
.unwrap_or_else(|guar| Ty::new_error(tcx, guar))
208+
} else {
209+
let mut normalize = |ty| self.normalize(ty, location);
210+
let tail = tcx.struct_tail_raw(ty, &mut normalize, || {});
211+
normalize(tail)
212+
}
213+
}
214+
168215
#[instrument(skip(self), level = "debug")]
169216
pub(super) fn ascribe_user_type(
170217
&mut self,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,17 +2329,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23292329
let cast_ty_to = CastTy::from_ty(*ty);
23302330
match (cast_ty_from, cast_ty_to) {
23312331
(Some(CastTy::Ptr(src)), Some(CastTy::Ptr(dst))) => {
2332-
let mut normalize = |t| self.normalize(t, location);
2333-
2334-
// N.B. `struct_tail_with_normalize` only "structurally resolves"
2335-
// the type. It is not fully normalized, so we have to normalize it
2336-
// afterwards.
2337-
let src_tail =
2338-
tcx.struct_tail_with_normalize(src.ty, &mut normalize, || ());
2339-
let src_tail = normalize(src_tail);
2340-
let dst_tail =
2341-
tcx.struct_tail_with_normalize(dst.ty, &mut normalize, || ());
2342-
let dst_tail = normalize(dst_tail);
2332+
let src_tail = self.struct_tail(src.ty, location);
2333+
let dst_tail = self.struct_tail(dst.ty, location);
23432334

23442335
// This checks (lifetime part of) vtable validity for pointer casts,
23452336
// which is irrelevant when there are aren't principal traits on both sides (aka only auto traits).

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ pub(super) fn op_to_const<'tcx>(
226226
let pointee_ty = imm.layout.ty.builtin_deref(false).unwrap(); // `false` = no raw ptrs
227227
debug_assert!(
228228
matches!(
229-
ecx.tcx.struct_tail_without_normalization(pointee_ty).kind(),
229+
ecx.tcx.struct_tail_for_codegen(pointee_ty, ecx.param_env).kind(),
230230
ty::Str | ty::Slice(..),
231231
),
232232
"`ConstValue::Slice` is for slice-tailed types only, but got {}",

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn reconstruct_place_meta<'tcx>(
195195

196196
let mut last_valtree = valtree;
197197
// Traverse the type, and update `last_valtree` as we go.
198-
let tail = tcx.struct_tail_with_normalize(
198+
let tail = tcx.struct_tail_raw(
199199
layout.ty,
200200
|ty| ty,
201201
|| {

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,8 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai
17001700
trait_ref: ty::EarlyBinder::bind(trait_ref),
17011701
safety: impl_.safety,
17021702
polarity: polarity_of_impl(tcx, def_id, impl_, item.span),
1703+
do_not_recommend: tcx.features().do_not_recommend
1704+
&& tcx.has_attrs_with_path(def_id, &[sym::diagnostic, sym::do_not_recommend]),
17031705
}
17041706
})
17051707
}

compiler/rustc_hir_typeck/src/cast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9797
return Ok(Some(PointerKind::Thin));
9898
}
9999

100+
let t = self.try_structurally_resolve_type(span, t);
101+
100102
Ok(match *t.kind() {
101103
ty::Slice(_) | ty::Str => Some(PointerKind::Length),
102104
ty::Dynamic(tty, _, ty::Dyn) => Some(PointerKind::VTable(tty)),

compiler/rustc_hir_typeck/src/expectation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ impl<'a, 'tcx> Expectation<'tcx> {
7070
/// See the test case `test/ui/coerce-expect-unsized.rs` and #20169
7171
/// for examples of where this comes up,.
7272
pub(super) fn rvalue_hint(fcx: &FnCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Expectation<'tcx> {
73-
match fcx.tcx.struct_tail_without_normalization(ty).kind() {
73+
// FIXME: This is not right, even in the old solver...
74+
match fcx.tcx.struct_tail_raw(ty, |ty| ty, || {}).kind() {
7475
ty::Slice(_) | ty::Str | ty::Dynamic(..) => ExpectRvalueLikeUnsized(ty),
7576
_ => ExpectHasType(ty),
7677
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
404404
code: traits::ObligationCauseCode<'tcx>,
405405
) {
406406
if !ty.references_error() {
407-
let tail = self.tcx.struct_tail_with_normalize(
407+
let tail = self.tcx.struct_tail_raw(
408408
ty,
409409
|ty| {
410410
if self.next_trait_solver() {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,6 +3176,12 @@ impl<'tcx> TyCtxt<'tcx> {
31763176
pub fn impl_polarity(self, def_id: impl IntoQueryParam<DefId>) -> ty::ImplPolarity {
31773177
self.impl_trait_header(def_id).map_or(ty::ImplPolarity::Positive, |h| h.polarity)
31783178
}
3179+
3180+
/// Whether this is a trait implementation that has `#[diagnostic::do_not_recommend]`
3181+
pub fn do_not_recommend_impl(self, def_id: DefId) -> bool {
3182+
matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true })
3183+
&& self.impl_trait_header(def_id).is_some_and(|header| header.do_not_recommend)
3184+
}
31793185
}
31803186

31813187
/// Parameter attributes that can only be determined by examining the body of a function instead

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
362362
ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => {
363363
let non_zero = !ty.is_unsafe_ptr();
364364

365-
let tail = tcx.struct_tail_with_normalize(
365+
let tail = tcx.struct_tail_raw(
366366
pointee,
367367
|ty| match tcx.try_normalize_erasing_regions(param_env, ty) {
368368
Ok(ty) => ty,

0 commit comments

Comments
 (0)