From 5a4f7d4ad3e1124291b177af369023c3f181422e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 30 Aug 2022 06:19:48 +0000 Subject: [PATCH] Tweak WellFormedLocs a bit --- compiler/rustc_typeck/src/check/wfcheck.rs | 21 ++++++++++++++++--- compiler/rustc_typeck/src/hir_wf_check.rs | 4 ++++ ...ature-gate-object_safe_for_dispatch.stderr | 8 +++---- ...-trait-in-return-position-dyn-trait.stderr | 4 ++-- ...bject-safety-associated-consts.curr.stderr | 4 ++-- .../object-safety/object-safety-bounds.stderr | 4 ++-- .../object-safety-generics.curr.stderr | 8 +++---- .../object-safety-mentions-Self.curr.stderr | 8 +++---- .../object-safety-no-static.curr.stderr | 4 ++-- .../object-safety-sized-2.curr.stderr | 4 ++-- .../object-safety-sized.curr.stderr | 4 ++-- src/test/ui/type/type-check-defaults.stderr | 8 +++---- src/test/ui/wf/wf-trait-fn-ret.stderr | 4 ++-- 13 files changed, 52 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index ce42647c837a5..ba42453bd60e9 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -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())), @@ -1307,7 +1311,11 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id // parameter includes another (e.g., ``). 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(), + ); } } } @@ -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); } diff --git a/compiler/rustc_typeck/src/hir_wf_check.rs b/compiler/rustc_typeck/src/hir_wf_check.rs index fd9715e6ca374..7b080dc2942e0 100644 --- a/compiler/rustc_typeck/src/hir_wf_check.rs +++ b/compiler/rustc_typeck/src/hir_wf_check.rs @@ -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 } => { diff --git a/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr b/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr index 72cb4cc843cc4..d76c697fe737d 100644 --- a/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr +++ b/src/test/ui/feature-gates/feature-gate-object_safe_for_dispatch.stderr @@ -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 --> $DIR/feature-gate-object_safe_for_dispatch.rs:7:8 @@ -50,10 +50,10 @@ LL | fn foo(&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 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `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 --> $DIR/feature-gate-object_safe_for_dispatch.rs:15:22 diff --git a/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr b/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr index 365ecd9fcfa1d..687dbe65e6c38 100644 --- a/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr +++ b/src/test/ui/impl-trait/object-unsafe-trait-in-return-position-dyn-trait.stderr @@ -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 { - | ^^^^^^^^^^^^^^^^^^^^^^ `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 --> $DIR/object-unsafe-trait-in-return-position-dyn-trait.rs:3:8 diff --git a/src/test/ui/object-safety/object-safety-associated-consts.curr.stderr b/src/test/ui/object-safety/object-safety-associated-consts.curr.stderr index 9dd144fee24a6..5f94c9284ea66 100644 --- a/src/test/ui/object-safety/object-safety-associated-consts.curr.stderr +++ b/src/test/ui/object-safety/object-safety-associated-consts.curr.stderr @@ -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: &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 --> $DIR/object-safety-associated-consts.rs:9:11 diff --git a/src/test/ui/object-safety/object-safety-bounds.stderr b/src/test/ui/object-safety/object-safety-bounds.stderr index 89c4f8ced79f6..29ffb5448427d 100644 --- a/src/test/ui/object-safety/object-safety-bounds.stderr +++ b/src/test/ui/object-safety/object-safety-bounds.stderr @@ -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> { - | ^^^^^^^^^^^^^^^^^^^ `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 --> $DIR/object-safety-bounds.rs:4:13 diff --git a/src/test/ui/object-safety/object-safety-generics.curr.stderr b/src/test/ui/object-safety/object-safety-generics.curr.stderr index 345950f1ae670..4581037526397 100644 --- a/src/test/ui/object-safety/object-safety-generics.curr.stderr +++ b/src/test/ui/object-safety/object-safety-generics.curr.stderr @@ -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: &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 --> $DIR/object-safety-generics.rs:10:8 @@ -14,10 +14,10 @@ LL | fn bar(&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: &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 --> $DIR/object-safety-generics.rs:10:8 diff --git a/src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr b/src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr index f91c9b9856055..de430a89bf82b 100644 --- a/src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr +++ b/src/test/ui/object-safety/object-safety-mentions-Self.curr.stderr @@ -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: &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 --> $DIR/object-safety-mentions-Self.rs:11:22 @@ -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: &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 --> $DIR/object-safety-mentions-Self.rs:15:22 diff --git a/src/test/ui/object-safety/object-safety-no-static.curr.stderr b/src/test/ui/object-safety/object-safety-no-static.curr.stderr index bd8cf4e30f7fa..1b025229e543e 100644 --- a/src/test/ui/object-safety/object-safety-no-static.curr.stderr +++ b/src/test/ui/object-safety/object-safety-no-static.curr.stderr @@ -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 { - | ^^^^^^^^^^^^ `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 --> $DIR/object-safety-no-static.rs:9:8 diff --git a/src/test/ui/object-safety/object-safety-sized-2.curr.stderr b/src/test/ui/object-safety/object-safety-sized-2.curr.stderr index 71236c8e38438..b019264128e76 100644 --- a/src/test/ui/object-safety/object-safety-sized-2.curr.stderr +++ b/src/test/ui/object-safety/object-safety-sized-2.curr.stderr @@ -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: &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 --> $DIR/object-safety-sized-2.rs:9:18 diff --git a/src/test/ui/object-safety/object-safety-sized.curr.stderr b/src/test/ui/object-safety/object-safety-sized.curr.stderr index 94b06ee934d44..97481312142fb 100644 --- a/src/test/ui/object-safety/object-safety-sized.curr.stderr +++ b/src/test/ui/object-safety/object-safety-sized.curr.stderr @@ -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: &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 --> $DIR/object-safety-sized.rs:8:13 diff --git a/src/test/ui/type/type-check-defaults.stderr b/src/test/ui/type/type-check-defaults.stderr index 56a9b5317f76e..cf77c057d46d4 100644 --- a/src/test/ui/type/type-check-defaults.stderr +++ b/src/test/ui/type/type-check-defaults.stderr @@ -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); - | ^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator` + | ^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator` is not implemented for `i32` note: required by a bound in `Foo` @@ -12,10 +12,10 @@ LL | struct Foo>(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); - | ^^^^^^^^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator` + | ^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator` is not implemented for `i32` note: required by a bound in `Foo` diff --git a/src/test/ui/wf/wf-trait-fn-ret.stderr b/src/test/ui/wf/wf-trait-fn-ret.stderr index a59ba3400a4d1..9bd3cc7711b84 100644 --- a/src/test/ui/wf/wf-trait-fn-ret.stderr +++ b/src/test/ui/wf/wf-trait-fn-ret.stderr @@ -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; - | ^^^^^^^^^^ 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