Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7e8758b
Update compiler_builtins to 0.1.7
jordanrh1 Mar 5, 2019
967e7f4
resolve: Account for new importable entities
petrochenkov Mar 9, 2019
d320b4a
Add tests for malformed input in `#[proc_macro_derive]`
petrochenkov Feb 28, 2019
18d6c6e
syntax: Do not accidentally treat multi-segment meta-items as single-…
petrochenkov Feb 28, 2019
f3b8809
syntax_ext: Validate `#[proc_macro_derive]` input better
petrochenkov Mar 3, 2019
7d90794
syntax: Introduce `Ident::can_be_raw`
petrochenkov Feb 27, 2019
e81535c
Rename `MetaItem::ident` to `MetaItem::path`
petrochenkov Mar 2, 2019
98de9b7
Refactor away `NestedMetaItemKind`
petrochenkov Mar 3, 2019
bfb200d
Fix rebase
petrochenkov Mar 10, 2019
e25df32
consistent naming for duration_float methods and additional f32 methods
newpavlov Mar 11, 2019
35c19c5
move MAX_NANOS_F64/32 to methods
newpavlov Mar 11, 2019
980871a
fix tests
newpavlov Mar 11, 2019
197efb0
fix test
newpavlov Mar 11, 2019
b9d12ed
Be more discerning on when to attempt suggesting a comma in a macro i…
estebank Mar 11, 2019
78b248d
fix typo
newpavlov Mar 12, 2019
795d307
Suggest return lifetime when there's only one named lifetime
estebank Mar 12, 2019
f923476
review comments
estebank Mar 12, 2019
adbd0a6
Make std time tests more robust for platform differences
Mar 12, 2019
0ea9b58
Suggest adding lifetime to struct field
estebank Mar 13, 2019
27abd52
Fix operator precedence
estebank Mar 13, 2019
9d938f6
Add test for #55809.
davidtwco Mar 13, 2019
311025e
Fix generic argument lookup for Self
Mar 7, 2019
9758d97
Rollup merge of #58789 - jordanrh1:update-compiler-builtins, r=sanxiyn
Centril Mar 13, 2019
80049d9
Rollup merge of #58899 - petrochenkov:derval2, r=estebank
Centril Mar 13, 2019
d263029
Rollup merge of #59025 - aoikonomopoulos:issue-57924, r=varkor
Centril Mar 13, 2019
f5138a9
Rollup merge of #59047 - petrochenkov:modnodefid, r=Centril
Centril Mar 13, 2019
7787734
Rollup merge of #59102 - newpavlov:duration_float, r=alexcrichton
Centril Mar 13, 2019
4e992e0
Rollup merge of #59116 - estebank:comma-sugg, r=petrochenkov
Centril Mar 13, 2019
156fec0
Rollup merge of #59146 - estebank:suggest-return-lt, r=varkor
Centril Mar 13, 2019
353740d
Rollup merge of #59147 - jethrogb:jb/time-tests, r=sfackler
Centril Mar 13, 2019
3569af1
Rollup merge of #59156 - davidtwco:issue-55809, r=nikomatsakis
Centril Mar 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2299,19 +2299,26 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
let span = lifetime_refs[0].span;
let mut late_depth = 0;
let mut scope = self.scope;
let mut lifetime_names = FxHashSet::default();
let error = loop {
match *scope {
// Do not assign any resolution, it will be inferred.
Scope::Body { .. } => return,

Scope::Root => break None,

Scope::Binder { s, .. } => {
Scope::Binder { s, ref lifetimes, .. } => {
// collect named lifetimes for suggestions
for name in lifetimes.keys() {
if let hir::ParamName::Plain(name) = name {
lifetime_names.insert(*name);
}
}
late_depth += 1;
scope = s;
}

Scope::Elision { ref elide, .. } => {
Scope::Elision { ref elide, ref s, .. } => {
let lifetime = match *elide {
Elide::FreshLateAnon(ref counter) => {
for lifetime_ref in lifetime_refs {
Expand All @@ -2321,7 +2328,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
return;
}
Elide::Exact(l) => l.shifted(late_depth),
Elide::Error(ref e) => break Some(e),
Elide::Error(ref e) => {
if let Scope::Binder { ref lifetimes, .. } = s {
// collect named lifetimes for suggestions
for name in lifetimes.keys() {
if let hir::ParamName::Plain(name) = name {
lifetime_names.insert(*name);
}
}
}
break Some(e);
}
};
for lifetime_ref in lifetime_refs {
self.insert_lifetime(lifetime_ref, lifetime);
Expand All @@ -2344,7 +2361,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
}
}
if add_label {
add_missing_lifetime_specifiers_label(&mut err, span, lifetime_refs.len());
add_missing_lifetime_specifiers_label(
&mut err,
span,
lifetime_refs.len(),
&lifetime_names,
self.tcx.sess.source_map().span_to_snippet(span).ok().as_ref().map(|s| s.as_str()),
);
}

err.emit();
Expand Down Expand Up @@ -2885,10 +2908,23 @@ fn add_missing_lifetime_specifiers_label(
err: &mut DiagnosticBuilder<'_>,
span: Span,
count: usize,
lifetime_names: &FxHashSet<ast::Ident>,
snippet: Option<&str>,
) {
if count > 1 {
err.span_label(span, format!("expected {} lifetime parameters", count));
} else if let (1, Some(name), Some("&")) = (
lifetime_names.len(),
lifetime_names.iter().next(),
snippet,
) {
err.span_suggestion(
span,
"consider using the named lifetime",
format!("&{} ", name),
Applicability::MaybeIncorrect,
);
} else {
err.span_label(span, "expected lifetime parameter");
};
}
}
10 changes: 10 additions & 0 deletions src/test/ui/suggestions/return-without-lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
struct Thing<'a>(&'a ());
struct Foo<'a>(&usize);
//~^ ERROR missing lifetime specifier

fn func1<'a>(_arg: &'a Thing) -> &() { unimplemented!() }
//~^ ERROR missing lifetime specifier
fn func2<'a>(_arg: &Thing<'a>) -> &() { unimplemented!() }
//~^ ERROR missing lifetime specifier

fn main() {}
25 changes: 25 additions & 0 deletions src/test/ui/suggestions/return-without-lifetime.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0106]: missing lifetime specifier
--> $DIR/return-without-lifetime.rs:2:16
|
LL | struct Foo<'a>(&usize);
| ^ help: consider using the named lifetime: `&'a`

error[E0106]: missing lifetime specifier
--> $DIR/return-without-lifetime.rs:5:34
|
LL | fn func1<'a>(_arg: &'a Thing) -> &() { unimplemented!() }
| ^ help: consider using the named lifetime: `&'a`
|
= help: this function's return type contains a borrowed value, but the signature does not say which one of `_arg`'s 2 lifetimes it is borrowed from

error[E0106]: missing lifetime specifier
--> $DIR/return-without-lifetime.rs:7:35
|
LL | fn func2<'a>(_arg: &Thing<'a>) -> &() { unimplemented!() }
| ^ help: consider using the named lifetime: `&'a`
|
= help: this function's return type contains a borrowed value, but the signature does not say which one of `_arg`'s 2 lifetimes it is borrowed from

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0106`.