Skip to content

Commit

Permalink
rename elided_lifetimes_in_paths lint to hidden_lifetimes_in_types
Browse files Browse the repository at this point in the history
It's only with reluctance and sadness that we rename a lint that has
already been renamed once (rust-lang#50879), but it seems worth it to pick the
best name now because since the lint is relatively new and has
heretofore been allow-by-default, the ecosystem breakage should be
minimal. (And—also sadly—the fact that the original implementation was
so buggy for so long testifies that not very many people are tuning up
the allow-by-default lints. Also, as always, lint capping prevents
lint changes from spreading contagiously to dependencies.)

The rationales here are that—

 • "hidden" is less potentially ambiguous than "elided", because this
   lint is specifically about angle-bracketed lifetime parameters,
   whereas the term "elided" has a strong precedent for also
   encompassing omitted lifetime names in reference ('&') types, which
   is not the concern of this lint, and

 • "types" is a more specific description of where the lint fires than
   "paths" (indeed, previous implementations of the lint used to fire
   on non-type paths in ways that proved to be erroneous
   false-positives, as evidenced by applications of the suggestion to
   use an anonymous lifetime (`'_`) resulting in code that didn't even
   parse)

This comes from discussion on rust-lang#52069.
  • Loading branch information
zackmdavis committed Jul 15, 2018
1 parent 47aabb3 commit be9758a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ declare_lint! {
}

declare_lint! {
pub ELIDED_LIFETIMES_IN_PATHS,
pub HIDDEN_LIFETIMES_IN_TYPES,
Allow,
"implicit lifetime parameters are deprecated"
"hidden lifetime parameters in types are deprecated"
}

declare_lint! {
Expand Down Expand Up @@ -376,7 +376,7 @@ impl LintPass for HardwiredLints {
UNUSED_LIFETIMES,
UNUSED_LABELS,
TYVAR_BEHIND_RAW_POINTER,
ELIDED_LIFETIMES_IN_PATHS,
HIDDEN_LIFETIMES_IN_TYPES,
BARE_TRAIT_OBJECTS,
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
UNSTABLE_NAME_COLLISIONS,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2102,10 +2102,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}

let mut err = self.tcx.struct_span_lint_node(
lint::builtin::ELIDED_LIFETIMES_IN_PATHS,
lint::builtin::HIDDEN_LIFETIMES_IN_TYPES,
implicit_lifetimes[0].id, // FIXME: HirIdify #50928
path.span,
&format!("implicit lifetime parameters in types are deprecated"),
&format!("hidden lifetime parameters in types are deprecated"),
);

if implicit_lifetimes.len() == 1 {
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extern crate syntax_pos;
use rustc::lint;
use rustc::lint::{LateContext, LateLintPass, LintPass, LintArray};
use rustc::lint::builtin::{BARE_TRAIT_OBJECTS, ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
ELIDED_LIFETIMES_IN_PATHS, MACRO_USE_EXTERN_CRATE};
HIDDEN_LIFETIMES_IN_TYPES, MACRO_USE_EXTERN_CRATE};

use rustc::session;
use rustc::util;
Expand Down Expand Up @@ -184,7 +184,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UNREACHABLE_PUB,
UNUSED_EXTERN_CRATES,
MACRO_USE_EXTERN_CRATE,
ELIDED_LIFETIMES_IN_PATHS,
HIDDEN_LIFETIMES_IN_TYPES,
ELLIPSIS_INCLUSIVE_RANGE_PATTERNS);

// Guidelines for creating a future incompatibility lint:
Expand Down Expand Up @@ -308,11 +308,14 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {

// Register renamed and removed lints
store.register_renamed("single_use_lifetime", "single_use_lifetimes");
store.register_renamed("elided_lifetime_in_path", "elided_lifetimes_in_paths");
store.register_renamed("bare_trait_object", "bare_trait_objects");
store.register_renamed("unstable_name_collision", "unstable_name_collisions");
store.register_renamed("unused_doc_comment", "unused_doc_comments");
store.register_renamed("unknown_features", "unused_features");
// Yes, it got renamed twice :'(
store.register_renamed("elided_lifetime_in_path", "hidden_lifetimes_in_types");
store.register_renamed("elided_lifetimes_in_paths", "hidden_lifetimes_in_types");

store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
store.register_removed("negate_unsigned", "cast a signed value instead");
store.register_removed("raw_pointer_derive", "using derive with raw pointers is ok");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// compile-flags: --edition 2018

#![allow(unused)]
#![deny(elided_lifetimes_in_paths)]
#![deny(hidden_lifetimes_in_types)]
//~^ NOTE lint level defined here

use std::cell::{RefCell, Ref};
Expand All @@ -21,7 +21,7 @@ use std::cell::{RefCell, Ref};
struct Foo<'a> { x: &'a u32 }

fn foo(x: &Foo<'_>) {
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
}

Expand All @@ -35,13 +35,13 @@ struct WrappedWithBow<'a> {
}

