Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
45b97f2
miri: use backtrace crate printing instead of rolling our own
RalfJung Dec 11, 2018
b17a3f2
fix rust-lang/rust issue #50583
piersfinlayson Dec 11, 2018
8e994a2
bump backtrace version to get prettier pretty-printing
RalfJung Dec 11, 2018
b96186b
Add missing urls in ffi module docs
GuillaumeGomez Dec 11, 2018
517bfe0
Fix private_no_mangle_fns message grammar
turboladen Dec 12, 2018
29e7ca9
Add test of current behavior (infer free region within closure body) …
pnkfelix Dec 10, 2018
29bec2d
target: remove Box returned from get_targets
ljedrz Dec 12, 2018
8a6ca24
Allow ptr::hash to accept fat pointers
mbrubeck Dec 12, 2018
b9235ea
Account for `impl Trait` when suggesting lifetime
estebank Dec 12, 2018
ae893bb
Add short emoji status to toolstate updates
Manishearth Dec 12, 2018
bec5b66
Deduplicate unsatisfied trait bounds
estebank Dec 12, 2018
88cf2a2
Add x86_64-unknown-uefi target
Dec 13, 2018
a39f184
Use `dedup` instead of `dedup_by`
oli-obk Dec 13, 2018
b6b278e
Fixes broken links
jrvidal Dec 14, 2018
275deac
Fix docs path to PermissionsExt
dbrgn Dec 14, 2018
c435357
Bootstrap: Add testsuite for compiletest tool
phansch Dec 13, 2018
9f3151a
Rollup merge of #56718 - RalfJung:use-libbacktrace-printing, r=alexcr…
pietroalbini Dec 15, 2018
63acc9f
Rollup merge of #56725 - piersfinlayson:master, r=alexcrichton
pietroalbini Dec 15, 2018
3af0cf8
Rollup merge of #56731 - GuillaumeGomez:ffi-doc-urls, r=Centril
pietroalbini Dec 15, 2018
846db94
Rollup merge of #56738 - turboladen:fix-private_no_mangle_fns-message…
pietroalbini Dec 15, 2018
9544c17
Rollup merge of #56746 - pnkfelix:issue-56537-add-test-of-closure-usi…
pietroalbini Dec 15, 2018
3a9fa9b
Rollup merge of #56747 - ljedrz:remove_box_from_target, r=zackmdavis
pietroalbini Dec 15, 2018
7c83737
Rollup merge of #56751 - mbrubeck:hash, r=dtolnay
pietroalbini Dec 15, 2018
c530e31
Rollup merge of #56755 - estebank:impl-trait-lt-sugg, r=cramertj
pietroalbini Dec 15, 2018
050bb10
Rollup merge of #56758 - Manishearth:emoji-status-toolstate, r=kennytm
pietroalbini Dec 15, 2018
e433da7
Rollup merge of #56760 - estebank:dedup-bounds, r=oli-obk
pietroalbini Dec 15, 2018
1116546
Rollup merge of #56769 - dvdhrm:uefi-target, r=alexcrichton
pietroalbini Dec 15, 2018
1f0a730
Rollup merge of #56792 - phansch:add_compiletest_testsuite, r=alexcri…
pietroalbini Dec 15, 2018
a352dd4
Rollup merge of #56808 - jrvidal:broken-links, r=kennytm
pietroalbini Dec 15, 2018
ae3882c
Rollup merge of #56809 - dbrgn:permissions-ext, r=alexcrichton
pietroalbini Dec 15, 2018
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
31 changes: 20 additions & 11 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,15 +1095,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
let sp = hir.span(id);
// `sp` only covers `T`, change it so that it covers
// `T:` when appropriate
let sp = if has_bounds {
let is_impl_trait = bound_kind.to_string().starts_with("impl ");
let sp = if has_bounds && !is_impl_trait {
sp.to(self.tcx
.sess
.source_map()
.next_point(self.tcx.sess.source_map().next_point(sp)))
} else {
sp
};
(sp, has_bounds)
(sp, has_bounds, is_impl_trait)
})
} else {
None
Expand Down Expand Up @@ -1136,25 +1137,33 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

fn binding_suggestion<'tcx, S: fmt::Display>(
err: &mut DiagnosticBuilder<'tcx>,
type_param_span: Option<(Span, bool)>,
type_param_span: Option<(Span, bool, bool)>,
bound_kind: GenericKind<'tcx>,
sub: S,
) {
let consider = &format!(
"consider adding an explicit lifetime bound `{}: {}`...",
bound_kind, sub
let consider = format!(
"consider adding an explicit lifetime bound {}",
if type_param_span.map(|(_, _, is_impl_trait)| is_impl_trait).unwrap_or(false) {
format!(" `{}` to `{}`...", sub, bound_kind)
} else {
format!("`{}: {}`...", bound_kind, sub)
},
);
if let Some((sp, has_lifetimes)) = type_param_span {
let tail = if has_lifetimes { " + " } else { "" };
let suggestion = format!("{}: {}{}", bound_kind, sub, tail);
if let Some((sp, has_lifetimes, is_impl_trait)) = type_param_span {
let suggestion = if is_impl_trait {
format!("{} + {}", bound_kind, sub)
} else {
let tail = if has_lifetimes { " + " } else { "" };
format!("{}: {}{}", bound_kind, sub, tail)
};
err.span_suggestion_short_with_applicability(
sp,
consider,
&consider,
suggestion,
Applicability::MaybeIncorrect, // Issue #41966
);
} else {
err.help(consider);
err.help(&consider);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/suggestions/suggest-impl-trait-lifetime.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// run-rustfix

use std::fmt::Debug;

fn foo(d: impl Debug + 'static) {
//~^ HELP consider adding an explicit lifetime bound `'static` to `impl Debug`
bar(d);
//~^ ERROR the parameter type `impl Debug` may not live long enough
//~| NOTE ...so that the type `impl Debug` will meet its required lifetime bounds
}

fn bar(d: impl Debug + 'static) {
println!("{:?}", d)
}

fn main() {
foo("hi");
}
18 changes: 18 additions & 0 deletions src/test/ui/suggestions/suggest-impl-trait-lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// run-rustfix

use std::fmt::Debug;

fn foo(d: impl Debug) {
//~^ HELP consider adding an explicit lifetime bound `'static` to `impl Debug`
bar(d);
//~^ ERROR the parameter type `impl Debug` may not live long enough
//~| NOTE ...so that the type `impl Debug` will meet its required lifetime bounds
}

fn bar(d: impl Debug + 'static) {
println!("{:?}", d)
}

fn main() {
foo("hi");
}
19 changes: 19 additions & 0 deletions src/test/ui/suggestions/suggest-impl-trait-lifetime.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0310]: the parameter type `impl Debug` may not live long enough
--> $DIR/suggest-impl-trait-lifetime.rs:7:5
|
LL | bar(d);
| ^^^
|
note: ...so that the type `impl Debug` will meet its required lifetime bounds
--> $DIR/suggest-impl-trait-lifetime.rs:7:5
|
LL | bar(d);
| ^^^
help: consider adding an explicit lifetime bound `'static` to `impl Debug`...
|
LL | fn foo(d: impl Debug + 'static) {
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

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