Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
if !sp.contains(p_span) {
diag.span_label(p_span, format!("{expected}this type parameter"));
}
let parent = p_def_id.as_local().and_then(|id| {
let param_def_id = match *proj.self_ty().kind() {
ty::Param(param) => {
tcx.generics_of(body_owner_def_id).type_param(param, tcx).def_id
}
_ => p_def_id,
};
let parent = param_def_id.as_local().and_then(|id| {
let local_id = tcx.local_def_id_to_hir_id(id);
let generics = tcx.parent_hir_node(local_id).generics()?;
Some((id, generics))
Expand Down
38 changes: 38 additions & 0 deletions tests/ui/trait-bounds/associated-error-bound-issue-145586.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//@ run-rustfix

#![allow(dead_code)]

use std::marker::PhantomData;

trait Visitor<'de> {
type Value;
}

trait Deserializer<'de> {
type Error;

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>;
}

struct Wrapper<'de, T, E>(Result<T, E>, PhantomData<&'de ()>);

impl<'de, T, E> Deserializer<'de> for Wrapper<'de, T, E>
where
T: Deserializer<'de, Error = E>,
{
type Error = E;

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
match self.0 {
Ok(deserializer) => deserializer.deserialize_ignored_any(visitor), //~ ERROR mismatched types
Err(error) => Err(error),
}
}
}

fn main() {}
38 changes: 38 additions & 0 deletions tests/ui/trait-bounds/associated-error-bound-issue-145586.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//@ run-rustfix

#![allow(dead_code)]

use std::marker::PhantomData;

trait Visitor<'de> {
type Value;
}

trait Deserializer<'de> {
type Error;

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>;
}

struct Wrapper<'de, T, E>(Result<T, E>, PhantomData<&'de ()>);

impl<'de, T, E> Deserializer<'de> for Wrapper<'de, T, E>
where
T: Deserializer<'de>,
{
type Error = E;

fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where
V: Visitor<'de>,
{
match self.0 {
Ok(deserializer) => deserializer.deserialize_ignored_any(visitor), //~ ERROR mismatched types
Err(error) => Err(error),
}
}
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/trait-bounds/associated-error-bound-issue-145586.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0308]: mismatched types
--> $DIR/associated-error-bound-issue-145586.rs:32:33
|
LL | impl<'de, T, E> Deserializer<'de> for Wrapper<'de, T, E>
| - expected this type parameter
...
LL | fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
| ----------------------------- expected `Result<<V as Visitor<'de>>::Value, E>` because of return type
...
LL | Ok(deserializer) => deserializer.deserialize_ignored_any(visitor),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<<V as Visitor<'_>>::Value, E>`, found `Result<<V as Visitor<'_>>::Value, ...>`
|
= note: expected enum `Result<_, E>`
found enum `Result<_, <T as Deserializer<'de>>::Error>`
help: consider further restricting this bound
|
LL | T: Deserializer<'de, Error = E>,
| +++++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: `Rc<Foo>` cannot be shared between threads safely
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:14:7
--> $DIR/deep-level-send-bound-check-issue-40827.rs:14:7

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's weird to see uppercase in test file name, so fix it by the way.

|
LL | f(Foo(Arc::new(Bar::B(None))));
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rc<Foo>` cannot be shared between threads safely
Expand All @@ -8,24 +8,24 @@ LL | f(Foo(Arc::new(Bar::B(None))));
|
= help: within `Bar`, the trait `Sync` is not implemented for `Rc<Foo>`
note: required because it appears within the type `Bar`
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:6:6
--> $DIR/deep-level-send-bound-check-issue-40827.rs:6:6
|
LL | enum Bar {
| ^^^
= note: required for `Arc<Bar>` to implement `Send`
note: required because it appears within the type `Foo`
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:4:8
--> $DIR/deep-level-send-bound-check-issue-40827.rs:4:8
|
LL | struct Foo(Arc<Bar>);
| ^^^
note: required by a bound in `f`
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:11:9
--> $DIR/deep-level-send-bound-check-issue-40827.rs:11:9
|
LL | fn f<T: Send>(_: T) {}
| ^^^^ required by this bound in `f`

error[E0277]: `Rc<Foo>` cannot be sent between threads safely
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:14:7
--> $DIR/deep-level-send-bound-check-issue-40827.rs:14:7
|
LL | f(Foo(Arc::new(Bar::B(None))));
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rc<Foo>` cannot be sent between threads safely
Expand All @@ -34,18 +34,18 @@ LL | f(Foo(Arc::new(Bar::B(None))));
|
= help: within `Bar`, the trait `Send` is not implemented for `Rc<Foo>`
note: required because it appears within the type `Bar`
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:6:6
--> $DIR/deep-level-send-bound-check-issue-40827.rs:6:6
|
LL | enum Bar {
| ^^^
= note: required for `Arc<Bar>` to implement `Send`
note: required because it appears within the type `Foo`
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:4:8
--> $DIR/deep-level-send-bound-check-issue-40827.rs:4:8
|
LL | struct Foo(Arc<Bar>);
| ^^^
note: required by a bound in `f`
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:11:9
--> $DIR/deep-level-send-bound-check-issue-40827.rs:11:9
|
LL | fn f<T: Send>(_: T) {}
| ^^^^ required by this bound in `f`
Expand Down
Loading