Skip to content

Commit b862d88

Browse files
committed
Use predicate spans instead of whole item spans
1 parent 2719b6d commit b862d88

15 files changed

+113
-135
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::ty::{
2525
};
2626
use rustc_middle::{bug, span_bug};
2727
use rustc_session::parse::feature_err;
28-
use rustc_span::{DUMMY_SP, Ident, Span, sym};
28+
use rustc_span::{DUMMY_SP, Span, sym};
2929
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3030
use rustc_trait_selection::regions::{InferCtxtRegionExt, OutlivesEnvironmentBuildExt};
3131
use rustc_trait_selection::traits::misc::{
@@ -291,8 +291,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
291291
}
292292
res
293293
}
294-
hir::ItemKind::Fn { ident, sig, .. } => check_item_fn(tcx, def_id, ident, sig.decl),
295-
hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span, item.span),
294+
hir::ItemKind::Fn { sig, .. } => check_item_fn(tcx, def_id, sig.decl),
295+
hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span),
296296
hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false),
297297
hir::ItemKind::Union(..) => check_type_defn(tcx, item, true),
298298
hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true),
@@ -308,7 +308,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
308308
Some(WellFormedLoc::Ty(def_id)),
309309
item_ty.into(),
310310
);
311-
check_where_clauses(wfcx, item.span, def_id);
311+
check_where_clauses(wfcx, def_id);
312312
Ok(())
313313
})
314314
}
@@ -330,7 +330,7 @@ fn check_foreign_item<'tcx>(
330330
);
331331

332332
match item.kind {
333-
hir::ForeignItemKind::Fn(sig, ..) => check_item_fn(tcx, def_id, item.ident, sig.decl),
333+
hir::ForeignItemKind::Fn(sig, ..) => check_item_fn(tcx, def_id, sig.decl),
334334
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => Ok(()),
335335
}
336336
}
@@ -1086,13 +1086,7 @@ fn check_associated_item(
10861086
ty::AssocKind::Fn { .. } => {
10871087
let sig = tcx.fn_sig(item.def_id).instantiate_identity();
10881088
let hir_sig = sig_if_method.expect("bad signature for method");
1089-
check_fn_or_method(
1090-
wfcx,
1091-
item.ident(tcx).span,
1092-
sig,
1093-
hir_sig.decl,
1094-
item.def_id.expect_local(),
1095-
);
1089+
check_fn_or_method(wfcx, sig, hir_sig.decl, item.def_id.expect_local());
10961090
check_method_receiver(wfcx, hir_sig, item, self_ty)
10971091
}
10981092
ty::AssocKind::Type { .. } => {
@@ -1221,7 +1215,7 @@ fn check_type_defn<'tcx>(
12211215
}
12221216
}
12231217

1224-
check_where_clauses(wfcx, item.span, item.owner_id.def_id);
1218+
check_where_clauses(wfcx, item.owner_id.def_id);
12251219
Ok(())
12261220
})
12271221
}
@@ -1247,7 +1241,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
12471241
}
12481242

12491243
let res = enter_wf_checking_ctxt(tcx, def_id, |wfcx| {
1250-
check_where_clauses(wfcx, item.span, def_id);
1244+
check_where_clauses(wfcx, def_id);
12511245
Ok(())
12521246
});
12531247

@@ -1283,12 +1277,11 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
12831277
fn check_item_fn(
12841278
tcx: TyCtxt<'_>,
12851279
def_id: LocalDefId,
1286-
ident: Ident,
12871280
decl: &hir::FnDecl<'_>,
12881281
) -> Result<(), ErrorGuaranteed> {
12891282
enter_wf_checking_ctxt(tcx, def_id, |wfcx| {
12901283
let sig = tcx.fn_sig(def_id).instantiate_identity();
1291-
check_fn_or_method(wfcx, ident.span, sig, decl, def_id);
1284+
check_fn_or_method(wfcx, sig, decl, def_id);
12921285
Ok(())
12931286
})
12941287
}
@@ -1349,7 +1342,6 @@ fn check_const_item(
13491342
tcx: TyCtxt<'_>,
13501343
def_id: LocalDefId,
13511344
ty_span: Span,
1352-
item_span: Span,
13531345
) -> Result<(), ErrorGuaranteed> {
13541346
enter_wf_checking_ctxt(tcx, def_id, |wfcx| {
13551347
let ty = tcx.type_of(def_id).instantiate_identity();
@@ -1367,7 +1359,7 @@ fn check_const_item(
13671359
tcx.require_lang_item(LangItem::Sized, None),
13681360
);
13691361

1370-
check_where_clauses(wfcx, item_span, def_id);
1362+
check_where_clauses(wfcx, def_id);
13711363

13721364
Ok(())
13731365
})
@@ -1464,14 +1456,14 @@ fn check_impl<'tcx>(
14641456
}
14651457
}
14661458

1467-
check_where_clauses(wfcx, item.span, item.owner_id.def_id);
1459+
check_where_clauses(wfcx, item.owner_id.def_id);
14681460
Ok(())
14691461
})
14701462
}
14711463

