From 742147dacd0834dd955617216655a6e7c1822b89 Mon Sep 17 00:00:00 2001 From: Undxxx <32825301+Undxxx@users.noreply.github.com> Date: Sun, 28 Mar 2021 15:47:08 +0800 Subject: [PATCH 1/3] Update rustc-driver-interacting-with-the-ast.rs remove the unused fields and change unknown field --- examples/rustc-driver-interacting-with-the-ast.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/rustc-driver-interacting-with-the-ast.rs b/examples/rustc-driver-interacting-with-the-ast.rs index 8ee38206f..6337fc762 100644 --- a/examples/rustc-driver-interacting-with-the-ast.rs +++ b/examples/rustc-driver-interacting-with-the-ast.rs @@ -15,8 +15,8 @@ extern crate rustc_span; use rustc_ast_pretty::pprust::item_to_string; use rustc_errors::registry; use rustc_session::config; -use rustc_session::config::PpMode::PpmSource; -use rustc_session::config::PpSourceMode::PpmExpanded; +//use rustc_session::config::PpMode::PpmSource; +//use rustc_session::config::PpSourceMode::PpmExpanded; use rustc_span::source_map; use std::path; use std::process; @@ -46,7 +46,7 @@ fn main() { output_file: None, file_loader: None, stderr: None, - crate_name: None, + //crate_name: None, lint_caps: rustc_hash::FxHashMap::default(), register_lints: None, override_queries: None, @@ -57,8 +57,8 @@ fn main() { compiler.enter(|queries| { // TODO: add this to -Z unpretty let ast_krate = queries.parse().unwrap().take(); - let ast_krate_mod = ast_krate.module; - for item in ast_krate_mod.items { + //let ast_krate_mod = ast_krate.module; + for item in ast_krate.items { println!("{}", item_to_string(&item)); } From 81fa28ebcb7011ae9b3a57a89d1c69f2b74e547a Mon Sep 17 00:00:00 2001 From: Undxxx <32825301+Undxxx@users.noreply.github.com> Date: Sun, 28 Mar 2021 16:37:48 +0800 Subject: [PATCH 2/3] modify example to run with recent nightly --- examples/rustc-driver-example.rs | 6 ++++-- examples/rustc-driver-getting-diagnostics.rs | 4 +++- examples/rustc-driver-interacting-with-the-ast.rs | 8 +++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/rustc-driver-example.rs b/examples/rustc-driver-example.rs index f01072b7b..8da9910c5 100644 --- a/examples/rustc-driver-example.rs +++ b/examples/rustc-driver-example.rs @@ -3,6 +3,8 @@ // NOTE: For the example to compile, you will need to first run the following: // rustup component add rustc-dev +// version: rustc 1.52.0-nightly 2021-03-05 + extern crate rustc_error_codes; extern crate rustc_errors; extern crate rustc_hash; @@ -46,7 +48,6 @@ fn main() { diagnostic_output: rustc_session::DiagnosticOutput::Default, // Set to capture stderr output during compiler execution stderr: None, // Option>>> - crate_name: None, // Option lint_caps: FxHashMap::default(), // FxHashMap // This is a callback from the driver that is called when we're registering lints; // it is called during plugin registration when we have the LintStore in a non-shared state. @@ -61,6 +62,7 @@ fn main() { override_queries: None, // Option, &mut ty::query::Providers<'_>)> // Registry of diagnostics codes. registry: registry::Registry::new(&rustc_error_codes::DIAGNOSTICS), + make_codegen_backend: None, }; rustc_interface::run_compiler(config, |compiler| { compiler.enter(|queries| { @@ -73,7 +75,7 @@ fn main() { match item.kind { rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn(_, _, _) => { let name = item.ident; - let ty = tcx.type_of(tcx.hir().local_def_id(item.hir_id)); + let ty = tcx.type_of(tcx.hir().local_def_id(item.hir_id())); println!("{:?}:\t{:?}", name, ty) } _ => (), diff --git a/examples/rustc-driver-getting-diagnostics.rs b/examples/rustc-driver-getting-diagnostics.rs index e1caab326..0d12abc42 100644 --- a/examples/rustc-driver-getting-diagnostics.rs +++ b/examples/rustc-driver-getting-diagnostics.rs @@ -3,6 +3,8 @@ // NOTE: For the example to compile, you will need to first run the following: // rustup component add rustc-dev +// version: rustc 1.52.0-nightly 2021-03-05 + extern crate rustc_error_codes; extern crate rustc_errors; extern crate rustc_hash; @@ -68,11 +70,11 @@ fn main() { output_file: None, file_loader: None, stderr: None, - crate_name: None, lint_caps: rustc_hash::FxHashMap::default(), register_lints: None, override_queries: None, registry: registry::Registry::new(&rustc_error_codes::DIAGNOSTICS), + make_codegen_backend: None, }; rustc_interface::run_compiler(config, |compiler| { compiler.enter(|queries| { diff --git a/examples/rustc-driver-interacting-with-the-ast.rs b/examples/rustc-driver-interacting-with-the-ast.rs index 6337fc762..13b0519d3 100644 --- a/examples/rustc-driver-interacting-with-the-ast.rs +++ b/examples/rustc-driver-interacting-with-the-ast.rs @@ -3,6 +3,8 @@ // NOTE: For the example to compile, you will need to first run the following: // rustup component add rustc-dev llvm-tools-preview +// version: rustc 1.52.0-nightly 2021-03-05 + extern crate rustc_ast_pretty; extern crate rustc_error_codes; extern crate rustc_errors; @@ -15,8 +17,6 @@ extern crate rustc_span; use rustc_ast_pretty::pprust::item_to_string; use rustc_errors::registry; use rustc_session::config; -//use rustc_session::config::PpMode::PpmSource; -//use rustc_session::config::PpSourceMode::PpmExpanded; use rustc_span::source_map; use std::path; use std::process; @@ -46,7 +46,6 @@ fn main() { output_file: None, file_loader: None, stderr: None, - //crate_name: None, lint_caps: rustc_hash::FxHashMap::default(), register_lints: None, override_queries: None, @@ -57,7 +56,6 @@ fn main() { compiler.enter(|queries| { // TODO: add this to -Z unpretty let ast_krate = queries.parse().unwrap().take(); - //let ast_krate_mod = ast_krate.module; for item in ast_krate.items { println!("{}", item_to_string(&item)); } @@ -75,7 +73,7 @@ fn main() { if let rustc_hir::StmtKind::Local(local) = block.stmts[0].kind { if let Some(expr) = local.init { let hir_id = expr.hir_id; // hir_id identifies the string "Hello, world!" - let def_id = tcx.hir().local_def_id(item.hir_id); // def_id identifies the main function + let def_id = tcx.hir().local_def_id(item.hir_id()); // def_id identifies the main function let ty = tcx.typeck(def_id).node_type(hir_id); println!("{:?}: {:?}", expr, ty); // prints expr(HirId { owner: DefIndex(3), local_id: 4 }: "Hello, world!"): &'static str } From 4f71263786d89e52df70e5fe88d9936d9683baf6 Mon Sep 17 00:00:00 2001 From: Undxxx <32825301+Undxxx@users.noreply.github.com> Date: Sun, 28 Mar 2021 17:29:50 +0800 Subject: [PATCH 3/3] use the latest nightly version --- examples/rustc-driver-example.rs | 4 +++- examples/rustc-driver-getting-diagnostics.rs | 3 ++- examples/rustc-driver-interacting-with-the-ast.rs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/rustc-driver-example.rs b/examples/rustc-driver-example.rs index 8da9910c5..51af6f5aa 100644 --- a/examples/rustc-driver-example.rs +++ b/examples/rustc-driver-example.rs @@ -3,7 +3,7 @@ // NOTE: For the example to compile, you will need to first run the following: // rustup component add rustc-dev -// version: rustc 1.52.0-nightly 2021-03-05 +// version: 1.53.0-nightly (9b0edb7fd 2021-03-27) extern crate rustc_error_codes; extern crate rustc_errors; @@ -49,6 +49,8 @@ fn main() { // Set to capture stderr output during compiler execution stderr: None, // Option>>> lint_caps: FxHashMap::default(), // FxHashMap + // This is a callback from the driver that is called when [`ParseSess`] is created. + parse_sess_created: None, //Option> // This is a callback from the driver that is called when we're registering lints; // it is called during plugin registration when we have the LintStore in a non-shared state. // diff --git a/examples/rustc-driver-getting-diagnostics.rs b/examples/rustc-driver-getting-diagnostics.rs index 0d12abc42..ee9a20c05 100644 --- a/examples/rustc-driver-getting-diagnostics.rs +++ b/examples/rustc-driver-getting-diagnostics.rs @@ -3,7 +3,7 @@ // NOTE: For the example to compile, you will need to first run the following: // rustup component add rustc-dev -// version: rustc 1.52.0-nightly 2021-03-05 +// version: 1.53.0-nightly (9b0edb7fd 2021-03-27) extern crate rustc_error_codes; extern crate rustc_errors; @@ -71,6 +71,7 @@ fn main() { file_loader: None, stderr: None, lint_caps: rustc_hash::FxHashMap::default(), + parse_sess_created: None, register_lints: None, override_queries: None, registry: registry::Registry::new(&rustc_error_codes::DIAGNOSTICS), diff --git a/examples/rustc-driver-interacting-with-the-ast.rs b/examples/rustc-driver-interacting-with-the-ast.rs index 13b0519d3..2c7533498 100644 --- a/examples/rustc-driver-interacting-with-the-ast.rs +++ b/examples/rustc-driver-interacting-with-the-ast.rs @@ -3,7 +3,7 @@ // NOTE: For the example to compile, you will need to first run the following: // rustup component add rustc-dev llvm-tools-preview -// version: rustc 1.52.0-nightly 2021-03-05 +// version: 1.53.0-nightly (9b0edb7fd 2021-03-27) extern crate rustc_ast_pretty; extern crate rustc_error_codes; @@ -47,6 +47,7 @@ fn main() { file_loader: None, stderr: None, lint_caps: rustc_hash::FxHashMap::default(), + parse_sess_created: None, register_lints: None, override_queries: None, make_codegen_backend: None,