mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 17:24:06 +00:00
Rollup merge of #92917 - jackh726:issue-91762-2, r=nikomatsakis
Don't constrain projection predicates with inference vars in GAT substs cc #91762 Not a fix, but a mitigation to prevent a backwards-compatible hazard where we normalize using a predicate only because it's the only one available, but shouldn't. This would constrain an inference variable which didn't really want. We already do this when selecting a projection candidate, which isn't always correct. But changing that is a problem for a different day. Also found out that a suggestion for `await`ing a future was using the wrong substs. r? ``@nikomatsakis``
This commit is contained in:
commit
a11e2b1f75
@ -2473,7 +2473,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
// `T`
|
// `T`
|
||||||
substs: self.tcx.mk_substs_trait(
|
substs: self.tcx.mk_substs_trait(
|
||||||
trait_pred.self_ty().skip_binder(),
|
trait_pred.self_ty().skip_binder(),
|
||||||
self.fresh_substs_for_item(span, item_def_id),
|
&self.fresh_substs_for_item(span, item_def_id)[1..],
|
||||||
),
|
),
|
||||||
// `Future::Output`
|
// `Future::Output`
|
||||||
item_def_id,
|
item_def_id,
|
||||||
|
@ -1073,6 +1073,16 @@ fn project<'cx, 'tcx>(
|
|||||||
return Ok(Projected::Progress(Progress::error(selcx.tcx())));
|
return Ok(Projected::Progress(Progress::error(selcx.tcx())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the obligation contains any inference types or consts in associated
|
||||||
|
// type substs, then we don't assemble any candidates.
|
||||||
|
// This isn't really correct, but otherwise we can end up in a case where
|
||||||
|
// we constrain inference variables by selecting a single predicate, when
|
||||||
|
// we need to stay general. See issue #91762.
|
||||||
|
let (_, predicate_own_substs) = obligation.predicate.trait_ref_and_own_substs(selcx.tcx());
|
||||||
|
if predicate_own_substs.iter().any(|g| g.has_infer_types_or_consts()) {
|
||||||
|
return Err(ProjectionError::TooManyCandidates);
|
||||||
|
}
|
||||||
|
|
||||||
let mut candidates = ProjectionCandidateSet::None;
|
let mut candidates = ProjectionCandidateSet::None;
|
||||||
|
|
||||||
// Make sure that the following procedures are kept in order. ParamEnv
|
// Make sure that the following procedures are kept in order. ParamEnv
|
||||||
|
@ -17,6 +17,7 @@ impl<T> UnsafeCopy for T {}
|
|||||||
fn main() {
|
fn main() {
|
||||||
let b = Box::new(42usize);
|
let b = Box::new(42usize);
|
||||||
let copy = <()>::copy(&b);
|
let copy = <()>::copy(&b);
|
||||||
|
//~^ type annotations needed
|
||||||
|
|
||||||
let raw_b = Box::deref(&b) as *const _;
|
let raw_b = Box::deref(&b) as *const _;
|
||||||
let raw_copy = Box::deref(©) as *const _;
|
let raw_copy = Box::deref(©) as *const _;
|
||||||
|
@ -27,6 +27,13 @@ help: consider restricting type parameter `T`
|
|||||||
LL | type Copy<T: std::clone::Clone>: Copy = Box<T>;
|
LL | type Copy<T: std::clone::Clone>: Copy = Box<T>;
|
||||||
| +++++++++++++++++++
|
| +++++++++++++++++++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error[E0282]: type annotations needed
|
||||||
|
--> $DIR/issue-74824.rs:19:16
|
||||||
|
|
|
||||||
|
LL | let copy = <()>::copy(&b);
|
||||||
|
| ^^^^^^^^^^ cannot infer type for type parameter `T` declared on the associated function `copy`
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0277`.
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0277, E0282.
|
||||||
|
For more information about an error, try `rustc --explain E0277`.
|
||||||
|
30
src/test/ui/generic-associated-types/issue-91762.rs
Normal file
30
src/test/ui/generic-associated-types/issue-91762.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// check-fail
|
||||||
|
|
||||||
|
// FIXME(generic_associated_types): We almost certaintly want this to pass, but
|
||||||
|
// it's particularly difficult currently, because we need a way of specifying
|
||||||
|
// that `<Self::Base as Functor>::With<T> = Self` without using that when we have
|
||||||
|
// a `U`. See `https://github.com/rust-lang/rust/pull/92728` for a (hacky)
|
||||||
|
// solution. This might be better to just wait for Chalk.
|
||||||
|
|
||||||
|
#![feature(generic_associated_types)]
|
||||||
|
|
||||||
|
pub trait Functor {
|
||||||
|
type With<T>;
|
||||||
|
|
||||||
|
fn fmap<T, U>(this: Self::With<T>) -> Self::With<U>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait FunctorExt<T>: Sized {
|
||||||
|
type Base: Functor<With<T> = Self>;
|
||||||
|
|
||||||
|
fn fmap<U>(self) {
|
||||||
|
let arg: <Self::Base as Functor>::With<T>;
|
||||||
|
let ret: <Self::Base as Functor>::With<U>;
|
||||||
|
|
||||||
|
arg = self;
|
||||||
|
ret = <Self::Base as Functor>::fmap(arg);
|
||||||
|
//~^ type annotations needed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
9
src/test/ui/generic-associated-types/issue-91762.stderr
Normal file
9
src/test/ui/generic-associated-types/issue-91762.stderr
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
error[E0282]: type annotations needed
|
||||||
|
--> $DIR/issue-91762.rs:25:15
|
||||||
|
|
|
||||||
|
LL | ret = <Self::Base as Functor>::fmap(arg);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the associated function `fmap`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0282`.
|
Loading…
Reference in New Issue
Block a user