From: Michael Goulet Date: Tue, 7 Feb 2023 23:08:25 +0000 (+0000) Subject: Remove astconv usage in diagnostic X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=6fdfdea8b11bd1c6b66d03869e7ec0bee0b94b4d;p=rust.git Remove astconv usage in diagnostic --- diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 51e3e3ec73d..4e3c2019694 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -1336,16 +1336,17 @@ pub(crate) fn suggest_associated_const( hir::Path { segments: [segment], .. }, )) | hir::ExprKind::Path(QPath::TypeRelative(ty, segment)) => { - let self_ty = self.astconv().ast_ty_to_ty(ty); - if let Ok(pick) = self.probe_for_name( - Mode::Path, - Ident::new(capitalized_name, segment.ident.span), - Some(expected_ty), - IsSuggestion(true), - self_ty, - expr.hir_id, - ProbeScope::TraitsInScope, - ) { + if let Some(self_ty) = self.typeck_results.borrow().node_type_opt(ty.hir_id) + && let Ok(pick) = self.probe_for_name( + Mode::Path, + Ident::new(capitalized_name, segment.ident.span), + Some(expected_ty), + IsSuggestion(true), + self_ty, + expr.hir_id, + ProbeScope::TraitsInScope, + ) + { (pick.item, segment) } else { return false; diff --git a/tests/ui/typeck/issue-107775.rs b/tests/ui/typeck/issue-107775.rs new file mode 100644 index 00000000000..6fbac2ee975 --- /dev/null +++ b/tests/ui/typeck/issue-107775.rs @@ -0,0 +1,40 @@ +// edition: 2021 + +use std::collections::HashMap; +use std::future::Future; +use std::pin::Pin; + +pub trait Trait { + fn do_something<'async_trait>(byte: u8) + -> + Pin + + Send + 'async_trait>>; +} + +pub struct Struct; + +impl Trait for Struct { + fn do_something<'async_trait>(byte: u8) + -> + Pin + + Send + 'async_trait>> { + Box::pin( + + async move { let byte = byte; let _: () = {}; }) + } +} + +pub struct Map { + map: HashMap Pin + Send>>>, +} + +impl Map { + pub fn new() -> Self { + let mut map = HashMap::new(); + map.insert(1, Struct::do_something); + Self { map } + //~^ ERROR mismatched types + } +} + +fn main() {} diff --git a/tests/ui/typeck/issue-107775.stderr b/tests/ui/typeck/issue-107775.stderr new file mode 100644 index 00000000000..9ee9c022c6e --- /dev/null +++ b/tests/ui/typeck/issue-107775.stderr @@ -0,0 +1,16 @@ +error[E0308]: mismatched types + --> $DIR/issue-107775.rs:35:16 + | +LL | map.insert(1, Struct::do_something); + | - -------------------- this is of type `fn(u8) -> Pin + Send>> {::do_something::<'_>}`, which causes `map` to be inferred as `HashMap<{integer}, fn(u8) -> Pin + Send>> {::do_something::<'_>}>` + | | + | this is of type `{integer}`, which causes `map` to be inferred as `HashMap<{integer}, fn(u8) -> Pin + Send>> {::do_something::<'_>}>` +LL | Self { map } + | ^^^ expected `HashMap Pin<...>>`, found `HashMap<{integer}, ...>` + | + = note: expected struct `HashMap Pin + Send + 'static)>>>` + found struct `HashMap<{integer}, fn(_) -> Pin + Send>> {::do_something::<'_>}>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.