Skip to content

Commit 8e6b478

Browse files
committed
Auto merge of #83905 - JohnTitor:rollup-pa1la80, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #83370 (Add `x.py setup tools` which enables `download-rustc` by default) - #83489 (Properly suggest deref in else block) - #83734 (Catch a bad placeholder type error for statics in `extern`s) - #83814 (expand: Do not ICE when a legacy AST-based macro attribute produces and empty expression) - #83835 (rustdoc: sort search index items for compression) - #83849 (rustdoc: Cleanup handling of associated items for intra-doc links) - #83881 (:arrow_up: rust-analyzer) - #83885 (Document compiler/ with -Aprivate-intra-doc-links) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d322385 + d8c04b1 commit 8e6b478

25 files changed

+367
-192
lines changed

compiler/rustc_errors/src/diagnostic_builder.rs

-9
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ macro_rules! forward {
4545
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)?) -> &Self
4646
) => {
4747
$(#[$attrs])*
48-
// we always document with --document-private-items
49-
#[cfg_attr(not(bootstrap), allow(rustdoc::private_intra_doc_links))]
50-
#[cfg_attr(bootstrap, allow(private_intra_doc_links))]
5148
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
5249
pub fn $n(&self, $($name: $ty),*) -> &Self {
5350
self.diagnostic.$n($($name),*);
@@ -62,9 +59,6 @@ macro_rules! forward {
6259
) => {
6360
$(#[$attrs])*
6461
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
65-
// we always document with --document-private-items
66-
#[cfg_attr(not(bootstrap), allow(rustdoc::private_intra_doc_links))]
67-
#[cfg_attr(bootstrap, allow(private_intra_doc_links))]
6862
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
6963
self.0.diagnostic.$n($($name),*);
7064
self
@@ -82,9 +76,6 @@ macro_rules! forward {
8276
) => {
8377
$(#[$attrs])*
8478
#[doc = concat!("See [`Diagnostic::", stringify!($n), "()`].")]
85-
// we always document with --document-private-items
86-
#[cfg_attr(not(bootstrap), allow(rustdoc::private_intra_doc_links))]
87-
#[cfg_attr(bootstrap, allow(private_intra_doc_links))]
8879
pub fn $n<$($generic: $bound),*>(&mut self, $($name: $ty),*) -> &mut Self {
8980
self.0.diagnostic.$n($($name),*);
9081
self

compiler/rustc_expand/src/expand.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
735735
});
736736
}
737737
};
738-
fragment_kind.expect_from_annotatables(items)
738+
if fragment_kind == AstFragmentKind::Expr && items.is_empty() {
739+
let msg =
740+
"removing an expression is not supported in this position";
741+
self.cx.span_err(span, msg);
742+
fragment_kind.dummy(span)
743+
} else {
744+
fragment_kind.expect_from_annotatables(items)
745+
}
739746
}
740747
Err(mut err) => {
741748
err.emit();

compiler/rustc_resolve/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![feature(nll)]
1919
#![cfg_attr(bootstrap, feature(or_patterns))]
2020
#![recursion_limit = "256"]
21+
#![allow(rustdoc::private_intra_doc_links)]
2122

2223
pub use rustc_hir::def::{Namespace, PerNS};
2324

compiler/rustc_typeck/src/check/demand.rs

+28
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
366366
false
367367
}
368368

369+
/// If the given `HirId` corresponds to a block with a trailing expression, return that expression
370+
crate fn maybe_get_block_expr(&self, hir_id: hir::HirId) -> Option<&'tcx hir::Expr<'tcx>> {
371+
match self.tcx.hir().find(hir_id)? {
372+
Node::Expr(hir::Expr { kind: hir::ExprKind::Block(block, ..), .. }) => block.expr,
373+
_ => None,
374+
}
375+
}
376+
377+
/// Returns whether the given expression is an `else if`.
378+
crate fn is_else_if_block(&self, expr: &hir::Expr<'_>) -> bool {
379+
if let hir::ExprKind::If(..) = expr.kind {
380+
let parent_id = self.tcx.hir().get_parent_node(expr.hir_id);
381+
if let Some(Node::Expr(hir::Expr {
382+
kind: hir::ExprKind::If(_, _, Some(else_expr)),
383+
..
384+
})) = self.tcx.hir().find(parent_id)
385+
{
386+
return else_expr.hir_id == expr.hir_id;
387+
}
388+
}
389+
false
390+
}
391+
369392
/// This function is used to determine potential "simple" improvements or users' errors and
370393
/// provide them useful help. For example:
371394
///
@@ -652,6 +675,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
652675
};
653676
let suggestion = if is_struct_pat_shorthand_field {
654677
format!("{}: *{}", code, code)
678+
} else if self.is_else_if_block(expr) {
679+
// Don't suggest nonsense like `else *if`
680+
return None;
681+
} else if let Some(expr) = self.maybe_get_block_expr(expr.hir_id) {
682+
format!("*{}", sm.span_to_snippet(expr.span).unwrap_or(code))
655683
} else {
656684
format!("*{}", code)
657685
};

compiler/rustc_typeck/src/collect.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
734734
tcx.ensure().generics_of(item.def_id);
735735
tcx.ensure().type_of(item.def_id);
736736
tcx.ensure().predicates_of(item.def_id);
737-
if let hir::ForeignItemKind::Fn(..) = item.kind {
738-
tcx.ensure().fn_sig(item.def_id);
737+
match item.kind {
738+
hir::ForeignItemKind::Fn(..) => tcx.ensure().fn_sig(item.def_id),
739+
hir::ForeignItemKind::Static(..) => {
740+
let mut visitor = PlaceholderHirTyCollector::default();
741+
visitor.visit_foreign_item(item);
742+
placeholder_type_error(tcx, None, &[], visitor.0, false, None);
743+
}
744+
_ => (),
739745
}
740746
}
741747
}

src/bootstrap/defaults/config.compiler.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ debug-logging = true
88
incremental = true
99

1010
[llvm]
11-
# Will download LLVM from CI if available on your platform (Linux only for now)
12-
# https://github.com/rust-lang/rust/issues/77084 tracks support for more platforms
11+
# Will download LLVM from CI if available on your platform.
1312
download-ci-llvm = "if-available"
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# These defaults are meant for contributors to tools which build on the
2+
# compiler, but do not modify it directly.
3+
[rust]
4+
# This enables `RUSTC_LOG=debug`, avoiding confusing situations
5+
# where adding `debug!()` appears to do nothing.
6+
# However, it makes running the compiler slightly slower.
7+
debug-logging = true
8+
# This greatly increases the speed of rebuilds, especially when there are only minor changes. However, it makes the initial build slightly slower.
9+
incremental = true
10+
# Download rustc from CI instead of building it from source.
11+
# This cuts compile times by almost 60x, but means you can't modify the compiler.
12+
download-rustc = "if-unchanged"
13+
14+
[llvm]
15+
# Will download LLVM from CI if available on your platform.
16+
download-ci-llvm = "if-available"

src/bootstrap/doc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ impl Step for Rustc {
549549
// Build cargo command.
550550
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc");
551551
cargo.rustdocflag("--document-private-items");
552+
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
553+
cargo.rustdocflag("-Arustdoc::private-intra-doc-links");
552554
cargo.rustdocflag("--enable-index-page");
553555
cargo.rustdocflag("-Zunstable-options");
554556
cargo.rustdocflag("-Znormalize-docs");

src/bootstrap/setup.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub enum Profile {
1313
Compiler,
1414
Codegen,
1515
Library,
16+
Tools,
1617
User,
1718
}
1819

@@ -24,15 +25,16 @@ impl Profile {
2425
pub fn all() -> impl Iterator<Item = Self> {
2526
use Profile::*;
2627
// N.B. these are ordered by how they are displayed, not alphabetically
27-
[Library, Compiler, Codegen, User].iter().copied()
28+
[Library, Compiler, Codegen, Tools, User].iter().copied()
2829
}
2930

3031
pub fn purpose(&self) -> String {
3132
use Profile::*;
3233
match self {
3334
Library => "Contribute to the standard library",
34-
Compiler => "Contribute to the compiler or rustdoc",
35+
Compiler => "Contribute to the compiler itself",
3536
Codegen => "Contribute to the compiler, and also modify LLVM or codegen",
37+
Tools => "Contribute to tools which depend on the compiler, but do not modify it directly (e.g. rustdoc, clippy, miri)",
3638
User => "Install Rust from source",
3739
}
3840
.to_string()
@@ -53,9 +55,12 @@ impl FromStr for Profile {
5355
fn from_str(s: &str) -> Result<Self, Self::Err> {
5456
match s {
5557
"lib" | "library" => Ok(Profile::Library),
56-
"compiler" | "rustdoc" => Ok(Profile::Compiler),
58+
"compiler" => Ok(Profile::Compiler),
5759
"llvm" | "codegen" => Ok(Profile::Codegen),
5860
"maintainer" | "user" => Ok(Profile::User),
61+
"tools" | "tool" | "rustdoc" | "clippy" | "miri" | "rustfmt" | "rls" => {
62+
Ok(Profile::Tools)
63+
}
5964
_ => Err(format!("unknown profile: '{}'", s)),
6065
}
6166
}
@@ -68,6 +73,7 @@ impl fmt::Display for Profile {
6873
Profile::Codegen => write!(f, "codegen"),
6974
Profile::Library => write!(f, "library"),
7075
Profile::User => write!(f, "user"),
76+
Profile::Tools => write!(f, "tools"),
7177
}
7278
}
7379
}
@@ -103,6 +109,14 @@ pub fn setup(src_path: &Path, profile: Profile) {
103109

104110
let suggestions = match profile {
105111
Profile::Codegen | Profile::Compiler => &["check", "build", "test"][..],
112+
Profile::Tools => &[
113+
"check",
114+
"build",
115+
"test src/test/rustdoc*",
116+
"test src/tools/clippy",
117+
"test src/tools/miri",
118+
"test src/tools/rustfmt",
119+
],
106120
Profile::Library => &["check", "build", "test library/std", "doc"],
107121
Profile::User => &["dist", "build"],
108122
};

src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ impl Attributes {
914914
.collect()
915915
}
916916

917-
crate fn get_doc_aliases(&self) -> FxHashSet<String> {
917+
crate fn get_doc_aliases(&self) -> Box<[String]> {
918918
let mut aliases = FxHashSet::default();
919919

920920
for attr in self.other_attrs.lists(sym::doc).filter(|a| a.has_name(sym::alias)) {
@@ -931,7 +931,7 @@ impl Attributes {
931931
aliases.insert(attr.value_str().map(|s| s.to_string()).unwrap());
932932
}
933933
}
934-
aliases
934+
aliases.into_iter().collect::<Vec<String>>().into()
935935
}
936936
}
937937

src/librustdoc/formats/cache.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ crate struct Cache {
120120
// when gathering trait documentation on a type, hold impls here while
121121
// folding and add them to the cache later on if we find the trait.
122122
orphan_trait_impls: Vec<(DefId, FxHashSet<DefId>, Impl)>,
123-
124-
/// Aliases added through `#[doc(alias = "...")]`. Since a few items can have the same alias,
125-
/// we need the alias element to have an array of items.
126-
crate aliases: BTreeMap<String, Vec<usize>>,
127123
}
128124

129125
/// This struct is used to wrap the `cache` and `tcx` in order to run `DocFolder`.
@@ -309,15 +305,8 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
309305
parent,
310306
parent_idx: None,
311307
search_type: get_index_search_type(&item, &self.empty_cache, self.tcx),
308+
aliases: item.attrs.get_doc_aliases(),
312309
});
313-
314-
for alias in item.attrs.get_doc_aliases() {
315-
self.cache
316-
.aliases
317-
.entry(alias.to_lowercase())
318-
.or_insert(Vec::new())
319-
.push(self.cache.search_index.len() - 1);
320-
}
321310
}
322311
}
323312
(Some(parent), None) if is_inherent_impl_item => {

src/librustdoc/html/render/cache.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,31 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
8282
parent: Some(did),
8383
parent_idx: None,
8484
search_type: get_index_search_type(&item, cache, tcx),
85+
aliases: item.attrs.get_doc_aliases(),
8586
});
86-
for alias in item.attrs.get_doc_aliases() {
87-
cache
88-
.aliases
89-
.entry(alias.to_lowercase())
90-
.or_insert(Vec::new())
91-
.push(cache.search_index.len() - 1);
92-
}
9387
}
9488
}
9589

