Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6876f9b
filter linkcheck spurious failure
mark-i-m Aug 26, 2019
2e59c4a
fix bugs + review comments
mark-i-m Aug 29, 2019
3f6db84
actually compiles now?
mark-i-m Aug 30, 2019
0133941
Add an ExpnKind for AST passes
matthewjasper Aug 25, 2019
4082cd9
Allow ast passes to create hygienic spans
matthewjasper Aug 25, 2019
6fcdb36
Make use of hygiene in AST passes
matthewjasper Aug 25, 2019
2a82aec
Move tests for unit tests to their own directory
matthewjasper Aug 25, 2019
beb2f5b
Remove `Ident::{gensym, is_gensymed}`
matthewjasper Aug 25, 2019
846df20
Fix 2018 edition expanded pretty printing
matthewjasper Aug 25, 2019
0b86782
Don't call `diag_span_note_once` for suppressed lints
matthewjasper Aug 27, 2019
c8cf9f5
Add `with_{def_site,call_site,legacy}_ctxt,` methods to `Span`
petrochenkov Aug 28, 2019
e552840
Document test harness generation
matthewjasper Aug 28, 2019
afcf9b2
Bail out when encountering likely missing turbofish in parser
estebank Sep 5, 2019
3f3fc52
Simplify std lib injection
matthewjasper Sep 5, 2019
bad8147
fix reviewer comments
mark-i-m Sep 5, 2019
dc613c6
Fix test
estebank Sep 5, 2019
eedf555
rustc_codegen_llvm: give names to non-alloca variable values.
eddyb Sep 4, 2019
10f46b6
Move the HIR cfg to `rustc_ast_borrowck`
matthewjasper Sep 6, 2019
f6481ed
Correct pluralisation of various diagnostic messages
varkor Sep 6, 2019
0b97726
Update ui tests
varkor Sep 6, 2019
055d379
reduce visibility
matklad Aug 31, 2019
a26ee85
Include compiler-rt in the source tarball
maurer Sep 6, 2019
7dd5c66
Added more prereqs and note about default directory
Sep 6, 2019
3dde650
Move injection of attributes from command line to `libsyntax_ext`
petrochenkov Sep 6, 2019
db493ef
Rollup merge of #63919 - matthewjasper:remove-gensymmed, r=petrochenkov
Centril Sep 7, 2019
7dcac19
Rollup merge of #63927 - mark-i-m:filter-spurious, r=ehuss
Centril Sep 7, 2019
da61325
Rollup merge of #64149 - eddyb:llvm-var-names, r=rkruppe
Centril Sep 7, 2019
fae7bc7
Rollup merge of #64192 - estebank:turbofish-madness, r=petrochenkov
Centril Sep 7, 2019
84cb352
Rollup merge of #64231 - matthewjasper:move-ast-cfg, r=Centril
Centril Sep 7, 2019
d5caeac
Rollup merge of #64233 - varkor:correct-pluralisation, r=estebank
Centril Sep 7, 2019
e6a7689
Rollup merge of #64236 - matklad:reduce-visibility, r=Centril
Centril Sep 7, 2019
e77ba6f
Rollup merge of #64240 - maurer:include-compiler-rt, r=alexcrichton
Centril Sep 7, 2019
69121f5
Rollup merge of #64241 - adityaatluri:install-doc, r=Mark-Simulacrum
Centril Sep 7, 2019
3d4cb50
Rollup merge of #64243 - petrochenkov:cmdattr, r=alexcrichton
Centril Sep 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move injection of attributes from command line to libsyntax_ext
  • Loading branch information
