diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 13efa94a5c9..12362c8d3bf 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1081,20 +1081,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { Some(body) } - // `fn(...) -> R` and `Trait(...) -> R` (both types and bounds). - hir::map::NodeTy(_) | hir::map::NodeTraitRef(_) => None, - - // Foreign `fn` decls are terrible because we messed up, - // and their return types get argument type elision. - // And now too much code out there is abusing this rule. - hir::map::NodeForeignItem(_) => { - let arg_scope = Scope::Elision { - elide: arg_elide, - s: self.scope - }; - self.with(arg_scope, |_, this| this.visit_ty(output)); - return; - } + // Foreign functions, `fn(...) -> R` and `Trait(...) -> R` (both types and bounds). + hir::map::NodeForeignItem(_) | hir::map::NodeTy(_) | hir::map::NodeTraitRef(_) => None, // Everything else (only closures?) doesn't // actually enjoy elision in return types. diff --git a/src/test/compile-fail/foreign-fn-return-lifetime.rs b/src/test/compile-fail/foreign-fn-return-lifetime.rs new file mode 100644 index 00000000000..da77066150c --- /dev/null +++ b/src/test/compile-fail/foreign-fn-return-lifetime.rs @@ -0,0 +1,16 @@ +// 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. + +extern "C" { + fn g(_: &u8) -> &u8; // OK + fn f() -> &u8; //~ ERROR missing lifetime specifier +} + +fn main() {}