Skip to content

Commit fa867b6

Browse files
committed
better spans for WF errors
1 parent c2a7e68 commit fa867b6

File tree

7 files changed

+28
-19
lines changed

7 files changed

+28
-19
lines changed

compiler/rustc_passes/src/abi_test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut
118118
let param_env = tcx.param_env(item_def_id);
119119
let ty = tcx.type_of(item_def_id).instantiate_identity();
120120
let span = tcx.def_span(item_def_id);
121-
if !ensure_wf(tcx, param_env, ty, span) {
121+
if !ensure_wf(tcx, param_env, ty, item_def_id, span) {
122122
return;
123123
}
124124
let meta_items = attr.meta_item_list().unwrap_or_default();

compiler/rustc_passes/src/layout_test.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ pub fn ensure_wf<'tcx>(
3838
tcx: TyCtxt<'tcx>,
3939
param_env: ParamEnv<'tcx>,
4040
ty: Ty<'tcx>,
41+
def_id: LocalDefId,
4142
span: Span,
4243
) -> bool {
4344
let pred = ty::ClauseKind::WellFormed(ty.into());
4445
let obligation = traits::Obligation::new(
4546
tcx,
46-
traits::ObligationCause::dummy_with_span(span),
47+
traits::ObligationCause::new(
48+
span,
49+
def_id,
50+
traits::ObligationCauseCode::WellFormed(Some(traits::WellFormedLoc::Ty(def_id))),
51+
),
4752
param_env,
4853
pred,
4954
);
@@ -64,7 +69,7 @@ fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
6469
let param_env = tcx.param_env(item_def_id);
6570
let ty = tcx.type_of(item_def_id).instantiate_identity();
6671
let span = tcx.def_span(item_def_id.to_def_id());
67-
if !ensure_wf(tcx, param_env, ty, span) {
72+
if !ensure_wf(tcx, param_env, ty, item_def_id, span) {
6873
return;
6974
}
7075
match tcx.layout_of(param_env.and(ty)) {

tests/ui/abi/debug.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,10 @@ LL | type TestAbiNeSign = (fn(i32), fn(u32));
852852
| ^^^^^^^^^^^^^^^^^^
853853

854854
error[E0277]: the size for values of type `str` cannot be known at compilation time
855-
--> $DIR/debug.rs:53:1
855+
--> $DIR/debug.rs:53:46
856856
|
857857
LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
858-
| ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
858+
| ^^^^^^^^^^ doesn't have a size known at compile-time
859859
|
860860
= help: the trait `Sized` is not implemented for `str`
861861
= note: only the last element of a tuple may have a dynamically sized type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: the trait bound `[E]: ToOwned` is not satisfied
2+
--> $DIR/issue-85103.rs:6:21
3+
|
4+
LL | type Edges<'a, E> = Cow<'a, [E]>;
5+
| ^^^^^^^^^^^^ the trait `ToOwned` is not implemented for `[E]`
6+
|
7+
note: required by a bound in `Cow`
8+
--> $SRC_DIR/alloc/src/borrow.rs:LL:COL
9+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
10+
|
11+
LL | type Edges<'a, E> where [E]: ToOwned = Cow<'a, [E]>;
12+
| ++++++++++++++++++
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.

tests/ui/associated-types/issue-85103.stderr

-12
This file was deleted.

tests/ui/layout/debug.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@ LL | const C: () = ();
558558
| ^^^^^^^^^^^
559559

560560
error[E0277]: the size for values of type `str` cannot be known at compilation time
561-
--> $DIR/debug.rs:78:1
561+
--> $DIR/debug.rs:78:19
562562
|
563563
LL | type Impossible = (str, str);
564-
| ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
564+
| ^^^^^^^^^^ doesn't have a size known at compile-time
565565
|
566566
= help: the trait `Sized` is not implemented for `str`
567567
= note: only the last element of a tuple may have a dynamically sized type

0 commit comments

Comments
 (0)