mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Merge #8989
8989: fix: Fix type inference not working for new Try trait r=Veykril a=Veykril Fixes https://github.com/rust-analyzer/rust-analyzer/issues/8907 bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
ddc2fb3923
2 changed files with 41 additions and 1 deletions
|
@ -580,7 +580,10 @@ impl<'a> InferenceContext<'a> {
|
|||
fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> {
|
||||
let path = path![core::ops::Try];
|
||||
let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?;
|
||||
self.db.trait_data(trait_).associated_type_by_name(&name![Ok])
|
||||
let trait_data = self.db.trait_data(trait_);
|
||||
trait_data
|
||||
.associated_type_by_name(&name![Ok])
|
||||
.or_else(|| trait_data.associated_type_by_name(&name![Output]))
|
||||
}
|
||||
|
||||
fn resolve_ops_neg_output(&self) -> Option<TypeAliasId> {
|
||||
|
|
|
@ -160,6 +160,43 @@ mod result {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_tryv2() {
|
||||
check_types(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:core
|
||||
fn test() {
|
||||
let r: Result<i32, u64> = Result::Ok(1);
|
||||
let v = r?;
|
||||
v;
|
||||
} //^ i32
|
||||
|
||||
//- /core.rs crate:core
|
||||
#[prelude_import] use ops::*;
|
||||
mod ops {
|
||||
trait Try {
|
||||
type Output;
|
||||
type Residual;
|
||||
}
|
||||
}
|
||||
|
||||
#[prelude_import] use result::*;
|
||||
mod result {
|
||||
enum Infallible {}
|
||||
enum Result<O, E> {
|
||||
Ok(O),
|
||||
Err(E)
|
||||
}
|
||||
|
||||
impl<O, E> crate::ops::Try for Result<O, E> {
|
||||
type Output = O;
|
||||
type Error = Result<Infallible, E>;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_for_loop() {
|
||||
check_types(
|
||||
|
|
Loading…
Reference in a new issue