From 82684ad30a0929afba9463b89232730a9c6dadf4 Mon Sep 17 00:00:00 2001 From: Josh White Date: Wed, 5 Feb 2020 06:28:31 -0500 Subject: [PATCH 01/12] Added long error description & modifed error_codes.rs --- src/librustc_error_codes/error_codes.rs | 2 +- src/librustc_error_codes/error_codes/E0637.md | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/librustc_error_codes/error_codes/E0637.md diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index c3d9ed088981d..ba43b29538d50 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -353,6 +353,7 @@ E0631: include_str!("./error_codes/E0631.md"), E0633: include_str!("./error_codes/E0633.md"), E0635: include_str!("./error_codes/E0635.md"), E0636: include_str!("./error_codes/E0636.md"), +E0637: include_str!("./error_codes/E0637.md"), E0638: include_str!("./error_codes/E0638.md"), E0639: include_str!("./error_codes/E0639.md"), E0641: include_str!("./error_codes/E0641.md"), @@ -584,7 +585,6 @@ E0746: include_str!("./error_codes/E0746.md"), E0632, // cannot provide explicit generic arguments when `impl Trait` is // used in argument position E0634, // type has conflicting packed representaton hints - E0637, // "'_" is not a valid lifetime bound E0640, // infer outlives requirements // E0645, // trait aliases not finished E0657, // `impl Trait` can only capture lifetimes bound at the fn level diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md new file mode 100644 index 0000000000000..4f139b0ec49d6 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -0,0 +1,22 @@ +The underscore `_` character has been used as the identifier for a lifetime. + +Erroneous code example: +``` +fn some_function<'_>(x: &'_ str, y: &'_ str) -> &'_ str { + //Some code +} +``` + +Lifetimes are named with 'ident, where ident is the name of the +lifetime or loop. The `_` character, which represents the ignore pattern, +cannot be used because it is a reserved lifetime name. +To fix this, use a single lowercase letter as the +lifetime identifier, such as `'a`. For more information, see [The Rust Book](https://doc.rust-lang.org/stable/book/appendix-02-operators.html#non-operator-symbols). + +Corrected code example: +``` +fn some_function<'a>(x: &'a str, y: &'a str) -> &'a str { + //Some code +} +``` + From 4a1c6ce23547346757fa8b61207aea7eb6997aa3 Mon Sep 17 00:00:00 2001 From: Josh White Date: Wed, 5 Feb 2020 06:28:31 -0500 Subject: [PATCH 02/12] Added long error description & modifed error_codes.rs --- src/librustc_error_codes/error_codes.rs | 2 +- src/librustc_error_codes/error_codes/E0637.md | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/librustc_error_codes/error_codes/E0637.md diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index c3d9ed088981d..ba43b29538d50 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -353,6 +353,7 @@ E0631: include_str!("./error_codes/E0631.md"), E0633: include_str!("./error_codes/E0633.md"), E0635: include_str!("./error_codes/E0635.md"), E0636: include_str!("./error_codes/E0636.md"), +E0637: include_str!("./error_codes/E0637.md"), E0638: include_str!("./error_codes/E0638.md"), E0639: include_str!("./error_codes/E0639.md"), E0641: include_str!("./error_codes/E0641.md"), @@ -584,7 +585,6 @@ E0746: include_str!("./error_codes/E0746.md"), E0632, // cannot provide explicit generic arguments when `impl Trait` is // used in argument position E0634, // type has conflicting packed representaton hints - E0637, // "'_" is not a valid lifetime bound E0640, // infer outlives requirements // E0645, // trait aliases not finished E0657, // `impl Trait` can only capture lifetimes bound at the fn level diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md new file mode 100644 index 0000000000000..4f139b0ec49d6 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -0,0 +1,22 @@ +The underscore `_` character has been used as the identifier for a lifetime. + +Erroneous code example: +``` +fn some_function<'_>(x: &'_ str, y: &'_ str) -> &'_ str { + //Some code +} +``` + +Lifetimes are named with 'ident, where ident is the name of the +lifetime or loop. The `_` character, which represents the ignore pattern, +cannot be used because it is a reserved lifetime name. +To fix this, use a single lowercase letter as the +lifetime identifier, such as `'a`. For more information, see [The Rust Book](https://doc.rust-lang.org/stable/book/appendix-02-operators.html#non-operator-symbols). + +Corrected code example: +``` +fn some_function<'a>(x: &'a str, y: &'a str) -> &'a str { + //Some code +} +``` + From 201a262ac4a9cb61e4e94d8e841a973fee0edc86 Mon Sep 17 00:00:00 2001 From: Josh White Date: Thu, 6 Feb 2020 16:07:35 -0500 Subject: [PATCH 03/12] Revised error long description --- src/librustc_error_codes/error_codes/E0637.md | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index 4f139b0ec49d6..f5da357534e26 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -1,22 +1,34 @@ -The underscore `_` character has been used as the identifier for a lifetime. + +An underscore `_` character or a numeric literal `u8`, `i32`, `f64`, etc has +been used as the identifier for a lifetime. Erroneous code example: ``` -fn some_function<'_>(x: &'_ str, y: &'_ str) -> &'_ str { +fn some_function<'_>(string1: &'_ str, string2: &'_ str) -> &'_ str { + //Some code +} +``` +or Erroneous code example 2: +``` +fn some_function<'u8>(string1: &'u8 str, string2: &'u8 str) -> &'u8 str { //Some code } ``` -Lifetimes are named with 'ident, where ident is the name of the -lifetime or loop. The `_` character, which represents the ignore pattern, -cannot be used because it is a reserved lifetime name. -To fix this, use a single lowercase letter as the -lifetime identifier, such as `'a`. For more information, see [The Rust Book](https://doc.rust-lang.org/stable/book/appendix-02-operators.html#non-operator-symbols). +Lifetimes are named with `'ident`, where ident is the name of the lifetime or +loop. The `_` character, which represents the ignore pattern, cannot be used +as the identifier because it is a reserved lifetime name. Numeric literals are +also invalid lifetime identifiers and will cause this error to be thrown. To fix +this, use a series of lowercase letters as the lifetime identifier. Often a +single lowercase letter, such as `'a`, is sufficient. For more information, see +[the book][bk-no]. Corrected code example: ``` -fn some_function<'a>(x: &'a str, y: &'a str) -> &'a str { +fn some_function<'a>(string1: &'a str, string2: &'a str) -> &'a str { //Some code } ``` +[bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols + From 1923586286dea1a0f8ece43056126fc2ecc89337 Mon Sep 17 00:00:00 2001 From: Josh White Date: Thu, 6 Feb 2020 16:54:24 -0500 Subject: [PATCH 04/12] Edited error description --- src/librustc_error_codes/error_codes/E0637.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index f5da357534e26..44a365be7e0f7 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -2,15 +2,15 @@ An underscore `_` character or a numeric literal `u8`, `i32`, `f64`, etc has been used as the identifier for a lifetime. -Erroneous code example: +Erroneous code example 1: ``` -fn some_function<'_>(string1: &'_ str, string2: &'_ str) -> &'_ str { +fn some_function<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { //Some code } ``` or Erroneous code example 2: ``` -fn some_function<'u8>(string1: &'u8 str, string2: &'u8 str) -> &'u8 str { +fn some_function<'u8>(str1: &'u8 str, str2: &'u8 str) -> &'u8 str { //Some code } ``` @@ -25,7 +25,7 @@ single lowercase letter, such as `'a`, is sufficient. For more information, see Corrected code example: ``` -fn some_function<'a>(string1: &'a str, string2: &'a str) -> &'a str { +fn some_function<'a>(str1: &'a str, str2: &'a str) -> &'a str { //Some code } ``` From 78df44655aa8547baa25ee9ca49699ad82c7f76d Mon Sep 17 00:00:00 2001 From: Josh White Date: Thu, 6 Feb 2020 17:28:03 -0500 Subject: [PATCH 05/12] Tidied up the long error description --- src/librustc_error_codes/error_codes/E0637.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index 44a365be7e0f7..978cf273c94d3 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -1,6 +1,5 @@ - An underscore `_` character or a numeric literal `u8`, `i32`, `f64`, etc has -been used as the identifier for a lifetime. +been used as the identifier for a lifetime. Erroneous code example 1: ``` @@ -29,6 +28,4 @@ fn some_function<'a>(str1: &'a str, str2: &'a str) -> &'a str { //Some code } ``` - [bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols - From 8b77f8688e9436c6b35d5746e3bb79e20c67567d Mon Sep 17 00:00:00 2001 From: Josh White Date: Fri, 7 Feb 2020 12:44:31 -0500 Subject: [PATCH 06/12] performed --bless of 15 ui tests affected --- src/librustc_error_codes/error_codes/E0637.md | 69 ++++++++++++++----- .../const-param-elided-lifetime.stderr | 1 + src/test/ui/error-codes/E0637.stderr | 1 + ...rrect-explicit-lifetime-name-needed.stderr | 3 +- .../ui/underscore-lifetime/in-binder.stderr | 1 + .../underscore-lifetime-binders.stderr | 3 +- .../underscore-outlives-bounds.stderr | 1 + ...se-inherent-impl-ampersand.rust2015.stderr | 1 + ...se-inherent-impl-ampersand.rust2018.stderr | 1 + ...e-inherent-impl-underscore.rust2015.stderr | 1 + ...e-inherent-impl-underscore.rust2018.stderr | 1 + ...e-clause-trait-impl-region.rust2015.stderr | 1 + ...e-clause-trait-impl-region.rust2018.stderr | 1 + ...ause-trait-impl-underscore.rust2015.stderr | 1 + ...ause-trait-impl-underscore.rust2018.stderr | 1 + .../underscore-lifetime/where-clauses.stderr | 1 + 16 files changed, 67 insertions(+), 21 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index 978cf273c94d3..ba81e42ce0850 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -1,31 +1,62 @@ -An underscore `_` character or a numeric literal `u8`, `i32`, `f64`, etc has -been used as the identifier for a lifetime. +An underscore `_` character has been used as the identifier for a lifetime, +or a const generic has been borrowed without an explicit lifetime. -Erroneous code example 1: +Erroneous example with an underscore: ``` -fn some_function<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { - //Some code -} +fn foo<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {} + // ^^ `'_` is a reserved lifetime name +``` +Lifetimes are named with `'ident`, where ident is the name of the lifetime or +loop. The `_` character, which represents the ignore pattern, cannot be used +as the identifier because it is a reserved lifetime name. To fix +this, use a lowercase letter, or a series of lowercase letters as the lifetime +identifier. Often a single lowercase letter, such as `'a`, is sufficient. For +more information, see +[the book][bk-no]. + +Corrected underscore example: +``` +fn <'a>(str1: &'a str, str2: &'a str) -> &'a str {} ``` -or Erroneous code example 2: + +Erroneous example with const generic: ``` -fn some_function<'u8>(str1: &'u8 str, str2: &'u8 str) -> &'u8 str { - //Some code +struct A; +//~^ ERROR `&` without an explicit lifetime name cannot be used here +trait B {} + +impl A { +//~^ ERROR `&` without an explicit lifetime name cannot be used here + fn foo(&self) {} + //~^ ERROR `&` without an explicit lifetime name cannot be used here +} + +impl B for A {} +//~^ ERROR `&` without an explicit lifetime name cannot be used here + +fn bar() {} +//~^ ERROR `&` without an explicit lifetime name cannot be used here } ``` -Lifetimes are named with `'ident`, where ident is the name of the lifetime or -loop. The `_` character, which represents the ignore pattern, cannot be used -as the identifier because it is a reserved lifetime name. Numeric literals are -also invalid lifetime identifiers and will cause this error to be thrown. To fix -this, use a series of lowercase letters as the lifetime identifier. Often a -single lowercase letter, such as `'a`, is sufficient. For more information, see -[the book][bk-no]. +Const generics cannot be borrowed without specifying a lifetime.The +compiler handles memory allocation of constants differently than that of +variables and it cannot infer the lifetime of the borrowed constant. +To fix this, explicitly specify a lifetime for the const generic. -Corrected code example: +Corrected const generic example: ``` -fn some_function<'a>(str1: &'a str, str2: &'a str) -> &'a str { - //Some code +struct A; + +trait B {} + +impl A { + fn foo(&self) {} +} + +impl B for A {} + +fn bar() {} } ``` [bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols diff --git a/src/test/ui/const-generics/const-param-elided-lifetime.stderr b/src/test/ui/const-generics/const-param-elided-lifetime.stderr index 93133c507fe40..6841d1fdf360b 100644 --- a/src/test/ui/const-generics/const-param-elided-lifetime.stderr +++ b/src/test/ui/const-generics/const-param-elided-lifetime.stderr @@ -38,3 +38,4 @@ LL | #![feature(const_generics)] error: aborting due to 5 previous errors +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/error-codes/E0637.stderr b/src/test/ui/error-codes/E0637.stderr index 9c3ca87ed7e64..d19ebfd15a52c 100644 --- a/src/test/ui/error-codes/E0637.stderr +++ b/src/test/ui/error-codes/E0637.stderr @@ -18,3 +18,4 @@ LL | impl<'a: '_> Bar<'a> { error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/generics/issue-65285-incorrect-explicit-lifetime-name-needed.stderr b/src/test/ui/generics/issue-65285-incorrect-explicit-lifetime-name-needed.stderr index 8720288b53e58..9f410c0dbbbd2 100644 --- a/src/test/ui/generics/issue-65285-incorrect-explicit-lifetime-name-needed.stderr +++ b/src/test/ui/generics/issue-65285-incorrect-explicit-lifetime-name-needed.stderr @@ -18,4 +18,5 @@ LL | fn bar<'b, L: X<&'b Nested>>(){} error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0106`. +Some errors have detailed explanations: E0106, E0637. +For more information about an error, try `rustc --explain E0106`. diff --git a/src/test/ui/underscore-lifetime/in-binder.stderr b/src/test/ui/underscore-lifetime/in-binder.stderr index 1b936dd9aec2f..fcd7eddb57605 100644 --- a/src/test/ui/underscore-lifetime/in-binder.stderr +++ b/src/test/ui/underscore-lifetime/in-binder.stderr @@ -36,3 +36,4 @@ LL | fn foo<'_>() { error: aborting due to 6 previous errors +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr b/src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr index c7cda38e47691..ada4551baefff 100644 --- a/src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr +++ b/src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr @@ -38,4 +38,5 @@ LL | fn foo2<'a>(_: &'a u8, y: &'a u8) -> &'a u8 { y } error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0106`. +Some errors have detailed explanations: E0106, E0637. +For more information about an error, try `rustc --explain E0106`. diff --git a/src/test/ui/underscore-lifetime/underscore-outlives-bounds.stderr b/src/test/ui/underscore-lifetime/underscore-outlives-bounds.stderr index 6fa74d4e31034..4b38a26f957f9 100644 --- a/src/test/ui/underscore-lifetime/underscore-outlives-bounds.stderr +++ b/src/test/ui/underscore-lifetime/underscore-outlives-bounds.stderr @@ -6,3 +6,4 @@ LL | impl<'b: '_> Foo<'b> for i32 {} error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2015.stderr b/src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2015.stderr index eec8e4b846886..fe726cb49c737 100644 --- a/src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2015.stderr +++ b/src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2015.stderr @@ -6,3 +6,4 @@ LL | T: WithType<&u32> error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2018.stderr b/src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2018.stderr index eec8e4b846886..fe726cb49c737 100644 --- a/src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2018.stderr +++ b/src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2018.stderr @@ -6,3 +6,4 @@ LL | T: WithType<&u32> error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2015.stderr b/src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2015.stderr index d2c3e352045b6..95939fd6b7e03 100644 --- a/src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2015.stderr +++ b/src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2015.stderr @@ -6,3 +6,4 @@ LL | T: WithRegion<'_> error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2018.stderr b/src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2018.stderr index d2c3e352045b6..95939fd6b7e03 100644 --- a/src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2018.stderr +++ b/src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2018.stderr @@ -6,3 +6,4 @@ LL | T: WithRegion<'_> error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clause-trait-impl-region.rust2015.stderr b/src/test/ui/underscore-lifetime/where-clause-trait-impl-region.rust2015.stderr index 586b2b6aeaf28..fbd14de21078b 100644 --- a/src/test/ui/underscore-lifetime/where-clause-trait-impl-region.rust2015.stderr +++ b/src/test/ui/underscore-lifetime/where-clause-trait-impl-region.rust2015.stderr @@ -6,3 +6,4 @@ LL | T: WithType<&u32> error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clause-trait-impl-region.rust2018.stderr b/src/test/ui/underscore-lifetime/where-clause-trait-impl-region.rust2018.stderr index 586b2b6aeaf28..fbd14de21078b 100644 --- a/src/test/ui/underscore-lifetime/where-clause-trait-impl-region.rust2018.stderr +++ b/src/test/ui/underscore-lifetime/where-clause-trait-impl-region.rust2018.stderr @@ -6,3 +6,4 @@ LL | T: WithType<&u32> error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clause-trait-impl-underscore.rust2015.stderr b/src/test/ui/underscore-lifetime/where-clause-trait-impl-underscore.rust2015.stderr index faabf57a7df40..92caff0dcde99 100644 --- a/src/test/ui/underscore-lifetime/where-clause-trait-impl-underscore.rust2015.stderr +++ b/src/test/ui/underscore-lifetime/where-clause-trait-impl-underscore.rust2015.stderr @@ -6,3 +6,4 @@ LL | T: WithRegion<'_> error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clause-trait-impl-underscore.rust2018.stderr b/src/test/ui/underscore-lifetime/where-clause-trait-impl-underscore.rust2018.stderr index faabf57a7df40..92caff0dcde99 100644 --- a/src/test/ui/underscore-lifetime/where-clause-trait-impl-underscore.rust2018.stderr +++ b/src/test/ui/underscore-lifetime/where-clause-trait-impl-underscore.rust2018.stderr @@ -6,3 +6,4 @@ LL | T: WithRegion<'_> error: aborting due to previous error +For more information about this error, try `rustc --explain E0637`. diff --git a/src/test/ui/underscore-lifetime/where-clauses.stderr b/src/test/ui/underscore-lifetime/where-clauses.stderr index 8674a925c110d..1a3ea4af7e12e 100644 --- a/src/test/ui/underscore-lifetime/where-clauses.stderr +++ b/src/test/ui/underscore-lifetime/where-clauses.stderr @@ -12,3 +12,4 @@ LL | impl Foo<'static> for Vec {} error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0637`. From 92fc98c695d133ae28fb9d386d22efef57e2fc87 Mon Sep 17 00:00:00 2001 From: Josh White Date: Fri, 7 Feb 2020 23:40:16 -0500 Subject: [PATCH 07/12] Cleaned up long error description --- src/librustc_error_codes/error_codes/E0637.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index ba81e42ce0850..13be503676790 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -11,8 +11,7 @@ loop. The `_` character, which represents the ignore pattern, cannot be used as the identifier because it is a reserved lifetime name. To fix this, use a lowercase letter, or a series of lowercase letters as the lifetime identifier. Often a single lowercase letter, such as `'a`, is sufficient. For -more information, see -[the book][bk-no]. +more information, see [the book][bk-no]. Corrected underscore example: ``` From 409146673c38ffeed1a9c93b9d1736be9de3cce4 Mon Sep 17 00:00:00 2001 From: Josh White Date: Sat, 8 Feb 2020 00:22:15 -0500 Subject: [PATCH 08/12] Removed trailing white spaces --- src/librustc_error_codes/error_codes/E0637.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index 13be503676790..f2ec7fa0b49ef 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -24,7 +24,7 @@ struct A; //~^ ERROR `&` without an explicit lifetime name cannot be used here trait B {} -impl A { +impl A { //~^ ERROR `&` without an explicit lifetime name cannot be used here fn foo(&self) {} //~^ ERROR `&` without an explicit lifetime name cannot be used here @@ -38,7 +38,7 @@ fn bar() {} } ``` -Const generics cannot be borrowed without specifying a lifetime.The +Const generics cannot be borrowed without specifying a lifetime.The compiler handles memory allocation of constants differently than that of variables and it cannot infer the lifetime of the borrowed constant. To fix this, explicitly specify a lifetime for the const generic. From 58d0e67f504fb55ccbe1094265d029a10bc168c7 Mon Sep 17 00:00:00 2001 From: Josh White Date: Sat, 8 Feb 2020 06:18:42 -0500 Subject: [PATCH 09/12] Added compiler flags to example code, removed unexpected curly --- src/librustc_error_codes/error_codes/E0637.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index f2ec7fa0b49ef..9b5db8fe733df 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -2,7 +2,7 @@ An underscore `_` character has been used as the identifier for a lifetime, or a const generic has been borrowed without an explicit lifetime. Erroneous example with an underscore: -``` +```compile_fail,E0106,E0637 fn foo<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {} // ^^ `'_` is a reserved lifetime name ``` @@ -19,7 +19,7 @@ fn <'a>(str1: &'a str, str2: &'a str) -> &'a str {} ``` Erroneous example with const generic: -``` +```compile_fail,E0637 struct A; //~^ ERROR `&` without an explicit lifetime name cannot be used here trait B {} @@ -35,7 +35,6 @@ impl B for A {} fn bar() {} //~^ ERROR `&` without an explicit lifetime name cannot be used here -} ``` Const generics cannot be borrowed without specifying a lifetime.The @@ -56,6 +55,5 @@ impl A { impl B for A {} fn bar() {} -} ``` [bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols From a804d476a670e29f2ac55d97c72ae0bd456b3f84 Mon Sep 17 00:00:00 2001 From: Josh White Date: Sat, 8 Feb 2020 08:14:28 -0500 Subject: [PATCH 10/12] Corrected E0637.md based on test failure --- src/librustc_error_codes/error_codes/E0637.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index 9b5db8fe733df..a79a2fda1a0e6 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -15,11 +15,11 @@ more information, see [the book][bk-no]. Corrected underscore example: ``` -fn <'a>(str1: &'a str, str2: &'a str) -> &'a str {} +fn foo<'a>(str1: &'a str, str2: &'a str) -> &'a str {} ``` Erroneous example with const generic: -```compile_fail,E0637 +```compile_fail,E0261,E0637,E0658 struct A; //~^ ERROR `&` without an explicit lifetime name cannot be used here trait B {} From 8c351182de955b3dea73681a1e3b3eb6afb0edca Mon Sep 17 00:00:00 2001 From: Josh White Date: Sat, 8 Feb 2020 14:24:35 -0500 Subject: [PATCH 11/12] Corrected E0637.md based on test failures --- src/librustc_error_codes/error_codes/E0637.md | 73 ++++++------------- 1 file changed, 23 insertions(+), 50 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index a79a2fda1a0e6..f21b1749ec735 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -1,59 +1,32 @@ -An underscore `_` character has been used as the identifier for a lifetime, -or a const generic has been borrowed without an explicit lifetime. +An underscore `_` character has been used as the identifier for a lifetime. -Erroneous example with an underscore: +Erroneous example: ```compile_fail,E0106,E0637 -fn foo<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {} - // ^^ `'_` is a reserved lifetime name -``` -Lifetimes are named with `'ident`, where ident is the name of the lifetime or -loop. The `_` character, which represents the ignore pattern, cannot be used -as the identifier because it is a reserved lifetime name. To fix -this, use a lowercase letter, or a series of lowercase letters as the lifetime -identifier. Often a single lowercase letter, such as `'a`, is sufficient. For -more information, see [the book][bk-no]. - -Corrected underscore example: -``` -fn foo<'a>(str1: &'a str, str2: &'a str) -> &'a str {} -``` - -Erroneous example with const generic: -```compile_fail,E0261,E0637,E0658 -struct A; -//~^ ERROR `&` without an explicit lifetime name cannot be used here -trait B {} - -impl A { -//~^ ERROR `&` without an explicit lifetime name cannot be used here - fn foo(&self) {} - //~^ ERROR `&` without an explicit lifetime name cannot be used here +fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { + //^^ `'_` is a reserved lifetime name + if str1.len() > str2.len() { + str1 + } else { + str2 + } } - -impl B for A {} -//~^ ERROR `&` without an explicit lifetime name cannot be used here - -fn bar() {} -//~^ ERROR `&` without an explicit lifetime name cannot be used here ``` +`'_`, cannot be used as a lifetime identifier because it is a reserved for the +anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series +of lowercase letters such as `'foo`. For more information, see [the book][bk-no]. +For more information on using the anonymous lifetime in rust nightly, see [the +nightly book][bk-al]. -Const generics cannot be borrowed without specifying a lifetime.The -compiler handles memory allocation of constants differently than that of -variables and it cannot infer the lifetime of the borrowed constant. -To fix this, explicitly specify a lifetime for the const generic. - -Corrected const generic example: +Corrected example: ``` -struct A; - -trait B {} - -impl A { - fn foo(&self) {} +fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str { + if str1.len() > str2.len() { + str1 + } else { + str2 + } } - -impl B for A {} - -fn bar() {} ``` + [bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols +[bk-al]: https://doc.rust-lang.org/nightly/edition-guide/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html From 9d54bb28b30d26688f71cff672c68ed4fe00ab1e Mon Sep 17 00:00:00 2001 From: Josh White Date: Sat, 8 Feb 2020 16:26:09 -0500 Subject: [PATCH 12/12] Tidied up E0637.md --- src/librustc_error_codes/error_codes/E0637.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0637.md b/src/librustc_error_codes/error_codes/E0637.md index f21b1749ec735..e114d3d0f94ae 100644 --- a/src/librustc_error_codes/error_codes/E0637.md +++ b/src/librustc_error_codes/error_codes/E0637.md @@ -13,9 +13,9 @@ fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { ``` `'_`, cannot be used as a lifetime identifier because it is a reserved for the anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series -of lowercase letters such as `'foo`. For more information, see [the book][bk-no]. -For more information on using the anonymous lifetime in rust nightly, see [the -nightly book][bk-al]. +of lowercase letters such as `'foo`. For more information, see [the +book][bk-no]. For more information on using the anonymous lifetime in rust +nightly, see [the nightly book][bk-al]. Corrected example: ```