diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-03 08:56:17 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-03 08:56:17 +0000 |
commit | 520b8a5a4dde032ba6118efb02801611191acc4e (patch) | |
tree | 811cd86e5c9a2803bc3d38f19f4ad86e60be1d18 /crates/ide/src/diagnostics | |
parent | 3bf4cec79932de0a49338f6b87dc20f85dc3a509 (diff) | |
parent | 40cd6cdf67dcfad89a80ff3a662bec2dfd983d67 (diff) |
Merge #7115
7115: Migrate HasSource::source to return Option r=matklad a=nick96
I've made a start on fixing #6913 based on the provided work plan, migrating `HasSource::source` to return an `Option`. The simple cases are migrated but there are a few that I'm unsure exactly how they should be handled:
- Logging the processing of functions in `AnalysisStatsCmd::run`: In verbose mode it includes the path to the module containing the function and the syntax range. I've handled this with an if-let but would it be better to blow up here with `expect`? I'm not 100% on the code paths but if we're processing a function definition then the source should exist.
I've handled `source()` in all code paths as `None` being a valid return value but are there some cases where we should just blow up? Also, all I've done is bubble up the returned `None`s, there may be some places where we can recover and still provide something.
Co-authored-by: Nick Spain <[email protected]>
Co-authored-by: Nick Spain <[email protected]>
Diffstat (limited to 'crates/ide/src/diagnostics')
-rw-r--r-- | crates/ide/src/diagnostics/fixes.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index d79f5c170..ec0f840e9 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs | |||
@@ -156,20 +156,23 @@ fn missing_record_expr_field_fix( | |||
156 | let record_fields = match VariantDef::from(def_id) { | 156 | let record_fields = match VariantDef::from(def_id) { |
157 | VariantDef::Struct(s) => { | 157 | VariantDef::Struct(s) => { |
158 | module = s.module(sema.db); | 158 | module = s.module(sema.db); |
159 | let source = s.source(sema.db); | 159 | #[allow(deprecated)] |
160 | let source = s.source(sema.db)?; | ||
160 | def_file_id = source.file_id; | 161 | def_file_id = source.file_id; |
161 | let fields = source.value.field_list()?; | 162 | let fields = source.value.field_list()?; |
162 | record_field_list(fields)? | 163 | record_field_list(fields)? |
163 | } | 164 | } |
164 | VariantDef::Union(u) => { | 165 | VariantDef::Union(u) => { |
165 | module = u.module(sema.db); | 166 | module = u.module(sema.db); |
166 | let source = u.source(sema.db); | 167 | #[allow(deprecated)] |
168 | let source = u.source(sema.db)?; | ||
167 | def_file_id = source.file_id; | 169 | def_file_id = source.file_id; |
168 | source.value.record_field_list()? | 170 | source.value.record_field_list()? |
169 | } | 171 | } |
170 | VariantDef::Variant(e) => { | 172 | VariantDef::Variant(e) => { |
171 | module = e.module(sema.db); | 173 | module = e.module(sema.db); |
172 | let source = e.source(sema.db); | 174 | #[allow(deprecated)] |
175 | let source = e.source(sema.db)?; | ||
173 | def_file_id = source.file_id; | 176 | def_file_id = source.file_id; |
174 | let fields = source.value.field_list()?; | 177 | let fields = source.value.field_list()?; |
175 | record_field_list(fields)? | 178 | record_field_list(fields)? |