diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-14 14:08:08 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-14 14:08:08 +0000 |
commit | 77db6177658b32f69ad7ebfdef96c1b3b2893fdd (patch) | |
tree | 2a9f0f16b34821dfe4319bef410e177311e87f16 /crates/ra_hir_ty | |
parent | 7238037de42a2fd88434930c521b926d7b0026da (diff) | |
parent | f02fcc16444fcd18ccd51b43fa01bf0233e044fa (diff) |
Merge #2554
2554: Add macros for known names and paths r=matklad a=flodiebold
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/src/autoderef.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer.rs | 38 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/builtin.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/utils.rs | 6 |
6 files changed, 30 insertions, 32 deletions
diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs index d557962b4..ee48fa537 100644 --- a/crates/ra_hir_ty/src/autoderef.rs +++ b/crates/ra_hir_ty/src/autoderef.rs | |||
@@ -6,7 +6,7 @@ | |||
6 | use std::iter::successors; | 6 | use std::iter::successors; |
7 | 7 | ||
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | use hir_expand::name; | 9 | use hir_expand::name::name; |
10 | use log::{info, warn}; | 10 | use log::{info, warn}; |
11 | use ra_db::CrateId; | 11 | use ra_db::CrateId; |
12 | 12 | ||
@@ -52,7 +52,7 @@ fn deref_by_trait( | |||
52 | LangItemTarget::TraitId(it) => it, | 52 | LangItemTarget::TraitId(it) => it, |
53 | _ => return None, | 53 | _ => return None, |
54 | }; | 54 | }; |
55 | let target = db.trait_data(deref_trait).associated_type_by_name(&name::TARGET_TYPE)?; | 55 | let target = db.trait_data(deref_trait).associated_type_by_name(&name![Target])?; |
56 | 56 | ||
57 | let generic_params = generics(db, target.into()); | 57 | let generic_params = generics(db, target.into()); |
58 | if generic_params.len() != 1 { | 58 | if generic_params.len() != 1 { |
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index d2bd64e5c..f752a9f09 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use hir_def::{ | 5 | use hir_def::{ |
6 | path::{known, Path}, | 6 | path::{path, Path}, |
7 | resolver::HasResolver, | 7 | resolver::HasResolver, |
8 | AdtId, FunctionId, | 8 | AdtId, FunctionId, |
9 | }; | 9 | }; |
@@ -124,7 +124,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
124 | None => return, | 124 | None => return, |
125 | }; | 125 | }; |
126 | 126 | ||
127 | let std_result_path = known::std_result_result(); | 127 | let std_result_path = path![std::result::Result]; |
128 | 128 | ||
129 | let resolver = self.func.resolver(db); | 129 | let resolver = self.func.resolver(db); |
130 | let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) { | 130 | let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) { |
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index a1201b3e4..f1b7e9442 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -24,12 +24,12 @@ use hir_def::{ | |||
24 | body::Body, | 24 | body::Body, |
25 | data::{ConstData, FunctionData}, | 25 | data::{ConstData, FunctionData}, |
26 | expr::{BindingAnnotation, ExprId, PatId}, | 26 | expr::{BindingAnnotation, ExprId, PatId}, |
27 | path::{known, Path}, | 27 | path::{path, Path}, |
28 | resolver::{HasResolver, Resolver, TypeNs}, | 28 | resolver::{HasResolver, Resolver, TypeNs}, |
29 | type_ref::{Mutability, TypeRef}, | 29 | type_ref::{Mutability, TypeRef}, |
30 | AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TypeAliasId, VariantId, | 30 | AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TypeAliasId, VariantId, |
31 | }; | 31 | }; |
32 | use hir_expand::{diagnostics::DiagnosticSink, name}; | 32 | use hir_expand::{diagnostics::DiagnosticSink, name::name}; |
33 | use ra_arena::map::ArenaMap; | 33 | use ra_arena::map::ArenaMap; |
34 | use ra_prof::profile; | 34 | use ra_prof::profile; |
35 | 35 | ||
@@ -422,73 +422,73 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
422 | } | 422 | } |
423 | 423 | ||
424 | fn resolve_into_iter_item(&self) -> Option<TypeAliasId> { | 424 | fn resolve_into_iter_item(&self) -> Option<TypeAliasId> { |
425 | let path = known::std_iter_into_iterator(); | 425 | let path = path![std::iter::IntoIterator]; |
426 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 426 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
427 | self.db.trait_data(trait_).associated_type_by_name(&name::ITEM_TYPE) | 427 | self.db.trait_data(trait_).associated_type_by_name(&name![Item]) |
428 | } | 428 | } |
429 | 429 | ||
430 | fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> { | 430 | fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> { |
431 | let path = known::std_ops_try(); | 431 | let path = path![std::ops::Try]; |
432 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 432 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
433 | self.db.trait_data(trait_).associated_type_by_name(&name::OK_TYPE) | 433 | self.db.trait_data(trait_).associated_type_by_name(&name![Ok]) |
434 | } | 434 | } |
435 | 435 | ||
436 | fn resolve_ops_neg_output(&self) -> Option<TypeAliasId> { | 436 | fn resolve_ops_neg_output(&self) -> Option<TypeAliasId> { |
437 | let path = known::std_ops_neg(); | 437 | let path = path![std::ops::Neg]; |
438 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 438 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
439 | self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) | 439 | self.db.trait_data(trait_).associated_type_by_name(&name![Output]) |
440 | } | 440 | } |
441 | 441 | ||
442 | fn resolve_ops_not_output(&self) -> Option<TypeAliasId> { | 442 | fn resolve_ops_not_output(&self) -> Option<TypeAliasId> { |
443 | let path = known::std_ops_not(); | 443 | let path = path![std::ops::Not]; |
444 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 444 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
445 | self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) | 445 | self.db.trait_data(trait_).associated_type_by_name(&name![Output]) |
446 | } | 446 | } |
447 | 447 | ||
448 | fn resolve_future_future_output(&self) -> Option<TypeAliasId> { | 448 | fn resolve_future_future_output(&self) -> Option<TypeAliasId> { |
449 | let path = known::std_future_future(); | 449 | let path = path![std::future::Future]; |
450 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 450 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; |
451 | self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) | 451 | self.db.trait_data(trait_).associated_type_by_name(&name![Output]) |
452 | } | 452 | } |
453 | 453 | ||
454 | fn resolve_boxed_box(&self) -> Option<AdtId> { | 454 | fn resolve_boxed_box(&self) -> Option<AdtId> { |
455 | let path = known::std_boxed_box(); | 455 | let path = path![std::boxed::Box]; |
456 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 456 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
457 | Some(struct_.into()) | 457 | Some(struct_.into()) |
458 | } | 458 | } |
459 | 459 | ||
460 | fn resolve_range_full(&self) -> Option<AdtId> { | 460 | fn resolve_range_full(&self) -> Option<AdtId> { |
461 | let path = known::std_ops_range_full(); | 461 | let path = path![std::ops::RangeFull]; |
462 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 462 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
463 | Some(struct_.into()) | 463 | Some(struct_.into()) |
464 | } | 464 | } |
465 | 465 | ||
466 | fn resolve_range(&self) -> Option<AdtId> { | 466 | fn resolve_range(&self) -> Option<AdtId> { |
467 | let path = known::std_ops_range(); | 467 | let path = path![std::ops::Range]; |
468 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 468 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
469 | Some(struct_.into()) | 469 | Some(struct_.into()) |
470 | } | 470 | } |
471 | 471 | ||
472 | fn resolve_range_inclusive(&self) -> Option<AdtId> { | 472 | fn resolve_range_inclusive(&self) -> Option<AdtId> { |
473 | let path = known::std_ops_range_inclusive(); | 473 | let path = path![std::ops::RangeInclusive]; |
474 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 474 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
475 | Some(struct_.into()) | 475 | Some(struct_.into()) |
476 | } | 476 | } |
477 | 477 | ||
478 | fn resolve_range_from(&self) -> Option<AdtId> { | 478 | fn resolve_range_from(&self) -> Option<AdtId> { |
479 | let path = known::std_ops_range_from(); | 479 | let path = path![std::ops::RangeFrom]; |
480 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 480 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
481 | Some(struct_.into()) | 481 | Some(struct_.into()) |
482 | } | 482 | } |
483 | 483 | ||
484 | fn resolve_range_to(&self) -> Option<AdtId> { | 484 | fn resolve_range_to(&self) -> Option<AdtId> { |
485 | let path = known::std_ops_range_to(); | 485 | let path = path![std::ops::RangeTo]; |
486 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 486 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
487 | Some(struct_.into()) | 487 | Some(struct_.into()) |
488 | } | 488 | } |
489 | 489 | ||
490 | fn resolve_range_to_inclusive(&self) -> Option<AdtId> { | 490 | fn resolve_range_to_inclusive(&self) -> Option<AdtId> { |
491 | let path = known::std_ops_range_to_inclusive(); | 491 | let path = path![std::ops::RangeToInclusive]; |
492 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 492 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; |
493 | Some(struct_.into()) | 493 | Some(struct_.into()) |
494 | } | 494 | } |
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index f8c00a7b4..2e3cdd53a 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -10,7 +10,7 @@ use hir_def::{ | |||
10 | resolver::resolver_for_expr, | 10 | resolver::resolver_for_expr, |
11 | AdtId, ContainerId, Lookup, StructFieldId, | 11 | AdtId, ContainerId, Lookup, StructFieldId, |
12 | }; | 12 | }; |
13 | use hir_expand::name::{self, Name}; | 13 | use hir_expand::name::{name, Name}; |
14 | use ra_syntax::ast::RangeOp; | 14 | use ra_syntax::ast::RangeOp; |
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
@@ -631,7 +631,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
631 | // Parent arguments are unknown, except for the receiver type | 631 | // Parent arguments are unknown, except for the receiver type |
632 | if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { | 632 | if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { |
633 | for (_id, param) in parent_generics { | 633 | for (_id, param) in parent_generics { |
634 | if param.name == name::SELF_TYPE { | 634 | if param.name == name![Self] { |
635 | substs.push(receiver_ty.clone()); | 635 | substs.push(receiver_ty.clone()); |
636 | } else { | 636 | } else { |
637 | substs.push(Ty::Unknown); | 637 | substs.push(Ty::Unknown); |
diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index 598fd81e3..cd587a338 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! This module provides the built-in trait implementations, e.g. to make | 1 | //! This module provides the built-in trait implementations, e.g. to make |
2 | //! closures implement `Fn`. | 2 | //! closures implement `Fn`. |
3 | use hir_def::{expr::Expr, lang_item::LangItemTarget, TraitId, TypeAliasId}; | 3 | use hir_def::{expr::Expr, lang_item::LangItemTarget, TraitId, TypeAliasId}; |
4 | use hir_expand::name; | 4 | use hir_expand::name::name; |
5 | use ra_db::CrateId; | 5 | use ra_db::CrateId; |
6 | 6 | ||
7 | use super::{AssocTyValue, Impl}; | 7 | use super::{AssocTyValue, Impl}; |
@@ -79,7 +79,7 @@ fn closure_fn_trait_impl_datum( | |||
79 | // and don't want to return a valid value only to find out later that FnOnce | 79 | // and don't want to return a valid value only to find out later that FnOnce |
80 | // is broken | 80 | // is broken |
81 | let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; | 81 | let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; |
82 | let _output = db.trait_data(fn_once_trait).associated_type_by_name(&name::OUTPUT_TYPE)?; | 82 | let _output = db.trait_data(fn_once_trait).associated_type_by_name(&name![Output])?; |
83 | 83 | ||
84 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { | 84 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { |
85 | Expr::Lambda { args, .. } => args.len() as u16, | 85 | Expr::Lambda { args, .. } => args.len() as u16, |
@@ -137,7 +137,7 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
137 | 137 | ||
138 | let output_ty_id = db | 138 | let output_ty_id = db |
139 | .trait_data(fn_once_trait) | 139 | .trait_data(fn_once_trait) |
140 | .associated_type_by_name(&name::OUTPUT_TYPE) | 140 | .associated_type_by_name(&name![Output]) |
141 | .expect("assoc ty value should not exist"); | 141 | .expect("assoc ty value should not exist"); |
142 | 142 | ||
143 | BuiltinImplAssocTyValueData { | 143 | BuiltinImplAssocTyValueData { |
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index aeb211a91..0049d3c6f 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs | |||
@@ -10,10 +10,8 @@ use hir_def::{ | |||
10 | type_ref::TypeRef, | 10 | type_ref::TypeRef, |
11 | ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, | 11 | ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, |
12 | }; | 12 | }; |
13 | use hir_expand::name::{self, Name}; | 13 | use hir_expand::name::{name, Name}; |
14 | 14 | ||
15 | // FIXME: this is wrong, b/c it can't express `trait T: PartialEq<()>`. | ||
16 | // We should return a `TraitREf` here. | ||
17 | fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { | 15 | fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { |
18 | let resolver = trait_.resolver(db); | 16 | let resolver = trait_.resolver(db); |
19 | // returning the iterator directly doesn't easily work because of | 17 | // returning the iterator directly doesn't easily work because of |
@@ -24,7 +22,7 @@ fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { | |||
24 | .where_predicates | 22 | .where_predicates |
25 | .iter() | 23 | .iter() |
26 | .filter_map(|pred| match &pred.type_ref { | 24 | .filter_map(|pred| match &pred.type_ref { |
27 | TypeRef::Path(p) if p.as_ident() == Some(&name::SELF_TYPE) => pred.bound.as_path(), | 25 | TypeRef::Path(p) if p.as_ident() == Some(&name![Self]) => pred.bound.as_path(), |
28 | _ => None, | 26 | _ => None, |
29 | }) | 27 | }) |
30 | .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { | 28 | .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { |