Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #73271

Closed
wants to merge 26 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ba9588e
Add `const_float_bits_conv` for `f64::to_bits` and friends
ecstatic-morse May 22, 2020
040da96
Make floating point classify functions `const fn`
ecstatic-morse May 23, 2020
cbc14a2
Test new floating point bit casts
ecstatic-morse May 22, 2020
407f9a4
Ensure consts get compared at runtime
ecstatic-morse May 23, 2020
9dadeb3
Test `is_nan`
ecstatic-morse May 23, 2020
d1c275b
linker: MSVC supports linking static libraries as a whole archive
petrochenkov May 30, 2020
687767a
Suggest substituting `'static` lifetime in impl/dyn `Trait + 'static`…
estebank May 29, 2020
c91320f
When `'static` is explicit, suggest constraining argument with it
estebank May 30, 2020
abf74b9
Reduce verbosity of suggestion message and mention lifetime in label
estebank May 30, 2020
50c422e
Move overlapping span to a note
estebank May 30, 2020
17951e2
Tweak output for overlapping required/captured spans
estebank May 30, 2020
19bb589
Tweak wording and add error code
estebank May 30, 2020
3cfecde
review comments: wording
estebank Jun 1, 2020
bdfb9b1
Use note for requirement source span
estebank Jun 2, 2020
215de3b
Register new eror code
estebank Jun 2, 2020
187e105
small tweaks
estebank Jun 2, 2020
6145918
Change E0758 to E0759 to avoid conflict with #72912
estebank Jun 3, 2020
fff822f
Migrate to numeric associated consts
tesuji Jun 2, 2020
c29b3fa
On recursive ADT, provide indirection structured suggestion
estebank May 29, 2020
7cde07e
review comments: only suggest one substitution
estebank May 31, 2020
03552ec
fix rebase
estebank Jun 10, 2020
802a9ac
Rollup merge of #72449 - ecstatic-morse:const-float-bitcast, r=RalfJu…
RalfJung Jun 12, 2020
35e5dfe
Rollup merge of #72740 - estebank:recursive-indirection, r=matthewjasper
RalfJung Jun 12, 2020
97ae4f6
Rollup merge of #72785 - petrochenkov:wholemsvc, r=matthewjasper
RalfJung Jun 12, 2020
cb425c8
Rollup merge of #72804 - estebank:opaque-missing-lts-in-fn-2, r=nikom…
RalfJung Jun 12, 2020
eda9d21
Rollup merge of #72906 - lzutao:migrate-numeric-assoc-consts, r=dtolnay
RalfJung Jun 12, 2020
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
Prev Previous commit
Next Next commit
Reduce verbosity of suggestion message and mention lifetime in label
estebank committed Jun 9, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
hoangnt2 Nguyen Thai Hoang
commit abf74b9e729463a18f5da1d79cecaf9f4fc07d17
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Error Reporting for static impl Traits.
use crate::infer::error_reporting::msg_span_from_free_region;
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
use rustc_errors::{Applicability, ErrorReported};
@@ -33,9 +32,17 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let sp = var_origin.span();
let return_sp = sub_origin.span();
let param_info = self.find_param_with_region(sup_r, sub_r)?;
let (lifetime_name, lifetime) = if sup_r.has_name() {
(sup_r.to_string(), format!("lifetime `{}`", sup_r))
} else {
("'_".to_owned(), "the anonymous lifetime `'_`".to_string())
};
let mut err =
self.tcx().sess.struct_span_err(sp, "cannot infer an appropriate lifetime");
err.span_label(param_info.param_ty_span, "data with this lifetime...");
err.span_label(
param_info.param_ty_span,
&format!("this data with {}...", lifetime),
);
debug!("try_report_static_impl_trait: param_info={:?}", param_info);

// We try to make the output have fewer overlapping spans if possible.
@@ -60,10 +67,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
);
}

