]> git.lizzy.rs Git - rust.git/commit
Auto merge of #46785 - leodasvacas:type-check-defaults-at-declaration, r=nikomatsakis
authorbors <bors@rust-lang.org>
Thu, 1 Mar 2018 13:19:18 +0000 (13:19 +0000)
committerbors <bors@rust-lang.org>
Thu, 1 Mar 2018 13:19:18 +0000 (13:19 +0000)
commit3eeb5a665e313c5b281820099e04d4c6c8188b46
treee16ca17237185c562aa8a02f382c3102e6f44061
parenta85417f5938023d1491b44d94da705f539bb8b17
parent3e84aeda0fa308424338529611a8ee157776b221
Auto merge of #46785 - leodasvacas:type-check-defaults-at-declaration, r=nikomatsakis

[Underspecified semantics] Type check defaults at declaration.

Fixes  #46669. See the test for code that compiles on stable but will no longer compile. This falls under a "Underspecified language semantics" fix. **Needs crater**.

On type and trait declarations, we currently allow anything that name checks as a type parameter default. That allows the user to write a default that can never be applied, or even a default that may conditionally be applied depending on the type of another parameter. Mostly this just defers the error to use sites, but also allows clever hacks such as `Foo<T, U = <T as Iterator>::Item>` where `U` will be able to apply it's default only when `T: Iterator`. Maybe that means this bug is a feature, but it's a fiddly behaviour that seems undesirable.

This PR validates defaults at declaration sites by ensuring all predicates on the parameter are valid for the default. With the exception of `Self: Sized` which we don't want to check to allow things like `trait Add<RHS = Self>`.