diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/chalk_db.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 31 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/attribute.rs | 37 |
3 files changed, 59 insertions, 17 deletions
diff --git a/crates/hir_ty/src/chalk_db.rs b/crates/hir_ty/src/chalk_db.rs index b108fd559..4e042bf42 100644 --- a/crates/hir_ty/src/chalk_db.rs +++ b/crates/hir_ty/src/chalk_db.rs | |||
@@ -383,7 +383,7 @@ pub(crate) fn associated_ty_data_query( | |||
383 | // Lower bounds -- we could/should maybe move this to a separate query in `lower` | 383 | // Lower bounds -- we could/should maybe move this to a separate query in `lower` |
384 | let type_alias_data = db.type_alias_data(type_alias); | 384 | let type_alias_data = db.type_alias_data(type_alias); |
385 | let generic_params = generics(db.upcast(), type_alias.into()); | 385 | let generic_params = generics(db.upcast(), type_alias.into()); |
386 | let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); | 386 | // let bound_vars = generic_params.bound_vars_subst(DebruijnIndex::INNERMOST); |
387 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); | 387 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); |
388 | let ctx = crate::TyLoweringContext::new(db, &resolver) | 388 | let ctx = crate::TyLoweringContext::new(db, &resolver) |
389 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); | 389 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); |
@@ -396,8 +396,10 @@ pub(crate) fn associated_ty_data_query( | |||
396 | .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty)) | 396 | .filter_map(|pred| generic_predicate_to_inline_bound(db, &pred, &self_ty)) |
397 | .collect(); | 397 | .collect(); |
398 | 398 | ||
399 | let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); | 399 | // FIXME: Re-enable where clauses on associated types when an upstream chalk bug is fixed. |
400 | let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses }; | 400 | // (rust-analyzer#9052) |
401 | // let where_clauses = convert_where_clauses(db, type_alias.into(), &bound_vars); | ||
402 | let bound_data = rust_ir::AssociatedTyDatumBound { bounds, where_clauses: vec![] }; | ||
401 | let datum = AssociatedTyDatum { | 403 | let datum = AssociatedTyDatum { |
402 | trait_id: to_chalk_trait_id(trait_), | 404 | trait_id: to_chalk_trait_id(trait_), |
403 | id, | 405 | id, |
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 7c0ff2170..49add4ab9 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -161,7 +161,7 @@ mod result { | |||
161 | } | 161 | } |
162 | 162 | ||
163 | #[test] | 163 | #[test] |
164 | fn infer_tryv2() { | 164 | fn infer_try_trait_v2() { |
165 | check_types( | 165 | check_types( |
166 | r#" | 166 | r#" |
167 | //- /main.rs crate:main deps:core | 167 | //- /main.rs crate:main deps:core |
@@ -172,26 +172,41 @@ fn test() { | |||
172 | } //^ i32 | 172 | } //^ i32 |
173 | 173 | ||
174 | //- /core.rs crate:core | 174 | //- /core.rs crate:core |
175 | #[prelude_import] use ops::*; | ||
176 | mod ops { | 175 | mod ops { |
177 | trait Try { | 176 | mod try_trait { |
178 | type Output; | 177 | pub trait Try: FromResidual { |
179 | type Residual; | 178 | type Output; |
179 | type Residual; | ||
180 | } | ||
181 | pub trait FromResidual<R = <Self as Try>::Residual> {} | ||
180 | } | 182 | } |
183 | |||
184 | pub use self::try_trait::FromResidual; | ||
185 | pub use self::try_trait::Try; | ||
186 | } | ||
187 | |||
188 | mov convert { | ||
189 | pub trait From<T> {} | ||
190 | impl<T> From<T> for T {} | ||
181 | } | 191 | } |
182 | 192 | ||
183 | #[prelude_import] use result::*; | 193 | #[prelude_import] use result::*; |
184 | mod result { | 194 | mod result { |
185 | enum Infallible {} | 195 | use crate::convert::From; |
186 | enum Result<O, E> { | 196 | use crate::ops::{Try, FromResidual}; |
197 | |||
198 | pub enum Infallible {} | ||
199 | pub enum Result<O, E> { | ||
187 | Ok(O), | 200 | Ok(O), |
188 | Err(E) | 201 | Err(E) |
189 | } | 202 | } |
190 | 203 | ||
191 | impl<O, E> crate::ops::Try for Result<O, E> { | 204 | impl<O, E> Try for Result<O, E> { |
192 | type Output = O; | 205 | type Output = O; |
193 | type Error = Result<Infallible, E>; | 206 | type Error = Result<Infallible, E>; |
194 | } | 207 | } |
208 | |||
209 | impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {} | ||
195 | } | 210 | } |
196 | "#, | 211 | "#, |
197 | ); | 212 | ); |
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs index 13d5b90c9..76d926157 100644 --- a/crates/ide_completion/src/completions/attribute.rs +++ b/crates/ide_completion/src/completions/attribute.rs | |||
@@ -219,8 +219,7 @@ const ATTRIBUTES: &[AttrCompletion] = &[ | |||
219 | ), | 219 | ), |
220 | attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(), | 220 | attr("feature(…)", Some("feature"), Some("feature(${0:flag})")).prefer_inner(), |
221 | attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")), | 221 | attr("forbid(…)", Some("forbid"), Some("forbid(${0:lint})")), |
222 | // FIXME: resolve through macro resolution? | 222 | attr("global_allocator", None, None), |
223 | attr("global_allocator", None, None).prefer_inner(), | ||
224 | attr(r#"ignore = "…""#, Some("ignore"), Some(r#"ignore = "${0:reason}""#)), | 223 | attr(r#"ignore = "…""#, Some("ignore"), Some(r#"ignore = "${0:reason}""#)), |
225 | attr("inline", Some("inline"), Some("inline")), | 224 | attr("inline", Some("inline"), Some("inline")), |
226 | attr("link", None, None), | 225 | attr("link", None, None), |
@@ -239,7 +238,7 @@ const ATTRIBUTES: &[AttrCompletion] = &[ | |||
239 | attr("no_mangle", None, None), | 238 | attr("no_mangle", None, None), |
240 | attr("no_std", None, None).prefer_inner(), | 239 | attr("no_std", None, None).prefer_inner(), |
241 | attr("non_exhaustive", None, None), | 240 | attr("non_exhaustive", None, None), |
242 | attr("panic_handler", None, None).prefer_inner(), | 241 | attr("panic_handler", None, None), |
243 | attr(r#"path = "…""#, Some("path"), Some(r#"path ="${0:path}""#)), | 242 | attr(r#"path = "…""#, Some("path"), Some(r#"path ="${0:path}""#)), |
244 | attr("proc_macro", None, None), | 243 | attr("proc_macro", None, None), |
245 | attr("proc_macro_attribute", None, None), | 244 | attr("proc_macro_attribute", None, None), |
@@ -609,6 +608,7 @@ mod tests { | |||
609 | at export_name = "…" | 608 | at export_name = "…" |
610 | at link_name = "…" | 609 | at link_name = "…" |
611 | at link_section = "…" | 610 | at link_section = "…" |
611 | at global_allocator | ||
612 | at used | 612 | at used |
613 | "#]], | 613 | "#]], |
614 | ); | 614 | ); |
@@ -732,9 +732,9 @@ mod tests { | |||
732 | } | 732 | } |
733 | 733 | ||
734 | #[test] | 734 | #[test] |
735 | fn complete_attribute_on_expr() { | 735 | fn complete_attribute_on_fn() { |
736 | check( | 736 | check( |
737 | r#"fn main() { #[$0] foo() }"#, | 737 | r#"#[$0] fn main() {}"#, |
738 | expect![[r#" | 738 | expect![[r#" |
739 | at allow(…) | 739 | at allow(…) |
740 | at cfg(…) | 740 | at cfg(…) |
@@ -742,10 +742,35 @@ mod tests { | |||
742 | at deny(…) | 742 | at deny(…) |
743 | at forbid(…) | 743 | at forbid(…) |
744 | at warn(…) | 744 | at warn(…) |
745 | at deprecated | ||
746 | at doc = "…" | ||
747 | at doc(hidden) | ||
748 | at doc(alias = "…") | ||
749 | at must_use | ||
750 | at no_mangle | ||
751 | at export_name = "…" | ||
752 | at link_name = "…" | ||
753 | at link_section = "…" | ||
754 | at cold | ||
755 | at ignore = "…" | ||
756 | at inline | ||
757 | at must_use | ||
758 | at panic_handler | ||
759 | at proc_macro | ||
760 | at proc_macro_derive(…) | ||
761 | at proc_macro_attribute | ||
762 | at should_panic | ||
763 | at target_feature = "…" | ||
764 | at test | ||
765 | at track_caller | ||
745 | "#]], | 766 | "#]], |
746 | ); | 767 | ); |
768 | } | ||
769 | |||
770 | #[test] | ||
771 | fn complete_attribute_on_expr() { | ||
747 | check( | 772 | check( |
748 | r#"fn main() { #[$0] foo(); }"#, | 773 | r#"fn main() { #[$0] foo() }"#, |
749 | expect![[r#" | 774 | expect![[r#" |
750 | at allow(…) | 775 | at allow(…) |
751 | at cfg(…) | 776 | at cfg(…) |