Skip to content

Commit 4a41f53

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 151fae0 commit 4a41f53

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
@@ -295,8 +295,6 @@ lint_hidden_lifetime_in_path =
295295
lint_hidden_lifetime_in_path_suggestion =
296296
indicate the anonymous lifetime
297297
298-
lint_hidden_lifetime_parameters = hidden lifetime parameters in types are deprecated
299-
300298
lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
301299
.label = this {$label} contains {$count ->
302300
[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
@@ -321,7 +321,9 @@ fn register_builtins(store: &mut LintStore) {
321321
BARE_TRAIT_OBJECTS,
322322
UNUSED_EXTERN_CRATES,
323323
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS,
324-
ELIDED_LIFETIMES_IN_PATHS,
324+
HIDDEN_LIFETIMES_IN_OUTPUT_PATHS,
325+
HIDDEN_LIFETIMES_IN_INPUT_PATHS,
326+
HIDDEN_LIFETIMES_IN_TYPE_PATHS,
325327
EXPLICIT_OUTLIVES_REQUIREMENTS,
326328
// FIXME(#52665, #47816) not always applicable and not all
327329
// macros are ready for this yet.
@@ -341,9 +343,15 @@ fn register_builtins(store: &mut LintStore) {
341343

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

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

370+
// Register renamed lint groups
371+
store.register_renamed_group("elided_lifetime_in_path", "hidden_lifetimes_in_paths");
372+
store.register_renamed_group("elided_lifetimes_in_paths", "hidden_lifetimes_in_paths");
373+
362374
// These were moved to tool lints, but rustc still sees them when compiling normally, before
363375
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use
364376
// `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
/// }
@@ -636,10 +634,9 @@ declare_lint! {
636634
/// ### Example
637635
///
638636
/// ```rust,compile_fail
639-
/// #![deny(hidden_lifetimes_in_type_paths)]
640-
///
641637
/// struct ContainsLifetime<'a>(&'a i32);
642638
///
639+
/// #[deny(hidden_lifetimes_in_type_paths)]
643640
/// static FOO: ContainsLifetime = ContainsLifetime(&42);
644641
/// ```
645642
///

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;
@@ -2745,13 +2745,6 @@ pub(crate) struct MacroExpandedMacroExportsAccessedByAbsolutePaths {
27452745
pub definition: Span,
27462746
}
27472747

2748-
#[derive(LintDiagnostic)]
2749-
#[diag(lint_hidden_lifetime_parameters)]
2750-
pub(crate) struct ElidedLifetimesInPaths {
2751-
#[subdiagnostic]
2752-
pub subdiag: ElidedLifetimeInPathSubdiag,
2753-
}
2754-
27552748
#[derive(LintDiagnostic)]
27562749
#[diag(lint_invalid_crate_type_value)]
27572750
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,
@@ -1796,41 +1795,6 @@ declare_lint! {
17961795
};
17971796
}
17981797

1799-
declare_lint! {
1800-
/// The `elided_lifetimes_in_paths` lint detects the use of hidden
1801-
/// lifetime parameters.
1802-
///
1803-
/// ### Example
1804-
///
1805-
/// ```rust,compile_fail
1806-
/// #![deny(elided_lifetimes_in_paths)]
1807-
/// #![deny(warnings)]
1808-
/// struct Foo<'a> {
1809-
/// x: &'a u32
1810-
/// }
1811-
///
1812-
/// fn foo(x: &Foo) {
1813-
/// }
1814-
/// ```
1815-
///
1816-
/// {{produces}}
1817-
///
1818-
/// ### Explanation
1819-
///
1820-
/// Elided lifetime parameters can make it difficult to see at a glance
1821-
/// that borrowing is occurring. This lint ensures that lifetime
1822-
/// parameters are always explicitly stated, even if it is the `'_`
1823-
/// [placeholder lifetime].
1824-
///
1825-
/// This lint is "allow" by default because it has some known issues, and
1826-
/// may require a significant transition for old code.
1827-
///
1828-
/// [placeholder lifetime]: https://doc.rust-lang.org/reference/lifetime-elision.html#lifetime-elision-in-functions
1829-
pub ELIDED_LIFETIMES_IN_PATHS,
1830-
Allow,
1831-
"hidden lifetime parameters in types are deprecated"
1832-
}
1833-
18341798
declare_lint! {
18351799
/// The `bare_trait_objects` lint suggests using `dyn Trait` for trait
18361800
/// 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
@@ -2619,7 +2619,6 @@ ui/let-else/issue-100103.rs
26192619
ui/let-else/issue-102317.rs
26202620
ui/let-else/issue-94176.rs
26212621
ui/let-else/issue-99975.rs
2622-
ui/lifetimes/auxiliary/issue-91763-aux.rs
26232622
ui/lifetimes/issue-103582-hint-for-missing-lifetime-bound-on-trait-object-using-type-alias.rs
26242623
ui/lifetimes/issue-104432-unused-lifetimes-in-expansion.rs
26252624
ui/lifetimes/issue-105227.rs
@@ -2652,7 +2651,6 @@ ui/lifetimes/issue-84398.rs
26522651
ui/lifetimes/issue-84604.rs
26532652
ui/lifetimes/issue-90170-elision-mismatch.rs
26542653
ui/lifetimes/issue-90600-expected-return-static-indirect.rs
2655-
ui/lifetimes/issue-91763.rs
26562654
ui/lifetimes/issue-93911.rs
26572655
ui/lifetimes/issue-95023.rs
26582656
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)