Skip to content

Commit fe26182

Browse files
authored
Rollup merge of #107779 - compiler-errors:issue-107775, r=jackh726
Remove astconv usage in diagnostic Fixes #107775 Location of the test sucks, I know, but I needed to put it somewhere 😓 The issue here is that the root cause of the issue has nothing to do with what's being tested, so I couldn't really give it a better name. Oh well.
2 parents 5e467f5 + 6fdfdea commit fe26182

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1336,16 +1336,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13361336
hir::Path { segments: [segment], .. },
13371337
))
13381338
| hir::ExprKind::Path(QPath::TypeRelative(ty, segment)) => {
1339-
let self_ty = self.astconv().ast_ty_to_ty(ty);
1340-
if let Ok(pick) = self.probe_for_name(
1341-
Mode::Path,
1342-
Ident::new(capitalized_name, segment.ident.span),
1343-
Some(expected_ty),
1344-
IsSuggestion(true),
1345-
self_ty,
1346-
expr.hir_id,
1347-
ProbeScope::TraitsInScope,
1348-
) {
1339+
if let Some(self_ty) = self.typeck_results.borrow().node_type_opt(ty.hir_id)
1340+
&& let Ok(pick) = self.probe_for_name(
1341+
Mode::Path,
1342+
Ident::new(capitalized_name, segment.ident.span),
1343+
Some(expected_ty),
1344+
IsSuggestion(true),
1345+
self_ty,
1346+
expr.hir_id,
1347+
ProbeScope::TraitsInScope,
1348+
)
1349+
{
13491350
(pick.item, segment)
13501351
} else {
13511352
return false;

tests/ui/typeck/issue-107775.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// edition: 2021
2+
3+
use std::collections::HashMap;
4+
use std::future::Future;
5+
use std::pin::Pin;
6+
7+
pub trait Trait {
8+
fn do_something<'async_trait>(byte: u8)
9+
->
10+
Pin<Box<dyn Future<Output = ()> +
11+
Send + 'async_trait>>;
12+
}
13+
14+
pub struct Struct;
15+
16+
impl Trait for Struct {
17+
fn do_something<'async_trait>(byte: u8)
18+
->
19+
Pin<Box<dyn Future<Output = ()> +
20+
Send + 'async_trait>> {
21+
Box::pin(
22+
23+
async move { let byte = byte; let _: () = {}; })
24+
}
25+
}
26+
27+
pub struct Map {
28+
map: HashMap<u16, fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>>>,
29+
}
30+
31+
impl Map {
32+
pub fn new() -> Self {
33+
let mut map = HashMap::new();
34+
map.insert(1, Struct::do_something);
35+
Self { map }
36+
//~^ ERROR mismatched types
37+
}
38+
}
39+
40+
fn main() {}

tests/ui/typeck/issue-107775.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-107775.rs:35:16
3+
|
4+
LL | map.insert(1, Struct::do_something);
5+
| - -------------------- this is of type `fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>> {<Struct as Trait>::do_something::<'_>}`, which causes `map` to be inferred as `HashMap<{integer}, fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>> {<Struct as Trait>::do_something::<'_>}>`
6+
| |
7+
| this is of type `{integer}`, which causes `map` to be inferred as `HashMap<{integer}, fn(u8) -> Pin<Box<dyn Future<Output = ()> + Send>> {<Struct as Trait>::do_something::<'_>}>`
8+
LL | Self { map }
9+
| ^^^ expected `HashMap<u16, fn(u8) -> Pin<...>>`, found `HashMap<{integer}, ...>`
10+
|
11+
= note: expected struct `HashMap<u16, fn(_) -> Pin<Box<(dyn Future<Output = ()> + Send + 'static)>>>`
12+
found struct `HashMap<{integer}, fn(_) -> Pin<Box<dyn Future<Output = ()> + Send>> {<Struct as Trait>::do_something::<'_>}>`
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)