aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Spain <[email protected]>2021-01-01 05:52:59 +0000
committerNick Spain <[email protected]>2021-01-02 10:53:52 +0000
commit6800c606ec7be5f19c1728a246eb2e2ffa4110f6 (patch)
tree9255106fd55ba6685b089ade581907eac2ef5933
parent0a9b73524059cf29a19f9333c7753c11e268ef51 (diff)
Handle missing source in target_data_for_def
-rw-r--r--crates/assists/src/handlers/fix_visibility.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/crates/assists/src/handlers/fix_visibility.rs b/crates/assists/src/handlers/fix_visibility.rs
index f5cd5f9da..de1e8f0bf 100644
--- a/crates/assists/src/handlers/fix_visibility.rs
+++ b/crates/assists/src/handlers/fix_visibility.rs
@@ -146,54 +146,53 @@ fn target_data_for_def(
146 fn offset_target_and_file_id<S, Ast>( 146 fn offset_target_and_file_id<S, Ast>(
147 db: &dyn HirDatabase, 147 db: &dyn HirDatabase,
148 x: S, 148 x: S,
149 ) -> (TextSize, Option<ast::Visibility>, TextRange, FileId) 149 ) -> Option<(TextSize, Option<ast::Visibility>, TextRange, FileId)>
150 where 150 where
151 S: HasSource<Ast = Ast>, 151 S: HasSource<Ast = Ast>,
152 Ast: AstNode + ast::VisibilityOwner, 152 Ast: AstNode + ast::VisibilityOwner,
153 { 153 {
154 #[allow(deprecated)] 154 let source = x.source(db)?;
155 let source = x.source_old(db);
156 let in_file_syntax = source.syntax(); 155 let in_file_syntax = source.syntax();
157 let file_id = in_file_syntax.file_id; 156 let file_id = in_file_syntax.file_id;
158 let syntax = in_file_syntax.value; 157 let syntax = in_file_syntax.value;
159 let current_visibility = source.value.visibility(); 158 let current_visibility = source.value.visibility();
160 ( 159 Some((
161 vis_offset(syntax), 160 vis_offset(syntax),
162 current_visibility, 161 current_visibility,
163 syntax.text_range(), 162 syntax.text_range(),
164 file_id.original_file(db.upcast()), 163 file_id.original_file(db.upcast()),
165 ) 164 ))
166 } 165 }
167 166
168 let target_name; 167 let target_name;
169 let (offset, current_visibility, target, target_file) = match def { 168 let (offset, current_visibility, target, target_file) = match def {
170 hir::ModuleDef::Function(f) => { 169 hir::ModuleDef::Function(f) => {
171 target_name = Some(f.name(db)); 170 target_name = Some(f.name(db));
172 offset_target_and_file_id(db, f) 171 offset_target_and_file_id(db, f)?
173 } 172 }
174 hir::ModuleDef::Adt(adt) => { 173 hir::ModuleDef::Adt(adt) => {
175 target_name = Some(adt.name(db)); 174 target_name = Some(adt.name(db));
176 match adt { 175 match adt {
177 hir::Adt::Struct(s) => offset_target_and_file_id(db, s), 176 hir::Adt::Struct(s) => offset_target_and_file_id(db, s)?,
178 hir::Adt::Union(u) => offset_target_and_file_id(db, u), 177 hir::Adt::Union(u) => offset_target_and_file_id(db, u)?,
179 hir::Adt::Enum(e) => offset_target_and_file_id(db, e), 178 hir::Adt::Enum(e) => offset_target_and_file_id(db, e)?,
180 } 179 }
181 } 180 }
182 hir::ModuleDef::Const(c) => { 181 hir::ModuleDef::Const(c) => {
183 target_name = c.name(db); 182 target_name = c.name(db);
184 offset_target_and_file_id(db, c) 183 offset_target_and_file_id(db, c)?
185 } 184 }
186 hir::ModuleDef::Static(s) => { 185 hir::ModuleDef::Static(s) => {
187 target_name = s.name(db); 186 target_name = s.name(db);
188 offset_target_and_file_id(db, s) 187 offset_target_and_file_id(db, s)?
189 } 188 }
190 hir::ModuleDef::Trait(t) => { 189 hir::ModuleDef::Trait(t) => {
191 target_name = Some(t.name(db)); 190 target_name = Some(t.name(db));
192 offset_target_and_file_id(db, t) 191 offset_target_and_file_id(db, t)?
193 } 192 }
194 hir::ModuleDef::TypeAlias(t) => { 193 hir::ModuleDef::TypeAlias(t) => {
195 target_name = Some(t.name(db)); 194 target_name = Some(t.name(db));
196 offset_target_and_file_id(db, t) 195 offset_target_and_file_id(db, t)?
197 } 196 }
198 hir::ModuleDef::Module(m) => { 197 hir::ModuleDef::Module(m) => {
199 target_name = m.name(db); 198 target_name = m.name(db);