-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #90161 - JohnTitor:rollup-1j2qc8m, r=JohnTitor
Rollup of 14 pull requests Successful merges: - #87537 (Clarify undefined behaviour in binary heap, btree and hashset docs) - #88624 (Stabilize feature `saturating_div` for rust 1.58.0) - #89257 (Give better error for `macro_rules name`) - #89665 (Ensure that pushing empty path works as before on verbatim paths) - #89895 (Don't mark for loop iter expression as desugared) - #89922 (Update E0637 description to mention `&` w/o an explicit lifetime name) - #89944 (Change `Duration::[try_]from_secs_{f32, f64}` underflow error) - #89991 (rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant) - #90028 (Reject closures in patterns) - #90069 (Fix const qualification when executed after promotion) - #90078 (Add a regression test for issue-83479) - #90114 (Add some tests for const_generics_defaults) - #90115 (Add test for issue #78561) - #90129 (triagebot: Treat `I-*nominated` like `I-nominated`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
52 changed files
with
692 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,51 @@ | ||
An underscore `_` character has been used as the identifier for a lifetime. | ||
`'_` lifetime name or `&T` without an explicit lifetime name has been used | ||
on illegal place. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0106,E0637 | ||
fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { | ||
//^^ `'_` is a reserved lifetime name | ||
fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str { | ||
//^^ `'_` is a reserved lifetime name | ||
if str1.len() > str2.len() { | ||
str1 | ||
} else { | ||
str2 | ||
} | ||
} | ||
fn and_without_explicit_lifetime<T>() | ||
where | ||
T: Into<&u32>, | ||
//^ `&` without an explicit lifetime name | ||
{ | ||
} | ||
``` | ||
|
||
`'_`, 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]. | ||
First, `'_` cannot be used as a lifetime identifier in some places | ||
because it is a reserved for the anonymous lifetime. Second, `&T` | ||
without an explicit lifetime name cannot also be used in some places. | ||
To fix them, use a lowercase letter such as `'a`, or a series | ||
of lowercase letters such as `'foo`. For more information about lifetime | ||
identifier, see [the book][bk-no]. For more information on using | ||
the anonymous lifetime in Rust 2018, see [the Rust 2018 blog post][blog-al]. | ||
|
||
Corrected example: | ||
|
||
``` | ||
fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str { | ||
fn underscore_lifetime<'a>(str1: &'a str, str2: &'a str) -> &'a str { | ||
if str1.len() > str2.len() { | ||
str1 | ||
} else { | ||
str2 | ||
} | ||
} | ||
fn and_without_explicit_lifetime<'foo, T>() | ||
where | ||
T: Into<&'foo u32>, | ||
{ | ||
} | ||
``` | ||
|
||
[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 | ||
[blog-al]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#more-lifetime-elision-rules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.