Skip to content

Commit ec7f258

Browse files
committed
Auto merge of rust-lang#82756 - JohnTitor:rollup-e4ij7h6, r=JohnTitor
Rollup of 8 pull requests Successful merges: - rust-lang#80527 (Make rustdoc lints a tool lint instead of built-in) - rust-lang#82310 (Load rustdoc's JS search index on-demand.) - rust-lang#82315 (Improve page load performance in rustdoc) - rust-lang#82564 (Revert `Vec::spare_capacity_mut` impl to prevent pointers invalidation) - rust-lang#82697 (Fix stabilization version of move_ref_pattern) - rust-lang#82717 (Account for macros when suggesting adding lifetime) - rust-lang#82740 (Fix commit detected when using `download-rustc`) - rust-lang#82744 (Pass `CrateNum` by value instead of by reference) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7f32f62 + 06630f7 commit ec7f258

File tree

100 files changed

+685
-420
lines changed

Some content is hidden

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

100 files changed

+685
-420
lines changed

compiler/rustc_ast/src/attr/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl MarkedAttrs {
3434
}
3535

3636
pub fn is_known_lint_tool(m_item: Ident) -> bool {
37-
[sym::clippy, sym::rustc].contains(&m_item.name)
37+
[sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item.name)
3838
}
3939

4040
impl NestedMetaItem {

compiler/rustc_error_codes/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![deny(invalid_codeblock_attributes)]
1+
#![cfg_attr(bootstrap, deny(invalid_codeblock_attributes))]
2+
#![cfg_attr(not(bootstrap), deny(rustdoc::invalid_codeblock_attributes))]
23
//! This library is used to gather all error codes into one place,
34
//! the goal being to make their maintenance easier.
45

compiler/rustc_feature/src/accepted.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ declare_features! (
272272
(accepted, doc_alias, "1.48.0", Some(50146), None),
273273
/// Allows patterns with concurrent by-move and by-ref bindings.
274274
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
275-
(accepted, move_ref_pattern, "1.48.0", Some(68354), None),
275+
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
276276
/// The smallest useful subset of `const_generics`.
277277
(accepted, min_const_generics, "1.51.0", Some(74878), None),
278278

compiler/rustc_lint/src/context.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl SessionLintStore for LintStore {
8989
}
9090

9191
/// The target of the `by_name` map, which accounts for renaming/deprecation.
92+
#[derive(Debug)]
9293
enum TargetLint {
9394
/// A direct lint target
9495
Id(LintId),
@@ -470,7 +471,10 @@ impl LintStore {
470471
Some(&Id(ref id)) => {
471472
CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name)))
472473
}
473-
_ => CheckLintNameResult::NoLint(None),
474+
Some(other) => {
475+
tracing::debug!("got renamed lint {:?}", other);
476+
CheckLintNameResult::NoLint(None)
477+
}
474478
}
475479
}
476480
}

compiler/rustc_lint/src/lib.rs

+23-15
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ use rustc_hir::def_id::LocalDefId;
6969
use rustc_middle::ty::query::Providers;
7070
use rustc_middle::ty::TyCtxt;
7171
use rustc_session::lint::builtin::{
72-
BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS,
73-
EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS,
74-
MISSING_DOC_CODE_EXAMPLES, NON_AUTOLINKS, PRIVATE_DOC_TESTS,
72+
BARE_TRAIT_OBJECTS, ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_OUTLIVES_REQUIREMENTS,
7573
};
7674
use rustc_span::symbol::{Ident, Symbol};
7775
use rustc_span::Span;
@@ -314,17 +312,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
314312
// MACRO_USE_EXTERN_CRATE
315313
);
316314

317-
add_lint_group!(
318-
"rustdoc",
319-
NON_AUTOLINKS,
320-
BROKEN_INTRA_DOC_LINKS,
321-
PRIVATE_INTRA_DOC_LINKS,
322-
INVALID_CODEBLOCK_ATTRIBUTES,
323-
MISSING_DOC_CODE_EXAMPLES,
324-
PRIVATE_DOC_TESTS,
325-
INVALID_HTML_TAGS
326-
);
327-
328315
// Register renamed and removed lints.
329316
store.register_renamed("single_use_lifetime", "single_use_lifetimes");
330317
store.register_renamed("elided_lifetime_in_path", "elided_lifetimes_in_paths");
@@ -334,8 +321,29 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
334321
store.register_renamed("async_idents", "keyword_idents");
335322
store.register_renamed("exceeding_bitshifts", "arithmetic_overflow");
336323
store.register_renamed("redundant_semicolon", "redundant_semicolons");
337-
store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links");
338324
store.register_renamed("overlapping_patterns", "overlapping_range_endpoints");
325+
326+
// These were moved to tool lints, but rustc still sees them when compiling normally, before
327+
// tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use
328+
// `register_removed` explicitly.
329+
const RUSTDOC_LINTS: &[&str] = &[
330+
"broken_intra_doc_links",
331+
"private_intra_doc_links",
332+
"missing_crate_level_docs",
333+
"missing_doc_code_examples",
334+
"private_doc_tests",
335+
"invalid_codeblock_attributes",
336+
"invalid_html_tags",
337+
"non_autolinks",
338+
];
339+
for rustdoc_lint in RUSTDOC_LINTS {
340+
store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint));
341+
}
342+
store.register_removed(
343+
"intra_doc_link_resolution_failure",
344+
"use `rustdoc::broken_intra_doc_links` instead",
345+
);
346+
339347
store.register_removed("unknown_features", "replaced by an error");
340348
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
341349
store.register_removed("negate_unsigned", "cast a signed value instead");

compiler/rustc_lint_defs/src/builtin.rs

-95
Original file line numberDiff line numberDiff line change
@@ -1875,93 +1875,6 @@ declare_lint! {
18751875
"detects labels that are never used"
18761876
}
18771877

1878-
declare_lint! {
1879-
/// The `broken_intra_doc_links` lint detects failures in resolving
1880-
/// intra-doc link targets. This is a `rustdoc` only lint, see the
1881-
/// documentation in the [rustdoc book].
1882-
///
1883-
/// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links
1884-
pub BROKEN_INTRA_DOC_LINKS,
1885-
Warn,
1886-
"failures in resolving intra-doc link targets"
1887-
}
1888-
1889-
declare_lint! {
1890-
/// This is a subset of `broken_intra_doc_links` that warns when linking from
1891-
/// a public item to a private one. This is a `rustdoc` only lint, see the
1892-
/// documentation in the [rustdoc book].
1893-
///
1894-
/// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links
1895-
pub PRIVATE_INTRA_DOC_LINKS,
1896-
Warn,
1897-
"linking from a public item to a private one"
1898-
}
1899-
1900-
declare_lint! {
1901-
/// The `invalid_codeblock_attributes` lint detects code block attributes
1902-
/// in documentation examples that have potentially mis-typed values. This
1903-
/// is a `rustdoc` only lint, see the documentation in the [rustdoc book].
1904-
///
1905-
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes
1906-
pub INVALID_CODEBLOCK_ATTRIBUTES,
1907-
Warn,
1908-
"codeblock attribute looks a lot like a known one"
1909-
}
1910-
1911-
declare_lint! {
1912-
/// The `missing_crate_level_docs` lint detects if documentation is
1913-
/// missing at the crate root. This is a `rustdoc` only lint, see the
1914-
/// documentation in the [rustdoc book].
1915-
///
1916-
/// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs
1917-
pub MISSING_CRATE_LEVEL_DOCS,
1918-
Allow,
1919-
"detects crates with no crate-level documentation"
1920-
}
1921-
1922-
declare_lint! {
1923-
/// The `missing_doc_code_examples` lint detects publicly-exported items
1924-
/// without code samples in their documentation. This is a `rustdoc` only
1925-
/// lint, see the documentation in the [rustdoc book].
1926-
///
1927-
/// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples
1928-
pub MISSING_DOC_CODE_EXAMPLES,
1929-
Allow,
1930-
"detects publicly-exported items without code samples in their documentation"
1931-
}
1932-
1933-
declare_lint! {
1934-
/// The `private_doc_tests` lint detects code samples in docs of private
1935-
/// items not documented by `rustdoc`. This is a `rustdoc` only lint, see
1936-
/// the documentation in the [rustdoc book].
1937-
///
1938-
/// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests
1939-
pub PRIVATE_DOC_TESTS,
1940-
Allow,
1941-
"detects code samples in docs of private items not documented by rustdoc"
1942-
}
1943-
1944-
declare_lint! {
1945-
/// The `invalid_html_tags` lint detects invalid HTML tags. This is a
1946-
/// `rustdoc` only lint, see the documentation in the [rustdoc book].
1947-
///
1948-
/// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags
1949-
pub INVALID_HTML_TAGS,
1950-
Allow,
1951-
"detects invalid HTML tags in doc comments"
1952-
}
1953-
1954-
declare_lint! {
1955-
/// The `non_autolinks` lint detects when a URL could be written using
1956-
/// only angle brackets. This is a `rustdoc` only lint, see the
1957-
/// documentation in the [rustdoc book].
1958-
///
1959-
/// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks
1960-
pub NON_AUTOLINKS,
1961-
Warn,
1962-
"detects URLs that could be written using only angle brackets"
1963-
}
1964-
19651878
declare_lint! {
19661879
/// The `where_clauses_object_safety` lint detects for [object safety] of
19671880
/// [where clauses].
@@ -3020,14 +2933,6 @@ declare_lint_pass! {
30202933
ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE,
30212934
UNSTABLE_NAME_COLLISIONS,
30222935
IRREFUTABLE_LET_PATTERNS,
3023-
BROKEN_INTRA_DOC_LINKS,
3024-
PRIVATE_INTRA_DOC_LINKS,
3025-
INVALID_CODEBLOCK_ATTRIBUTES,
3026-
MISSING_CRATE_LEVEL_DOCS,
3027-
MISSING_DOC_CODE_EXAMPLES,
3028-
INVALID_HTML_TAGS,
3029-
PRIVATE_DOC_TESTS,
3030-
NON_AUTOLINKS,
30312936
WHERE_CLAUSES_OBJECT_SAFETY,
30322937
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
30332938
MACRO_USE_EXTERN_CRATE,

compiler/rustc_resolve/src/late/diagnostics.rs

+21-8
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
16451645
);
16461646
err.span_label(lifetime_ref.span, "undeclared lifetime");
16471647
let mut suggests_in_band = false;
1648+
let mut suggest_note = true;
16481649
for missing in &self.missing_named_lifetime_spots {
16491650
match missing {
16501651
MissingLifetimeSpot::Generics(generics) => {
@@ -1664,12 +1665,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
16641665
suggests_in_band = true;
16651666
(generics.span, format!("<{}>", lifetime_ref))
16661667
};
1667-
err.span_suggestion(
1668-
span,
1669-
&format!("consider introducing lifetime `{}` here", lifetime_ref),
1670-
sugg,
1671-
Applicability::MaybeIncorrect,
1672-
);
1668+
if !span.from_expansion() {
1669+
err.span_suggestion(
1670+
span,
1671+
&format!("consider introducing lifetime `{}` here", lifetime_ref),
1672+
sugg,
1673+
Applicability::MaybeIncorrect,
1674+
);
1675+
} else if suggest_note {
1676+
suggest_note = false; // Avoid displaying the same help multiple times.
1677+
err.span_label(
1678+
span,
1679+
&format!(
1680+
"lifetime `{}` is missing in item created through this procedural \
1681+
macro",
1682+
lifetime_ref,
1683+
),
1684+
);
1685+
}
16731686
}
16741687
MissingLifetimeSpot::HigherRanked { span, span_type } => {
16751688
err.span_suggestion(
@@ -1684,7 +1697,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
16841697
);
16851698
err.note(
16861699
"for more information on higher-ranked polymorphism, visit \
1687-
https://doc.rust-lang.org/nomicon/hrtb.html",
1700+
https://doc.rust-lang.org/nomicon/hrtb.html",
16881701
);
16891702
}
16901703
_ => {}
@@ -1696,7 +1709,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
16961709
{
16971710
err.help(
16981711
"if you want to experiment with in-band lifetime bindings, \
1699-
add `#![feature(in_band_lifetimes)]` to the crate attributes",
1712+
add `#![feature(in_band_lifetimes)]` to the crate attributes",
17001713
);
17011714
}
17021715
err.emit();

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ symbols! {
10211021
rustc_then_this_would_need,
10221022
rustc_unsafe_specialization_marker,
10231023
rustc_variance,
1024+
rustdoc,
10241025
rustfmt,
10251026
rvalue_static_promotion,
10261027
sanitize,

library/alloc/src/vec/mod.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -1877,7 +1877,15 @@ impl<T, A: Allocator> Vec<T, A> {
18771877
#[unstable(feature = "vec_spare_capacity", issue = "75017")]
18781878
#[inline]
18791879
pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>] {
1880-
self.split_at_spare_mut().1
1880+
// Note:
1881+
// This method is not implemented in terms of `split_at_spare_mut`,
1882+
// to prevent invalidation of pointers to the buffer.
1883+
unsafe {
1884+
slice::from_raw_parts_mut(
1885+
self.as_mut_ptr().add(self.len) as *mut MaybeUninit<T>,
1886+
self.buf.capacity() - self.len,
1887+
)
1888+
}
18811889
}
18821890

18831891
/// Returns vector content as a slice of `T`, along with the remaining spare
@@ -1934,20 +1942,16 @@ impl<T, A: Allocator> Vec<T, A> {
19341942
#[unstable(feature = "vec_split_at_spare", issue = "81944")]
19351943
#[inline]
19361944
pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit<T>]) {
1937-
let ptr = self.as_mut_ptr();
1938-
1939-
// SAFETY:
1940-
// - `ptr` is guaranteed to be in bounds for `capacity` elements
1941-
// - `len` is guaranteed to less or equal to `capacity`
1942-
// - `MaybeUninit<T>` has the same layout as `T`
1943-
let spare_ptr = unsafe { ptr.cast::<MaybeUninit<T>>().add(self.len) };
1945+
let Range { start: ptr, end: spare_ptr } = self.as_mut_ptr_range();
1946+
let spare_ptr = spare_ptr.cast::<MaybeUninit<T>>();
1947+
let spare_len = self.buf.capacity() - self.len;
19441948

19451949
// SAFETY:
19461950
// - `ptr` is guaranteed to be valid for `len` elements
1947-
// - `spare_ptr` is offseted from `ptr` by `len`, so it doesn't overlap `initialized` slice
1951+
// - `spare_ptr` is pointing one element past the buffer, so it doesn't overlap with `initialized`
19481952
unsafe {
19491953
let initialized = slice::from_raw_parts_mut(ptr, self.len);
1950-
let spare = slice::from_raw_parts_mut(spare_ptr, self.buf.capacity() - self.len);
1954+
let spare = slice::from_raw_parts_mut(spare_ptr, spare_len);
19511955

19521956
(initialized, spare)
19531957
}

library/alloc/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(vecdeque_binary_search)]
2121
#![feature(slice_group_by)]
2222
#![feature(vec_extend_from_within)]
23+
#![feature(vec_spare_capacity)]
2324

2425
use std::collections::hash_map::DefaultHasher;
2526
use std::hash::{Hash, Hasher};

library/alloc/tests/vec.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,10 @@ fn test_stable_pointers() {
16911691
next_then_drop(v.splice(5..6, vec![1; 10].into_iter().filter(|_| true))); // lower bound not exact
16921692
assert_eq!(*v0, 13);
16931693

1694+
// spare_capacity_mut
1695+
v.spare_capacity_mut();
1696+
assert_eq!(*v0, 13);
1697+
16941698
// Smoke test that would fire even outside Miri if an actual relocation happened.
16951699
*v0 -= 13;
16961700
assert_eq!(v[0], 0);

library/core/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ pub mod primitive;
297297
unused_imports,
298298
unsafe_op_in_unsafe_fn
299299
)]
300-
#[allow(non_autolinks)]
300+
#[cfg_attr(bootstrap, allow(non_autolinks))]
301+
#[cfg_attr(not(bootstrap), allow(rustdoc::non_autolinks))]
301302
// FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is
302303
// merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet.
303304
#[allow(clashing_extern_declarations)]

src/bootstrap/bootstrap.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,8 @@ def maybe_download_rustc(self):
647647
compiler = "{}/compiler/".format(top_level)
648648

649649
# Look for a version to compare to based on the current commit.
650-
# Ideally this would just use `merge-base`, but on beta and stable branches that wouldn't
651-
# come up with any commits, so hack it and use `author=bors` instead.
652-
merge_base = ["git", "log", "--author=bors", "--pretty=%H", "-n1", "--", compiler]
650+
# Only commits merged by bors will have CI artifacts.
651+
merge_base = ["git", "log", "--author=bors", "--pretty=%H", "-n1"]
653652
commit = subprocess.check_output(merge_base, universal_newlines=True).strip()
654653

655654
# Warn if there were changes to the compiler since the ancestor commit.

src/bootstrap/builder.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,15 @@ impl<'a> Builder<'a> {
735735
.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler))
736736
.env("CFG_RELEASE_CHANNEL", &self.config.channel)
737737
.env("RUSTDOC_REAL", self.rustdoc(compiler))
738-
.env("RUSTC_BOOTSTRAP", "1")
739-
.arg("-Winvalid_codeblock_attributes");
738+
.env("RUSTC_BOOTSTRAP", "1");
739+
740+
// cfg(bootstrap), can be removed on the next beta bump
741+
if compiler.stage == 0 {
742+
cmd.arg("-Winvalid_codeblock_attributes");
743+
} else {
744+
cmd.arg("-Wrustdoc::invalid_codeblock_attributes");
745+
}
746+
740747
if self.config.deny_warnings {
741748
cmd.arg("-Dwarnings");
742749
}
@@ -1292,7 +1299,12 @@ impl<'a> Builder<'a> {
12921299
// fixed via better support from Cargo.
12931300
cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" "));
12941301

1295-
rustdocflags.arg("-Winvalid_codeblock_attributes");
1302+
// cfg(bootstrap), can be removed on the next beta bump
1303+
if compiler.stage == 0 {
1304+
rustdocflags.arg("-Winvalid_codeblock_attributes");
1305+
} else {
1306+
rustdocflags.arg("-Wrustdoc::invalid_codeblock_attributes");
1307+
}
12961308
}
12971309

12981310
if mode == Mode::Rustc {

0 commit comments

Comments
 (0)