96-
let Cache { ref mut search_index, ref paths, ref mut aliases, .. } = *cache;
90+
let Cache { ref mut search_index, ref paths, .. } = *cache;
91+
92+
// Aliases added through `#[doc(alias = "...")]`. Since a few items can have the same alias,
93+
// we need the alias element to have an array of items.
94+
let mut aliases: BTreeMap<String, Vec<usize>> = BTreeMap::new();
95+
96+
// Sort search index items. This improves the compressibility of the search index.
97+
search_index.sort_unstable_by(|k1, k2| {
98+
// `sort_unstable_by_key` produces lifetime errors
99+
let k1 = (&k1.path, &k1.name, &k1.ty, &k1.parent);
100+
let k2 = (&k2.path, &k2.name, &k2.ty, &k2.parent);
101+
std::cmp::Ord::cmp(&k1, &k2)
102+
});
103+
104+
// Set up alias indexes.
105+
for (i, item) in search_index.iter().enumerate() {
106+
for alias in &item.aliases[..] {
107+
aliases.entry(alias.to_lowercase()).or_insert(Vec::new()).push(i);
108+
}
109+
}
97110

98111
// Reduce `DefId` in paths into smaller sequential numbers,
99112
// and prune the paths that do not appear in the index.
@@ -201,7 +214,7 @@ crate fn build_index<'tcx>(krate: &clean::Crate, cache: &mut Cache, tcx: TyCtxt<
201214
doc: crate_doc,
202215
items: crate_items,
203216
paths: crate_paths,
204-
aliases,
217+
aliases: &aliases,
205218
})
206219
.expect("failed serde conversion")
207220
// All these `replace` calls are because we have to go through JS string for JSON content.

src/librustdoc/html/render/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ crate struct IndexItem {
164164
crate parent: Option<DefId>,
165165
crate parent_idx: Option<usize>,
166166
crate search_type: Option<IndexItemFunctionType>,
167+
crate aliases: Box<[String]>,
167168
}
168169

169170
/// A type used for the search index.

0 commit comments

Comments
 (0)