Skip to content

Commit 49ed325

Browse files
authored
Rollup merge of #101185 - compiler-errors:tweak-wf-locs, r=davidtwco
Tweak `WellFormedLoc`s a bit Gives a bit tighter spans in returns and generic ty defaults
2 parents 0ed046f + 5a4f7d4 commit 49ed325

13 files changed

+52
-33
lines changed

compiler/rustc_typeck/src/check/wfcheck.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,11 @@ fn check_impl<'tcx>(
12621262
}
12631263
None => {
12641264
let self_ty = tcx.type_of(item.def_id);
1265-
let self_ty = wfcx.normalize(item.span, None, self_ty);
1265+
let self_ty = wfcx.normalize(
1266+
item.span,
1267+
Some(WellFormedLoc::Ty(item.hir_id().expect_owner())),
1268+
self_ty,
1269+
);
12661270
wfcx.register_wf_obligation(
12671271
ast_self_ty.span,
12681272
Some(WellFormedLoc::Ty(item.hir_id().expect_owner())),
@@ -1307,7 +1311,11 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13071311
// parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
13081312
// be sure if it will error or not as user might always specify the other.
13091313
if !ty.needs_subst() {
1310-
wfcx.register_wf_obligation(tcx.def_span(param.def_id), None, ty.into());
1314+
wfcx.register_wf_obligation(
1315+
tcx.def_span(param.def_id),
1316+
Some(WellFormedLoc::Ty(param.def_id.expect_local())),
1317+
ty.into(),
1318+
);
13111319
}
13121320
}
13131321
}
@@ -1512,7 +1520,14 @@ fn check_fn_or_method<'tcx>(
15121520
);
15131521
}
15141522

1515-
wfcx.register_wf_obligation(hir_decl.output.span(), None, sig.output().into());
1523+
wfcx.register_wf_obligation(
1524+
hir_decl.output.span(),
1525+
Some(WellFormedLoc::Param {
1526+
function: def_id,
1527+
param_idx: sig.inputs().len().try_into().unwrap(),
1528+
}),
1529+
sig.output().into(),
1530+
);
15161531

15171532
check_where_clauses(wfcx, span, def_id);
15181533
}

