Do not ICE on non-ADT rcvr type when looking for crate version collision · rust-lang/rust@c78e7fa (original) (raw)

`@@ -3498,7 +3498,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

3498

3498

` err,

`

3499

3499

` pick.item.def_id,

`

3500

3500

` rcvr.hir_id,

`

3501

``

`-

*rcvr_ty,

`

``

3501

`+

Some(*rcvr_ty),

`

3502

3502

`);

`

3503

3503

`if pick.autoderefs == 0 && !trait_in_other_version_found {

`

3504

3504

` err.span_label(

`

`@@ -3689,8 +3689,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

3689

3689

`if let SelfSource::QPath(ty) = source

`

3690

3690

` && !valid_out_of_scope_traits.is_empty()

`

3691

3691

` && let hir::TyKind::Path(path) = ty.kind

`

3692

``

`-

&& let hir::QPath::Resolved(_, path) = path

`

3693

``

`-

&& let Some(def_id) = path.res.opt_def_id()

`

``

3692

`+

&& let hir::QPath::Resolved(..) = path

`

3694

3693

` && let Some(assoc) = self

`

3695

3694

`.tcx

`

3696

3695

`.associated_items(valid_out_of_scope_traits[0])

`

`@@ -3700,7 +3699,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

3700

3699

`` // See if the Type::function(val) where function wasn't found corresponds to a

``

3701

3700

`` // Trait that is imported directly, but Type came from a different version of the

``

3702

3701

`// same crate.

`

3703

``

`-

let rcvr_ty = self.tcx.type_of(def_id).instantiate_identity();

`

``

3702

+

``

3703

`+

let rcvr_ty = self.node_ty_opt(ty.hir_id);

`

3704

3704

` trait_in_other_version_found = self.detect_and_explain_multiple_crate_versions(

`

3705

3705

` err,

`

3706

3706

` assoc.def_id,

`

`@@ -4080,7 +4080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

4080

4080

`err: &mut Diag<'_>,

`

4081

4081

`item_def_id: DefId,

`

4082

4082

`hir_id: hir::HirId,

`

4083

``

`-

rcvr_ty: Ty<'_>,

`

``

4083

`+

rcvr_ty: Option<Ty<'_>>,

`

4084

4084

`) -> bool {

`

4085

4085

`let hir_id = self.tcx.parent_hir_id(hir_id);

`

4086

4086

`let Some(traits) = self.tcx.in_scope_traits(hir_id) else { return false };

`

`@@ -4110,8 +4110,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

4110

4110

`let mut multi_span: MultiSpan = trait_span.into();

`

4111

4111

` multi_span.push_span_label(trait_span, format!("this is the trait that is needed"));

`

4112

4112

`let descr = self.tcx.associated_item(item_def_id).descr();

`

``

4113

`+

let rcvr_ty =

`

``

4114

`` +

rcvr_ty.map(|t| format!("{t}")).unwrap_or_else(|| "the receiver".to_string());

``

4113

4115

` multi_span

`

4114

``

`` -

.push_span_label(item_span, format!("the {descr} is available for {rcvr_ty} here"));

``

``

4116

`+

.push_span_label(item_span, format!("the {descr} is available for {rcvr_ty} here"));

`

4115

4117

`for (def_id, import_def_id) in candidates {

`

4116

4118

`if let Some(import_def_id) = import_def_id {

`

4117

4119

` multi_span.push_span_label(

`