about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2017-08-05 03:13:38 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2017-08-05 14:59:28 +0300
commit7704762604a8bf4504a06e8c9713bc7c158d362a (patch)
tree11ae6d11341b2d01e37e8b0a6b51540d45ae5e17
parent5c7add7551fa093f655e76650a48564ac347c83a (diff)
downloadrust-7704762604a8bf4504a06e8c9713bc7c158d362a.tar.gz
rust-7704762604a8bf4504a06e8c9713bc7c158d362a.zip
Use usual lifetime elision rules for foreign functions
-rw-r--r--src/librustc/middle/resolve_lifetime.rs16
-rw-r--r--src/test/compile-fail/foreign-fn-return-lifetime.rs16
2 files changed, 18 insertions, 14 deletions
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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}