Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #82460

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3ed189e
Cleanup `PpMode` and friends
LeSeulArtichaut Feb 18, 2021
dd3772e
A few more code cleanups
LeSeulArtichaut Feb 19, 2021
7ad4b7a
Replace normalize.css 3.0.0 with unminified version.
jsha Feb 20, 2021
9bbd482
Update normalize.css to 8.0.1
jsha Feb 20, 2021
7acb105
Re-minify normalize.css.
jsha Feb 20, 2021
10f2342
Remove some P-s
bugadani Feb 20, 2021
fece59b
Change `find_anon_type` method to function
0yoyoyo Feb 21, 2021
17176cc
Add indication of anonymous lifetime position
0yoyoyo Feb 21, 2021
ce1a521
Apply tidy check
0yoyoyo Feb 21, 2021
b9449a3
Add option enabling MIR inlining independently of mir-opt-level
tmiasko Feb 21, 2021
5c546be
Use optional values for inlining thresholds
tmiasko Feb 21, 2021
5f7d663
:arrow_up: rust-analyzer
lnicola Feb 22, 2021
75d1e30
Update test cases
0yoyoyo Feb 22, 2021
24c23f5
Test hexagon-enum only when llvm target is present
nagisa Feb 22, 2021
c02d210
Add tests
petrochenkov Feb 22, 2021
fc9d578
expand: Preserve order of inert attributes during expansion
petrochenkov Feb 22, 2021
e8dcc02
Add a `size()` function to WASI's `MetadataExt`.
sunfishcode Feb 22, 2021
fa74d48
Improve error msgs when found type is deref of expected
osa1 Feb 21, 2021
132ec26
Enable API documentation for `std::os::wasi`.
sunfishcode Feb 22, 2021
a6eb836
Use #[doc = include_str!()] in std
LeSeulArtichaut Dec 30, 2020
de6f1b8
Do not consider using a semicolon inside of a different-crate macro
notriddle Feb 14, 2021
df78eea
expand: Resolve and expand inner attributes on out-of-line modules
petrochenkov Feb 21, 2021
408ccd7
Rollup merge of #80534 - LeSeulArtichaut:doc-include, r=jyn514
Dylan-DPC Feb 24, 2021
d3e3d58
Rollup merge of #82090 - notriddle:consider-using-a-semicolon-here, r…
Dylan-DPC Feb 24, 2021
1975088
Rollup merge of #82269 - LeSeulArtichaut:cleanup-ppmode, r=spastorino
Dylan-DPC Feb 24, 2021
b98f608
Rollup merge of #82313 - jsha:update-normalize-css, r=GuillaumeGomez
Dylan-DPC Feb 24, 2021
2ffc621
Rollup merge of #82321 - bugadani:ast3, r=varkor
Dylan-DPC Feb 24, 2021
b0458bc
Rollup merge of #82364 - osa1:issue82361, r=estebank
Dylan-DPC Feb 24, 2021
5fdfc09
Rollup merge of #82370 - 0yoyoyo:update-issue-81650-point-anonymous-l…
Dylan-DPC Feb 24, 2021
936a488
Rollup merge of #82376 - tmiasko:inline-options, r=oli-obk
Dylan-DPC Feb 24, 2021
5878913
Rollup merge of #82394 - lnicola:rust-analyzer-2021-02-22, r=jonas-sc…
Dylan-DPC Feb 24, 2021
cc0c8f1
Rollup merge of #82399 - petrochenkov:modin2, r=Aaron1011
Dylan-DPC Feb 24, 2021
fb19700
Rollup merge of #82404 - nagisa:nagisa/hexagon-enums-llvm-comps, r=pe…
Dylan-DPC Feb 24, 2021
4f3203f
Rollup merge of #82419 - petrochenkov:inertord, r=Aaron1011
Dylan-DPC Feb 24, 2021
2d80e0b
Rollup merge of #82420 - sunfishcode:wasi-docs, r=alexcrichton
Dylan-DPC Feb 24, 2021
ec0e4c2
Rollup merge of #82421 - sunfishcode:wasi-metadata-size, r=alexcrichton
Dylan-DPC Feb 24, 2021
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
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2299,7 +2299,7 @@ impl FnRetTy {
}
}

