From db97c48ad6e7f36468b152e9b08efc6f2f7da691 Mon Sep 17 00:00:00 2001 From: Mark Simulacrum Date: Fri, 1 Jun 2018 16:40:33 -0600 Subject: [PATCH] Remove quote_*! macros and associated APIs --- src/bootstrap/builder.rs | 3 - src/bootstrap/mk/Makefile.in | 1 - src/bootstrap/test.rs | 20 - .../src/language-features/plugin.md | 3 +- src/librustc/lib.rs | 1 - src/librustc_borrowck/lib.rs | 1 - src/librustc_codegen_llvm/lib.rs | 1 - src/librustc_codegen_ssa/lib.rs | 1 - src/librustc_codegen_utils/lib.rs | 1 - src/librustc_driver/driver.rs | 2 +- src/librustc_driver/lib.rs | 1 - src/librustc_lint/lib.rs | 1 - src/librustc_metadata/lib.rs | 1 - src/librustc_typeck/lib.rs | 1 - src/libsyntax/ext/quote.rs | 893 ------------------ src/libsyntax/feature_gate.rs | 2 +- src/libsyntax/lib.rs | 1 - src/libsyntax/parse/mod.rs | 39 +- src/libsyntax/parse/parser.rs | 3 - src/libsyntax/util/parser_testing.rs | 2 +- src/libsyntax_ext/lib.rs | 22 +- src/test/run-fail-fulldeps/qquote.rs | 35 - .../auxiliary/issue-16723.rs | 29 - .../auxiliary/macro_crate_test.rs | 223 +---- .../auxiliary/plugin_with_plugin_lib.rs | 13 - .../auxiliary/procedural_mbe_matching.rs | 82 -- .../syntax_extension_with_dll_deps_2.rs | 27 - src/test/run-pass-fulldeps/issue-16723.rs | 19 - src/test/run-pass-fulldeps/issue-16992.rs | 15 - .../issue-18763-quote-token-tree.rs | 22 - .../macro-crate-does-hygiene-work.rs | 16 - .../macro-crate-multi-decorator-literals.rs | 50 - .../macro-crate-multi-decorator.rs | 4 +- src/test/run-pass-fulldeps/macro-crate.rs | 46 - .../mbe_matching_test_macro.rs | 11 - .../plugin-lib-ok-in-plugin.rs | 16 - .../plugin-plus-extern-crate.rs | 17 - src/test/run-pass-fulldeps/qquote.rs | 92 -- src/test/run-pass-fulldeps/quote-tokens.rs | 45 - .../quote-unused-sp-no-warning.rs | 15 - .../syntax-extension-with-dll-deps.rs | 10 - .../ui-fulldeps/auxiliary/macro_crate_test.rs | 149 --- src/test/ui-fulldeps/gated-plugin.rs | 4 +- src/test/ui-fulldeps/gated-plugin.stderr | 2 +- src/test/ui-fulldeps/gated-quote.rs | 57 -- src/test/ui-fulldeps/gated-quote.stderr | 80 -- src/test/ui-fulldeps/issue-48941.rs | 16 - src/test/ui-fulldeps/issue-48941.stderr | 14 - .../ui-fulldeps/macro-crate-doesnt-resolve.rs | 8 - .../macro-crate-doesnt-resolve.stderr | 9 - .../macro-crate-unexported-macro.rs | 9 - .../macro-crate-unexported-macro.stderr | 8 - .../ui-fulldeps/plugin-as-extern-crate.rs | 6 +- .../ui-fulldeps/plugin-as-extern-crate.stderr | 2 +- .../ui-fulldeps/plugin-plus-extern-crate.rs | 17 - .../plugin-plus-extern-crate.stderr | 14 - src/test/ui-fulldeps/qquote.rs | 27 - src/test/ui-fulldeps/qquote.stderr | 9 - src/test/ui/quote-with-interpolated.rs | 14 - src/test/ui/quote-with-interpolated.stderr | 40 - 60 files changed, 55 insertions(+), 2217 deletions(-) delete mode 100644 src/libsyntax/ext/quote.rs delete mode 100644 src/test/run-fail-fulldeps/qquote.rs delete mode 100644 src/test/run-pass-fulldeps/auxiliary/issue-16723.rs delete mode 100644 src/test/run-pass-fulldeps/auxiliary/plugin_with_plugin_lib.rs delete mode 100644 src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs delete mode 100644 src/test/run-pass-fulldeps/auxiliary/syntax_extension_with_dll_deps_2.rs delete mode 100644 src/test/run-pass-fulldeps/issue-16723.rs delete mode 100644 src/test/run-pass-fulldeps/issue-16992.rs delete mode 100644 src/test/run-pass-fulldeps/issue-18763-quote-token-tree.rs delete mode 100644 src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs delete mode 100644 src/test/run-pass-fulldeps/macro-crate-multi-decorator-literals.rs delete mode 100644 src/test/run-pass-fulldeps/macro-crate.rs delete mode 100644 src/test/run-pass-fulldeps/mbe_matching_test_macro.rs delete mode 100644 src/test/run-pass-fulldeps/plugin-lib-ok-in-plugin.rs delete mode 100644 src/test/run-pass-fulldeps/plugin-plus-extern-crate.rs delete mode 100644 src/test/run-pass-fulldeps/qquote.rs delete mode 100644 src/test/run-pass-fulldeps/quote-tokens.rs delete mode 100644 src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs delete mode 100644 src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs delete mode 100644 src/test/ui-fulldeps/auxiliary/macro_crate_test.rs delete mode 100644 src/test/ui-fulldeps/gated-quote.rs delete mode 100644 src/test/ui-fulldeps/gated-quote.stderr delete mode 100644 src/test/ui-fulldeps/issue-48941.rs delete mode 100644 src/test/ui-fulldeps/issue-48941.stderr delete mode 100644 src/test/ui-fulldeps/macro-crate-doesnt-resolve.rs delete mode 100644 src/test/ui-fulldeps/macro-crate-doesnt-resolve.stderr delete mode 100644 src/test/ui-fulldeps/macro-crate-unexported-macro.rs delete mode 100644 src/test/ui-fulldeps/macro-crate-unexported-macro.stderr delete mode 100644 src/test/ui-fulldeps/plugin-plus-extern-crate.rs delete mode 100644 src/test/ui-fulldeps/plugin-plus-extern-crate.stderr delete mode 100644 src/test/ui-fulldeps/qquote.rs delete mode 100644 src/test/ui-fulldeps/qquote.stderr delete mode 100644 src/test/ui/quote-with-interpolated.rs delete mode 100644 src/test/ui/quote-with-interpolated.stderr diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 31adab64f60..c3dc9458839 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -378,14 +378,11 @@ impl<'a> Builder<'a> { test::Debuginfo, test::UiFullDeps, test::RunPassFullDeps, - test::RunFailFullDeps, test::Rustdoc, test::Pretty, test::RunPassPretty, test::RunFailPretty, test::RunPassValgrindPretty, - test::RunPassFullDepsPretty, - test::RunFailFullDepsPretty, test::Crate, test::CrateLibrustc, test::CrateRustdoc, diff --git a/src/bootstrap/mk/Makefile.in b/src/bootstrap/mk/Makefile.in index 8ff1456f0f4..1c27cf3909b 100644 --- a/src/bootstrap/mk/Makefile.in +++ b/src/bootstrap/mk/Makefile.in @@ -53,7 +53,6 @@ check-aux: src/test/run-fail/pretty \ src/test/run-pass-valgrind/pretty \ src/test/run-pass-fulldeps/pretty \ - src/test/run-fail-fulldeps/pretty \ $(AUX_ARGS) \ $(BOOTSTRAP_ARGS) check-bootstrap: diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 2edc78ebaa9..216649808e2 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -848,12 +848,6 @@ host_test!(RunPassFullDeps { suite: "run-pass-fulldeps" }); -host_test!(RunFailFullDeps { - path: "src/test/run-fail-fulldeps", - mode: "run-fail", - suite: "run-fail-fulldeps" -}); - host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", @@ -888,20 +882,6 @@ test!(RunPassValgrindPretty { default: false, host: true }); -test!(RunPassFullDepsPretty { - path: "src/test/run-pass-fulldeps/pretty", - mode: "pretty", - suite: "run-pass-fulldeps", - default: false, - host: true -}); -test!(RunFailFullDepsPretty { - path: "src/test/run-fail-fulldeps/pretty", - mode: "pretty", - suite: "run-fail-fulldeps", - default: false, - host: true -}); default_test!(RunMake { path: "src/test/run-make", diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md index 03ea392c863..cab350381d2 100644 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ b/src/doc/unstable-book/src/language-features/plugin.md @@ -52,6 +52,7 @@ that implements Roman numeral integer literals. #![feature(plugin_registrar, rustc_private)] extern crate syntax; +extern crate syntax_pos; extern crate rustc; extern crate rustc_plugin; @@ -59,7 +60,7 @@ use syntax::parse::token; use syntax::tokenstream::TokenTree; use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager}; use syntax::ext::build::AstBuilder; // A trait for expr_usize. -use syntax::ext::quote::rt::Span; +use syntax_pos::Span; use rustc_plugin::Registry; fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree]) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index fba9b852767..7ecec0b9a69 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -41,7 +41,6 @@ #![feature(nll)] #![feature(non_exhaustive)] #![feature(proc_macro_internals)] -#![feature(quote)] #![feature(optin_builtin_traits)] #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] diff --git a/src/librustc_borrowck/lib.rs b/src/librustc_borrowck/lib.rs index 14e0381dad1..8bdc4e1d5c1 100644 --- a/src/librustc_borrowck/lib.rs +++ b/src/librustc_borrowck/lib.rs @@ -5,7 +5,6 @@ #![allow(non_camel_case_types)] #![feature(nll)] -#![feature(quote)] #![recursion_limit="256"] diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index 272f34b0b3f..a88b1a8f52e 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -17,7 +17,6 @@ #![allow(unused_attributes)] #![feature(libc)] #![feature(nll)] -#![feature(quote)] #![feature(range_contains)] #![feature(rustc_diagnostic_macros)] #![feature(slice_sort_by_cached_key)] diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index d47bd23766f..1accbeb2aa8 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -12,7 +12,6 @@ #![feature(nll)] #![allow(unused_attributes)] #![allow(dead_code)] -#![feature(quote)] #![recursion_limit="256"] diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs index 5f61852178d..1f590d46ed8 100644 --- a/src/librustc_codegen_utils/lib.rs +++ b/src/librustc_codegen_utils/lib.rs @@ -11,7 +11,6 @@ #![feature(custom_attribute)] #![feature(nll)] #![allow(unused_attributes)] -#![feature(quote)] #![feature(rustc_diagnostic_macros)] #![recursion_limit="256"] diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index d23d8b829c0..142d60c8d00 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -916,7 +916,7 @@ where crate_loader, &resolver_arenas, ); - syntax_ext::register_builtins(&mut resolver, syntax_exts, sess.features_untracked().quote); + syntax_ext::register_builtins(&mut resolver, syntax_exts); // Expand all macros sess.profiler(|p| p.start_activity(ProfileCategory::Expansion)); diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index c8a5bbe8315..abcdf175ada 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -11,7 +11,6 @@ #![feature(box_syntax)] #![cfg_attr(unix, feature(libc))] #![feature(nll)] -#![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(slice_sort_by_cached_key)] #![feature(set_stdio)] diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 71c859d8dbe..d3d17184a01 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -17,7 +17,6 @@ #![feature(box_patterns)] #![feature(box_syntax)] #![feature(nll)] -#![feature(quote)] #![feature(rustc_diagnostic_macros)] #![recursion_limit="256"] diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index d38562c93f8..1a661421240 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -7,7 +7,6 @@ #![feature(nll)] #![feature(proc_macro_internals)] #![feature(proc_macro_quote)] -#![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(slice_sort_by_cached_key)] #![feature(crate_visibility_modifier)] diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 6c1c49bda4c..5149f460bac 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -66,7 +66,6 @@ This API is completely unstable and subject to change. #![feature(crate_visibility_modifier)] #![feature(exhaustive_patterns)] #![feature(nll)] -#![feature(quote)] #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] #![feature(slice_patterns)] diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs deleted file mode 100644 index df3b49cf6ed..00000000000 --- a/src/libsyntax/ext/quote.rs +++ /dev/null @@ -1,893 +0,0 @@ -use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Stmt, Ty}; -use source_map::respan; -use syntax_pos::{Span, DUMMY_SP}; -use ext::base::ExtCtxt; -use ext::base; -use ext::build::AstBuilder; -use parse::parser::{Parser, PathStyle}; -use parse::token; -use ptr::P; -use tokenstream::{DelimSpan, TokenStream, TokenTree}; - -/// Quasiquoting works via token trees. -/// -/// This is registered as a set of expression syntax extension called quote! -/// that lifts its argument token-tree to an AST representing the -/// construction of the same token tree, with `token::SubstNt` interpreted -/// as antiquotes (splices). - -pub mod rt { - use ast; - use source_map::Spanned; - use ext::base::ExtCtxt; - use parse::{self, classify}; - use parse::token::{self, Token}; - use ptr::P; - use symbol::Symbol; - use ThinVec; - - use tokenstream::{DelimSpan, TokenTree, TokenStream}; - - pub use parse::new_parser_from_tts; - pub use syntax_pos::{BytePos, Span, DUMMY_SP, FileName}; - pub use source_map::{dummy_spanned}; - - pub trait ToTokens { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec; - } - - impl ToTokens for TokenTree { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - vec![self.clone()] - } - } - - impl ToTokens for Vec { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - self.iter().flat_map(|t| t.to_tokens(cx)).collect() - } - } - - impl ToTokens for Spanned { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - // FIXME: use the span? - self.node.to_tokens(cx) - } - } - - impl ToTokens for Option { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - match *self { - Some(ref t) => t.to_tokens(cx), - None => Vec::new(), - } - } - } - - impl ToTokens for ast::Ident { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - vec![TokenTree::Token(self.span, Token::from_ast_ident(*self))] - } - } - - impl ToTokens for ast::Path { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtPath(self.clone()); - vec![TokenTree::Token(DUMMY_SP, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::Ty { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtTy(P(self.clone())); - vec![TokenTree::Token(self.span, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::Block { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtBlock(P(self.clone())); - vec![TokenTree::Token(self.span, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::Generics { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtGenerics(self.clone()); - vec![TokenTree::Token(DUMMY_SP, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::WhereClause { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtWhereClause(self.clone()); - vec![TokenTree::Token(DUMMY_SP, Token::interpolated(nt))] - } - } - - impl ToTokens for P { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtItem(self.clone()); - vec![TokenTree::Token(self.span, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::ImplItem { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtImplItem(self.clone()); - vec![TokenTree::Token(self.span, Token::interpolated(nt))] - } - } - - impl ToTokens for P { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtImplItem((**self).clone()); - vec![TokenTree::Token(self.span, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::TraitItem { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtTraitItem(self.clone()); - vec![TokenTree::Token(self.span, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::Stmt { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtStmt(self.clone()); - let mut tts = vec![TokenTree::Token(self.span, Token::interpolated(nt))]; - - // Some statements require a trailing semicolon. - if classify::stmt_ends_with_semi(&self.node) { - tts.push(TokenTree::Token(self.span, token::Semi)); - } - - tts - } - } - - impl ToTokens for P { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtExpr(self.clone()); - vec![TokenTree::Token(self.span, Token::interpolated(nt))] - } - } - - impl ToTokens for P { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtPat(self.clone()); - vec![TokenTree::Token(self.span, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::Arm { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtArm(self.clone()); - vec![TokenTree::Token(DUMMY_SP, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::Arg { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtArg(self.clone()); - vec![TokenTree::Token(DUMMY_SP, Token::interpolated(nt))] - } - } - - impl ToTokens for P { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtBlock(self.clone()); - vec![TokenTree::Token(DUMMY_SP, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::Lifetime { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - vec![TokenTree::Token(self.ident.span, token::Lifetime(self.ident))] - } - } - - macro_rules! impl_to_tokens_slice { - ($t: ty, $sep: expr) => { - impl ToTokens for [$t] { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - let mut v = vec![]; - for (i, x) in self.iter().enumerate() { - if i > 0 { - v.extend_from_slice(&$sep); - } - v.extend(x.to_tokens(cx)); - } - v - } - } - }; - } - - impl_to_tokens_slice! { ast::Ty, [TokenTree::Token(DUMMY_SP, token::Comma)] } - impl_to_tokens_slice! { P, [] } - impl_to_tokens_slice! { ast::Arg, [TokenTree::Token(DUMMY_SP, token::Comma)] } - - impl ToTokens for ast::MetaItem { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let nt = token::NtMeta(self.clone()); - vec![TokenTree::Token(DUMMY_SP, Token::interpolated(nt))] - } - } - - impl ToTokens for ast::Attribute { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - let mut r = vec![]; - // FIXME: The spans could be better - r.push(TokenTree::Token(self.span, token::Pound)); - if self.style == ast::AttrStyle::Inner { - r.push(TokenTree::Token(self.span, token::Not)); - } - let mut inner = Vec::new(); - for (i, segment) in self.path.segments.iter().enumerate() { - if i > 0 { - inner.push(TokenTree::Token(self.span, token::Colon).into()); - } - inner.push(TokenTree::Token( - self.span, token::Token::from_ast_ident(segment.ident) - ).into()); - } - self.tokens.clone().append_to_tree_and_joint_vec(&mut inner); - - let delim_span = DelimSpan::from_single(self.span); - r.push(TokenTree::Delimited( - delim_span, token::Bracket, TokenStream::new(inner).into() - )); - r - } - } - - impl ToTokens for str { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - let lit = ast::LitKind::Str(Symbol::intern(self), ast::StrStyle::Cooked); - dummy_spanned(lit).to_tokens(cx) - } - } - - impl ToTokens for () { - fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - vec![ - TokenTree::Delimited(DelimSpan::dummy(), token::Paren, TokenStream::empty().into()) - ] - } - } - - impl ToTokens for ast::Lit { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - // FIXME: This is wrong - P(ast::Expr { - id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::Lit(self.clone()), - span: DUMMY_SP, - attrs: ThinVec::new(), - }).to_tokens(cx) - } - } - - impl ToTokens for bool { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - dummy_spanned(ast::LitKind::Bool(*self)).to_tokens(cx) - } - } - - impl ToTokens for char { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - dummy_spanned(ast::LitKind::Char(*self)).to_tokens(cx) - } - } - - macro_rules! impl_to_tokens_int { - (signed, $t:ty, $tag:expr) => ( - impl ToTokens for $t { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - let val = if *self < 0 { - -self - } else { - *self - }; - let lit = ast::LitKind::Int(val as u128, ast::LitIntType::Signed($tag)); - let lit = P(ast::Expr { - id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::Lit(dummy_spanned(lit)), - span: DUMMY_SP, - attrs: ThinVec::new(), - }); - if *self >= 0 { - return lit.to_tokens(cx); - } - P(ast::Expr { - id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::Unary(ast::UnOp::Neg, lit), - span: DUMMY_SP, - attrs: ThinVec::new(), - }).to_tokens(cx) - } - } - ); - (unsigned, $t:ty, $tag:expr) => ( - impl ToTokens for $t { - fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - let lit = ast::LitKind::Int(*self as u128, ast::LitIntType::Unsigned($tag)); - dummy_spanned(lit).to_tokens(cx) - } - } - ); - } - - impl_to_tokens_int! { signed, isize, ast::IntTy::Isize } - impl_to_tokens_int! { signed, i8, ast::IntTy::I8 } - impl_to_tokens_int! { signed, i16, ast::IntTy::I16 } - impl_to_tokens_int! { signed, i32, ast::IntTy::I32 } - impl_to_tokens_int! { signed, i64, ast::IntTy::I64 } - - impl_to_tokens_int! { unsigned, usize, ast::UintTy::Usize } - impl_to_tokens_int! { unsigned, u8, ast::UintTy::U8 } - impl_to_tokens_int! { unsigned, u16, ast::UintTy::U16 } - impl_to_tokens_int! { unsigned, u32, ast::UintTy::U32 } - impl_to_tokens_int! { unsigned, u64, ast::UintTy::U64 } - - pub trait ExtParseUtils { - fn parse_item(&self, s: String) -> P; - fn parse_expr(&self, s: String) -> P; - fn parse_stmt(&self, s: String) -> ast::Stmt; - fn parse_tts(&self, s: String) -> Vec; - } - - impl<'a> ExtParseUtils for ExtCtxt<'a> { - fn parse_item(&self, s: String) -> P { - panictry!(parse::parse_item_from_source_str( - FileName::quote_expansion_source_code(&s), - s, - self.parse_sess())).expect("parse error") - } - - fn parse_stmt(&self, s: String) -> ast::Stmt { - panictry!(parse::parse_stmt_from_source_str( - FileName::quote_expansion_source_code(&s), - s, - self.parse_sess())).expect("parse error") - } - - fn parse_expr(&self, s: String) -> P { - panictry!(parse::parse_expr_from_source_str( - FileName::quote_expansion_source_code(&s), - s, - self.parse_sess())) - } - - fn parse_tts(&self, s: String) -> Vec { - let source_name = FileName::quote_expansion_source_code(&s); - parse::parse_stream_from_source_str(source_name, s, self.parse_sess(), None) - .into_trees().collect() - } - } -} - -// Replaces `Token::OpenDelim .. Token::CloseDelim` with `TokenTree::Delimited(..)`. -pub fn unflatten(tts: Vec) -> Vec { - let mut results = Vec::new(); - let mut result = Vec::new(); - let mut open_span = DUMMY_SP; - for tree in tts { - match tree { - TokenTree::Token(span, token::OpenDelim(..)) => { - open_span = span; - results.push(::std::mem::replace(&mut result, Vec::new())); - } - TokenTree::Token(span, token::CloseDelim(delim)) => { - let delim_span = DelimSpan::from_pair(open_span, span); - let tree = TokenTree::Delimited( - delim_span, - delim, - result.into_iter().map(TokenStream::from).collect::().into(), - ); - result = results.pop().unwrap(); - result.push(tree); - } - tree => result.push(tree), - } - } - result -} - -// These panicking parsing functions are used by the quote_*!() syntax extensions, -// but shouldn't be used otherwise. -pub fn parse_expr_panic(parser: &mut Parser) -> P { - panictry!(parser.parse_expr()) -} - -pub fn parse_item_panic(parser: &mut Parser) -> Option> { - panictry!(parser.parse_item()) -} - -pub fn parse_pat_panic(parser: &mut Parser) -> P { - panictry!(parser.parse_pat(None)) -} - -pub fn parse_arm_panic(parser: &mut Parser) -> Arm { - panictry!(parser.parse_arm()) -} - -pub fn parse_ty_panic(parser: &mut Parser) -> P { - panictry!(parser.parse_ty()) -} - -pub fn parse_stmt_panic(parser: &mut Parser) -> Option { - panictry!(parser.parse_stmt()) -} - -pub fn parse_attribute_panic(parser: &mut Parser, permit_inner: bool) -> ast::Attribute { - panictry!(parser.parse_attribute(permit_inner)) -} - -pub fn parse_arg_panic(parser: &mut Parser) -> Arg { - panictry!(parser.parse_arg()) -} - -pub fn parse_block_panic(parser: &mut Parser) -> P { - panictry!(parser.parse_block()) -} - -pub fn parse_meta_item_panic(parser: &mut Parser) -> ast::MetaItem { - panictry!(parser.parse_meta_item()) -} - -pub fn parse_path_panic(parser: &mut Parser, mode: PathStyle) -> ast::Path { - panictry!(parser.parse_path(mode)) -} - -pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let (cx_expr, expr) = expand_tts(cx, sp, tts); - let expanded = expand_wrapper(cx, sp, cx_expr, expr, &[&["syntax", "ext", "quote", "rt"]]); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_expr_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_item<'cx>(cx: &'cx mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_item_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_pat<'cx>(cx: &'cx mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_pat_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_arm(cx: &mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_arm_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_ty(cx: &mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_ty_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_stmt(cx: &mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_stmt_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_attr(cx: &mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_attribute_panic", - vec![cx.expr_bool(sp, true)], tts); - - base::MacEager::expr(expanded) -} - -pub fn expand_quote_arg(cx: &mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_arg_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_block(cx: &mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_block_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_meta_item(cx: &mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let expanded = expand_parse_call(cx, sp, "parse_meta_item_panic", vec![], tts); - base::MacEager::expr(expanded) -} - -pub fn expand_quote_path(cx: &mut ExtCtxt, - sp: Span, - tts: &[TokenTree]) - -> Box { - let mode = mk_parser_path(cx, sp, &["PathStyle", "Type"]); - let expanded = expand_parse_call(cx, sp, "parse_path_panic", vec![mode], tts); - base::MacEager::expr(expanded) -} - -fn ids_ext(strs: Vec) -> Vec { - strs.iter().map(|s| ast::Ident::from_str(s)).collect() -} - -fn id_ext(s: &str) -> ast::Ident { - ast::Ident::from_str(s) -} - -// Lift an ident to the expr that evaluates to that ident. -fn mk_ident(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> P { - let e_str = cx.expr_str(sp, ident.name); - cx.expr_method_call(sp, - cx.expr_ident(sp, id_ext("ext_cx")), - id_ext("ident_of"), - vec![e_str]) -} - -// Lift a name to the expr that evaluates to that name -fn mk_name(cx: &ExtCtxt, sp: Span, ident: ast::Ident) -> P { - let e_str = cx.expr_str(sp, ident.name); - cx.expr_method_call(sp, - cx.expr_ident(sp, id_ext("ext_cx")), - id_ext("name_of"), - vec![e_str]) -} - -fn mk_tt_path(cx: &ExtCtxt, sp: Span, name: &str) -> P { - let idents = vec![id_ext("syntax"), id_ext("tokenstream"), id_ext("TokenTree"), id_ext(name)]; - cx.expr_path(cx.path_global(sp, idents)) -} - -fn mk_token_path(cx: &ExtCtxt, sp: Span, name: &str) -> P { - let idents = vec![id_ext("syntax"), id_ext("parse"), id_ext("token"), id_ext(name)]; - cx.expr_path(cx.path_global(sp, idents)) -} - -fn mk_parser_path(cx: &ExtCtxt, sp: Span, names: &[&str]) -> P { - let mut idents = vec![id_ext("syntax"), id_ext("parse"), id_ext("parser")]; - idents.extend(names.iter().cloned().map(id_ext)); - cx.expr_path(cx.path_global(sp, idents)) -} - -fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOpToken) -> P { - let name = match bop { - token::Plus => "Plus", - token::Minus => "Minus", - token::Star => "Star", - token::Slash => "Slash", - token::Percent => "Percent", - token::Caret => "Caret", - token::And => "And", - token::Or => "Or", - token::Shl => "Shl", - token::Shr => "Shr" - }; - mk_token_path(cx, sp, name) -} - -fn mk_delim(cx: &ExtCtxt, sp: Span, delim: token::DelimToken) -> P { - let name = match delim { - token::Paren => "Paren", - token::Bracket => "Bracket", - token::Brace => "Brace", - token::NoDelim => "NoDelim", - }; - mk_token_path(cx, sp, name) -} - -#[allow(non_upper_case_globals)] -fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { - macro_rules! mk_lit { - ($name: expr, $suffix: expr, $content: expr $(, $count: expr)*) => {{ - let name = mk_name(cx, sp, ast::Ident::with_empty_ctxt($content)); - let inner = cx.expr_call(sp, mk_token_path(cx, sp, $name), vec![ - name $(, cx.expr_u16(sp, $count))* - ]); - let suffix = match $suffix { - Some(name) => cx.expr_some(sp, mk_name(cx, sp, ast::Ident::with_empty_ctxt(name))), - None => cx.expr_none(sp) - }; - cx.expr_call(sp, mk_token_path(cx, sp, "Literal"), vec![inner, suffix]) - }} - } - - let name = match *tok { - token::BinOp(binop) => { - return cx.expr_call(sp, mk_token_path(cx, sp, "BinOp"), vec![mk_binop(cx, sp, binop)]); - } - token::BinOpEq(binop) => { - return cx.expr_call(sp, mk_token_path(cx, sp, "BinOpEq"), - vec![mk_binop(cx, sp, binop)]); - } - - token::OpenDelim(delim) => { - return cx.expr_call(sp, mk_token_path(cx, sp, "OpenDelim"), - vec![mk_delim(cx, sp, delim)]); - } - token::CloseDelim(delim) => { - return cx.expr_call(sp, mk_token_path(cx, sp, "CloseDelim"), - vec![mk_delim(cx, sp, delim)]); - } - - token::Literal(token::Byte(i), suf) => return mk_lit!("Byte", suf, i), - token::Literal(token::Char(i), suf) => return mk_lit!("Char", suf, i), - token::Literal(token::Err(_i), _suf) => return cx.expr(sp, ast::ExprKind::Err), - token::Literal(token::Integer(i), suf) => return mk_lit!("Integer", suf, i), - token::Literal(token::Float(i), suf) => return mk_lit!("Float", suf, i), - token::Literal(token::Str_(i), suf) => return mk_lit!("Str_", suf, i), - token::Literal(token::StrRaw(i, n), suf) => return mk_lit!("StrRaw", suf, i, n), - token::Literal(token::ByteStr(i), suf) => return mk_lit!("ByteStr", suf, i), - token::Literal(token::ByteStrRaw(i, n), suf) => return mk_lit!("ByteStrRaw", suf, i, n), - - token::Ident(ident, is_raw) => { - return cx.expr_call(sp, - mk_token_path(cx, sp, "Ident"), - vec![mk_ident(cx, sp, ident), cx.expr_bool(sp, is_raw)]); - } - - token::Lifetime(ident) => { - return cx.expr_call(sp, - mk_token_path(cx, sp, "Lifetime"), - vec![mk_ident(cx, sp, ident)]); - } - - token::DocComment(ident) => { - return cx.expr_call(sp, - mk_token_path(cx, sp, "DocComment"), - vec![mk_name(cx, sp, ast::Ident::with_empty_ctxt(ident))]); - } - - token::Interpolated(_) => { - cx.span_err(sp, "quote! with interpolated token"); - // Use dummy name. - "Interpolated" - } - - token::Eq => "Eq", - token::Lt => "Lt", - token::Le => "Le", - token::EqEq => "EqEq", - token::Ne => "Ne", - token::Ge => "Ge", - token::Gt => "Gt", - token::AndAnd => "AndAnd", - token::OrOr => "OrOr", - token::Not => "Not", - token::Tilde => "Tilde", - token::At => "At", - token::Dot => "Dot", - token::DotDot => "DotDot", - token::DotDotDot => "DotDotDot", - token::DotDotEq => "DotDotEq", - token::Comma => "Comma", - token::Semi => "Semi", - token::Colon => "Colon", - token::ModSep => "ModSep", - token::RArrow => "RArrow", - token::LArrow => "LArrow", - token::FatArrow => "FatArrow", - token::Pound => "Pound", - token::Dollar => "Dollar", - token::Question => "Question", - token::SingleQuote => "SingleQuote", - token::Eof => "Eof", - - token::Whitespace | token::Comment | token::Shebang(_) => { - panic!("unhandled token in quote!"); - } - }; - mk_token_path(cx, sp, name) -} - -fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, quoted: bool) -> Vec { - match *tt { - TokenTree::Token(sp, token::Ident(ident, _)) if quoted => { - // tt.extend($ident.to_tokens(ext_cx)) - - let e_to_toks = - cx.expr_method_call(sp, - cx.expr_ident(sp, ident), - id_ext("to_tokens"), - vec![cx.expr_ident(sp, id_ext("ext_cx"))]); - let e_to_toks = - cx.expr_method_call(sp, e_to_toks, id_ext("into_iter"), vec![]); - - let e_push = - cx.expr_method_call(sp, - cx.expr_ident(sp, id_ext("tt")), - id_ext("extend"), - vec![e_to_toks]); - - vec![cx.stmt_expr(e_push)] - } - TokenTree::Token(sp, ref tok) => { - let e_sp = cx.expr_ident(sp, id_ext("_sp")); - let e_tok = cx.expr_call(sp, - mk_tt_path(cx, sp, "Token"), - vec![e_sp, expr_mk_token(cx, sp, tok)]); - let e_push = - cx.expr_method_call(sp, - cx.expr_ident(sp, id_ext("tt")), - id_ext("push"), - vec![e_tok]); - vec![cx.stmt_expr(e_push)] - }, - TokenTree::Delimited(span, delim, ref tts) => { - let mut stmts = statements_mk_tt(cx, &TokenTree::open_tt(span.open, delim), false); - stmts.extend(statements_mk_tts(cx, tts.clone())); - stmts.extend(statements_mk_tt(cx, &TokenTree::close_tt(span.close, delim), false)); - stmts - } - } -} - -fn parse_arguments_to_quote(cx: &ExtCtxt, tts: &[TokenTree]) - -> (P, Vec) { - let mut p = cx.new_parser_from_tts(tts); - - let cx_expr = panictry!(p.parse_expr()); - if !p.eat(&token::Comma) { - let _ = p.diagnostic().fatal("expected token `,`"); - } - - let tts = panictry!(p.parse_all_token_trees()); - p.abort_if_errors(); - - (cx_expr, tts) -} - -fn mk_stmts_let(cx: &ExtCtxt, sp: Span) -> Vec { - // We also bind a single value, sp, to ext_cx.call_site() - // - // This causes every span in a token-tree quote to be attributed to the - // call site of the extension using the quote. We can't really do much - // better since the source of the quote may well be in a library that - // was not even parsed by this compilation run, that the user has no - // source code for (eg. in libsyntax, which they're just _using_). - // - // The old quasiquoter had an elaborate mechanism for denoting input - // file locations from which quotes originated; unfortunately this - // relied on feeding the source string of the quote back into the - // compiler (which we don't really want to do) and, in any case, only - // pushed the problem a very small step further back: an error - // resulting from a parse of the resulting quote is still attributed to - // the site the string literal occurred, which was in a source file - // _other_ than the one the user has control over. For example, an - // error in a quote from the protocol compiler, invoked in user code - // using macro_rules! for example, will be attributed to the macro_rules.rs - // file in libsyntax, which the user might not even have source to (unless - // they happen to have a compiler on hand). Over all, the phase distinction - // just makes quotes "hard to attribute". Possibly this could be fixed - // by recreating some of the original qq machinery in the tt regime - // (pushing fake SourceFiles onto the parser to account for original sites - // of quotes, for example) but at this point it seems not likely to be - // worth the hassle. - - let e_sp = cx.expr_method_call(sp, - cx.expr_ident(sp, id_ext("ext_cx")), - id_ext("call_site"), - Vec::new()); - - let stmt_let_sp = cx.stmt_let(sp, false, - id_ext("_sp"), - e_sp); - - let stmt_let_tt = cx.stmt_let(sp, true, id_ext("tt"), cx.expr_vec_ng(sp)); - - vec![stmt_let_sp, stmt_let_tt] -} - -fn statements_mk_tts(cx: &ExtCtxt, tts: TokenStream) -> Vec { - let mut ss = Vec::new(); - let mut quoted = false; - for tt in tts.into_trees() { - quoted = match tt { - TokenTree::Token(_, token::Dollar) if !quoted => true, - _ => { - ss.extend(statements_mk_tt(cx, &tt, quoted)); - false - } - } - } - ss -} - -fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[TokenTree]) -> (P, P) { - let (cx_expr, tts) = parse_arguments_to_quote(cx, tts); - - let mut vector = mk_stmts_let(cx, sp); - vector.extend(statements_mk_tts(cx, tts.iter().cloned().collect())); - vector.push(cx.stmt_expr(cx.expr_ident(sp, id_ext("tt")))); - let block = cx.expr_block(cx.block(sp, vector)); - let unflatten = vec![id_ext("syntax"), id_ext("ext"), id_ext("quote"), id_ext("unflatten")]; - - (cx_expr, cx.expr_call_global(sp, unflatten, vec![block])) -} - -fn expand_wrapper(cx: &ExtCtxt, - sp: Span, - cx_expr: P, - expr: P, - imports: &[&[&str]]) -> P { - // Explicitly borrow to avoid moving from the invoker (#16992) - let cx_expr_borrow = cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr)); - let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow); - - let mut stmts = imports.iter().map(|path| { - // make item: `use ...;` - let path = path.iter().map(|s| s.to_string()).collect(); - let use_item = cx.item_use_glob( - sp, - respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited), - ids_ext(path), - ); - cx.stmt_item(sp, use_item) - }).chain(Some(stmt_let_ext_cx)).collect::>(); - stmts.push(cx.stmt_expr(expr)); - - cx.expr_block(cx.block(sp, stmts)) -} - -fn expand_parse_call(cx: &ExtCtxt, - sp: Span, - parse_method: &str, - arg_exprs: Vec> , - tts: &[TokenTree]) -> P { - let (cx_expr, tts_expr) = expand_tts(cx, sp, tts); - - let parse_sess_call = || cx.expr_method_call( - sp, cx.expr_ident(sp, id_ext("ext_cx")), - id_ext("parse_sess"), Vec::new()); - - let new_parser_call = - cx.expr_call(sp, - cx.expr_ident(sp, id_ext("new_parser_from_tts")), - vec![parse_sess_call(), tts_expr]); - - let path = vec![id_ext("syntax"), id_ext("ext"), id_ext("quote"), id_ext(parse_method)]; - let mut args = vec![cx.expr_mut_addr_of(sp, new_parser_call)]; - args.extend(arg_exprs); - let expr = cx.expr_call_global(sp, path, args); - - if parse_method == "parse_attribute" { - expand_wrapper(cx, sp, cx_expr, expr, &[&["syntax", "ext", "quote", "rt"], - &["syntax", "parse", "attr"]]) - } else { - expand_wrapper(cx, sp, cx_expr, expr, &[&["syntax", "ext", "quote", "rt"]]) - } -} diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9b54e8f9c1f..9e107fee5ba 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -124,7 +124,6 @@ declare_features! ( (active, link_llvm_intrinsics, "1.0.0", Some(29602), None), (active, linkage, "1.0.0", Some(29603), None), - (active, quote, "1.0.0", Some(29601), None), // rustc internal (active, rustc_diagnostic_macros, "1.0.0", None, None), @@ -504,6 +503,7 @@ declare_features! ( // Paths of the form: `extern::foo::bar` (removed, extern_in_paths, "1.33.0", Some(55600), None, Some("subsumed by `::foo::bar` paths")), + (removed, quote, "1.0.0", Some(29601), None, None), ); declare_features! ( diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index df22dacce1a..b2a3ae7f9d9 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -174,7 +174,6 @@ pub mod ext { pub mod derive; pub mod expand; pub mod placeholders; - pub mod quote; pub mod source_util; pub mod tt { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 8d039692ac4..c7330004d6d 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -8,7 +8,6 @@ use syntax_pos::{Span, SourceFile, FileName, MultiSpan}; use errors::{FatalError, Level, Handler, ColorConfig, Diagnostic, DiagnosticBuilder}; use feature_gate::UnstableFeatures; use parse::parser::Parser; -use ptr::P; use symbol::Symbol; use tokenstream::{TokenStream, TokenTree}; use diagnostics::plugin::ErrorMap; @@ -135,25 +134,6 @@ pub fn parse_crate_attrs_from_source_str(name: FileName, source: String, sess: & new_parser_from_source_str(sess, name, source).parse_inner_attributes() } -crate fn parse_expr_from_source_str(name: FileName, source: String, sess: &ParseSess) - -> PResult> { - new_parser_from_source_str(sess, name, source).parse_expr() -} - -/// Parses an item. -/// -/// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and `Err` -/// when a syntax error occurred. -crate fn parse_item_from_source_str(name: FileName, source: String, sess: &ParseSess) - -> PResult>> { - new_parser_from_source_str(sess, name, source).parse_item() -} - -crate fn parse_stmt_from_source_str(name: FileName, source: String, sess: &ParseSess) - -> PResult> { - new_parser_from_source_str(sess, name, source).parse_stmt() -} - pub fn parse_stream_from_source_str(name: FileName, source: String, sess: &ParseSess, override_span: Option) -> TokenStream { @@ -781,13 +761,22 @@ mod tests { use syntax_pos::{Span, BytePos, Pos, NO_EXPANSION}; use ast::{self, Ident, PatKind}; use attr::first_attr_value_str_by_name; - use parse; + use ptr::P; use print::pprust::item_to_string; use tokenstream::{DelimSpan, TokenTree}; use util::parser_testing::string_to_stream; use util::parser_testing::{string_to_expr, string_to_item}; use with_globals; + /// Parses an item. + /// + /// Returns `Ok(Some(item))` when successful, `Ok(None)` when no item was found, and `Err` + /// when a syntax error occurred. + fn parse_item_from_source_str(name: FileName, source: String, sess: &ParseSess) + -> PResult>> { + new_parser_from_source_str(sess, name, source).parse_item() + } + // produce a syntax_pos::span fn sp(a: u32, b: u32) -> Span { Span::new(BytePos(a), BytePos(b), NO_EXPANSION) @@ -1016,9 +1005,15 @@ mod tests { #[test] fn ttdelim_span() { + fn parse_expr_from_source_str( + name: FileName, source: String, sess: &ParseSess + ) -> PResult> { + new_parser_from_source_str(sess, name, source).parse_expr() + } + with_globals(|| { let sess = ParseSess::new(FilePathMapping::empty()); - let expr = parse::parse_expr_from_source_str(PathBuf::from("foo").into(), + let expr = parse_expr_from_source_str(PathBuf::from("foo").into(), "foo!( fn main() { body } )".to_string(), &sess).unwrap(); let tts: Vec<_> = match expr.node { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 09ea0995253..624baeaf85a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1285,9 +1285,6 @@ impl<'a> Parser<'a> { crate fn span_bug>(&self, sp: S, m: &str) -> ! { self.sess.span_diagnostic.span_bug(sp, m) } - crate fn abort_if_errors(&self) { - self.sess.span_diagnostic.abort_if_errors(); - } fn cancel(&self, err: &mut DiagnosticBuilder) { self.sess.span_diagnostic.cancel(err) diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index e407be6c1fe..d0b3cd865ce 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -25,7 +25,7 @@ fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T { let mut p = string_to_parser(&ps, s); let x = panictry!(f(&mut p)); - p.abort_if_errors(); + p.sess.span_diagnostic.abort_if_errors(); x } diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 17996f23691..5e767d237cc 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -11,7 +11,6 @@ #![feature(decl_macro)] #![feature(nll)] #![feature(str_escape)] -#![feature(quote)] #![feature(rustc_diagnostic_macros)] #![recursion_limit="256"] @@ -58,8 +57,7 @@ use syntax::ext::hygiene; use syntax::symbol::Symbol; pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, - user_exts: Vec, - enable_quotes: bool) { + user_exts: Vec) { deriving::register_builtin_derives(resolver); let mut register = |name, ext| { @@ -81,24 +79,6 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, )* } } - if enable_quotes { - use syntax::ext::quote::*; - register! { - quote_tokens: expand_quote_tokens, - quote_expr: expand_quote_expr, - quote_ty: expand_quote_ty, - quote_item: expand_quote_item, - quote_pat: expand_quote_pat, - quote_arm: expand_quote_arm, - quote_stmt: expand_quote_stmt, - quote_attr: expand_quote_attr, - quote_arg: expand_quote_arg, - quote_block: expand_quote_block, - quote_meta_item: expand_quote_meta_item, - quote_path: expand_quote_path, - } - } - use syntax::ext::source_util::*; register! { line: expand_line, diff --git a/src/test/run-fail-fulldeps/qquote.rs b/src/test/run-fail-fulldeps/qquote.rs deleted file mode 100644 index d0e05216728..00000000000 --- a/src/test/run-fail-fulldeps/qquote.rs +++ /dev/null @@ -1,35 +0,0 @@ -// ignore-cross-compile - -// error-pattern:expected expression, found statement (`let`) - -#![feature(quote, rustc_private)] - -extern crate syntax; -extern crate syntax_pos; - -use syntax::ast; -use syntax::source_map; -use syntax::print::pprust; -use syntax::symbol::Symbol; -use syntax_pos::DUMMY_SP; - -fn main() { - syntax::with_globals(|| run()); -} - -fn run() { - let ps = syntax::parse::ParseSess::new(source_map::FilePathMapping::empty()); - let mut resolver = syntax::ext::base::DummyResolver; - let mut cx = syntax::ext::base::ExtCtxt::new( - &ps, - syntax::ext::expand::ExpansionConfig::default("qquote".to_string()), - &mut resolver); - let cx = &mut cx; - - println!("{}", pprust::expr_to_string(&*quote_expr!(&cx, 23))); - assert_eq!(pprust::expr_to_string(&*quote_expr!(&cx, 23)), "23"); - - let expr = quote_expr!(&cx, let x isize = 20;); - println!("{}", pprust::expr_to_string(&*expr)); - assert_eq!(pprust::expr_to_string(&*expr), "let x isize = 20;"); -} diff --git a/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs b/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs deleted file mode 100644 index 76680f5dda2..00000000000 --- a/src/test/run-pass-fulldeps/auxiliary/issue-16723.rs +++ /dev/null @@ -1,29 +0,0 @@ -// force-host - -#![feature(plugin_registrar, quote, rustc_private)] -#![crate_type = "dylib"] - -extern crate syntax; -extern crate rustc; -extern crate rustc_data_structures; -extern crate rustc_plugin; -#[macro_use] extern crate smallvec; -extern crate syntax_pos; - -use smallvec::SmallVec; -use syntax::ext::base::{ExtCtxt, MacResult, MacEager}; -use syntax::tokenstream; -use rustc_plugin::Registry; - -#[plugin_registrar] -pub fn plugin_registrar(reg: &mut Registry) { - reg.register_macro("multiple_items", expand) -} - -fn expand(cx: &mut ExtCtxt, _: syntax_pos::Span, _: &[tokenstream::TokenTree]) - -> Box { - MacEager::items(smallvec![ - quote_item!(cx, struct Struct1;).unwrap(), - quote_item!(cx, struct Struct2;).unwrap() - ]) -} diff --git a/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs b/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs index e31628782dc..a2b1d6976d0 100644 --- a/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs +++ b/src/test/run-pass-fulldeps/auxiliary/macro_crate_test.rs @@ -1,209 +1,34 @@ // force-host +// no-prefer-dynamic -#![feature(plugin_registrar, quote, rustc_private)] +#![crate_type = "proc-macro"] +#![feature(rustc_private)] extern crate syntax; extern crate rustc; extern crate rustc_plugin; extern crate syntax_pos; +extern crate proc_macro; -use syntax::ast::{self, Item, MetaItem, ItemKind}; -use syntax::source_map::DUMMY_SP; -use syntax::ext::base::*; -use syntax::ext::quote::rt::ToTokens; -use syntax::parse::{self, token}; -use syntax::ptr::P; -use syntax::symbol::Symbol; -use syntax::tokenstream::TokenTree; -use syntax_pos::Span; -use rustc_plugin::Registry; +use proc_macro::{TokenTree, TokenStream}; -#[macro_export] -macro_rules! exported_macro { () => (2) } -macro_rules! unexported_macro { () => (3) } - -#[plugin_registrar] -pub fn plugin_registrar(reg: &mut Registry) { - reg.register_macro("make_a_1", expand_make_a_1); - reg.register_macro("identity", expand_identity); - reg.register_syntax_extension( - Symbol::intern("rustc_into_multi_foo"), - MultiModifier(Box::new(expand_into_foo_multi))); - reg.register_syntax_extension( - Symbol::intern("rustc_duplicate"), - MultiDecorator(Box::new(expand_duplicate))); - reg.register_syntax_extension( - Symbol::intern("rustc_caller"), - MultiDecorator(Box::new(expand_caller))); +#[proc_macro_attribute] +pub fn rustc_duplicate(attr: TokenStream, item: TokenStream) -> TokenStream { + let mut new_name = Some(attr.into_iter().nth(0).unwrap()); + let mut encountered_idents = 0; + let input = item.to_string(); + let ret = item.into_iter().map(move |token| match token { + TokenTree::Ident(_) if encountered_idents == 1 => { + encountered_idents += 1; + new_name.take().unwrap() + } + TokenTree::Ident(_) => { + encountered_idents += 1; + token + } + _ => token + }).collect::(); + let mut input_again = input.parse::().unwrap(); + input_again.extend(ret); + input_again } - -fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box { - if !tts.is_empty() { - cx.span_fatal(sp, "make_a_1 takes no arguments"); - } - MacEager::expr(quote_expr!(cx, 1)) -} - -// See Issue #15750 -fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree]) -> Box { - // Parse an expression and emit it unchanged. - let mut parser = parse::new_parser_from_tts(cx.parse_sess(), tts.to_vec()); - let expr = parser.parse_expr().unwrap(); - MacEager::expr(quote_expr!(&mut *cx, $expr)) -} - -fn expand_into_foo_multi(cx: &mut ExtCtxt, - _sp: Span, - _attr: &MetaItem, - it: Annotatable) - -> Vec { - match it { - Annotatable::Item(it) => vec![ - Annotatable::Item(P(Item { - attrs: it.attrs.clone(), - ..(*quote_item!(cx, enum Foo2 { Bar2, Baz2 }).unwrap()).clone() - })), - Annotatable::Item(quote_item!(cx, enum Foo3 { Bar }).unwrap()), - Annotatable::Item(quote_item!(cx, #[cfg(any())] fn foo2() {}).unwrap()), - ], - Annotatable::ImplItem(_it) => vec![ - quote_item!(cx, impl X { fn foo(&self) -> i32 { 42 } }).unwrap().and_then(|i| { - match i.node { - ItemKind::Impl(.., mut items) => { - Annotatable::ImplItem(P(items.pop().expect("impl method not found"))) - } - _ => unreachable!("impl parsed to something other than impl") - } - }) - ], - Annotatable::TraitItem(_it) => vec![ - quote_item!(cx, trait X { fn foo(&self) -> i32 { 0 } }).unwrap().and_then(|i| { - match i.node { - ItemKind::Trait(.., mut items) => { - Annotatable::TraitItem(P(items.pop().expect("trait method not found"))) - } - _ => unreachable!("trait parsed to something other than trait") - } - }) - ], - // covered in proc_macro/macros-in-extern.rs - Annotatable::ForeignItem(..) => unimplemented!(), - // covered in proc_macro/attr-stmt-expr.rs - Annotatable::Stmt(_) | Annotatable::Expr(_) => panic!("expected item"), - } -} - -// Create a duplicate of the annotatable, based on the MetaItem -fn expand_duplicate(cx: &mut ExtCtxt, - _sp: Span, - mi: &MetaItem, - it: &Annotatable, - push: &mut FnMut(Annotatable)) { - let copy_name = match mi.node { - ast::MetaItemKind::List(ref xs) => { - if let Some(word) = xs[0].word() { - word.ident.segments.last().unwrap().ident - } else { - cx.span_err(mi.span, "Expected word"); - return; - } - } - _ => { - cx.span_err(mi.span, "Expected list"); - return; - } - }; - - // Duplicate the item but replace its ident by the MetaItem - match it.clone() { - Annotatable::Item(it) => { - let mut new_it = (*it).clone(); - new_it.attrs.clear(); - new_it.ident = copy_name; - push(Annotatable::Item(P(new_it))); - } - Annotatable::ImplItem(it) => { - let mut new_it = (*it).clone(); - new_it.attrs.clear(); - new_it.ident = copy_name; - push(Annotatable::ImplItem(P(new_it))); - } - Annotatable::TraitItem(tt) => { - let mut new_it = (*tt).clone(); - new_it.attrs.clear(); - new_it.ident = copy_name; - push(Annotatable::TraitItem(P(new_it))); - } - // covered in proc_macro/macros-in-extern.rs - Annotatable::ForeignItem(..) => unimplemented!(), - // covered in proc_macro/attr-stmt-expr.rs - Annotatable::Stmt(_) | Annotatable::Expr(_) => panic!("expected item") - } -} - -pub fn token_separate(ecx: &ExtCtxt, things: &[T], - token: token::Token) -> Vec { - let mut output: Vec = vec![]; - for (i, thing) in things.iter().enumerate() { - output.extend(thing.to_tokens(ecx)); - if i < things.len() - 1 { - output.push(TokenTree::Token(DUMMY_SP, token.clone())); - } - } - - output -} - -fn expand_caller(cx: &mut ExtCtxt, - sp: Span, - mi: &MetaItem, - it: &Annotatable, - push: &mut FnMut(Annotatable)) { - let (orig_fn_name, ret_type) = match *it { - Annotatable::Item(ref item) => match item.node { - ItemKind::Fn(ref decl, ..) => { - (item.ident, &decl.output) - } - _ => cx.span_fatal(item.span, "Only functions with return types can be annotated.") - }, - _ => cx.span_fatal(sp, "Only functions can be annotated.") - }; - - let (caller_name, arguments) = if let Some(list) = mi.meta_item_list() { - if list.len() < 2 { - cx.span_fatal(mi.span(), "Need a function name and at least one parameter."); - } - - let fn_name = match list[0].name() { - Some(name) => ast::Ident::with_empty_ctxt(name), - None => cx.span_fatal(list[0].span(), "First parameter must be an ident.") - }; - - (fn_name, &list[1..]) - } else { - cx.span_fatal(mi.span, "Expected list."); - }; - - let literals: Vec = arguments.iter().map(|arg| { - if let Some(lit) = arg.literal() { - lit.clone() - } else { - cx.span_fatal(arg.span(), "Expected literal."); - } - }).collect(); - - let arguments = token_separate(cx, literals.as_slice(), token::Comma); - if let ast::FunctionRetTy::Ty(ref rt) = *ret_type { - push(Annotatable::Item(quote_item!(cx, - fn $caller_name() -> $rt { - $orig_fn_name($arguments) - }).unwrap())) - } else { - push(Annotatable::Item(quote_item!(cx, - fn $caller_name() { - $orig_fn_name($arguments) - }).unwrap())) - } -} - -pub fn foo() {} diff --git a/src/test/run-pass-fulldeps/auxiliary/plugin_with_plugin_lib.rs b/src/test/run-pass-fulldeps/auxiliary/plugin_with_plugin_lib.rs deleted file mode 100644 index 320b77e8ea8..00000000000 --- a/src/test/run-pass-fulldeps/auxiliary/plugin_with_plugin_lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -// force-host - -#![feature(plugin_registrar, rustc_private)] -#![deny(plugin_as_library)] // should have no effect in a plugin crate - -extern crate macro_crate_test; -extern crate rustc; -extern crate rustc_plugin; - -use rustc_plugin::Registry; - -#[plugin_registrar] -pub fn plugin_registrar(_: &mut Registry) { } diff --git a/src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs b/src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs deleted file mode 100644 index e2fa3744ad8..00000000000 --- a/src/test/run-pass-fulldeps/auxiliary/procedural_mbe_matching.rs +++ /dev/null @@ -1,82 +0,0 @@ -// force-host - -#![crate_type="dylib"] -#![feature(plugin_registrar, quote, rustc_private)] - -extern crate syntax; -extern crate syntax_pos; -extern crate rustc; -extern crate rustc_plugin; - -use syntax::feature_gate::Features; -use syntax::parse::token::{NtExpr, NtPat}; -use syntax::ast::{Ident, Pat, NodeId}; -use syntax::tokenstream::{TokenTree}; -use syntax::ext::base::{ExtCtxt, MacResult, MacEager}; -use syntax::ext::build::AstBuilder; -use syntax::ext::tt::quoted; -use syntax::ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal}; -use syntax::ext::tt::macro_parser::{Success, Failure, Error}; -use syntax::ext::tt::macro_parser::parse_failure_msg; -use syntax::ptr::P; -use syntax_pos::{Span, edition::Edition}; -use rustc_plugin::Registry; - -fn expand_mbe_matches(cx: &mut ExtCtxt, _: Span, args: &[TokenTree]) - -> Box { - - let mbe_matcher = quote_tokens!(cx, $$matched:expr, $$($$pat:pat)|+); - let mbe_matcher = quoted::parse(mbe_matcher.into_iter().collect(), - true, - cx.parse_sess, - &Features::new(), - &[], - Edition::Edition2015, - // not used... - NodeId::from_u32(0)); - let map = match TokenTree::parse(cx, &mbe_matcher, args.iter().cloned().collect()) { - Success(map) => map, - Failure(_, tok, msg) => { - panic!("expected Success, but got Failure: {} - {}", parse_failure_msg(tok), msg); - } - Error(_, s) => { - panic!("expected Success, but got Error: {}", s); - } - }; - - let matched_nt = match *map[&Ident::from_str("matched")] { - MatchedNonterminal(ref nt) => nt.clone(), - _ => unreachable!(), - }; - - let mac_expr = match (&*matched_nt, &*map[&Ident::from_str("pat")]) { - (&NtExpr(ref matched_expr), &MatchedSeq(ref pats, seq_sp)) => { - let pats: Vec> = pats.iter().map(|pat_nt| { - match *pat_nt { - MatchedNonterminal(ref nt) => match **nt { - NtPat(ref pat) => pat.clone(), - _ => unreachable!(), - }, - _ => unreachable!(), - } - }).collect(); - let span = seq_sp.entire(); - let arm = cx.arm(span, pats, cx.expr_bool(span, true)); - - quote_expr!(cx, - match $matched_expr { - $arm - _ => false - } - ) - } - _ => unreachable!() - }; - - MacEager::expr(mac_expr) -} - -#[plugin_registrar] -pub fn plugin_registrar(reg: &mut Registry) { - reg.register_macro("matches", expand_mbe_matches); -} diff --git a/src/test/run-pass-fulldeps/auxiliary/syntax_extension_with_dll_deps_2.rs b/src/test/run-pass-fulldeps/auxiliary/syntax_extension_with_dll_deps_2.rs deleted file mode 100644 index a356df55b35..00000000000 --- a/src/test/run-pass-fulldeps/auxiliary/syntax_extension_with_dll_deps_2.rs +++ /dev/null @@ -1,27 +0,0 @@ -// force-host - -#![crate_type = "dylib"] -#![feature(plugin_registrar, quote, rustc_private)] - -extern crate syntax_extension_with_dll_deps_1 as other; -extern crate syntax; -extern crate syntax_pos; -extern crate rustc; -extern crate rustc_plugin; - -use syntax::ast::{Item, MetaItem}; -use syntax::ext::base::*; -use syntax::tokenstream::TokenTree; -use syntax_pos::Span; -use rustc_plugin::Registry; - -#[plugin_registrar] -pub fn plugin_registrar(reg: &mut Registry) { - reg.register_macro("foo", expand_foo); -} - -fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) - -> Box { - let answer = other::the_answer(); - MacEager::expr(quote_expr!(cx, $answer)) -} diff --git a/src/test/run-pass-fulldeps/issue-16723.rs b/src/test/run-pass-fulldeps/issue-16723.rs deleted file mode 100644 index a3965f98927..00000000000 --- a/src/test/run-pass-fulldeps/issue-16723.rs +++ /dev/null @@ -1,19 +0,0 @@ -// ignore-stage1 -// aux-build:issue-16723.rs -#![feature(plugin)] -#![plugin(issue_16723)] - -multiple_items!(); - -impl Struct1 { - fn foo() {} -} -impl Struct2 { - fn foo() {} -} - -fn main() { - Struct1::foo(); - Struct2::foo(); - println!("hallo"); -} diff --git a/src/test/run-pass-fulldeps/issue-16992.rs b/src/test/run-pass-fulldeps/issue-16992.rs deleted file mode 100644 index e5945b679f3..00000000000 --- a/src/test/run-pass-fulldeps/issue-16992.rs +++ /dev/null @@ -1,15 +0,0 @@ -// ignore-cross-compile - -#![feature(quote, rustc_private)] - -extern crate syntax; - -use syntax::ext::base::ExtCtxt; - -#[allow(dead_code)] -fn foobar(cx: &mut ExtCtxt) { - quote_expr!(cx, 1); - quote_expr!(cx, 2); -} - -fn main() { } diff --git a/src/test/run-pass-fulldeps/issue-18763-quote-token-tree.rs b/src/test/run-pass-fulldeps/issue-18763-quote-token-tree.rs deleted file mode 100644 index 9fa3d3de8f2..00000000000 --- a/src/test/run-pass-fulldeps/issue-18763-quote-token-tree.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_imports)] -// ignore-cross-compile -#![feature(quote, rustc_private)] - -extern crate syntax; - -use syntax::ext::base::ExtCtxt; - -fn syntax_extension(cx: &ExtCtxt) { - let _toks_1 = vec![quote_tokens!(cx, /** comment */ fn foo() {})]; - let name = quote_tokens!(cx, bar); - let _toks_2 = vec![quote_item!(cx, static $name:isize = 2;)]; - let _toks_4 = quote_tokens!(cx, $name:static $name:sizeof); - let _toks_3 = vec![quote_item!(cx, - /// comment - fn foo() { let $name:isize = 3; } - )]; -} - -fn main() { -} diff --git a/src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs b/src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs deleted file mode 100644 index 3c251cc0f55..00000000000 --- a/src/test/run-pass-fulldeps/macro-crate-does-hygiene-work.rs +++ /dev/null @@ -1,16 +0,0 @@ -// aux-build:macro_crate_test.rs -// ignore-stage1 - -// Issue #15750: a macro that internally parses its input and then -// uses `quote_expr!` to rearrange it should be hygiene-preserving. - -#![feature(plugin)] -#![plugin(macro_crate_test)] - -fn main() { - let x = 3; - assert_eq!(3, identity!(x)); - assert_eq!(6, identity!(x+x)); - let x = 4; - assert_eq!(4, identity!(x)); -} diff --git a/src/test/run-pass-fulldeps/macro-crate-multi-decorator-literals.rs b/src/test/run-pass-fulldeps/macro-crate-multi-decorator-literals.rs deleted file mode 100644 index eb7ab139d64..00000000000 --- a/src/test/run-pass-fulldeps/macro-crate-multi-decorator-literals.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(plugin_as_library)] -#![allow(unused_imports)] -// aux-build:macro_crate_test.rs -// ignore-stage1 - -#![feature(plugin, rustc_attrs)] -#![plugin(macro_crate_test)] - -#[macro_use] -#[no_link] -extern crate macro_crate_test; - -// The `caller(name, args...)` attribute emits a new nullary function named -// `name` that calls the annotated function with `args`. As an example, consider -// the following: -// -// #[caller(simple, 1, "hello", 3.14)] -// fn f(num: isize, string: &'static str, float: f32) -> (isize, &'static str, float) { -// (num, string, float) -// } -// -// This results in a function named `simple` that calls `f(1, "hello", 3.14)`. -// As a result, the expression `simple()` evaluates to `(1, "helllo", 3.14)`. - -#[rustc_caller(simple, 1, "hello", 3.14)] -#[rustc_caller(simple1, 2, "bye", 6.28)] -#[rustc_caller(simple2, 3, "hi", 1.01)] -fn f(num: isize, string: &'static str, float: f32) -> (isize, &'static str, f32) { - (num, string, float) -} - -#[rustc_caller(complex, true, 10)] -#[rustc_caller(complex1, false, 15)] -#[rustc_caller(complex2, true, 20)] -fn g(emit: bool, num: i32) -> Option { - match emit { - true => Some(num), - false => None - } -} - -fn main() { - assert_eq!(simple(), (1, "hello", 3.14)); - assert_eq!(simple1(), (2, "bye", 6.28)); - assert_eq!(simple2(), (3, "hi", 1.01)); - - assert_eq!(complex(), Some(10)); - assert_eq!(complex1(), None); - assert_eq!(complex2(), Some(20)); -} diff --git a/src/test/run-pass-fulldeps/macro-crate-multi-decorator.rs b/src/test/run-pass-fulldeps/macro-crate-multi-decorator.rs index ef28f233fea..dcac160c4c9 100644 --- a/src/test/run-pass-fulldeps/macro-crate-multi-decorator.rs +++ b/src/test/run-pass-fulldeps/macro-crate-multi-decorator.rs @@ -5,11 +5,9 @@ // aux-build:macro_crate_test.rs // ignore-stage1 -#![feature(plugin, rustc_attrs)] -#![plugin(macro_crate_test)] +#![feature(rustc_attrs)] #[macro_use] -#[no_link] extern crate macro_crate_test; // The duplicate macro will create a copy of the item with the given identifier. diff --git a/src/test/run-pass-fulldeps/macro-crate.rs b/src/test/run-pass-fulldeps/macro-crate.rs deleted file mode 100644 index 62838c2c083..00000000000 --- a/src/test/run-pass-fulldeps/macro-crate.rs +++ /dev/null @@ -1,46 +0,0 @@ -#![allow(plugin_as_library)] -#![allow(dead_code)] -// aux-build:macro_crate_test.rs -// ignore-stage1 - -#![feature(plugin, rustc_attrs)] -#![plugin(macro_crate_test)] - -#[macro_use] #[no_link] -extern crate macro_crate_test; - -#[rustc_into_multi_foo] -#[derive(PartialEq, Clone, Debug)] -fn foo() -> AnotherFakeTypeThatHadBetterGoAway {} - -// Check that the `#[into_multi_foo]`-generated `foo2` is configured away -fn foo2() {} - -trait Qux { - #[rustc_into_multi_foo] - fn bar(); -} - -impl Qux for i32 { - #[rustc_into_multi_foo] - fn bar() {} -} - -impl Qux for u8 {} - -pub fn main() { - assert_eq!(1, make_a_1!()); - assert_eq!(2, exported_macro!()); - - assert_eq!(Foo2::Bar2, Foo2::Bar2); - test(None::); - - let _ = Foo3::Bar; - - let x = 10i32; - assert_eq!(x.foo(), 42); - let x = 10u8; - assert_eq!(x.foo(), 0); -} - -fn test(_: Option) {} diff --git a/src/test/run-pass-fulldeps/mbe_matching_test_macro.rs b/src/test/run-pass-fulldeps/mbe_matching_test_macro.rs deleted file mode 100644 index c672081edf4..00000000000 --- a/src/test/run-pass-fulldeps/mbe_matching_test_macro.rs +++ /dev/null @@ -1,11 +0,0 @@ -// aux-build:procedural_mbe_matching.rs -// ignore-stage1 - -#![feature(plugin)] -#![plugin(procedural_mbe_matching)] - -pub fn main() { - assert_eq!(matches!(Some(123), None | Some(0)), false); - assert_eq!(matches!(Some(123), None | Some(123)), true); - assert_eq!(matches!(true, true), true); -} diff --git a/src/test/run-pass-fulldeps/plugin-lib-ok-in-plugin.rs b/src/test/run-pass-fulldeps/plugin-lib-ok-in-plugin.rs deleted file mode 100644 index e9f234f7f54..00000000000 --- a/src/test/run-pass-fulldeps/plugin-lib-ok-in-plugin.rs +++ /dev/null @@ -1,16 +0,0 @@ -// aux-build:macro_crate_test.rs -// aux-build:plugin_with_plugin_lib.rs -// ignore-stage1 -// ignore-cross-compile -// -// macro_crate_test will not compile on a cross-compiled target because -// libsyntax is not compiled for it. - -#![deny(plugin_as_library)] -#![feature(plugin)] -#![plugin(macro_crate_test)] -#![plugin(plugin_with_plugin_lib)] - -fn main() { - assert_eq!(1, make_a_1!()); -} diff --git a/src/test/run-pass-fulldeps/plugin-plus-extern-crate.rs b/src/test/run-pass-fulldeps/plugin-plus-extern-crate.rs deleted file mode 100644 index e45a7f59c1b..00000000000 --- a/src/test/run-pass-fulldeps/plugin-plus-extern-crate.rs +++ /dev/null @@ -1,17 +0,0 @@ -// aux-build:macro_crate_test.rs -// ignore-stage1 -// ignore-cross-compile -// -// macro_crate_test will not compile on a cross-compiled target because -// libsyntax is not compiled for it. - -#![allow(plugin_as_library)] -#![feature(plugin)] -#![plugin(macro_crate_test)] - -extern crate macro_crate_test; - -fn main() { - assert_eq!(1, make_a_1!()); - macro_crate_test::foo(); -} diff --git a/src/test/run-pass-fulldeps/qquote.rs b/src/test/run-pass-fulldeps/qquote.rs deleted file mode 100644 index 33063fc74bf..00000000000 --- a/src/test/run-pass-fulldeps/qquote.rs +++ /dev/null @@ -1,92 +0,0 @@ -#![allow(unused_imports)] -// ignore-cross-compile - -#![feature(quote, rustc_private)] - -extern crate syntax; -extern crate syntax_pos; - -use syntax::source_map::FilePathMapping; -use syntax::print::pprust::*; -use syntax::symbol::Symbol; -use syntax_pos::DUMMY_SP; - -fn main() { - syntax::with_globals(|| run()); -} - -fn run() { - let ps = syntax::parse::ParseSess::new(FilePathMapping::empty()); - let mut resolver = syntax::ext::base::DummyResolver; - let mut cx = syntax::ext::base::ExtCtxt::new( - &ps, - syntax::ext::expand::ExpansionConfig::default("qquote".to_string()), - &mut resolver); - let cx = &mut cx; - - macro_rules! check { - ($f: ident, $($e: expr),+; $expect: expr) => ({ - $(assert_eq!($f(&$e), $expect);)+ - }); - } - - let abc = quote_expr!(cx, 23); - check!(expr_to_string, abc, *quote_expr!(cx, $abc); "23"); - - let ty = quote_ty!(cx, isize); - check!(ty_to_string, ty, *quote_ty!(cx, $ty); "isize"); - - let item = quote_item!(cx, static x: $ty = 10;).unwrap(); - check!(item_to_string, item, quote_item!(cx, $item).unwrap(); "static x: isize = 10;"); - - let twenty: u16 = 20; - let stmt = quote_stmt!(cx, let x = $twenty;).unwrap(); - check!(stmt_to_string, stmt, quote_stmt!(cx, $stmt).unwrap(); "let x = 20u16;"); - - let pat = quote_pat!(cx, Some(_)); - check!(pat_to_string, pat, *quote_pat!(cx, $pat); "Some(_)"); - - let expr = quote_expr!(cx, (x, y)); - let arm = quote_arm!(cx, (ref x, ref y) => $expr,); - check!(arm_to_string, arm, quote_arm!(cx, $arm); " (ref x, ref y) => (x, y),"); - - let attr = quote_attr!(cx, #![cfg(foo = "bar")]); - check!(attribute_to_string, attr, quote_attr!(cx, $attr); r#"#![cfg(foo = "bar")]"#); - - // quote_arg! - - let arg = quote_arg!(cx, foo: i32); - check!(arg_to_string, arg, quote_arg!(cx, $arg); "foo: i32"); - - let function = quote_item!(cx, fn f($arg) { }).unwrap(); - check!(item_to_string, function; "fn f(foo: i32) { }"); - - let args = vec![arg, quote_arg!(cx, bar: u32)]; - let args = &args[..]; - let function = quote_item!(cx, fn f($args) { }).unwrap(); - check!(item_to_string, function; "fn f(foo: i32, bar: u32) { }"); - - // quote_block! - - let block = quote_block!(cx, { $stmt let y = 40u32; }); - check!(block_to_string, block, *quote_block!(cx, $block); "{ let x = 20u16; let y = 40u32; }"); - - let function = quote_item!(cx, fn f() $block).unwrap(); - check!(item_to_string, function; "fn f() { let x = 20u16; let y = 40u32; }"); - - // quote_path! - - let path = quote_path!(cx, ::syntax::ptr::P); - check!(path_to_string, path, quote_path!(cx, $path); "::syntax::ptr::P"); - - let ty = quote_ty!(cx, $path); - check!(ty_to_string, ty; "::syntax::ptr::P"); - - // quote_meta_item! - - let meta = quote_meta_item!(cx, cfg(foo = "bar")); - check!(meta_item_to_string, meta, quote_meta_item!(cx, $meta); r#"cfg(foo = "bar")"#); - - let attr = quote_attr!(cx, #![$meta]); - check!(attribute_to_string, attr; r#"#![cfg(foo = "bar")]"#); -} diff --git a/src/test/run-pass-fulldeps/quote-tokens.rs b/src/test/run-pass-fulldeps/quote-tokens.rs deleted file mode 100644 index 04a4c442e00..00000000000 --- a/src/test/run-pass-fulldeps/quote-tokens.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] -#![allow(unused_imports)] -// ignore-cross-compile -#![feature(quote, rustc_private)] - -extern crate syntax; - -use syntax::ext::base::ExtCtxt; -use syntax::ptr::P; -use syntax::parse::PResult; - -fn syntax_extension(cx: &ExtCtxt) { - let e_toks : Vec = quote_tokens!(cx, 1 + 2); - let p_toks : Vec = quote_tokens!(cx, (x, 1 .. 4, *)); - - let a: P = quote_expr!(cx, 1 + 2); - let _b: Option> = quote_item!(cx, static foo : isize = $e_toks; ); - let _c: P = quote_pat!(cx, (x, 1 .. 4, *) ); - let _d: Option = quote_stmt!(cx, let x = $a; ); - let _d: syntax::ast::Arm = quote_arm!(cx, (ref x, ref y) = (x, y) ); - let _e: P = quote_expr!(cx, match foo { $p_toks => 10 } ); - - let _f: P = quote_expr!(cx, ()); - let _g: P = quote_expr!(cx, true); - let _h: P = quote_expr!(cx, 'a'); - - let i: Option> = quote_item!(cx, #[derive(Eq)] struct Foo; ); - assert!(i.is_some()); - - let _l: P = quote_ty!(cx, &isize); - - let _n: syntax::ast::Attribute = quote_attr!(cx, #![cfg(foo, bar = "baz")]); - - let _o: Option> = quote_item!(cx, fn foo() {}); - - let stmts = vec![ - quote_stmt!(cx, let x = 1;).unwrap(), - quote_stmt!(cx, let y = 2;).unwrap(), - ]; - let expr: P = quote_expr!(cx, x + y); -} - -fn main() { -} diff --git a/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs b/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs deleted file mode 100644 index 1568bf26039..00000000000 --- a/src/test/run-pass-fulldeps/quote-unused-sp-no-warning.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![allow(dead_code)] -// ignore-cross-compile -#![feature(quote, rustc_private)] -#![deny(unused_variables)] - -extern crate syntax; - -use syntax::ext::base::ExtCtxt; - -fn test(cx: &mut ExtCtxt) { - let foo = 10; - let _e = quote_expr!(cx, $foo); -} - -pub fn main() { } diff --git a/src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs b/src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs deleted file mode 100644 index 7c236fd69ea..00000000000 --- a/src/test/run-pass-fulldeps/syntax-extension-with-dll-deps.rs +++ /dev/null @@ -1,10 +0,0 @@ -// aux-build:syntax_extension_with_dll_deps_1.rs -// aux-build:syntax_extension_with_dll_deps_2.rs -// ignore-stage1 - -#![feature(plugin, rustc_private)] -#![plugin(syntax_extension_with_dll_deps_2)] - -fn main() { - foo!(); -} diff --git a/src/test/ui-fulldeps/auxiliary/macro_crate_test.rs b/src/test/ui-fulldeps/auxiliary/macro_crate_test.rs deleted file mode 100644 index a364aa0422d..00000000000 --- a/src/test/ui-fulldeps/auxiliary/macro_crate_test.rs +++ /dev/null @@ -1,149 +0,0 @@ -// force-host - -#![feature(plugin_registrar, quote, rustc_private)] - -extern crate syntax; -extern crate syntax_pos; -extern crate rustc; -extern crate rustc_plugin; - -use syntax::ast::{self, Item, MetaItem, ItemKind}; -use syntax::ext::base::*; -use syntax::parse; -use syntax::ptr::P; -use syntax::symbol::Symbol; -use syntax::tokenstream::TokenTree; -use syntax_pos::Span; -use rustc_plugin::Registry; - -#[macro_export] -macro_rules! exported_macro { () => (2) } -macro_rules! unexported_macro { () => (3) } - -#[plugin_registrar] -pub fn plugin_registrar(reg: &mut Registry) { - reg.register_macro("make_a_1", expand_make_a_1); - reg.register_macro("identity", expand_identity); - reg.register_syntax_extension( - Symbol::intern("into_multi_foo"), - MultiModifier(Box::new(expand_into_foo_multi))); - reg.register_syntax_extension( - Symbol::intern("noop_attribute"), - MultiModifier(Box::new(expand_noop_attribute))); - reg.register_syntax_extension( - Symbol::intern("duplicate"), - MultiDecorator(Box::new(expand_duplicate))); -} - -fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) - -> Box { - if !tts.is_empty() { - cx.span_fatal(sp, "make_a_1 takes no arguments"); - } - MacEager::expr(quote_expr!(cx, 1)) -} - -// See Issue #15750 -fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree]) - -> Box { - // Parse an expression and emit it unchanged. - let mut parser = parse::new_parser_from_tts(cx.parse_sess(), tts.to_vec()); - let expr = parser.parse_expr().unwrap(); - MacEager::expr(quote_expr!(&mut *cx, $expr)) -} - -fn expand_into_foo_multi(cx: &mut ExtCtxt, - _sp: Span, - _attr: &MetaItem, - it: Annotatable) -> Annotatable { - match it { - Annotatable::Item(it) => { - Annotatable::Item(P(Item { - attrs: it.attrs.clone(), - ..(*quote_item!(cx, enum Foo2 { Bar2, Baz2 }).unwrap()).clone() - })) - } - Annotatable::ImplItem(_) => { - quote_item!(cx, impl X { fn foo(&self) -> i32 { 42 } }).unwrap().and_then(|i| { - match i.node { - ItemKind::Impl(.., mut items) => { - Annotatable::ImplItem(P(items.pop().expect("impl method not found"))) - } - _ => unreachable!("impl parsed to something other than impl") - } - }) - } - Annotatable::TraitItem(_) => { - quote_item!(cx, trait X { fn foo(&self) -> i32 { 0 } }).unwrap().and_then(|i| { - match i.node { - ItemKind::Trait(.., mut items) => { - Annotatable::TraitItem(P(items.pop().expect("trait method not found"))) - } - _ => unreachable!("trait parsed to something other than trait") - } - }) - } - // covered in proc_macro/macros-in-extern.rs - Annotatable::ForeignItem(_) => unimplemented!(), - // covered in proc_macro/attr-stmt-expr.rs - Annotatable::Stmt(_) | Annotatable::Expr(_) => panic!("expected item") - } -} - -fn expand_noop_attribute(_cx: &mut ExtCtxt, - _sp: Span, - _attr: &MetaItem, - it: Annotatable) -> Annotatable { - it -} - -// Create a duplicate of the annotatable, based on the MetaItem -fn expand_duplicate(cx: &mut ExtCtxt, - _sp: Span, - mi: &MetaItem, - it: &Annotatable, - push: &mut FnMut(Annotatable)) -{ - let copy_name = match mi.node { - ast::MetaItemKind::List(ref xs) => { - if let Some(word) = xs[0].word() { - word.ident.segments.last().unwrap().ident - } else { - cx.span_err(mi.span, "Expected word"); - return; - } - } - _ => { - cx.span_err(mi.span, "Expected list"); - return; - } - }; - - // Duplicate the item but replace its ident by the MetaItem - match it.clone() { - Annotatable::Item(it) => { - let mut new_it = (*it).clone(); - new_it.attrs.clear(); - new_it.ident = copy_name; - push(Annotatable::Item(P(new_it))); - } - Annotatable::ImplItem(it) => { - let mut new_it = (*it).clone(); - new_it.attrs.clear(); - new_it.ident = copy_name; - push(Annotatable::ImplItem(P(new_it))); - } - Annotatable::TraitItem(tt) => { - let mut new_it = (*tt).clone(); - new_it.attrs.clear(); - new_it.ident = copy_name; - push(Annotatable::TraitItem(P(new_it))); - } - // covered in proc_macro/macros-in-extern.rs - Annotatable::ForeignItem(_) => unimplemented!(), - // covered in proc_macro/attr-stmt-expr.rs - Annotatable::Stmt(_) | Annotatable::Expr(_) => panic!("expected item") - } -} - -pub fn foo() {} diff --git a/src/test/ui-fulldeps/gated-plugin.rs b/src/test/ui-fulldeps/gated-plugin.rs index 3a138d9af03..a647585e621 100644 --- a/src/test/ui-fulldeps/gated-plugin.rs +++ b/src/test/ui-fulldeps/gated-plugin.rs @@ -1,6 +1,6 @@ -// aux-build:macro_crate_test.rs +// aux-build:attr_plugin_test.rs -#![plugin(macro_crate_test)] +#![plugin(attr_plugin_test)] //~^ ERROR compiler plugins are experimental and possibly buggy fn main() {} diff --git a/src/test/ui-fulldeps/gated-plugin.stderr b/src/test/ui-fulldeps/gated-plugin.stderr index a72a45833d0..37c2b443247 100644 --- a/src/test/ui-fulldeps/gated-plugin.stderr +++ b/src/test/ui-fulldeps/gated-plugin.stderr @@ -1,7 +1,7 @@ error[E0658]: compiler plugins are experimental and possibly buggy (see issue #29597) --> $DIR/gated-plugin.rs:3:1 | -LL | #![plugin(macro_crate_test)] +LL | #![plugin(attr_plugin_test)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(plugin)] to the crate attributes to enable diff --git a/src/test/ui-fulldeps/gated-quote.rs b/src/test/ui-fulldeps/gated-quote.rs deleted file mode 100644 index 86848e3156f..00000000000 --- a/src/test/ui-fulldeps/gated-quote.rs +++ /dev/null @@ -1,57 +0,0 @@ -// Test that `quote`-related macro are gated by `quote` feature gate. - -// (To sanity-check the code, uncomment this.) -// #![feature(quote)] - -// FIXME the error message that is current emitted seems pretty bad. - -// gate-test-quote - -#![feature(rustc_private)] -#![allow(dead_code, unused_imports, unused_variables)] - -#[macro_use] -extern crate syntax; - -use syntax::ast; -use syntax::parse; - -struct ParseSess; - -impl ParseSess { - fn cfg(&self) -> ast::CrateConfig { loop { } } - fn parse_sess<'a>(&'a self) -> &'a parse::ParseSess { loop { } } - fn call_site(&self) -> () { loop { } } - fn ident_of(&self, st: &str) -> ast::Ident { loop { } } - fn name_of(&self, st: &str) -> ast::Name { loop { } } -} - -pub fn main() { - let ecx = &ParseSess; - let x = quote_tokens!(ecx, 3); - //~^ ERROR cannot find macro `quote_tokens!` in this scope - let x = quote_expr!(ecx, 3); - //~^ ERROR cannot find macro `quote_expr!` in this scope - let x = quote_ty!(ecx, 3); - //~^ ERROR cannot find macro `quote_ty!` in this scope - let x = quote_method!(ecx, 3); - //~^ ERROR cannot find macro `quote_method!` in this scope - let x = quote_item!(ecx, 3); - //~^ ERROR cannot find macro `quote_item!` in this scope - let x = quote_pat!(ecx, 3); - //~^ ERROR cannot find macro `quote_pat!` in this scope - let x = quote_arm!(ecx, 3); - //~^ ERROR cannot find macro `quote_arm!` in this scope - let x = quote_stmt!(ecx, 3); - //~^ ERROR cannot find macro `quote_stmt!` in this scope - let x = quote_attr!(ecx, 3); - //~^ ERROR cannot find macro `quote_attr!` in this scope - let x = quote_arg!(ecx, 3); - //~^ ERROR cannot find macro `quote_arg!` in this scope - let x = quote_block!(ecx, 3); - //~^ ERROR cannot find macro `quote_block!` in this scope - let x = quote_meta_item!(ecx, 3); - //~^ ERROR cannot find macro `quote_meta_item!` in this scope - let x = quote_path!(ecx, 3); - //~^ ERROR cannot find macro `quote_path!` in this scope -} diff --git a/src/test/ui-fulldeps/gated-quote.stderr b/src/test/ui-fulldeps/gated-quote.stderr deleted file mode 100644 index 897e97b7eb1..00000000000 --- a/src/test/ui-fulldeps/gated-quote.stderr +++ /dev/null @@ -1,80 +0,0 @@ -error: cannot find macro `quote_path!` in this scope - --> $DIR/gated-quote.rs:55:13 - | -LL | let x = quote_path!(ecx, 3); - | ^^^^^^^^^^ - -error: cannot find macro `quote_meta_item!` in this scope - --> $DIR/gated-quote.rs:53:13 - | -LL | let x = quote_meta_item!(ecx, 3); - | ^^^^^^^^^^^^^^^ - -error: cannot find macro `quote_block!` in this scope - --> $DIR/gated-quote.rs:51:13 - | -LL | let x = quote_block!(ecx, 3); - | ^^^^^^^^^^^ - -error: cannot find macro `quote_arg!` in this scope - --> $DIR/gated-quote.rs:49:13 - | -LL | let x = quote_arg!(ecx, 3); - | ^^^^^^^^^ - -error: cannot find macro `quote_attr!` in this scope - --> $DIR/gated-quote.rs:47:13 - | -LL | let x = quote_attr!(ecx, 3); - | ^^^^^^^^^^ - -error: cannot find macro `quote_stmt!` in this scope - --> $DIR/gated-quote.rs:45:13 - | -LL | let x = quote_stmt!(ecx, 3); - | ^^^^^^^^^^ - -error: cannot find macro `quote_arm!` in this scope - --> $DIR/gated-quote.rs:43:13 - | -LL | let x = quote_arm!(ecx, 3); - | ^^^^^^^^^ - -error: cannot find macro `quote_pat!` in this scope - --> $DIR/gated-quote.rs:41:13 - | -LL | let x = quote_pat!(ecx, 3); - | ^^^^^^^^^ - -error: cannot find macro `quote_item!` in this scope - --> $DIR/gated-quote.rs:39:13 - | -LL | let x = quote_item!(ecx, 3); - | ^^^^^^^^^^ - -error: cannot find macro `quote_method!` in this scope - --> $DIR/gated-quote.rs:37:13 - | -LL | let x = quote_method!(ecx, 3); - | ^^^^^^^^^^^^ - -error: cannot find macro `quote_ty!` in this scope - --> $DIR/gated-quote.rs:35:13 - | -LL | let x = quote_ty!(ecx, 3); - | ^^^^^^^^ - -error: cannot find macro `quote_expr!` in this scope - --> $DIR/gated-quote.rs:33:13 - | -LL | let x = quote_expr!(ecx, 3); - | ^^^^^^^^^^ - -error: cannot find macro `quote_tokens!` in this scope - --> $DIR/gated-quote.rs:31:13 - | -LL | let x = quote_tokens!(ecx, 3); - | ^^^^^^^^^^^^ - -error: aborting due to 13 previous errors - diff --git a/src/test/ui-fulldeps/issue-48941.rs b/src/test/ui-fulldeps/issue-48941.rs deleted file mode 100644 index 8c4c2445670..00000000000 --- a/src/test/ui-fulldeps/issue-48941.rs +++ /dev/null @@ -1,16 +0,0 @@ -// This is a regression test against an ICE that used to occur -// on malformed attributes for a custom MultiModifier. - -// aux-build:macro_crate_test.rs -// ignore-stage1 - -#![feature(plugin)] -#![plugin(macro_crate_test)] - -#[noop_attribute("hi", rank = a)] //~ ERROR expected unsuffixed literal or identifier, found a -fn knight() { } - -#[noop_attribute("/user", data= = " $DIR/issue-48941.rs:10:24 - | -LL | #[noop_attribute("hi", rank = a)] //~ ERROR expected unsuffixed literal or identifier, found a - | ^^^^ - -error: expected unsuffixed literal or identifier, found = - --> $DIR/issue-48941.rs:13:27 - | -LL | #[noop_attribute("/user", data= = " $DIR/macro-crate-doesnt-resolve.rs:7:23 - | -LL | macro_crate_test::foo(); //~ ERROR cannot find function `foo` in module `macro_crate_test` - | ^^^ not found in `macro_crate_test` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui-fulldeps/macro-crate-unexported-macro.rs b/src/test/ui-fulldeps/macro-crate-unexported-macro.rs deleted file mode 100644 index 8cf0cc4e4f3..00000000000 --- a/src/test/ui-fulldeps/macro-crate-unexported-macro.rs +++ /dev/null @@ -1,9 +0,0 @@ -// aux-build:macro_crate_test.rs - -#[macro_use] #[no_link] -extern crate macro_crate_test; - -fn main() { - unexported_macro!(); - //~^ ERROR cannot find macro `unexported_macro!` in this scope -} diff --git a/src/test/ui-fulldeps/macro-crate-unexported-macro.stderr b/src/test/ui-fulldeps/macro-crate-unexported-macro.stderr deleted file mode 100644 index 0d1b4b64fc5..00000000000 --- a/src/test/ui-fulldeps/macro-crate-unexported-macro.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: cannot find macro `unexported_macro!` in this scope - --> $DIR/macro-crate-unexported-macro.rs:7:5 - | -LL | unexported_macro!(); - | ^^^^^^^^^^^^^^^^ help: you could try the macro: `exported_macro` - -error: aborting due to previous error - diff --git a/src/test/ui-fulldeps/plugin-as-extern-crate.rs b/src/test/ui-fulldeps/plugin-as-extern-crate.rs index f192694dc73..37ac8dfa391 100644 --- a/src/test/ui-fulldeps/plugin-as-extern-crate.rs +++ b/src/test/ui-fulldeps/plugin-as-extern-crate.rs @@ -1,12 +1,12 @@ -// aux-build:macro_crate_test.rs +// aux-build:attr_plugin_test.rs // ignore-cross-compile // -// macro_crate_test will not compile on a cross-compiled target because +// attr_plugin_test will not compile on a cross-compiled target because // libsyntax is not compiled for it. #![deny(plugin_as_library)] #![allow(unused_extern_crates)] -extern crate macro_crate_test; //~ ERROR compiler plugin used as an ordinary library +extern crate attr_plugin_test; //~ ERROR compiler plugin used as an ordinary library fn main() { } diff --git a/src/test/ui-fulldeps/plugin-as-extern-crate.stderr b/src/test/ui-fulldeps/plugin-as-extern-crate.stderr index f0406d5181a..4a5a53980eb 100644 --- a/src/test/ui-fulldeps/plugin-as-extern-crate.stderr +++ b/src/test/ui-fulldeps/plugin-as-extern-crate.stderr @@ -1,7 +1,7 @@ error: compiler plugin used as an ordinary library --> $DIR/plugin-as-extern-crate.rs:10:1 | -LL | extern crate macro_crate_test; //~ ERROR compiler plugin used as an ordinary library +LL | extern crate attr_plugin_test; //~ ERROR compiler plugin used as an ordinary library | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: lint level defined here diff --git a/src/test/ui-fulldeps/plugin-plus-extern-crate.rs b/src/test/ui-fulldeps/plugin-plus-extern-crate.rs deleted file mode 100644 index db13954f8ed..00000000000 --- a/src/test/ui-fulldeps/plugin-plus-extern-crate.rs +++ /dev/null @@ -1,17 +0,0 @@ -// aux-build:macro_crate_test.rs -// ignore-stage1 -// ignore-cross-compile -// -// macro_crate_test will not compile on a cross-compiled target because -// libsyntax is not compiled for it. - -#![deny(plugin_as_library)] -#![feature(plugin)] -#![plugin(macro_crate_test)] - -extern crate macro_crate_test; //~ ERROR compiler plugin used as an ordinary library - -fn main() { - assert_eq!(1, make_a_1!()); - macro_crate_test::foo(); -} diff --git a/src/test/ui-fulldeps/plugin-plus-extern-crate.stderr b/src/test/ui-fulldeps/plugin-plus-extern-crate.stderr deleted file mode 100644 index 284d76b6132..00000000000 --- a/src/test/ui-fulldeps/plugin-plus-extern-crate.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: compiler plugin used as an ordinary library - --> $DIR/plugin-plus-extern-crate.rs:12:1 - | -LL | extern crate macro_crate_test; //~ ERROR compiler plugin used as an ordinary library - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: lint level defined here - --> $DIR/plugin-plus-extern-crate.rs:8:9 - | -LL | #![deny(plugin_as_library)] - | ^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui-fulldeps/qquote.rs b/src/test/ui-fulldeps/qquote.rs deleted file mode 100644 index 99e365d21ff..00000000000 --- a/src/test/ui-fulldeps/qquote.rs +++ /dev/null @@ -1,27 +0,0 @@ -// ignore-cross-compile - -#![feature(quote, rustc_private)] - -extern crate syntax; -extern crate syntax_pos; - -use syntax::ast; -use syntax::source_map::FilePathMapping; -use syntax::print::pprust; -use syntax::symbol::Symbol; -use syntax_pos::DUMMY_SP; - -fn main() { - let ps = syntax::parse::ParseSess::new(FilePathMapping::empty()); - let mut resolver = syntax::ext::base::DummyResolver; - let mut cx = syntax::ext::base::ExtCtxt::new( - &ps, - syntax::ext::expand::ExpansionConfig::default("qquote".to_string()), - &mut resolver); - let cx = &mut cx; - - assert_eq!(pprust::expr_to_string(&*quote_expr!(&cx, 23)), "23"); - - let expr = quote_expr!(&cx, 2 - $abcd + 7); //~ ERROR cannot find value `abcd` in this scope - assert_eq!(pprust::expr_to_string(&*expr), "2 - $abcd + 7"); -} diff --git a/src/test/ui-fulldeps/qquote.stderr b/src/test/ui-fulldeps/qquote.stderr deleted file mode 100644 index a51318b0edc..00000000000 --- a/src/test/ui-fulldeps/qquote.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0425]: cannot find value `abcd` in this scope - --> $DIR/qquote.rs:25:38 - | -LL | let expr = quote_expr!(&cx, 2 - $abcd + 7); //~ ERROR cannot find value `abcd` in this scope - | ^^^^ not found in this scope - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/quote-with-interpolated.rs b/src/test/ui/quote-with-interpolated.rs deleted file mode 100644 index b948226652b..00000000000 --- a/src/test/ui/quote-with-interpolated.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(quote)] -fn main() { - macro_rules! foo { - ($bar:expr) => { - quote_expr!(cx, $bar) - //~^ ERROR quote! with interpolated token - //~| ERROR failed to resolve: maybe a missing `extern crate syntax;`? - //~| ERROR failed to resolve: maybe a missing `extern crate syntax;`? - //~| ERROR cannot find value `cx` in this scope - //~| ERROR cannot find function `new_parser_from_tts` in this scope - } - } - foo!(bar); -} diff --git a/src/test/ui/quote-with-interpolated.stderr b/src/test/ui/quote-with-interpolated.stderr deleted file mode 100644 index 96feff949bf..00000000000 --- a/src/test/ui/quote-with-interpolated.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: quote! with interpolated token - --> $DIR/quote-with-interpolated.rs:5:29 - | -LL | quote_expr!(cx, $bar) - | ^^^^ -... -LL | foo!(bar); - | ---------- in this macro invocation - -error[E0433]: failed to resolve: maybe a missing `extern crate syntax;`? - --> $DIR/quote-with-interpolated.rs:5:13 - | -LL | quote_expr!(cx, $bar) - | ^^^^^^^^^^^^^^^^^^^^^ maybe a missing `extern crate syntax;`? - -error[E0433]: failed to resolve: maybe a missing `extern crate syntax;`? - --> $DIR/quote-with-interpolated.rs:5:29 - | -LL | quote_expr!(cx, $bar) - | ^^^^ maybe a missing `extern crate syntax;`? - -error[E0425]: cannot find value `cx` in this scope - --> $DIR/quote-with-interpolated.rs:5:25 - | -LL | quote_expr!(cx, $bar) - | ^^ not found in this scope -... -LL | foo!(bar); - | ---------- in this macro invocation - -error[E0425]: cannot find function `new_parser_from_tts` in this scope - --> $DIR/quote-with-interpolated.rs:5:13 - | -LL | quote_expr!(cx, $bar) - | ^^^^^^^^^^^^^^^^^^^^^ not found in this scope - -error: aborting due to 5 previous errors - -Some errors occurred: E0425, E0433. -For more information about an error, try `rustc --explain E0425`.