Skip to content

Commit 0fa28ce

Browse files
committed
Auto merge of #86821 - cuviper:beta-next, r=Mark-Simulacrum
[beta] backports - rustfmt: load nested out-of-line mods correctly #86424 - Re-add support for parsing (and pretty-printing) inner-attributes in match body #85193 - Revert "List trait impls before methods from deref in the sidebar ..." #86564 - Revert "Don't load all extern crates unconditionally" #85749 r? `@Mark-Simulacrum`
2 parents bf62f4d + d78e83a commit 0fa28ce

File tree

23 files changed

+131
-126
lines changed

23 files changed

+131
-126
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+5
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
369369
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
370370
}
371371

372+
fn print_inner_attributes_no_trailing_hardbreak(&mut self, attrs: &[ast::Attribute]) {
373+
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, false)
374+
}
375+
372376
fn print_outer_attributes(&mut self, attrs: &[ast::Attribute]) {
373377
self.print_either_attributes(attrs, ast::AttrStyle::Outer, false, true)
374378
}
@@ -1960,6 +1964,7 @@ impl<'a> State<'a> {
19601964
self.print_expr_as_cond(expr);
19611965
self.s.space();
19621966
self.bopen();
1967+
self.print_inner_attributes_no_trailing_hardbreak(attrs);
19631968
for arm in arms {
19641969
self.print_arm(arm);
19651970
}

Diff for: compiler/rustc_parse/src/parser/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ impl<'a> Parser<'a> {
19451945
}
19461946

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

19641965
let mut arms: Vec<Arm> = Vec::new();
19651966
while self.token != token::CloseDelim(token::Brace) {

Diff for: src/librustdoc/core.rs

+35-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use rustc_ast as ast;
21
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
32
use rustc_data_structures::sync::{self, Lrc};
43
use rustc_driver::abort_on_err;
54
use rustc_errors::emitter::{Emitter, EmitterWriter};
65
use rustc_errors::json::JsonEmitter;
76
use rustc_feature::UnstableFeatures;
7+
use rustc_hir::def::Namespace::TypeNS;
88
use rustc_hir::def::Res;
9-
use rustc_hir::def_id::{DefId, LocalDefId};
9+
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX};
1010
use rustc_hir::HirId;
1111
use rustc_hir::{
1212
intravisit::{self, NestedVisitorMap, Visitor},
@@ -23,7 +23,7 @@ use rustc_session::DiagnosticOutput;
2323
use rustc_session::Session;
2424
use rustc_span::source_map;
2525
use rustc_span::symbol::sym;
26-
use rustc_span::Span;
26+
use rustc_span::{Span, DUMMY_SP};
2727

2828
use std::cell::RefCell;
2929
use std::mem;
@@ -300,17 +300,42 @@ crate fn create_config(
300300
}
301301

302302
crate fn create_resolver<'a>(
303+
externs: config::Externs,
303304
queries: &Queries<'a>,
304305
sess: &Session,
305306
) -> Rc<RefCell<interface::BoxedResolver>> {
306-
let parts = abort_on_err(queries.expansion(), sess).peek();
307-
let (krate, resolver, _) = &*parts;
308-
let resolver = resolver.borrow().clone();
309-
310-
let mut loader = crate::passes::collect_intra_doc_links::IntraLinkCrateLoader::new(resolver);
311-
ast::visit::walk_crate(&mut loader, krate);
307+
let extern_names: Vec<String> = externs
308+
.iter()
309+
.filter(|(_, entry)| entry.add_prelude)
310+
.map(|(name, _)| name)
311+
.cloned()
312+
.collect();
313+
314+
let (_, resolver, _) = &*abort_on_err(queries.expansion(), sess).peek();
315+
let resolver = resolver.borrow();
316+
317+
// Before we actually clone it, let's force all the extern'd crates to
318+
// actually be loaded, just in case they're only referred to inside
319+
// intra-doc links
320+
resolver.borrow_mut().access(|resolver| {
321+
sess.time("load_extern_crates", || {
322+
for extern_name in &extern_names {
323+
debug!("loading extern crate {}", extern_name);
324+
if let Err(()) = resolver
325+
.resolve_str_path_error(
326+
DUMMY_SP,
327+
extern_name,
328+
TypeNS,
329+
LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(),
330+
) {
331+
warn!("unable to resolve external crate {} (do you have an unused `--extern` crate?)", extern_name)
332+
}
333+
}
334+
});
335+
});
312336

313-
loader.resolver
337+
// Now we're good to clone the resolver because everything should be loaded
338+
resolver.clone()
314339
}
315340

316341
crate fn run_global_ctxt(

Diff for: src/librustdoc/html/render/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,14 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
18871887
}
18881888

18891889
if v.iter().any(|i| i.inner_impl().trait_.is_some()) {
1890+
if let Some(impl_) = v
1891+
.iter()
1892+
.filter(|i| i.inner_impl().trait_.is_some())
1893+
.find(|i| i.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_trait_did)
1894+
{
1895+
sidebar_deref_methods(cx, out, impl_, v);
1896+
}
1897+
18901898
let format_impls = |impls: Vec<&Impl>| {
18911899
let mut links = FxHashSet::default();
18921900

@@ -1954,14 +1962,6 @@ fn sidebar_assoc_items(cx: &Context<'_>, out: &mut Buffer, it: &clean::Item) {
19541962
);
19551963
write_sidebar_links(out, blanket_format);
19561964
}
1957-
1958-
if let Some(impl_) = v
1959-
.iter()
1960-
.filter(|i| i.inner_impl().trait_.is_some())
1961-
.find(|i| i.inner_impl().trait_.def_id_full(cache) == cx.cache.deref_trait_did)
1962-
{
1963-
sidebar_deref_methods(cx, out, impl_, v);
1964-
}
19651965
}
19661966
}
19671967
}

