From 6d53466fe0110d7f1da509ff2b633ad85d5995dd Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 15 Aug 2019 18:11:11 -0400 Subject: [PATCH 1/4] include description of bindings in the reference --- src/lifetime-elision.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/lifetime-elision.md b/src/lifetime-elision.md index a90f38aec..103708d91 100644 --- a/src/lifetime-elision.md +++ b/src/lifetime-elision.md @@ -71,6 +71,14 @@ rules. If the trait object is used as a type argument of a generic type then the containing type is first used to try to infer a bound. +* If there is a unique bound from the containing type then that is the default +* If there is more than one bound from the containing type then an explicit + bound must be specified + +If the trait object is used as a binding for an associated type (e.g., +`Item = dyn Trait`) then the containing trait is first used to try to +infer a bound, in an analogous way to type arguments: + * If there is a unique bound from the containing type then that is the default * If there is more than one bound from the containing type then an explicit bound must be specified @@ -129,6 +137,29 @@ struct TwoBounds<'a, 'b, T: ?Sized + 'a + 'b> TwoBounds<'a, 'b, dyn Foo<'c>> ``` +Here is an example featuring associated type bindings: + +```rust,ignore +trait Bar<'a> { + type Item1: ?Sized; + type Item2: ?Sized + 'a; +} +trait Baz { } + +dyn Bar< + 'x + Item1 = dyn Baz, // defaults to `dyn Baz + 'static` + Item2 = dyn Baz, // defaults to 'dyn Baz + `x` +> +``` + +**Note:** As of this writing, the rules for associated type bindings +are incompletely implemented, and explicit bounds may sometimes be +required when they ought not to be. See [rust-lang/rust#63618][] for +more details. + +[rust-lang/rust#63618]: https://github.com/rust-lang/rust/issues/63618 + ## `'static` lifetime elision Both [constant] and [static] declarations of reference types have *implicit* From d91c4407e77c4d2866e7504383865baf9a024966 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 16 Aug 2019 11:54:57 -0400 Subject: [PATCH 2/4] Update src/lifetime-elision.md Co-Authored-By: Ryan Scheel --- src/lifetime-elision.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lifetime-elision.md b/src/lifetime-elision.md index 103708d91..665552571 100644 --- a/src/lifetime-elision.md +++ b/src/lifetime-elision.md @@ -154,7 +154,7 @@ dyn Bar< ``` **Note:** As of this writing, the rules for associated type bindings -are incompletely implemented, and explicit bounds may sometimes be +are implemented incompletely, and explicit bounds may sometimes be required when they ought not to be. See [rust-lang/rust#63618][] for more details. From 24b5d405977ed30c738747f4fb1a0cf4e1f0bf5d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 16 Aug 2019 11:55:38 -0400 Subject: [PATCH 3/4] add periods to bullets --- src/lifetime-elision.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lifetime-elision.md b/src/lifetime-elision.md index 665552571..70b15c6b8 100644 --- a/src/lifetime-elision.md +++ b/src/lifetime-elision.md @@ -71,17 +71,17 @@ rules. If the trait object is used as a type argument of a generic type then the containing type is first used to try to infer a bound. -* If there is a unique bound from the containing type then that is the default +* If there is a unique bound from the containing type then that is the default. * If there is more than one bound from the containing type then an explicit - bound must be specified + bound must be specified. If the trait object is used as a binding for an associated type (e.g., `Item = dyn Trait`) then the containing trait is first used to try to infer a bound, in an analogous way to type arguments: -* If there is a unique bound from the containing type then that is the default +* If there is a unique bound from the containing type then that is the default. * If there is more than one bound from the containing type then an explicit - bound must be specified + bound must be specified. If neither of those rules apply, then the bounds on the trait are used: From d1413e478d892d7cb36f026b4445a33ee488f2f5 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 16 Aug 2019 11:56:56 -0400 Subject: [PATCH 4/4] reformat link --- src/lifetime-elision.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lifetime-elision.md b/src/lifetime-elision.md index 70b15c6b8..c2eff592a 100644 --- a/src/lifetime-elision.md +++ b/src/lifetime-elision.md @@ -155,11 +155,9 @@ dyn Bar< **Note:** As of this writing, the rules for associated type bindings are implemented incompletely, and explicit bounds may sometimes be -required when they ought not to be. See [rust-lang/rust#63618][] for +required when they ought not to be. See [rust-lang/rust#63618] for more details. -[rust-lang/rust#63618]: https://github.com/rust-lang/rust/issues/63618 - ## `'static` lifetime elision Both [constant] and [static] declarations of reference types have *implicit* @@ -206,5 +204,6 @@ const RESOLVED_STATIC: &dyn Fn(&Foo, &Bar) -> &Baz = .. [function pointer]: types/function-pointer.html [RFC 599]: https://github.com/rust-lang/rfcs/blob/master/text/0599-default-object-bound.md [RFC 1156]: https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md +[rust-lang/rust#63618]: https://github.com/rust-lang/rust/issues/63618 [static]: items/static-items.html [trait object]: types/trait-object.html