Auto merge of #120619 - compiler-errors:param, r=lcnr
Assert that params with the same *index* have the same *name* Found this bug when trying to build libcore with the new solver, since it will canonicalize two params with the same index into *different* placeholders if those params differ by name.
This commit is contained in:
commit
520b0b20aa
10 changed files with 90 additions and 41 deletions
|
@ -12,7 +12,7 @@ use rustc_errors::{codes::*, struct_span_code_err, DiagnosticMessage};
|
|||
use rustc_hir as hir;
|
||||
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
fn equate_intrinsic_type<'tcx>(
|
||||
|
@ -133,7 +133,17 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
|
|||
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
|
||||
/// and in `library/core/src/intrinsics.rs`.
|
||||
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
||||
let param = |n| Ty::new_param(tcx, n, Symbol::intern(&format!("P{n}")));
|
||||
let generics = tcx.generics_of(it.owner_id);
|
||||
let param = |n| {
|
||||
if let Some(&ty::GenericParamDef {
|
||||
name, kind: ty::GenericParamDefKind::Type { .. }, ..
|
||||
}) = generics.opt_param_at(n as usize, tcx)
|
||||
{
|
||||
Ty::new_param(tcx, n, name)
|
||||
} else {
|
||||
Ty::new_error_with_message(tcx, tcx.def_span(it.owner_id), "expected param")
|
||||
}
|
||||
};
|
||||
let intrinsic_id = it.owner_id.to_def_id();
|
||||
let intrinsic_name = tcx.item_name(intrinsic_id);
|
||||
let name_str = intrinsic_name.as_str();
|
||||
|
@ -478,9 +488,16 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
|
||||
/// Type-check `extern "platform-intrinsic" { ... }` functions.
|
||||
pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
||||
let generics = tcx.generics_of(it.owner_id);
|
||||
let param = |n| {
|
||||
let name = Symbol::intern(&format!("P{n}"));
|
||||
Ty::new_param(tcx, n, name)
|
||||
if let Some(&ty::GenericParamDef {
|
||||
name, kind: ty::GenericParamDefKind::Type { .. }, ..
|
||||
}) = generics.opt_param_at(n as usize, tcx)
|
||||
{
|
||||
Ty::new_param(tcx, n, name)
|
||||
} else {
|
||||
Ty::new_error_with_message(tcx, tcx.def_span(it.owner_id), "expected param")
|
||||
}
|
||||
};
|
||||
|
||||
let name = it.ident.name;
|
||||
|
|
|
@ -435,7 +435,10 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
|||
Ok(a)
|
||||
}
|
||||
|
||||
(ty::Param(a_p), ty::Param(b_p)) if a_p.index == b_p.index => Ok(a),
|
||||
(ty::Param(a_p), ty::Param(b_p)) if a_p.index == b_p.index => {
|
||||
debug_assert_eq!(a_p.name, b_p.name, "param types with same index differ in name");
|
||||
Ok(a)
|
||||
}
|
||||
|
||||
(ty::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => Ok(a),
|
||||
|
||||
|
@ -593,7 +596,10 @@ pub fn structurally_relate_consts<'tcx, R: TypeRelation<'tcx>>(
|
|||
(ty::ConstKind::Error(_), _) => return Ok(a),
|
||||
(_, ty::ConstKind::Error(_)) => return Ok(b),
|
||||
|
||||
(ty::ConstKind::Param(a_p), ty::ConstKind::Param(b_p)) => a_p.index == b_p.index,
|
||||
(ty::ConstKind::Param(a_p), ty::ConstKind::Param(b_p)) if a_p.index == b_p.index => {
|
||||
debug_assert_eq!(a_p.name, b_p.name, "param types with same index differ in name");
|
||||
true
|
||||
}
|
||||
(ty::ConstKind::Placeholder(p1), ty::ConstKind::Placeholder(p2)) => p1 == p2,
|
||||
(ty::ConstKind::Value(a_val), ty::ConstKind::Value(b_val)) => a_val == b_val,
|
||||
|
||||
|
|
|
@ -447,16 +447,13 @@ fn build_thread_local_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'t
|
|||
fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Body<'tcx> {
|
||||
debug!("build_clone_shim(def_id={:?})", def_id);
|
||||
|
||||
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
||||
|
||||
let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
|
||||
let is_copy = self_ty.is_copy_modulo_regions(tcx, param_env);
|
||||
|
||||
let dest = Place::return_place();
|
||||
let src = tcx.mk_place_deref(Place::from(Local::new(1 + 0)));
|
||||
|
||||
match self_ty.kind() {
|
||||
_ if is_copy => builder.copy_shim(),
|
||||
ty::FnDef(..) | ty::FnPtr(_) => builder.copy_shim(),
|
||||
ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()),
|
||||
ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
|
||||
ty::Coroutine(coroutine_def_id, args) => {
|
||||
|
|
|
@ -209,10 +209,8 @@ fn resolve_associated_item<'tcx>(
|
|||
let name = tcx.item_name(trait_item_id);
|
||||
if name == sym::clone {
|
||||
let self_ty = trait_ref.self_ty();
|
||||
|
||||
let is_copy = self_ty.is_copy_modulo_regions(tcx, param_env);
|
||||
match self_ty.kind() {
|
||||
_ if is_copy => (),
|
||||
ty::FnDef(..) | ty::FnPtr(_) => (),
|
||||
ty::Coroutine(..)
|
||||
| ty::CoroutineWitness(..)
|
||||
| ty::Closure(..)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue