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

Include a span in more expected...found notes #67011

Merged
merged 1 commit into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1809,12 +1809,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
sub_region,
"...",
);
err.note(&format!(
"...so that the {}:\nexpected {}\n found {}",
sup_trace.cause.as_requirement_str(),
sup_expected.content(),
sup_found.content()
err.span_note(sup_trace.cause.span, &format!(
"...so that the {}",
sup_trace.cause.as_requirement_str()
));

err.note_expected_found(
&"",
sup_expected,
&"",
sup_found
);
err.emit();
return;
}
Expand Down
20 changes: 14 additions & 6 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
match *origin {
infer::Subtype(ref trace) => {
if let Some((expected, found)) = self.values_str(&trace.values) {
let expected = expected.content();
let found = found.content();
err.note(&format!("...so that the {}:\nexpected {}\n found {}",
trace.cause.as_requirement_str(),
expected,
found));
err.span_note(
trace.cause.span,
&format!(
"...so that the {}",
trace.cause.as_requirement_str()
)
);

err.note_expected_found(
&"",
expected,
&"",
found
);
} else {
// FIXME: this really should be handled at some earlier stage. Our
// handling of region checking when type errors are present is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ note: first, the lifetime cannot outlive the lifetime `'a` as defined on the fun
|
LL | fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {
| ^^
= note: ...so that the expression is assignable:
expected Type<'_>
found Type<'a>
note: ...so that the expression is assignable
--> $DIR/project-fn-ret-invariant.rs:48:13
|
LL | bar(foo, x)
| ^
= note: expected `Type<'_>`
found `Type<'a>`
= note: but, the lifetime must be valid for the static lifetime...
= note: ...so that the expression is assignable:
expected Type<'static>
found Type<'_>
note: ...so that the expression is assignable
--> $DIR/project-fn-ret-invariant.rs:48:4
|
LL | bar(foo, x)
| ^^^^^^^^^^^
= note: expected `Type<'static>`
found `Type<'_>`

error: aborting due to previous error

Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/c-variadic/variadic-ffi-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on th
|
LL | let _ = ap.with_copy(|ap| { ap });
| ^^^^^^^^^^^
= note: ...so that the expression is assignable:
expected core::ffi::VaList<'_, '_>
found core::ffi::VaList<'_, '_>
note: ...so that the expression is assignable
--> $DIR/variadic-ffi-4.rs:16:33
|
LL | let _ = ap.with_copy(|ap| { ap });
| ^^
= note: expected `core::ffi::VaList<'_, '_>`
found `core::ffi::VaList<'_, '_>`
note: but, the lifetime must be valid for the method call at 16:13...
--> $DIR/variadic-ffi-4.rs:16:13
|
Expand Down
20 changes: 14 additions & 6 deletions src/test/ui/impl-header-lifetime-elision/dyn-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ note: first, the lifetime cannot outlive the lifetime `'a` as defined on the fun
|
LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {
| ^^
= note: ...so that the expression is assignable:
expected std::boxed::Box<dyn std::fmt::Debug>
found std::boxed::Box<(dyn std::fmt::Debug + 'a)>
note: ...so that the expression is assignable
--> $DIR/dyn-trait.rs:20:16
|
LL | static_val(x);
| ^
= note: expected `std::boxed::Box<dyn std::fmt::Debug>`
found `std::boxed::Box<(dyn std::fmt::Debug + 'a)>`
= note: but, the lifetime must be valid for the static lifetime...
= note: ...so that the types are compatible:
expected StaticTrait
found StaticTrait
note: ...so that the types are compatible
--> $DIR/dyn-trait.rs:20:5
|
LL | static_val(x);
| ^^^^^^^^^^
= note: expected `StaticTrait`
found `StaticTrait`

error: aborting due to previous error

Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/issues/issue-16683.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ note: but, the lifetime must be valid for the lifetime `'a` as defined on the tr
|
LL | trait T<'a> {
| ^^
= note: ...so that the types are compatible:
expected &'a Self
found &Self
note: ...so that the types are compatible
--> $DIR/issue-16683.rs:4:14
|
LL | self.a();
| ^
= note: expected `&'a Self`
found `&Self`

error: aborting due to previous error

Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/issues/issue-17758.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ note: but, the lifetime must be valid for the lifetime `'a` as defined on the tr
|
LL | trait Foo<'a> {
| ^^
= note: ...so that the types are compatible:
expected &'a Self
found &Self
note: ...so that the types are compatible
--> $DIR/issue-17758.rs:7:14
|
LL | self.foo();
| ^^^
= note: expected `&'a Self`
found `&Self`

error: aborting due to previous error

Expand Down
16 changes: 13 additions & 3 deletions src/test/ui/issues/issue-20831-debruijn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,19 @@ note: ...but the lifetime must also be valid for the lifetime `'a` as defined on
|
LL | impl<'a> Publisher<'a> for MyStruct<'a> {
| ^^
= note: ...so that the types are compatible:
expected Publisher<'_>
found Publisher<'_>
note: ...so that the types are compatible
--> $DIR/issue-20831-debruijn.rs:28:5
|
LL | / fn subscribe(&mut self, t : Box<dyn Subscriber<Input=<Self as Publisher>::Output> + 'a>) {
LL | | // Not obvious, but there is an implicit lifetime here -------^
LL | |
LL | |
... |
LL | | self.sub = t;
LL | | }
| |_____^
= note: expected `Publisher<'_>`
found `Publisher<'_>`

error: aborting due to 3 previous errors

Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/issues/issue-52213.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ note: first, the lifetime cannot outlive the lifetime `'a` as defined on the fun
|
LL | fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
| ^^
= note: ...so that the types are compatible:
expected (&&(T,),)
found (&&'a (T,),)
note: ...so that the types are compatible
--> $DIR/issue-52213.rs:2:11
|
LL | match (&t,) {
| ^^^^^
= note: expected `(&&(T,),)`
found `(&&'a (T,),)`
note: but, the lifetime must be valid for the lifetime `'b` as defined on the function body at 1:27...
--> $DIR/issue-52213.rs:1:27
|
Expand Down
20 changes: 14 additions & 6 deletions src/test/ui/issues/issue-55796.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ note: ...so that the type `std::iter::Map<<Self as Graph<'a>>::EdgesIter, [closu
LL | Box::new(self.out_edges(u).map(|e| e.target()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: but, the lifetime must be valid for the static lifetime...
= note: ...so that the expression is assignable:
expected std::boxed::Box<(dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node> + 'static)>
found std::boxed::Box<dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node>>
note: ...so that the expression is assignable
--> $DIR/issue-55796.rs:16:9
|
LL | Box::new(self.out_edges(u).map(|e| e.target()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `std::boxed::Box<(dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node> + 'static)>`
found `std::boxed::Box<dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node>>`

error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/issue-55796.rs:21:9
Expand All @@ -36,9 +40,13 @@ note: ...so that the type `std::iter::Map<<Self as Graph<'a>>::EdgesIter, [closu
LL | Box::new(self.in_edges(u).map(|e| e.target()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: but, the lifetime must be valid for the static lifetime...
= note: ...so that the expression is assignable:
expected std::boxed::Box<(dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node> + 'static)>
found std::boxed::Box<dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node>>
note: ...so that the expression is assignable
--> $DIR/issue-55796.rs:21:9
|
LL | Box::new(self.in_edges(u).map(|e| e.target()))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `std::boxed::Box<(dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node> + 'static)>`
found `std::boxed::Box<dyn std::iter::Iterator<Item = <Self as Graph<'a>>::Node>>`

error: aborting due to 2 previous errors

Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/nll/issue-55394.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ note: but, the lifetime must be valid for the lifetime `'_` as defined on the im
|
LL | impl Foo<'_> {
| ^^
= note: ...so that the expression is assignable:
expected Foo<'_>
found Foo<'_>
note: ...so that the expression is assignable
--> $DIR/issue-55394.rs:9:9
|
LL | Foo { bar }
| ^^^^^^^^^^^
= note: expected `Foo<'_>`
found `Foo<'_>`

error: aborting due to previous error

Expand Down
10 changes: 7 additions & 3 deletions src/test/ui/nll/normalization-bounds-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ note: ...but the lifetime must also be valid for the lifetime `'a` as defined on
|
LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {}
| ^^
= note: ...so that the types are compatible:
expected Visitor<'d>
found Visitor<'_>
note: ...so that the types are compatible
--> $DIR/normalization-bounds-error.rs:12:1
|
LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected `Visitor<'d>`
found `Visitor<'_>`

error: aborting due to previous error

Expand Down
40 changes: 28 additions & 12 deletions src/test/ui/nll/type-alias-free-regions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ LL | / fn from_box(b: Box<B>) -> Self {
LL | | C { f: b }
LL | | }
| |_____^
= note: ...so that the expression is assignable:
expected std::boxed::Box<std::boxed::Box<&isize>>
found std::boxed::Box<std::boxed::Box<&isize>>
note: ...so that the expression is assignable
--> $DIR/type-alias-free-regions.rs:17:16
|
LL | C { f: b }
| ^
= note: expected `std::boxed::Box<std::boxed::Box<&isize>>`
found `std::boxed::Box<std::boxed::Box<&isize>>`
note: but, the lifetime must be valid for the lifetime `'a` as defined on the impl at 15:6...
--> $DIR/type-alias-free-regions.rs:15:6
|
LL | impl<'a> FromBox<'a> for C<'a> {
| ^^
= note: ...so that the expression is assignable:
expected C<'a>
found C<'_>
note: ...so that the expression is assignable
--> $DIR/type-alias-free-regions.rs:17:9
|
LL | C { f: b }
| ^^^^^^^^^^
= note: expected `C<'a>`
found `C<'_>`

error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/type-alias-free-regions.rs:27:16
Expand All @@ -36,17 +44,25 @@ LL | / fn from_tuple(b: (B,)) -> Self {
LL | | C { f: Box::new(b.0) }
LL | | }
| |_____^
= note: ...so that the expression is assignable:
expected std::boxed::Box<&isize>
found std::boxed::Box<&isize>
note: ...so that the expression is assignable
--> $DIR/type-alias-free-regions.rs:27:25
|
LL | C { f: Box::new(b.0) }
| ^^^
= note: expected `std::boxed::Box<&isize>`
found `std::boxed::Box<&isize>`
note: but, the lifetime must be valid for the lifetime `'a` as defined on the impl at 25:6...
--> $DIR/type-alias-free-regions.rs:25:6
|
LL | impl<'a> FromTuple<'a> for C<'a> {
| ^^
= note: ...so that the expression is assignable:
expected C<'a>
found C<'_>
note: ...so that the expression is assignable
--> $DIR/type-alias-free-regions.rs:27:9
|
LL | C { f: Box::new(b.0) }
| ^^^^^^^^^^^^^^^^^^^^^^
= note: expected `C<'a>`
found `C<'_>`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ note: first, the lifetime cannot outlive the lifetime `'a` as defined on the fun
|
LL | fn foo<'a>(_: &'a u32) -> &'static u32 {
| ^^
= note: ...so that the types are compatible:
expected Foo<'_>
found Foo<'a>
note: ...so that the types are compatible
--> $DIR/constant-in-expr-inherent-1.rs:8:5
|
LL | <Foo<'a>>::C
| ^^^^^^^^^^^^
= note: expected `Foo<'_>`
found `Foo<'a>`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that reference does not outlive borrowed content
--> $DIR/constant-in-expr-inherent-1.rs:8:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ note: first, the lifetime cannot outlive the lifetime `'a` as defined on the fun
|
LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 {
| ^^
= note: ...so that the types are compatible:
expected Foo<'_>
found Foo<'a>
note: ...so that the types are compatible
--> $DIR/constant-in-expr-trait-item-3.rs:10:5
|
LL | T::C
| ^^^^
= note: expected `Foo<'_>`
found `Foo<'a>`
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that reference does not outlive borrowed content
--> $DIR/constant-in-expr-trait-item-3.rs:10:5
Expand Down
20 changes: 14 additions & 6 deletions src/test/ui/object-lifetime/object-lifetime-default-elision.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ note: but, the lifetime must be valid for the lifetime `'b` as defined on the fu
|
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
| ^^
= note: ...so that the expression is assignable:
expected &'b (dyn SomeTrait + 'b)
found &dyn SomeTrait
note: ...so that the expression is assignable
--> $DIR/object-lifetime-default-elision.rs:71:5
|
LL | ss
| ^^
= note: expected `&'b (dyn SomeTrait + 'b)`
found `&dyn SomeTrait`

error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> $DIR/object-lifetime-default-elision.rs:71:5
Expand All @@ -44,9 +48,13 @@ note: but, the lifetime must be valid for the lifetime `'b` as defined on the fu
|
LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {
| ^^
= note: ...so that the expression is assignable:
expected &'b (dyn SomeTrait + 'b)
found &dyn SomeTrait
note: ...so that the expression is assignable
--> $DIR/object-lifetime-default-elision.rs:71:5
|
LL | ss
| ^^
= note: expected `&'b (dyn SomeTrait + 'b)`
found `&dyn SomeTrait`

error: aborting due to 2 previous errors

Expand Down
Loading