Skip to content

Commit

Permalink
Auto merge of rust-lang#86821 - cuviper:beta-next, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
[beta] backports

- rustfmt: load nested out-of-line mods correctly rust-lang#86424
- Re-add support for parsing (and pretty-printing) inner-attributes in match body rust-lang#85193
- Revert "List trait impls before methods from deref in the sidebar ..." rust-lang#86564
- Revert "Don't load all extern crates unconditionally" rust-lang#85749

r? `@Mark-Simulacrum`
  • Loading branch information
bors committed Jul 2, 2021
2 parents bf62f4d + d78e83a commit 0fa28ce
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 126 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Expand Up @@ -369,6 +369,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
}

fn print_inner_attributes_no_trailing_hardbreak(&mut self, attrs: &[ast::Attribute]) {
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, false)
}

fn print_outer_attributes(&mut self, attrs: &[ast::Attribute]) {
self.print_either_attributes(attrs, ast::AttrStyle::Outer, false, true)
}
Expand Down Expand Up @@ -1960,6 +1964,7 @@ impl<'a> State<'a> {
self.print_expr_as_cond(expr);
self.s.space();
self.bopen();
self.print_inner_attributes_no_trailing_hardbreak(attrs);
for arm in arms {
self.print_arm(arm);
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Expand Up @@ -1945,7 +1945,7 @@ impl<'a> Parser<'a> {
}

/// Parses a `match ... { ... }` expression (`match` token already eaten).
fn parse_match_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
fn parse_match_expr(&mut self, mut attrs: AttrVec) -> PResult<'a, P<Expr>> {
let match_span = self.prev_token.span;
let lo = self.prev_token.span;
let scrutinee = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
Expand All @@ -1960,6 +1960,7 @@ impl<'a> Parser<'a> {
}
return Err(e);
}
attrs.extend(self.parse_inner_attributes()?);

let mut arms: Vec<Arm> = Vec::new();
while self.token != token::CloseDelim(token::Brace) {
Expand Down
45 changes: 35 additions & 10 deletions src/librustdoc/core.rs
@@ -1,12 +1,12 @@
use rustc_ast as ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{self, Lrc};
use rustc_driver::abort_on_err;
use rustc_errors::emitter::{Emitter, EmitterWriter};
use rustc_errors::json::JsonEmitter;
use rustc_feature::UnstableFeatures;
use rustc_hir::def::Namespace::TypeNS;
use rustc_hir::def::Res;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX};
use rustc_hir::HirId;
use rustc_hir::{
intravisit::{self, NestedVisitorMap, Visitor},
Expand All @@ -23,7 +23,7 @@ use rustc_session::DiagnosticOutput;
use rustc_session::Session;
use rustc_span::source_map;
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};

use std::cell::RefCell;
use std::mem;
Expand Down Expand Up @@ -300,17 +300,42 @@ crate fn create_config(
}

crate fn create_resolver<'a>(
externs: config::Externs,
queries: &Queries<'a>,
sess: &Session,
) -> Rc<RefCell<interface::BoxedResolver>> {
let parts = abort_on_err(queries.expansion(), sess).peek();
let (krate, resolver, _) = &*parts;
let resolver = resolver.borrow().clone();

let mut loader = crate::passes::collect_intra_doc_links::IntraLinkCrateLoader::new(resolver);
ast::visit::walk_crate(&mut loader, krate);
let extern_names: Vec<String> = externs
.iter()
.filter(|(_, entry)| entry.add_prelude)
.map(|(name, _)| name)
.cloned()
.collect();

let (_, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek();
let resolver = resolver.borrow();

// Before we actually clone it, let's force all the extern'd crates to
// actually be loaded, just in case they're only referred to inside
// intra-doc links
resolver.borrow_mut().access(|resolver| {
sess.time("load_extern_crates", || {
for extern_name in &extern_names {
debug!("loading extern crate {}", extern_name);
if let Err(()) = resolver
.resolve_str_path_error(
DUMMY_SP,
extern_name,
TypeNS,
LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(),
) {
warn!("unable to resolve external crate {} (do you have an unused `--extern` crate?)", extern_name)
}
}
});
});

loader.resolver
// Now we're good to clone the resolver because everything should be loaded
resolver.clone()
}

crate fn run_global_ctxt(
Expand Down
16 changes: 8 additions & 8 deletions src/librustdoc/html/render/mod.rs
Expand Up @@ -1887,6 +1887,14 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
}

if v.iter().any(|i| i.inner_impl().trait_.is_some()) {
if let Some(impl_) = v
.iter()
.filter(|i| i.inner_impl().trait_.is_some())
.find(|i| i.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_trait_did)
{
sidebar_deref_methods(cx, out, impl_, v);
}

let format_impls = |impls: Vec<&Impl>| {
let mut links = FxHashSet::default();

Expand Down Expand Up @@ -1954,14 +1962,6 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
);
write_sidebar_links(out, blanket_format);
}

if let Some(impl_) = v
.iter()
.filter(|i| i.inner_impl().trait_.is_some())
.find(|i| i.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_trait_did)
{
sidebar_deref_methods(cx, out, impl_, v);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/lib.rs
Expand Up @@ -31,7 +31,6 @@ extern crate tracing;
// Dependencies listed in Cargo.toml do not need `extern crate`.

extern crate rustc_ast;
extern crate rustc_ast_lowering;
extern crate rustc_ast_pretty;
extern crate rustc_attr;
extern crate rustc_data_structures;
Expand Down Expand Up @@ -714,6 +713,7 @@ fn main_options(options: config::Options) -> MainResult {
let default_passes = options.default_passes;
let output_format = options.output_format;
// FIXME: fix this clone (especially render_options)
let externs = options.externs.clone();
let manual_passes = options.manual_passes.clone();
let render_options = options.render_options.clone();
let config = core::create_config(options);
Expand All @@ -731,7 +731,7 @@ fn main_options(options: config::Options) -> MainResult {
// We need to hold on to the complete resolver, so we cause everything to be
// cloned for the analysis passes to use. Suboptimal, but necessary in the
// current architecture.
let resolver = core::create_resolver(queries, &sess);
let resolver = core::create_resolver(externs, queries, &sess);

if sess.has_errors() {
sess.fatal("Compilation failed, aborting rustdoc");
Expand Down
3 changes: 0 additions & 3 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Expand Up @@ -37,9 +37,6 @@ use crate::html::markdown::{markdown_links, MarkdownLink};
use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS};
use crate::passes::Pass;

mod early;
crate use early::IntraLinkCrateLoader;

crate const COLLECT_INTRA_DOC_LINKS: Pass = Pass {
name: "collect-intra-doc-links",
run: collect_intra_doc_links,
Expand Down
63 changes: 0 additions & 63 deletions src/librustdoc/passes/collect_intra_doc_links/early.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/librustdoc/passes/mod.rs
Expand Up @@ -30,7 +30,7 @@ crate use self::unindent_comments::UNINDENT_COMMENTS;
mod propagate_doc_cfg;
crate use self::propagate_doc_cfg::PROPAGATE_DOC_CFG;

crate mod collect_intra_doc_links;
mod collect_intra_doc_links;
crate use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS;

mod doc_test_lints;
Expand Down
8 changes: 4 additions & 4 deletions src/test/pretty/ast-stmt-expr-attr.rs
Expand Up @@ -43,10 +43,10 @@ fn syntax() {
#![attr]
};
let _ =
#[attr] match true
{
#[attr]
_ => false,
#[attr] match true {
#![attr]
#[attr]
_ => false,
};
let _ = #[attr] || #[attr] foo;
let _ = #[attr] move || #[attr] foo;
Expand Down
17 changes: 14 additions & 3 deletions src/test/pretty/stmt_expr_attributes.rs
Expand Up @@ -41,9 +41,16 @@ fn _3() {
fn _4() {

#[rustc_dummy]
match () { _ => (), }
match () {
#![rustc_dummy]
_ => (),
}

let _ = #[rustc_dummy] match () { () => (), };
let _ =
#[rustc_dummy] match () {
#![rustc_dummy]
() => (),
};
}

fn _5() {
Expand Down Expand Up @@ -164,7 +171,11 @@ fn _11() {
#[rustc_dummy] loop {
#![rustc_dummy]
};
let _ = #[rustc_dummy] match false { _ => (), };
let _ =
#[rustc_dummy] match false {
#![rustc_dummy]
_ => (),
};
let _ = #[rustc_dummy] || #[rustc_dummy] ();
let _ = #[rustc_dummy] move || #[rustc_dummy] ();
let _ =
Expand Down
17 changes: 0 additions & 17 deletions src/test/rustdoc-ui/auxiliary/panic-item.rs

This file was deleted.

3 changes: 0 additions & 3 deletions src/test/rustdoc-ui/unused-extern-crate.rs

This file was deleted.

2 changes: 2 additions & 0 deletions src/test/rustdoc/auxiliary/issue-66159-1.rs
@@ -0,0 +1,2 @@
/// This will be referred to by the test docstring
pub struct Something;
10 changes: 10 additions & 0 deletions src/test/rustdoc/issue-66159.rs
@@ -0,0 +1,10 @@
// aux-crate:priv:issue_66159_1=issue-66159-1.rs
// compile-flags:-Z unstable-options

// The issue was an ICE which meant that we never actually generated the docs
// so if we have generated the docs, we're okay.
// Since we don't generate the docs for the auxiliary files, we can't actually
// verify that the struct is linked correctly.

// @has issue_66159/index.html
//! [issue_66159_1::Something]
2 changes: 1 addition & 1 deletion src/test/ui/parser/stmt_expr_attrs_placement.rs
Expand Up @@ -30,7 +30,7 @@ fn main() {
//~^ ERROR an inner attribute is not permitted in this context

let g = match true { #![allow(warnings)] _ => {} };
//~^ ERROR an inner attribute is not permitted in this context


struct MyStruct { field: u8 }
let h = MyStruct { #![allow(warnings)] field: 0 };
Expand Down
10 changes: 1 addition & 9 deletions src/test/ui/parser/stmt_expr_attrs_placement.stderr
Expand Up @@ -46,14 +46,6 @@ LL | let f = [#![allow(warnings)] 1; 0];
|
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.

error: an inner attribute is not permitted in this context
--> $DIR/stmt_expr_attrs_placement.rs:32:26
|
LL | let g = match true { #![allow(warnings)] _ => {} };
| ^^^^^^^^^^^^^^^^^^^
|
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.

error: an inner attribute is not permitted in this context
--> $DIR/stmt_expr_attrs_placement.rs:36:24
|
Expand All @@ -62,5 +54,5 @@ LL | let h = MyStruct { #![allow(warnings)] field: 0 };
|
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes, like `#[test]`, annotate the item following them.

error: aborting due to 8 previous errors
error: aborting due to 7 previous errors

2 changes: 1 addition & 1 deletion src/tools/rustfmt/src/modules.rs
Expand Up @@ -318,7 +318,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
self.directory = directory;
}
match (sub_mod.ast_mod_kind, sub_mod.items) {
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, ast::Inline::No, _))), _) => {
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
self.visit_mod_from_ast(&items)
}
(Some(Cow::Owned(..)), Cow::Owned(items)) => self.visit_mod_outside_ast(items),
Expand Down
1 change: 1 addition & 0 deletions src/tools/rustfmt/src/test/mod.rs
Expand Up @@ -16,6 +16,7 @@ use crate::source_file;
use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session};

mod configuration_snippet;
mod mod_resolver;
mod parser;

const DIFF_CONTEXT_SIZE: usize = 3;
Expand Down

0 comments on commit 0fa28ce

Please sign in to comment.