Skip to content

Commit ba17759

Browse files
committed
Make lifetime elision help more useful on type signatures.
Fixes rust-lang#19707.
1 parent 6366631 commit ba17759

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/librustc_typeck/astconv.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,16 @@ pub fn opt_ast_region_to_region<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
164164
let mut m = String::new();
165165
let len = v.len();
166166
for (i, (name, n)) in v.into_iter().enumerate() {
167-
m.push_str(if n == 1 {
167+
let help_name = if name.is_empty() {
168+
format!("argument {}", i + 1)
169+
} else {
168170
format!("`{}`", name)
171+
};
172+
173+
m.push_str(if n == 1 {
174+
help_name
169175
} else {
170-
format!("one of `{}`'s {} elided lifetimes", name, n)
176+
format!("one of {}'s {} elided lifetimes", help_name, n)
171177
}[]);
172178

173179
if len == 2 && i == 0 {

src/test/compile-fail/issue-19707.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 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+
#![feature(unboxed_closures)]
12+
#![allow(dead_code)]
13+
14+
type foo = fn(&u8, &u8) -> &u8; //~ ERROR missing lifetime specifier
15+
//~^ HELP the signature does not say whether it is borrowed from argument 1 or argument 2
16+
17+
fn bar<F: Fn(&u8, &u8) -> &u8>(f: &F) {} //~ ERROR missing lifetime specifier
18+
//~^ HELP the signature does not say whether it is borrowed from argument 1 or argument 2
19+
20+
fn main() {}

0 commit comments

Comments
 (0)