-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fix feature = "nightly"
in the new trait solver
#126649
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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 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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
//! traits, `Copy`/`Clone`. | ||
|
||
use rustc_ast_ir::{Movability, Mutability}; | ||
use rustc_data_structures::fx::FxHashMap; | ||
use rustc_type_ir::data_structures::HashMap; | ||
use rustc_type_ir::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; | ||
use rustc_type_ir::inherent::*; | ||
use rustc_type_ir::lang_items::TraitSolverLangItem; | ||
|
@@ -304,9 +304,10 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern | |
let kind_ty = args.kind_ty(); | ||
let sig = args.coroutine_closure_sig().skip_binder(); | ||
|
||
let coroutine_ty = if let Some(closure_kind) = kind_ty.to_opt_closure_kind() | ||
&& !args.tupled_upvars_ty().is_ty_var() | ||
{ | ||
// FIXME: let_chains | ||
let kind = kind_ty.to_opt_closure_kind(); | ||
let coroutine_ty = if kind.is_some() && !args.tupled_upvars_ty().is_ty_var() { | ||
let closure_kind = kind.unwrap(); | ||
if !closure_kind.extends(goal_kind) { | ||
return Err(NoSolution); | ||
} | ||
|
@@ -411,10 +412,11 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I: | |
let kind_ty = args.kind_ty(); | ||
let sig = args.coroutine_closure_sig().skip_binder(); | ||
let mut nested = vec![]; | ||
let coroutine_ty = if let Some(closure_kind) = kind_ty.to_opt_closure_kind() | ||
&& !args.tupled_upvars_ty().is_ty_var() | ||
{ | ||
if !closure_kind.extends(goal_kind) { | ||
|
||
// FIXME: let_chains | ||
let kind = kind_ty.to_opt_closure_kind(); | ||
let coroutine_ty = if kind.is_some() && !args.tupled_upvars_ty().is_ty_var() { | ||
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. same here |
||
if !kind.unwrap().extends(goal_kind) { | ||
return Err(NoSolution); | ||
} | ||
|
||
|
@@ -683,7 +685,7 @@ where | |
); | ||
} | ||
|
||
let mut replace_projection_with = FxHashMap::default(); | ||
let mut replace_projection_with = HashMap::default(); | ||
for bound in object_bounds { | ||
if let ty::ExistentialPredicate::Projection(proj) = bound.skip_binder() { | ||
let proj = proj.with_self_ty(tcx, trait_ref.self_ty()); | ||
|
@@ -713,7 +715,7 @@ where | |
struct ReplaceProjectionWith<'a, Infcx: SolverDelegate<Interner = I>, I: Interner> { | ||
ecx: &'a EvalCtxt<'a, Infcx>, | ||
param_env: I::ParamEnv, | ||
mapping: FxHashMap<I::DefId, ty::Binder<I, ty::ProjectionPredicate<I>>>, | ||
mapping: HashMap<I::DefId, ty::Binder<I, ty::ProjectionPredicate<I>>>, | ||
nested: Vec<Goal<I, I::Predicate>>, | ||
} | ||
|
||
|
@@ -725,24 +727,28 @@ impl<Infcx: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> | |
} | ||
|
||
fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { | ||
if let ty::Alias(ty::Projection, alias_ty) = ty.kind() | ||
&& let Some(replacement) = self.mapping.get(&alias_ty.def_id) | ||
{ | ||
// We may have a case where our object type's projection bound is higher-ranked, | ||
// but the where clauses we instantiated are not. We can solve this by instantiating | ||
// the binder at the usage site. | ||
let proj = self.ecx.instantiate_binder_with_infer(*replacement); | ||
// FIXME: Technically this equate could be fallible... | ||
self.nested.extend( | ||
self.ecx | ||
.eq_and_get_goals( | ||
self.param_env, | ||
alias_ty, | ||
proj.projection_term.expect_ty(self.ecx.interner()), | ||
) | ||
.expect("expected to be able to unify goal projection with dyn's projection"), | ||
); | ||
proj.term.expect_ty() | ||
if let ty::Alias(ty::Projection, alias_ty) = ty.kind() { | ||
if let Some(replacement) = self.mapping.get(&alias_ty.def_id) { | ||
// We may have a case where our object type's projection bound is higher-ranked, | ||
// but the where clauses we instantiated are not. We can solve this by instantiating | ||
// the binder at the usage site. | ||
let proj = self.ecx.instantiate_binder_with_infer(*replacement); | ||
// FIXME: Technically this equate could be fallible... | ||
self.nested.extend( | ||
self.ecx | ||
.eq_and_get_goals( | ||
self.param_env, | ||
alias_ty, | ||
proj.projection_term.expect_ty(self.ecx.interner()), | ||
) | ||
.expect( | ||
"expected to be able to unify goal projection with dyn's projection", | ||
), | ||
); | ||
proj.term.expect_ty() | ||
} else { | ||
ty.super_fold_with(self) | ||
} | ||
} else { | ||
ty.super_fold_with(self) | ||
} | ||
|
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
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,29 @@ | ||
#[cfg(feature = "nightly")] | ||
mod impl_ { | ||
pub use rustc_data_structures::fx::FxHashMap as HashMap; | ||
pub use rustc_data_structures::fx::FxHashSet as HashSet; | ||
pub use rustc_data_structures::fx::FxIndexMap as IndexMap; | ||
pub use rustc_data_structures::fx::FxIndexSet as IndexSet; | ||
pub use rustc_data_structures::sso::SsoHashMap; | ||
pub use rustc_data_structures::sso::SsoHashSet; | ||
pub use rustc_data_structures::stack::ensure_sufficient_stack; | ||
pub use rustc_data_structures::sync::Lrc; | ||
} | ||
|
||
#[cfg(not(feature = "nightly"))] | ||
mod impl_ { | ||
pub use indexmap::IndexMap; | ||
pub use indexmap::IndexSet; | ||
pub use std::collections::HashMap; | ||
pub use std::collections::HashMap as SsoHashMap; | ||
pub use std::collections::HashSet; | ||
pub use std::collections::HashSet as SsoHashSet; | ||
pub use std::sync::Arc as Lrc; | ||
|
||
#[inline] | ||
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R { | ||
f() | ||
} | ||
} | ||
|
||
pub use impl_::*; |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this is so much harder to read. I'd really rather unwrap, or restructure the whole block to just be nested
if
s.