@@ -426,7 +426,15 @@ impl<'tcx> fmt::Display for Instance<'tcx> {
426
426
}
427
427
428
428
impl < ' tcx > Instance < ' tcx > {
429
- pub fn new ( def_id : DefId , args : GenericArgsRef < ' tcx > ) -> Instance < ' tcx > {
429
+ /// Creates a new [`InstanceKind::Item`] from the `def_id` and `args`.
430
+ ///
431
+ /// Note that this item corresponds to the body of `def_id` directly, which
432
+ /// likely does not make sense for trait items which need to be resolved to an
433
+ /// implementation, and which may not even have a body themselves. Usages of
434
+ /// this function should probably use [`Instance::expect_resolve`], or if run
435
+ /// in a polymorphic environment or within a lint (that may encounter ambiguity)
436
+ /// [`Instance::try_resolve`] instead.
437
+ pub fn new_raw ( def_id : DefId , args : GenericArgsRef < ' tcx > ) -> Instance < ' tcx > {
430
438
assert ! (
431
439
!args. has_escaping_bound_vars( ) ,
432
440
"args of instance {def_id:?} has escaping bound vars: {args:?}"
@@ -445,7 +453,7 @@ impl<'tcx> Instance<'tcx> {
445
453
}
446
454
} ) ;
447
455
448
- Instance :: new ( def_id, args)
456
+ Instance :: new_raw ( def_id, args)
449
457
}
450
458
451
459
#[ inline]
@@ -538,7 +546,7 @@ impl<'tcx> Instance<'tcx> {
538
546
let type_length = type_length ( args) ;
539
547
if !tcx. type_length_limit ( ) . value_within_limit ( type_length) {
540
548
let ( shrunk, written_to_path) =
541
- shrunk_instance_name ( tcx, Instance :: new ( def_id, args) ) ;
549
+ shrunk_instance_name ( tcx, Instance :: new_raw ( def_id, args) ) ;
542
550
let mut path = PathBuf :: new ( ) ;
543
551
let was_written = if let Some ( path2) = written_to_path {
544
552
path = path2;
@@ -708,7 +716,7 @@ impl<'tcx> Instance<'tcx> {
708
716
709
717
match needs_fn_once_adapter_shim ( actual_kind, requested_kind) {
710
718
Ok ( true ) => Instance :: fn_once_adapter_instance ( tcx, def_id, args) ,
711
- _ => Instance :: new ( def_id, args) ,
719
+ _ => Instance :: new_raw ( def_id, args) ,
712
720
}
713
721
}
714
722
@@ -822,7 +830,7 @@ impl<'tcx> Instance<'tcx> {
822
830
// This is important for `Iterator`'s combinators, but also useful for
823
831
// adding future default methods to `Future`, for instance.
824
832
debug_assert ! ( tcx. defaultness( trait_item_id) . has_value( ) ) ;
825
- Some ( Instance :: new ( trait_item_id, rcvr_args) )
833
+ Some ( Instance :: new_raw ( trait_item_id, rcvr_args) )
826
834
}
827
835
}
828
836
0 commit comments