let (lifetime, _) = msg_span_from_free_region(self.tcx(), sup_r);

let lifetime_name =
if sup_r.has_name() { sup_r.to_string() } else { "'_".to_owned() };
// only apply this suggestion onto functions with
// explicit non-desugar'able return.
if fn_return.span.desugaring_kind().is_none() {
@@ -93,8 +96,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
{
err.span_suggestion_verbose(
span,
"consider changing the `impl Trait`'s explicit \
`'static` bound",
&format!(
"consider changing the `impl Trait`'s explicit \
`'static` bound to {}",
lifetime,
),
lifetime_name,
Applicability::MaybeIncorrect,
);
@@ -118,40 +124,41 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
);
};
}
TyKind::TraitObject(_, lt) => {
match lt.name {
LifetimeName::ImplicitObjectLifetimeDefault => {
err.span_suggestion_verbose(
fn_return.span.shrink_to_hi(),
&format!(
"to permit non-static references in a trait object \
value, you can add an explicit bound for {}",
lifetime,
),
format!(" + {}", lifetime_name),
Applicability::MaybeIncorrect,
);
}
_ => {
err.span_suggestion_verbose(
lt.span,
TyKind::TraitObject(_, lt) => match lt.name {
LifetimeName::ImplicitObjectLifetimeDefault => {
err.span_suggestion_verbose(
fn_return.span.shrink_to_hi(),
&format!(
"to permit non-static references in a trait object \
value, you can add an explicit bound for {}",
lifetime,
),
format!(" + {}", lifetime_name),
Applicability::MaybeIncorrect,
);
}
_ => {
err.span_suggestion_verbose(
lt.span,
&format!(
"consider changing the trait object's explicit \
`'static` bound",
lifetime_name,
Applicability::MaybeIncorrect,
);
err.span_suggestion_verbose(
param_info.param_ty_span,
&format!(
"alternatively, set an explicit `'static` lifetime \
in this parameter",
),
param_info.param_ty.to_string(),
Applicability::MaybeIncorrect,
);
}
`'static` bound to {}",
lifetime,
),
lifetime_name,
Applicability::MaybeIncorrect,
);
err.span_suggestion_verbose(
param_info.param_ty_span,
&format!(
"alternatively, set an explicit `'static` lifetime \
in this parameter",
),
param_info.param_ty.to_string(),
Applicability::MaybeIncorrect,
);
}
}
},
_ => {}
}
}
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issues/issue-62097.stderr
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ error: cannot infer an appropriate lifetime
LL | pub async fn run_dummy_fn(&self) {
| ^^^^^
| |
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
| ...is captured here...
LL | foo(|| self.bar()).await;
| --- ...and required to be `'static` by this
38 changes: 20 additions & 18 deletions src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@ LL | fn elided(x: &i32) -> impl Copy { x }
| ---- --------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 3:1
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ^^^^
@@ -19,9 +19,9 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| ------- --------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with lifetime `'a`...
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the lifetime `'a` as defined on the function body at 6:13
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for lifetime `'a`
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ^^^^
@@ -33,9 +33,9 @@ LL | fn elided2(x: &i32) -> impl Copy + 'static { x }
| ---- ------------------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
|
help: consider changing the `impl Trait`'s explicit `'static` bound
help: consider changing the `impl Trait`'s explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn elided2(x: &i32) -> impl Copy + '_ { x }
| ^^
@@ -51,9 +51,9 @@ LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'static { x }
| ------- ------------------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with lifetime `'a`...
|
help: consider changing the `impl Trait`'s explicit `'static` bound
help: consider changing the `impl Trait`'s explicit `'static` bound to lifetime `'a`
|
LL | fn explicit2<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ^^
@@ -77,9 +77,9 @@ LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x }
| ------- -------------------------------- ^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with lifetime `'a`...
|
help: consider changing the `impl Trait`'s explicit `'static` bound
help: consider changing the `impl Trait`'s explicit `'static` bound to lifetime `'a`
|
LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'a { x }
| ^^
@@ -113,9 +113,9 @@ LL | fn elided3(x: &i32) -> Box<dyn Debug> { Box::new(x) }
| | | |
| | | ...and is captured here
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 18:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn elided3(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
| ^^^^
@@ -128,9 +128,9 @@ LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug> { Box::new(x) }
| | | |
| | | ...and is captured here
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with lifetime `'a`...
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the lifetime `'a` as defined on the function body at 21:14
help: to permit non-static references in a trait object value, you can add an explicit bound for lifetime `'a`
|
LL | fn explicit3<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
| ^^^^
@@ -142,9 +142,10 @@ LL | fn elided4(x: &i32) -> Box<dyn Debug + 'static> { Box::new(x) }
| ---- ---------^-
| | | |
| | | ...and is captured here
| data with this lifetime... ...is required to be `'static` by this...
| | ...is required to be `'static` by this...
| this data with the anonymous lifetime `'_`...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn elided4(x: &i32) -> Box<dyn Debug + '_> { Box::new(x) }
| ^^
@@ -160,9 +161,10 @@ LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'static> { Box::new(x) }
| ------- ---------^-
| | | |
| | | ...and is captured here
| data with this lifetime... ...is required to be `'static` by this...
| | ...is required to be `'static` by this...
| this data with lifetime `'a`...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
LL | fn explicit4<'a>(x: &'a i32) -> Box<dyn Debug + 'a> { Box::new(x) }
| ^^
8 changes: 4 additions & 4 deletions src/test/ui/impl-trait/static-return-lifetime-infered.stderr
Original file line number Diff line number Diff line change
@@ -4,13 +4,13 @@ error: cannot infer an appropriate lifetime
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
| ----- ----------------------- ...is required to be `'static` by this...
| |
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
LL | self.x.iter().map(|a| a.0)
| ------ ^^^^
| |
| ...and is captured here
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the method body at 6:5
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ^^^^
@@ -21,13 +21,13 @@ error: cannot infer an appropriate lifetime
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
| -------- ----------------------- ...is required to be `'static` by this...
| |
| data with this lifetime...
| this data with lifetime `'a`...
LL | self.x.iter().map(|a| a.0)
| ------ ^^^^
| |
| ...and is captured here
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the lifetime `'a` as defined on the method body at 10:20
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for lifetime `'a`
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
| ^^^^
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-16922.stderr
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/issue-16922.rs:4:14
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
| -- data with this lifetime...
| -- this data with the anonymous lifetime `'_`...
LL | Box::new(value) as Box<dyn Any>
| ---------^^^^^-
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 3:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
| ^^^^
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@ error: cannot infer an appropriate lifetime
--> $DIR/object-lifetime-default-from-box-error.rs:18:5
|
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
| --------------- data with this lifetime...
| --------------- this data with the anonymous lifetime `'_`...
...
LL | ss.r
| ^^^^ ...is captured and required to be `'static` here
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #2 defined on the function body at 14:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait + '_> {
| ^^^^
12 changes: 6 additions & 6 deletions src/test/ui/regions/region-object-lifetime-in-coercion.stderr
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:8:46
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + 'static> {
| ----- data with this lifetime...
| ----- this data with the anonymous lifetime `'_`...
LL | let x: Box<dyn Foo + 'static> = Box::new(v);
| ---------^-
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn a(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^
@@ -22,14 +22,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:13:14
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + 'static> {
| ----- data with this lifetime...
| ----- this data with the anonymous lifetime `'_`...
LL | Box::new(v)
| ---------^-
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn b(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^
@@ -42,15 +42,15 @@ error: cannot infer an appropriate lifetime
--> $DIR/region-object-lifetime-in-coercion.rs:19:14
|
LL | fn c(v: &[u8]) -> Box<dyn Foo> {
| ----- data with this lifetime...
| ----- this data with the anonymous lifetime `'_`...
...
LL | Box::new(v)
| ---------^-
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 16:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn c(v: &[u8]) -> Box<dyn Foo + '_> {
| ^^^^
4 changes: 2 additions & 2 deletions src/test/ui/regions/regions-close-object-into-object-2.stderr
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/regions-close-object-into-object-2.rs:10:11
|
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'static> {
| ------------------ data with this lifetime...
| ------------------ this data with lifetime `'a`...
LL | box B(&*v) as Box<dyn X>
| ------^^^---------------
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
LL | fn g<'a, T: 'static>(v: Box<dyn A<T> + 'a>) -> Box<dyn X + 'a> {
| ^^
4 changes: 2 additions & 2 deletions src/test/ui/regions/regions-close-object-into-object-4.stderr
Original file line number Diff line number Diff line change
@@ -2,14 +2,14 @@ error: cannot infer an appropriate lifetime
--> $DIR/regions-close-object-into-object-4.rs:10:11
|
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'static> {
| ---------------- data with this lifetime...
| ---------------- this data with lifetime `'a`...
LL | box B(&*v) as Box<dyn X>
| ------^^^---------------
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to lifetime `'a`
|
LL | fn i<'a, T, U>(v: Box<dyn A<U>+'a>) -> Box<dyn X + 'a> {
| ^^
4 changes: 2 additions & 2 deletions src/test/ui/regions/regions-proc-bound-capture.stderr
Original file line number Diff line number Diff line change
@@ -2,15 +2,15 @@ error: cannot infer an appropriate lifetime
--> $DIR/regions-proc-bound-capture.rs:9:14
|
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + 'static> {
| ------ data with this lifetime...
| ------ this data with the anonymous lifetime `'_`...
LL | // This is illegal, because the region bound on `proc` is 'static.
LL | Box::new(move || { *x })
| ---------^^^^^^^^^^^^^^-
| | |
| | ...and is captured here
| ...is required to be `'static` by this...
|
help: consider changing the trait object's explicit `'static` bound
help: consider changing the trait object's explicit `'static` bound to the anonymous lifetime `'_`
|
LL | fn static_proc(x: &isize) -> Box<dyn FnMut() -> (isize) + '_> {
| ^^
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ error: cannot infer an appropriate lifetime
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
| ^^^^ ---------- ---------- ...and required to be `'static` by this
| | |
| | data with this lifetime...
| | this data with the anonymous lifetime `'_`...
| ...is captured here...

error: aborting due to previous error
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@ LL | fn f(self: Pin<&Self>) -> impl Clone { self }
| ---------- ---------- ^^^^ ...and is captured here
| | |
| | ...is required to be `'static` by this...
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the method body at 6:5
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
| ^^^^
Original file line number Diff line number Diff line change
@@ -12,14 +12,14 @@ error: cannot infer an appropriate lifetime
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
| ------ ------------- ...is required to be `'static` by this...
| |
| data with this lifetime...
| this data with the anonymous lifetime `'_`...
...
LL | / move || {
LL | | *dest = g.get();
LL | | }
| |_____^ ...and is captured here
|
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 15:1
help: to permit non-static references in an `impl Trait` value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
| ^^^^
4 changes: 2 additions & 2 deletions src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr
Original file line number Diff line number Diff line change
@@ -2,12 +2,12 @@ error: cannot infer an appropriate lifetime
--> $DIR/dyn-trait-underscore.rs:8:20
|
LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
| ---- data with this lifetime...
| ---- this data with the anonymous lifetime `'_`...
LL | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
LL | Box::new(items.iter())
| ---------------^^^^--- ...is captured and required to be `'static` here
|
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime #1 defined on the function body at 6:1
help: to permit non-static references in a trait object value, you can add an explicit bound for the anonymous lifetime `'_`
|
LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T> + '_> {
| ^^^^