#[derive(Clone, PartialEq, Encodable, Decodable, Debug)]
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]
pub enum Inline {
Yes,
No,
Expand Down Expand Up @@ -2695,7 +2695,7 @@ pub enum ItemKind {
/// A use declaration item (`use`).
///
/// E.g., `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;`.
Use(P<UseTree>),
Use(UseTree),
/// A static item (`static`).
///
/// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`.
Expand All @@ -2719,7 +2719,7 @@ pub enum ItemKind {
/// E.g., `extern {}` or `extern "C" {}`.
ForeignMod(ForeignMod),
/// Module-level inline assembly (from `global_asm!()`).
GlobalAsm(P<GlobalAsm>),
GlobalAsm(GlobalAsm),
/// A type alias (`type`).
///
/// E.g., `type Foo = Bar<u8>;`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/global_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn expand_global_asm<'cx>(
ident: Ident::invalid(),
attrs: Vec::new(),
id: ast::DUMMY_NODE_ID,
kind: ast::ItemKind::GlobalAsm(P(global_asm)),
kind: ast::ItemKind::GlobalAsm(global_asm),
vis: ast::Visibility {
span: sp.shrink_to_lo(),
kind: ast::VisibilityKind::Inherited,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_builtin_macros/src/standard_library_imports.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rustc_ast as ast;
use rustc_ast::ptr::P;
use rustc_expand::base::{ExtCtxt, ResolverExpand};
use rustc_expand::expand::ExpansionConfig;
use rustc_session::Session;
Expand Down Expand Up @@ -72,11 +71,11 @@ pub fn inject(
span,
Ident::invalid(),
vec![cx.attribute(cx.meta_word(span, sym::prelude_import))],
ast::ItemKind::Use(P(ast::UseTree {
ast::ItemKind::Use(ast::UseTree {
prefix: cx.path(span, import_path),
kind: ast::UseTreeKind::Glob,
span,
})),
}),
);

krate.items.insert(0, use_item);
Expand Down
72 changes: 27 additions & 45 deletions compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map;
use rustc_middle::ty::{self, TyCtxt};
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
use rustc_session::config::{Input, PpMode, PpSourceMode};
use rustc_session::config::{Input, PpHirMode, PpMode, PpSourceMode};
use rustc_session::Session;
use rustc_span::symbol::Ident;
use rustc_span::FileName;
Expand Down Expand Up @@ -42,43 +42,41 @@ where
F: FnOnce(&dyn PrinterSupport) -> A,
{
match *ppmode {
PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
Normal | EveryBodyLoops | Expanded => {
let annotation = NoAnn { sess, tcx };
f(&annotation)
}

PpmIdentified | PpmExpandedIdentified => {
Identified | ExpandedIdentified => {
let annotation = IdentifiedAnnotation { sess, tcx };
f(&annotation)
}
PpmExpandedHygiene => {
ExpandedHygiene => {
let annotation = HygieneAnnotation { sess };
f(&annotation)
}
_ => panic!("Should use call_with_pp_support_hir"),
}
}
fn call_with_pp_support_hir<A, F>(ppmode: &PpSourceMode, tcx: TyCtxt<'_>, f: F) -> A
fn call_with_pp_support_hir<A, F>(ppmode: &PpHirMode, tcx: TyCtxt<'_>, f: F) -> A
where
F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate<'_>) -> A,
{
match *ppmode {
PpmNormal => {
PpHirMode::Normal => {
let annotation = NoAnn { sess: tcx.sess, tcx: Some(tcx) };
f(&annotation, tcx.hir().krate())
}

PpmIdentified => {
PpHirMode::Identified => {
let annotation = IdentifiedAnnotation { sess: tcx.sess, tcx: Some(tcx) };
f(&annotation, tcx.hir().krate())
}
PpmTyped => {
PpHirMode::Typed => {
abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);

let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) };
tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
}
_ => panic!("Should use call_with_pp_support"),
}
}

Expand Down Expand Up @@ -393,16 +391,13 @@ pub fn print_after_parsing(
) {
let (src, src_name) = get_source(input, sess);

let mut out = String::new();

if let PpmSource(s) = ppm {
let out = if let Source(s) = ppm {
// Silently ignores an identified node.
let out = &mut out;
call_with_pp_support(&s, sess, None, move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
let parse = &sess.parse_sess;
*out = pprust::print_crate(
pprust::print_crate(
sess.source_map(),
krate,
src_name,
Expand All @@ -413,7 +408,7 @@ pub fn print_after_parsing(
)
})
} else {
unreachable!();
unreachable!()
};

write_or_print(&out, ofile);
Expand All @@ -433,17 +428,14 @@ pub fn print_after_hir_lowering<'tcx>(

let (src, src_name) = get_source(input, tcx.sess);

let mut out = String::new();

match ppm {
PpmSource(s) => {
let out = match ppm {
Source(s) => {
// Silently ignores an identified node.
let out = &mut out;
call_with_pp_support(&s, tcx.sess, Some(tcx), move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
let parse = &sess.parse_sess;
*out = pprust::print_crate(
pprust::print_crate(
sess.source_map(),
krate,
src_name,
Expand All @@ -455,26 +447,20 @@ pub fn print_after_hir_lowering<'tcx>(
})
}

PpmHir(s) => {
let out = &mut out;
call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
let sm = sess.source_map();
*out = pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
})
}
Hir(s) => call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
debug!("pretty printing HIR {:?}", s);
let sess = annotation.sess();
let sm = sess.source_map();
pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
}),

PpmHirTree(s) => {
let out = &mut out;
call_with_pp_support_hir(&s, tcx, move |_annotation, krate| {
debug!("pretty printing source code {:?}", s);
*out = format!("{:#?}", krate);
});
}
HirTree => call_with_pp_support_hir(&PpHirMode::Normal, tcx, move |_annotation, krate| {
debug!("pretty printing HIR tree");
format!("{:#?}", krate)
}),

_ => unreachable!(),
}
};

write_or_print(&out, ofile);
}
Expand All @@ -493,14 +479,10 @@ fn print_with_analysis(
tcx.analysis(LOCAL_CRATE)?;

match ppm {
PpmMir | PpmMirCFG => match ppm {
PpmMir => write_mir_pretty(tcx, None, &mut out),
PpmMirCFG => write_mir_graphviz(tcx, None, &mut out),
_ => unreachable!(),
},
Mir => write_mir_pretty(tcx, None, &mut out).unwrap(),
MirCFG => write_mir_graphviz(tcx, None, &mut out).unwrap(),
_ => unreachable!(),
}
.unwrap();

let out = std::str::from_utf8(&out).unwrap();
write_or_print(out, ofile);
Expand Down
79 changes: 55 additions & 24 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ pub enum InvocationKind {
},
Attr {
attr: ast::Attribute,
// Re-insertion position for inert attributes.
pos: usize,
item: Annotatable,
// Required for resolving derive helper attributes.
derives: Vec<Path>,
Expand Down Expand Up @@ -690,7 +692,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
_ => unreachable!(),
},
InvocationKind::Attr { attr, mut item, derives } => match ext {
InvocationKind::Attr { attr, pos, mut item, derives } => match ext {
SyntaxExtensionKind::Attr(expander) => {
self.gate_proc_macro_input(&item);
self.gate_proc_macro_attr_item(span, &item);
Expand Down Expand Up @@ -721,7 +723,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
ExpandResult::Retry(item) => {
// Reassemble the original invocation for retrying.
return ExpandResult::Retry(Invocation {
kind: InvocationKind::Attr { attr, item, derives },
kind: InvocationKind::Attr { attr, pos, item, derives },
..invoc
});
}
Expand All @@ -739,7 +741,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
if *mark_used {
self.cx.sess.mark_attr_used(&attr);
}
item.visit_attrs(|attrs| attrs.push(attr));
item.visit_attrs(|attrs| attrs.insert(pos, attr));
fragment_kind.expect_from_annotatables(iter::once(item))
}
_ => unreachable!(),
Expand Down Expand Up @@ -1000,17 +1002,20 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {

fn collect_attr(
&mut self,
(attr, derives): (ast::Attribute, Vec<Path>),
(attr, pos, derives): (ast::Attribute, usize, Vec<Path>),
item: Annotatable,
kind: AstFragmentKind,
) -> AstFragment {
self.collect(kind, InvocationKind::Attr { attr, item, derives })
self.collect(kind, InvocationKind::Attr { attr, pos, item, derives })
}

/// If `item` is an attribute invocation, remove the attribute and return it together with
/// derives following it. We have to collect the derives in order to resolve legacy derive
/// helpers (helpers written before derives that introduce them).
fn take_first_attr(&mut self, item: &mut impl HasAttrs) -> Option<(ast::Attribute, Vec<Path>)> {
/// its position and derives following it. We have to collect the derives in order to resolve
/// legacy derive helpers (helpers written before derives that introduce them).
fn take_first_attr(
&mut self,
item: &mut impl HasAttrs,
) -> Option<(ast::Attribute, usize, Vec<Path>)> {
let mut attr = None;

item.visit_attrs(|attrs| {
Expand All @@ -1033,7 +1038,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
})
.collect();

(attr, following_derives)
(attr, attr_pos, following_derives)
})
});

Expand Down Expand Up @@ -1278,16 +1283,24 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
let pushed = &mut false; // Record `parse_external_mod` pushing so we can pop.
let dir = Directory { ownership: orig_ownership, path: module.directory };
let Directory { ownership, path } = match mod_kind {
ModKind::Loaded(_, Inline::Yes, _) => {
// Inline `mod foo { ... }`, but we still need to push directories.
ModKind::Loaded(_, inline, inner_span) => {
// Inline `mod foo { ... }` or previously loaded `mod foo;`,
// we still need to push directories.
let dir = push_directory(
&self.cx.sess,
ident,
&attrs,
dir,
*inline,
*inner_span,
span,
);
item.attrs = attrs;
push_directory(&self.cx.sess, ident, &item.attrs, dir)
}
ModKind::Loaded(_, Inline::No, _) => {
panic!("`mod` item is loaded from a file for the second time")
dir
}
ModKind::Unloaded => {
// We have an outline `mod foo;` so we need to parse the file.
let old_attrs_len = attrs.len();
let (items, inner_span, dir) =
parse_external_mod(&self.cx.sess, ident, span, dir, &mut attrs, pushed);

Expand All @@ -1299,16 +1312,34 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {

*mod_kind = ModKind::Loaded(krate.items, Inline::No, inner_span);
item.attrs = krate.attrs;
// File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
item = match self.configure(item) {
Some(node) => node,
None => {
if *pushed {
sess.included_mod_stack.borrow_mut().pop();
}
return Default::default();

if item.attrs.len() > old_attrs_len {
// If we loaded an out-of-line module and added some inner attributes,
// then we need to re-configure it and re-collect attributes for
// resolution and expansion.
let file_path = if *pushed {
sess.included_mod_stack.borrow_mut().pop()
} else {
None
};

item = configure!(self, item);

if let Some(attr) = self.take_first_attr(&mut item) {
return self
.collect_attr(
attr,
Annotatable::Item(item),
AstFragmentKind::Items,
)
.make_items();
}
};

if let Some(file_path) = file_path {
sess.included_mod_stack.borrow_mut().push(file_path);
}
}

dir
}
};
Expand Down
Loading