Skip to content

Commit 0968c18

Browse files
committed
Stop errorring for elided lifetimes in path.
1 parent 673090e commit 0968c18

File tree

12 files changed

+65
-127
lines changed

12 files changed

+65
-127
lines changed

compiler/rustc_error_codes/src/error_codes/E0726.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
An argument lifetime was elided in an async function.
24

35
Erroneous code example:
@@ -7,7 +9,7 @@ the Rust compiler to know, on usage, the lifespan of the type. When the
79
lifetime is not explicitly mentioned and the Rust Compiler cannot determine
810
the lifetime of your type, the following error occurs.
911

10-
```compile_fail,E0726
12+
```compile_fail
1113
use futures::executor::block_on;
1214
struct Content<'a> {
1315
title: &'a str,

compiler/rustc_resolve/src/late.rs

+17-52
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ enum LifetimeRibKind {
225225
/// Create a new anonymous region parameter and reference that.
226226
AnonymousCreateParameter(NodeId),
227227

228-
/// Give a hard error when generic lifetime arguments are elided.
229-
ReportElidedInPath,
230-
231228
/// Give a hard error when either `&` or `'_` is written. Used to
232229
/// rule out things like `where T: Foo<'_>`. Does not imply an
233230
/// error on default object bounds (e.g., `Box<dyn Foo>`).
@@ -743,10 +740,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
743740
this.with_lifetime_rib(
744741
LifetimeRibKind::AnonymousCreateParameter(fn_id),
745742
|this| {
746-
this.with_lifetime_rib(LifetimeRibKind::ReportElidedInPath, |this| {
747-
// Add each argument to the rib.
748-
this.resolve_params(&declaration.inputs)
749-
});
743+
// Add each argument to the rib.
744+
this.resolve_params(&declaration.inputs)
750745
},
751746
);
752747

@@ -1397,7 +1392,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
13971392
path_span: Span,
13981393
) {
13991394
let proj_start = path.len() - partial_res.unresolved_segments();
1400-
'segment: for (i, segment) in path.iter().enumerate() {
1395+
for (i, segment) in path.iter().enumerate() {
14011396
if segment.has_lifetime_args {
14021397
continue;
14031398
}
@@ -1464,32 +1459,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
14641459

14651460
for rib in self.lifetime_ribs.iter().rev() {
14661461
match rib.kind {
1467-
// We error here because we don't want to support deprecated impl elision in
1468-
// new features like impl elision and `async fn`,
1469-
LifetimeRibKind::ReportElidedInPath => {
1470-
let sess = self.r.session;
1471-
let mut err = rustc_errors::struct_span_err!(
1472-
sess,
1473-
path_span,
1474-
E0726,
1475-
"implicit elided lifetime not allowed here"
1476-
);
1477-
rustc_errors::add_elided_lifetime_in_path_suggestion(
1478-
sess.source_map(),
1479-
&mut err,
1480-
expected_lifetimes,
1481-
path_span,
1482-
!segment.has_generic_args,
1483-
elided_lifetime_span,
1484-
);
1485-
err.note("assuming a `'static` lifetime...");
1486-
err.emit();
1487-
for i in 0..expected_lifetimes {
1488-
let id = node_ids.start.plus(i);
1489-
self.record_lifetime_res(id, LifetimeRes::Error);
1490-
}
1491-
continue 'segment;
1492-
}
14931462
LifetimeRibKind::AnonymousCreateParameter(binder) => {
14941463
let ident = Ident::new(kw::UnderscoreLifetime, elided_lifetime_span);
14951464
for i in 0..expected_lifetimes {
@@ -2096,14 +2065,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
20962065
let mut new_id = None;
20972066
if let Some(trait_ref) = opt_trait_ref {
20982067
let path: Vec<_> = Segment::from_path(&trait_ref.path);
2099-
let res = self.with_lifetime_rib(LifetimeRibKind::ReportElidedInPath, |this| {
2100-
this.smart_resolve_path_fragment(
2101-
None,
2102-
&path,
2103-
PathSource::Trait(AliasPossibility::No),
2104-
Finalize::new(trait_ref.ref_id, trait_ref.path.span),
2105-
)
2106-
});
2068+
let res = self.smart_resolve_path_fragment(
2069+
None,
2070+
&path,
2071+
PathSource::Trait(AliasPossibility::No),
2072+
Finalize::new(trait_ref.ref_id, trait_ref.path.span),
2073+
);
21072074
if let Some(def_id) = res.base_res().opt_def_id() {
21082075
new_id = Some(def_id);
21092076
new_val = Some((self.r.expect_module(def_id), trait_ref.clone()));
@@ -2156,16 +2123,14 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
21562123
let res =
21572124
Res::SelfTy { trait_: trait_id, alias_to: Some((item_def_id, false)) };
21582125
this.with_self_rib(res, |this| {
2159-
this.with_lifetime_rib(LifetimeRibKind::ReportElidedInPath, |this| {
2160-
if let Some(trait_ref) = opt_trait_reference.as_ref() {
2161-
// Resolve type arguments in the trait path.
2162-
visit::walk_trait_ref(this, trait_ref);
2163-
}
2164-
// Resolve the self type.
2165-
this.visit_ty(self_type);
2166-
// Resolve the generic parameters.
2167-
this.visit_generics(generics);
2168-
});
2126+
if let Some(trait_ref) = opt_trait_reference.as_ref() {
2127+
// Resolve type arguments in the trait path.
2128+
visit::walk_trait_ref(this, trait_ref);
2129+
}
2130+
// Resolve the self type.
2131+
this.visit_ty(self_type);
2132+
// Resolve the generic parameters.
2133+
this.visit_generics(generics);
21692134

21702135
// Resolve the items within the impl.
21712136
this.with_lifetime_rib(LifetimeRibKind::AnonymousPassThrough(item_id,false),

src/test/ui/async-await/async-fn-path-elision.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// edition:2018
2+
#![deny(elided_lifetimes_in_paths)]
23

34
struct HasLifetime<'a>(&'a bool);
45

5-
async fn error(lt: HasLifetime) { //~ ERROR implicit elided lifetime not allowed here
6+
async fn error(lt: HasLifetime) { //~ ERROR hidden lifetime parameters in types are deprecated
67
if *lt.0 {}
78
}
89

9-
fn no_error(lt: HasLifetime) {
10+
fn also_error(lt: HasLifetime) { //~ ERROR hidden lifetime parameters in types are deprecated
1011
if *lt.0 {}
1112
}
1213

src/test/ui/async-await/async-fn-path-elision.stderr

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
error[E0726]: implicit elided lifetime not allowed here
2-
--> $DIR/async-fn-path-elision.rs:5:20
1+
error: hidden lifetime parameters in types are deprecated
2+
--> $DIR/async-fn-path-elision.rs:6:20
33
|
44
LL | async fn error(lt: HasLifetime) {
55
| ^^^^^^^^^^^ expected lifetime parameter
66
|
7-
= note: assuming a `'static` lifetime...
7+
note: the lint level is defined here
8+
--> $DIR/async-fn-path-elision.rs:2:9
9+
|
10+
LL | #![deny(elided_lifetimes_in_paths)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
812
help: indicate the anonymous lifetime
913
|
1014
LL | async fn error(lt: HasLifetime<'_>) {
1115
| ++++
1216

13-
error: aborting due to previous error
17+
error: hidden lifetime parameters in types are deprecated
18+
--> $DIR/async-fn-path-elision.rs:10:19
19+
|
20+
LL | fn also_error(lt: HasLifetime) {
21+
| ^^^^^^^^^^^ expected lifetime parameter
22+
|
23+
help: indicate the anonymous lifetime
24+
|
25+
LL | fn also_error(lt: HasLifetime<'_>) {
26+
| ++++
27+
28+
error: aborting due to 2 previous errors
1429

15-
For more information about this error, try `rustc --explain E0726`.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#![allow(warnings)]
1+
#![deny(elided_lifetimes_in_paths)]
22

33
trait MyTrait { }
44

55
struct Foo<'a> { x: &'a u32 }
66

77
impl MyTrait for Foo {
8-
//~^ ERROR implicit elided lifetime not allowed here
8+
//~^ ERROR hidden lifetime parameters in types are deprecated [elided_lifetimes_in_paths]
99
}
1010

1111
fn main() {}

src/test/ui/impl-header-lifetime-elision/path-elided.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
error[E0726]: implicit elided lifetime not allowed here
1+
error: hidden lifetime parameters in types are deprecated
22
--> $DIR/path-elided.rs:7:18
33
|
44
LL | impl MyTrait for Foo {
55
| ^^^ expected lifetime parameter
66
|
7-
= note: assuming a `'static` lifetime...
7+
note: the lint level is defined here
8+
--> $DIR/path-elided.rs:1:9
9+
|
10+
LL | #![deny(elided_lifetimes_in_paths)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
812
help: indicate the anonymous lifetime
913
|
1014
LL | impl MyTrait for Foo<'_> {
1115
| ++++
1216

1317
error: aborting due to previous error
1418

15-
For more information about this error, try `rustc --explain E0726`.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#![allow(warnings)]
1+
#![deny(elided_lifetimes_in_paths)]
22

33
trait MyTrait<'a> {}
44

55
impl MyTrait for u32 {}
6-
//~^ ERROR implicit elided lifetime not allowed here
6+
//~^ ERROR hidden lifetime parameters in types are deprecated [elided_lifetimes_in_paths]
77

88
fn main() {}

src/test/ui/impl-header-lifetime-elision/trait-elided.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
error[E0726]: implicit elided lifetime not allowed here
1+
error: hidden lifetime parameters in types are deprecated
22
--> $DIR/trait-elided.rs:5:6
33
|
44
LL | impl MyTrait for u32 {}
55
| ^^^^^^^ expected lifetime parameter
66
|
7-
= note: assuming a `'static` lifetime...
7+
note: the lint level is defined here
8+
--> $DIR/trait-elided.rs:1:9
9+
|
10+
LL | #![deny(elided_lifetimes_in_paths)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
812
help: indicate the anonymous lifetime
913
|
1014
LL | impl MyTrait<'_> for u32 {}
1115
| ++++
1216

1317
error: aborting due to previous error
1418

15-
For more information about this error, try `rustc --explain E0726`.

src/test/ui/issues/issue-10412.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ trait Serializable<'self, T> {
77
impl<'self> Serializable<str> for &'self str {
88
//~^ ERROR lifetimes cannot use keyword names
99
//~| ERROR lifetimes cannot use keyword names
10-
//~| ERROR implicit elided lifetime not allowed here
1110
//~| ERROR the size for values of type `str` cannot be known at compilation time [E0277]
1211
fn serialize(val: &'self str) -> Vec<u8> {
1312
//~^ ERROR lifetimes cannot use keyword names

src/test/ui/issues/issue-10412.stderr

+4-17
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,17 @@ LL | impl<'self> Serializable<str> for &'self str {
2929
| ^^^^^
3030

3131
error: lifetimes cannot use keyword names
32-
--> $DIR/issue-10412.rs:12:24
32+
--> $DIR/issue-10412.rs:11:24
3333
|
3434
LL | fn serialize(val: &'self str) -> Vec<u8> {
3535
| ^^^^^
3636

3737
error: lifetimes cannot use keyword names
38-
--> $DIR/issue-10412.rs:16:37
38+
--> $DIR/issue-10412.rs:15:37
3939
|
4040
LL | fn deserialize(repr: &[u8]) -> &'self str {
4141
| ^^^^^
4242

43-
error[E0726]: implicit elided lifetime not allowed here
44-
--> $DIR/issue-10412.rs:7:13
45-
|
46-
LL | impl<'self> Serializable<str> for &'self str {
47-
| ^^^^^^^^^^^^^^^^^ expected lifetime parameter
48-
|
49-
= note: assuming a `'static` lifetime...
50-
help: indicate the anonymous lifetime
51-
|
52-
LL | impl<'self> Serializable<'_, str> for &'self str {
53-
| +++
54-
5543
error[E0277]: the size for values of type `str` cannot be known at compilation time
5644
--> $DIR/issue-10412.rs:7:13
5745
|
@@ -69,7 +57,6 @@ help: consider relaxing the implicit `Sized` restriction
6957
LL | trait Serializable<'self, T: ?Sized> {
7058
| ++++++++
7159

72-
error: aborting due to 9 previous errors
60+
error: aborting due to 8 previous errors
7361

74-
Some errors have detailed explanations: E0277, E0726.
75-
For more information about an error, try `rustc --explain E0277`.
62+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// check-pass
12
// Regression test for #80468.
23

34
#![crate_type = "lib"]
@@ -10,8 +11,8 @@ pub struct Wrapper<T: Trait>(T);
1011
#[repr(transparent)]
1112
pub struct Ref<'a>(&'a u8);
1213

13-
impl Trait for Ref {} //~ ERROR: implicit elided lifetime not allowed here
14+
impl Trait for Ref {}
1415

1516
extern "C" {
16-
pub fn repro(_: Wrapper<Ref>); //~ ERROR: incompatible lifetime on type
17+
pub fn repro(_: Wrapper<Ref>);
1718
}

src/test/ui/wf/wf-in-foreign-fn-decls-issue-80468.stderr

-37
This file was deleted.

0 commit comments

Comments
 (0)