Skip to content
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

[RFC] Clarify (and improve) rules for projections and well-formedness #1214

Merged
merged 10 commits into from Aug 7, 2015

Conversation

Projects
None yet
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jul 17, 2015

RFC has been accepted and merged.

Current text: https://github.com/rust-lang/rfcs/blob/master/text/1214-projections-lifetimes-and-wf.md
Tracking issue: rust-lang/rust#27579


Type system changes to address the outlives relation with respect to projections, and to better enforce that all types are well-formed (meaning that they respect their declared bounds). The current implementation can be both unsound (rust-lang/rust#24622), inconvenient (rust-lang/rust#23442), and surprising (rust-lang/rust#21748, rust-lang/rust#25692). The changes are as follows:

  • Simplify the outlives relation to be syntactically based.
  • Specify improved rules for the outlives relation and projections.
  • Specify more specifically where WF bounds are enforced, covering several cases missing from the implementation.

The proposed changes here have been tested and found to cause only a modest number of regressions (about two dozen root regressions were previously found on crates.io; however, that run did not yet include all the provisions from this RFC; updated numbers coming soon). In order to minimize the impact on users, the plan is to first introduce the changes in two stages:

  1. Initially, warnings will be issued for cases that violate the rules specified in this RFC. These warnings are not lints and cannot be silenced except by correcting the code such that it type-checks under the new rules.
  2. After one release cycle, those warnings will become errors.

Note that although the changes do cause regressions, they also cause some code (like that in rust-lang/rust#23442) which currently gets errors to compile successfully.

cc @rust-lang/lang

Rendered

@nikomatsakis nikomatsakis added the T-lang label Jul 17, 2015

@nikomatsakis nikomatsakis self-assigned this Jul 17, 2015

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

nikomatsakis commented Jul 17, 2015

@Ryman

This comment has been minimized.

Copy link

Ryman commented Jul 17, 2015

@nikomatsakis I think the issue referenced for 'unsound' in your description should be rust-lang/rust#24622 which is mentioned in the RFC (also labelled wrong).

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

nikomatsakis commented Jul 17, 2015

@Ryman thanks.

R ⊢ scalar: 'a

OutlivesNominalType:
∀i. Pi: 'a

This comment has been minimized.

@Diggsey

Diggsey Jul 18, 2015

Contributor

Should this be ∀i. R ⊢ Pi: 'a?

R ⊢ 'x: 'a
R ⊢ T: 'a
--------------------------------------------------
R ⊢ &'x T: 'a

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

It seems like T: 'a is redundant, since &'x T is WF only if T: 'x, no?

So T: 'x and 'x: 'a -> T: 'a by transitivity?

Maybe I'm missing a corner case.

This comment has been minimized.

@nikomatsakis

nikomatsakis Aug 7, 2015

Author Contributor

@Gankro

Sorry, I'm not sure if I ever answered this.

It seems like T: 'a is redundant, since &'x T is WF only if T: 'x, no?

This seems true, if harmless.

∀i. R ⊢ Oi: 'a
R ⊢ 'x: 'a
--------------------------------------------------
R ⊢ O0..On+'x: 'a

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

Similar as above

This comment has been minimized.

@arielb1

arielb1 Jul 18, 2015

Contributor

Shouldn't this be ∀i R, i: 'a ⊢ Oi: 'a (otherwise for<'α> Fn(&'α ()) : 'a would be false).

This comment has been minimized.

@nikomatsakis

nikomatsakis Aug 7, 2015

Author Contributor

@arielb1

Shouldn't this be ∀i R, i: 'a ⊢ Oi: 'a (otherwise for<'α> Fn(&'α ()) : 'a would be false).

No, because the binder is within the Oi.

question was bound within a type or not. In the usual case, we decide
the relationship between two lifetimes by consulting the environment.
Lifetimes representing scopes within the current fn have a
relationship derived from the code itself, lifetime parameters have

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

maybe add a "while" after the comma. Took me a second to parse this correctly.


OutlivesScalar:
--------------------------------------------------
R ⊢ scalar: 'a

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

Note for those of us without a very strong type theory background:

⊢ == "proves"

So this is just saying that any set of bounds proves that a scalar outlives 'a, for any given 'a (Plain Old Data has no external lifetime constraints, so it lives for any lifetime).

(I think)

This comment has been minimized.

@arielb1

arielb1 Jul 18, 2015

Contributor

Not exactly "proves". this is a sequent-style deduction rule, read "(implicitly) for every environment R, scalar s and lifetime 'a, s outlives 'a given R"

'x not in R
('x: 'a) in Env
--------------------------------------------------
R ⊢ 'x: 'a

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

Env being "the union of all in scope where clauses and implied bounds"? Unclear.

Also unclear what the significance of 'x not in R is? Are saying that R can only use facts from the environment to prove bounds for otherwise unbound lifetimes?


'x in R
--------------------------------------------------
R ⊢ 'x: 'a

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

Are these supposed to be the same 'a and 'x from the proceeding paragraph?

Projections have the most possibilities. First, we may find
information in the environment, as with type parameters, but we can
also consult the trait definition to find bounds (consider an
associated type declared like `type Foo: 'static`). These rule only

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

It's seems interesting that trait definitions are not considered part of the environment when talking about a type that implements that trait.

reduce `<PROJ>: 'x` to `&'a T: 'x`, which in turn holds if `'a: 'x`
and `T: 'x` (from the rule `OutlivesReference`).

But often we are in a situation where we can't normalize the

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

An example would be great. Is it simply any time you're working with a generic I: Iterator?

This comment has been minimized.

@nikomatsakis

nikomatsakis Aug 7, 2015

Author Contributor

@Gankro

An example would be great. Is it simply any time you're working with a generic I: Iterator?

I added an example, but yes that's roughly right (and other analogous cases, of course).

know this is true without ever knowing what `<TYPE>` is -- we just
need to see that the trait reference `<Foo as Iterator>` doesn't have
any lifetimes or type parameters in it, and hence the impl cannot
refer to any lifetime or type parameters.

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

More generally:

Something can only fail to outlive 'x if its type refers to (non-'static) lifetime that doesn't outlive 'x, and the only lifetimes it can possibly refer to have to be declared in the impl declaration. So it's sufficient (though perhaps not always necessary?) to make sure everything referred to in the impl declaration outlives 'x.

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 20, 2015

Author Contributor

@Gankro

Something can only fail to outlive 'x if its type refers to (non-'static) lifetime that doesn't outlive 'x, and the only lifetimes it can possibly refer to have to be declared in the impl declaration. So it's sufficient (though perhaps not always necessary?) to make sure everything referred to in the impl declaration outlives 'x.

