Open haslersn opened 1 year ago
@rustbot label +E-needs-mcve
Also you could try to see if this repros on the latest stable 1.65. If possible you can also try the latest nightly 1.67.
Possibly the same bug or a closely related one can be triggered with the following MCVE on both current stable and nightly. If this is a different bug, I can open a new issue or comment on another issue.
pub trait Foo: Clone {}
pub struct Bar<'a, T: Clone> {
pub cow: std::borrow::Cow<'a, [T]>,
pub THIS_CAUSES_ICE: (), // #1
}
impl<T> Bar<'_, T>
where
T: Clone,
[T]: Foo,
{
pub fn MOVES_SELF(self) {} // #2
}
results in
error: internal compiler error: unexpected ambiguity: Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [Binder(TraitPredicate(<[T] as Foo>, polarity:Positive), []), Binder(TraitPredicate(<[T] as std::clone::Clone>, polarity:Positive), []), Binder(TraitPredicate(<[T] as std::marker::Sized>, polarity:Positive), []), Binder(TraitPredicate(<T as std::clone::Clone>, polarity:Positive), []), Binder(TraitPredicate(<T as std::marker::Sized>, polarity:Positive), [])], reveal: UserFacing, constness: NotConst }, value: ProjectionTy { substs: [[T]], item_def_id: DefId(5:859 ~ alloc[d987]::borrow::ToOwned::Owned) } } } Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Ty(General(U0)) }], value: QueryResponse { var_values: CanonicalVarValues { var_values: [] }, region_constraints: QueryRegionConstraints { outlives: [], member_constraints: [] }, certainty: Ambiguous, opaque_types: [], value: NormalizationResult { normalized_ty: ^0 } } }
The critical lines are marked as #1
and #2
; commenting out #1
prevents the ICE and gives the following error which is presumably caused by the compiler not being able to prove that Cow<'_, [T]>
is Sized
(presumably caused by missing ToOwned
bound?) Removing line #2
, or changing it to borrow self
makes the code compile, as expected.
Seems this is related to the fact that a DST can be the last field, but only the last field, of a struct. Moving #1
one line up also makes the ICE go away.
error[[E0284]](https://doc.rust-lang.org/stable/error-index.html#E0284): type annotations needed
--> src/lib.rs:17:23
|
17 | pub fn MOVES_SELF(self) {}
| ^^^^ cannot infer type
|
= note: cannot satisfy `<[T] as ToOwned>::Owned == _`
note: required because it appears within the type `Bar<'_, T>`
--> src/lib.rs:3:12
|
3 | pub struct Bar<'a, T>
| ^^^
help: function arguments must have a statically known size, borrowed types always have a known size
|
17 | pub fn MOVES_SELF(&self) {}
| +
@rustbot label -E-needs-mcve
Today I encountered a compiler panic with rustc 1.64.0.
Code
Unfortunately I cannot provide the code at this point, as it's not released, yet. The project makes heavy use of (const) generics. There were some errors in the code which probably lead to the compiler panic. After fixing some errors, the panic went away, too.
Meta
rustc --version --verbose
:Error output
Backtrace
```
```