compiler/rustc_typeck/src/hir_wf_check.rs

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ fn diagnostic_hir_wf_check<'tcx>(
140140
hir::Node::ForeignItem(ForeignItem {
141141
kind: ForeignItemKind::Static(ty, _), ..
142142
}) => Some(*ty),
143+
hir::Node::GenericParam(hir::GenericParam {
144+
kind: hir::GenericParamKind::Type { default: Some(ty), .. },
145+
..
146+
}) => Some(*ty),
143147
ref node => bug!("Unexpected node {:?}", node),
144148
},
145149
WellFormedLoc::Param { function: _, param_idx } => {

src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ LL | trait NonObjectSafe1: Sized {}
1313
| this trait cannot be made into an object...
1414

1515
error[E0038]: the trait `NonObjectSafe2` cannot be made into an object
16-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:36
16+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:22:45
1717
|
1818
LL | fn return_non_object_safe_ref() -> &'static dyn NonObjectSafe2 {
19-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object
19+
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe2` cannot be made into an object
2020
|
2121
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>
2222
--> $DIR/feature-gate-object_safe_for_dispatch.rs:7:8
@@ -50,10 +50,10 @@ LL | fn foo<T>(&self);
5050
= help: consider moving `foo` to another trait
5151

5252
error[E0038]: the trait `NonObjectSafe4` cannot be made into an object
53-
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:35
53+
--> $DIR/feature-gate-object_safe_for_dispatch.rs:31:47
5454
|
5555
LL | fn return_non_object_safe_rc() -> std::rc::Rc<dyn NonObjectSafe4> {
56-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object
56+
| ^^^^^^^^^^^^^^^^^^ `NonObjectSafe4` cannot be made into an object
5757
|
5858
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>
5959
--> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22

src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ LL | fn foo() -> Self where Self: Sized;
2121
| +++++++++++++++++
2222

2323
error[E0038]: the trait `NotObjectSafe` cannot be made into an object
24-
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:28:13
24+
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:28:17
2525
|
2626
LL | fn cat() -> Box<dyn NotObjectSafe> {
27-
| ^^^^^^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
27+
| ^^^^^^^^^^^^^^^^^ `NotObjectSafe` cannot be made into an object
2828
|
2929
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>
3030
--> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8

src/test/ui/object-safety/object-safety-associated-consts.curr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/object-safety-associated-consts.rs:12:30
2+
--> $DIR/object-safety-associated-consts.rs:12:31
33
|
44
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
5-
| ^^^^^^^^ `Bar` cannot be made into an object
5+
| ^^^^^^^ `Bar` cannot be made into an object
66
|
77
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>
88
--> $DIR/object-safety-associated-consts.rs:9:11

src/test/ui/object-safety/object-safety-bounds.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0038]: the trait `X` cannot be made into an object
2-
--> $DIR/object-safety-bounds.rs:7:11
2+
--> $DIR/object-safety-bounds.rs:7:15
33
|
44
LL | fn f() -> Box<dyn X<U = u32>> {
5-
| ^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object
5+
| ^^^^^^^^^^^^^^ `X` cannot be made into an object
66
|
77
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>
88
--> $DIR/object-safety-bounds.rs:4:13

src/test/ui/object-safety/object-safety-generics.curr.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/object-safety-generics.rs:18:30
2+
--> $DIR/object-safety-generics.rs:18:31
33
|
44
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
5-
| ^^^^^^^^ `Bar` cannot be made into an object
5+
| ^^^^^^^ `Bar` cannot be made into an object
66
|
77
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>
88
--> $DIR/object-safety-generics.rs:10:8
@@ -14,10 +14,10 @@ LL | fn bar<T>(&self, t: T);
1414
= help: consider moving `bar` to another trait
1515

1616
error[E0038]: the trait `Bar` cannot be made into an object
17-
--> $DIR/object-safety-generics.rs:24:39
17+
--> $DIR/object-safety-generics.rs:24:40
1818
|
1919
LL | fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
20-
| ^^^^^^^^ `Bar` cannot be made into an object
20+
| ^^^^^^^ `Bar` cannot be made into an object
2121
|
2222
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>
2323
--> $DIR/object-safety-generics.rs:10:8

src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/object-safety-mentions-Self.rs:22:30
2+
--> $DIR/object-safety-mentions-Self.rs:22:31
33
|
44
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
5-
| ^^^^^^^^ `Bar` cannot be made into an object
5+
| ^^^^^^^ `Bar` cannot be made into an object
66
|
77
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>
88
--> $DIR/object-safety-mentions-Self.rs:11:22
@@ -14,10 +14,10 @@ LL | fn bar(&self, x: &Self);
1414
= help: consider moving `bar` to another trait
1515

1616
error[E0038]: the trait `Baz` cannot be made into an object
17-
--> $DIR/object-safety-mentions-Self.rs:28:30
17+
--> $DIR/object-safety-mentions-Self.rs:28:31
1818
|
1919
LL | fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
20-
| ^^^^^^^^ `Baz` cannot be made into an object
20+
| ^^^^^^^ `Baz` cannot be made into an object
2121
|
2222
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>
2323
--> $DIR/object-safety-mentions-Self.rs:15:22

src/test/ui/object-safety/object-safety-no-static.curr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0038]: the trait `Foo` cannot be made into an object
2-
--> $DIR/object-safety-no-static.rs:12:18
2+
--> $DIR/object-safety-no-static.rs:12:22
33
|
44
LL | fn diverges() -> Box<dyn Foo> {
5-
| ^^^^^^^^^^^^ `Foo` cannot be made into an object
5+
| ^^^^^^^ `Foo` cannot be made into an object
66
|
77
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>
88
--> $DIR/object-safety-no-static.rs:9:8

src/test/ui/object-safety/object-safety-sized-2.curr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/object-safety-sized-2.rs:14:30
2+
--> $DIR/object-safety-sized-2.rs:14:31
33
|
44
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
5-
| ^^^^^^^^ `Bar` cannot be made into an object
5+
| ^^^^^^^ `Bar` cannot be made into an object
66
|
77
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>
88
--> $DIR/object-safety-sized-2.rs:9:18

src/test/ui/object-safety/object-safety-sized.curr.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0038]: the trait `Bar` cannot be made into an object
2-
--> $DIR/object-safety-sized.rs:12:30
2+
--> $DIR/object-safety-sized.rs:12:31
33
|
44
LL | fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
5-
| ^^^^^^^^ `Bar` cannot be made into an object
5+
| ^^^^^^^ `Bar` cannot be made into an object
66
|
77
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>
88
--> $DIR/object-safety-sized.rs:8:13

src/test/ui/type/type-check-defaults.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: a value of type `i32` cannot be built from an iterator over elements of type `i32`
2-
--> $DIR/type-check-defaults.rs:6:19
2+
--> $DIR/type-check-defaults.rs:6:23
33
|
44
LL | struct WellFormed<Z = Foo<i32, i32>>(Z);
5-
| ^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
5+
| ^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
66
|
77
= help: the trait `FromIterator<i32>` is not implemented for `i32`
88
note: required by a bound in `Foo`
@@ -12,10 +12,10 @@ LL | struct Foo<T, U: FromIterator<T>>(T, U);
1212
| ^^^^^^^^^^^^^^^ required by this bound in `Foo`
1313

1414
error[E0277]: a value of type `i32` cannot be built from an iterator over elements of type `i32`
15-
--> $DIR/type-check-defaults.rs:8:27
15+
--> $DIR/type-check-defaults.rs:8:38
1616
|
1717
LL | struct WellFormedNoBounds<Z:?Sized = Foo<i32, i32>>(Z);
18-
| ^^^^^^^^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
18+
| ^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator<Item=i32>`
1919
|
2020
= help: the trait `FromIterator<i32>` is not implemented for `i32`
2121
note: required by a bound in `Foo`

src/test/ui/wf/wf-trait-fn-ret.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: the trait bound `Self: Eq` is not satisfied
2-
--> $DIR/wf-trait-fn-ret.rs:10:22
2+
--> $DIR/wf-trait-fn-ret.rs:10:23
33
|
44
LL | fn bar(&self) -> &Bar<Self>;
5-
| ^^^^^^^^^^ the trait `Eq` is not implemented for `Self`
5+
| ^^^^^^^^^ the trait `Eq` is not implemented for `Self`
66
|
77
note: required by a bound in `Bar`
88
--> $DIR/wf-trait-fn-ret.rs:7:14

0 commit comments

Comments
 (0)