Skip to content

Beta regression error "trait ... is not implemented for usize" #56020

@ketotek

Description

@ketotek

Hello,

I have hit this strange error after updating the nightly(and beta) compiler. I tried the code below, this is a minimized version from a larger code base. Here is it on playground.

trait MyIterator {	type Item; } trait ObjectTrait {	fn size(&self) -> u32; } trait ObjectCollectionTrait<'a> {	type ItemType: 'a + ObjectTrait;	type Iter: MyIterator<Item = &'a Self::ItemType>; } impl ObjectTrait for u32 {	fn size(&self) -> u32 {	0	} } struct ObjectCollection<'a> {	collection: &'a ObjectCollectionTrait<'a, ItemType = u32, Iter = MyIterator<Item = &'a u32>> } fn main() {} 

I am getting this error and I don't know how usize is involved here.

error[E0277]: the trait bound `usize: ObjectCollectionTrait<'a>` is not satisfied --> src/main.rs:21:1 | 21 | / struct ObjectCollection<'a> { 22 | | collection: &'a ObjectCollectionTrait<'a, ItemType = u32, Iter = MyIterator<Item = &'a u32>> 23 | | } |_^ the trait `ObjectCollectionTrait<'a>` is not implemented for `usize` error[E0277]: the trait bound `usize: ObjectCollectionTrait<'a>` is not satisfied --> src/main.rs:25:10 | 25 | impl<'a> ObjectCollection<'a> { | ^^^^^^^^^^^^^^^^^^^^ the trait `ObjectCollectionTrait<'a>` is not implemented for `usize` 

After bisecting for a while, I discovered the error appears starting with this version of nightly:

$ rustc --version --verbose rustc 1.30.0-nightly (f2302daef 2018-09-12) binary: rustc commit-hash: f2302daef3608c09e2b50193a64611b18ced86f3 commit-date: 2018-09-12 host: x86_64-unknown-linux-gnu release: 1.30.0-nightly LLVM version: 8.0 

The build from the day before doesn't show this error (and stable is also fine):

$ rustc --version --verbose rustc 1.30.0-nightly (2f1547c0a 2018-09-11) binary: rustc commit-hash: 2f1547c0aa5957b42cc768c00119c6eb7b4262d3 commit-date: 2018-09-11 host: x86_64-unknown-linux-gnu release: 1.30.0-nightly LLVM version: 8.0 

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions