aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/body/tests.rs2
-rw-r--r--crates/hir_def/src/nameres/tests/diagnostics.rs2
-rw-r--r--crates/hir_expand/src/builtin_macro.rs21
3 files changed, 13 insertions, 12 deletions
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs
index f8e6f70e8..faa133297 100644
--- a/crates/hir_def/src/body/tests.rs
+++ b/crates/hir_def/src/body/tests.rs
@@ -137,7 +137,7 @@ fn f() {
137 include!(invalid); 137 include!(invalid);
138 //^^^^^^^^^^^^^^^^^ could not convert tokens 138 //^^^^^^^^^^^^^^^^^ could not convert tokens
139 include!("does not exist"); 139 include!("does not exist");
140 //^^^^^^^^^^^^^^^^^^^^^^^^^^ could not convert tokens 140 //^^^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `does not exist`
141 141
142 env!(invalid); 142 env!(invalid);
143 //^^^^^^^^^^^^^ could not convert tokens 143 //^^^^^^^^^^^^^ could not convert tokens
diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs
index 6becd9ff1..a89061c2e 100644
--- a/crates/hir_def/src/nameres/tests/diagnostics.rs
+++ b/crates/hir_def/src/nameres/tests/diagnostics.rs
@@ -196,7 +196,7 @@ fn builtin_macro_fails_expansion() {
196 macro_rules! include { () => {} } 196 macro_rules! include { () => {} }
197 197
198 include!("doesntexist"); 198 include!("doesntexist");
199 //^^^^^^^^^^^^^^^^^^^^^^^^ could not convert tokens 199 //^^^^^^^^^^^^^^^^^^^^^^^^ failed to load file `doesntexist`
200 "#, 200 "#,
201 ); 201 );
202} 202}
diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs
index 2a79c892b..fce09a9e7 100644
--- a/crates/hir_expand/src/builtin_macro.rs
+++ b/crates/hir_expand/src/builtin_macro.rs
@@ -333,17 +333,19 @@ fn concat_expand(
333fn relative_file( 333fn relative_file(
334 db: &dyn AstDatabase, 334 db: &dyn AstDatabase,
335 call_id: MacroCallId, 335 call_id: MacroCallId,
336 path: &str, 336 path_str: &str,
337 allow_recursion: bool, 337 allow_recursion: bool,
338) -> Option<FileId> { 338) -> Result<FileId, mbe::ExpandError> {
339 let call_site = call_id.as_file().original_file(db); 339 let call_site = call_id.as_file().original_file(db);
340 let path = AnchoredPath { anchor: call_site, path }; 340 let path = AnchoredPath { anchor: call_site, path: path_str };
341 let res = db.resolve_path(path)?; 341 let res = db
342 .resolve_path(path)
343 .ok_or_else(|| mbe::ExpandError::Other(format!("failed to load file `{}`", path_str)))?;
342 // Prevent include itself 344 // Prevent include itself
343 if res == call_site && !allow_recursion { 345 if res == call_site && !allow_recursion {
344 None 346 Err(mbe::ExpandError::Other(format!("recursive inclusion of `{}`", path_str)))
345 } else { 347 } else {
346 Some(res) 348 Ok(res)
347 } 349 }
348} 350}
349 351
@@ -364,8 +366,7 @@ fn include_expand(
364) -> ExpandResult<Option<(tt::Subtree, FragmentKind)>> { 366) -> ExpandResult<Option<(tt::Subtree, FragmentKind)>> {
365 let res = (|| { 367 let res = (|| {
366 let path = parse_string(tt)?; 368 let path = parse_string(tt)?;
367 let file_id = relative_file(db, arg_id.into(), &path, false) 369 let file_id = relative_file(db, arg_id.into(), &path, false)?;
368 .ok_or_else(|| mbe::ExpandError::ConversionError)?;
369 370
370 Ok(parse_to_token_tree(&db.file_text(file_id)) 371 Ok(parse_to_token_tree(&db.file_text(file_id))
371 .ok_or_else(|| mbe::ExpandError::ConversionError)? 372 .ok_or_else(|| mbe::ExpandError::ConversionError)?
@@ -417,8 +418,8 @@ fn include_str_expand(
417 // Ideally, we'd be able to offer a precise expansion if the user asks for macro 418 // Ideally, we'd be able to offer a precise expansion if the user asks for macro
418 // expansion. 419 // expansion.
419 let file_id = match relative_file(db, arg_id.into(), &path, true) { 420 let file_id = match relative_file(db, arg_id.into(), &path, true) {
420 Some(file_id) => file_id, 421 Ok(file_id) => file_id,
421 None => { 422 Err(_) => {
422 return ExpandResult::ok(Some((quote!(""), FragmentKind::Expr))); 423 return ExpandResult::ok(Some((quote!(""), FragmentKind::Expr)));
423 } 424 }
424 }; 425 };