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

Rollup of 15 pull requests #90159

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
82348ef
nice_region_error: Include lifetime placeholders in error output
notriddle Oct 1, 2021
729ff2d
Give better error for `macro_rules name`
aDotInTheVoid Sep 25, 2021
1bb399c
Ensure that pushing empty path works as before
seanyoung Oct 8, 2021
bd1a1e4
Don't mark for loop head span with desugaring
camsteffen Oct 14, 2021
a697aa6
Use more lowered spans in for loop
camsteffen Oct 15, 2021
ffdd5a0
Fix clippy with for loop span change
camsteffen Oct 14, 2021
4333091
Update E0637 description to mention `&` w/o an explicit lifetime name
JohnTitor Oct 15, 2021
d2470e7
rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant
petrochenkov Oct 17, 2021
7581bae
Fix const qualification when executed after promotion
tmiasko Oct 19, 2021
c97cf7f
Reject closures in patterns
tmiasko Oct 18, 2021
21d02bf
Add a regression test for issue-83479
JohnTitor Oct 20, 2021
396a4f4
Increase `ROOT_ENTRY_LIMIT` to 1331
JohnTitor Oct 20, 2021
fe060bf
Change `Duration::from_secs_*` underflow error
mbartlett21 Oct 16, 2021
6469fba
Trait objects
BoxyUwU Oct 20, 2021
a81e489
Return pos impl trait
BoxyUwU Oct 20, 2021
83a1834
Wfness
BoxyUwU Oct 20, 2021
8f23779
Inference
BoxyUwU Oct 20, 2021
7a8bd2d
add fixme
BoxyUwU Oct 20, 2021
c75d8cb
Ordering
BoxyUwU Oct 20, 2021
e7a9e82
*dust dust*
BoxyUwU Oct 20, 2021
74c6636
Verify that only NeedsNonConstDrop expects promoteds
tmiasko Oct 21, 2021
ab44e46
Add test for issue #78561
samlich Oct 20, 2021
d50832b
triagebot: Treat `I-*nominated` like `I-nominated`
joshtriplett Oct 21, 2021
04c1ec5
Clarify undefined behaviour for binary heap, btree and hashset
Wilfred Jul 28, 2021
0dba9d0
Stabilize feature saturating_div for rust 1.58
kellerkindt Oct 21, 2021
121411d
Rollup merge of #87537 - Wilfred:improve-min-heap-docs, r=Mark-Simula…
JohnTitor Oct 22, 2021
0c7b513
Rollup merge of #88624 - kellerkindt:master, r=JohnTitor
JohnTitor Oct 22, 2021
1585730
Rollup merge of #89257 - aDotInTheVoid:macro-error-2, r=estebank
JohnTitor Oct 22, 2021
0cc8b39
Rollup merge of #89416 - notriddle:notriddle/do-not-elide-lifetimes-i…
JohnTitor Oct 22, 2021
0d70763
Rollup merge of #89665 - seanyoung:push-empty, r=m-ou-se
JohnTitor Oct 22, 2021
01f7352
Rollup merge of #89895 - camsteffen:for-loop-head-span, r=davidtwco
JohnTitor Oct 22, 2021
8c210e0
Rollup merge of #89922 - JohnTitor:update-e0637, r=jackh726
JohnTitor Oct 22, 2021
5256761
Rollup merge of #89944 - mbartlett21:patch-2, r=Mark-Simulacrum
JohnTitor Oct 22, 2021
05e0281
Rollup merge of #89991 - petrochenkov:visitok2, r=jackh726
JohnTitor Oct 22, 2021
a93e7e0
Rollup merge of #90028 - tmiasko:structural-match-closure, r=spastorino
JohnTitor Oct 22, 2021
efdb8e5
Rollup merge of #90069 - tmiasko:promoted-const-qualif, r=oli-obk
JohnTitor Oct 22, 2021
7bcc6be
Rollup merge of #90078 - JohnTitor:test-83479, r=Mark-Simulacrum
JohnTitor Oct 22, 2021
61e4e3b
Rollup merge of #90114 - BoxyUwU:cg_defaults_tests, r=lcnr
JohnTitor Oct 22, 2021
c24e75a
Rollup merge of #90115 - samlich:test-issue-78561, r=oli-obk
JohnTitor Oct 22, 2021
1fbce5c
Rollup merge of #90129 - joshtriplett:triagebot-nominated, r=Mark-Sim…
JohnTitor Oct 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update E0637 description to mention & w/o an explicit lifetime name
  • Loading branch information
JohnTitor committed Oct 15, 2021
commit 43330916251221764c28e6bc650f01be8713b79b
36 changes: 26 additions & 10 deletions compiler/rustc_error_codes/src/error_codes/E0637.md
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
18 changes: 13 additions & 5 deletions src/test/ui/error-codes/E0637.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
struct Foo<'a: '_>(&'a u8); //~ ERROR cannot be used here
fn foo<'a: '_>(_: &'a u8) {} //~ ERROR cannot be used here
fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
//~^ ERROR: `'_` cannot be used here [E0637]
//~| ERROR: missing lifetime specifier
if str1.len() > str2.len() {
str1
} else {
str2
}
}

struct Bar<'a>(&'a u8);
impl<'a: '_> Bar<'a> { //~ ERROR cannot be used here
fn bar() {}
fn and_without_explicit_lifetime<T>()
where
T: Into<&u32>, //~ ERROR: `&` without an explicit lifetime name cannot be used here [E0637]
{
}

fn main() {}
31 changes: 19 additions & 12 deletions src/test/ui/error-codes/E0637.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
error[E0637]: `'_` cannot be used here
--> $DIR/E0637.rs:1:16
--> $DIR/E0637.rs:1:24
|
LL | struct Foo<'a: '_>(&'a u8);
| ^^ `'_` is a reserved lifetime name
LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
| ^^ `'_` is a reserved lifetime name

error[E0637]: `'_` cannot be used here
--> $DIR/E0637.rs:2:12
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/E0637.rs:13:13
|
LL | fn foo<'a: '_>(_: &'a u8) {}
| ^^ `'_` is a reserved lifetime name
LL | T: Into<&u32>,
| ^ explicit lifetime name needed here

error[E0637]: `'_` cannot be used here
--> $DIR/E0637.rs:5:10
error[E0106]: missing lifetime specifier
--> $DIR/E0637.rs:1:62
|
LL | fn underscore_lifetime<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
| ------- ------- ^^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `str1` or `str2`
help: consider introducing a named lifetime parameter
|
LL | impl<'a: '_> Bar<'a> {
| ^^ `'_` is a reserved lifetime name
LL | fn underscore_lifetime<'a, '_>(str1: &'a str, str2: &'a str) -> &'a str {
| +++ ~~ ~~ ~~

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0637`.
Some errors have detailed explanations: E0106, E0637.
For more information about an error, try `rustc --explain E0106`.