@@ -491,7 +491,15 @@ fn resolve_async_drop_poll<'tcx>(mut cor_ty: Ty<'tcx>) -> Instance<'tcx> {
491
491
}
492
492
493
493
impl < ' tcx > Instance < ' tcx > {
494
- pub fn new ( def_id : DefId , args : GenericArgsRef < ' tcx > ) -> Instance < ' tcx > {
494
+ /// Creates a new [`InstanceKind::Item`] from the `def_id` and `args`.
495
+ ///
496
+ /// Note that this item corresponds to the body of `def_id` directly, which
497
+ /// likely does not make sense for trait items which need to be resolved to an
498
+ /// implementation, and which may not even have a body themselves. Usages of
499
+ /// this function should probably use [`Instance::expect_resolve`], or if run
500
+ /// in a polymorphic environment or within a lint (that may encounter ambiguity)
501
+ /// [`Instance::try_resolve`] instead.
502
+ pub fn new_raw ( def_id : DefId , args : GenericArgsRef < ' tcx > ) -> Instance < ' tcx > {
495
503
assert ! (
496
504
!args. has_escaping_bound_vars( ) ,
497
505
"args of instance {def_id:?} has escaping bound vars: {args:?}"
@@ -510,7 +518,7 @@ impl<'tcx> Instance<'tcx> {
510
518
}
511
519
} ) ;
512
520
513
- Instance :: new ( def_id, args)
521
+ Instance :: new_raw ( def_id, args)
514
522
}
515
523
516
524
#[ inline]
@@ -603,7 +611,7 @@ impl<'tcx> Instance<'tcx> {
603
611
let type_length = type_length ( args) ;
604
612
if !tcx. type_length_limit ( ) . value_within_limit ( type_length) {
605
613
let ( shrunk, written_to_path) =
606
- shrunk_instance_name ( tcx, Instance :: new ( def_id, args) ) ;
614
+ shrunk_instance_name ( tcx, Instance :: new_raw ( def_id, args) ) ;
607
615
let mut path = PathBuf :: new ( ) ;
608
616
let was_written = if let Some ( path2) = written_to_path {
609
617
path = path2;
@@ -773,7 +781,7 @@ impl<'tcx> Instance<'tcx> {
773
781
774
782
match needs_fn_once_adapter_shim ( actual_kind, requested_kind) {
775
783
Ok ( true ) => Instance :: fn_once_adapter_instance ( tcx, def_id, args) ,
776
- _ => Instance :: new ( def_id, args) ,
784
+ _ => Instance :: new_raw ( def_id, args) ,
777
785
}
778
786
}
779
787
@@ -899,7 +907,7 @@ impl<'tcx> Instance<'tcx> {
899
907
// This is important for `Iterator`'s combinators, but also useful for
900
908
// adding future default methods to `Future`, for instance.
901
909
debug_assert ! ( tcx. defaultness( trait_item_id) . has_value( ) ) ;
902
- Some ( Instance :: new ( trait_item_id, rcvr_args) )
910
+ Some ( Instance :: new_raw ( trait_item_id, rcvr_args) )
903
911
}
904
912
}
905
913
0 commit comments