Yes, with a bit of subtlety -- we have to be sure that it not only appears in the impl declaration, but does not appear as part of a projection (as specified below). But this rule already exists.

In other words:

impl<'a> Trait for <i32 as SomeTrait<'a>>::Bar { ... }

wouldn't be good enough for 'a because maybe <i32 as SomeTrait<'a>>::Bar normalized to u32 (and 'a doesn't appear in u32).

This comment has been minimized.

@Gankro

Gankro Jul 20, 2015

Contributor

Is that a problem though? We're trying to reason that it outlives 'a, and u32 is 'static.

This complication is unfortunate, but to a large extent already exists
with where-clauses and trait matching (see e.g. [#21974]). (Moreover,
it seems to be inherent to the concept of assocated types, since they
take several inputs (the parameters to the trait) which may or may not

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

yesss nested asides


WfParameter:
--------------------------------------------------
R ⊢ X WF

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

X is a type parameter, I gather?


WfProjection:
∀i. R ⊢ Pi WF // all components well-formed
R ⊢ <P0 as Trait<P1..Pn>> // the projection itself is valid

This comment has been minimized.

@Gankro

Gankro Jul 18, 2015

Contributor

Should this be P0: Trait<P1..Pn>?

This comment has been minimized.

@nikomatsakis

nikomatsakis Jul 20, 2015

Author Contributor

@Gankro

Should this be P0: Trait<P1..Pn>?

Yeah, I guess. I alternate between those notations somewhat interchangeably. :)

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 18, 2015

I think the [[T]] issue is a straight bug in rustc and shouldn't result in just a warning.

R ⊢ T WF
R ⊢ T: Sized
--------------------------------------------------
[T] WF

This comment has been minimized.

@arielb1

arielb1 Jul 18, 2015

Contributor

There should also be a WfTuple - in fact in the form you use there should be a Wf rule for each type constructor.

This comment has been minimized.

@nikomatsakis

nikomatsakis Aug 7, 2015

Author Contributor

@arielb1

There should also be a WfTuple - in fact in the form you use there should be a Wf rule for each type constructor.

Added.

WfFn:
∀i. R, r.. ⊢ Ti
--------------------------------------------------
R ⊢ for<r..> fn(T1..Tn) -> T0

This comment has been minimized.

@arielb1

arielb1 Jul 18, 2015

Contributor

missing WF - should be

∀i. R, r.. ⊢ Ti WF
--------------------------------------------------
R ⊢ for<r..> fn(T1..Tn) -> T0 WF

and a trait object like `Foo+'x`, when we require that `'static: 'x`
(which is true, clearly, but in some cases the implicit bounds from
traits are not `'static` but rather some named lifetime).

This comment has been minimized.

@arielb1

arielb1 Jul 18, 2015

Contributor

Is there a case where this is relevant? What's an object type vs. object fragment?

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

nikomatsakis commented Jul 20, 2015

@arielb1

I think the [[T]] issue is a straight bug in rustc and shouldn't result in just a warning.

Perhaps, but the issue is really not whether it's a bug or not, the question is about whether code is affected by the change. That said, I haven't observed any.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 20, 2015

@nikomatsakis

[[T]] basically causes an ICE every time it is used, so it is relatively hard to abuse.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 21, 2015

Could you also clarify which of Box<Foo<'a>+'static>, Box<Foo<'static>+'a> and Box<Foo<'a>+'b> are well-formed (assuming 'a and `'b' are unrelated free regions)? AFAICT the rules say that only the second of these is valid, but an example would always be helpful.

crumblingstatue added a commit to crumblingstatue/rust-sdl2_image that referenced this pull request Aug 24, 2015

Put Sized bound on LoadSurface trait
This fixes a warning on nightly Rust (which will later become a hard error).

See rust-lang/rfcs#1214.

frewsxcv added a commit to frewsxcv/rust-block that referenced this pull request Sep 2, 2015

Fix nightly warnings related to lifetimes
The following warnings appear:

```
src/lib.rs:73:5: 73:68 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:73     unsafe fn call_block<R>(self, block: *mut Block<Self, R>) -> R;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:73:5: 73:68 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:73:5: 73:68 note: `Self` does not have a constant size known at compile-time
src/lib.rs:73     unsafe fn call_block<R>(self, block: *mut Block<Self, R>) -> R;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:73:5: 73:68 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:73     unsafe fn call_block<R>(self, block: *mut Block<Self, R>) -> R;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:73:5: 73:68 note: required by `Block`
src/lib.rs:73     unsafe fn call_block<R>(self, block: *mut Block<Self, R>) -> R;
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:187:5: 187:71 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:187     fn into_concrete_block(self) -> ConcreteBlock<A, Self::Ret, Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:187:5: 187:71 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:187:5: 187:71 note: `Self` does not have a constant size known at compile-time
src/lib.rs:187     fn into_concrete_block(self) -> ConcreteBlock<A, Self::Ret, Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:187:5: 187:71 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:187     fn into_concrete_block(self) -> ConcreteBlock<A, Self::Ret, Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:187:5: 187:71 note: required by `ConcreteBlock`
src/lib.rs:187     fn into_concrete_block(self) -> ConcreteBlock<A, Self::Ret, Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

...because of:

rust-lang/rfcs#1214

frewsxcv added a commit to frewsxcv/webdriver-rust that referenced this pull request Sep 2, 2015

Fix nightly warnings related to lifetimes
The following warnings appear:

```
src/command.rs:344:5: 344:56 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/command.rs:344     fn from_json(body: &Json) -> WebDriverResult<Self>;
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/command.rs:344:5: 344:56 help: run `rustc --explain E0277` to see a detailed explanation
src/command.rs:344:5: 344:56 note: `Self` does not have a constant size known at compile-time
src/command.rs:344     fn from_json(body: &Json) -> WebDriverResult<Self>;
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/command.rs:344:5: 344:56 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/command.rs:344     fn from_json(body: &Json) -> WebDriverResult<Self>;
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/command.rs:344:5: 344:56 note: required by `core::result::Result`
src/command.rs:344     fn from_json(body: &Json) -> WebDriverResult<Self>;
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

...because of:

rust-lang/rfcs#1214

frewsxcv added a commit to frewsxcv/rust-offscreen-rendering-context that referenced this pull request Sep 2, 2015

Fix nightly warnings related to lifetimes
The following warnings appear:

```
src/platform/mod.rs:7:5: 7:56 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/platform/mod.rs:7     fn create_headless() -> Result<Self, &'static str>;
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/platform/mod.rs:7:5: 7:56 help: run `rustc --explain E0277` to see a detailed explanation
src/platform/mod.rs:7:5: 7:56 note: `Self` does not have a constant size known at compile-time
src/platform/mod.rs:7     fn create_headless() -> Result<Self, &'static str>;
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/platform/mod.rs:7:5: 7:56 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/platform/mod.rs:7     fn create_headless() -> Result<Self, &'static str>;
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/platform/mod.rs:7:5: 7:56 note: required by `core::result::Result`
src/platform/mod.rs:7     fn create_headless() -> Result<Self, &'static str>;
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

...because of:

rust-lang/rfcs#1214

frewsxcv added a commit to frewsxcv/rust-chrono that referenced this pull request Sep 5, 2015

Fix nightly warnings related to lifetimes
The following warnings appear:

```
   Compiling chrono v0.2.15 (file:///Users/coreyf/Development/rust/rust-chrono)
src/lib.rs:504:5: 504:52 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:504     fn with_year(&self, year: i32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:504:5: 504:52 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:504:5: 504:52 note: `Self` does not have a constant size known at compile-time
src/lib.rs:504     fn with_year(&self, year: i32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:504:5: 504:52 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:504     fn with_year(&self, year: i32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:504:5: 504:52 note: required by `core::option::Option`
src/lib.rs:504     fn with_year(&self, year: i32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:509:5: 509:54 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:509     fn with_month(&self, month: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:509:5: 509:54 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:509:5: 509:54 note: `Self` does not have a constant size known at compile-time
src/lib.rs:509     fn with_month(&self, month: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:509:5: 509:54 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:509     fn with_month(&self, month: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:509:5: 509:54 note: required by `core::option::Option`
src/lib.rs:509     fn with_month(&self, month: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:514:5: 514:56 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:514     fn with_month0(&self, month0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:514:5: 514:56 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:514:5: 514:56 note: `Self` does not have a constant size known at compile-time
src/lib.rs:514     fn with_month0(&self, month0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:514:5: 514:56 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:514     fn with_month0(&self, month0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:514:5: 514:56 note: required by `core::option::Option`
src/lib.rs:514     fn with_month0(&self, month0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:519:5: 519:50 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:519     fn with_day(&self, day: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:519:5: 519:50 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:519:5: 519:50 note: `Self` does not have a constant size known at compile-time
src/lib.rs:519     fn with_day(&self, day: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:519:5: 519:50 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:519     fn with_day(&self, day: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:519:5: 519:50 note: required by `core::option::Option`
src/lib.rs:519     fn with_day(&self, day: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:524:5: 524:52 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:524     fn with_day0(&self, day0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:524:5: 524:52 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:524:5: 524:52 note: `Self` does not have a constant size known at compile-time
src/lib.rs:524     fn with_day0(&self, day0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:524:5: 524:52 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:524     fn with_day0(&self, day0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:524:5: 524:52 note: required by `core::option::Option`
src/lib.rs:524     fn with_day0(&self, day0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:529:5: 529:58 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:529     fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:529:5: 529:58 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:529:5: 529:58 note: `Self` does not have a constant size known at compile-time
src/lib.rs:529     fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:529:5: 529:58 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:529     fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:529:5: 529:58 note: required by `core::option::Option`
src/lib.rs:529     fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:534:5: 534:60 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:534     fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:534:5: 534:60 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:534:5: 534:60 note: `Self` does not have a constant size known at compile-time
src/lib.rs:534     fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:534:5: 534:60 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:534     fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:534:5: 534:60 note: required by `core::option::Option`
src/lib.rs:534     fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:580:5: 580:52 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:580     fn with_hour(&self, hour: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:580:5: 580:52 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:580:5: 580:52 note: `Self` does not have a constant size known at compile-time
src/lib.rs:580     fn with_hour(&self, hour: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:580:5: 580:52 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:580     fn with_hour(&self, hour: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:580:5: 580:52 note: required by `core::option::Option`
src/lib.rs:580     fn with_hour(&self, hour: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:585:5: 585:53 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:585     fn with_minute(&self, min: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:585:5: 585:53 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:585:5: 585:53 note: `Self` does not have a constant size known at compile-time
src/lib.rs:585     fn with_minute(&self, min: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:585:5: 585:53 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:585     fn with_minute(&self, min: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:585:5: 585:53 note: required by `core::option::Option`
src/lib.rs:585     fn with_minute(&self, min: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:590:5: 590:53 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:590     fn with_second(&self, sec: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:590:5: 590:53 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:590:5: 590:53 note: `Self` does not have a constant size known at compile-time
src/lib.rs:590     fn with_second(&self, sec: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:590:5: 590:53 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:590     fn with_second(&self, sec: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:590:5: 590:53 note: required by `core::option::Option`
src/lib.rs:590     fn with_second(&self, sec: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:595:5: 595:58 warning: the trait `core::marker::Sized` is not implemented for the type `Self` [E0277]
src/lib.rs:595     fn with_nanosecond(&self, nano: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:595:5: 595:58 help: run `rustc --explain E0277` to see a detailed explanation
src/lib.rs:595:5: 595:58 note: `Self` does not have a constant size known at compile-time
src/lib.rs:595     fn with_nanosecond(&self, nano: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:595:5: 595:58 note: this warning results from recent bug fixes and clarifications; it will become a HARD ERROR in the next release. See RFC 1214 for details.
src/lib.rs:595     fn with_nanosecond(&self, nano: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:595:5: 595:58 note: required by `core::option::Option`
src/lib.rs:595     fn with_nanosecond(&self, nano: u32) -> Option<Self>;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```

...because of:

rust-lang/rfcs#1214
@Zalastra

This comment has been minimized.

Copy link

Zalastra commented Sep 22, 2015

Ran into this error using an associated const on a trait. On IRC it was suggested that this is likely a compiler bug.

pub trait IterableEnum<T> {
    const ENUM_VARIANTS: &'static [T];
}
@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Sep 22, 2015

@Zalastra

Just add T: 'static. Not a bug.

@bluss

This comment has been minimized.

Copy link

bluss commented Sep 22, 2015

It outputs two warnings (playpen)

  • warning: the trait core::marker::Sized is not implemented for the type T
  • warning: the parameter type T may not live long enough

The first one must be a bug.

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Sep 22, 2015

@bluss it's odd because it seems like it doesn't take actual bounds into account - see fixed version (the Sized bound is unnecessary, but it's there to show the issue).

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

nikomatsakis commented Sep 30, 2015

I agree that the T: Sized message is a bug. Did anyone file an issue?

On Tue, Sep 22, 2015 at 8:14 AM, Eduard-Mihai Burtescu <
notifications@github.com> wrote:

@bluss https://github.com/bluss it's odd because it seems like it
doesn't take actual bounds into account - see fixed version
https://play.rust-lang.org/?gist=343add7244bd4b210961&version=nightly&run=1
(the Sized bound is unnecessary, but it's there to show the issue).


Reply to this email directly or view it on GitHub
#1214 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.