Diff for: src/librustdoc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ extern crate tracing;
3131
// Dependencies listed in Cargo.toml do not need `extern crate`.
3232

3333
extern crate rustc_ast;
34-
extern crate rustc_ast_lowering;
3534
extern crate rustc_ast_pretty;
3635
extern crate rustc_attr;
3736
extern crate rustc_data_structures;
@@ -714,6 +713,7 @@ fn main_options(options: config::Options) -> MainResult {
714713
let default_passes = options.default_passes;
715714
let output_format = options.output_format;
716715
// FIXME: fix this clone (especially render_options)
716+
let externs = options.externs.clone();
717717
let manual_passes = options.manual_passes.clone();
718718
let render_options = options.render_options.clone();
719719
let config = core::create_config(options);
@@ -731,7 +731,7 @@ fn main_options(options: config::Options) -> MainResult {
731731
// We need to hold on to the complete resolver, so we cause everything to be
732732
// cloned for the analysis passes to use. Suboptimal, but necessary in the
733733
// current architecture.
734-
let resolver = core::create_resolver(queries, &sess);
734+
let resolver = core::create_resolver(externs, queries, &sess);
735735

736736
if sess.has_errors() {
737737
sess.fatal("Compilation failed, aborting rustdoc");

Diff for: src/librustdoc/passes/collect_intra_doc_links.rs

-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ use crate::html::markdown::{markdown_links, MarkdownLink};
3737
use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS};
3838
use crate::passes::Pass;
3939

40-
mod early;
41-
crate use early::IntraLinkCrateLoader;
42-
4340
crate const COLLECT_INTRA_DOC_LINKS: Pass = Pass {
4441
name: "collect-intra-doc-links",
4542
run: collect_intra_doc_links,

Diff for: src/librustdoc/passes/collect_intra_doc_links/early.rs

-63
This file was deleted.

Diff for: src/librustdoc/passes/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ crate use self::unindent_comments::UNINDENT_COMMENTS;
3030
mod propagate_doc_cfg;
3131
crate use self::propagate_doc_cfg::PROPAGATE_DOC_CFG;
3232

33-
crate mod collect_intra_doc_links;
33+
mod collect_intra_doc_links;
3434
crate use self::collect_intra_doc_links::COLLECT_INTRA_DOC_LINKS;
3535

3636
mod doc_test_lints;

Diff for: src/test/pretty/ast-stmt-expr-attr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ fn syntax() {
4343
#![attr]
4444
};
4545
let _ =
46-
#[attr] match true
47-
{
48-
#[attr]
49-
_ => false,
46+
#[attr] match true {
47+
#![attr]
48+
#[attr]
49+
_ => false,
5050
};
5151
let _ = #[attr] || #[attr] foo;
5252
let _ = #[attr] move || #[attr] foo;

Diff for: src/test/pretty/stmt_expr_attributes.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,16 @@ fn _3() {
4141
fn _4() {
4242

4343
#[rustc_dummy]
44-
match () { _ => (), }
44+
match () {
45+
#![rustc_dummy]
46+
_ => (),
47+
}
4548

46-
let _ = #[rustc_dummy] match () { () => (), };
49+
let _ =
50+
#[rustc_dummy] match () {
51+
#![rustc_dummy]
52+
() => (),
53+
};
4754
}
4855

4956
fn _5() {
@@ -164,7 +171,11 @@ fn _11() {
164171
#[rustc_dummy] loop {
165172
#![rustc_dummy]
166173
};
167-
let _ = #[rustc_dummy] match false { _ => (), };
174+
let _ =
175+
#[rustc_dummy] match false {
176+
#![rustc_dummy]
177+
_ => (),
178+
};
168179
let _ = #[rustc_dummy] || #[rustc_dummy] ();
169180
let _ = #[rustc_dummy] move || #[rustc_dummy] ();
170181
let _ =

Diff for: src/test/rustdoc-ui/auxiliary/panic-item.rs

-17
This file was deleted.

Diff for: src/test/rustdoc-ui/unused-extern-crate.rs

-3
This file was deleted.

Diff for: src/test/rustdoc/auxiliary/issue-66159-1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// This will be referred to by the test docstring
2+
pub struct Something;

Diff for: src/test/rustdoc/issue-66159.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// aux-crate:priv:issue_66159_1=issue-66159-1.rs
2+
// compile-flags:-Z unstable-options
3+
4+
// The issue was an ICE which meant that we never actually generated the docs
5+
// so if we have generated the docs, we're okay.
6+
// Since we don't generate the docs for the auxiliary files, we can't actually
7+
// verify that the struct is linked correctly.
8+
9+
// @has issue_66159/index.html
10+
//! [issue_66159_1::Something]

Diff for: src/test/ui/parser/stmt_expr_attrs_placement.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() {
3030
//~^ ERROR an inner attribute is not permitted in this context
3131

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

3535
struct MyStruct { field: u8 }
3636
let h = MyStruct { #![allow(warnings)] field: 0 };

Diff for: src/test/ui/parser/stmt_expr_attrs_placement.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@ LL | let f = [#![allow(warnings)] 1; 0];
4646
|
4747
= 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.
4848

49-
error: an inner attribute is not permitted in this context
50-
--> $DIR/stmt_expr_attrs_placement.rs:32:26
51-
|
52-
LL | let g = match true { #![allow(warnings)] _ => {} };
53-
| ^^^^^^^^^^^^^^^^^^^
54-
|
55-
= 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.
56-
5749
error: an inner attribute is not permitted in this context
5850
--> $DIR/stmt_expr_attrs_placement.rs:36:24
5951
|
@@ -62,5 +54,5 @@ LL | let h = MyStruct { #![allow(warnings)] field: 0 };
6254
|
6355
= 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.
6456

65-
error: aborting due to 8 previous errors
57+
error: aborting due to 7 previous errors
6658

Diff for: src/tools/rustfmt/src/modules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
318318
self.directory = directory;
319319
}
320320
match (sub_mod.ast_mod_kind, sub_mod.items) {
321-
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, ast::Inline::No, _))), _) => {
321+
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
322322
self.visit_mod_from_ast(&items)
323323
}
324324
(Some(Cow::Owned(..)), Cow::Owned(items)) => self.visit_mod_outside_ast(items),

Diff for: src/tools/rustfmt/src/test/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::source_file;
1616
use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session};
1717

1818
mod configuration_snippet;
19+
mod mod_resolver;
1920
mod parser;
2021

2122
const DIFF_CONTEXT_SIZE: usize = 3;

0 commit comments

Comments
 (0)