Skip to content

Commit ba167f0

Browse files
committed
Replace elided_lifetime_in_paths with multiple renamed lints
Removing the `issue-91763` test as the implementation is completely different now.
1 parent 54c9d04 commit ba167f0

28 files changed

+567
-238
lines changed

compiler/rustc_baked_icu_data/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
//! ```
2222
2323
// tidy-alphabetical-start
24-
#![allow(elided_lifetimes_in_paths)]
2524
#![allow(internal_features)]
2625
#![allow(unreachable_pub)] // because this crate is mostly generated code
2726
#![doc(rust_logo)]
2827
#![feature(rustdoc_internals)]
2928
// #![warn(unreachable_pub)] // don't use because this crate is mostly generated code
3029
// tidy-alphabetical-end
30+
#![cfg_attr(bootstrap, allow(elided_lifetimes_in_paths))]
31+
#![cfg_attr(not(bootstrap), allow(hidden_lifetimes_in_paths))]
3132

3233
mod data {
3334
include!("data/mod.rs");

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ lint_hidden_glob_reexport = private item shadows public glob re-export
287287
.note_glob_reexport = the name `{$name}` in the {$namespace} namespace is supposed to be publicly re-exported here
288288
.note_private_item = but the private item here shadows it
289289
290-
lint_hidden_lifetime_parameters = hidden lifetime parameters in types are deprecated
291-
292290
lint_hidden_lifetime_in_path =
293291
paths containing hidden lifetime parameters are deprecated
294292

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
use std::borrow::Cow;
55

66
use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
7-
use rustc_errors::{
8-
Applicability, Diag, DiagArgValue, LintDiagnostic, elided_lifetime_in_path_suggestion,
9-
};
7+
use rustc_errors::{Applicability, Diag, DiagArgValue, LintDiagnostic};
108
use rustc_middle::middle::stability;
119
use rustc_middle::ty::TyCtxt;
1210
use rustc_session::Session;
@@ -75,19 +73,6 @@ pub(super) fn decorate_lint(
7573
lints::MacroExpandedMacroExportsAccessedByAbsolutePaths { definition: span_def }
7674
.decorate_lint(diag)
7775
}
78-
79-
BuiltinLintDiag::ElidedLifetimesInPaths(n, path_span, incl_angl_brckt, insertion_span) => {
80-
lints::ElidedLifetimesInPaths {
81-
subdiag: elided_lifetime_in_path_suggestion(
82-
sess.source_map(),
83-
n,
84-
path_span,
85-
incl_angl_brckt,
86-
insertion_span,
87-
),
88-
}
89-
.decorate_lint(diag);
90-
}
9176
BuiltinLintDiag::UnknownCrateTypes { span, candidate } => {
9277
let sugg = candidate.map(|candidate| lints::UnknownCrateTypesSub { span, candidate });
9378
lints::UnknownCrateTypes { sugg }.decorate_lint(diag);

compiler/rustc_lint/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ fn register_builtins(store: &mut LintStore) {
319319
BARE_TRAIT_OBJECTS,
320320
UNUSED_EXTERN_CRATES,
321321
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
322-
ELIDED_LIFETIMES_IN_PATHS,
322+
HIDDEN_LIFETIMES_IN_OUTPUT_PATHS,
323+
HIDDEN_LIFETIMES_IN_INPUT_PATHS,
324+
HIDDEN_LIFETIMES_IN_TYPE_PATHS,
323325
EXPLICIT_OUTLIVES_REQUIREMENTS,
324326
// FIXME(#52665, #47816) not always applicable and not all
325327
// macros are ready for this yet.
@@ -339,9 +341,15 @@ fn register_builtins(store: &mut LintStore) {
339341

340342
add_lint_group!("deprecated_safe", DEPRECATED_SAFE_2024);
341343

344+
add_lint_group!(
345+
"hidden_lifetimes_in_paths",
346+
HIDDEN_LIFETIMES_IN_OUTPUT_PATHS,
347+
HIDDEN_LIFETIMES_IN_INPUT_PATHS,
348+
HIDDEN_LIFETIMES_IN_TYPE_PATHS,
349+
);
350+
342351
// Register renamed and removed lints.
343352
store.register_renamed("single_use_lifetime", "single_use_lifetimes");
344-
store.register_renamed("elided_lifetime_in_path", "elided_lifetimes_in_paths");
345353
store.register_renamed("bare_trait_object", "bare_trait_objects");
346354
store.register_renamed("unstable_name_collision", "unstable_name_collisions");
347355
store.register_renamed("unused_doc_comment", "unused_doc_comments");
@@ -357,6 +365,10 @@ fn register_builtins(store: &mut LintStore) {
357365
store.register_renamed("temporary_cstring_as_ptr", "dangling_pointers_from_temporaries");
358366
store.register_renamed("elided_named_lifetimes", "lifetime_style_mismatch");
359367

368+
// Register renamed lint groups
369+
store.register_renamed_group("elided_lifetime_in_path", "hidden_lifetimes_in_paths");
370+
store.register_renamed_group("elided_lifetimes_in_paths", "hidden_lifetimes_in_paths");
371+
360372
// These were moved to tool lints, but rustc still sees them when compiling normally, before
361373
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use
362374
// `register_removed` explicitly.

compiler/rustc_lint/src/lifetime_style.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ declare_lint! {
6464
}
6565

6666
declare_lint! {
67-
/// The `hidden_lifetimes_in_input_paths2` lint detects the use of
67+
/// The `hidden_lifetimes_in_input_paths` lint detects the use of
6868
/// hidden lifetime parameters in types occurring as a function
6969
/// argument.
7070
///
7171
/// ### Example
7272
///
7373
/// ```rust,compile_fail
74-
/// #![deny(hidden_lifetimes_in_input_paths2)]
74+
/// #![deny(hidden_lifetimes_in_input_paths)]
7575
///
7676
/// struct ContainsLifetime<'a>(&'a i32);
7777
///
@@ -93,20 +93,20 @@ declare_lint! {
9393
/// themselves do not usually cause much confusion.
9494
///
9595
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
96-
pub HIDDEN_LIFETIMES_IN_INPUT_PATHS2,
96+
pub HIDDEN_LIFETIMES_IN_INPUT_PATHS,
9797
Allow,
9898
"hidden lifetime parameters in types in function arguments may be confusing"
9999
}
100100

101101
declare_lint! {
102-
/// The `hidden_lifetimes_in_output_paths2` lint detects the use
102+
/// The `hidden_lifetimes_in_output_paths` lint detects the use
103103
/// of hidden lifetime parameters in types occurring as a function
104104
/// return value.
105105
///
106106
/// ### Example
107107
///
108108
/// ```rust,compile_fail
109-
/// #![deny(hidden_lifetimes_in_input_paths2)]
109+
/// #![deny(hidden_lifetimes_in_input_paths)]
110110
///
111111
/// struct ContainsLifetime<'a>(&'a i32);
112112
///
@@ -131,15 +131,15 @@ declare_lint! {
131131
/// lifetime].
132132
///
133133
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
134-
pub HIDDEN_LIFETIMES_IN_OUTPUT_PATHS2,
134+
pub HIDDEN_LIFETIMES_IN_OUTPUT_PATHS,
135135
Allow,
136136
"hidden lifetime parameters in types in function return values are deprecated"
137137
}
138138

139139
declare_lint_pass!(LifetimeStyle => [
140140
MISMATCHED_ELIDED_LIFETIME_STYLES,
141-
HIDDEN_LIFETIMES_IN_INPUT_PATHS2,
142-
HIDDEN_LIFETIMES_IN_OUTPUT_PATHS2,
141+
HIDDEN_LIFETIMES_IN_INPUT_PATHS,
142+
HIDDEN_LIFETIMES_IN_OUTPUT_PATHS,
143143
]);
144144

145145
impl<'tcx> LateLintPass<'tcx> for LifetimeStyle {
@@ -165,8 +165,8 @@ impl<'tcx> LateLintPass<'tcx> for LifetimeStyle {
165165
}
166166

167167
report_mismatches(cx, &input_map, &output_map);
168-
report_hidden_in_paths(cx, &input_map, HIDDEN_LIFETIMES_IN_INPUT_PATHS2);
169-
report_hidden_in_paths(cx, &output_map, HIDDEN_LIFETIMES_IN_OUTPUT_PATHS2);
168+
report_hidden_in_paths(cx, &input_map, HIDDEN_LIFETIMES_IN_INPUT_PATHS);
169+
report_hidden_in_paths(cx, &output_map, HIDDEN_LIFETIMES_IN_OUTPUT_PATHS);
170170
}
171171
}
172172

@@ -451,14 +451,14 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeInfoCollector<'a, 'tcx> {
451451
}
452452

453453
declare_lint! {
454-
/// The `hidden_lifetimes_in_type_paths2` lint detects the use of
454+
/// The `hidden_lifetimes_in_type_paths` lint detects the use of
455455
/// hidden lifetime parameters in types not part of a function's
456456
/// arguments or return values.
457457
///
458458
/// ### Example
459459
///
460460
/// ```rust,compile_fail
461-
/// #![deny(hidden_lifetimes_in_input_paths2)]
461+
/// #![deny(hidden_lifetimes_in_input_paths)]
462462
///
463463
/// struct ContainsLifetime<'a>(&'a i32);
464464
///
@@ -477,7 +477,7 @@ declare_lint! {
477477
/// lifetime].
478478
///
479479
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
480-
pub HIDDEN_LIFETIMES_IN_TYPE_PATHS2,
480+
pub HIDDEN_LIFETIMES_IN_TYPE_PATHS,
481481
Allow,
482482
"hidden lifetime parameters in types outside function signatures are discouraged"
483483
}
@@ -487,7 +487,7 @@ pub(crate) struct HiddenLifetimesInTypePaths {
487487
inside_fn_signature: bool,
488488
}
489489

490-
impl_lint_pass!(HiddenLifetimesInTypePaths => [HIDDEN_LIFETIMES_IN_TYPE_PATHS2]);
490+
impl_lint_pass!(HiddenLifetimesInTypePaths => [HIDDEN_LIFETIMES_IN_TYPE_PATHS]);
491491

492492
impl<'tcx> LateLintPass<'tcx> for HiddenLifetimesInTypePaths {
493493
#[instrument(skip(self, cx))]
@@ -529,7 +529,7 @@ impl<'tcx> LateLintPass<'tcx> for HiddenLifetimesInTypePaths {
529529
}
530530

531531
cx.emit_span_lint(
532-
HIDDEN_LIFETIMES_IN_TYPE_PATHS2,
532+
HIDDEN_LIFETIMES_IN_TYPE_PATHS,
533533
ty.span,
534534
lints::HiddenLifetimeInPath {
535535
suggestions: lints::HiddenLifetimeInPathSuggestion { suggestions },

compiler/rustc_lint/src/lints.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::num::NonZero;
55
use rustc_abi::ExternAbi;
66
use rustc_errors::codes::*;
77
use rustc_errors::{
8-
Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, ElidedLifetimeInPathSubdiag,
9-
EmissionGuarantee, LintDiagnostic, MultiSpan, SubdiagMessageOp, Subdiagnostic, SuggestionStyle,
8+
Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, EmissionGuarantee,
9+
LintDiagnostic, MultiSpan, SubdiagMessageOp, Subdiagnostic, SuggestionStyle,
1010
};
1111
use rustc_hir as hir;
1212
use rustc_hir::def::Namespace;
@@ -2669,13 +2669,6 @@ pub(crate) struct MacroExpandedMacroExportsAccessedByAbsolutePaths {
26692669
pub definition: Span,
26702670
}
26712671

2672-
#[derive(LintDiagnostic)]
2673-
#[diag(lint_hidden_lifetime_parameters)]
2674-
pub(crate) struct ElidedLifetimesInPaths {
2675-
#[subdiagnostic]
2676-
pub subdiag: ElidedLifetimeInPathSubdiag,
2677-
}
2678-
26792672
#[derive(LintDiagnostic)]
26802673
#[diag(lint_invalid_crate_type_value)]
26812674
pub(crate) struct UnknownCrateTypes {

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +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,
4342
EXPLICIT_BUILTIN_CFGS_IN_FLAGS,
4443
EXPORTED_PRIVATE_DEPENDENCIES,
4544
FFI_UNWIND_CALLS,
@@ -1791,41 +1790,6 @@ declare_lint! {
17911790
};
17921791
}
17931792

1794-
declare_lint! {
1795-
/// The `elided_lifetimes_in_paths` lint detects the use of hidden
1796-
/// lifetime parameters.
1797-
///
1798-
/// ### Example
1799-
///
1800-
/// ```rust,compile_fail
1801-
/// #![deny(elided_lifetimes_in_paths)]
1802-
/// #![deny(warnings)]
1803-
/// struct Foo<'a> {
1804-
/// x: &'a u32
1805-
/// }
1806-
///
1807-
/// fn foo(x: &Foo) {
1808-
/// }
1809-
/// ```
1810-
///
1811-
/// {{produces}}
1812-
///
1813-
/// ### Explanation
1814-
///
1815-
/// Elided lifetime parameters can make it difficult to see at a glance
1816-
/// that borrowing is occurring. This lint ensures that lifetime
1817-
/// parameters are always explicitly stated, even if it is the `'_`
1818-
/// [placeholder lifetime].
1819-
///
1820-
/// This lint is "allow" by default because it has some known issues, and
1821-
/// may require a significant transition for old code.
1822-
///
1823-
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1824-
pub ELIDED_LIFETIMES_IN_PATHS,
1825-
Allow,
1826-
"hidden lifetime parameters in types are deprecated"
1827-
}
1828-
18291793
declare_lint! {
18301794
/// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
18311795
/// objects.

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ pub enum BuiltinLintDiag {
645645
ident: Ident,
646646
},
647647
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
648-
ElidedLifetimesInPaths(usize, Span, bool, Span),
649648
UnknownCrateTypes {
650649
span: Span,
651650
candidate: Option<Symbol>,

compiler/rustc_resolve/src/late.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
20792079
kind,
20802080
count: expected_lifetimes,
20812081
};
2082-
let mut should_lint = true;
20832082
for rib in self.lifetime_ribs.iter().rev() {
20842083
match rib.kind {
20852084
// In create-parameter mode we error here because we don't want to support
@@ -2102,7 +2101,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
21022101
span: path_span,
21032102
subdiag,
21042103
});
2105-
should_lint = false;
21062104

21072105
for id in node_ids {
21082106
self.record_lifetime_res(
@@ -2171,20 +2169,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
21712169
}
21722170
}
21732171
}
2174-
2175-
if should_lint {
2176-
self.r.lint_buffer.buffer_lint(
2177-
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
2178-
segment_id,
2179-
elided_lifetime_span,
2180-
lint::BuiltinLintDiag::ElidedLifetimesInPaths(
2181-
expected_lifetimes,
2182-
path_span,
2183-
!segment.has_generic_args,
2184-
elided_lifetime_span,
2185-
),
2186-
);
2187-
}
21882172
}
21892173
}
21902174

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ static GROUP_DESCRIPTIONS: &[(&str, &str)] = &[
1212
("let-underscore", "Lints that detect wildcard let bindings that are likely to be invalid"),
1313
("rustdoc", "Rustdoc-specific lints"),
1414
("rust-2018-idioms", "Lints to nudge you toward idiomatic features of Rust 2018"),
15+
("hidden-lifetimes-in-paths", "Lints that detect the use of hidden lifetime parameters"),
1516
("nonstandard-style", "Violation of standard naming conventions"),
1617
("future-incompatible", "Lints that detect code that has future-compatibility problems"),
1718
("rust-2018-compatibility", "Lints used to transition code from the 2015 edition to 2018"),

0 commit comments

Comments
 (0)