diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-08-19 12:27:02 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-08-19 12:27:02 +0100 |
commit | 529ca7e5e0573e15b23cd0067a691bf1ffebae84 (patch) | |
tree | 0cc09513805718a7c31cadb1776ff4eb865caaef /crates/hir/src/code_model.rs | |
parent | c1cfd010096daa85f8acd6f1ea15d92097816e14 (diff) | |
parent | 3456e2eec7c1e18734f8fa41924a83b4c676dc00 (diff) |
Merge #5643
5643: Add new consuming modifier, apply consuming and mutable to methods r=matklad a=Nashenas88
This adds a new `consuming` semantic modifier for syntax highlighters.
This also emits `mutable` and `consuming` in two cases:
- When a method takes `&mut self`, then it now has `function.mutable` emitted.
- When a method takes `self`, and the type of `Self` is not `Copy`, then `function.consuming` is emitted.
CC @flodiebold
Co-authored-by: Paul Daniel Faria <[email protected]>
Diffstat (limited to 'crates/hir/src/code_model.rs')
-rw-r--r-- | crates/hir/src/code_model.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index c442654dd..31d5276b0 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -670,6 +670,21 @@ impl Function { | |||
670 | db.function_data(self.id).has_self_param | 670 | db.function_data(self.id).has_self_param |
671 | } | 671 | } |
672 | 672 | ||
673 | pub fn mutability_of_self_param(self, db: &dyn HirDatabase) -> Option<Mutability> { | ||
674 | let func_data = db.function_data(self.id); | ||
675 | if !func_data.has_self_param { | ||
676 | return None; | ||
677 | } | ||
678 | |||
679 | func_data.params.first().and_then(|param| { | ||
680 | if let TypeRef::Reference(_, mutability) = param { | ||
681 | Some(*mutability) | ||
682 | } else { | ||
683 | None | ||
684 | } | ||
685 | }) | ||
686 | } | ||
687 | |||
673 | pub fn params(self, db: &dyn HirDatabase) -> Vec<TypeRef> { | 688 | pub fn params(self, db: &dyn HirDatabase) -> Vec<TypeRef> { |
674 | db.function_data(self.id).params.clone() | 689 | db.function_data(self.id).params.clone() |
675 | } | 690 | } |