Skip to content

Commit 3d5e01f

Browse files
committed
Misc fixes (pattern type lowering, cfi, pretty printing)
1 parent 783d902 commit 3d5e01f

File tree

4 files changed

+36
-40
lines changed

4 files changed

+36
-40
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -2182,17 +2182,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21822182
}
21832183
_ => (expr, None),
21842184
};
2185-
let c = match &expr.kind {
2185+
let (c, c_ty) = match &expr.kind {
21862186
hir::ExprKind::Lit(lit) => {
21872187
let lit_input =
21882188
LitToConstInput { lit: &lit.node, ty, neg: neg.is_some() };
2189-
match tcx.lit_to_const(lit_input) {
2189+
let ct = match tcx.lit_to_const(lit_input) {
21902190
Ok(c) => c,
21912191
Err(LitToConstError::Reported(err)) => {
21922192
ty::Const::new_error(tcx, err)
21932193
}
21942194
Err(LitToConstError::TypeError) => todo!(),
2195-
}
2195+
};
2196+
(ct, ty)
21962197
}
21972198

21982199
hir::ExprKind::Path(hir::QPath::Resolved(
@@ -2210,20 +2211,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22102211
.type_of(def_id)
22112212
.no_bound_vars()
22122213
.expect("const parameter types cannot be generic");
2213-
self.lower_const_param(expr.hir_id)
2214+
let ct = self.lower_const_param(expr.hir_id);
2215+
(ct, ty)
22142216
}
22152217

22162218
_ => {
22172219
let err = tcx
22182220
.dcx()
22192221
.emit_err(crate::errors::NonConstRange { span: expr.span });
2220-
ty::Const::new_error(tcx, err)
2222+
(ty::Const::new_error(tcx, err), Ty::new_error(tcx, err))
22212223
}
22222224
};
2223-
// THISPR
2224-
self.record_ty(expr.hir_id, todo!(), expr.span);
2225+
self.record_ty(expr.hir_id, c_ty, expr.span);
22252226
if let Some((id, span)) = neg {
2226-
self.record_ty(id, todo!(), span);
2227+
self.record_ty(id, c_ty, span);
22272228
}
22282229
c
22292230
};

compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
141141
// `trait_object_dummy_self`, so check for that.
142142
let references_self = match pred.skip_binder().term.unpack() {
143143
ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()),
144-
ty::TermKind::Const(c) => {
145-
// THISPR
146-
false
147-
}
144+
// FIXME(associated_const_equality): We should walk the const instead of not doing anything
145+
ty::TermKind::Const(_) => false,
148146
};
149147

150148
// If the projection output contains `Self`, force the user to

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

+1-18
Original file line numberDiff line numberDiff line change
@@ -1459,23 +1459,6 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
14591459
return Ok(());
14601460
}
14611461

