Skip to content

Commit f0f788e

Browse files
authored
Unrolled build for #154655
Rollup merge of #154655 - chenyukang:yukang-fix-145586-deserializer-bound-syntax, r=jieyouxu Fix associated type bound suggestion span issue Fixes #145586
2 parents 3ebe60c + 50c6679 commit f0f788e

File tree

6 files changed

+113
-9
lines changed

6 files changed

+113
-9
lines changed

‎compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
105105
if !sp.contains(p_span) {
106106
diag.span_label(p_span, format!("{expected}this type parameter"));
107107
}
108-
let parent = p_def_id.as_local().and_then(|id| {
108+
let param_def_id = match *proj.self_ty().kind() {
109+
ty::Param(param) => {
110+
tcx.generics_of(body_owner_def_id).type_param(param, tcx).def_id
111+
}
112+
_ => p_def_id,
113+
};
114+
let parent = param_def_id.as_local().and_then(|id| {
109115
let local_id = tcx.local_def_id_to_hir_id(id);
110116
let generics = tcx.parent_hir_node(local_id).generics()?;
111117
Some((id, generics))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ run-rustfix
2+
3+
#![allow(dead_code)]
4+
5+
use std::marker::PhantomData;
6+
7+
trait Visitor<'de> {
8+
type Value;
9+
}
10+
11+
trait Deserializer<'de> {
12+
type Error;
13+
14+
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
15+
where
16+
V: Visitor<'de>;
17+
}
18+
19+
struct Wrapper<'de, T, E>(Result<T, E>, PhantomData<&'de ()>);
20+
21+
impl<'de, T, E> Deserializer<'de> for Wrapper<'de, T, E>
22+
where
23+
T: Deserializer<'de, Error = E>,
24+
{
25+
type Error = E;
26+
27+
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
28+
where
29+
V: Visitor<'de>,
30+
{
31+
match self.0 {
32+
Ok(deserializer) => deserializer.deserialize_ignored_any(visitor), //~ ERROR mismatched types
33+
Err(error) => Err(error),
34+
}
35+
}
36+
}
37+
38+
fn main() {}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ run-rustfix
2+
3+
#![allow(dead_code)]
4+
5+
use std::marker::PhantomData;
6+
7+
trait Visitor<'de> {
8+
type Value;
9+
}
10+
11+
trait Deserializer<'de> {
12+
type Error;
13+
14+
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
15+
where
16+
V: Visitor<'de>;
17+
}
18+
19+
struct Wrapper<'de, T, E>(Result<T, E>, PhantomData<&'de ()>);
20+
21+
impl<'de, T, E> Deserializer<'de> for Wrapper<'de, T, E>
22+
where
23+
T: Deserializer<'de>,
24+
{
25+
type Error = E;
26+
27+
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
28+
where
29+
V: Visitor<'de>,
30+
{
31+
match self.0 {
32+
Ok(deserializer) => deserializer.deserialize_ignored_any(visitor), //~ ERROR mismatched types
33+
Err(error) => Err(error),
34+
}
35+
}
36+
}
37+
38+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/associated-error-bound-issue-145586.rs:32:33
3+
|
4+
LL | impl<'de, T, E> Deserializer<'de> for Wrapper<'de, T, E>
5+
| - expected this type parameter
6+
...
7+
LL | fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
8+
| ----------------------------- expected `Result<<V as Visitor<'de>>::Value, E>` because of return type
9+
...
10+
LL | Ok(deserializer) => deserializer.deserialize_ignored_any(visitor),
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<<V as Visitor<'_>>::Value, E>`, found `Result<<V as Visitor<'_>>::Value, ...>`
12+
|
13+
= note: expected enum `Result<_, E>`
14+
found enum `Result<_, <T as Deserializer<'de>>::Error>`
15+
help: consider further restricting this bound
16+
|
17+
LL | T: Deserializer<'de, Error = E>,
18+
| +++++++++++
19+
20+
error: aborting due to 1 previous error
21+
22+
For more information about this error, try `rustc --explain E0308`.

tests/ui/trait-bounds/deep-level-Send-bound-check-issue-40827.rs renamed to tests/ui/trait-bounds/deep-level-send-bound-check-issue-40827.rs

File renamed without changes.

tests/ui/trait-bounds/deep-level-Send-bound-check-issue-40827.stderr renamed to tests/ui/trait-bounds/deep-level-send-bound-check-issue-40827.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: `Rc<Foo>` cannot be shared between threads safely
2-
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:14:7
2+
--> $DIR/deep-level-send-bound-check-issue-40827.rs:14:7
33
|
44
LL | f(Foo(Arc::new(Bar::B(None))));
55
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rc<Foo>` cannot be shared between threads safely
@@ -8,24 +8,24 @@ LL | f(Foo(Arc::new(Bar::B(None))));
88
|
99
= help: within `Bar`, the trait `Sync` is not implemented for `Rc<Foo>`
1010
note: required because it appears within the type `Bar`
11-
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:6:6
11+
--> $DIR/deep-level-send-bound-check-issue-40827.rs:6:6
1212
|
1313
LL | enum Bar {
1414
| ^^^
1515
= note: required for `Arc<Bar>` to implement `Send`
1616
note: required because it appears within the type `Foo`
17-
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:4:8
17+
--> $DIR/deep-level-send-bound-check-issue-40827.rs:4:8
1818
|
1919
LL | struct Foo(Arc<Bar>);
2020
| ^^^
2121
note: required by a bound in `f`
22-
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:11:9
22+
--> $DIR/deep-level-send-bound-check-issue-40827.rs:11:9
2323
|
2424
LL | fn f<T: Send>(_: T) {}
2525
| ^^^^ required by this bound in `f`
2626

2727
error[E0277]: `Rc<Foo>` cannot be sent between threads safely
28-
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:14:7
28+
--> $DIR/deep-level-send-bound-check-issue-40827.rs:14:7
2929
|
3030
LL | f(Foo(Arc::new(Bar::B(None))));
3131
| - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Rc<Foo>` cannot be sent between threads safely
@@ -34,18 +34,18 @@ LL | f(Foo(Arc::new(Bar::B(None))));
3434
|
3535
= help: within `Bar`, the trait `Send` is not implemented for `Rc<Foo>`
3636
note: required because it appears within the type `Bar`
37-
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:6:6
37+
--> $DIR/deep-level-send-bound-check-issue-40827.rs:6:6
3838
|
3939
LL | enum Bar {
4040
| ^^^
4141
= note: required for `Arc<Bar>` to implement `Send`
4242
note: required because it appears within the type `Foo`
43-
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:4:8
43+
--> $DIR/deep-level-send-bound-check-issue-40827.rs:4:8
4444
|
4545
LL | struct Foo(Arc<Bar>);
4646
| ^^^
4747
note: required by a bound in `f`
48-
--> $DIR/deep-level-Send-bound-check-issue-40827.rs:11:9
48+
--> $DIR/deep-level-send-bound-check-issue-40827.rs:11:9
4949
|
5050
LL | fn f<T: Send>(_: T) {}
5151
| ^^^^ required by this bound in `f`

0 commit comments

Comments
 (0)