mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #130485 - compiler-errors:impossible-types, r=BoxyUwU
Do not expect infer/bound/placeholder/error in v0 symbol mangling
Infer/bound/placeholder/error are not encounterable during codegen. Let's make sure v0 symbol mangling doesn't "accidentally" handle them.
As for aliases (namely: projections and uv consts) these may still be encounterable because of the way that we render the def paths of items. Specifically, when we have something like:
```
struct W<T>(T);
impl<T> W<T> {
fn x() {
fn y() {}
}
}
```
The path of `y` is rendered like `crate_name::W<T>:❌:y`. Specifically, since `y` doesn't inherit the generics of the impl, we use the *identity* substitutions for that impl. If the impl has any aliases, they will remain unnormalized if they're rigid.
r? `@BoxyUwU`
This commit is contained in:
commit
b963750b6b
@ -330,8 +330,12 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
|||||||
ty::Float(FloatTy::F128) => "C4f128",
|
ty::Float(FloatTy::F128) => "C4f128",
|
||||||
ty::Never => "z",
|
ty::Never => "z",
|
||||||
|
|
||||||
// Placeholders (should be demangled as `_`).
|
// Should only be encountered with polymorphization,
|
||||||
ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => "p",
|
// or within the identity-substituted impl header of an
|
||||||
|
// item nested within an impl item.
|
||||||
|
ty::Param(_) => "p",
|
||||||
|
|
||||||
|
ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => bug!(),
|
||||||
|
|
||||||
_ => "",
|
_ => "",
|
||||||
};
|
};
|
||||||
@ -416,12 +420,18 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
|||||||
// Mangle all nominal types as paths.
|
// Mangle all nominal types as paths.
|
||||||
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args)
|
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args)
|
||||||
| ty::FnDef(def_id, args)
|
| ty::FnDef(def_id, args)
|
||||||
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
|
|
||||||
| ty::Closure(def_id, args)
|
| ty::Closure(def_id, args)
|
||||||
| ty::CoroutineClosure(def_id, args)
|
| ty::CoroutineClosure(def_id, args)
|
||||||
| ty::Coroutine(def_id, args) => {
|
| ty::Coroutine(def_id, args) => {
|
||||||
self.print_def_path(def_id, args)?;
|
self.print_def_path(def_id, args)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We may still encounter projections here due to the printing
|
||||||
|
// logic sometimes passing identity-substituted impl headers.
|
||||||
|
ty::Alias(ty::Projection, ty::AliasTy { def_id, args, .. }) => {
|
||||||
|
self.print_def_path(def_id, args)?;
|
||||||
|
}
|
||||||
|
|
||||||
ty::Foreign(def_id) => {
|
ty::Foreign(def_id) => {
|
||||||
self.print_def_path(def_id, &[])?;
|
self.print_def_path(def_id, &[])?;
|
||||||
}
|
}
|
||||||
@ -467,8 +477,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
|||||||
r.print(self)?;
|
r.print(self)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Alias(ty::Inherent, _) => bug!("symbol_names: unexpected inherent projection"),
|
ty::Alias(..) => bug!("symbol_names: unexpected alias"),
|
||||||
ty::Alias(ty::Weak, _) => bug!("symbol_names: unexpected weak projection"),
|
|
||||||
ty::CoroutineWitness(..) => bug!("symbol_names: unexpected `CoroutineWitness`"),
|
ty::CoroutineWitness(..) => bug!("symbol_names: unexpected `CoroutineWitness`"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,21 +559,26 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
|
|||||||
let (ct_ty, valtree) = match ct.kind() {
|
let (ct_ty, valtree) = match ct.kind() {
|
||||||
ty::ConstKind::Value(ty, val) => (ty, val),
|
ty::ConstKind::Value(ty, val) => (ty, val),
|
||||||
|
|
||||||
// Placeholders (should be demangled as `_`).
|
// Should only be encountered with polymorphization,
|
||||||
// NOTE(eddyb) despite `Unevaluated` having a `DefId` (and therefore
|
// or within the identity-substituted impl header of an
|
||||||
// a path), even for it we still need to encode a placeholder, as
|
// item nested within an impl item.
|
||||||
// the path could refer back to e.g. an `impl` using the constant.
|
ty::ConstKind::Param(_) => {
|
||||||
ty::ConstKind::Unevaluated(_)
|
|
||||||
| ty::ConstKind::Expr(_)
|
|
||||||
| ty::ConstKind::Param(_)
|
|
||||||
| ty::ConstKind::Infer(_)
|
|
||||||
| ty::ConstKind::Bound(..)
|
|
||||||
| ty::ConstKind::Placeholder(_)
|
|
||||||
| ty::ConstKind::Error(_) => {
|
|
||||||
// Never cached (single-character).
|
// Never cached (single-character).
|
||||||
self.push("p");
|
self.push("p");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We may still encounter unevaluated consts due to the printing
|
||||||
|
// logic sometimes passing identity-substituted impl headers.
|
||||||
|
ty::Unevaluated(ty::UnevaluatedConst { def, args, .. }) => {
|
||||||
|
return self.print_def_path(def, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
ty::ConstKind::Expr(_)
|
||||||
|
| ty::ConstKind::Infer(_)
|
||||||
|
| ty::ConstKind::Bound(..)
|
||||||
|
| ty::ConstKind::Placeholder(_)
|
||||||
|
| ty::ConstKind::Error(_) => bug!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(&i) = self.consts.get(&ct) {
|
if let Some(&i) = self.consts.get(&ct) {
|
||||||
|
Loading…
Reference in New Issue
Block a user