about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src/source_util.rs
diff options
context:
space:
mode:
authorridwanabdillahi <91507758+ridwanabdillahi@users.noreply.github.com>2022-04-25 18:02:43 -0700
committerridwanabdillahi <91507758+ridwanabdillahi@users.noreply.github.com>2022-05-03 10:53:54 -0700
commit175a4eab84379cebfc230ea357ae02dc9be39660 (patch)
tree19f4ae4b9b91cb53e6ee05368127daa4fbc88d33 /compiler/rustc_builtin_macros/src/source_util.rs
parente1df625306f4136949e02612406f0c60df6008f3 (diff)
downloadrust-175a4eab84379cebfc230ea357ae02dc9be39660.tar.gz
rust-175a4eab84379cebfc230ea357ae02dc9be39660.zip
Add support for a new attribute `#[debugger_visualizer]` to support embedding debugger visualizers into a generated PDB.
Cleanup `DebuggerVisualizerFile` type and other minor cleanup of queries.

Merge the queries for debugger visualizers into a single query.

Revert move of `resolve_path` to `rustc_builtin_macros`. Update dependencies in Cargo.toml for `rustc_passes`.

Respond to PR comments. Load visualizer files into opaque bytes `Vec<u8>`. Debugger visualizers for dynamically linked crates should not be embedded in the current crate.

Update the unstable book with the new feature. Add the tracking issue for the debugger_visualizer feature.

Respond to PR comments and minor cleanups.
Diffstat (limited to 'compiler/rustc_builtin_macros/src/source_util.rs')
-rw-r--r--compiler/rustc_builtin_macros/src/source_util.rs47
1 files changed, 4 insertions, 43 deletions
diff --git a/compiler/rustc_builtin_macros/src/source_util.rs b/compiler/rustc_builtin_macros/src/source_util.rs
index 2817fce463b..8bf3a0799b6 100644
--- a/compiler/rustc_builtin_macros/src/source_util.rs
+++ b/compiler/rustc_builtin_macros/src/source_util.rs
@@ -3,17 +3,15 @@ use rustc_ast::ptr::P;
 use rustc_ast::token;
 use rustc_ast::tokenstream::TokenStream;
 use rustc_ast_pretty::pprust;
-use rustc_errors::PResult;
 use rustc_expand::base::{self, *};
 use rustc_expand::module::DirOwnership;
 use rustc_parse::parser::{ForceCollect, Parser};
 use rustc_parse::{self, new_parser_from_file};
 use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
 use rustc_span::symbol::Symbol;
-use rustc_span::{self, FileName, Pos, Span};
+use rustc_span::{self, Pos, Span};
 
 use smallvec::SmallVec;
-use std::path::PathBuf;
 use std::rc::Rc;
 
 // These macros all relate to the file system; they either return
@@ -104,7 +102,7 @@ pub fn expand_include<'cx>(
         return DummyResult::any(sp);
     };
     // The file will be added to the code map by the parser
-    let file = match resolve_path(cx, file.as_str(), sp) {
+    let file = match resolve_path(&cx.sess.parse_sess, file.as_str(), sp) {
         Ok(f) => f,
         Err(mut err) => {
             err.emit();
@@ -176,7 +174,7 @@ pub fn expand_include_str(
     let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_str!") else {
         return DummyResult::any(sp);
     };
-    let file = match resolve_path(cx, file.as_str(), sp) {
+    let file = match resolve_path(&cx.sess.parse_sess, file.as_str(), sp) {
         Ok(f) => f,
         Err(mut err) => {
             err.emit();
@@ -210,7 +208,7 @@ pub fn expand_include_bytes(
     let Some(file) = get_single_str_from_tts(cx, sp, tts, "include_bytes!") else {
         return DummyResult::any(sp);
     };
-    let file = match resolve_path(cx, file.as_str(), sp) {
+    let file = match resolve_path(&cx.sess.parse_sess, file.as_str(), sp) {
         Ok(f) => f,
         Err(mut err) => {
             err.emit();
@@ -225,40 +223,3 @@ pub fn expand_include_bytes(
         }
     }
 }
-
-/// Resolves a `path` mentioned inside Rust code, returning an absolute path.
-///
-/// This unifies the logic used for resolving `include_X!`.
-fn resolve_path<'a>(
-    cx: &mut ExtCtxt<'a>,
-    path: impl Into<PathBuf>,
-    span: Span,
-) -> PResult<'a, PathBuf> {
-    let path = path.into();
-
-    // Relative paths are resolved relative to the file in which they are found
-    // after macro expansion (that is, they are unhygienic).
-    if !path.is_absolute() {
-        let callsite = span.source_callsite();
-        let mut result = match cx.source_map().span_to_filename(callsite) {
-            FileName::Real(name) => name
-                .into_local_path()
-                .expect("attempting to resolve a file path in an external file"),
-            FileName::DocTest(path, _) => path,
-            other => {
-                return Err(cx.struct_span_err(
-                    span,
-                    &format!(
-                        "cannot resolve relative path in non-file source `{}`",
-                        cx.source_map().filename_for_diagnostics(&other)
-                    ),
-                ));
-            }
-        };
-        result.pop();
-        result.push(path);
-        Ok(result)
-    } else {
-        Ok(path)
-    }
-}