Skip to content

Commit 669a403

Browse files
committed
review comments: move code, fix indentation and change span
1 parent 0118278 commit 669a403

File tree

5 files changed

+77
-69
lines changed

5 files changed

+77
-69
lines changed

src/librustc/ty/wf.rs

+51-39
Original file line numberDiff line numberDiff line change
@@ -170,55 +170,67 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
170170
let cause = self.cause(traits::MiscObligation);
171171
let param_env = self.param_env;
172172

173-
if let Elaborate::All = elaborate {
174-
let trait_assoc_items = tcx.associated_items(trait_ref.def_id);
175-
176-
let predicates = obligations.iter()
177-
.map(|obligation| obligation.predicate.clone())
178-
.collect();
179-
let implied_obligations = traits::elaborate_predicates(tcx, predicates);
180-
let item_span: Option<Span> = self.item.map(|i| i.span);
181-
let item = &self.item;
182-
let implied_obligations = implied_obligations.map(|pred| {
183-
let mut cause = cause.clone();
184-
match &pred {
185-
ty::Predicate::Projection(proj) => {
186-
if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
187-
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
188-
if let Some(impl_item) = impl_items.iter().filter(|item| {
189-
item.ident == trait_assoc_item.ident
190-
}).next() {
191-
cause.span = impl_item.span;
192-
cause.code = traits::AssocTypeBound(
193-
item_span,
194-
trait_assoc_item.ident.span,
195-
);
196-
}
173+
let item = &self.item;
174+
let extend_cause_with_original_assoc_item_obligation = |
175+
cause: &mut traits::ObligationCause<'_>,
176+
pred: &ty::Predicate<'_>,
177+
trait_assoc_items: ty::AssocItemsIterator<'_>,
178+
| {
179+
let item_span = item.map(|i| tcx.sess.source_map().def_span(i.span));
180+
match pred {
181+
ty::Predicate::Projection(proj) => {
182+
if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
183+
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
184+
if let Some(impl_item) = impl_items.iter().filter(|item| {
185+
item.ident == trait_assoc_item.ident
186+
}).next() {
187+
cause.span = impl_item.span;
188+
cause.code = traits::AssocTypeBound(
189+
item_span,
190+
trait_assoc_item.ident.span,
191+
);
197192
}
198193
}
199-
ty::Predicate::Trait(proj) => {
194+
}
195+
ty::Predicate::Trait(proj) => {
200196
if let (
201197
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
202-
Some(hir::ItemKind::Impl(.., impl_items)),
203-
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind)) {
204-
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items.clone()
198+
Some(hir::ItemKind::Impl(.., impl_items)),
199+
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind)) {
200+
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
205201
.filter(|i| i.def_id == *item_def_id)
206202
.next()
207-
.and_then(|trait_assoc_item| impl_items.iter()
208-
.filter(|i| i.ident == trait_assoc_item.ident)
209-
.next()
210-
.map(|impl_item| (impl_item, trait_assoc_item)))
203+
.and_then(|trait_assoc_item| impl_items.iter()
204+
.filter(|i| i.ident == trait_assoc_item.ident)
205+
.next()
206+
.map(|impl_item| (impl_item, trait_assoc_item)))
211207
{
212-
cause.span = impl_item.span;
213-
cause.code = traits::AssocTypeBound(
214-
item_span,
215-
trait_assoc_item.ident.span,
216-
);
217-
}
208+
cause.span = impl_item.span;
209+
cause.code = traits::AssocTypeBound(
210+
item_span,
211+
trait_assoc_item.ident.span,
212+
);
218213
}
219214
}
220-
_ => {}
221215
}
216+
_ => {}
217+
}
218+
};
219+
220+
if let Elaborate::All = elaborate {
221+
let trait_assoc_items = tcx.associated_items(trait_ref.def_id);
222+
223+
let predicates = obligations.iter()
224+
.map(|obligation| obligation.predicate.clone())
225+
.collect();
226+
let implied_obligations = traits::elaborate_predicates(tcx, predicates);
227+
let implied_obligations = implied_obligations.map(|pred| {
228+
let mut cause = cause.clone();
229+
extend_cause_with_original_assoc_item_obligation(
230+
&mut cause,
231+
&pred,
232+
trait_assoc_items.clone(),
233+
);
222234
traits::Obligation::new(cause, param_env, pred)
223235
});
224236
self.out.extend(implied_obligations);

src/test/ui/associated-types/point-at-type-on-obligation-failure-2.stderr

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
error[E0277]: the trait bound `bool: Bar` is not satisfied
22
--> $DIR/point-at-type-on-obligation-failure-2.rs:8:5
33
|
4-
LL | type Assoc: Bar;
5-
| ----- associated type defined here
4+
LL | type Assoc: Bar;
5+
| ----- associated type defined here
66
...
7-
LL | / impl Foo for () {
8-
LL | | type Assoc = bool;
9-
| | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
10-
LL | | }
11-
| |_- in this `impl` item
7+
LL | impl Foo for () {
8+
| --------------- in this `impl` item
9+
LL | type Assoc = bool;
10+
| ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
1211

1312
error: aborting due to previous error
1413

src/test/ui/associated-types/point-at-type-on-obligation-failure.stderr

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
22
--> $DIR/point-at-type-on-obligation-failure.rs:13:5
33
|
4-
LL | type Ok;
5-
| -- associated type defined here
4+
LL | type Ok;
5+
| -- associated type defined here
66
...
7-
LL | / impl Bar for Foo {
8-
LL | | type Ok = ();
9-
| | ^^^^^^^^^^^^^ expected u32, found ()
10-
LL | | type Sibling = Foo2;
11-
LL | | }
12-
| |_- in this `impl` item
7+
LL | impl Bar for Foo {
8+
| ---------------- in this `impl` item
9+
LL | type Ok = ();
10+
| ^^^^^^^^^^^^^ expected u32, found ()
1311
|
1412
= note: expected type `u32`
1513
found type `()`

src/test/ui/issues/issue-43784-associated-type.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
22
--> $DIR/issue-43784-associated-type.rs:14:5
33
|
4-
LL | type Assoc: Partial<Self>;
5-
| ----- associated type defined here
4+
LL | type Assoc: Partial<Self>;
5+
| ----- associated type defined here
66
...
7-
LL | / impl<T> Complete for T {
8-
| | - help: consider restricting this bound: `T: std::marker::Copy`
9-
LL | | type Assoc = T;
10-
| | ^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
11-
LL | | }
12-
| |_- in this `impl` item
7+
LL | impl<T> Complete for T {
8+
| ---------------------- in this `impl` item
9+
| |
10+
| help: consider restricting this bound: `T: std::marker::Copy`
11+
LL | type Assoc = T;
12+
| ^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
1313
|
1414
= help: consider adding a `where T: std::marker::Copy` bound
1515

src/test/ui/traits/cycle-cache-err-60010.stderr

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ LL | _parse: <ParseQuery as Query<RootDatabase>>::Data,
99
error[E0275]: overflow evaluating the requirement `RootDatabase: SourceDatabase`
1010
--> $DIR/cycle-cache-err-60010.rs:31:5
1111
|
12-
LL | type Storage;
13-
| ------- associated type defined here
12+
LL | type Storage;
13+
| ------- associated type defined here
1414
...
15-
LL | / impl Database for RootDatabase {
16-
LL | | type Storage = SalsaStorage;
17-
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18-
LL | | }
19-
| |_- in this `impl` item
15+
LL | impl Database for RootDatabase {
16+
| ------------------------------ in this `impl` item
17+
LL | type Storage = SalsaStorage;
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2019
|
2120
= note: required because of the requirements on the impl of `Query<RootDatabase>` for `ParseQuery`
2221
= note: required because it appears within the type `SalsaStorage`

0 commit comments

Comments
 (0)