Skip to content

Commit 78c8573

Browse files
committed
Auto merge of rust-lang#128301 - matthiaskrgr:rollup-9fyf587, r=matthiaskrgr
Rollup of 3 pull requests Successful merges: - rust-lang#125889 (Add migration lint for 2024 prelude additions) - rust-lang#128215 (Update the reference) - rust-lang#128263 (rustdoc: use strategic ThinVec/Box to shrink `clean::ItemKind`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1b51d80 + 3a4051c commit 78c8573

Some content is hidden

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

46 files changed

+774
-184
lines changed

compiler/rustc_hir_typeck/src/method/prelude_edition_lints.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir as hir;
99
use rustc_lint::{ARRAY_INTO_ITER, BOXED_SLICE_INTO_ITER};
1010
use rustc_middle::span_bug;
1111
use rustc_middle::ty::{self, Ty};
12-
use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS;
12+
use rustc_session::lint::builtin::{RUST_2021_PRELUDE_COLLISIONS, RUST_2024_PRELUDE_COLLISIONS};
1313
use rustc_span::symbol::kw::{Empty, Underscore};
1414
use rustc_span::symbol::{sym, Ident};
1515
use rustc_span::Span;
@@ -35,6 +35,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3535
let (prelude_or_array_lint, edition) = match segment.ident.name {
3636
// `try_into` was added to the prelude in Rust 2021.
3737
sym::try_into if !span.at_least_rust_2021() => (RUST_2021_PRELUDE_COLLISIONS, "2021"),
38+
// `Future::poll` was added to the prelude in Rust 2024.
39+
sym::poll
40+
// We check that the self type is `Pin<&mut _>` to avoid false positives for this common name.
41+
if !span.at_least_rust_2024()
42+
&& let ty::Adt(adt_def, args) = self_ty.kind()
43+
&& self.tcx.is_lang_item(adt_def.did(), hir::LangItem::Pin)
44+
&& let ty::Ref(_, _, ty::Mutability::Mut) =
45+
args[0].as_type().unwrap().kind() =>
46+
{
47+
(RUST_2024_PRELUDE_COLLISIONS, "2024")
48+
}
49+
// `IntoFuture::into_future` was added to the prelude in Rust 2024.
50+
sym::into_future if !span.at_least_rust_2024() => {
51+
(RUST_2024_PRELUDE_COLLISIONS, "2024")
52+
}
3853
// `into_iter` wasn't added to the prelude,
3954
// but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter
4055
// before Rust 2021, which results in the same problem.

compiler/rustc_lint_defs/src/builtin.rs

+41
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ declare_lint_pass! {
9191
RUST_2021_PREFIXES_INCOMPATIBLE_SYNTAX,
9292
RUST_2021_PRELUDE_COLLISIONS,
9393
RUST_2024_INCOMPATIBLE_PAT,
94+
RUST_2024_PRELUDE_COLLISIONS,
9495
SELF_CONSTRUCTOR_FROM_OUTER_ITEM,
9596
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
9697
SINGLE_USE_LIFETIMES,
@@ -3754,6 +3755,46 @@ declare_lint! {
37543755
};
37553756
}
37563757

3758+
declare_lint! {
3759+
/// The `rust_2024_prelude_collisions` lint detects the usage of trait methods which are ambiguous
3760+
/// with traits added to the prelude in future editions.
3761+
///
3762+
/// ### Example
3763+
///
3764+
/// ```rust,edition2021,compile_fail
3765+
/// #![deny(rust_2024_prelude_collisions)]
3766+
/// trait Meow {
3767+
/// fn poll(&self) {}
3768+
/// }
3769+
/// impl<T> Meow for T {}
3770+
///
3771+
/// fn main() {
3772+
/// core::pin::pin!(async {}).poll();
3773+
/// // ^^^^^^
3774+
/// // This call to try_into matches both Future::poll and Meow::poll as
3775+
/// // `Future` has been added to the Rust prelude in 2024 edition.
3776+
/// }
3777+
/// ```
3778+
///
3779+
/// {{produces}}
3780+
///
3781+
/// ### Explanation
3782+
///
3783+
/// Rust 2024, introduces two new additions to the standard library's prelude:
3784+
/// `Future` and `IntoFuture`. This results in an ambiguity as to which method/function
3785+
/// to call when an existing `poll`/`into_future` method is called via dot-call syntax or
3786+
/// a `poll`/`into_future` associated function is called directly on a type.
3787+
///
3788+
pub RUST_2024_PRELUDE_COLLISIONS,
3789+
Allow,
3790+
"detects the usage of trait methods which are ambiguous with traits added to the \
3791+
prelude in future editions",
3792+
@future_incompatible = FutureIncompatibleInfo {
3793+
reason: FutureIncompatibilityReason::EditionError(Edition::Edition2024),
3794+
reference: "<https://doc.rust-lang.org/nightly/edition-guide/rust-2024/prelude.html>",
3795+
};
3796+
}
3797+
37573798
declare_lint! {
37583799
/// The `rust_2021_prefixes_incompatible_syntax` lint detects identifiers that will be parsed as a
37593800
/// prefix instead in Rust 2021.

src/bootstrap/src/core/build_steps/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::core::builder::{
99
};
1010
use crate::core::config::TargetSelection;
1111
use crate::{Compiler, Mode, Subcommand};
12-
use std::path::{Path, PathBuf};
12+
use std::path::PathBuf;
1313

1414
pub fn cargo_subcommand(kind: Kind) -> &'static str {
1515
match kind {
@@ -52,7 +52,7 @@ impl Step for Std {
5252
}
5353

5454
fn run(self, builder: &Builder<'_>) {
55-
builder.update_submodule(&Path::new("library").join("stdarch"));
55+
builder.require_submodule("library/stdarch", None);
5656

5757
let target = self.target;
5858
let compiler = builder.compiler(builder.top_stage, builder.config.build);

src/bootstrap/src/core/build_steps/clippy.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Implementation of running clippy on the compiler, standard library and various tools.
22
3-
use std::path::Path;
4-
53
use crate::builder::Builder;
64
use crate::builder::ShouldRun;
75
use crate::core::builder;
@@ -127,7 +125,7 @@ impl Step for Std {
127125
}
128126

129127
fn run(self, builder: &Builder<'_>) {
130-
builder.update_submodule(&Path::new("library").join("stdarch"));
128+
builder.require_submodule("library/stdarch", None);
131129

132130
let target = self.target;
133131
let compiler = builder.compiler(builder.top_stage, builder.config.build);

src/bootstrap/src/core/build_steps/compile.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,16 @@ impl Step for Std {
182182
return;
183183
}
184184

185-
builder.update_submodule(&Path::new("library").join("stdarch"));
185+
builder.require_submodule("library/stdarch", None);
186186

187187
// Profiler information requires LLVM's compiler-rt
188188
if builder.config.profiler {
189-
builder.update_submodule(Path::new("src/llvm-project"));
189+
builder.require_submodule(
190+
"src/llvm-project",
191+
Some(
192+
"The `build.profiler` config option requires `compiler-rt` sources from LLVM.",
193+
),
194+
);
190195
}
191196

192197
let mut target_deps = builder.ensure(StartupObjects { compiler, target });
@@ -456,13 +461,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
456461
// That's probably ok? At least, the difference wasn't enforced before. There's a comment in
457462
// the compiler_builtins build script that makes me nervous, though:
458463
// https://github.com/rust-lang/compiler-builtins/blob/31ee4544dbe47903ce771270d6e3bea8654e9e50/build.rs#L575-L579
459-
builder.update_submodule(&Path::new("src").join("llvm-project"));
464+
builder.require_submodule(
465+
"src/llvm-project",
466+
Some(
467+
"The `build.optimized-compiler-builtins` config option \
468+
requires `compiler-rt` sources from LLVM.",
469+
),
470+
);
460471
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
461-
if !compiler_builtins_root.exists() {
462-
panic!(
463-
"need LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true` or disabling `optimized-compiler-builtins`"
464-
);
465-
}
472+
assert!(compiler_builtins_root.exists());
466473
// Note that `libprofiler_builtins/build.rs` also computes this so if
467474
// you're changing something here please also change that.
468475
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);

src/bootstrap/src/core/build_steps/dist.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ impl Step for Src {
907907
/// Creates the `rust-src` installer component
908908
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
909909
if !builder.config.dry_run() {
910-
builder.update_submodule(Path::new("src/llvm-project"));
910+
builder.require_submodule("src/llvm-project", None);
911911
}
912912

913913
let tarball = Tarball::new_targetless(builder, "rust-src");
@@ -1022,10 +1022,7 @@ impl Step for PlainSourceTarball {
10221022
// FIXME: This code looks _very_ similar to what we have in `src/core/build_steps/vendor.rs`
10231023
// perhaps it should be removed in favor of making `dist` perform the `vendor` step?
10241024

1025-
// Ensure we have all submodules from src and other directories checked out.
1026-
for submodule in build_helper::util::parse_gitmodules(&builder.src) {
1027-
builder.update_submodule(Path::new(submodule));
1028-
}
1025+
builder.require_and_update_all_submodules();
10291026

10301027
// Vendor all Cargo dependencies
10311028
let mut cmd = command(&builder.initial_cargo);

src/bootstrap/src/core/build_steps/doc.rs

+70-31
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
1010
use std::io::{self, Write};
1111
use std::path::{Path, PathBuf};
12-
use std::{fs, mem};
12+
use std::{env, fs, mem};
1313

1414
use crate::core::build_steps::compile;
1515
use crate::core::build_steps::tool::{self, prepare_tool_cargo, SourceType, Tool};
1616
use crate::core::builder::{self, crate_description};
1717
use crate::core::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
1818
use crate::core::config::{Config, TargetSelection};
19-
use crate::utils::helpers::{dir_is_empty, symlink_dir, t, up_to_date};
19+
use crate::utils::helpers::{symlink_dir, t, up_to_date};
2020
use crate::Mode;
2121

2222
macro_rules! submodule_helper {
@@ -53,15 +53,16 @@ macro_rules! book {
5353

5454
fn run(self, builder: &Builder<'_>) {
5555
$(
56-
let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
57-
builder.update_submodule(&path);
56+
let path = submodule_helper!( $path, submodule $( = $submodule )? );
57+
builder.require_submodule(path, None);
5858
)?
5959
builder.ensure(RustbookSrc {
6060
target: self.target,
6161
name: $book_name.to_owned(),
6262
src: builder.src.join($path),
6363
parent: Some(self),
6464
languages: $lang.into(),
65+
rustdoc: None,
6566
})
6667
}
6768
}
@@ -80,7 +81,6 @@ book!(
8081
EditionGuide, "src/doc/edition-guide", "edition-guide", &[], submodule;
8182
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[], submodule;
8283
Nomicon, "src/doc/nomicon", "nomicon", &[], submodule;
83-
Reference, "src/doc/reference", "reference", &[], submodule;
8484
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja"], submodule;
8585
RustdocBook, "src/doc/rustdoc", "rustdoc", &[];
8686
StyleGuide, "src/doc/style-guide", "style-guide", &[];
@@ -112,6 +112,7 @@ impl Step for UnstableBook {
112112
src: builder.md_doc_out(self.target).join("unstable-book"),
113113
parent: Some(self),
114114
languages: vec![],
115+
rustdoc: None,
115116
})
116117
}
117118
}
@@ -123,6 +124,7 @@ struct RustbookSrc<P: Step> {
123124
src: PathBuf,
124125
parent: Option<P>,
125126
languages: Vec<&'static str>,
127+
rustdoc: Option<PathBuf>,
126128
}
127129

128130
impl<P: Step> Step for RustbookSrc<P> {
@@ -153,13 +155,18 @@ impl<P: Step> Step for RustbookSrc<P> {
153155
builder.info(&format!("Rustbook ({target}) - {name}"));
154156
let _ = fs::remove_dir_all(&out);
155157

156-
builder
157-
.tool_cmd(Tool::Rustbook)
158-
.arg("build")
159-
.arg(&src)
160-
.arg("-d")
161-
.arg(&out)
162-
.run(builder);
158+
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
159+
if let Some(mut rustdoc) = self.rustdoc {
160+
rustdoc.pop();
161+
let old_path = env::var_os("PATH").unwrap_or_default();
162+
let new_path =
163+
env::join_paths(std::iter::once(rustdoc).chain(env::split_paths(&old_path)))
164+
.expect("could not add rustdoc to PATH");
165+
166+
rustbook_cmd.env("PATH", new_path);
167+
}
168+
169+
rustbook_cmd.arg("build").arg(&src).arg("-d").arg(&out).run(builder);
163170

164171
for lang in &self.languages {
165172
let out = out.join(lang);
@@ -217,29 +224,22 @@ impl Step for TheBook {
217224
/// * Index page
218225
/// * Redirect pages
219226
fn run(self, builder: &Builder<'_>) {
220-
let relative_path = Path::new("src").join("doc").join("book");
221-
builder.update_submodule(&relative_path);
227+
builder.require_submodule("src/doc/book", None);
222228

223229
let compiler = self.compiler;
224230
let target = self.target;
225231

226-
let absolute_path = builder.src.join(&relative_path);
232+
let absolute_path = builder.src.join("src/doc/book");
227233
let redirect_path = absolute_path.join("redirects");
228-
if !absolute_path.exists()
229-
|| !redirect_path.exists()
230-
|| dir_is_empty(&absolute_path)
231-
|| dir_is_empty(&redirect_path)
232-
{
233-
eprintln!("Please checkout submodule: {}", relative_path.display());
234-
crate::exit!(1);
235-
}
234+
236235
// build book
237236
builder.ensure(RustbookSrc {
238237
target,
239238
name: "book".to_owned(),
240239
src: absolute_path.clone(),
241240
parent: Some(self),
242241
languages: vec![],
242+
rustdoc: None,
243243
});
244244

245245
// building older edition redirects
@@ -252,6 +252,7 @@ impl Step for TheBook {
252252
// treat the other editions as not having a parent.
253253
parent: Option::<Self>::None,
254254
languages: vec![],
255+
rustdoc: None,
255256
});
256257
}
257258

@@ -932,8 +933,8 @@ macro_rules! tool_doc {
932933
let _ = source_type; // silence the "unused variable" warning
933934
let source_type = SourceType::Submodule;
934935

935-
let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
936-
builder.update_submodule(&path);
936+
let path = submodule_helper!( $path, submodule $( = $submodule )? );
937+
builder.require_submodule(path, None);
937938
)?
938939

939940
let stage = builder.top_stage;
@@ -1172,12 +1173,6 @@ impl Step for RustcBook {
11721173
/// in the "md-doc" directory in the build output directory. Then
11731174
/// "rustbook" is used to convert it to HTML.
11741175
fn run(self, builder: &Builder<'_>) {
1175-
// These submodules are required to be checked out to build rustbook
1176-
// because they have Cargo dependencies that are needed.
1177-
#[allow(clippy::single_element_loop)] // This will change soon.
1178-
for path in ["src/doc/book"] {
1179-
builder.update_submodule(Path::new(path));
1180-
}
11811176
let out_base = builder.md_doc_out(self.target).join("rustc");
11821177
t!(fs::create_dir_all(&out_base));
11831178
let out_listing = out_base.join("src/lints");
@@ -1228,6 +1223,50 @@ impl Step for RustcBook {
12281223
src: out_base,
12291224
parent: Some(self),
12301225
languages: vec![],
1226+
rustdoc: None,
1227+
});
1228+
}
1229+
}
1230+
1231+
#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
1232+
pub struct Reference {
1233+
pub compiler: Compiler,
1234+
pub target: TargetSelection,
1235+
}
1236+
1237+
impl Step for Reference {
1238+
type Output = ();
1239+
const DEFAULT: bool = true;
1240+
1241+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1242+
let builder = run.builder;
1243+
run.path("src/doc/reference").default_condition(builder.config.docs)
1244+
}
1245+
1246+
fn make_run(run: RunConfig<'_>) {
1247+
run.builder.ensure(Reference {
1248+
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
1249+
target: run.target,
1250+
});
1251+
}
1252+
1253+
/// Builds the reference book.
1254+
fn run(self, builder: &Builder<'_>) {
1255+
builder.require_submodule("src/doc/reference", None);
1256+
1257+
// This is needed for generating links to the standard library using
1258+
// the mdbook-spec plugin.
1259+
builder.ensure(compile::Std::new(self.compiler, builder.config.build));
1260+
let rustdoc = builder.rustdoc(self.compiler);
1261+
1262+
// Run rustbook/mdbook to generate the HTML pages.
1263+
builder.ensure(RustbookSrc {
1264+
target: self.target,
1265+
name: "reference".to_owned(),
1266+
src: builder.src.join("src/doc/reference"),
1267+
parent: Some(self),
1268+
languages: vec![],
1269+
rustdoc: Some(rustdoc),
12311270
});
12321271
}
12331272
}

0 commit comments

Comments
 (0)