Skip to content

Commit 237d54f

Browse files
committed
Auto merge of #65433 - Centril:rollup-rzvry15, r=Centril
Rollup of 4 pull requests Successful merges: - #64035 (Stabilize proc macros generating `macro_rules` items) - #65376 (syntax: misc extractions) - #65426 (Remove custom `PartialEq` impls for `LocalInternedString`.) - #65428 (Refactor: Rename `db` locals to `diag`) Failed merges: r? @ghost
2 parents 437ca55 + 8370f14 commit 237d54f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+531
-612
lines changed

src/librustc/hir/lowering.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ use syntax::errors;
6767
use syntax::ext::base::SpecialDerives;
6868
use syntax::ext::hygiene::ExpnId;
6969
use syntax::print::pprust;
70-
use syntax::source_map::{respan, ExpnData, ExpnKind, DesugaringKind, Spanned};
71-
use syntax::symbol::{kw, sym, Symbol};
7270
use syntax::tokenstream::{TokenStream, TokenTree};
7371
use syntax::parse::token::{self, Nonterminal, Token};
74-
use syntax::parse::ParseSess;
72+
use syntax::sess::ParseSess;
73+
use syntax::source_map::{respan, ExpnData, ExpnKind, DesugaringKind, Spanned};
74+
use syntax::symbol::{kw, sym, Symbol};
7575
use syntax::visit::{self, Visitor};
7676
use syntax_pos::Span;
7777

src/librustc/hir/print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use rustc_target::spec::abi::Abi;
22
use syntax::ast;
33
use syntax::source_map::{SourceMap, Spanned};
4-
use syntax::parse::ParseSess;
54
use syntax::print::pp::{self, Breaks};
65
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
76
use syntax::print::pprust::{self, Comments, PrintState};
7+
use syntax::sess::ParseSess;
88
use syntax::symbol::kw;
99
use syntax::util::parser::{self, AssocOp, Fixity};
1010
use syntax_pos::{self, BytePos, FileName};

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#![feature(test)]
5757
#![feature(in_band_lifetimes)]
5858
#![feature(crate_visibility_modifier)]
59-
#![feature(proc_macro_hygiene)]
59+
#![cfg_attr(bootstrap, feature(proc_macro_hygiene))]
6060
#![feature(log_syntax)]
6161
#![feature(associated_type_bounds)]
6262
#![feature(rustc_attrs)]

src/librustc/session/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ use syntax;
1616
use syntax::ast::{self, IntTy, UintTy, MetaItemKind};
1717
use syntax::source_map::{FileName, FilePathMapping};
1818
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
19-
use syntax::parse::{ParseSess, new_parser_from_source_str};
19+
use syntax::parse::new_parser_from_source_str;
2020
use syntax::parse::token;
21+
use syntax::sess::ParseSess;
2122
use syntax::symbol::{sym, Symbol};
2223
use syntax::feature_gate::UnstableFeatures;
2324
use syntax::source_map::SourceMap;

src/librustc/session/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use syntax::ext::allocator::AllocatorKind;
2828
use syntax::feature_gate::{self, AttributeType};
2929
use syntax::json::JsonEmitter;
3030
use syntax::source_map;
31-
use syntax::parse::{self, ParseSess};
31+
use syntax::sess::ParseSess;
3232
use syntax::symbol::Symbol;
3333
use syntax_pos::{MultiSpan, Span};
3434
use crate::util::profiling::{SelfProfiler, SelfProfilerRef};
@@ -1159,7 +1159,7 @@ fn build_session_(
11591159
);
11601160
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
11611161

