Skip to content
This repository was archived by the owner on May 23, 2024. It is now read-only.

ices/54108.rs: fixed with errors #489

Merged
merged 1 commit into from
Oct 7, 2020
Merged

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Oct 7, 2020

Issue: rust-lang/rust#54108

use std::ops::Add;

pub trait Encoder {
	type Size: Add<Output = Self::Size>;

	fn foo(&self) -> Self::Size;
}

pub trait SubEncoder : Encoder {
	type ActualSize;

	fn bar(&self) -> Self::Size;
}

impl<T> Encoder for T where T: SubEncoder {
	type Size = <Self as SubEncoder>::ActualSize;

	fn foo(&self) -> Self::Size {
		self.bar() + self.bar()
	}
}

pub struct UnitEncoder;

impl SubEncoder for UnitEncoder {
	type ActualSize = ();

	fn bar(&self) {}
}


fn main() {
	fun(&UnitEncoder {});
}

pub fn fun<R: Encoder>(encoder: &R) {
	encoder.foo();
}
=== stdout ===
=== stderr ===
error[E0277]: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
  --> /home/runner/work/glacier/glacier/ices/54108.rs:16:2
   |
4  |     type Size: Add<Output = Self::Size>;
   |                ------------------------ required by this bound in `Encoder::Size`
...
16 |     type Size = <Self as SubEncoder>::ActualSize;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `<T as SubEncoder>::ActualSize + <T as SubEncoder>::ActualSize`
   |
   = help: the trait `Add` is not implemented for `<T as SubEncoder>::ActualSize`
help: consider further restricting the associated type
   |
15 | impl<T> Encoder for T where T: SubEncoder, <T as SubEncoder>::ActualSize: Add {
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
==============

=== stdout ===
=== stderr ===
error[E0277]: cannot add `<T as SubEncoder>::ActualSize` to `<T as SubEncoder>::ActualSize`
  --> /home/runner/work/glacier/glacier/ices/54108.rs:16:2
   |
4  |     type Size: Add<Output = Self::Size>;
   |                ------------------------ required by this bound in `Encoder::Size`
...
16 |     type Size = <Self as SubEncoder>::ActualSize;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `<T as SubEncoder>::ActualSize + <T as SubEncoder>::ActualSize`
   |
   = help: the trait `Add` is not implemented for `<T as SubEncoder>::ActualSize`
help: consider further restricting the associated type
   |
15 | impl<T> Encoder for T where T: SubEncoder, <T as SubEncoder>::ActualSize: Add {
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
==============
@JohnTitor JohnTitor merged commit 37972fb into master Oct 7, 2020
@JohnTitor JohnTitor deleted the autofix/ices/54108.rs branch October 7, 2020 12:53
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants