Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 61fa5f9

Browse files
committed
Auto merge of rust-lang#129022 - matthiaskrgr:rollup-gs94t7k, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#128712 (Normalize struct tail properly for `dyn` ptr-to-ptr casting in new solver) - rust-lang#128861 (Rework MIR inlining debuginfo so function parameters show up in debuggers.) - 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`) Failed merges: - rust-lang#128935 (More work on `zstd` compression) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 91376f4 + 6f8c7c9 commit 61fa5f9

File tree

33 files changed

+206
-114
lines changed

33 files changed

+206
-114
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_codegen_llvm/src/debuginfo/create_scope_map.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn make_mir_scope<'ll, 'tcx>(
8888
let loc = cx.lookup_debug_loc(scope_data.span.lo());
8989
let file_metadata = file_metadata(cx, &loc.file);
9090

91-
let parent_dbg_scope = match scope_data.inlined {
91+
let dbg_scope = match scope_data.inlined {
9292
Some((callee, _)) => {
9393
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
9494
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
@@ -102,17 +102,15 @@ fn make_mir_scope<'ll, 'tcx>(
102102
cx.dbg_scope_fn(callee, callee_fn_abi, None)
103103
})
104104
}
105-
None => parent_scope.dbg_scope,
106-
};
107-
108-
let dbg_scope = unsafe {
109-
llvm::LLVMRustDIBuilderCreateLexicalBlock(
110-
DIB(cx),
111-
parent_dbg_scope,
112-
file_metadata,
113-
loc.line,
114-
loc.col,
115-
)
105+
None => unsafe {
106+
llvm::LLVMRustDIBuilderCreateLexicalBlock(
107+
DIB(cx),
108+
parent_scope.dbg_scope,
109+
file_metadata,
110+
loc.line,
111+
loc.col,
112+
)
113+
},
116114
};
117115

118116
let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::hash_map::Entry;
12
use std::ops::Range;
23

34
use rustc_data_structures::fx::FxHashMap;
@@ -447,6 +448,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
447448
}
448449

449450
let mut per_local = IndexVec::from_elem(vec![], &self.mir.local_decls);
451+
let mut params_seen: FxHashMap<_, Bx::DIVariable> = Default::default();
450452
for var in &self.mir.var_debug_info {
451453
let dbg_scope_and_span = if full_debug_info {
452454
self.adjusted_span_and_dbg_scope(var.source_info)
@@ -491,7 +493,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
491493
VariableKind::LocalVariable
492494
};
493495

494-
self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span)
496+
if let VariableKind::ArgumentVariable(arg_index) = var_kind {
497+
match params_seen.entry((dbg_scope, arg_index)) {
498+
Entry::Occupied(o) => o.get().clone(),
499+
Entry::Vacant(v) => v
500+
.insert(
501+
self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span),
502+
)
503+
.clone(),
504+
}
505+
} else {
506+
self.cx.create_dbg_var(var.name, var_ty, dbg_scope, var_kind, span)
507+
}
495508
});
496509

497510
let fragment = if let Some(ref fragment) = var.composite {

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
106106
locals: locals::Locals<'tcx, Bx::Value>,
107107

108108
/// All `VarDebugInfo` from the MIR body, partitioned by `Local`.
109-
/// This is `None` if no var`#[non_exhaustive]`iable debuginfo/names are needed.
109+
/// This is `None` if no variable debuginfo/names are needed.
110110
per_local_var_debug_info:
111111
Option<IndexVec<mir::Local, Vec<PerLocalVarDebugInfo<'tcx, Bx::DIVariable>>>>,
112112

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::any::Any;
2+
use std::hash::Hash;
23

34
use rustc_ast::expand::allocator::AllocatorKind;
45
use rustc_data_structures::fx::FxIndexMap;
@@ -30,7 +31,7 @@ pub trait BackendTypes {
3031

3132
// FIXME(eddyb) find a common convention for all of the debuginfo-related
3233
// names (choose between `Dbg`, `Debug`, `DebugInfo`, `DI` etc.).
33-
type DIScope: Copy;
34+
type DIScope: Copy + Hash + PartialEq + Eq;
3435
type DILocation: Copy;
3536
type DIVariable: Copy;
3637
}

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)),

0 commit comments

Comments
 (0)