1462-
macro_rules! print_underscore {
1463-
() => {{
1464-
if print_ty {
1465-
self.typed_value(
1466-
|this| {
1467-
write!(this, "_")?;
1468-
Ok(())
1469-
},
1470-
|this| this.print_type(todo!()),
1471-
": ",
1472-
)?;
1473-
} else {
1474-
write!(self, "_")?;
1475-
}
1476-
}};
1477-
}
1478-
14791462
match ct.kind() {
14801463
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args }) => {
14811464
match self.tcx().def_kind(def) {
@@ -1508,7 +1491,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15081491
ty::InferConst::Var(ct_vid) if let Some(name) = self.const_infer_name(ct_vid) => {
15091492
p!(write("{}", name))
15101493
}
1511-
_ => print_underscore!(),
1494+
_ => write!(self, "_")?,
15121495
},
15131496
ty::ConstKind::Param(ParamConst { name, .. }) => p!(write("{}", name)),
15141497
ty::ConstKind::Value(ty, value) => {

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs

+24-10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ fn compress<'tcx>(
6868
fn encode_args<'tcx>(
6969
tcx: TyCtxt<'tcx>,
7070
args: GenericArgsRef<'tcx>,
71+
for_def: DefId,
72+
has_erased_self: bool,
7173
dict: &mut FxHashMap<DictKey<'tcx>, usize>,
7274
options: EncodeTyOptions,
7375
) -> String {
@@ -76,7 +78,8 @@ fn encode_args<'tcx>(
7678
let args: Vec<GenericArg<'_>> = args.iter().collect();
7779
if !args.is_empty() {
7880
s.push('I');
79-
for arg in args {
81+
let def_generics = tcx.generics_of(for_def);
82+
for (n, arg) in args.iter().enumerate() {
8083
match arg.unpack() {
8184
GenericArgKind::Lifetime(region) => {
8285
s.push_str(&encode_region(region, dict));
@@ -85,7 +88,10 @@ fn encode_args<'tcx>(
8588
s.push_str(&encode_ty(tcx, ty, dict, options));
8689
}
8790
GenericArgKind::Const(c) => {
88-
s.push_str(&encode_const(tcx, c, dict, options));
91+
let n = n + (has_erased_self as usize);
92+
let ct_ty =
93+
tcx.type_of(def_generics.param_at(n, tcx).def_id).instantiate_identity();
94+
s.push_str(&encode_const(tcx, c, ct_ty, dict, options));
8995
}
9096
}
9197
}
@@ -99,6 +105,7 @@ fn encode_args<'tcx>(
99105
fn encode_const<'tcx>(
100106
tcx: TyCtxt<'tcx>,
101107
c: Const<'tcx>,
108+
ct_ty: Ty<'tcx>,
102109
dict: &mut FxHashMap<DictKey<'tcx>, usize>,
103110
options: EncodeTyOptions,
104111
) -> String {
@@ -111,8 +118,7 @@ fn encode_const<'tcx>(
111118
// L<element-type>E as literal argument
112119

113120
// Element type
114-
// THISPR
115-
s.push_str(&encode_ty(tcx, todo!(), dict, options));
121+
s.push_str(&encode_ty(tcx, ct_ty, dict, options));
116122
}
117123

118124
// Literal arguments
@@ -232,15 +238,21 @@ fn encode_predicate<'tcx>(
232238
ty::ExistentialPredicate::Trait(trait_ref) => {
233239
let name = encode_ty_name(tcx, trait_ref.def_id);
234240
let _ = write!(s, "u{}{}", name.len(), &name);
235-
s.push_str(&encode_args(tcx, trait_ref.args, dict, options));
241+
s.push_str(&encode_args(tcx, trait_ref.args, trait_ref.def_id, true, dict, options));
236242
}
237243
ty::ExistentialPredicate::Projection(projection) => {
238244
let name = encode_ty_name(tcx, projection.def_id);
239245
let _ = write!(s, "u{}{}", name.len(), &name);
240-
s.push_str(&encode_args(tcx, projection.args, dict, options));
246+
s.push_str(&encode_args(tcx, projection.args, projection.def_id, true, dict, options));
241247
match projection.term.unpack() {
242248
TermKind::Ty(ty) => s.push_str(&encode_ty(tcx, ty, dict, options)),
243-
TermKind::Const(c) => s.push_str(&encode_const(tcx, c, dict, options)),
249+
TermKind::Const(c) => s.push_str(&encode_const(
250+
tcx,
251+
c,
252+
tcx.type_of(projection.def_id).instantiate(tcx, projection.args),
253+
dict,
254+
options,
255+
)),
244256
}
245257
}
246258
ty::ExistentialPredicate::AutoTrait(def_id) => {
@@ -486,7 +498,7 @@ pub fn encode_ty<'tcx>(
486498
// <subst>, as vendor extended type.
487499
let name = encode_ty_name(tcx, def_id);
488500
let _ = write!(s, "u{}{}", name.len(), &name);
489-
s.push_str(&encode_args(tcx, args, dict, options));
501+
s.push_str(&encode_args(tcx, args, def_id, false, dict, options));
490502
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
491503
}
492504
typeid.push_str(&s);
@@ -530,7 +542,7 @@ pub fn encode_ty<'tcx>(
530542
let mut s = String::new();
531543
let name = encode_ty_name(tcx, *def_id);
532544
let _ = write!(s, "u{}{}", name.len(), &name);
533-
s.push_str(&encode_args(tcx, args, dict, options));
545+
s.push_str(&encode_args(tcx, args, *def_id, false, dict, options));
534546
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
535547
typeid.push_str(&s);
536548
}
@@ -542,7 +554,7 @@ pub fn encode_ty<'tcx>(
542554
let name = encode_ty_name(tcx, *def_id);
543555
let _ = write!(s, "u{}{}", name.len(), &name);
544556
let parent_args = tcx.mk_args(args.as_coroutine_closure().parent_args());
545-
s.push_str(&encode_args(tcx, parent_args, dict, options));
557+
s.push_str(&encode_args(tcx, parent_args, *def_id, false, dict, options));
546558
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
547559
typeid.push_str(&s);
548560
}
@@ -557,6 +569,8 @@ pub fn encode_ty<'tcx>(
557569
s.push_str(&encode_args(
558570
tcx,
559571
tcx.mk_args(args.as_coroutine().parent_args()),
572+
*def_id,
573+
false,
560574
dict,
561575
options,
562576
));

0 commit comments

Comments
 (0)