Skip to content

Commit 88dd6fc

Browse files
committed
Rename elided_lifetimes_in_paths to lifetimes_hidden_in_paths
Technically, `&u8` has a hidden lifetime that becomes the anonymous lifetime `&'_ u8` which may then participate in elision in a function signature. We specifically don't want to warn about usages of the anonymous lifetime when it is part of elision.
1 parent f6d1275 commit 88dd6fc

16 files changed

+74
-73
lines changed

compiler/rustc_baked_icu_data/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
#![allow(internal_features)]
2424
#![feature(rustdoc_internals)]
2525
#![doc(rust_logo)]
26-
#![allow(elided_lifetimes_in_paths)]
26+
#![cfg_attr(bootstrap, allow(elided_lifetimes_in_paths))]
27+
#![cfg_attr(not(bootstrap), allow(lifetimes_hidden_in_paths))]
2728

2829
mod data {
2930
include!("data/mod.rs");

compiler/rustc_lint/src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -303,8 +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_TIED,
307-
ELIDED_LIFETIMES_IN_PATHS_UNTIED,
306+
TIED_LIFETIMES_HIDDEN_IN_PATHS,
307+
UNTIED_LIFETIMES_HIDDEN_IN_PATHS,
308308
EXPLICIT_OUTLIVES_REQUIREMENTS,
309309
// FIXME(#52665, #47816) not always applicable and not all
310310
// macros are ready for this yet.
@@ -315,9 +315,9 @@ fn register_builtins(store: &mut LintStore) {
315315
);
316316

317317
add_lint_group!(
318-
"elided_lifetimes_in_paths",
319-
ELIDED_LIFETIMES_IN_PATHS_TIED,
320-
ELIDED_LIFETIMES_IN_PATHS_UNTIED,
318+
"lifetimes_hidden_in_paths",
319+
TIED_LIFETIMES_HIDDEN_IN_PATHS,
320+
UNTIED_LIFETIMES_HIDDEN_IN_PATHS,
321321
);
322322

323323
// Register renamed and removed lints.
@@ -336,7 +336,8 @@ fn register_builtins(store: &mut LintStore) {
336336
store.register_renamed("static_mut_ref", "static_mut_refs");
337337

338338
// Register renamed lint groups
339-
store.register_renamed_group("elided_lifetime_in_path", "elided_lifetimes_in_paths");
339+
store.register_renamed_group("elided_lifetime_in_path", "lifetimes_hidden_in_paths");
340+
store.register_renamed_group("elided_lifetimes_in_paths", "lifetimes_hidden_in_paths");
340341

341342
// These were moved to tool lints, but rustc still sees them when compiling normally, before
342343
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use

compiler/rustc_lint_defs/src/builtin.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ declare_lint_pass! {
3939
DEPRECATED_WHERE_CLAUSE_LOCATION,
4040
DUPLICATE_MACRO_ATTRIBUTES,
4141
ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
42-
ELIDED_LIFETIMES_IN_PATHS_TIED,
43-
ELIDED_LIFETIMES_IN_PATHS_UNTIED,
4442
EXPORTED_PRIVATE_DEPENDENCIES,
4543
FFI_UNWIND_CALLS,
4644
FORBIDDEN_LINT_GROUPS,
@@ -93,6 +91,7 @@ declare_lint_pass! {
9391
STATIC_MUT_REFS,
9492
TEST_UNSTABLE_LINT,
9593
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
94+
TIED_LIFETIMES_HIDDEN_IN_PATHS,
9695
TRIVIAL_CASTS,
9796
TRIVIAL_NUMERIC_CASTS,
9897
TYVAR_BEHIND_RAW_POINTER,
@@ -113,6 +112,7 @@ declare_lint_pass! {
113112
UNSTABLE_NAME_COLLISIONS,
114113
UNSTABLE_SYNTAX_PRE_EXPANSION,
115114
UNSUPPORTED_CALLING_CONVENTIONS,
115+
UNTIED_LIFETIMES_HIDDEN_IN_PATHS,
116116
UNUSED_ASSIGNMENTS,
117117
UNUSED_ASSOCIATED_TYPE_BOUNDS,
118118
UNUSED_ATTRIBUTES,
@@ -1731,14 +1731,14 @@ declare_lint! {
17311731
}
17321732

17331733
declare_lint! {
1734-
/// The `elided_lifetimes_in_paths_tied` lint detects the use of
1734+
/// The `tied_lifetimes_hidden_in_paths` lint detects the use of
17351735
/// hidden lifetime parameters when those lifetime parameters tie
17361736
/// an input lifetime parameter to an output lifetime parameter.
17371737
///
17381738
/// ### Example
17391739
///
17401740
/// ```rust,compile_fail
1741-
/// #![deny(elided_lifetimes_in_paths_tied)]
1741+
/// #![deny(tied_lifetimes_hidden_in_paths)]
17421742
/// #![deny(warnings)]
17431743
/// struct Foo<'a> {
17441744
/// x: &'a u32
@@ -1753,7 +1753,7 @@ declare_lint! {
17531753
///
17541754
/// ### Explanation
17551755
///
1756-
/// Elided lifetime parameters can make it difficult to see at a glance
1756+
/// Hidden lifetime parameters can make it difficult to see at a glance
17571757
/// that borrowing is occurring. This lint ensures that lifetime
17581758
/// parameters are always explicitly stated, even if it is the `'_`
17591759
/// [placeholder lifetime].
@@ -1762,22 +1762,22 @@ declare_lint! {
17621762
/// may require a significant transition for old code.
17631763
///
17641764
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1765-
pub ELIDED_LIFETIMES_IN_PATHS_TIED,
1765+
pub TIED_LIFETIMES_HIDDEN_IN_PATHS,
17661766
Allow,
17671767
"hidden lifetime parameters in types are deprecated",
17681768
crate_level_only
17691769
}
17701770

17711771
declare_lint! {
1772-
/// The `elided_lifetimes_in_paths_untied` lint detects the use of
1772+
/// The `untied_lifetimes_hidden_in_paths` lint detects the use of
17731773
/// hidden lifetime parameters when those lifetime parameters do
17741774
/// not tie an input lifetime parameter to an output lifetime
17751775
/// parameter.
17761776
///
17771777
/// ### Example
17781778
///
17791779
/// ```rust,compile_fail
1780-
/// #![deny(elided_lifetimes_in_paths_untied)]
1780+
/// #![deny(untied_lifetimes_hidden_in_paths)]
17811781
/// #![deny(warnings)]
17821782
/// struct Foo<'a> {
17831783
/// x: &'a u32
@@ -1792,7 +1792,7 @@ declare_lint! {
17921792
///
17931793
/// ### Explanation
17941794
///
1795-
/// Elided lifetime parameters can make it difficult to see at a glance
1795+
/// Hidden lifetime parameters can make it difficult to see at a glance
17961796
/// that borrowing is occurring. This lint ensures that lifetime
17971797
/// parameters are always explicitly stated, even if it is the `'_`
17981798
/// [placeholder lifetime].
@@ -1801,7 +1801,7 @@ declare_lint! {
18011801
/// may require a significant transition for old code.
18021802
///
18031803
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1804-
pub ELIDED_LIFETIMES_IN_PATHS_UNTIED,
1804+
pub UNTIED_LIFETIMES_HIDDEN_IN_PATHS,
18051805
Allow,
18061806
"hidden lifetime parameters in types make it hard to tell when borrowing is happening",
18071807
crate_level_only

compiler/rustc_resolve/src/late.rs

+39-40
Original file line numberDiff line numberDiff line change
@@ -646,26 +646,26 @@ struct DiagMetadata<'ast> {
646646
}
647647

648648
#[derive(Debug)]
649-
enum ResolvedElisionTarget {
650-
/// Elision in `&u8` -> `&'_ u8`
649+
enum HiddenLifetimeTarget {
650+
/// Lifetime in `&u8` is hidden (becomes `&'_ u8`)
651651
TopLevel(NodeId),
652-
/// Elision in `Foo` -> `Foo<'_>`
653-
Nested(NestedResolvedElisionTarget),
652+
/// Lifetime in `Foo` is hidden (becomes `Foo<'_>`)
653+
Nested(NestedHiddenLifetimeTarget),
654654
}
655655

656-
impl ResolvedElisionTarget {
656+
impl HiddenLifetimeTarget {
657657
fn node_id(&self) -> NodeId {
658658
match *self {
659659
Self::TopLevel(n) => n,
660-
Self::Nested(NestedResolvedElisionTarget { segment_id, .. }) => segment_id,
660+
Self::Nested(NestedHiddenLifetimeTarget { segment_id, .. }) => segment_id,
661661
}
662662
}
663663
}
664664

665665
#[derive(Debug)]
666-
struct NestedResolvedElisionTarget {
666+
struct NestedHiddenLifetimeTarget {
667667
segment_id: NodeId,
668-
elided_lifetime_span: Span,
668+
lifetime_span: Span,
669669
diagnostic: lint::BuiltinLintDiag,
670670
}
671671

@@ -710,8 +710,8 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
710710
/// Count the number of places a lifetime is used.
711711
lifetime_uses: FxHashMap<LocalDefId, LifetimeUseSet>,
712712

713-
/// Track which types participated in lifetime elision
714-
resolved_lifetime_elisions: Vec<ResolvedElisionTarget>,
713+
/// Track which parameters/return values had hidden lifetimes.
714+
hidden_lifetimes: Vec<HiddenLifetimeTarget>,
715715
}
716716

717717
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -1325,7 +1325,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
13251325
// errors at module scope should always be reported
13261326
in_func_body: false,
13271327
lifetime_uses: Default::default(),
1328-
resolved_lifetime_elisions: Vec::new(),
1328+
hidden_lifetimes: Vec::new(),
13291329
}
13301330
}
13311331

@@ -1760,7 +1760,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
17601760
);
17611761
self.resolve_anonymous_lifetime(&lt, true);
17621762

1763-
self.resolved_lifetime_elisions.push(ResolvedElisionTarget::TopLevel(anchor_id));
1763+
self.hidden_lifetimes.push(HiddenLifetimeTarget::TopLevel(anchor_id));
17641764
}
17651765

17661766
#[instrument(level = "debug", skip(self))]
@@ -1972,10 +1972,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
19721972
}
19731973

19741974
if should_lint {
1975-
self.resolved_lifetime_elisions.push(ResolvedElisionTarget::Nested(
1976-
NestedResolvedElisionTarget {
1975+
self.hidden_lifetimes.push(HiddenLifetimeTarget::Nested(
1976+
NestedHiddenLifetimeTarget {
19771977
segment_id,
1978-
elided_lifetime_span,
1978+
lifetime_span: elided_lifetime_span,
19791979
diagnostic: lint::BuiltinLintDiag::ElidedLifetimesInPaths(
19801980
expected_lifetimes,
19811981
path_span,
@@ -2026,12 +2026,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20262026
inputs: impl Iterator<Item = (Option<&'ast Pat>, &'ast Ty)> + Clone,
20272027
output_ty: &'ast FnRetTy,
20282028
) {
2029-
let outer_resolved_lifetime_elisions = take(&mut self.resolved_lifetime_elisions);
2029+
let outer_hidden_lifetimes = take(&mut self.hidden_lifetimes);
20302030

20312031
// Add each argument to the rib.
20322032
let elision_lifetime = self.resolve_fn_params(has_self, inputs);
20332033
debug!(?elision_lifetime);
2034-
let param_resolved_lifetime_elisions = take(&mut self.resolved_lifetime_elisions);
2034+
let param_hidden_lifetimes = take(&mut self.hidden_lifetimes);
20352035

20362036
let outer_failures = take(&mut self.diag_metadata.current_elision_failures);
20372037

@@ -2059,31 +2059,30 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20592059
}
20602060
};
20612061

2062-
// We've recorded all elisions that occurred in the params and
2063-
// outputs, categorized by top-level or nested.
2062+
// We've recorded all hidden lifetimes that occurred in the
2063+
// params and outputs, categorized by top-level or nested.
20642064
//
20652065
// Our primary lint case is when an output lifetime is tied to
20662066
// an input lifetime. In that case, we want to warn about any
20672067
// nested hidden lifetimes in those params or outputs.
20682068
//
2069-
// The secondary case is for nested elisions that are not part
2070-
// of the tied lifetime relationship.
2069+
// The secondary case is for nested hidden lifetimes that are
2070+
// not part of the tied lifetime relationship.
20712071

2072-
let output_resolved_lifetime_elisions =
2073-
replace(&mut self.resolved_lifetime_elisions, outer_resolved_lifetime_elisions);
2072+
let output_hidden_lifetimes = replace(&mut self.hidden_lifetimes, outer_hidden_lifetimes);
20742073

2075-
match (output_resolved_lifetime_elisions.is_empty(), elision_lifetime) {
2074+
match (output_hidden_lifetimes.is_empty(), elision_lifetime) {
20762075
(true, _) | (_, None) => {
20772076
// Treat all parameters as untied
2078-
self.report_elided_lifetimes_in_paths(
2079-
param_resolved_lifetime_elisions,
2080-
lint::builtin::ELIDED_LIFETIMES_IN_PATHS_UNTIED,
2077+
self.report_lifetimes_hidden_in_paths(
2078+
param_hidden_lifetimes,
2079+
lint::builtin::UNTIED_LIFETIMES_HIDDEN_IN_PATHS,
20812080
);
20822081
}
20832082
(false, Some(elision_lifetime)) => {
20842083
let (primary, secondary): (Vec<_>, Vec<_>) =
2085-
param_resolved_lifetime_elisions.into_iter().partition(|re| {
2086-
// Recover the `NodeId` of an elided lifetime
2084+
param_hidden_lifetimes.into_iter().partition(|re| {
2085+
// Recover the `NodeId` of a hidden lifetime
20872086
let lvl1 = &self.r.lifetimes_res_map[&re.node_id()];
20882087
let lvl2 = match lvl1 {
20892088
LifetimeRes::ElidedAnchor { start, .. } => {
@@ -2095,32 +2094,32 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20952094
lvl2 == &elision_lifetime
20962095
});
20972096

2098-
self.report_elided_lifetimes_in_paths(
2099-
primary.into_iter().chain(output_resolved_lifetime_elisions),
2100-
lint::builtin::ELIDED_LIFETIMES_IN_PATHS_TIED,
2097+
self.report_lifetimes_hidden_in_paths(
2098+
primary.into_iter().chain(output_hidden_lifetimes),
2099+
lint::builtin::TIED_LIFETIMES_HIDDEN_IN_PATHS,
21012100
);
2102-
self.report_elided_lifetimes_in_paths(
2101+
self.report_lifetimes_hidden_in_paths(
21032102
secondary,
2104-
lint::builtin::ELIDED_LIFETIMES_IN_PATHS_UNTIED,
2103+
lint::builtin::UNTIED_LIFETIMES_HIDDEN_IN_PATHS,
21052104
);
21062105
}
21072106
}
21082107
}
21092108

2110-
fn report_elided_lifetimes_in_paths(
2109+
fn report_lifetimes_hidden_in_paths(
21112110
&mut self,
2112-
resolved_elisions: impl IntoIterator<Item = ResolvedElisionTarget>,
2111+
hidden_lifetimes: impl IntoIterator<Item = HiddenLifetimeTarget>,
21132112
lint: &'static lint::Lint,
21142113
) {
2115-
for re in resolved_elisions {
2116-
let ResolvedElisionTarget::Nested(d) = re else { continue };
2114+
for hl in hidden_lifetimes {
2115+
let HiddenLifetimeTarget::Nested(n) = hl else { continue };
21172116

2118-
let NestedResolvedElisionTarget { segment_id, elided_lifetime_span, diagnostic } = d;
2117+
let NestedHiddenLifetimeTarget { segment_id, lifetime_span, diagnostic } = n;
21192118

21202119
self.r.lint_buffer.buffer_lint_with_diagnostic(
21212120
lint,
21222121
segment_id,
2123-
elided_lifetime_span,
2122+
lifetime_span,
21242123
"hidden lifetime parameters in types are deprecated",
21252124
diagnostic,
21262125
);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +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"),
14+
("lifetimes-hidden-in-paths", "Lints that detect the use of hidden lifetime parameters"),
1515
("nonstandard-style", "Violation of standard naming conventions"),
1616
("future-incompatible", "Lints that detect code that has future-compatibility problems"),
1717
("rust-2018-compatibility", "Lints used to transition code from the 2015 edition to 2018"),

tests/ui/lifetimes/elided-lifetime-in-path-details.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@revisions: tied untied
22

3-
#![cfg_attr(tied, deny(elided_lifetimes_in_paths_tied))]
4-
#![cfg_attr(untied, deny(elided_lifetimes_in_paths_untied))]
3+
#![cfg_attr(tied, deny(tied_lifetimes_hidden_in_paths))]
4+
#![cfg_attr(untied, deny(untied_lifetimes_hidden_in_paths))]
55

66
struct ContainsLifetime<'a>(&'a u8);
77

tests/ui/lifetimes/elided-lifetime-in-path-details.tied.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | ContainsLifetime
77
note: the lint level is defined here
88
--> $DIR/elided-lifetime-in-path-details.rs:3:24
99
|
10-
LL | #![cfg_attr(tied, deny(elided_lifetimes_in_paths_tied))]
10+
LL | #![cfg_attr(tied, deny(tied_lifetimes_hidden_in_paths))]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: indicate the anonymous lifetime
1313
|

tests/ui/lifetimes/elided-lifetime-in-path-details.untied.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fn nested_parameter(v: ContainsLifetime) {}
77
note: the lint level is defined here
88
--> $DIR/elided-lifetime-in-path-details.rs:4:26
99
|
10-
LL | #![cfg_attr(untied, deny(elided_lifetimes_in_paths_untied))]
10+
LL | #![cfg_attr(untied, deny(untied_lifetimes_hidden_in_paths))]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
help: indicate the anonymous lifetime
1313
|

tests/ui/lifetimes/issue-91763.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ aux-build:issue-91763-aux.rs
22

3-
#![deny(elided_lifetimes_in_paths)]
3+
#![deny(lifetimes_hidden_in_paths)]
44

55
extern crate issue_91763_aux;
66

tests/ui/lifetimes/issue-91763.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ LL | fn f() -> Ptr<Thing>;
77
note: the lint level is defined here
88
--> $DIR/issue-91763.rs:3:9
99
|
10-
LL | #![deny(elided_lifetimes_in_paths)]
10+
LL | #![deny(lifetimes_hidden_in_paths)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= note: `#[deny(elided_lifetimes_in_paths_untied)]` implied by `#[deny(elided_lifetimes_in_paths)]`
12+
= note: `#[deny(untied_lifetimes_hidden_in_paths)]` implied by `#[deny(lifetimes_hidden_in_paths)]`
1313
help: indicate the anonymous lifetime
1414
|
1515
LL | fn f() -> Ptr<Thing><'_>;

tests/ui/lint/force-warn/allowed-by-default-lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// --force-warn $LINT causes $LINT (which is allow-by-default) to warn
2-
//@ compile-flags: --force-warn elided_lifetimes_in_paths
2+
//@ compile-flags: --force-warn lifetimes_hidden_in_paths
33
//@ check-pass
44

55
struct Foo<'a> {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ warning: hidden lifetime parameters in types are deprecated
44
LL | fn foo(x: &Foo) {}
55
| ^^^ expected lifetime parameter
66
|
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)]`
7+
= note: `--force-warn untied-lifetimes-hidden-in-paths` implied by `--force-warn lifetimes-hidden-in-paths`
8+
= help: to override `--force-warn lifetimes-hidden-in-paths` add `#[allow(untied_lifetimes_hidden_in_paths)]`
99
help: indicate the anonymous lifetime
1010
|
1111
LL | fn foo(x: &Foo<'_>) {}

0 commit comments

Comments
 (0)