Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cc85718

Browse files
committedFeb 11, 2024
Split elided_lifetime_in_paths into tied and untied
Types that contain a reference can be confusing when lifetime elision occurs: ```rust // Confusing fn foo(_: &u8) -> Bar { todo!() } // Less confusing fn foo(_: &u8) -> Bar<'_> { todo!() } ``` However, the previous lint did not distinguish when these types were not "tying" lifetimes across the function inputs / outputs: ```rust // Maybe a little confusing fn foo(_: Bar) {} // More explicit but noisier with less obvious value fn foo(_: Bar<'_>) {} ``` We now report different lints for each case, hopefully paving the way to marking the first case (when lifetimes are tied together) as warn-by-default.
1 parent f914d68 commit cc85718

File tree

11 files changed

+553
-29
lines changed

11 files changed

+553
-29
lines changed
 

‎compiler/rustc_lint/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ fn register_builtins(store: &mut LintStore) {
303303
BARE_TRAIT_OBJECTS,
304304
UNUSED_EXTERN_CRATES,
305305
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
306-
ELIDED_LIFETIMES_IN_PATHS,
306+
ELIDED_LIFETIMES_IN_PATHS_TIED,
307+
ELIDED_LIFETIMES_IN_PATHS_UNTIED,
307308
EXPLICIT_OUTLIVES_REQUIREMENTS,
308309
// FIXME(#52665, #47816) not always applicable and not all
309310
// macros are ready for this yet.
@@ -313,6 +314,12 @@ fn register_builtins(store: &mut LintStore) {
313314
// MACRO_USE_EXTERN_CRATE
314315
);
315316

317+
add_lint_group!(
318+
"elided_lifetimes_in_paths",
319+
ELIDED_LIFETIMES_IN_PATHS_TIED,
320+
ELIDED_LIFETIMES_IN_PATHS_UNTIED,
321+
);
322+
316323
// Register renamed and removed lints.
317324
store.register_renamed("single_use_lifetime", "single_use_lifetimes");
318325
// store.register_renamed("elided_lifetime_in_path", "elided_lifetimes_in_paths");

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ declare_lint_pass! {
4040
DEPRECATED_WHERE_CLAUSE_LOCATION,
4141
DUPLICATE_MACRO_ATTRIBUTES,
4242
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
43-
ELIDED_LIFETIMES_IN_PATHS,
43+
ELIDED_LIFETIMES_IN_PATHS_TIED,
44+
ELIDED_LIFETIMES_IN_PATHS_UNTIED,
4445
EXPORTED_PRIVATE_DEPENDENCIES,
4546
FFI_UNWIND_CALLS,
4647
FORBIDDEN_LINT_GROUPS,
@@ -1701,19 +1702,21 @@ declare_lint! {
17011702
}
17021703

17031704
declare_lint! {
1704-
/// The `elided_lifetimes_in_paths` lint detects the use of hidden
1705-
/// lifetime parameters.
1705+
/// The `elided_lifetimes_in_paths_tied` lint detects the use of
1706+
/// hidden lifetime parameters when those lifetime parameters tie
1707+
/// an input lifetime parameter to an output lifetime parameter.
17061708
///
17071709
/// ### Example
17081710
///
17091711
/// ```rust,compile_fail
1710-
/// #![deny(elided_lifetimes_in_paths)]
1712+
/// #![deny(elided_lifetimes_in_paths_tied)]
17111713
/// #![deny(warnings)]
17121714
/// struct Foo<'a> {
17131715
/// x: &'a u32
17141716
/// }
17151717
///
1716-
/// fn foo(x: &Foo) {
1718+
/// fn foo(x: Foo) -> &u32 {
1719+
/// &x.0
17171720
/// }
17181721
/// ```
17191722
///
@@ -1730,12 +1733,51 @@ declare_lint! {
17301733
/// may require a significant transition for old code.
17311734
///
17321735
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1733-
pub ELIDED_LIFETIMES_IN_PATHS,
1736+
pub ELIDED_LIFETIMES_IN_PATHS_TIED,
17341737
Allow,
17351738
"hidden lifetime parameters in types are deprecated",
17361739
crate_level_only
17371740
}
17381741

1742+
declare_lint! {
1743+
/// The `elided_lifetimes_in_paths_untied` lint detects the use of
1744+
/// hidden lifetime parameters when those lifetime parameters do
1745+
/// not tie an input lifetime parameter to an output lifetime
1746+
/// parameter.
1747+
///
1748+
/// ### Example
1749+
///
1750+
/// ```rust,compile_fail
1751+
/// #![deny(elided_lifetimes_in_paths_untied)]
1752+
/// #![deny(warnings)]
1753+
/// struct Foo<'a> {
1754+
/// x: &'a u32
1755+
/// }
1756+
///
1757+
/// fn foo(x: Foo) -> u32 {
1758+
/// x.0
1759+
/// }
1760+
/// ```
1761+
///
1762+
/// {{produces}}
1763+
///
1764+
/// ### Explanation
1765+
///
1766+
/// Elided lifetime parameters can make it difficult to see at a glance
1767+
/// that borrowing is occurring. This lint ensures that lifetime
1768+
/// parameters are always explicitly stated, even if it is the `'_`
1769+
/// [placeholder lifetime].
1770+
///
1771+
/// This lint is "allow" by default because it has some known issues, and
1772+
/// may require a significant transition for old code.
1773+
///
1774+
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1775+
pub ELIDED_LIFETIMES_IN_PATHS_UNTIED,
1776+
Allow,
1777+
"hidden lifetime parameters in types make it hard to tell when borrowing is happening",
1778+
crate_level_only
1779+
}
1780+
17391781
declare_lint! {
17401782
/// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
17411783
/// objects.

‎compiler/rustc_resolve/src/late.rs

Lines changed: 99 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,24 @@ struct DiagnosticMetadata<'ast> {
646646
}
647647

648648
#[derive(Debug)]
649-
struct ResolvedNestedElisionTarget {
649+
enum ResolvedElisionTarget {
650+
/// Elision in `&u8` -> `&'_ u8`
651+
TopLevel(NodeId),
652+
/// Elision in `Foo` -> `Foo<'_>`
653+
Nested(NestedResolvedElisionTarget),
654+
}
655+
656+
impl ResolvedElisionTarget {
657+
fn node_id(&self) -> NodeId {
658+
match *self {
659+
Self::TopLevel(n) => n,
660+
Self::Nested(NestedResolvedElisionTarget { segment_id, .. }) => segment_id,
661+
}
662+
}
663+
}
664+
665+
#[derive(Debug)]
666+
struct NestedResolvedElisionTarget {
650667
segment_id: NodeId,
651668
elided_lifetime_span: Span,
652669
diagnostic: lint::BuiltinLintDiagnostics,
@@ -694,7 +711,7 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
694711
lifetime_uses: FxHashMap<LocalDefId, LifetimeUseSet>,
695712

696713
/// Track which types participated in lifetime elision
697-
resolved_lifetime_elisions: Vec<ResolvedNestedElisionTarget>,
714+
resolved_lifetime_elisions: Vec<ResolvedElisionTarget>,
698715
}
699716

700717
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -1745,6 +1762,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17451762
LifetimeElisionCandidate::Ignore,
17461763
);
17471764
self.resolve_anonymous_lifetime(&lt, true);
1765+
1766+
self.resolved_lifetime_elisions.push(ResolvedElisionTarget::TopLevel(anchor_id));
17481767
}
17491768

17501769
#[instrument(level = "debug", skip(self))]
@@ -1957,16 +1976,18 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
19571976
}
19581977

19591978
if should_lint {
1960-
self.resolved_lifetime_elisions.push(ResolvedNestedElisionTarget {
1961-
segment_id,
1962-
elided_lifetime_span,
1963-
diagnostic: lint::BuiltinLintDiagnostics::ElidedLifetimesInPaths(
1964-
expected_lifetimes,
1965-
path_span,
1966-
!segment.has_generic_args,
1979+
self.resolved_lifetime_elisions.push(ResolvedElisionTarget::Nested(
1980+
NestedResolvedElisionTarget {
1981+
segment_id,
19671982
elided_lifetime_span,
1968-
),
1969-
});
1983+
diagnostic: lint::BuiltinLintDiagnostics::ElidedLifetimesInPaths(
1984+
expected_lifetimes,
1985+
path_span,
1986+
!segment.has_generic_args,
1987+
elided_lifetime_span,
1988+
),
1989+
},
1990+
));
19701991
}
19711992
}
19721993
}
@@ -2028,22 +2049,80 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20282049

20292050
let elision_failures =
20302051
replace(&mut self.diagnostic_metadata.current_elision_failures, outer_failures);
2031-
if !elision_failures.is_empty() {
2032-
let Err(failure_info) = elision_lifetime else { bug!() };
2033-
self.report_missing_lifetime_specifiers(elision_failures, Some(failure_info));
2034-
}
2052+
2053+
let elision_lifetime = match (elision_failures.is_empty(), elision_lifetime) {
2054+
(true, Ok(lifetime)) => Some(lifetime),
2055+
2056+
(true, Err(_)) => None,
2057+
2058+
(false, Ok(_)) => bug!(),
2059+
2060+
(false, Err(failure_info)) => {
2061+
self.report_missing_lifetime_specifiers(elision_failures, Some(failure_info));
2062+
None
2063+
}
2064+
};
2065+
2066+
// We've recorded all elisions that occurred in the params and
2067+
// outputs, categorized by top-level or nested.
2068+
//
2069+
// Our primary lint case is when an output lifetime is tied to
2070+
// an input lifetime. In that case, we want to warn about any
2071+
// parameters that had a nested elision.
2072+
//
2073+
// The secondary case is for nested elisions that are not part
2074+
// of the tied lifetime relationship.
20352075

20362076
let output_resolved_lifetime_elisions =
20372077
replace(&mut self.resolved_lifetime_elisions, outer_resolved_lifetime_elisions);
20382078

2039-
let resolved_lifetime_elisions =
2040-
param_resolved_lifetime_elisions.into_iter().chain(output_resolved_lifetime_elisions);
2079+
match (output_resolved_lifetime_elisions.is_empty(), elision_lifetime) {
2080+
(true, _) | (_, None) => {
2081+
// Treat all parameters as untied
2082+
self.report_elided_lifetimes_in_paths(
2083+
param_resolved_lifetime_elisions,
2084+
lint::builtin::ELIDED_LIFETIMES_IN_PATHS_UNTIED,
2085+
);
2086+
}
2087+
(false, Some(elision_lifetime)) => {
2088+
let (primary, secondary): (Vec<_>, Vec<_>) =
2089+
param_resolved_lifetime_elisions.into_iter().partition(|re| {
2090+
// Recover the `NodeId` of an elided lifetime
2091+
let lvl1 = &self.r.lifetimes_res_map[&re.node_id()];
2092+
let lvl2 = match lvl1 {
2093+
LifetimeRes::ElidedAnchor { start, .. } => {
2094+
&self.r.lifetimes_res_map[&start]
2095+
}
2096+
o => o,
2097+
};
2098+
2099+
lvl2 == &elision_lifetime
2100+
});
2101+
2102+
self.report_elided_lifetimes_in_paths(
2103+
primary.into_iter().chain(output_resolved_lifetime_elisions),
2104+
lint::builtin::ELIDED_LIFETIMES_IN_PATHS_TIED,
2105+
);
2106+
self.report_elided_lifetimes_in_paths(
2107+
secondary,
2108+
lint::builtin::ELIDED_LIFETIMES_IN_PATHS_UNTIED,
2109+
);
2110+
}
2111+
}
2112+
}
2113+
2114+
fn report_elided_lifetimes_in_paths(
2115+
&mut self,
2116+
resolved_elisions: impl IntoIterator<Item = ResolvedElisionTarget>,
2117+
lint: &'static lint::Lint,
2118+
) {
2119+
for re in resolved_elisions {
2120+
let ResolvedElisionTarget::Nested(d) = re else { continue };
20412121

2042-
for re in resolved_lifetime_elisions {
2043-
let ResolvedNestedElisionTarget { segment_id, elided_lifetime_span, diagnostic } = re;
2122+
let NestedResolvedElisionTarget { segment_id, elided_lifetime_span, diagnostic } = d;
20442123

20452124
self.r.lint_buffer.buffer_lint_with_diagnostic(
2046-
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
2125+
lint,
20472126
segment_id,
20482127
elided_lifetime_span,
20492128
"hidden lifetime parameters in types are deprecated",

‎src/tools/lint-docs/src/groups.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static GROUP_DESCRIPTIONS: &[(&str, &str)] = &[
1111
("let-underscore", "Lints that detect wildcard let bindings that are likely to be invalid"),
1212
("rustdoc", "Rustdoc-specific lints"),
1313
("rust-2018-idioms", "Lints to nudge you toward idiomatic features of Rust 2018"),
14+
("elided-lifetimes-in-paths", "Lints that detect the use of hidden lifetime parameters"),
1415
("nonstandard-style", "Violation of standard naming conventions"),
1516
("future-incompatible", "Lints that detect code that has future-compatibility problems"),
1617
("rust-2018-compatibility", "Lints used to transition code from the 2015 edition to 2018"),
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
// revisions: tied untied
2+
3+
#![cfg_attr(tied, deny(elided_lifetimes_in_paths_tied))]
4+
#![cfg_attr(untied, deny(elided_lifetimes_in_paths_untied))]
5+
6+
struct ContainsLifetime<'a>(&'a u8);
7+
8+
// ==========
9+
// Core desired functionality
10+
11+
fn top_level_to_nested(v: &u8) ->
12+
ContainsLifetime
13+
//[tied]~^ ERROR hidden lifetime parameters
14+
{
15+
ContainsLifetime(v)
16+
}
17+
18+
fn nested_to_top_level(
19+
v: ContainsLifetime,
20+
//[tied]~^ ERROR hidden lifetime parameters
21+
) -> &u8
22+
{
23+
v.0
24+
}
25+
26+
fn nested_to_nested(
27+
v: ContainsLifetime,
28+
//[tied]~^ ERROR hidden lifetime parameters
29+
) -> ContainsLifetime
30+
//[tied]~^ ERROR hidden lifetime parameters
31+
{
32+
v
33+
}
34+
35+
fn top_level_to_top_level(v: &u8) -> &u8 {
36+
v
37+
}
38+
39+
// ==========
40+
// Mixed named and elided lifetimes
41+
42+
fn named_top_level_to_nested<'a>(v: &'a u8) ->
43+
ContainsLifetime
44+
//[tied]~^ ERROR hidden lifetime parameters
45+
{
46+
ContainsLifetime(v)
47+
}
48+
49+
// ==========
50+
// Using named lifetimes everywhere should not report
51+
52+
fn named_top_level_to_named_nested<'a>(v: &'a u8) -> ContainsLifetime<'a> {
53+
ContainsLifetime(v)
54+
}
55+
56+
fn named_nested_to_named_top_level<'a>(v: ContainsLifetime<'a>) -> &'a u8 {
57+
v.0
58+
}
59+
60+
fn named_nested_to_named_nested<'a>(v: ContainsLifetime<'a>) -> ContainsLifetime<'a> {
61+
v
62+
}
63+
64+
// ==========
65+
// Lifetimes with nothing to tie to
66+
67+
fn top_level_parameter(v: &u8) {}
68+
69+
fn nested_parameter(v: ContainsLifetime) {}
70+
//[untied]~^ ERROR hidden lifetime parameters
71+
72+
fn top_level_nested_parameter(v: &ContainsLifetime) {}
73+
//[untied]~^ ERROR hidden lifetime parameters
74+
75+
// ==========
76+
// More complicated types
77+
78+
fn top_level_to_multiple_nested(v: &u8) -> (
79+
ContainsLifetime,
80+
//[tied]~^ ERROR hidden lifetime parameters
81+
ContainsLifetime,
82+
//[tied]~^ ERROR hidden lifetime parameters
83+
)
84+
{
85+
(ContainsLifetime(v), ContainsLifetime(v))
86+
}
87+
88+
// ----------
89+
90+
struct AsAMethod(u8);
91+
92+
impl AsAMethod {
93+
fn top_level_to_nested(v: &u8) ->
94+
ContainsLifetime
95+
//[tied]~^ ERROR hidden lifetime parameters
96+
{
97+
ContainsLifetime(v)
98+
}
99+
100+
fn nested_to_top_level(
101+
v: ContainsLifetime,
102+
//[tied]~^ ERROR hidden lifetime parameters
103+
) -> &u8
104+
{
105+
v.0
106+
}
107+
108+
fn nested_to_nested(
109+
v: ContainsLifetime,
110+
//[tied]~^ ERROR hidden lifetime parameters
111+
) -> ContainsLifetime
112+
//[tied]~^ ERROR hidden lifetime parameters
113+
{
114+
v
115+
}
116+
117+
fn top_level_to_top_level(v: &u8) -> &u8 {
118+
v
119+
}
120+
121+
fn self_to_nested(&self) ->
122+
ContainsLifetime
123+
//[tied]~^ ERROR hidden lifetime parameters
124+
{
125+
ContainsLifetime(&self.0)
126+
}
127+
128+
fn self_to_nested_with_irrelevant_top_level_parameter(&self, _: &u8) ->
129+
ContainsLifetime
130+
//[tied]~^ ERROR hidden lifetime parameters
131+
{
132+
ContainsLifetime(&self.0)
133+
}
134+
135+
fn self_to_nested_with_irrelevant_nested_parameter(
136+
&self,
137+
_: ContainsLifetime,
138+
//[untied]~^ ERROR hidden lifetime parameters
139+
) -> ContainsLifetime
140+
//[tied]~^ ERROR hidden lifetime parameters
141+
{
142+
ContainsLifetime(&self.0)
143+
}
144+
145+
fn nested_in_parameter(
146+
&self,
147+
v: ContainsLifetime,
148+
//[untied]~^ ERROR hidden lifetime parameters
149+
) {}
150+
151+
fn nested_in_parameter_with_return(
152+
&self,
153+
v: ContainsLifetime,
154+
//[untied]~^ ERROR hidden lifetime parameters
155+
) -> &u8
156+
{
157+
&self.0
158+
}
159+
}
160+
161+
// // Do we need to worry about nested function signatures?
162+
// // fn outer(_: fn(&) -> &)
163+
164+
// // Do we need to worry about closures?
165+
166+
// // Do we need to write tests for `self: Foo` syntax?
167+
168+
fn main() {}
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
error: hidden lifetime parameters in types are deprecated
2+
--> $DIR/elided-lifetime-in-path-details.rs:12:5
3+
|
4+
LL | ContainsLifetime
5+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/elided-lifetime-in-path-details.rs:3:24
9+
|
10+
LL | #![cfg_attr(tied, deny(elided_lifetimes_in_paths_tied))]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: indicate the anonymous lifetime
13+
|
14+
LL | ContainsLifetime<'_>
15+
| ++++
16+
17+
error: hidden lifetime parameters in types are deprecated
18+
--> $DIR/elided-lifetime-in-path-details.rs:19:8
19+
|
20+
LL | v: ContainsLifetime,
21+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
22+
|
23+
help: indicate the anonymous lifetime
24+
|
25+
LL | v: ContainsLifetime<'_>,
26+
| ++++
27+
28+
error: hidden lifetime parameters in types are deprecated
29+
--> $DIR/elided-lifetime-in-path-details.rs:27:8
30+
|
31+
LL | v: ContainsLifetime,
32+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
33+
|
34+
help: indicate the anonymous lifetime
35+
|
36+
LL | v: ContainsLifetime<'_>,
37+
| ++++
38+
39+
error: hidden lifetime parameters in types are deprecated
40+
--> $DIR/elided-lifetime-in-path-details.rs:29:6
41+
|
42+
LL | ) -> ContainsLifetime
43+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
44+
|
45+
help: indicate the anonymous lifetime
46+
|
47+
LL | ) -> ContainsLifetime<'_>
48+
| ++++
49+
50+
error: hidden lifetime parameters in types are deprecated
51+
--> $DIR/elided-lifetime-in-path-details.rs:43:5
52+
|
53+
LL | ContainsLifetime
54+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
55+
|
56+
help: indicate the anonymous lifetime
57+
|
58+
LL | ContainsLifetime<'_>
59+
| ++++
60+
61+
error: hidden lifetime parameters in types are deprecated
62+
--> $DIR/elided-lifetime-in-path-details.rs:79:5
63+
|
64+
LL | ContainsLifetime,
65+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
66+
|
67+
help: indicate the anonymous lifetime
68+
|
69+
LL | ContainsLifetime<'_>,
70+
| ++++
71+
72+
error: hidden lifetime parameters in types are deprecated
73+
--> $DIR/elided-lifetime-in-path-details.rs:81:5
74+
|
75+
LL | ContainsLifetime,
76+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
77+
|
78+
help: indicate the anonymous lifetime
79+
|
80+
LL | ContainsLifetime<'_>,
81+
| ++++
82+
83+
error: hidden lifetime parameters in types are deprecated
84+
--> $DIR/elided-lifetime-in-path-details.rs:94:9
85+
|
86+
LL | ContainsLifetime
87+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
88+
|
89+
help: indicate the anonymous lifetime
90+
|
91+
LL | ContainsLifetime<'_>
92+
| ++++
93+
94+
error: hidden lifetime parameters in types are deprecated
95+
--> $DIR/elided-lifetime-in-path-details.rs:101:12
96+
|
97+
LL | v: ContainsLifetime,
98+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
99+
|
100+
help: indicate the anonymous lifetime
101+
|
102+
LL | v: ContainsLifetime<'_>,
103+
| ++++
104+
105+
error: hidden lifetime parameters in types are deprecated
106+
--> $DIR/elided-lifetime-in-path-details.rs:109:12
107+
|
108+
LL | v: ContainsLifetime,
109+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
110+
|
111+
help: indicate the anonymous lifetime
112+
|
113+
LL | v: ContainsLifetime<'_>,
114+
| ++++
115+
116+
error: hidden lifetime parameters in types are deprecated
117+
--> $DIR/elided-lifetime-in-path-details.rs:111:10
118+
|
119+
LL | ) -> ContainsLifetime
120+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
121+
|
122+
help: indicate the anonymous lifetime
123+
|
124+
LL | ) -> ContainsLifetime<'_>
125+
| ++++
126+
127+
error: hidden lifetime parameters in types are deprecated
128+
--> $DIR/elided-lifetime-in-path-details.rs:122:9
129+
|
130+
LL | ContainsLifetime
131+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
132+
|
133+
help: indicate the anonymous lifetime
134+
|
135+
LL | ContainsLifetime<'_>
136+
| ++++
137+
138+
error: hidden lifetime parameters in types are deprecated
139+
--> $DIR/elided-lifetime-in-path-details.rs:129:9
140+
|
141+
LL | ContainsLifetime
142+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
143+
|
144+
help: indicate the anonymous lifetime
145+
|
146+
LL | ContainsLifetime<'_>
147+
| ++++
148+
149+
error: hidden lifetime parameters in types are deprecated
150+
--> $DIR/elided-lifetime-in-path-details.rs:139:10
151+
|
152+
LL | ) -> ContainsLifetime
153+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
154+
|
155+
help: indicate the anonymous lifetime
156+
|
157+
LL | ) -> ContainsLifetime<'_>
158+
| ++++
159+
160+
error: aborting due to 14 previous errors
161+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error: hidden lifetime parameters in types are deprecated
2+
--> $DIR/elided-lifetime-in-path-details.rs:69:24
3+
|
4+
LL | fn nested_parameter(v: ContainsLifetime) {}
5+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/elided-lifetime-in-path-details.rs:4:26
9+
|
10+
LL | #![cfg_attr(untied, deny(elided_lifetimes_in_paths_untied))]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: indicate the anonymous lifetime
13+
|
14+
LL | fn nested_parameter(v: ContainsLifetime<'_>) {}
15+
| ++++
16+
17+
error: hidden lifetime parameters in types are deprecated
18+
--> $DIR/elided-lifetime-in-path-details.rs:72:35
19+
|
20+
LL | fn top_level_nested_parameter(v: &ContainsLifetime) {}
21+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
22+
|
23+
help: indicate the anonymous lifetime
24+
|
25+
LL | fn top_level_nested_parameter(v: &ContainsLifetime<'_>) {}
26+
| ++++
27+
28+
error: hidden lifetime parameters in types are deprecated
29+
--> $DIR/elided-lifetime-in-path-details.rs:137:12
30+
|
31+
LL | _: ContainsLifetime,
32+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
33+
|
34+
help: indicate the anonymous lifetime
35+
|
36+
LL | _: ContainsLifetime<'_>,
37+
| ++++
38+
39+
error: hidden lifetime parameters in types are deprecated
40+
--> $DIR/elided-lifetime-in-path-details.rs:147:12
41+
|
42+
LL | v: ContainsLifetime,
43+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
44+
|
45+
help: indicate the anonymous lifetime
46+
|
47+
LL | v: ContainsLifetime<'_>,
48+
| ++++
49+
50+
error: hidden lifetime parameters in types are deprecated
51+
--> $DIR/elided-lifetime-in-path-details.rs:153:12
52+
|
53+
LL | v: ContainsLifetime,
54+
| ^^^^^^^^^^^^^^^^ expected lifetime parameter
55+
|
56+
help: indicate the anonymous lifetime
57+
|
58+
LL | v: ContainsLifetime<'_>,
59+
| ++++
60+
61+
error: aborting due to 5 previous errors
62+

‎tests/ui/lifetimes/issue-91763.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ note: the lint level is defined here
99
|
1010
LL | #![deny(elided_lifetimes_in_paths)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: `#[deny(elided_lifetimes_in_paths_untied)]` implied by `#[deny(elided_lifetimes_in_paths)]`
1213
help: indicate the anonymous lifetime
1314
|
1415
LL | fn f() -> Ptr<Thing><'_>;

‎tests/ui/lint/force-warn/allowed-by-default-lint.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ warning: hidden lifetime parameters in types are deprecated
44
LL | fn foo(x: &Foo) {}
55
| ^^^ expected lifetime parameter
66
|
7-
= note: requested on the command line with `--force-warn elided-lifetimes-in-paths`
7+
= note: `--force-warn elided-lifetimes-in-paths-untied` implied by `--force-warn elided-lifetimes-in-paths`
8+
= help: to override `--force-warn elided-lifetimes-in-paths` add `#[allow(elided_lifetimes_in_paths_untied)]`
89
help: indicate the anonymous lifetime
910
|
1011
LL | fn foo(x: &Foo<'_>) {}

‎tests/ui/lint/reasons.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct CheaterDetectionMechanism {}
1919
impl fmt::Debug for CheaterDetectionMechanism {
2020
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
2121
//~^ WARN hidden lifetime parameters in types are deprecated
22+
//~| NOTE implied by
2223
//~| NOTE expected lifetime parameter
2324
//~| NOTE explicit anonymous lifetimes aid
2425
//~| HELP indicate the anonymous lifetime

‎tests/ui/lint/reasons.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ note: the lint level is defined here
1212
|
1313
LL | #![warn(elided_lifetimes_in_paths,
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+
= note: `#[warn(elided_lifetimes_in_paths_untied)]` implied by `#[warn(elided_lifetimes_in_paths)]`
1516
help: indicate the anonymous lifetime
1617
|
1718
LL | fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1819
| ++++
1920

2021
warning: variable `Social_exchange_psychology` should have a snake case name
21-
--> $DIR/reasons.rs:30:9
22+
--> $DIR/reasons.rs:31:9
2223
|
2324
LL | let Social_exchange_psychology = CheaterDetectionMechanism {};
2425
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case (notice the capitalization): `social_exchange_psychology`

0 commit comments

Comments
 (0)
Please sign in to comment.