about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-09-09 17:43:20 +0200
committerRalf Jung <post@ralfj.de>2023-09-09 18:00:13 +0200
commit3bd8bcb8bb431462858d71b94786fe90cfa7faed (patch)
tree235cb4df242003b5f0bdc7b9d97d26e39fe68eba
parentc2a7e684cd43f449bc40a696dbf9b69ebccc33c3 (diff)
downloadrust-3bd8bcb8bb431462858d71b94786fe90cfa7faed.tar.gz
rust-3bd8bcb8bb431462858d71b94786fe90cfa7faed.zip
better spans for WF errors
-rw-r--r--compiler/rustc_passes/src/abi_test.rs2
-rw-r--r--compiler/rustc_passes/src/layout_test.rs9
-rw-r--r--tests/ui/abi/debug.stderr4
-rw-r--r--tests/ui/associated-types/issue-85103-layout-debug.rs (renamed from tests/ui/associated-types/issue-85103.rs)0
-rw-r--r--tests/ui/associated-types/issue-85103-layout-debug.stderr16
-rw-r--r--tests/ui/associated-types/issue-85103.stderr12
-rw-r--r--tests/ui/layout/debug.stderr4
7 files changed, 28 insertions, 19 deletions
diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs
index 240999b91b7..6a946b55213 100644
--- a/compiler/rustc_passes/src/abi_test.rs
+++ b/compiler/rustc_passes/src/abi_test.rs
@@ -118,7 +118,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
     let param_env = tcx.param_env(item_def_id);
     let ty = tcx.type_of(item_def_id).instantiate_identity();
     let span = tcx.def_span(item_def_id);
-    if !ensure_wf(tcx, param_env, ty, span) {
+    if !ensure_wf(tcx, param_env, ty, item_def_id, span) {
         return;
     }
     let meta_items = attr.meta_item_list().unwrap_or_default();
diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs
index 6403effe027..3e0dc1f6063 100644
--- a/compiler/rustc_passes/src/layout_test.rs
+++ b/compiler/rustc_passes/src/layout_test.rs
@@ -38,12 +38,17 @@ pub fn ensure_wf<'tcx>(
     tcx: TyCtxt<'tcx>,
     param_env: ParamEnv<'tcx>,
     ty: Ty<'tcx>,
+    def_id: LocalDefId,
     span: Span,
 ) -> bool {
     let pred = ty::ClauseKind::WellFormed(ty.into());
     let obligation = traits::Obligation::new(
         tcx,
-        traits::ObligationCause::dummy_with_span(span),
+        traits::ObligationCause::new(
+            span,
+            def_id,
+            traits::ObligationCauseCode::WellFormed(Some(traits::WellFormedLoc::Ty(def_id))),
+        ),
         param_env,
         pred,
     );
@@ -64,7 +69,7 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
     let param_env = tcx.param_env(item_def_id);
     let ty = tcx.type_of(item_def_id).instantiate_identity();
     let span = tcx.def_span(item_def_id.to_def_id());
-    if !ensure_wf(tcx, param_env, ty, span) {
+    if !ensure_wf(tcx, param_env, ty, item_def_id, span) {
         return;
     }
     match tcx.layout_of(param_env.and(ty)) {
diff --git a/tests/ui/abi/debug.stderr b/tests/ui/abi/debug.stderr
index c0c808c1ede..ceaf5136a6f 100644
--- a/tests/ui/abi/debug.stderr
+++ b/tests/ui/abi/debug.stderr
@@ -852,10 +852,10 @@ LL | type TestAbiNeSign = (fn(i32), fn(u32));
    | ^^^^^^^^^^^^^^^^^^
 
 error[E0277]: the size for values of type `str` cannot be known at compilation time
-  --> $DIR/debug.rs:53:1
+  --> $DIR/debug.rs:53:46
    |
 LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
-   | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+   |                                              ^^^^^^^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `Sized` is not implemented for `str`
    = note: only the last element of a tuple may have a dynamically sized type
diff --git a/tests/ui/associated-types/issue-85103.rs b/tests/ui/associated-types/issue-85103-layout-debug.rs
index 77c9876ffa5..77c9876ffa5 100644
--- a/tests/ui/associated-types/issue-85103.rs
+++ b/tests/ui/associated-types/issue-85103-layout-debug.rs
diff --git a/tests/ui/associated-types/issue-85103-layout-debug.stderr b/tests/ui/associated-types/issue-85103-layout-debug.stderr
new file mode 100644
index 00000000000..0bdea10ba47
--- /dev/null
+++ b/tests/ui/associated-types/issue-85103-layout-debug.stderr
@@ -0,0 +1,16 @@
+error[E0277]: the trait bound `[E]: ToOwned` is not satisfied
+  --> $DIR/issue-85103-layout-debug.rs:6:21
+   |
+LL | type Edges<'a, E> = Cow<'a, [E]>;
+   |                     ^^^^^^^^^^^^ the trait `ToOwned` is not implemented for `[E]`
+   |
+note: required by a bound in `Cow`
+  --> $SRC_DIR/alloc/src/borrow.rs:LL:COL
+help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
+   |
+LL | type Edges<'a, E> where [E]: ToOwned = Cow<'a, [E]>;
+   |                   ++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/associated-types/issue-85103.stderr b/tests/ui/associated-types/issue-85103.stderr
deleted file mode 100644
index 302dec8dad1..00000000000
--- a/tests/ui/associated-types/issue-85103.stderr
+++ /dev/null
@@ -1,12 +0,0 @@
-error[E0277]: the trait bound `[E]: ToOwned` is not satisfied
-  --> $DIR/issue-85103.rs:6:1
-   |
-LL | type Edges<'a, E> = Cow<'a, [E]>;
-   | ^^^^^^^^^^^^^^^^^ the trait `ToOwned` is not implemented for `[E]`
-   |
-note: required by a bound in `Cow`
-  --> $SRC_DIR/alloc/src/borrow.rs:LL:COL
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/layout/debug.stderr b/tests/ui/layout/debug.stderr
index 59df10b737b..1ba70ae39e7 100644
--- a/tests/ui/layout/debug.stderr
+++ b/tests/ui/layout/debug.stderr
@@ -558,10 +558,10 @@ LL | const C: () = ();
    | ^^^^^^^^^^^
 
 error[E0277]: the size for values of type `str` cannot be known at compilation time
-  --> $DIR/debug.rs:78:1
+  --> $DIR/debug.rs:78:19
    |
 LL | type Impossible = (str, str);
-   | ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
+   |                   ^^^^^^^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `Sized` is not implemented for `str`
    = note: only the last element of a tuple may have a dynamically sized type