-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
243d2ca
commit 57639d3
Showing
4 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use rustc_infer::infer::TyCtxtInferExt as _; | ||
use rustc_middle::ty::{self, TyCtxt, TypingEnv}; | ||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt; | ||
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt}; | ||
|
||
pub(crate) fn check_instance_wf<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::Instance<'tcx>) { | ||
let ty::InstanceKind::Item(def_id) = instance.def else { | ||
// Probably want other instances too...: | ||
return; | ||
}; | ||
|
||
let (infcx, param_env) = | ||
tcx.infer_ctxt().build_with_typing_env(TypingEnv::fully_monomorphized()); | ||
let ocx = ObligationCtxt::new_with_diagnostics(&infcx); | ||
|
||
ocx.register_obligations( | ||
tcx.predicates_of(def_id).instantiate(tcx, instance.args).into_iter().map( | ||
|(clause, span)| { | ||
Obligation::new(tcx, ObligationCause::dummy_with_span(span), param_env, clause) | ||
}, | ||
), | ||
); | ||
|
||
let errors = ocx.select_all_or_error(); | ||
if !errors.is_empty() { | ||
infcx.err_ctxt().report_fulfillment_errors(errors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters