Skip to content

Commit f9a2715

Browse files
committed
Misc fixes (pattern type lowering, cfi, pretty printing)
1 parent f7e2846 commit f9a2715

File tree

4 files changed

+33
-40
lines changed

4 files changed

+33
-40
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -2166,17 +2166,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21662166
}
21672167
_ => (expr, None),
21682168
};
2169-
let c = match &expr.kind {
2169+
let (c, c_ty) = match &expr.kind {
21702170
hir::ExprKind::Lit(lit) => {
21712171
let lit_input =
21722172
LitToConstInput { lit: &lit.node, ty, neg: neg.is_some() };
2173-
match tcx.lit_to_const(lit_input) {
2173+
let ct = match tcx.lit_to_const(lit_input) {
21742174
Ok(c) => c,
21752175
Err(LitToConstError::Reported(err)) => {
21762176
ty::Const::new_error(tcx, err)
21772177
}
21782178
Err(LitToConstError::TypeError) => todo!(),
2179-
}
2179+
};
2180+
(ct, ty)
21802181
}
21812182

21822183
hir::ExprKind::Path(hir::QPath::Resolved(
@@ -2194,20 +2195,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21942195
.type_of(def_id)
21952196
.no_bound_vars()
21962197
.expect("const parameter types cannot be generic");
2197-
self.lower_const_param(expr.hir_id)
2198+
let ct = self.lower_const_param(expr.hir_id);
2199+
(ct, ty)
21982200
}
21992201

22002202
_ => {
22012203
let err = tcx
22022204
.dcx()
22032205
.emit_err(crate::errors::NonConstRange { span: expr.span });
2204-
ty::Const::new_error(tcx, err)
2206+
(ty::Const::new_error(tcx, err), Ty::new_error(tcx, err))
22052207
}
22062208
};
2207-
// THISPR
2208-
self.record_ty(expr.hir_id, todo!(), expr.span);
2209+
self.record_ty(expr.hir_id, c_ty, expr.span);
22092210
if let Some((id, span)) = neg {
2210-
self.record_ty(id, todo!(), span);
2211+
self.record_ty(id, c_ty, span);
22112212
}
22122213
c
22132214
};

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

+21-10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fn compress<'tcx>(
6868
fn encode_args<'tcx>(
6969
tcx: TyCtxt<'tcx>,
7070
args: GenericArgsRef<'tcx>,
71+
for_def: DefId,
7172
dict: &mut FxHashMap<DictKey<'tcx>, usize>,
7273
options: EncodeTyOptions,
7374
) -> String {
@@ -76,7 +77,7 @@ fn encode_args<'tcx>(
7677
let args: Vec<GenericArg<'_>> = args.iter().collect();
7778
if !args.is_empty() {
7879
s.push('I');
79-
for arg in args {
80+
for (n, arg) in args.iter().enumerate() {
8081
match arg.unpack() {
8182
GenericArgKind::Lifetime(region) => {
8283
s.push_str(&encode_region(region, dict));
@@ -85,7 +86,10 @@ fn encode_args<'tcx>(
8586
s.push_str(&encode_ty(tcx, ty, dict, options));
8687
}
8788
GenericArgKind::Const(c) => {
88-
s.push_str(&encode_const(tcx, c, dict, options));
89+
let ct_ty = tcx
90+
.type_of(tcx.generics_of(for_def).param_at(n, tcx).def_id)
91+
.instantiate_identity();
92+
s.push_str(&encode_const(tcx, c, ct_ty, dict, options));
8993
}
9094
}
9195
}
@@ -99,6 +103,7 @@ fn encode_args<'tcx>(
99103
fn encode_const<'tcx>(
100104
tcx: TyCtxt<'tcx>,
101105
c: Const<'tcx>,
106+
ct_ty: Ty<'tcx>,
102107
dict: &mut FxHashMap<DictKey<'tcx>, usize>,
103108
options: EncodeTyOptions,
104109
) -> String {
@@ -111,8 +116,7 @@ fn encode_const<'tcx>(
111116
// L<element-type>E as literal argument
112117

113118
// Element type
114-
// THISPR
115-
s.push_str(&encode_ty(tcx, todo!(), dict, options));
119+
s.push_str(&encode_ty(tcx, ct_ty, dict, options));
116120
}
117121

118122
// Literal arguments
@@ -232,15 +236,21 @@ fn encode_predicate<'tcx>(
232236
ty::ExistentialPredicate::Trait(trait_ref) => {
233237
let name = encode_ty_name(tcx, trait_ref.def_id);
234238
let _ = write!(s, "u{}{}", name.len(), &name);
235-
s.push_str(&encode_args(tcx, trait_ref.args, dict, options));
239+
s.push_str(&encode_args(tcx, trait_ref.args, trait_ref.def_id, dict, options));
236240
}
237241
ty::ExistentialPredicate::Projection(projection) => {
238242
let name = encode_ty_name(tcx, projection.def_id);
239243
let _ = write!(s, "u{}{}", name.len(), &name);
240-
s.push_str(&encode_args(tcx, projection.args, dict, options));
244+
s.push_str(&encode_args(tcx, projection.args, projection.def_id, dict, options));
241245
match projection.term.unpack() {
242246
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)),
247+
TermKind::Const(c) => s.push_str(&encode_const(
248+
tcx,
249+
c,
250+
tcx.type_of(projection.def_id).instantiate(tcx, projection.args),
251+
dict,
252+
options,
253+
)),
244254
}
245255
}
246256
ty::ExistentialPredicate::AutoTrait(def_id) => {
@@ -486,7 +496,7 @@ pub fn encode_ty<'tcx>(
486496
// <subst>, as vendor extended type.
487497
let name = encode_ty_name(tcx, def_id);
488498
let _ = write!(s, "u{}{}", name.len(), &name);
489-
s.push_str(&encode_args(tcx, args, dict, options));
499+
s.push_str(&encode_args(tcx, args, def_id, dict, options));
490500
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
491501
}
492502
typeid.push_str(&s);
@@ -530,7 +540,7 @@ pub fn encode_ty<'tcx>(
530540
let mut s = String::new();
531541
let name = encode_ty_name(tcx, *def_id);
532542
let _ = write!(s, "u{}{}", name.len(), &name);
533-
s.push_str(&encode_args(tcx, args, dict, options));
543+
s.push_str(&encode_args(tcx, args, *def_id, dict, options));
534544
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
535545
typeid.push_str(&s);
536546
}
@@ -542,7 +552,7 @@ pub fn encode_ty<'tcx>(
542552
let name = encode_ty_name(tcx, *def_id);
543553
let _ = write!(s, "u{}{}", name.len(), &name);
544554
let parent_args = tcx.mk_args(args.as_coroutine_closure().parent_args());
545-
s.push_str(&encode_args(tcx, parent_args, dict, options));
555+
s.push_str(&encode_args(tcx, parent_args, *def_id, dict, options));
546556
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
547557
typeid.push_str(&s);
548558
}
@@ -557,6 +567,7 @@ pub fn encode_ty<'tcx>(
557567
s.push_str(&encode_args(
558568
tcx,
559569
tcx.mk_args(args.as_coroutine().parent_args()),
570+
*def_id,
560571
dict,
561572
options,
562573
));

0 commit comments

Comments
 (0)