petrochenkov committed Sep 6, 2019
commit 3dde650efa3a8910cccaef38e89fe74272d67c91
4 changes: 3 additions & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ pub fn register_plugins<'a>(
crate_name: &str,
) -> Result<(ast::Crate, PluginInfo)> {
krate = time(sess, "attributes injection", || {
syntax::attr::inject(krate, &sess.parse_sess, &sess.opts.debugging_opts.crate_attr)
syntax_ext::cmdline_attrs::inject(
krate, &sess.parse_sess, &sess.opts.debugging_opts.crate_attr
)
});

let (mut krate, features) = syntax::config::features(
Expand Down
59 changes: 13 additions & 46 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::mut_visit::visit_clobber;
use crate::source_map::{BytePos, Spanned, DUMMY_SP};
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
use crate::parse::parser::Parser;
use crate::parse::{self, ParseSess, PResult};
use crate::parse::{ParseSess, PResult};
use crate::parse::token::{self, Token};
use crate::ptr::P;
use crate::symbol::{sym, Symbol};
Expand All @@ -25,7 +25,7 @@ use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};
use crate::GLOBALS;

use log::debug;
use syntax_pos::{FileName, Span};
use syntax_pos::Span;

use std::iter;
use std::ops::DerefMut;
Expand Down Expand Up @@ -381,28 +381,25 @@ crate fn mk_attr_id() -> AttrId {
AttrId(id)
}

/// Returns an inner attribute with the given value and span.
pub fn mk_attr_inner(item: MetaItem) -> Attribute {
pub fn mk_attr(style: AttrStyle, path: Path, tokens: TokenStream, span: Span) -> Attribute {
Attribute {
id: mk_attr_id(),
style: ast::AttrStyle::Inner,
path: item.path,
tokens: item.node.tokens(item.span),
style,
path,
tokens,
is_sugared_doc: false,
span: item.span,
span,
}
}

/// Returns an inner attribute with the given value and span.
pub fn mk_attr_inner(item: MetaItem) -> Attribute {
mk_attr(AttrStyle::Inner, item.path, item.node.tokens(item.span), item.span)
}

/// Returns an outer attribute with the given value and span.
pub fn mk_attr_outer(item: MetaItem) -> Attribute {
Attribute {
id: mk_attr_id(),
style: ast::AttrStyle::Outer,
path: item.path,
tokens: item.node.tokens(item.span),
is_sugared_doc: false,
span: item.span,
}
mk_attr(AttrStyle::Outer, item.path, item.node.tokens(item.span), item.span)
}

pub fn mk_sugared_doc_attr(text: Symbol, span: Span) -> Attribute {
Expand Down Expand Up @@ -716,33 +713,3 @@ derive_has_attrs! {
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::ImplItem, ast::TraitItem, ast::Arm,
ast::Field, ast::FieldPat, ast::Variant, ast::Param
}

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(
parse_sess,
FileName::cli_crate_attr_source_code(&raw_attr),
raw_attr.clone(),
);

let start_span = parser.token.span;
let (path, tokens) = panictry!(parser.parse_meta_item_unrestricted());
let end_span = parser.token.span;
if parser.token != token::Eof {
parse_sess.span_diagnostic
.span_err(start_span.to(end_span), "invalid crate attribute");
continue;
}

krate.attrs.push(Attribute {
id: mk_attr_id(),
style: AttrStyle::Inner,
path,
tokens,
is_sugared_doc: false,
span: start_span.to(end_span),
});
}

krate
}
2 changes: 1 addition & 1 deletion src/libsyntax/parse/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'a> Parser<'a> {
/// PATH
/// PATH `=` TOKEN_TREE
/// The delimiters or `=` are still put into the resulting token stream.
crate fn parse_meta_item_unrestricted(&mut self) -> PResult<'a, (ast::Path, TokenStream)> {
pub fn parse_meta_item_unrestricted(&mut self) -> PResult<'a, (ast::Path, TokenStream)> {
let meta = match self.token.kind {
token::Interpolated(ref nt) => match **nt {
Nonterminal::NtMeta(ref meta) => Some(meta.clone()),
Expand Down
30 changes: 30 additions & 0 deletions src/libsyntax_ext/cmdline_attrs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Attributes injected into the crate root from command line using `-Z crate-attr`.

use syntax::ast::{self, AttrStyle};
use syntax::attr::mk_attr;
use syntax::panictry;
use syntax::parse::{self, token, ParseSess};
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(
parse_sess,
FileName::cli_crate_attr_source_code(&raw_attr),
raw_attr.clone(),
);

let start_span = parser.token.span;
let (path, tokens) = panictry!(parser.parse_meta_item_unrestricted());
let end_span = parser.token.span;
if parser.token != token::Eof {
parse_sess.span_diagnostic
.span_err(start_span.to(end_span), "invalid crate attribute");
continue;
}

krate.attrs.push(mk_attr(AttrStyle::Inner, path, tokens, start_span.to(end_span)));
}

krate
}
1 change: 1 addition & 0 deletions src/libsyntax_ext/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod source_util;
mod test;
mod trace_macros;

pub mod cmdline_attrs;
pub mod plugin_macro_defs;
pub mod proc_macro_harness;
pub mod standard_library_imports;
Expand Down