Skip to content

Commit e40dc66

Browse files
committedAug 16, 2017
Auto merge of #43651 - petrochenkov:foreign-life, r=eddyb
Fix ICE with elided lifetimes in return type of foreign functions cc #43567 This is for a preliminary crater/cargobomb run. Lifetime elision in foreign functions now works exactly like in other functions or function-like entities. If the breakage is significant, I'll have to partially revert #43543 (all the stuff that was required for dealing with late bound lifetimes in this position). r? @eddyb
2 parents 1e60a47 + 7704762 commit e40dc66

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed
 

‎src/librustc/middle/resolve_lifetime.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -1081,20 +1081,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
10811081
Some(body)
10821082
}
10831083

1084-
// `fn(...) -> R` and `Trait(...) -> R` (both types and bounds).
1085-
hir::map::NodeTy(_) | hir::map::NodeTraitRef(_) => None,
1086-
1087-
// Foreign `fn` decls are terrible because we messed up,
1088-
// and their return types get argument type elision.
1089-
// And now too much code out there is abusing this rule.
1090-
hir::map::NodeForeignItem(_) => {
1091-
let arg_scope = Scope::Elision {
1092-
elide: arg_elide,
1093-
s: self.scope
1094-
};
1095-
self.with(arg_scope, |_, this| this.visit_ty(output));
1096-
return;
1097-
}
1084+
// Foreign functions, `fn(...) -> R` and `Trait(...) -> R` (both types and bounds).
1085+
hir::map::NodeForeignItem(_) | hir::map::NodeTy(_) | hir::map::NodeTraitRef(_) => None,
10981086

10991087
// Everything else (only closures?) doesn't
11001088
// actually enjoy elision in return types.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern "C" {
12+
fn g(_: &u8) -> &u8; // OK
13+
fn f() -> &u8; //~ ERROR missing lifetime specifier
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.