1162-
let parse_sess = parse::ParseSess::with_span_handler(
1162+
let parse_sess = ParseSess::with_span_handler(
11631163
span_diagnostic,
11641164
source_map,
11651165
);

src/librustc_codegen_ssa/back/write.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1667,13 +1667,13 @@ impl SharedEmitter {
16671667
}
16681668

16691669
impl Emitter for SharedEmitter {
1670-
fn emit_diagnostic(&mut self, db: &rustc_errors::Diagnostic) {
1670+
fn emit_diagnostic(&mut self, diag: &rustc_errors::Diagnostic) {
16711671
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
1672-
msg: db.message(),
1673-
code: db.code.clone(),
1674-
lvl: db.level,
1672+
msg: diag.message(),
1673+
code: diag.code.clone(),
1674+
lvl: diag.level,
16751675
})));
1676-
for child in &db.children {
1676+
for child in &diag.children {
16771677
drop(self.sender.send(SharedEmitterMessage::Diagnostic(Diagnostic {
16781678
msg: child.message(),
16791679
code: None,

src/librustc_errors/annotate_snippet_emitter_writer.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ pub struct AnnotateSnippetEmitterWriter {
3131

3232
impl Emitter for AnnotateSnippetEmitterWriter {
3333
/// The entry point for the diagnostics generation
34-
fn emit_diagnostic(&mut self, db: &Diagnostic) {
35-
let mut children = db.children.clone();
36-
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
34+
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
35+
let mut children = diag.children.clone();
36+
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
3737

3838
self.fix_multispans_in_std_macros(&self.source_map,
3939
&mut primary_span,
4040
&mut children,
41-
&db.level,
41+
&diag.level,
4242
self.external_macro_backtrace);
4343

44-
self.emit_messages_default(&db.level,
45-
db.message(),
46-
&db.code,
44+
self.emit_messages_default(&diag.level,
45+
diag.message(),
46+
&diag.code,
4747
&primary_span,
4848
&children,
4949
&suggestions);

src/librustc_errors/emitter.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const ANONYMIZED_LINE_NUM: &str = "LL";
180180
/// Emitter trait for emitting errors.
181181
pub trait Emitter {
182182
/// Emit a structured diagnostic.
183-
fn emit_diagnostic(&mut self, db: &Diagnostic);
183+
fn emit_diagnostic(&mut self, diag: &Diagnostic);
184184

185185
/// Emit a notification that an artifact has been output.
186186
/// This is currently only supported for the JSON format,
@@ -206,10 +206,10 @@ pub trait Emitter {
206206
/// we return the original `primary_span` and the original suggestions.
207207
fn primary_span_formatted<'a>(
208208
&mut self,
209-
db: &'a Diagnostic,
209+
diag: &'a Diagnostic,
210210
) -> (MultiSpan, &'a [CodeSuggestion]) {
211-
let mut primary_span = db.span.clone();
212-
if let Some((sugg, rest)) = db.suggestions.split_first() {
211+
let mut primary_span = diag.span.clone();
212+
if let Some((sugg, rest)) = diag.suggestions.split_first() {
213213
if rest.is_empty() &&
214214
// ^ if there is only one suggestion
215215
// don't display multi-suggestions as labels
@@ -260,10 +260,10 @@ pub trait Emitter {
260260
// to be consistent. We could try to figure out if we can
261261
// make one (or the first one) inline, but that would give
262262
// undue importance to a semi-random suggestion
263-
(primary_span, &db.suggestions)
263+
(primary_span, &diag.suggestions)
264264
}
265265
} else {
266-
(primary_span, &db.suggestions)
266+
(primary_span, &diag.suggestions)
267267
}
268268
}
269269

@@ -401,19 +401,19 @@ impl Emitter for EmitterWriter {
401401
self.sm.as_ref()
402402
}
403403

404-
fn emit_diagnostic(&mut self, db: &Diagnostic) {
405-
let mut children = db.children.clone();
406-
let (mut primary_span, suggestions) = self.primary_span_formatted(&db);
404+
fn emit_diagnostic(&mut self, diag: &Diagnostic) {
405+
let mut children = diag.children.clone();
406+
let (mut primary_span, suggestions) = self.primary_span_formatted(&diag);
407407

408408
self.fix_multispans_in_std_macros(&self.sm,
409409
&mut primary_span,
410410
&mut children,
411-
&db.level,
411+
&diag.level,
412412
self.external_macro_backtrace);
413413

414-
self.emit_messages_default(&db.level,
415-
&db.styled_message(),
416-
&db.code,
414+
self.emit_messages_default(&diag.level,
415+
&diag.styled_message(),
416+
&diag.code,
417417
&primary_span,
418418
&children,
419419
&suggestions);

src/librustdoc/clean/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::ops;
99

1010
use syntax::symbol::{Symbol, sym};
1111
use syntax::ast::{MetaItem, MetaItemKind, NestedMetaItem, LitKind};
12-
use syntax::parse::ParseSess;
12+
use syntax::sess::ParseSess;
1313
use syntax::feature_gate::Features;
1414

1515
use syntax_pos::Span;

src/librustdoc/html/highlight.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::io::prelude::*;
1414
use syntax::source_map::{SourceMap, FilePathMapping};
1515
use syntax::parse::lexer;
1616
use syntax::parse::token::{self, Token};
17-
use syntax::parse;
17+
use syntax::sess::ParseSess;
1818
use syntax::symbol::{kw, sym};
1919
use syntax_pos::{Span, FileName};
2020

@@ -33,7 +33,7 @@ pub fn render_with_highlighting(
3333
class, tooltip).unwrap();
3434
}
3535

36-
let sess = parse::ParseSess::new(FilePathMapping::empty());
36+
let sess = ParseSess::new(FilePathMapping::empty());
3737
let fm = sess.source_map().new_source_file(
3838
FileName::Custom(String::from("rustdoc-highlighting")),
3939
src.to_owned(),

src/librustdoc/passes/check_code_block_syntax.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use errors::Applicability;
22
use syntax::parse::lexer::{StringReader as Lexer};
3-
use syntax::parse::{ParseSess, token};
3+
use syntax::parse::token;
4+
use syntax::sess::ParseSess;
45
use syntax::source_map::FilePathMapping;
56
use syntax_pos::{InnerSpan, FileName};
67

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ pub fn make_test(s: &str,
394394
// Uses libsyntax to parse the doctest and find if there's a main fn and the extern
395395
// crate already is included.
396396
let (already_has_main, already_has_extern_crate, found_macro) = with_globals(edition, || {
397-
use crate::syntax::{parse::{self, ParseSess}, source_map::FilePathMapping};
397+
use crate::syntax::{parse, sess::ParseSess, source_map::FilePathMapping};
398398
use errors::emitter::EmitterWriter;
399399
use errors::Handler;
400400

src/libsyntax/attr/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use crate::ast::{self, Attribute, MetaItem, NestedMetaItem};
44
use crate::early_buffered_lints::BufferedEarlyLintId;
55
use crate::ext::base::ExtCtxt;
66
use crate::feature_gate::{Features, GatedCfg};
7-
use crate::parse::ParseSess;
87
use crate::print::pprust;
8+
use crate::sess::ParseSess;
99

1010
use errors::{Applicability, Handler};
1111
use syntax_pos::hygiene::Transparency;

src/libsyntax/attr/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ use crate::mut_visit::visit_clobber;
1616
use crate::source_map::{BytePos, Spanned, DUMMY_SP};
1717
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
1818
use crate::parse::parser::Parser;
19-
use crate::parse::{ParseSess, PResult};
19+
use crate::parse::PResult;
2020
use crate::parse::token::{self, Token};
2121
use crate::ptr::P;
22+
use crate::sess::ParseSess;
2223
use crate::symbol::{sym, Symbol};
2324
use crate::ThinVec;
2425
use crate::tokenstream::{TokenStream, TokenTree, DelimSpan};

src/libsyntax/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use crate::attr;
1010
use crate::ast;
1111
use crate::edition::Edition;
1212
use crate::mut_visit::*;
13-
use crate::parse::{token, ParseSess};
13+
use crate::parse::token;
1414
use crate::ptr::P;
15+
use crate::sess::ParseSess;
1516
use crate::symbol::sym;
1617
use crate::util::map_in_place::MapInPlace;
1718

src/libsyntax/ext/base.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use crate::edition::Edition;
55
use crate::ext::expand::{self, AstFragment, Invocation};
66
use crate::ext::hygiene::ExpnId;
77
use crate::mut_visit::{self, MutVisitor};
8-
use crate::parse::{self, parser, ParseSess, DirectoryOwnership};
8+
use crate::parse::{self, parser, DirectoryOwnership};
99
use crate::parse::token;
1010
use crate::ptr::P;
11+
use crate::sess::ParseSess;
1112
use crate::symbol::{kw, sym, Ident, Symbol};
1213
use crate::{ThinVec, MACRO_ARGUMENTS};
1314
use crate::tokenstream::{self, TokenStream};
@@ -892,7 +893,7 @@ pub struct ExpansionData {
892893
/// when a macro expansion occurs, the resulting nodes have the `backtrace()
893894
/// -> expn_data` of their expansion context stored into their span.
894895
pub struct ExtCtxt<'a> {
895-
pub parse_sess: &'a parse::ParseSess,
896+
pub parse_sess: &'a ParseSess,
896897
pub ecfg: expand::ExpansionConfig<'a>,
897898
pub root_path: PathBuf,
898899
pub resolver: &'a mut dyn Resolver,
@@ -901,7 +902,7 @@ pub struct ExtCtxt<'a> {
901902
}
902903

903904
impl<'a> ExtCtxt<'a> {
904-
pub fn new(parse_sess: &'a parse::ParseSess,
905+
pub fn new(parse_sess: &'a ParseSess,
905906
ecfg: expand::ExpansionConfig<'a>,
906907
resolver: &'a mut dyn Resolver)
907908
-> ExtCtxt<'a> {
@@ -935,7 +936,7 @@ impl<'a> ExtCtxt<'a> {
935936
parse::stream_to_parser(self.parse_sess, stream, MACRO_ARGUMENTS)
936937
}
937938
pub fn source_map(&self) -> &'a SourceMap { self.parse_sess.source_map() }
938-
pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess }
939+
pub fn parse_sess(&self) -> &'a ParseSess { self.parse_sess }
939940
pub fn cfg(&self) -> &ast::CrateConfig { &self.parse_sess.config }
940941
pub fn call_site(&self) -> Span {
941942
self.current_expansion.id.expn_data().call_site

src/libsyntax/ext/expand.rs

+4-45
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ use crate::ext::mbe::macro_rules::annotate_err_with_kind;
1010
use crate::ext::placeholders::{placeholder, PlaceholderExpander};
1111
use crate::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
1212
use crate::mut_visit::*;
13-
use crate::parse::{DirectoryOwnership, PResult, ParseSess};
13+
use crate::parse::{DirectoryOwnership, PResult};
1414
use crate::parse::token;
1515
use crate::parse::parser::Parser;
1616
use crate::print::pprust;
1717
use crate::ptr::P;
1818
use crate::symbol::{sym, Symbol};
1919
use crate::tokenstream::{TokenStream, TokenTree};
20-
use crate::visit::{self, Visitor};
20+
use crate::visit::Visitor;
2121
use crate::util::map_in_place::MapInPlace;
2222

2323
use errors::{Applicability, FatalError};
@@ -577,10 +577,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
577577
SyntaxExtensionKind::Bang(expander) => {
578578
self.gate_proc_macro_expansion_kind(span, fragment_kind);
579579
let tok_result = expander.expand(self.cx, span, mac.stream());
580-
let result =
581-
self.parse_ast_fragment(tok_result, fragment_kind, &mac.path, span);
582-
self.gate_proc_macro_expansion(span, &result);
583-
result
580+
self.parse_ast_fragment(tok_result, fragment_kind, &mac.path, span)
584581
}
585582
SyntaxExtensionKind::LegacyBang(expander) => {
586583
let prev = self.cx.current_expansion.prior_type_ascription;
@@ -624,10 +621,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
624621
})), DUMMY_SP).into();
625622
let input = self.extract_proc_macro_attr_input(attr.item.tokens, span);
626623
let tok_result = expander.expand(self.cx, span, input, item_tok);
627-
let res =
628-
self.parse_ast_fragment(tok_result, fragment_kind, &attr.item.path, span);
629-
self.gate_proc_macro_expansion(span, &res);
630-
res
624+
self.parse_ast_fragment(tok_result, fragment_kind, &attr.item.path, span)
631625
}
632626
SyntaxExtensionKind::LegacyAttr(expander) => {
633627
match attr.parse_meta(self.cx.parse_sess) {
@@ -718,41 +712,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
718712
);
719713
}
720714

721-
fn gate_proc_macro_expansion(&self, span: Span, fragment: &AstFragment) {
722-
if self.cx.ecfg.proc_macro_hygiene() {
723-
return
724-
}
725-
726-
fragment.visit_with(&mut DisallowMacros {
727-
span,
728-
parse_sess: self.cx.parse_sess,
729-
});
730-
731-
struct DisallowMacros<'a> {
732-
span: Span,
733-
parse_sess: &'a ParseSess,
734-
}
735-
736-
impl<'ast, 'a> Visitor<'ast> for DisallowMacros<'a> {
737-
fn visit_item(&mut self, i: &'ast ast::Item) {
738-
if let ast::ItemKind::MacroDef(_) = i.kind {
739-
emit_feature_err(
740-
self.parse_sess,
741-
sym::proc_macro_hygiene,
742-
self.span,
743-
GateIssue::Language,
744-
"procedural macros cannot expand to macro definitions",
745-
);
746-
}
747-
visit::walk_item(self, i);
748-
}
749-
750-
fn visit_mac(&mut self, _mac: &'ast ast::Mac) {
751-
// ...
752-
}
753-
}
754-
}
755-
756715
fn gate_proc_macro_expansion_kind(&self, span: Span, kind: AstFragmentKind) {
757716
let kind = match kind {
758717
AstFragmentKind::Expr |

src/libsyntax/ext/mbe/macro_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use crate::early_buffered_lints::BufferedEarlyLintId;
109109
use crate::ext::mbe::{KleeneToken, TokenTree};
110110
use crate::parse::token::TokenKind;
111111
use crate::parse::token::{DelimToken, Token};
112-
use crate::parse::ParseSess;
112+
use crate::sess::ParseSess;
113113
use crate::symbol::{kw, sym};
114114

115115
use rustc_data_structures::fx::FxHashMap;

src/libsyntax/ext/mbe/macro_parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ use TokenTreeOrTokenTreeSlice::*;
7676

7777
use crate::ast::{Ident, Name};
7878
use crate::ext::mbe::{self, TokenTree};
79-
use crate::parse::{Directory, ParseSess, PResult};
79+
use crate::parse::{Directory, PResult};
8080
use crate::parse::parser::{Parser, PathStyle};
8181
use crate::parse::token::{self, DocComment, Nonterminal, Token};
8282
use crate::print::pprust;
83+
use crate::sess::ParseSess;
8384
use crate::symbol::{kw, sym, Symbol};
8485
use crate::tokenstream::{DelimSpan, TokenStream};
8586

0 commit comments

Comments
 (0)