Skip to content

Commit 28f023c

Browse files
committed
Use predicate spans instead of whole item spans
1 parent ee8fa4e commit 28f023c

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::{
@@ -290,8 +290,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
290290
}
291291
res
292292
}
293-
hir::ItemKind::Fn { ident, sig, .. } => check_item_fn(tcx, def_id, ident, sig.decl),
294-
hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span, item.span),
293+
hir::ItemKind::Fn { sig, .. } => check_item_fn(tcx, def_id, sig.decl),
294+
hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span),
295295
hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false),
296296
hir::ItemKind::Union(..) => check_type_defn(tcx, item, true),
297297
hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true),
@@ -307,7 +307,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
307307
Some(WellFormedLoc::Ty(def_id)),
308308
item_ty.into(),
309309
);
310-
check_where_clauses(wfcx, item.span, def_id);
310+
check_where_clauses(wfcx, def_id);
311311
Ok(())
312312
})
313313
}
@@ -327,7 +327,7 @@ fn check_foreign_item<'tcx>(
327327
);
328328

329329
match item.kind {
330-
hir::ForeignItemKind::Fn(sig, ..) => check_item_fn(tcx, def_id, item.ident, sig.decl),
330+
hir::ForeignItemKind::Fn(sig, ..) => check_item_fn(tcx, def_id, sig.decl),
331331
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => Ok(()),
332332
}
333333
}
@@ -1017,13 +1017,7 @@ fn check_associated_item(
10171017
ty::AssocKind::Fn { .. } => {
10181018
let sig = tcx.fn_sig(item.def_id).instantiate_identity();
10191019
let hir_sig = sig_if_method.expect("bad signature for method");
1020-
check_fn_or_method(
1021-
wfcx,
1022-
item.ident(tcx).span,
1023-
sig,
1024-
hir_sig.decl,
1025-
item.def_id.expect_local(),
1026-
);
1020+
check_fn_or_method(wfcx, sig, hir_sig.decl, item.def_id.expect_local());
10271021
check_method_receiver(wfcx, hir_sig, item, self_ty)
10281022
}
10291023
ty::AssocKind::Type { .. } => {
@@ -1152,7 +1146,7 @@ fn check_type_defn<'tcx>(
11521146
}
11531147
}
11541148

1155-
check_where_clauses(wfcx, item.span, item.owner_id.def_id);
1149+
check_where_clauses(wfcx, item.owner_id.def_id);
11561150
Ok(())
11571151
})
11581152
}
@@ -1183,7 +1177,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
11831177
}
11841178

11851179
let res = enter_wf_checking_ctxt(tcx, def_id, |wfcx| {
1186-
check_where_clauses(wfcx, item.span, def_id);
1180+
check_where_clauses(wfcx, def_id);
11871181
Ok(())
11881182
});
11891183

@@ -1219,12 +1213,11 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
12191213
fn check_item_fn(
12201214
tcx: TyCtxt<'_>,
12211215
def_id: LocalDefId,
1222-
ident: Ident,
12231216
decl: &hir::FnDecl<'_>,
12241217
) -> Result<(), ErrorGuaranteed> {
12251218
enter_wf_checking_ctxt(tcx, def_id, |wfcx| {
12261219
let sig = tcx.fn_sig(def_id).instantiate_identity();
1227-
check_fn_or_method(wfcx, ident.span, sig, decl, def_id);
1220+
check_fn_or_method(wfcx, sig, decl, def_id);
12281221
Ok(())
12291222
})
12301223
}
@@ -1287,7 +1280,6 @@ fn check_const_item(
12871280
tcx: TyCtxt<'_>,
12881281
def_id: LocalDefId,
12891282
ty_span: Span,
1290-
item_span: Span,
12911283
) -> Result<(), ErrorGuaranteed> {
12921284
enter_wf_checking_ctxt(tcx, def_id, |wfcx| {
12931285
let ty = tcx.type_of(def_id).instantiate_identity();
@@ -1305,7 +1297,7 @@ fn check_const_item(
13051297
tcx.require_lang_item(LangItem::Sized, ty_span),
13061298
);
13071299

1308-
check_where_clauses(wfcx, item_span, def_id);
1300+
check_where_clauses(wfcx, def_id);
13091301

13101302
Ok(())
13111303
})
@@ -1402,14 +1394,14 @@ fn check_impl<'tcx>(
14021394
}
14031395
}
14041396

1405-
check_where_clauses(wfcx, item.span, item.owner_id.def_id);
1397+
check_where_clauses(wfcx, item.owner_id.def_id);
14061398
Ok(())
14071399
})
14081400
}
14091401

14101402
/// Checks where-clauses and inline bounds that are declared on `def_id`.
14111403
#[instrument(level = "debug", skip(wfcx))]
1412-
fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id: LocalDefId) {
1404+
pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: LocalDefId) {
14131405
let infcx = wfcx.infcx;
14141406
let tcx = wfcx.tcx();
14151407

@@ -1564,21 +1556,18 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
15641556

15651557
let predicates = predicates.instantiate_identity(tcx);
15661558

1567-
let predicates = wfcx.normalize(span, None, predicates);
1568-
1569-
debug!(?predicates.predicates);
15701559
assert_eq!(predicates.predicates.len(), predicates.spans.len());
15711560
let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| {
1561+
let p = wfcx.normalize(sp, None, p);
15721562
traits::wf::clause_obligations(infcx, wfcx.param_env, wfcx.body_def_id, p, sp)
15731563
});
15741564
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();
15751565
wfcx.register_obligations(obligations);
15761566
}
15771567

1578-
#[instrument(level = "debug", skip(wfcx, span, hir_decl))]
1568+
#[instrument(level = "debug", skip(wfcx, hir_decl))]
15791569
fn check_fn_or_method<'tcx>(
15801570
wfcx: &WfCheckingCtxt<'_, 'tcx>,
1581-
span: Span,
15821571
sig: ty::PolyFnSig<'tcx>,
15831572
hir_decl: &hir::FnDecl<'_>,
15841573
def_id: LocalDefId,
@@ -1616,7 +1605,7 @@ fn check_fn_or_method<'tcx>(
16161605
);
16171606
}
16181607

1619-
check_where_clauses(wfcx, span, def_id);
1608+
check_where_clauses(wfcx, def_id);
16201609

16211610
if sig.abi == ExternAbi::RustCall {
16221611
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)