From 05d5c593339334314f66ebc33c6a4ba2e17fe602 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 25 Nov 2017 18:00:58 +0530 Subject: [PATCH] elided lifetime --- src/librustc/lint/builtin.rs | 9 ++++++++- src/librustc/middle/resolve_lifetime.rs | 6 +++--- .../compile-fail/lint-elided-lifetime-in-path.rs | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/test/compile-fail/lint-elided-lifetime-in-path.rs diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 75446586365dd..dcb01880f6b45 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -216,6 +216,12 @@ declare_lint! { "detect mut variables which don't need to be mutable" } +declare_lint! { + pub ELIDED_LIFETIME_IN_PATH, + Allow, + "hidden lifetime parameters are deprecated, try `Foo<'_>`" +} + /// Does nothing as a lint pass, but registers some `Lint`s /// which are used by other parts of the compiler. #[derive(Copy, Clone)] @@ -256,7 +262,8 @@ impl LintPass for HardwiredLints { LATE_BOUND_LIFETIME_ARGUMENTS, DEPRECATED, UNUSED_UNSAFE, - UNUSED_MUT + UNUSED_MUT, + ELIDED_LIFETIME_IN_PATH ) } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index b39975d3ff919..27788b44e1a89 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -530,7 +530,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { fn visit_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime) { if lifetime_ref.is_elided() { - self.resolve_elided_lifetimes(slice::ref_slice(lifetime_ref)); + self.resolve_elided_lifetimes(slice::ref_slice(lifetime_ref), false); return; } if lifetime_ref.is_static() { @@ -1114,7 +1114,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } if params.lifetimes.iter().all(|l| l.is_elided()) { - self.resolve_elided_lifetimes(¶ms.lifetimes); + self.resolve_elided_lifetimes(¶ms.lifetimes, true); } else { for l in ¶ms.lifetimes { self.visit_lifetime(l); } } @@ -1445,7 +1445,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } - fn resolve_elided_lifetimes(&mut self, lifetime_refs: &[hir::Lifetime]) { + fn resolve_elided_lifetimes(&mut self, lifetime_refs: &[hir::Lifetime], deprecated: bool) { if lifetime_refs.is_empty() { return; } diff --git a/src/test/compile-fail/lint-elided-lifetime-in-path.rs b/src/test/compile-fail/lint-elided-lifetime-in-path.rs new file mode 100644 index 0000000000000..6f42b456f9cdd --- /dev/null +++ b/src/test/compile-fail/lint-elided-lifetime-in-path.rs @@ -0,0 +1,15 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(elided_lifetime_in_path)] +struct Foo<'a> { x: &'a u32 } +fn foo(x: &Foo) { + //~ ^warning: hidden lifetime parameters are deprecated, try `Foo<'_>` +} \ No newline at end of file