-
Notifications
You must be signed in to change notification settings - Fork 13.4k
selection failure: recompute applicable impls #103252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -38,7 +38,7 @@ impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> { | |
|
||
fn new_in_snapshot(tcx: TyCtxt<'tcx>) -> Box<Self> { | ||
if tcx.sess.opts.unstable_opts.chalk { | ||
Box::new(ChalkFulfillmentContext::new()) | ||
Box::new(ChalkFulfillmentContext::new_in_snapshot()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed for the changes here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, because |
||
} else { | ||
Box::new(FulfillmentContext::new_in_snapshot()) | ||
} | ||
|
@@ -119,13 +119,10 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> { | |
expected: T, | ||
actual: T, | ||
) -> Result<(), TypeError<'tcx>> { | ||
match self.infcx.at(cause, param_env).eq(expected, actual) { | ||
Ok(InferOk { obligations, value: () }) => { | ||
self.register_obligations(obligations); | ||
Ok(()) | ||
} | ||
Err(e) => Err(e), | ||
} | ||
self.infcx | ||
.at(cause, param_env) | ||
.eq(expected, actual) | ||
.map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) | ||
} | ||
|
||
pub fn sup<T: ToTrace<'tcx>>( | ||
|
@@ -144,6 +141,10 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> { | |
} | ||
} | ||
|
||
pub fn select_where_possible(&self) -> Vec<FulfillmentError<'tcx>> { | ||
self.engine.borrow_mut().select_where_possible(self.infcx) | ||
} | ||
|
||
pub fn select_all_or_error(&self) -> Vec<FulfillmentError<'tcx>> { | ||
self.engine.borrow_mut().select_all_or_error(self.infcx) | ||
} | ||
|
52 changes: 52 additions & 0 deletions
52
compiler/rustc_trait_selection/src/traits/error_reporting/ambiguity.rs
This file contains hidden or 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,52 @@ | ||
use rustc_hir::def_id::DefId; | ||
use rustc_infer::infer::InferCtxt; | ||
use rustc_infer::traits::{Obligation, ObligationCause, TraitObligation}; | ||
use rustc_span::DUMMY_SP; | ||
|
||
use crate::traits::ObligationCtxt; | ||
|
||
pub fn recompute_applicable_impls<'tcx>( | ||
infcx: &InferCtxt<'tcx>, | ||
obligation: &TraitObligation<'tcx>, | ||
) -> Vec<DefId> { | ||
let tcx = infcx.tcx; | ||
let param_env = obligation.param_env; | ||
let dummy_cause = ObligationCause::dummy(); | ||
let impl_may_apply = |impl_def_id| { | ||
let ocx = ObligationCtxt::new_in_snapshot(infcx); | ||
let placeholder_obligation = | ||
infcx.replace_bound_vars_with_placeholders(obligation.predicate); | ||
let obligation_trait_ref = | ||
ocx.normalize(dummy_cause.clone(), param_env, placeholder_obligation.trait_ref); | ||
|
||
let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id); | ||
let impl_trait_ref = tcx.bound_impl_trait_ref(impl_def_id).unwrap().subst(tcx, impl_substs); | ||
let impl_trait_ref = ocx.normalize(ObligationCause::dummy(), param_env, impl_trait_ref); | ||
|
||
if let Err(_) = ocx.eq(&dummy_cause, param_env, obligation_trait_ref, impl_trait_ref) { | ||
return false; | ||
} | ||
|
||
let impl_predicates = tcx.predicates_of(impl_def_id).instantiate(tcx, impl_substs); | ||
ocx.register_obligations( | ||
impl_predicates | ||
.predicates | ||
.iter() | ||
.map(|&predicate| Obligation::new(dummy_cause.clone(), param_env, predicate)), | ||
); | ||
|
||
ocx.select_where_possible().is_empty() | ||
}; | ||
|
||
let mut impls = Vec::new(); | ||
tcx.for_each_relevant_impl( | ||
obligation.predicate.def_id(), | ||
obligation.predicate.skip_binder().trait_ref.self_ty(), | ||
|impl_def_id| { | ||
if infcx.probe(move |_snapshot| impl_may_apply(impl_def_id)) { | ||
impls.push(impl_def_id) | ||
} | ||
}, | ||
); | ||
impls | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
fn main() { | ||
let x = "hello".chars().rev().collect(); //~ ERROR E0282 | ||
let x = "hello".chars().rev().collect(); | ||
//~^ ERROR E0282 | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
fn main() { | ||
let x = |a: (), b: ()| { | ||
Err(a)?; | ||
Ok(b) //~ ERROR type annotations needed | ||
Ok(b) | ||
//~^ ERROR type annotations needed | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.