Skip to content

Commit 6870f79

Browse files
committed
Use more accurate failed predicate spans
1 parent 8d48597 commit 6870f79

40 files changed

+187
-212
lines changed

src/librustc/ty/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ impl<'tcx> GenericPredicates<'tcx> {
10151015
) -> InstantiatedPredicates<'tcx> {
10161016
InstantiatedPredicates {
10171017
predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(),
1018+
spans: self.predicates.iter().map(|(_, sp)| *sp).collect(),
10181019
}
10191020
}
10201021

@@ -1028,6 +1029,7 @@ impl<'tcx> GenericPredicates<'tcx> {
10281029
tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs);
10291030
}
10301031
instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)));
1032+
instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp));
10311033
}
10321034

10331035
pub fn instantiate_identity(&self, tcx: TyCtxt<'tcx>) -> InstantiatedPredicates<'tcx> {
@@ -1044,7 +1046,8 @@ impl<'tcx> GenericPredicates<'tcx> {
10441046
if let Some(def_id) = self.parent {
10451047
tcx.predicates_of(def_id).instantiate_identity_into(tcx, instantiated);
10461048
}
1047-
instantiated.predicates.extend(self.predicates.iter().map(|&(p, _)| p))
1049+
instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p));
1050+
instantiated.spans.extend(self.predicates.iter().map(|(_, s)| s));
10481051
}
10491052

10501053
pub fn instantiate_supertrait(
@@ -1059,6 +1062,7 @@ impl<'tcx> GenericPredicates<'tcx> {
10591062
.iter()
10601063
.map(|(pred, _)| pred.subst_supertrait(tcx, poly_trait_ref))
10611064
.collect(),
1065+
spans: self.predicates.iter().map(|(_, sp)| *sp).collect(),
10621066
}
10631067
}
10641068
}
@@ -1511,11 +1515,12 @@ impl<'tcx> Predicate<'tcx> {
15111515
#[derive(Clone, Debug, TypeFoldable)]
15121516
pub struct InstantiatedPredicates<'tcx> {
15131517
pub predicates: Vec<Predicate<'tcx>>,
1518+
pub spans: Vec<Span>,
15141519
}
15151520

15161521
impl<'tcx> InstantiatedPredicates<'tcx> {
15171522
pub fn empty() -> InstantiatedPredicates<'tcx> {
1518-
InstantiatedPredicates { predicates: vec![] }
1523+
InstantiatedPredicates { predicates: vec![], spans: vec![] }
15191524
}
15201525