fn wrap_gift(gift: &str) -> Wrapped<'_> {
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
Wrapped(gift)
}

fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow<'_> {
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
WrappedWithBow { gift }
}
Expand All @@ -53,7 +53,7 @@ macro_rules! autowrapper {
}

fn $fn_name(gift: &str) -> $type_name<'_> {
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
$type_name { gift }
}
Expand All @@ -67,15 +67,15 @@ autowrapper!(Autowrapped, autowrap_gift, 'a);
macro_rules! anytuple_ref_ty {
($($types:ty),*) => {
Ref<'_, ($($types),*)>
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
}
}

fn main() {
let honesty = RefCell::new((4, 'e'));
let loyalty: Ref<'_, (u32, char)> = honesty.borrow();
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
let generosity = Ref::map(loyalty, |t| &t.0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// compile-flags: --edition 2018

#![allow(unused)]
#![deny(elided_lifetimes_in_paths)]
#![deny(hidden_lifetimes_in_types)]
//~^ NOTE lint level defined here

use std::cell::{RefCell, Ref};
Expand All @@ -21,7 +21,7 @@ use std::cell::{RefCell, Ref};
struct Foo<'a> { x: &'a u32 }

fn foo(x: &Foo) {
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
}

Expand All @@ -35,13 +35,13 @@ struct WrappedWithBow<'a> {
}

fn wrap_gift(gift: &str) -> Wrapped {
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
Wrapped(gift)
}

fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow {
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
WrappedWithBow { gift }
}
Expand All @@ -53,7 +53,7 @@ macro_rules! autowrapper {
}

fn $fn_name(gift: &str) -> $type_name {
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
$type_name { gift }
}
Expand All @@ -67,15 +67,15 @@ autowrapper!(Autowrapped, autowrap_gift, 'a);
macro_rules! anytuple_ref_ty {
($($types:ty),*) => {
Ref<($($types),*)>
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
}
}

fn main() {
let honesty = RefCell::new((4, 'e'));
let loyalty: Ref<(u32, char)> = honesty.borrow();
//~^ ERROR implicit lifetime parameters in types are deprecated
//~^ ERROR hidden lifetime parameters in types are deprecated
//~| HELP indicate the anonymous lifetime
let generosity = Ref::map(loyalty, |t| &t.0);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
error: implicit lifetime parameters in types are deprecated
--> $DIR/elided-lifetimes.rs:23:12
error: hidden lifetime parameters in types are deprecated
--> $DIR/hidden-lifetimes-in-types.rs:23:12
|
LL | fn foo(x: &Foo) {
| ^^^- help: indicate the anonymous lifetime: `<'_>`
|
note: lint level defined here
--> $DIR/elided-lifetimes.rs:15:9
--> $DIR/hidden-lifetimes-in-types.rs:15:9
|
LL | #![deny(elided_lifetimes_in_paths)]
LL | #![deny(hidden_lifetimes_in_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: implicit lifetime parameters in types are deprecated
--> $DIR/elided-lifetimes.rs:37:29
error: hidden lifetime parameters in types are deprecated
--> $DIR/hidden-lifetimes-in-types.rs:37:29
|
LL | fn wrap_gift(gift: &str) -> Wrapped {
| ^^^^^^^- help: indicate the anonymous lifetime: `<'_>`

error: implicit lifetime parameters in types are deprecated
--> $DIR/elided-lifetimes.rs:43:38
error: hidden lifetime parameters in types are deprecated
--> $DIR/hidden-lifetimes-in-types.rs:43:38
|
LL | fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow {
| ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`

error: implicit lifetime parameters in types are deprecated
--> $DIR/elided-lifetimes.rs:77:18
error: hidden lifetime parameters in types are deprecated
--> $DIR/hidden-lifetimes-in-types.rs:77:18
|
LL | let loyalty: Ref<(u32, char)> = honesty.borrow();
| ^^^^^^^^^^^^^^^^ help: indicate the anonymous lifetime: `Ref<'_, (u32, char)>`

error: implicit lifetime parameters in types are deprecated
--> $DIR/elided-lifetimes.rs:69:9
error: hidden lifetime parameters in types are deprecated
--> $DIR/hidden-lifetimes-in-types.rs:69:9
|
LL | Ref<($($types),*)>
| ^^^^^^^^^^^^^^^^^^ help: indicate the anonymous lifetime: `Ref<'_, ($($types),*)>`
...
LL | let yellow: anytuple_ref_ty!(bool, &str) = laughter.borrow();
| ---------------------------- in this macro invocation

error: implicit lifetime parameters in types are deprecated
--> $DIR/elided-lifetimes.rs:55:36
error: hidden lifetime parameters in types are deprecated
--> $DIR/hidden-lifetimes-in-types.rs:55:36
|
LL | fn $fn_name(gift: &str) -> $type_name {
| ^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
Expand Down

0 comments on commit be9758a

Please sign in to comment.