Skip to content

Commit

Permalink
Rollup merge of #101185 - compiler-errors:tweak-wf-locs, r=davidtwco
Browse files Browse the repository at this point in the history
Tweak `WellFormedLoc`s a bit

Gives a bit tighter spans in returns and generic ty defaults
  • Loading branch information
matthiaskrgr committed Aug 31, 2022
2 parents 69bd4d6 + 5a4f7d4 commit 92c6dfa
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 33 deletions.
21 changes: 18 additions & 3 deletions compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,11 @@ fn check_impl<'tcx>(
}
None => {
let self_ty = tcx.type_of(item.def_id);
let self_ty = wfcx.normalize(item.span, None, self_ty);
let self_ty = wfcx.normalize(
item.span,
Some(WellFormedLoc::Ty(item.hir_id().expect_owner())),
self_ty,
);
wfcx.register_wf_obligation(
ast_self_ty.span,
Some(WellFormedLoc::Ty(item.hir_id().expect_owner())),
Expand Down Expand Up @@ -1307,7 +1311,11 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
// parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
// be sure if it will error or not as user might always specify the other.
if !ty.needs_subst() {
wfcx.register_wf_obligation(tcx.def_span(param.def_id), None, ty.into());
wfcx.register_wf_obligation(
tcx.def_span(param.def_id),
Some(WellFormedLoc::Ty(param.def_id.expect_local())),
ty.into(),
);
}
}
}
Expand Down Expand Up @@ -1512,7 +1520,14 @@ fn check_fn_or_method<'tcx>(
);
}

wfcx.register_wf_obligation(hir_decl.output.span(), None, sig.output().into());
wfcx.register_wf_obligation(
hir_decl.output.span(),
Some(WellFormedLoc::Param {
function: def_id,
param_idx: sig.inputs().len().try_into().unwrap(),
}),
sig.output().into(),
);

check_where_clauses(wfcx, span, def_id);
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_typeck/src/hir_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ fn diagnostic_hir_wf_check<'tcx>(
hir::Node::ForeignItem(ForeignItem {
kind: ForeignItemKind::Static(ty, _), ..
}) => Some(*ty),
hir::Node::GenericParam(hir::GenericParam {
kind: hir::GenericParamKind::Type { default: Some(ty), .. },
..
}) => Some(*ty),
ref node => bug!("Unexpected node {:?}", node),
},
WellFormedLoc::Param { function: _, param_idx } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ LL | trait NonObjectSafe1: Sized {}
| this trait cannot be made into an object...

error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:36
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:45
|
LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:7:8
Expand Down Expand Up @@ -50,10 +50,10 @@ LL | fn foo<T>(&self);
= help: consider moving `foo` to another trait

error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:35
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:47
|
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ LL | fn foo() -> Self where Self: Sized;
| +++++++++++++++++

error[E0038]: the trait `NotObjectSafe` cannot be made into an object
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:28:13
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:28:17
|
LL | fn cat() -> Box<dyn NotObjectSafe> {
| ^^^^^^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
| ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-associated-consts.rs:12:30
--> $DIR/object-safety-associated-consts.rs:12:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^^ `Bar` cannot be made into an object
| ^^^^^^^ `Bar` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-associated-consts.rs:9:11
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/object-safety/object-safety-bounds.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0038]: the trait `X` cannot be made into an object
--> $DIR/object-safety-bounds.rs:7:11
--> $DIR/object-safety-bounds.rs:7:15
|
LL | fn f() -> Box<dyn X<U = u32>> {
| ^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object
| ^^^^^^^^^^^^^^ `X` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-bounds.rs:4:13
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/object-safety/object-safety-generics.curr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-generics.rs:18:30
--> $DIR/object-safety-generics.rs:18:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^^ `Bar` cannot be made into an object
| ^^^^^^^ `Bar` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-generics.rs:10:8
Expand All @@ -14,10 +14,10 @@ LL | fn bar<T>(&self, t: T);
= help: consider moving `bar` to another trait

error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-generics.rs:24:39
--> $DIR/object-safety-generics.rs:24:40
|
LL | fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^^ `Bar` cannot be made into an object
| ^^^^^^^ `Bar` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-generics.rs:10:8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-mentions-Self.rs:22:30
--> $DIR/object-safety-mentions-Self.rs:22:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^^ `Bar` cannot be made into an object
| ^^^^^^^ `Bar` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-mentions-Self.rs:11:22
Expand All @@ -14,10 +14,10 @@ LL | fn bar(&self, x: &Self);
= help: consider moving `bar` to another trait

error[E0038]: the trait `Baz` cannot be made into an object
--> $DIR/object-safety-mentions-Self.rs:28:30
--> $DIR/object-safety-mentions-Self.rs:28:31
|
LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
| ^^^^^^^^ `Baz` cannot be made into an object
| ^^^^^^^ `Baz` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-mentions-Self.rs:15:22
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/object-safety/object-safety-no-static.curr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/object-safety-no-static.rs:12:18
--> $DIR/object-safety-no-static.rs:12:22
|
LL | fn diverges() -> Box<dyn Foo> {
| ^^^^^^^^^^^^ `Foo` cannot be made into an object
| ^^^^^^^ `Foo` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-no-static.rs:9:8
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/object-safety/object-safety-sized-2.curr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-sized-2.rs:14:30
--> $DIR/object-safety-sized-2.rs:14:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^^ `Bar` cannot be made into an object
| ^^^^^^^ `Bar` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-sized-2.rs:9:18
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/object-safety/object-safety-sized.curr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0038]: the trait `Bar` cannot be made into an object
--> $DIR/object-safety-sized.rs:12:30
--> $DIR/object-safety-sized.rs:12:31
|
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
| ^^^^^^^^ `Bar` cannot be made into an object
| ^^^^^^^ `Bar` cannot be made into an object
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
--> $DIR/object-safety-sized.rs:8:13
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/type/type-check-defaults.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: a value of type `i32` cannot be built from an iterator over elements of type `i32`
--> $DIR/type-check-defaults.rs:6:19
--> $DIR/type-check-defaults.rs:6:23
|
LL | struct WellFormed<Z = Foo<i32, i32>>(Z);
| ^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
| ^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
|
= help: the trait `FromIterator<i32>` is not implemented for `i32`
note: required by a bound in `Foo`
Expand All @@ -12,10 +12,10 @@ LL | struct Foo<T, U: FromIterator<T>>(T, U);
| ^^^^^^^^^^^^^^^ required by this bound in `Foo`

error[E0277]: a value of type `i32` cannot be built from an iterator over elements of type `i32`
--> $DIR/type-check-defaults.rs:8:27
--> $DIR/type-check-defaults.rs:8:38
|
LL | struct WellFormedNoBounds<Z:?Sized = Foo<i32, i32>>(Z);
| ^^^^^^^^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
| ^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
|
= help: the trait `FromIterator<i32>` is not implemented for `i32`
note: required by a bound in `Foo`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/wf/wf-trait-fn-ret.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0277]: the trait bound `Self: Eq` is not satisfied
--> $DIR/wf-trait-fn-ret.rs:10:22
--> $DIR/wf-trait-fn-ret.rs:10:23
|
LL | fn bar(&self) -> &Bar<Self>;
| ^^^^^^^^^^ the trait `Eq` is not implemented for `Self`
| ^^^^^^^^^ the trait `Eq` is not implemented for `Self`
|
note: required by a bound in `Bar`
--> $DIR/wf-trait-fn-ret.rs:7:14
Expand Down

0 comments on commit 92c6dfa

Please sign in to comment.