14721464
/// Checks where-clauses and inline bounds that are declared on `def_id`.
14731465
#[instrument(level = "debug", skip(wfcx))]
1474-
fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id: LocalDefId) {
1466+
pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: LocalDefId) {
14751467
let infcx = wfcx.infcx;
14761468
let tcx = wfcx.tcx();
14771469

@@ -1624,21 +1616,18 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
16241616

16251617
let predicates = predicates.instantiate_identity(tcx);
16261618

1627-
let predicates = wfcx.normalize(span, None, predicates);
1628-
1629-
debug!(?predicates.predicates);
16301619
assert_eq!(predicates.predicates.len(), predicates.spans.len());
16311620
let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| {
1621+
let p = wfcx.normalize(sp, None, p);
16321622
traits::wf::clause_obligations(infcx, wfcx.param_env, wfcx.body_def_id, p, sp)
16331623
});
16341624
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();
16351625
wfcx.register_obligations(obligations);
16361626
}
16371627

1638-
#[instrument(level = "debug", skip(wfcx, span, hir_decl))]
1628+
#[instrument(level = "debug", skip(wfcx, hir_decl))]
16391629
fn check_fn_or_method<'tcx>(
16401630
wfcx: &WfCheckingCtxt<'_, 'tcx>,
1641-
span: Span,
16421631
sig: ty::PolyFnSig<'tcx>,
16431632
hir_decl: &hir::FnDecl<'_>,
16441633
def_id: LocalDefId,
@@ -1676,7 +1665,7 @@ fn check_fn_or_method<'tcx>(
16761665
);
16771666
}
16781667

1679-
check_where_clauses(wfcx, span, def_id);
1668+
check_where_clauses(wfcx, def_id);
16801669

