diff options
| author | Peter <peter.wilkins@polecat.com> | 2019-12-08 23:16:18 +0000 |
|---|---|---|
| committer | Peter <peter.wilkins@polecat.com> | 2019-12-08 23:49:30 +0000 |
| commit | 8f6a06285efe12d778ff7f44067aebeed7b14428 (patch) | |
| tree | 856b9d17a8e4700c44a2794e63ec75ecf9660397 /src/libsyntax_ext | |
| parent | 947772fc31b96ce90f57720f74571f14e35df66b (diff) | |
| parent | 59947fcae6a40df12e33af8c8c7291014b7603e0 (diff) | |
| download | rust-8f6a06285efe12d778ff7f44067aebeed7b14428.tar.gz rust-8f6a06285efe12d778ff7f44067aebeed7b14428.zip | |
move from non zero impls to `libcore/convert/num.rs`
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/Cargo.toml | 3 | ||||
| -rw-r--r-- | src/libsyntax_ext/asm.rs | 40 | ||||
| -rw-r--r-- | src/libsyntax_ext/assert.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax_ext/cmdline_attrs.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/default.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax_ext/error_codes.rs | 120 | ||||
| -rw-r--r-- | src/libsyntax_ext/format.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax_ext/format_foreign.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax_ext/lib.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax_ext/plugin_macro_defs.rs | 58 | ||||
| -rw-r--r-- | src/libsyntax_ext/proc_macro_harness.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax_ext/source_util.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax_ext/test_harness.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax_ext/util.rs | 5 |
15 files changed, 87 insertions, 250 deletions
diff --git a/src/libsyntax_ext/Cargo.toml b/src/libsyntax_ext/Cargo.toml index 703d51e1c4c..d73a9ea6cdb 100644 --- a/src/libsyntax_ext/Cargo.toml +++ b/src/libsyntax_ext/Cargo.toml @@ -14,8 +14,11 @@ errors = { path = "../librustc_errors", package = "rustc_errors" } fmt_macros = { path = "../libfmt_macros" } log = "0.4" rustc_data_structures = { path = "../librustc_data_structures" } +rustc_feature = { path = "../librustc_feature" } +rustc_parse = { path = "../librustc_parse" } rustc_target = { path = "../librustc_target" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } syntax = { path = "../libsyntax" } syntax_expand = { path = "../libsyntax_expand" } syntax_pos = { path = "../libsyntax_pos" } +rustc_error_codes = { path = "../librustc_error_codes" } diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 539d777105d..bd345a9a7da 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -2,19 +2,19 @@ // use State::*; +use errors::{DiagnosticBuilder, PResult}; use rustc_data_structures::thin_vec::ThinVec; - -use errors::DiagnosticBuilder; - -use syntax::ast; -use syntax_expand::base::{self, *}; -use syntax::token::{self, Token}; +use rustc_parse::parser::Parser; +use syntax_expand::base::*; +use syntax_pos::Span; +use syntax::{span_err, struct_span_err}; +use syntax::ast::{self, AsmDialect}; use syntax::ptr::P; use syntax::symbol::{kw, sym, Symbol}; -use syntax::ast::AsmDialect; -use syntax_pos::Span; +use syntax::token::{self, Token}; use syntax::tokenstream::{self, TokenStream}; -use syntax::{span_err, struct_span_err}; + +use rustc_error_codes::*; enum State { Asm, @@ -43,7 +43,7 @@ const OPTIONS: &[Symbol] = &[sym::volatile, sym::alignstack, sym::intel]; pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) - -> Box<dyn base::MacResult + 'cx> { + -> Box<dyn MacResult + 'cx> { let mut inline_asm = match parse_inline_asm(cx, sp, tts) { Ok(Some(inline_asm)) => inline_asm, Ok(None) => return DummyResult::any(sp), @@ -67,6 +67,18 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>, })) } +fn parse_asm_str<'a>(p: &mut Parser<'a>) -> PResult<'a, Symbol> { + match p.parse_str_lit() { + Ok(str_lit) => Ok(str_lit.symbol_unescaped), + Err(opt_lit) => { + let span = opt_lit.map_or(p.token.span, |lit| lit.span); + let mut err = p.sess.span_diagnostic.struct_span_err(span, "expected string literal"); + err.span_label(span, "not a string literal"); + Err(err) + } + } +} + fn parse_inline_asm<'a>( cx: &mut ExtCtxt<'a>, sp: Span, @@ -142,7 +154,7 @@ fn parse_inline_asm<'a>( p.eat(&token::Comma); } - let (constraint, _) = p.parse_str()?; + let constraint = parse_asm_str(&mut p)?; let span = p.prev_span; @@ -187,7 +199,7 @@ fn parse_inline_asm<'a>( p.eat(&token::Comma); } - let (constraint, _) = p.parse_str()?; + let constraint = parse_asm_str(&mut p)?; if constraint.as_str().starts_with("=") { span_err!(cx, p.prev_span, E0662, @@ -210,7 +222,7 @@ fn parse_inline_asm<'a>( p.eat(&token::Comma); } - let (s, _) = p.parse_str()?; + let s = parse_asm_str(&mut p)?; if OPTIONS.iter().any(|&opt| s == opt) { cx.span_warn(p.prev_span, "expected a clobber, found an option"); @@ -223,7 +235,7 @@ fn parse_inline_asm<'a>( } } Options => { - let (option, _) = p.parse_str()?; + let option = parse_asm_str(&mut p)?; if option == sym::volatile { // Indicates that the inline assembly has side effects diff --git a/src/libsyntax_ext/assert.rs b/src/libsyntax_ext/assert.rs index a15423b7ad8..c788d062994 100644 --- a/src/libsyntax_ext/assert.rs +++ b/src/libsyntax_ext/assert.rs @@ -1,13 +1,13 @@ use errors::{Applicability, DiagnosticBuilder}; +use rustc_parse::parser::Parser; use syntax::ast::{self, *}; -use syntax_expand::base::*; use syntax::token::{self, TokenKind}; -use syntax::parse::parser::Parser; use syntax::print::pprust; use syntax::ptr::P; use syntax::symbol::{sym, Symbol}; -use syntax::tokenstream::{TokenStream, TokenTree}; +use syntax::tokenstream::{DelimSpan, TokenStream, TokenTree}; +use syntax_expand::base::*; use syntax_pos::{Span, DUMMY_SP}; pub fn expand_assert<'cx>( @@ -26,19 +26,19 @@ pub fn expand_assert<'cx>( // `core::panic` and `std::panic` are different macros, so we use call-site // context to pick up whichever is currently in scope. let sp = cx.with_call_site_ctxt(sp); + let tokens = custom_message.unwrap_or_else(|| { + TokenStream::from(TokenTree::token( + TokenKind::lit(token::Str, Symbol::intern(&format!( + "assertion failed: {}", + pprust::expr_to_string(&cond_expr).escape_debug() + )), None), + DUMMY_SP, + )) + }); + let args = P(MacArgs::Delimited(DelimSpan::from_single(sp), MacDelimiter::Parenthesis, tokens)); let panic_call = Mac { path: Path::from_ident(Ident::new(sym::panic, sp)), - tts: custom_message.unwrap_or_else(|| { - TokenStream::from(TokenTree::token( - TokenKind::lit(token::Str, Symbol::intern(&format!( - "assertion failed: {}", - pprust::expr_to_string(&cond_expr).escape_debug() - )), None), - DUMMY_SP, - )) - }).into(), - delim: MacDelimiter::Parenthesis, - span: sp, + args, prior_type_ascription: None, }; let if_expr = cx.expr_if( diff --git a/src/libsyntax_ext/cmdline_attrs.rs b/src/libsyntax_ext/cmdline_attrs.rs index 171f2405573..98cf8a34742 100644 --- a/src/libsyntax_ext/cmdline_attrs.rs +++ b/src/libsyntax_ext/cmdline_attrs.rs @@ -2,7 +2,6 @@ use syntax::ast::{self, AttrItem, AttrStyle}; use syntax::attr::mk_attr; -use syntax::parse; use syntax::token; use syntax::sess::ParseSess; use syntax_expand::panictry; @@ -10,14 +9,14 @@ use syntax_pos::FileName; pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -> ast::Crate { for raw_attr in attrs { - let mut parser = parse::new_parser_from_source_str( + let mut parser = rustc_parse::new_parser_from_source_str( parse_sess, FileName::cli_crate_attr_source_code(&raw_attr), raw_attr.clone(), ); let start_span = parser.token.span; - let AttrItem { path, tokens } = panictry!(parser.parse_attr_item()); + let AttrItem { path, args } = panictry!(parser.parse_attr_item()); let end_span = parser.token.span; if parser.token != token::Eof { parse_sess.span_diagnostic @@ -25,7 +24,7 @@ pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) - continue; } - krate.attrs.push(mk_attr(AttrStyle::Inner, path, tokens, start_span.to(end_span))); + krate.attrs.push(mk_attr(AttrStyle::Inner, path, args, start_span.to(end_span))); } krate diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index cfc0f3cd6cb..ab57f395f6a 100644 --- a/src/libsyntax_ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -9,6 +9,8 @@ use syntax::symbol::{kw, sym}; use syntax::span_err; use syntax_pos::Span; +use rustc_error_codes::*; + pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>, span: Span, mitem: &MetaItem, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index b24306def74..5bd84b43a78 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -182,7 +182,7 @@ use std::iter; use std::vec; use rustc_data_structures::thin_vec::ThinVec; -use syntax::ast::{self, Abi, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; +use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind}; use syntax::ast::{VariantData, GenericParamKind, GenericArg}; use syntax::attr; use syntax::source_map::respan; @@ -340,14 +340,12 @@ pub fn combine_substructure(f: CombineSubstructureFunc<'_>) fn find_type_parameters( ty: &ast::Ty, ty_param_names: &[ast::Name], - span: Span, cx: &ExtCtxt<'_>, ) -> Vec<P<ast::Ty>> { use syntax::visit; struct Visitor<'a, 'b> { cx: &'a ExtCtxt<'b>, - span: Span, ty_param_names: &'a [ast::Name], types: Vec<P<ast::Ty>>, } @@ -366,18 +364,11 @@ fn find_type_parameters( } fn visit_mac(&mut self, mac: &ast::Mac) { - let span = mac.span.with_ctxt(self.span.ctxt()); - self.cx.span_err(span, "`derive` cannot be used on items with type macros"); + self.cx.span_err(mac.span(), "`derive` cannot be used on items with type macros"); } } - let mut visitor = Visitor { - ty_param_names, - types: Vec::new(), - span, - cx, - }; - + let mut visitor = Visitor { cx, ty_param_names, types: Vec::new() }; visit::Visitor::visit_ty(&mut visitor, ty); visitor.types @@ -605,7 +596,7 @@ impl<'a> TraitDef<'a> { .collect(); for field_ty in field_tys { - let tys = find_type_parameters(&field_ty, &ty_param_names, self.span, cx); + let tys = find_type_parameters(&field_ty, &ty_param_names, cx); for ty in tys { // if we have already handled this type, skip it @@ -737,7 +728,6 @@ impl<'a> TraitDef<'a> { self, type_ident, generics, - sym::Rust, explicit_self, tys, body) @@ -792,7 +782,6 @@ impl<'a> TraitDef<'a> { self, type_ident, generics, - sym::Rust, explicit_self, tys, body) @@ -918,7 +907,6 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'_>, type_ident: Ident, generics: &Generics, - abi: Symbol, explicit_self: Option<ast::ExplicitSelf>, arg_types: Vec<(Ident, P<ast::Ty>)>, body: P<Expr>) @@ -953,7 +941,7 @@ impl<'a> MethodDef<'a> { let sig = ast::FnSig { header: ast::FnHeader { unsafety, - abi: Abi::new(abi, trait_lo_sp), + ext: ast::Extern::None, ..ast::FnHeader::default() }, decl: fn_decl, diff --git a/src/libsyntax_ext/error_codes.rs b/src/libsyntax_ext/error_codes.rs deleted file mode 100644 index 2bc990574f7..00000000000 --- a/src/libsyntax_ext/error_codes.rs +++ /dev/null @@ -1,120 +0,0 @@ -// Error messages for EXXXX errors. -// Each message should start and end with a new line, and be wrapped to 80 -// characters. In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use -// `:set tw=0` to disable. -syntax::register_diagnostics! { -E0660: r##" -The argument to the `asm` macro is not well-formed. - -Erroneous code example: - -```compile_fail,E0660 -asm!("nop" "nop"); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0661: r##" -An invalid syntax was passed to the second argument of an `asm` macro line. - -Erroneous code example: - -```compile_fail,E0661 -let a; -asm!("nop" : "r"(a)); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0662: r##" -An invalid input operand constraint was passed to the `asm` macro (third line). - -Erroneous code example: - -```compile_fail,E0662 -asm!("xor %eax, %eax" - : - : "=test"("a") - ); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0663: r##" -An invalid input operand constraint was passed to the `asm` macro (third line). - -Erroneous code example: - -```compile_fail,E0663 -asm!("xor %eax, %eax" - : - : "+test"("a") - ); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0664: r##" -A clobber was surrounded by braces in the `asm` macro. - -Erroneous code example: - -```compile_fail,E0664 -asm!("mov $$0x200, %eax" - : - : - : "{eax}" - ); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0665: r##" -The `Default` trait was derived on an enum. - -Erroneous code example: - -```compile_fail,E0665 -#[derive(Default)] -enum Food { - Sweet, - Salty, -} -``` - -The `Default` cannot be derived on an enum for the simple reason that the -compiler doesn't know which value to pick by default whereas it can for a -struct as long as all its fields implement the `Default` trait as well. - -If you still want to implement `Default` on your enum, you'll have to do it "by -hand": - -``` -enum Food { - Sweet, - Salty, -} - -impl Default for Food { - fn default() -> Food { - Food::Sweet - } -} -``` -"##, -} diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 25daca9237f..0a19d64200c 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -172,7 +172,8 @@ fn parse_args<'a>( let e = p.parse_expr()?; if let Some(prev) = names.get(&name) { ecx.struct_span_err(e.span, &format!("duplicate argument named `{}`", name)) - .span_note(args[*prev].span, "previously here") + .span_label(args[*prev].span, "previously here") + .span_label(e.span, "duplicate argument") .emit(); continue; } diff --git a/src/libsyntax_ext/format_foreign.rs b/src/libsyntax_ext/format_foreign.rs index 3d4f8276441..0d1d2926c85 100644 --- a/src/libsyntax_ext/format_foreign.rs +++ b/src/libsyntax_ext/format_foreign.rs @@ -95,12 +95,12 @@ pub mod printf { }; // Has a special form in Rust for numbers. - let fill = if c_zero { Some("0") } else { None }; + let fill = c_zero.then_some("0"); - let align = if c_left { Some("<") } else { None }; + let align = c_left.then_some("<"); // Rust doesn't have an equivalent to the `' '` flag. - let sign = if c_plus { Some("+") } else { None }; + let sign = c_plus.then_some("+"); // Not *quite* the same, depending on the type... let alt = c_alt; diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 5516f276422..55c7f3fa574 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -3,6 +3,7 @@ #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")] +#![feature(bool_to_option)] #![feature(crate_visibility_modifier)] #![feature(decl_macro)] #![feature(nll)] @@ -19,8 +20,6 @@ use syntax::symbol::sym; use syntax_expand::base::{Resolver, SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn}; use syntax_expand::proc_macro::BangProcMacro; -mod error_codes; - mod asm; mod assert; mod cfg; @@ -40,7 +39,6 @@ mod trace_macros; mod util; pub mod cmdline_attrs; -pub mod plugin_macro_defs; pub mod proc_macro_harness; pub mod standard_library_imports; pub mod test_harness; diff --git a/src/libsyntax_ext/plugin_macro_defs.rs b/src/libsyntax_ext/plugin_macro_defs.rs deleted file mode 100644 index cee1b97af55..00000000000 --- a/src/libsyntax_ext/plugin_macro_defs.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! Each macro must have a definition, so `#[plugin]` attributes -//! inject a dummy `macro_rules` item for each macro they define. - -use syntax::ast::*; -use syntax::attr; -use syntax::edition::Edition; -use syntax::ptr::P; -use syntax::source_map::respan; -use syntax::symbol::sym; -use syntax::token; -use syntax::tokenstream::*; -use syntax_expand::base::{Resolver, NamedSyntaxExtension}; -use syntax_pos::{Span, DUMMY_SP}; -use syntax_pos::hygiene::{ExpnData, ExpnKind, AstPass}; - -use std::mem; - -fn plugin_macro_def(name: Name, span: Span) -> P<Item> { - let rustc_builtin_macro = attr::mk_attr_outer( - attr::mk_word_item(Ident::new(sym::rustc_builtin_macro, span))); - - let parens: TreeAndJoint = TokenTree::Delimited( - DelimSpan::from_single(span), token::Paren, TokenStream::default() - ).into(); - let trees = vec![parens.clone(), TokenTree::token(token::FatArrow, span).into(), parens]; - - P(Item { - ident: Ident::new(name, span), - attrs: vec![rustc_builtin_macro], - id: DUMMY_NODE_ID, - kind: ItemKind::MacroDef(MacroDef { tokens: TokenStream::new(trees), legacy: true }), - vis: respan(span, VisibilityKind::Inherited), - span: span, - tokens: None, - }) -} - -pub fn inject( - krate: &mut Crate, - resolver: &mut dyn Resolver, - named_exts: Vec<NamedSyntaxExtension>, - edition: Edition, -) { - if !named_exts.is_empty() { - let mut extra_items = Vec::new(); - let span = DUMMY_SP.fresh_expansion(ExpnData::allow_unstable( - ExpnKind::AstPass(AstPass::PluginMacroDefs), DUMMY_SP, edition, - [sym::rustc_attrs][..].into(), - )); - for (name, ext) in named_exts { - resolver.register_builtin_macro(Ident::with_dummy_span(name), ext); - extra_items.push(plugin_macro_def(name, span)); - } - // The `macro_rules` items must be inserted before any other items. - mem::swap(&mut extra_items, &mut krate.module.items); - krate.module.items.append(&mut extra_items); - } -} diff --git a/src/libsyntax_ext/proc_macro_harness.rs b/src/libsyntax_ext/proc_macro_harness.rs index 792c97d8508..604400c3cc2 100644 --- a/src/libsyntax_ext/proc_macro_harness.rs +++ b/src/libsyntax_ext/proc_macro_harness.rs @@ -92,10 +92,12 @@ pub fn inject(sess: &ParseSess, impl<'a> CollectProcMacros<'a> { fn check_not_pub_in_root(&self, vis: &ast::Visibility, sp: Span) { if self.is_proc_macro_crate && self.in_root && vis.node.is_pub() { - self.handler.span_err(sp, - "`proc-macro` crate types cannot \ - export any items other than functions \ - tagged with `#[proc_macro_derive]` currently"); + self.handler.span_err( + sp, + "`proc-macro` crate types currently cannot export any items other \ + than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, \ + or `#[proc_macro_attribute]`", + ); } } @@ -268,7 +270,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> { }; self.handler.struct_span_err(attr.span, &msg) - .span_note(prev_attr.span, "previous attribute here") + .span_label(prev_attr.span, "previous attribute here") .emit(); return; diff --git a/src/libsyntax_ext/source_util.rs b/src/libsyntax_ext/source_util.rs index 7e47b40714d..4aab68d7c0e 100644 --- a/src/libsyntax_ext/source_util.rs +++ b/src/libsyntax_ext/source_util.rs @@ -1,13 +1,13 @@ -use syntax_expand::panictry; -use syntax_expand::base::{self, *}; +use rustc_parse::{self, DirectoryOwnership, new_sub_parser_from_file, parser::Parser}; use syntax::ast; -use syntax::parse::{self, DirectoryOwnership}; use syntax::print::pprust; use syntax::ptr::P; use syntax::symbol::Symbol; use syntax::token; use syntax::tokenstream::TokenStream; -use syntax::early_buffered_lints::BufferedEarlyLintId; +use syntax::early_buffered_lints::INCOMPLETE_INCLUDE; +use syntax_expand::panictry; +use syntax_expand::base::{self, *}; use smallvec::SmallVec; use syntax_pos::{self, Pos, Span}; @@ -21,6 +21,7 @@ use rustc_data_structures::sync::Lrc; /// line!(): expands to the current line number pub fn expand_line(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) -> Box<dyn base::MacResult+'static> { + let sp = cx.with_def_site_ctxt(sp); base::check_zero_tts(cx, sp, tts, "line!"); let topmost = cx.expansion_cause().unwrap_or(sp); @@ -32,6 +33,7 @@ pub fn expand_line(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) /* column!(): expands to the current column number */ pub fn expand_column(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) -> Box<dyn base::MacResult+'static> { + let sp = cx.with_def_site_ctxt(sp); base::check_zero_tts(cx, sp, tts, "column!"); let topmost = cx.expansion_cause().unwrap_or(sp); @@ -45,6 +47,7 @@ pub fn expand_column(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) /// out if we wanted. pub fn expand_file(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) -> Box<dyn base::MacResult+'static> { + let sp = cx.with_def_site_ctxt(sp); base::check_zero_tts(cx, sp, tts, "file!"); let topmost = cx.expansion_cause().unwrap_or(sp); @@ -54,12 +57,14 @@ pub fn expand_file(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) pub fn expand_stringify(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) -> Box<dyn base::MacResult+'static> { + let sp = cx.with_def_site_ctxt(sp); let s = pprust::tts_to_string(tts); base::MacEager::expr(cx.expr_str(sp, Symbol::intern(&s))) } pub fn expand_mod(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) -> Box<dyn base::MacResult+'static> { + let sp = cx.with_def_site_ctxt(sp); base::check_zero_tts(cx, sp, tts, "module_path!"); let mod_path = &cx.current_expansion.module.mod_path; let string = mod_path.iter().map(|x| x.to_string()).collect::<Vec<String>>().join("::"); @@ -72,6 +77,7 @@ pub fn expand_mod(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) /// unhygienically. pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) -> Box<dyn base::MacResult+'cx> { + let sp = cx.with_def_site_ctxt(sp); let file = match get_single_str_from_tts(cx, sp, tts, "include!") { Some(f) => f, None => return DummyResult::any(sp), @@ -85,17 +91,17 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) }, }; let directory_ownership = DirectoryOwnership::Owned { relative: None }; - let p = parse::new_sub_parser_from_file(cx.parse_sess(), &file, directory_ownership, None, sp); + let p = new_sub_parser_from_file(cx.parse_sess(), &file, directory_ownership, None, sp); struct ExpandResult<'a> { - p: parse::parser::Parser<'a>, + p: Parser<'a>, } impl<'a> base::MacResult for ExpandResult<'a> { fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> { let r = panictry!(self.p.parse_expr()); if self.p.token != token::Eof { self.p.sess.buffer_lint( - BufferedEarlyLintId::IncompleteInclude, + &INCOMPLETE_INCLUDE, self.p.token.span, ast::CRATE_NODE_ID, "include macro expected single expression in source", @@ -125,6 +131,7 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) // include_str! : read the given file, insert it as a literal string expr pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) -> Box<dyn base::MacResult+'static> { + let sp = cx.with_def_site_ctxt(sp); let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") { Some(f) => f, None => return DummyResult::any(sp) @@ -156,6 +163,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) pub fn expand_include_bytes(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) -> Box<dyn base::MacResult+'static> { + let sp = cx.with_def_site_ctxt(sp); let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") { Some(f) => f, None => return DummyResult::any(sp) diff --git a/src/libsyntax_ext/test_harness.rs b/src/libsyntax_ext/test_harness.rs index 1492f6f575f..4c1eec38c6e 100644 --- a/src/libsyntax_ext/test_harness.rs +++ b/src/libsyntax_ext/test_harness.rs @@ -2,13 +2,13 @@ use log::debug; use smallvec::{smallvec, SmallVec}; +use rustc_feature::Features; use rustc_target::spec::PanicStrategy; use syntax::ast::{self, Ident}; use syntax::attr; use syntax::entry::{self, EntryPointType}; use syntax_expand::base::{ExtCtxt, Resolver}; use syntax_expand::expand::{AstFragment, ExpansionConfig}; -use syntax::feature_gate::Features; use syntax::mut_visit::{*, ExpectOne}; use syntax::ptr::P; use syntax::sess::ParseSess; @@ -67,7 +67,8 @@ pub fn inject( PanicStrategy::Unwind } (PanicStrategy::Abort, false) => { - span_diagnostic.err("building tests with panic=abort is not yet supported"); + span_diagnostic.err("building tests with panic=abort is not supported \ + without `-Zpanic_abort_tests`"); PanicStrategy::Unwind } (PanicStrategy::Unwind, _) => PanicStrategy::Unwind, diff --git a/src/libsyntax_ext/util.rs b/src/libsyntax_ext/util.rs index d84fe19b3ea..f7bd9a05604 100644 --- a/src/libsyntax_ext/util.rs +++ b/src/libsyntax_ext/util.rs @@ -1,11 +1,12 @@ +use rustc_parse::validate_attr; +use rustc_feature::AttributeTemplate; use syntax_pos::Symbol; use syntax::ast::MetaItem; -use syntax::attr::{check_builtin_attribute, AttributeTemplate}; use syntax_expand::base::ExtCtxt; pub fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaItem, name: Symbol) { // All the built-in macro attributes are "words" at the moment. let template = AttributeTemplate::only_word(); let attr = ecx.attribute(meta_item.clone()); - check_builtin_attribute(ecx.parse_sess, &attr, name, template); + validate_attr::check_builtin_attribute(ecx.parse_sess, &attr, name, template); } |
