Skip to content

Commit b0e622e

Browse files
committed
Replace elided_lifetime_in_paths with multiple renamed lints
Removing the `issue-91763` test as the implementation is completely different now. Bootstrap forces `rust_2018_idioms` to the warning level in the rustc_lint doctests using `-Zcrate-attr`. This overrides the doctest's crate-level `deny` attributes, so I've changed those to be statement-level attributes.
1 parent 788db3e commit b0e622e

27 files changed

+88
-234
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
@@ -292,8 +292,6 @@ lint_hidden_lifetime_in_path =
292292
lint_hidden_lifetime_in_path_suggestion =
293293
indicate the anonymous lifetime
294294
295-
lint_hidden_lifetime_parameters = hidden lifetime parameters in types are deprecated
296-
297295
lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
298296
.label = this {$label} contains {$count ->
299297
[one] an invisible

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 fn decorate_builtin_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
@@ -320,7 +320,9 @@ fn register_builtins(store: &mut LintStore) {
320320
BARE_TRAIT_OBJECTS,
321321
UNUSED_EXTERN_CRATES,
322322
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
323-
ELIDED_LIFETIMES_IN_PATHS,
323+
HIDDEN_LIFETIMES_IN_OUTPUT_PATHS,
324+
HIDDEN_LIFETIMES_IN_INPUT_PATHS,
325+
HIDDEN_LIFETIMES_IN_TYPE_PATHS,
324326
EXPLICIT_OUTLIVES_REQUIREMENTS,
325327
// FIXME(#52665, #47816) not always applicable and not all
326328
// macros are ready for this yet.
@@ -340,9 +342,15 @@ fn register_builtins(store: &mut LintStore) {
340342

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

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

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

compiler/rustc_lint/src/lifetime_syntax.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ declare_lint! {
8282
/// ### Example
8383
///
8484
/// ```rust,compile_fail
85-
/// #![deny(hidden_lifetimes_in_input_paths)]
86-
///
8785
/// struct ContainsLifetime<'a>(&'a i32);
8886
///
87+
/// #[deny(hidden_lifetimes_in_input_paths)]
8988
/// fn foo(x: ContainsLifetime) {}
9089
/// ```
9190
///
@@ -117,10 +116,9 @@ declare_lint! {
117116
/// ### Example
118117
///
119118
/// ```rust,compile_fail
120-
/// #![deny(hidden_lifetimes_in_output_paths)]
121-
///
122119
/// struct ContainsLifetime<'a>(&'a i32);
123120
///
121+
/// #[deny(hidden_lifetimes_in_output_paths)]
124122
/// fn foo(x: &i32) -> ContainsLifetime {
125123
/// ContainsLifetime(x)
126124
/// }
@@ -662,10 +660,9 @@ declare_lint! {
662660
/// ### Example
663661
///
664662
/// ```rust,compile_fail
665-
/// #![deny(hidden_lifetimes_in_type_paths)]
666-
///
667663
/// struct ContainsLifetime<'a>(&'a i32);
668664
///
665+
/// #[deny(hidden_lifetimes_in_type_paths)]
669666
/// static FOO: ContainsLifetime = ContainsLifetime(&42);
670667
/// ```
671668
///

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, Subdiagnostic, SuggestionStyle,
8+
Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, EmissionGuarantee,
9+
LintDiagnostic, MultiSpan, Subdiagnostic, SuggestionStyle,
1010
};
1111
use rustc_hir as hir;
1212
use rustc_hir::def::Namespace;
@@ -2715,13 +2715,6 @@ pub(crate) struct MacroExpandedMacroExportsAccessedByAbsolutePaths {
27152715
pub definition: Span,
27162716
}
27172717

2718-
#[derive(LintDiagnostic)]
2719-
#[diag(lint_hidden_lifetime_parameters)]
2720-
pub(crate) struct ElidedLifetimesInPaths {
2721-
#[subdiagnostic]
2722-
pub subdiag: ElidedLifetimeInPathSubdiag,
2723-
}
2724-
27252718
#[derive(LintDiagnostic)]
27262719
#[diag(lint_invalid_crate_type_value)]
27272720
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,
@@ -1750,41 +1749,6 @@ declare_lint! {
17501749
};
17511750
}
17521751

1753-
declare_lint! {
1754-
/// The `elided_lifetimes_in_paths` lint detects the use of hidden
1755-
/// lifetime parameters.
1756-
///
1757-
/// ### Example
1758-
///
1759-
/// ```rust,compile_fail
1760-
/// #![deny(elided_lifetimes_in_paths)]
1761-
/// #![deny(warnings)]
1762-
/// struct Foo<'a> {
1763-
/// x: &'a u32
1764-
/// }
1765-
///
1766-
/// fn foo(x: &Foo) {
1767-
/// }
1768-
/// ```
1769-
///
1770-
/// {{produces}}
1771-
///
1772-
/// ### Explanation
1773-
///
1774-
/// Elided lifetime parameters can make it difficult to see at a glance
1775-
/// that borrowing is occurring. This lint ensures that lifetime
1776-
/// parameters are always explicitly stated, even if it is the `'_`
1777-
/// [placeholder lifetime].
1778-
///
1779-
/// This lint is "allow" by default because it has some known issues, and
1780-
/// may require a significant transition for old code.
1781-
///
1782-
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1783-
pub ELIDED_LIFETIMES_IN_PATHS,
1784-
Allow,
1785-
"hidden lifetime parameters in types are deprecated"
1786-
}
1787-
17881752
declare_lint! {
17891753
/// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
17901754
/// objects.

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ pub enum BuiltinLintDiag {
621621
ident: Ident,
622622
},
623623
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
624-
ElidedLifetimesInPaths(usize, Span, bool, Span),
625624
UnknownCrateTypes {
626625
span: Span,
627626
candidate: Option<Symbol>,

compiler/rustc_resolve/src/late.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
21042104
kind,
21052105
count: expected_lifetimes,
21062106
};
2107-
let mut should_lint = true;
21082107
for rib in self.lifetime_ribs.iter().rev() {
21092108
match rib.kind {
21102109
// In create-parameter mode we error here because we don't want to support
@@ -2127,7 +2126,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
21272126
span: path_span,
21282127
subdiag,
21292128
});
2130-
should_lint = false;
21312129

21322130
for id in node_ids {
21332131
self.record_lifetime_res(
@@ -2196,20 +2194,6 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
21962194
}
21972195
}
21982196
}
2199-
2200-
if should_lint {
2201-
self.r.lint_buffer.buffer_lint(
2202-
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
2203-
segment_id,
2204-
elided_lifetime_span,
2205-
lint::BuiltinLintDiag::ElidedLifetimesInPaths(
2206-
expected_lifetimes,
2207-
path_span,
2208-
!segment.has_generic_args,
2209-
elided_lifetime_span,
2210-
),
2211-
);
2212-
}
22132197
}
22142198
}
22152199

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"),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static RENAMES: &[(Level, &[(&str, &str)])] = &[
2424
Level::Allow,
2525
&[
2626
("single-use-lifetime", "single-use-lifetimes"),
27-
("elided-lifetime-in-path", "elided-lifetimes-in-paths"),
27+
("elided-lifetime-in-path", "hidden-lifetimes-in-paths"),
2828
("async-idents", "keyword-idents"),
2929
("disjoint-capture-migration", "rust-2021-incompatible-closure-captures"),
3030
("keyword-idents", "keyword-idents-2018"),

src/tools/tidy/src/issues.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,7 +2618,6 @@ ui/let-else/issue-100103.rs
26182618
ui/let-else/issue-102317.rs
26192619
ui/let-else/issue-94176.rs
26202620
ui/let-else/issue-99975.rs
2621-
ui/lifetimes/auxiliary/issue-91763-aux.rs
26222621
ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs
26232622
ui/lifetimes/issue-104432-unused-lifetimes-in-expansion.rs
26242623
ui/lifetimes/issue-105227.rs
@@ -2651,7 +2650,6 @@ ui/lifetimes/issue-84398.rs
26512650
ui/lifetimes/issue-84604.rs
26522651
ui/lifetimes/issue-90170-elision-mismatch.rs
26532652
ui/lifetimes/issue-90600-expected-return-static-indirect.rs
2654-
ui/lifetimes/issue-91763.rs
26552653
ui/lifetimes/issue-93911.rs
26562654
ui/lifetimes/issue-95023.rs
26572655
ui/lifetimes/issue-97193.rs

tests/ui/lifetimes/auxiliary/issue-91763-aux.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/ui/lifetimes/elided-lint-in-mod.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/ui/lifetimes/elided-lint-in-mod.stderr

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Foo<'a>(&'a ());
2+
3+
fn test(_: Foo) {}
4+
5+
#[deny(hidden_lifetimes_in_paths)]
6+
mod w {
7+
fn test2(_: super::Foo) {}
8+
//~^ ERROR paths containing hidden lifetime parameters are deprecated
9+
}
10+
11+
fn main() {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: paths containing hidden lifetime parameters are deprecated
2+
--> $DIR/hidden-lifetimes-in-mod.rs:7:17
3+
|
4+
LL | fn test2(_: super::Foo) {}
5+
| ^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/hidden-lifetimes-in-mod.rs:5:8
9+
|
10+
LL | #[deny(hidden_lifetimes_in_paths)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: `#[deny(hidden_lifetimes_in_input_paths)]` implied by `#[deny(hidden_lifetimes_in_paths)]`
13+
help: indicate the anonymous lifetime
14+
|
15+
LL | fn test2(_: super::Foo<'_>) {}
16+
| ++++
17+
18+
error: aborting due to 1 previous error
19+

0 commit comments

Comments
 (0)