16811670
if sig.abi == ExternAbi::RustCall {
16821671
let span = tcx.def_span(def_id);

tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn take(
1212
K = { () }
1313
>,
1414
) {}
15-
//~^^^^^^ ERROR implementation of `Project` is not general enough
15+
//~^^^^^ ERROR implementation of `Project` is not general enough
1616
//~^^^^ ERROR higher-ranked subtype error
1717
//~| ERROR higher-ranked subtype error
1818

tests/ui/associated-consts/assoc-const-eq-bound-var-in-ty-not-wf.stderr

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ LL | K = { () }
1313
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1414

1515
error: implementation of `Project` is not general enough
16-
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:9:4
16+
--> $DIR/assoc-const-eq-bound-var-in-ty-not-wf.rs:10:13
1717
|
18-
LL | fn take(
19-
| ^^^^ implementation of `Project` is not general enough
18+
LL | _: impl Trait<
19+
| _____________^
20+
LL | | <<for<'a> fn(&'a str) -> &'a str as Project>::Out as Discard>::Out,
21+
LL | | K = { () }
22+
LL | | >,
23+
| |_____^ implementation of `Project` is not general enough
2024
|
2125
= note: `Project` would have to be implemented for the type `for<'a> fn(&'a str) -> &'a str`
2226
= note: ...but `Project` is actually implemented for the type `fn(&'0 str) -> &'0 str`, for some specific lifetime `'0`

tests/ui/associated-types/issue-38821.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ pub trait Column: Expression {}
3232
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3333
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3434
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
35+
pub enum ColumnInsertValue<Col, Expr> where
36+
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
37+
Col: Column,
38+
Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
39+
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3540
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3641
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3742
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3843
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
3944
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
40-
pub enum ColumnInsertValue<Col, Expr> where
41-
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
42-
//~| ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
43-
Col: Column,
44-
Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
4545
{
4646
Expression(Col, Expr),
4747
Default(Col),

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

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
2-
--> $DIR/issue-38821.rs:40:1
2+
--> $DIR/issue-38821.rs:35:1
33
|
44
LL | pub enum ColumnInsertValue<Col, Expr> where
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
@@ -17,16 +17,10 @@ LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Co
1717
| +++++++++++++++++++++++++++++++++++++
1818

1919
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
20-
--> $DIR/issue-38821.rs:40:1
20+
--> $DIR/issue-38821.rs:38:22
2121
|
22-
LL | / pub enum ColumnInsertValue<Col, Expr> where
23-
LL | |
24-
LL | |
25-
LL | | Col: Column,
26-
... |
27-
LL | | Default(Col),
28-
LL | | }
29-
| |_^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
22+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
3024
|
3125
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
3226
--> $DIR/issue-38821.rs:9:18
@@ -88,10 +82,10 @@ LL | impl<T: NotNull> IntoNullable for T {
8882
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
8983

9084
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
91-
--> $DIR/issue-38821.rs:23:10
85+
--> $DIR/issue-38821.rs:38:22
9286
|
93-
LL | #[derive(Debug, Copy, Clone)]
94-
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
87+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
88+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
9589
|
9690
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
9791
--> $DIR/issue-38821.rs:9:18
@@ -100,7 +94,6 @@ LL | impl<T: NotNull> IntoNullable for T {
10094
| ------- ^^^^^^^^^^^^ ^
10195
| |
10296
| unsatisfied trait bound introduced here
103-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
10497
help: consider further restricting the associated type
10598
|
10699
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
@@ -125,10 +118,10 @@ LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Co
125118
| +++++++++++++++++++++++++++++++++++++++
126119

127120
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
128-
--> $DIR/issue-38821.rs:23:17
121+
--> $DIR/issue-38821.rs:38:22
129122
|
130-
LL | #[derive(Debug, Copy, Clone)]
131-
| ^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
123+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
124+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
132125
|
133126
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
134127
--> $DIR/issue-38821.rs:9:18
@@ -137,7 +130,6 @@ LL | impl<T: NotNull> IntoNullable for T {
137130
| ------- ^^^^^^^^^^^^ ^
138131
| |
139132
| unsatisfied trait bound introduced here
140-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
141133
help: consider further restricting the associated type
142134
|
143135
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
@@ -191,10 +183,10 @@ LL | impl<T: NotNull> IntoNullable for T {
191183
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
192184

193185
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
194-
--> $DIR/issue-38821.rs:23:23
186+
--> $DIR/issue-38821.rs:38:22
195187
|
196-
LL | #[derive(Debug, Copy, Clone)]
197-
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
188+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
189+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
198190
|
199191
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
200192
--> $DIR/issue-38821.rs:9:18
@@ -203,7 +195,6 @@ LL | impl<T: NotNull> IntoNullable for T {
203195
| ------- ^^^^^^^^^^^^ ^
204196
| |
205197
| unsatisfied trait bound introduced here
206-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
207198
help: consider further restricting the associated type
208199
|
209200
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
@@ -225,10 +216,10 @@ LL | impl<T: NotNull> IntoNullable for T {
225216
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
226217

227218
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
228-
--> $DIR/issue-38821.rs:23:10
219+
--> $DIR/issue-38821.rs:38:22
229220
|
230-
LL | #[derive(Debug, Copy, Clone)]
231-
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
221+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
222+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
232223
|
233224
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
234225
--> $DIR/issue-38821.rs:9:18
@@ -237,7 +228,6 @@ LL | impl<T: NotNull> IntoNullable for T {
237228
| ------- ^^^^^^^^^^^^ ^
238229
| |
239230
| unsatisfied trait bound introduced here
240-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
241231

242232
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
243233
--> $DIR/issue-38821.rs:23:23
@@ -255,10 +245,10 @@ LL | impl<T: NotNull> IntoNullable for T {
255245
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
256246

257247
error[E0277]: the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
258-
--> $DIR/issue-38821.rs:23:23
248+
--> $DIR/issue-38821.rs:38:22
259249
|
260-
LL | #[derive(Debug, Copy, Clone)]
261-
| ^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
250+
LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>,
251+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NotNull` is not implemented for `<Col as Expression>::SqlType`
262252
|
263253
note: required for `<Col as Expression>::SqlType` to implement `IntoNullable`
264254
--> $DIR/issue-38821.rs:9:18

tests/ui/associated-types/issue-59324.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ pub trait Service {
1010

1111
pub trait ThriftService<Bug: NotFoo>:
1212
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
13-
//~| ERROR the trait bound `Bug: Foo` is not satisfied
1413
Service<AssocType = <Bug as Foo>::OnlyFoo>
14+
//~^ ERROR the trait bound `Bug: Foo` is not satisfied
1515
{
1616
fn get_service(
1717
//~^ ERROR the trait bound `Bug: Foo` is not satisfied

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `Bug: Foo` is not satisfied
22
--> $DIR/issue-59324.rs:11:1
33
|
44
LL | / pub trait ThriftService<Bug: NotFoo>:
5-
... |
5+
LL | |
66
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
77
| |______________________________________________^ the trait `Foo` is not implemented for `Bug`
88
|
@@ -12,15 +12,10 @@ LL | pub trait ThriftService<Bug: NotFoo + Foo>:
1212
| +++++
1313

1414
error[E0277]: the trait bound `Bug: Foo` is not satisfied
15-
--> $DIR/issue-59324.rs:11:1
15+
--> $DIR/issue-59324.rs:13:13
1616
|
17-
LL | / pub trait ThriftService<Bug: NotFoo>:
18-
LL | |
19-
LL | |
20-
LL | | Service<AssocType = <Bug as Foo>::OnlyFoo>
21-
... |
22-
LL | | }
23-
| |_^ the trait `Foo` is not implemented for `Bug`
17+
LL | Service<AssocType = <Bug as Foo>::OnlyFoo>
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bug`
2419
|
2520
help: consider further restricting type parameter `Bug` with trait `Foo`
2621
|

tests/ui/lifetimes/issue-76168-hr-outlives-3.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ async fn wrapper<F>(f: F)
77
//~^ ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
88
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
99
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
10-
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
1110
where
1211
F:,
1312
for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
13+
//~^ ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
14+
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
15+
//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
1416
{
1517
//~^ ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
1618
let mut i = 41;

0 commit comments

Comments
 (0)