15211526
pub fn is_empty(&self) -> bool {

src/librustc_traits/lowering/environment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ crate fn environment(tcx: TyCtxt<'_>, def_id: DefId) -> Environment<'_> {
161161
}
162162

163163
// Compute the bounds on `Self` and the type parameters.
164-
let ty::InstantiatedPredicates { predicates } =
164+
let ty::InstantiatedPredicates { predicates, .. } =
165165
tcx.predicates_of(def_id).instantiate_identity(tcx);
166166

167167
let clauses = predicates

src/librustc_ty/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
228228
}
229229
// Compute the bounds on Self and the type parameters.
230230

231-
let ty::InstantiatedPredicates { predicates } =
231+
let ty::InstantiatedPredicates { predicates, .. } =
232232
tcx.predicates_of(def_id).instantiate_identity(tcx);
233233

234234
// Finally, we have to normalize the bounds in the environment, in

src/librustc_typeck/check/wfcheck.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -665,16 +665,21 @@ fn check_where_clauses<'tcx, 'fcx>(
665665
let mut predicates = predicates.instantiate_identity(fcx.tcx);
666666

667667
if let Some((return_ty, span)) = return_ty {
668-
predicates.predicates.extend(check_opaque_types(tcx, fcx, def_id, span, return_ty));
668+
let opaque_types = check_opaque_types(tcx, fcx, def_id, span, return_ty);
669+
for _ in 0..opaque_types.len() {
670+
predicates.spans.push(span);
671+
}
672+
predicates.predicates.extend(opaque_types);
669673
}
670674

671675
let predicates = fcx.normalize_associated_types_in(span, &predicates);
672676

673677
debug!("check_where_clauses: predicates={:?}", predicates.predicates);
674-
let wf_obligations = predicates
675-
.predicates
676-
.iter()
677-
.flat_map(|p| traits::wf::predicate_obligations(fcx, fcx.param_env, fcx.body_id, p, span));
678+
assert_eq!(predicates.predicates.len(), predicates.spans.len());
679+
let wf_obligations =
680+
predicates.predicates.iter().zip(predicates.spans.iter()).flat_map(|(p, sp)| {
681+
traits::wf::predicate_obligations(fcx, fcx.param_env, fcx.body_id, p, *sp)
682+
});
678683

679684
for obligation in wf_obligations.chain(default_obligations) {
680685
debug!("next obligation cause: {:?}", obligation.cause);

src/test/ui/associated-type-bounds/bad-bounds-on-assoc-in-trait.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ error[E0277]: `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterato
1010
--> $DIR/bad-bounds-on-assoc-in-trait.rs:36:1
1111
|
1212
LL | fn assume_case1<T: Case1>() {
13-
| ^^^^^^^^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::iter::Iterator`
14-
| |
15-
| `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
13+
| ^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::iter::Iterator`
14+
| |
15+
| `<<T as Case1>::C as std::iter::Iterator>::Item` is not an iterator
1616
|
1717
= help: the trait `std::iter::Iterator` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
1818

@@ -23,9 +23,9 @@ LL | trait Case1 {
2323
| ----------- required by `Case1`
2424
...
2525
LL | fn assume_case1<T: Case1>() {
26-
| ^^^^^^^^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Send`
27-
| |
28-
| `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
26+
| ^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Send`
27+
| |
28+
| `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be sent between threads safely
2929
|
3030
= help: the trait `std::marker::Send` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
3131

@@ -36,9 +36,9 @@ LL | trait Case1 {
3636
| ----------- required by `Case1`
3737
...
3838
LL | fn assume_case1<T: Case1>() {
39-
| ^^^^^^^^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Sync`
40-
| |
41-
| `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
39+
| ^^^^^ - help: consider further restricting the associated type: `where <<T as Case1>::C as std::iter::Iterator>::Item: std::marker::Sync`
40+
| |
41+
| `<<T as Case1>::C as std::iter::Iterator>::Item` cannot be shared between threads safely
4242
|
4343
= help: the trait `std::marker::Sync` is not implemented for `<<T as Case1>::C as std::iter::Iterator>::Item`
4444

@@ -49,7 +49,7 @@ LL | trait Case1 {
4949
| ----------- required by `Case1`
5050
...
5151
LL | fn assume_case1<T: Case1>() {
52-
| ^^^^^^^^^^^^ `<_ as Lam<&'a u8>>::App` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
52+
| ^^^^^ `<_ as Lam<&'a u8>>::App` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
5353
|
5454
= help: the trait `for<'a> std::fmt::Debug` is not implemented for `<_ as Lam<&'a u8>>::App`
5555

src/test/ui/associated-types/associated-types-overridden-binding.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error[E0284]: type annotations needed
2-
--> $DIR/associated-types-overridden-binding.rs:4:1
2+
--> $DIR/associated-types-overridden-binding.rs:4:12
33
|
44
LL | trait Foo: Iterator<Item = i32> {}
55
| ------------------------------- required by `Foo`
66
LL | trait Bar: Foo<Item = u32> {}
7-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self`
7+
| ^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self`
88
|
99
= note: cannot resolve `<Self as std::iter::Iterator>::Item == i32`
1010

1111
error[E0284]: type annotations needed
12-
--> $DIR/associated-types-overridden-binding.rs:7:1
12+
--> $DIR/associated-types-overridden-binding.rs:7:21
1313
|
1414
LL | trait I32Iterator = Iterator<Item = i32>;
1515
| ----------------------------------------- required by `I32Iterator`
1616
LL | trait U32Iterator = I32Iterator<Item = u32>;
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self`
17+
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `Self`
1818
|
1919
= note: cannot resolve `<Self as std::iter::Iterator>::Item == i32`
2020

src/test/ui/error-codes/E0275.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0275]: overflow evaluating the requirement `Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<T>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>: Foo`
2-
--> $DIR/E0275.rs:5:1
2+
--> $DIR/E0275.rs:5:33
33
|
44
LL | trait Foo {}
55
| --------- required by `Foo`
66
...
77
LL | impl<T> Foo for T where Bar<T>: Foo {}
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8+
| ^^^
99
|
1010
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate
1111
= note: required because of the requirements on the impl of `Foo` for `Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<T>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`

src/test/ui/generic-associated-types/issue-62326-parameter-out-of-range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// FIXME(generic-associated-types) Investigate why this doesn't compile.
55

66
trait Iterator {
7-
//~^ ERROR the requirement `for<'a> <Self as Iterator>::Item<'a>: 'a` is not satisfied
87
type Item<'a>: 'a;
8+
//~^ ERROR the requirement `for<'a> <Self as Iterator>::Item<'a>: 'a` is not satisfied
99
}
1010

1111
fn main() {}
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
error[E0280]: the requirement `for<'a> <Self as Iterator>::Item<'a>: 'a` is not satisfied
2-
--> $DIR/issue-62326-parameter-out-of-range.rs:6:1
2+
--> $DIR/issue-62326-parameter-out-of-range.rs:7:20
33
|
4-
LL | trait Iterator {
5-
| ^-------------
6-
| |
7-
| _required by `Iterator`
8-
| |
9-
LL | |
10-
LL | | type Item<'a>: 'a;
11-
LL | | }
12-
| |_^
4+
LL | trait Iterator {
5+
| -------------- required by `Iterator`
6+
LL | type Item<'a>: 'a;
7+
| ^^
138

149
error: aborting due to previous error
1510

src/test/ui/issues/issue-20005.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ trait From<Src> {
55
}
66

77
trait To {
8-
fn to<Dst>( //~ ERROR the size for values of type
8+
fn to<Dst>(
99
self
10-
) -> <Dst as From<Self>>::Result where Dst: From<Self> {
10+
) -> <Dst as From<Self>>::Result where Dst: From<Self> { //~ ERROR the size for values of type
1111
From::from(self)
1212
}
1313
}

0 commit comments

Comments
 (0)