review comments: move code, fix indentation and change span
This commit is contained in:
parent
0118278cde
commit
669a4035ef
5 changed files with 78 additions and 70 deletions
|
@ -170,6 +170,53 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
let cause = self.cause(traits::MiscObligation);
|
let cause = self.cause(traits::MiscObligation);
|
||||||
let param_env = self.param_env;
|
let param_env = self.param_env;
|
||||||
|
|
||||||
|
let item = &self.item;
|
||||||
|
let extend_cause_with_original_assoc_item_obligation = |
|
||||||
|
cause: &mut traits::ObligationCause<'_>,
|
||||||
|
pred: &ty::Predicate<'_>,
|
||||||
|
trait_assoc_items: ty::AssocItemsIterator<'_>,
|
||||||
|
| {
|
||||||
|
let item_span = item.map(|i| tcx.sess.source_map().def_span(i.span));
|
||||||
|
match pred {
|
||||||
|
ty::Predicate::Projection(proj) => {
|
||||||
|
if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
|
||||||
|
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
|
||||||
|
if let Some(impl_item) = impl_items.iter().filter(|item| {
|
||||||
|
item.ident == trait_assoc_item.ident
|
||||||
|
}).next() {
|
||||||
|
cause.span = impl_item.span;
|
||||||
|
cause.code = traits::AssocTypeBound(
|
||||||
|
item_span,
|
||||||
|
trait_assoc_item.ident.span,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ty::Predicate::Trait(proj) => {
|
||||||
|
if let (
|
||||||
|
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
|
||||||
|
Some(hir::ItemKind::Impl(.., impl_items)),
|
||||||
|
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind)) {
|
||||||
|
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
|
||||||
|
.filter(|i| i.def_id == *item_def_id)
|
||||||
|
.next()
|
||||||
|
.and_then(|trait_assoc_item| impl_items.iter()
|
||||||
|
.filter(|i| i.ident == trait_assoc_item.ident)
|
||||||
|
.next()
|
||||||
|
.map(|impl_item| (impl_item, trait_assoc_item)))
|
||||||
|
{
|
||||||
|
cause.span = impl_item.span;
|
||||||
|
cause.code = traits::AssocTypeBound(
|
||||||
|
item_span,
|
||||||
|
trait_assoc_item.ident.span,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if let Elaborate::All = elaborate {
|
if let Elaborate::All = elaborate {
|
||||||
let trait_assoc_items = tcx.associated_items(trait_ref.def_id);
|
let trait_assoc_items = tcx.associated_items(trait_ref.def_id);
|
||||||
|
|
||||||
|
@ -177,48 +224,13 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
||||||
.map(|obligation| obligation.predicate.clone())
|
.map(|obligation| obligation.predicate.clone())
|
||||||
.collect();
|
.collect();
|
||||||
let implied_obligations = traits::elaborate_predicates(tcx, predicates);
|
let implied_obligations = traits::elaborate_predicates(tcx, predicates);
|
||||||
let item_span: Option<Span> = self.item.map(|i| i.span);
|
|
||||||
let item = &self.item;
|
|
||||||
let implied_obligations = implied_obligations.map(|pred| {
|
let implied_obligations = implied_obligations.map(|pred| {
|
||||||
let mut cause = cause.clone();
|
let mut cause = cause.clone();
|
||||||
match &pred {
|
extend_cause_with_original_assoc_item_obligation(
|
||||||
ty::Predicate::Projection(proj) => {
|
&mut cause,
|
||||||
if let Some(hir::ItemKind::Impl(.., impl_items)) = item.map(|i| &i.kind) {
|
&pred,
|
||||||
let trait_assoc_item = tcx.associated_item(proj.projection_def_id());
|
trait_assoc_items.clone(),
|
||||||
if let Some(impl_item) = impl_items.iter().filter(|item| {
|
);
|
||||||
item.ident == trait_assoc_item.ident
|
|
||||||
}).next() {
|
|
||||||
cause.span = impl_item.span;
|
|
||||||
cause.code = traits::AssocTypeBound(
|
|
||||||
item_span,
|
|
||||||
trait_assoc_item.ident.span,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ty::Predicate::Trait(proj) => {
|
|
||||||
if let (
|
|
||||||
ty::Projection(ty::ProjectionTy { item_def_id, .. }),
|
|
||||||
Some(hir::ItemKind::Impl(.., impl_items)),
|
|
||||||
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind)) {
|
|
||||||
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items.clone()
|
|
||||||
.filter(|i| i.def_id == *item_def_id)
|
|
||||||
.next()
|
|
||||||
.and_then(|trait_assoc_item| impl_items.iter()
|
|
||||||
.filter(|i| i.ident == trait_assoc_item.ident)
|
|
||||||
.next()
|
|
||||||
.map(|impl_item| (impl_item, trait_assoc_item)))
|
|
||||||
{
|
|
||||||
cause.span = impl_item.span;
|
|
||||||
cause.code = traits::AssocTypeBound(
|
|
||||||
item_span,
|
|
||||||
trait_assoc_item.ident.span,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
traits::Obligation::new(cause, param_env, pred)
|
traits::Obligation::new(cause, param_env, pred)
|
||||||
});
|
});
|
||||||
self.out.extend(implied_obligations);
|
self.out.extend(implied_obligations);
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
error[E0277]: the trait bound `bool: Bar` is not satisfied
|
error[E0277]: the trait bound `bool: Bar` is not satisfied
|
||||||
--> $DIR/point-at-type-on-obligation-failure-2.rs:8:5
|
--> $DIR/point-at-type-on-obligation-failure-2.rs:8:5
|
||||||
|
|
|
|
||||||
LL | type Assoc: Bar;
|
LL | type Assoc: Bar;
|
||||||
| ----- associated type defined here
|
| ----- associated type defined here
|
||||||
...
|
...
|
||||||
LL | / impl Foo for () {
|
LL | impl Foo for () {
|
||||||
LL | | type Assoc = bool;
|
| --------------- in this `impl` item
|
||||||
| | ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
|
LL | type Assoc = bool;
|
||||||
LL | | }
|
| ^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `bool`
|
||||||
| |_- in this `impl` item
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
|
error[E0271]: type mismatch resolving `<Foo2 as Bar2>::Ok == ()`
|
||||||
--> $DIR/point-at-type-on-obligation-failure.rs:13:5
|
--> $DIR/point-at-type-on-obligation-failure.rs:13:5
|
||||||
|
|
|
|
||||||
LL | type Ok;
|
LL | type Ok;
|
||||||
| -- associated type defined here
|
| -- associated type defined here
|
||||||
...
|
...
|
||||||
LL | / impl Bar for Foo {
|
LL | impl Bar for Foo {
|
||||||
LL | | type Ok = ();
|
| ---------------- in this `impl` item
|
||||||
| | ^^^^^^^^^^^^^ expected u32, found ()
|
LL | type Ok = ();
|
||||||
LL | | type Sibling = Foo2;
|
| ^^^^^^^^^^^^^ expected u32, found ()
|
||||||
LL | | }
|
|
||||||
| |_- in this `impl` item
|
|
||||||
|
|
|
|
||||||
= note: expected type `u32`
|
= note: expected type `u32`
|
||||||
found type `()`
|
found type `()`
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
|
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
|
||||||
--> $DIR/issue-43784-associated-type.rs:14:5
|
--> $DIR/issue-43784-associated-type.rs:14:5
|
||||||
|
|
|
|
||||||
LL | type Assoc: Partial<Self>;
|
LL | type Assoc: Partial<Self>;
|
||||||
| ----- associated type defined here
|
| ----- associated type defined here
|
||||||
...
|
...
|
||||||
LL | / impl<T> Complete for T {
|
LL | impl<T> Complete for T {
|
||||||
| | - help: consider restricting this bound: `T: std::marker::Copy`
|
| ---------------------- in this `impl` item
|
||||||
LL | | type Assoc = T;
|
| |
|
||||||
| | ^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
| help: consider restricting this bound: `T: std::marker::Copy`
|
||||||
LL | | }
|
LL | type Assoc = T;
|
||||||
| |_- in this `impl` item
|
| ^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
||||||
|
|
|
|
||||||
= help: consider adding a `where T: std::marker::Copy` bound
|
= help: consider adding a `where T: std::marker::Copy` bound
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,13 @@ LL | _parse: <ParseQuery as Query<RootDatabase>>::Data,
|
||||||
error[E0275]: overflow evaluating the requirement `RootDatabase: SourceDatabase`
|
error[E0275]: overflow evaluating the requirement `RootDatabase: SourceDatabase`
|
||||||
--> $DIR/cycle-cache-err-60010.rs:31:5
|
--> $DIR/cycle-cache-err-60010.rs:31:5
|
||||||
|
|
|
|
||||||
LL | type Storage;
|
LL | type Storage;
|
||||||
| ------- associated type defined here
|
| ------- associated type defined here
|
||||||
...
|
...
|
||||||
LL | / impl Database for RootDatabase {
|
LL | impl Database for RootDatabase {
|
||||||
LL | | type Storage = SalsaStorage;
|
| ------------------------------ in this `impl` item
|
||||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
LL | type Storage = SalsaStorage;
|
||||||
LL | | }
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
| |_- in this `impl` item
|
|
||||||
|
|
|
|
||||||
= note: required because of the requirements on the impl of `Query<RootDatabase>` for `ParseQuery`
|
= note: required because of the requirements on the impl of `Query<RootDatabase>` for `ParseQuery`
|
||||||
= note: required because it appears within the type `SalsaStorage`
|
= note: required because it appears within the type `SalsaStorage`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue