File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -580,7 +580,10 @@ impl<'a> InferenceContext<'a> {
580
580
fn resolve_ops_try_ok ( & self ) -> Option < TypeAliasId > {
581
581
let path = path ! [ core:: ops:: Try ] ;
582
582
let trait_ = self . resolver . resolve_known_trait ( self . db . upcast ( ) , & path) ?;
583
- self . db . trait_data ( trait_) . associated_type_by_name ( & name ! [ Ok ] )
583
+ let trait_data = self . db . trait_data ( trait_) ;
584
+ trait_data
585
+ . associated_type_by_name ( & name ! [ Ok ] )
586
+ . or_else ( || trait_data. associated_type_by_name ( & name ! [ Output ] ) )
584
587
}
585
588
586
589
fn resolve_ops_neg_output ( & self ) -> Option < TypeAliasId > {
Original file line number Diff line number Diff line change @@ -160,6 +160,43 @@ mod result {
160
160
) ;
161
161
}
162
162
163
+ #[ test]
164
+ fn infer_tryv2 ( ) {
165
+ check_types (
166
+ r#"
167
+ //- /main.rs crate:main deps:core
168
+ fn test() {
169
+ let r: Result<i32, u64> = Result::Ok(1);
170
+ let v = r?;
171
+ v;
172
+ } //^ i32
173
+
174
+ //- /core.rs crate:core
175
+ #[prelude_import] use ops::*;
176
+ mod ops {
177
+ trait Try {
178
+ type Output;
179
+ type Residual;
180
+ }
181
+ }
182
+
183
+ #[prelude_import] use result::*;
184
+ mod result {
185
+ enum Infallible {}
186
+ enum Result<O, E> {
187
+ Ok(O),
188
+ Err(E)
189
+ }
190
+
191
+ impl<O, E> crate::ops::Try for Result<O, E> {
192
+ type Output = O;
193
+ type Error = Result<Infallible, E>;
194
+ }
195
+ }
196
+ "# ,
197
+ ) ;
198
+ }
199
+
163
200
#[ test]
164
201
fn infer_for_loop ( ) {
165
202
check_types (
You can’t perform that action at this time.
0 commit comments