Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b1059cc

Browse files
Instance::resolve -> Instance::try_resolve, and other nits
1 parent 3273cce commit b1059cc

File tree

22 files changed

+44
-27
lines changed

22 files changed

+44
-27
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3733,7 +3733,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
37333733
if tcx.is_diagnostic_item(sym::deref_method, method_did) {
37343734
let deref_target =
37353735
tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
3736-
Instance::resolve(tcx, self.param_env, deref_target, method_args)
3736+
Instance::try_resolve(tcx, self.param_env, deref_target, method_args)
37373737
.transpose()
37383738
});
37393739
if let Some(Ok(instance)) = deref_target {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
948948
return;
949949
}
950950

951-
if let Ok(Some(instance)) = ty::Instance::resolve(
951+
if let Ok(Some(instance)) = ty::Instance::try_resolve(
952952
tcx,
953953
self.param_env,
954954
*fn_did,

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
768768
is_trait = true;
769769

770770
if let Ok(Some(instance)) =
771-
Instance::resolve(tcx, param_env, callee, fn_args)
771+
Instance::try_resolve(tcx, param_env, callee, fn_args)
772772
&& let InstanceKind::Item(def) = instance.def
773773
{
774774
// Resolve a trait method call to its concrete implementation, which may be in a

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
618618
trace!("resolve: {:?}, {:#?}", def, args);
619619
trace!("param_env: {:#?}", self.param_env);
620620
trace!("args: {:#?}", args);
621-
match ty::Instance::resolve(*self.tcx, self.param_env, def, args) {
621+
match ty::Instance::try_resolve(*self.tcx, self.param_env, def, args) {
622622
Ok(Some(instance)) => Ok(instance),
623623
Ok(None) => throw_inval!(TooGeneric),
624624

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
534534
let tcx = self.tcx();
535535

536536
// Find the method being called.
537-
let Ok(Some(instance)) = ty::Instance::resolve(
537+
let Ok(Some(instance)) = ty::Instance::try_resolve(
538538
tcx,
539539
ctxt.param_env,
540540
ctxt.assoc_item.def_id,

compiler/rustc_lint/src/internal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ declare_lint_pass!(QueryStability => [POTENTIAL_QUERY_INSTABILITY]);
8888
impl LateLintPass<'_> for QueryStability {
8989
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
9090
let Some((span, def_id, args)) = typeck_results_of_method_fn(cx, expr) else { return };
91-
if let Ok(Some(instance)) = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, args) {
91+
if let Ok(Some(instance)) = ty::Instance::try_resolve(cx.tcx, cx.param_env, def_id, args) {
9292
let def_id = instance.def_id();
9393
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
9494
cx.emit_span_lint(
@@ -393,7 +393,7 @@ impl LateLintPass<'_> for Diagnostics {
393393
};
394394

395395
// Is the callee marked with `#[rustc_lint_diagnostics]`?
396-
let has_attr = ty::Instance::resolve(cx.tcx, cx.param_env, def_id, fn_gen_args)
396+
let has_attr = ty::Instance::try_resolve(cx.tcx, cx.param_env, def_id, fn_gen_args)
397397
.ok()
398398
.flatten()
399399
.is_some_and(|inst| cx.tcx.has_attr(inst.def_id(), sym::rustc_lint_diagnostics));

compiler/rustc_lint/src/noop_method_call.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
9696
.tcx
9797
.normalize_erasing_regions(cx.param_env, cx.typeck_results().node_args(expr.hir_id));
9898
// Resolve the trait method instance.
99-
let Ok(Some(i)) = ty::Instance::resolve(cx.tcx, cx.param_env, did, args) else { return };
99+
let Ok(Some(i)) = ty::Instance::try_resolve(cx.tcx, cx.param_env, did, args) else {
100+
return;
101+
};
100102
// (Re)check that it implements the noop diagnostic.
101103
let Some(name) = cx.tcx.get_diagnostic_name(i.def_id()) else { return };
102104
if !matches!(

compiler/rustc_middle/src/mir/interpret/queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'tcx> TyCtxt<'tcx> {
7373
bug!("did not expect inference variables here");
7474
}
7575

76-
match ty::Instance::resolve(
76+
match ty::Instance::try_resolve(
7777
self, param_env,
7878
// FIXME: maybe have a separate version for resolving mir::UnevaluatedConst?
7979
ct.def, ct.args,
@@ -106,7 +106,7 @@ impl<'tcx> TyCtxt<'tcx> {
106106
bug!("did not expect inference variables here");
107107
}
108108

109-
match ty::Instance::resolve(self, param_env, ct.def, ct.args) {
109+
match ty::Instance::try_resolve(self, param_env, ct.def, ct.args) {
110110
Ok(Some(instance)) => {
111111
let cid = GlobalId { instance, promoted: None };
112112
self.const_eval_global_id_for_typeck(param_env, cid, span).inspect(|_| {

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ impl<'tcx> Instance<'tcx> {
516516
/// from `Ok(None)` to avoid misleading diagnostics when an error
517517
/// has already been/will be emitted, for the original cause
518518
#[instrument(level = "debug", skip(tcx), ret)]
519-
pub fn resolve(
519+
pub fn try_resolve(
520520
tcx: TyCtxt<'tcx>,
521521
param_env: ty::ParamEnv<'tcx>,
522522
def_id: DefId,
@@ -555,7 +555,7 @@ impl<'tcx> Instance<'tcx> {
555555
let span_or_local_def_span =
556556
|| if span.is_dummy() && def_id.is_local() { tcx.def_span(def_id) } else { span };
557557

558-
match ty::Instance::resolve(tcx, param_env, def_id, args) {
558+
match ty::Instance::try_resolve(tcx, param_env, def_id, args) {
559559
Ok(Some(instance)) => instance,
560560
Ok(None) => {
561561
let type_length = type_length(args);
@@ -605,7 +605,7 @@ impl<'tcx> Instance<'tcx> {
605605
// Use either `resolve_closure` or `resolve_for_vtable`
606606
assert!(!tcx.is_closure_like(def_id), "Called `resolve_for_fn_ptr` on closure: {def_id:?}");
607607
let reason = tcx.sess.is_sanitizer_kcfi_enabled().then_some(ReifyReason::FnPtr);
608-
Instance::resolve(tcx, param_env, def_id, args).ok().flatten().map(|mut resolved| {
608+
Instance::try_resolve(tcx, param_env, def_id, args).ok().flatten().map(|mut resolved| {
609609
match resolved.def {
610610
InstanceKind::Item(def) if resolved.def.requires_caller_location(tcx) => {
611611
debug!(" => fn pointer created for function with #[track_caller]");
@@ -738,13 +738,25 @@ impl<'tcx> Instance<'tcx> {
738738
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
739739
let def_id = tcx.require_lang_item(LangItem::DropInPlace, None);
740740
let args = tcx.mk_args(&[ty.into()]);
741-
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, DUMMY_SP)
741+
Instance::expect_resolve(
742+
tcx,
743+
ty::ParamEnv::reveal_all(),
744+
def_id,
745+
args,
746+
ty.ty_adt_def().and_then(|adt| tcx.hir().span_if_local(adt.did())).unwrap_or(DUMMY_SP),
747+
)
742748
}
743749

744750
pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
745751
let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, None);
746752
let args = tcx.mk_args(&[ty.into()]);
747-
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, DUMMY_SP)
753+
Instance::expect_resolve(
754+
tcx,
755+
ty::ParamEnv::reveal_all(),
756+
def_id,
757+
args,
758+
ty.ty_adt_def().and_then(|adt| tcx.hir().span_if_local(adt.did())).unwrap_or(DUMMY_SP),
759+
)
748760
}
749761

750762
#[instrument(level = "debug", skip(tcx), ret)]

compiler/rustc_middle/src/util/call_kind.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn call_kind<'tcx>(
9898
Some(CallKind::Operator { self_arg, trait_id, self_ty: method_args.type_at(0) })
9999
} else if is_deref {
100100
let deref_target = tcx.get_diagnostic_item(sym::deref_target).and_then(|deref_target| {
101-
Instance::resolve(tcx, param_env, deref_target, method_args).transpose()
101+
Instance::try_resolve(tcx, param_env, deref_target, method_args).transpose()
102102
});
103103
if let Some(Ok(instance)) = deref_target {
104104
let deref_target_ty = instance.ty(tcx, param_env);

0 commit comments

Comments
 (0)