From 2f04a793ae0b9331f6d853a971a670c8ea99b0b7 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 27 Feb 2021 00:20:46 +0300 Subject: [PATCH 01/19] Revert `Vec::spare_capacity_mut` impl to prevent pointers invalidation --- library/alloc/src/vec/mod.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index b1b2619428366..e5545d2a77ff7 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1879,7 +1879,15 @@ impl Vec { #[unstable(feature = "vec_spare_capacity", issue = "75017")] #[inline] pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit] { - self.split_at_spare_mut().1 + // Note: + // This method is not implemented in terms of `split_at_spare_mut`, + // to prevent invalidation of pointers to the buffer. + unsafe { + slice::from_raw_parts_mut( + self.as_mut_ptr().add(self.len) as *mut MaybeUninit, + self.buf.capacity() - self.len, + ) + } } /// Returns vector content as a slice of `T`, along with the remaining spare From cc62018e61edfa9706b8e4e61d1b571bdee7827d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Tue, 29 Dec 2020 23:16:16 -0500 Subject: [PATCH 02/19] Rename rustdoc lints to be a tool lint instead of built-in. - Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` - Ensure that the old lint names still work and give deprecation errors - Register lints even when running doctests Otherwise, all `rustdoc::` lints would be ignored. - Register all existing lints as removed This unfortunately doesn't work with `register_renamed` because tool lints have not yet been registered when rustc is running. For similar reasons, `check_backwards_compat` doesn't work either. Call `register_removed` directly instead. - Fix fallout + Rustdoc lints for compiler/ + Rustdoc lints for library/ Note that this does *not* suggest `rustdoc::broken_intra_doc_links` for `rustdoc::intra_doc_link_resolution_failure`, since there was no time when the latter was valid. --- compiler/rustc_ast/src/attr/mod.rs | 2 +- compiler/rustc_error_codes/src/lib.rs | 3 +- compiler/rustc_lint/src/context.rs | 6 +- compiler/rustc_lint/src/lib.rs | 34 +++-- compiler/rustc_lint_defs/src/builtin.rs | 83 ---------- compiler/rustc_span/src/symbol.rs | 1 + library/core/src/lib.rs | 3 +- src/bootstrap/builder.rs | 18 ++- src/librustdoc/core.rs | 144 ++++++++++++++---- src/librustdoc/doctest.rs | 10 +- src/librustdoc/html/markdown.rs | 3 +- src/librustdoc/lib.rs | 1 + .../passes/collect_intra_doc_links.rs | 6 +- src/librustdoc/passes/doc_test_lints.rs | 7 +- src/librustdoc/passes/html_tags.rs | 3 +- src/librustdoc/passes/non_autolinks.rs | 3 +- .../rustdoc-ui/assoc-item-not-in-scope.rs | 2 +- .../rustdoc-ui/assoc-item-not-in-scope.stderr | 4 +- src/test/rustdoc-ui/check-attr-test.rs | 2 +- src/test/rustdoc-ui/check-attr-test.stderr | 4 +- src/test/rustdoc-ui/check-attr.rs | 2 +- src/test/rustdoc-ui/check-attr.stderr | 4 +- src/test/rustdoc-ui/check-fail.stderr | 4 +- src/test/rustdoc-ui/check.stderr | 2 +- .../deny-intra-link-resolution-failure.rs | 2 +- .../deny-intra-link-resolution-failure.stderr | 4 +- src/test/rustdoc-ui/doc-without-codeblock.rs | 2 +- .../rustdoc-ui/doc-without-codeblock.stderr | 6 +- src/test/rustdoc-ui/intra-doc/alias-ice.rs | 2 +- .../rustdoc-ui/intra-doc/alias-ice.stderr | 4 +- src/test/rustdoc-ui/intra-doc/ambiguity.rs | 2 +- .../rustdoc-ui/intra-doc/ambiguity.stderr | 4 +- src/test/rustdoc-ui/intra-doc/anchors.rs | 2 +- src/test/rustdoc-ui/intra-doc/anchors.stderr | 4 +- .../rustdoc-ui/intra-doc/broken-reexport.rs | 2 +- .../intra-doc/disambiguator-mismatch.rs | 2 +- .../intra-doc/disambiguator-mismatch.stderr | 4 +- .../rustdoc-ui/intra-doc/double-anchor.stderr | 2 +- src/test/rustdoc-ui/intra-doc/errors.rs | 2 +- src/test/rustdoc-ui/intra-doc/errors.stderr | 4 +- .../incompatible-primitive-disambiguator.rs | 2 +- ...ncompatible-primitive-disambiguator.stderr | 4 +- .../intra-doc/malformed-generics.rs | 2 +- .../intra-doc/malformed-generics.stderr | 4 +- .../intra-doc/non-path-primitives.rs | 2 +- .../intra-doc/non-path-primitives.stderr | 4 +- .../rustdoc-ui/intra-doc/prim-conflict.rs | 2 +- .../rustdoc-ui/intra-doc/prim-conflict.stderr | 4 +- .../intra-doc/private.private.stderr | 2 +- .../intra-doc/private.public.stderr | 2 +- .../rustdoc-ui/intra-doc/span-ice-55723.rs | 2 +- .../intra-doc/span-ice-55723.stderr | 4 +- .../intra-doc/unused-extern-crate.rs | 2 +- .../intra-doc/unused-extern-crate.stderr | 4 +- .../rustdoc-ui/intra-doc/warning-crlf.stderr | 2 +- src/test/rustdoc-ui/intra-doc/warning.stderr | 2 +- src/test/rustdoc-ui/invalid-html-tags.rs | 2 +- src/test/rustdoc-ui/invalid-html-tags.stderr | 4 +- src/test/rustdoc-ui/issue-58473-2.rs | 2 +- .../rustdoc-ui/issue-74134.private.stderr | 2 +- src/test/rustdoc-ui/issue-74134.public.stderr | 2 +- src/test/rustdoc-ui/lint-group.stderr | 8 +- .../lint-missing-doc-code-example.rs | 4 +- .../lint-missing-doc-code-example.stderr | 4 +- src/test/rustdoc-ui/private-doc-test.rs | 2 +- src/test/rustdoc-ui/private-item-doc-test.rs | 2 +- .../rustdoc-ui/private-item-doc-test.stderr | 4 +- src/test/rustdoc-ui/pub-export-lint.rs | 2 +- src/test/rustdoc-ui/pub-export-lint.stderr | 4 +- .../reference-link-reports-error-once.rs | 2 +- .../reference-link-reports-error-once.stderr | 4 +- src/test/rustdoc-ui/reference-links.rs | 2 +- src/test/rustdoc-ui/reference-links.stderr | 4 +- src/test/rustdoc-ui/unknown-renamed-lints.rs | 13 +- .../rustdoc-ui/unknown-renamed-lints.stderr | 24 ++- src/test/rustdoc-ui/url-improvements.rs | 4 +- src/test/rustdoc-ui/url-improvements.stderr | 4 +- .../rustdoc/intra-doc/non-path-primitives.rs | 2 +- 78 files changed, 301 insertions(+), 243 deletions(-) diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 52ac7540f6943..1e224dbf83390 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -34,7 +34,7 @@ impl MarkedAttrs { } pub fn is_known_lint_tool(m_item: Ident) -> bool { - [sym::clippy, sym::rustc].contains(&m_item.name) + [sym::clippy, sym::rustc, sym::rustdoc].contains(&m_item.name) } impl NestedMetaItem { diff --git a/compiler/rustc_error_codes/src/lib.rs b/compiler/rustc_error_codes/src/lib.rs index e4a702531442e..14ddb3e20793a 100644 --- a/compiler/rustc_error_codes/src/lib.rs +++ b/compiler/rustc_error_codes/src/lib.rs @@ -1,4 +1,5 @@ -#![deny(invalid_codeblock_attributes)] +#![cfg_attr(bootstrap, deny(invalid_codeblock_attributes))] +#![cfg_attr(not(bootstrap), deny(rustdoc::invalid_codeblock_attributes))] //! This library is used to gather all error codes into one place, //! the goal being to make their maintenance easier. diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index b8db51f590d84..7d5577cdca663 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -89,6 +89,7 @@ impl SessionLintStore for LintStore { } /// The target of the `by_name` map, which accounts for renaming/deprecation. +#[derive(Debug)] enum TargetLint { /// A direct lint target Id(LintId), @@ -470,7 +471,10 @@ impl LintStore { Some(&Id(ref id)) => { CheckLintNameResult::Tool(Err((Some(slice::from_ref(id)), complete_name))) } - _ => CheckLintNameResult::NoLint(None), + Some(other) => { + tracing::debug!("got renamed lint {:?}", other); + CheckLintNameResult::NoLint(None) + } } } } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 638b73c27a8d7..67c0e999f5518 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -69,9 +69,7 @@ use rustc_hir::def_id::LocalDefId; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::lint::builtin::{ - BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS, - EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS, - MISSING_DOC_CODE_EXAMPLES, NON_AUTOLINKS, PRIVATE_DOC_TESTS, + BARE_TRAIT_OBJECTS, ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_OUTLIVES_REQUIREMENTS, }; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::Span; @@ -314,17 +312,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { // MACRO_USE_EXTERN_CRATE ); - add_lint_group!( - "rustdoc", - NON_AUTOLINKS, - BROKEN_INTRA_DOC_LINKS, - PRIVATE_INTRA_DOC_LINKS, - INVALID_CODEBLOCK_ATTRIBUTES, - MISSING_DOC_CODE_EXAMPLES, - PRIVATE_DOC_TESTS, - INVALID_HTML_TAGS - ); - // Register renamed and removed lints. store.register_renamed("single_use_lifetime", "single_use_lifetimes"); store.register_renamed("elided_lifetime_in_path", "elided_lifetimes_in_paths"); @@ -334,8 +321,25 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { store.register_renamed("async_idents", "keyword_idents"); store.register_renamed("exceeding_bitshifts", "arithmetic_overflow"); store.register_renamed("redundant_semicolon", "redundant_semicolons"); - store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links"); store.register_renamed("overlapping_patterns", "overlapping_range_endpoints"); + + // These were moved to tool lints, but rustc still sees them when compiling normally, before + // tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use + // `register_renamed` explicitly. + const RUSTDOC_LINTS: &[&str] = &[ + "broken_intra_doc_links", + "private_intra_doc_links", + "missing_doc_code_examples", + "private_doc_tests", + "invalid_codeblock_attributes", + "invalid_html_tags", + "non_autolinks", + ]; + for rustdoc_lint in RUSTDOC_LINTS { + // FIXME: maybe we could get `register_renamed` to work for tool lints? + store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint)); + } + store.register_removed("unknown_features", "replaced by an error"); store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate"); store.register_removed("negate_unsigned", "cast a signed value instead"); diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 46138df07bf69..53bb0fb28a65b 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1875,39 +1875,6 @@ declare_lint! { "detects labels that are never used" } -declare_lint! { - /// The `broken_intra_doc_links` lint detects failures in resolving - /// intra-doc link targets. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links - pub BROKEN_INTRA_DOC_LINKS, - Warn, - "failures in resolving intra-doc link targets" -} - -declare_lint! { - /// This is a subset of `broken_intra_doc_links` that warns when linking from - /// a public item to a private one. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links - pub PRIVATE_INTRA_DOC_LINKS, - Warn, - "linking from a public item to a private one" -} - -declare_lint! { - /// The `invalid_codeblock_attributes` lint detects code block attributes - /// in documentation examples that have potentially mis-typed values. This - /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes - pub INVALID_CODEBLOCK_ATTRIBUTES, - Warn, - "codeblock attribute looks a lot like a known one" -} - declare_lint! { /// The `missing_crate_level_docs` lint detects if documentation is /// missing at the crate root. This is a `rustdoc` only lint, see the @@ -1919,49 +1886,6 @@ declare_lint! { "detects crates with no crate-level documentation" } -declare_lint! { - /// The `missing_doc_code_examples` lint detects publicly-exported items - /// without code samples in their documentation. This is a `rustdoc` only - /// lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples - pub MISSING_DOC_CODE_EXAMPLES, - Allow, - "detects publicly-exported items without code samples in their documentation" -} - -declare_lint! { - /// The `private_doc_tests` lint detects code samples in docs of private - /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see - /// the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests - pub PRIVATE_DOC_TESTS, - Allow, - "detects code samples in docs of private items not documented by rustdoc" -} - -declare_lint! { - /// The `invalid_html_tags` lint detects invalid HTML tags. This is a - /// `rustdoc` only lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags - pub INVALID_HTML_TAGS, - Allow, - "detects invalid HTML tags in doc comments" -} - -declare_lint! { - /// The `non_autolinks` lint detects when a URL could be written using - /// only angle brackets. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks - pub NON_AUTOLINKS, - Warn, - "detects URLs that could be written using only angle brackets" -} - declare_lint! { /// The `where_clauses_object_safety` lint detects for [object safety] of /// [where clauses]. @@ -3020,14 +2944,7 @@ declare_lint_pass! { ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, UNSTABLE_NAME_COLLISIONS, IRREFUTABLE_LET_PATTERNS, - BROKEN_INTRA_DOC_LINKS, - PRIVATE_INTRA_DOC_LINKS, - INVALID_CODEBLOCK_ATTRIBUTES, MISSING_CRATE_LEVEL_DOCS, - MISSING_DOC_CODE_EXAMPLES, - INVALID_HTML_TAGS, - PRIVATE_DOC_TESTS, - NON_AUTOLINKS, WHERE_CLAUSES_OBJECT_SAFETY, PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, MACRO_USE_EXTERN_CRATE, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index f87267da9f6c7..a74ca5c1f7698 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1020,6 +1020,7 @@ symbols! { rustc_then_this_would_need, rustc_unsafe_specialization_marker, rustc_variance, + rustdoc, rustfmt, rvalue_static_promotion, sanitize, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 64e2a95130999..cb2bfa034188b 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -297,7 +297,8 @@ pub mod primitive; unused_imports, unsafe_op_in_unsafe_fn )] -#[allow(non_autolinks)] +#[cfg_attr(bootstrap, allow(non_autolinks))] +#[cfg_attr(not(bootstrap), allow(rustdoc::non_autolinks))] // FIXME: This annotation should be moved into rust-lang/stdarch after clashing_extern_declarations is // merged. It currently cannot because bootstrap fails as the lint hasn't been defined yet. #[allow(clashing_extern_declarations)] diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 2008348ea8d8e..9317c89625d06 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -735,8 +735,15 @@ impl<'a> Builder<'a> { .env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler)) .env("CFG_RELEASE_CHANNEL", &self.config.channel) .env("RUSTDOC_REAL", self.rustdoc(compiler)) - .env("RUSTC_BOOTSTRAP", "1") - .arg("-Winvalid_codeblock_attributes"); + .env("RUSTC_BOOTSTRAP", "1"); + + // cfg(bootstrap), can be removed on the next beta bump + if compiler.stage == 0 { + cmd.arg("-Winvalid_codeblock_attributes"); + } else { + cmd.arg("-Wrustdoc::invalid_codeblock_attributes"); + } + if self.config.deny_warnings { cmd.arg("-Dwarnings"); } @@ -1292,7 +1299,12 @@ impl<'a> Builder<'a> { // fixed via better support from Cargo. cargo.env("RUSTC_LINT_FLAGS", lint_flags.join(" ")); - rustdocflags.arg("-Winvalid_codeblock_attributes"); + // cfg(bootstrap), can be removed on the next beta bump + if compiler.stage == 0 { + rustdocflags.arg("-Winvalid_codeblock_attributes"); + } else { + rustdocflags.arg("-Wrustdoc::invalid_codeblock_attributes"); + } } if mode == Mode::Rustc { diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index f0b3159f737a6..0dc762ea27665 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -12,6 +12,8 @@ use rustc_hir::{ Path, }; use rustc_interface::{interface, Queries}; +use rustc_lint::LintStore; +use rustc_lint_defs::{declare_tool_lint, Lint, LintId}; use rustc_middle::hir::map::Map; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; @@ -24,9 +26,11 @@ use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::DUMMY_SP; +use std::cell::RefCell; +use std::collections::hash_map::Entry; +use std::lazy::SyncLazy as Lazy; use std::mem; use std::rc::Rc; -use std::{cell::RefCell, collections::hash_map::Entry}; use crate::clean; use crate::clean::inline::build_external_trait; @@ -286,6 +290,106 @@ where (lint_opts, lint_caps) } +declare_tool_lint! { + /// The `broken_intra_doc_links` lint detects failures in resolving + /// intra-doc link targets. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links + pub rustdoc::BROKEN_INTRA_DOC_LINKS, + Warn, + "failures in resolving intra-doc link targets" +} + +declare_tool_lint! { + /// This is a subset of `broken_intra_doc_links` that warns when linking from + /// a public item to a private one. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links + pub rustdoc::PRIVATE_INTRA_DOC_LINKS, + Warn, + "linking from a public item to a private one" +} + +declare_tool_lint! { + /// The `invalid_codeblock_attributes` lint detects code block attributes + /// in documentation examples that have potentially mis-typed values. This + /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes + pub rustdoc::INVALID_CODEBLOCK_ATTRIBUTES, + Warn, + "codeblock attribute looks a lot like a known one" +} + +declare_tool_lint! { + /// The `missing_doc_code_examples` lint detects publicly-exported items + /// without code samples in their documentation. This is a `rustdoc` only + /// lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples + pub rustdoc::MISSING_DOC_CODE_EXAMPLES, + Allow, + "detects publicly-exported items without code samples in their documentation" +} + +declare_tool_lint! { + /// The `private_doc_tests` lint detects code samples in docs of private + /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see + /// the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests + pub rustdoc::PRIVATE_DOC_TESTS, + Allow, + "detects code samples in docs of private items not documented by rustdoc" +} + +declare_tool_lint! { + /// The `invalid_html_tags` lint detects invalid HTML tags. This is a + /// `rustdoc` only lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags + pub rustdoc::INVALID_HTML_TAGS, + Allow, + "detects invalid HTML tags in doc comments" +} + +declare_tool_lint! { + /// The `non_autolinks` lint detects when a URL could be written using + /// only angle brackets. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks + pub rustdoc::NON_AUTOLINKS, + Warn, + "detects URLs that could be written using only angle brackets" +} + +static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { + vec![ + BROKEN_INTRA_DOC_LINKS, + PRIVATE_INTRA_DOC_LINKS, + MISSING_DOC_CODE_EXAMPLES, + PRIVATE_DOC_TESTS, + INVALID_CODEBLOCK_ATTRIBUTES, + INVALID_HTML_TAGS, + NON_AUTOLINKS, + ] +}); + +crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { + lint_store.register_lints(&**RUSTDOC_LINTS); + lint_store.register_group( + true, + "rustdoc", + None, + RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), + ); + lint_store + .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); +} + /// Parse, resolve, and typecheck the given crate. crate fn create_config( RustdocOptions { @@ -314,37 +418,23 @@ crate fn create_config( let cpath = Some(input.clone()); let input = Input::File(input); - let broken_intra_doc_links = lint::builtin::BROKEN_INTRA_DOC_LINKS.name; - let private_intra_doc_links = lint::builtin::PRIVATE_INTRA_DOC_LINKS.name; - let missing_docs = rustc_lint::builtin::MISSING_DOCS.name; - let missing_doc_example = rustc_lint::builtin::MISSING_DOC_CODE_EXAMPLES.name; - let private_doc_tests = rustc_lint::builtin::PRIVATE_DOC_TESTS.name; - let no_crate_level_docs = rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name; - let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name; - let invalid_html_tags = rustc_lint::builtin::INVALID_HTML_TAGS.name; - let renamed_and_removed_lints = rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name; - let non_autolinks = rustc_lint::builtin::NON_AUTOLINKS.name; - let unknown_lints = rustc_lint::builtin::UNKNOWN_LINTS.name; - // In addition to those specific lints, we also need to allow those given through // command line, otherwise they'll get ignored and we don't want that. - let lints_to_show = vec![ - broken_intra_doc_links.to_owned(), - private_intra_doc_links.to_owned(), - missing_docs.to_owned(), - missing_doc_example.to_owned(), - private_doc_tests.to_owned(), - no_crate_level_docs.to_owned(), - invalid_codeblock_attributes_name.to_owned(), - invalid_html_tags.to_owned(), - renamed_and_removed_lints.to_owned(), - unknown_lints.to_owned(), - non_autolinks.to_owned(), + let mut lints_to_show = vec![ + // it's unclear whether these should be part of rustdoc directly + rustc_lint::builtin::MISSING_DOCS.name.to_string(), + rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name.to_string(), + // these are definitely not part of rustdoc, but we want to warn on them anyway. + rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(), + rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(), ]; + lints_to_show.extend(RUSTDOC_LINTS.iter().map(|lint| lint.name.to_string())); let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| { // FIXME: why is this necessary? - if lint.name == broken_intra_doc_links || lint.name == invalid_codeblock_attributes_name { + if lint.name == BROKEN_INTRA_DOC_LINKS.name + || lint.name == INVALID_CODEBLOCK_ATTRIBUTES.name + { None } else { Some((lint.name_lower(), lint::Allow)) @@ -384,7 +474,7 @@ crate fn create_config( diagnostic_output: DiagnosticOutput::Default, stderr: None, lint_caps, - register_lints: None, + register_lints: Some(box register_lints), override_queries: Some(|_sess, providers, _external_providers| { // Most lints will require typechecking, so just don't run them. providers.lint_mod = |_, _| {}; diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index c3b9fd5a1dd42..eac0ad688d4a2 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -44,11 +44,15 @@ crate struct TestOptions { crate fn run(options: Options) -> Result<(), ErrorReported> { let input = config::Input::File(options.input.clone()); - let invalid_codeblock_attributes_name = rustc_lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES.name; + let invalid_codeblock_attributes_name = crate::core::INVALID_CODEBLOCK_ATTRIBUTES.name; // In addition to those specific lints, we also need to allow those given through // command line, otherwise they'll get ignored and we don't want that. - let allowed_lints = vec![invalid_codeblock_attributes_name.to_owned()]; + let allowed_lints = vec![ + invalid_codeblock_attributes_name.to_owned(), + lint::builtin::UNKNOWN_LINTS.name.to_owned(), + lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_owned(), + ]; let (lint_opts, lint_caps) = init_lints(allowed_lints, options.lint_opts.clone(), |lint| { if lint.name == invalid_codeblock_attributes_name { @@ -92,7 +96,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { diagnostic_output: DiagnosticOutput::Default, stderr: None, lint_caps, - register_lints: None, + register_lints: Some(box crate::core::register_lints), override_queries: None, make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 9a054e29dd3b5..8c8840e38e6a6 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -21,7 +21,6 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; use rustc_hir::HirId; use rustc_middle::ty::TyCtxt; -use rustc_session::lint; use rustc_span::edition::Edition; use rustc_span::Span; use std::borrow::Cow; @@ -721,7 +720,7 @@ impl<'tcx> ExtraInfo<'tcx> { (None, None) => return, }; self.tcx.struct_span_lint_hir( - lint::builtin::INVALID_CODEBLOCK_ATTRIBUTES, + crate::core::INVALID_CODEBLOCK_ATTRIBUTES, hir_id, self.sp, |lint| { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 2342ed3ab670d..6388733c8b219 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -45,6 +45,7 @@ extern crate rustc_infer; extern crate rustc_interface; extern crate rustc_lexer; extern crate rustc_lint; +extern crate rustc_lint_defs; extern crate rustc_metadata; extern crate rustc_middle; extern crate rustc_mir; diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index c047f8729adc1..6619adb5b7650 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -16,10 +16,7 @@ use rustc_hir::def_id::{CrateNum, DefId}; use rustc_middle::ty::TyCtxt; use rustc_middle::{bug, ty}; use rustc_resolve::ParentScope; -use rustc_session::lint::{ - builtin::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}, - Lint, -}; +use rustc_session::lint::Lint; use rustc_span::hygiene::{MacroKind, SyntaxContext}; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::DUMMY_SP; @@ -35,6 +32,7 @@ use std::ops::Range; use crate::clean::{self, utils::find_nearest_parent_module, Crate, Item, ItemLink, PrimitiveType}; use crate::core::DocContext; +use crate::core::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}; use crate::fold::DocFolder; use crate::html::markdown::{markdown_links, MarkdownLink}; use crate::passes::Pass; diff --git a/src/librustdoc/passes/doc_test_lints.rs b/src/librustdoc/passes/doc_test_lints.rs index e8e1bead84fb6..85547e557df5b 100644 --- a/src/librustdoc/passes/doc_test_lints.rs +++ b/src/librustdoc/passes/doc_test_lints.rs @@ -68,8 +68,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo return false; } let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local()); - let (level, source) = - cx.tcx.lint_level_at_node(lint::builtin::MISSING_DOC_CODE_EXAMPLES, hir_id); + let (level, source) = cx.tcx.lint_level_at_node(crate::core::MISSING_DOC_CODE_EXAMPLES, hir_id); level != lint::Level::Allow || matches!(source, LintLevelSource::Default) } @@ -91,7 +90,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); cx.tcx.struct_span_lint_hir( - lint::builtin::MISSING_DOC_CODE_EXAMPLES, + crate::core::MISSING_DOC_CODE_EXAMPLES, hir_id, sp, |lint| lint.build("missing code example in this documentation").emit(), @@ -99,7 +98,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { } } else if tests.found_tests > 0 && !cx.renderinfo.access_levels.is_public(item.def_id) { cx.tcx.struct_span_lint_hir( - lint::builtin::PRIVATE_DOC_TESTS, + crate::core::PRIVATE_DOC_TESTS, hir_id, span_of_attrs(&item.attrs).unwrap_or(item.source.span()), |lint| lint.build("documentation test in private item").emit(), diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index a6fe7e228d7e8..b97872c633392 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -5,7 +5,6 @@ use crate::fold::DocFolder; use crate::html::markdown::opts; use core::ops::Range; use pulldown_cmark::{Event, Parser, Tag}; -use rustc_session::lint; use std::iter::Peekable; use std::str::CharIndices; @@ -183,7 +182,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> { Some(sp) => sp, None => span_of_attrs(&item.attrs).unwrap_or(item.source.span()), }; - cx.tcx.struct_span_lint_hir(lint::builtin::INVALID_HTML_TAGS, hir_id, sp, |lint| { + cx.tcx.struct_span_lint_hir(crate::core::INVALID_HTML_TAGS, hir_id, sp, |lint| { lint.build(msg).emit() }); }; diff --git a/src/librustdoc/passes/non_autolinks.rs b/src/librustdoc/passes/non_autolinks.rs index 9d4539a9769ca..fe21887fc050b 100644 --- a/src/librustdoc/passes/non_autolinks.rs +++ b/src/librustdoc/passes/non_autolinks.rs @@ -7,7 +7,6 @@ use core::ops::Range; use pulldown_cmark::{Event, LinkType, Parser, Tag}; use regex::Regex; use rustc_errors::Applicability; -use rustc_session::lint; crate const CHECK_NON_AUTOLINKS: Pass = Pass { name: "check-non-autolinks", @@ -74,7 +73,7 @@ impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> { let sp = super::source_span_for_markdown_range(cx, &dox, &range, &item.attrs) .or_else(|| span_of_attrs(&item.attrs)) .unwrap_or(item.source.span()); - cx.tcx.struct_span_lint_hir(lint::builtin::NON_AUTOLINKS, hir_id, sp, |lint| { + cx.tcx.struct_span_lint_hir(crate::core::NON_AUTOLINKS, hir_id, sp, |lint| { lint.build(msg) .span_suggestion( sp, diff --git a/src/test/rustdoc-ui/assoc-item-not-in-scope.rs b/src/test/rustdoc-ui/assoc-item-not-in-scope.rs index c5bb4305db7ec..0976515f4a426 100644 --- a/src/test/rustdoc-ui/assoc-item-not-in-scope.rs +++ b/src/test/rustdoc-ui/assoc-item-not-in-scope.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] #[derive(Debug)] /// Link to [`S::fmt`] diff --git a/src/test/rustdoc-ui/assoc-item-not-in-scope.stderr b/src/test/rustdoc-ui/assoc-item-not-in-scope.stderr index 92d27179e8c3f..358871b532313 100644 --- a/src/test/rustdoc-ui/assoc-item-not-in-scope.stderr +++ b/src/test/rustdoc-ui/assoc-item-not-in-scope.stderr @@ -7,8 +7,8 @@ LL | /// Link to [`S::fmt`] note: the lint level is defined here --> $DIR/assoc-item-not-in-scope.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc-ui/check-attr-test.rs b/src/test/rustdoc-ui/check-attr-test.rs index 665f330e34ea5..023d620bea222 100644 --- a/src/test/rustdoc-ui/check-attr-test.rs +++ b/src/test/rustdoc-ui/check-attr-test.rs @@ -1,6 +1,6 @@ // compile-flags:--test -#![deny(invalid_codeblock_attributes)] +#![deny(rustdoc::invalid_codeblock_attributes)] /// foo /// diff --git a/src/test/rustdoc-ui/check-attr-test.stderr b/src/test/rustdoc-ui/check-attr-test.stderr index 1e067a5d21c44..affd0372a1f5e 100644 --- a/src/test/rustdoc-ui/check-attr-test.stderr +++ b/src/test/rustdoc-ui/check-attr-test.stderr @@ -11,8 +11,8 @@ error: unknown attribute `compile-fail`. Did you mean `compile_fail`? note: the lint level is defined here --> $DIR/check-attr-test.rs:3:9 | -3 | #![deny(invalid_codeblock_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 | #![deny(rustdoc::invalid_codeblock_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully error: unknown attribute `compilefail`. Did you mean `compile_fail`? diff --git a/src/test/rustdoc-ui/check-attr.rs b/src/test/rustdoc-ui/check-attr.rs index 9e02eab753e26..763bc4c6cddb9 100644 --- a/src/test/rustdoc-ui/check-attr.rs +++ b/src/test/rustdoc-ui/check-attr.rs @@ -1,4 +1,4 @@ -#![deny(invalid_codeblock_attributes)] +#![deny(rustdoc::invalid_codeblock_attributes)] /// foo //~^ ERROR diff --git a/src/test/rustdoc-ui/check-attr.stderr b/src/test/rustdoc-ui/check-attr.stderr index 919eb047eefb5..9312cfb76f35f 100644 --- a/src/test/rustdoc-ui/check-attr.stderr +++ b/src/test/rustdoc-ui/check-attr.stderr @@ -13,8 +13,8 @@ LL | | /// ``` note: the lint level is defined here --> $DIR/check-attr.rs:1:9 | -LL | #![deny(invalid_codeblock_attributes)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::invalid_codeblock_attributes)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully error: unknown attribute `compilefail`. Did you mean `compile_fail`? diff --git a/src/test/rustdoc-ui/check-fail.stderr b/src/test/rustdoc-ui/check-fail.stderr index b4f255642da53..9f5ccbc6687c2 100644 --- a/src/test/rustdoc-ui/check-fail.stderr +++ b/src/test/rustdoc-ui/check-fail.stderr @@ -21,7 +21,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc)]` error: unknown attribute `testharness`. Did you mean `test_harness`? --> $DIR/check-fail.rs:6:1 @@ -37,7 +37,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(invalid_codeblock_attributes)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::invalid_codeblock_attributes)]` implied by `#[deny(rustdoc)]` = help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function error: unknown attribute `testharness`. Did you mean `test_harness`? diff --git a/src/test/rustdoc-ui/check.stderr b/src/test/rustdoc-ui/check.stderr index 27e5a736148e1..3c29a45a64a98 100644 --- a/src/test/rustdoc-ui/check.stderr +++ b/src/test/rustdoc-ui/check.stderr @@ -37,7 +37,7 @@ note: the lint level is defined here | LL | #![warn(rustdoc)] | ^^^^^^^ - = note: `#[warn(missing_doc_code_examples)]` implied by `#[warn(rustdoc)]` + = note: `#[warn(rustdoc::missing_doc_code_examples)]` implied by `#[warn(rustdoc)]` warning: missing code example in this documentation --> $DIR/check.rs:9:1 diff --git a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs index 54e7689f3163f..09da124b16206 100644 --- a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs +++ b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] /// [v2] //~ ERROR pub fn foo() {} diff --git a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr index 9ec9dd4bc9ab7..67d9c3989f5ae 100644 --- a/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr +++ b/src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr @@ -7,8 +7,8 @@ LL | /// [v2] note: the lint level is defined here --> $DIR/deny-intra-link-resolution-failure.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/doc-without-codeblock.rs b/src/test/rustdoc-ui/doc-without-codeblock.rs index 5ad8e8a826f05..6812a454157b9 100644 --- a/src/test/rustdoc-ui/doc-without-codeblock.rs +++ b/src/test/rustdoc-ui/doc-without-codeblock.rs @@ -1,4 +1,4 @@ -#![deny(missing_doc_code_examples)] //~ ERROR missing code example in this documentation +#![deny(rustdoc::missing_doc_code_examples)] //~ ERROR missing code example in this documentation /// Some docs. //~^ ERROR missing code example in this documentation diff --git a/src/test/rustdoc-ui/doc-without-codeblock.stderr b/src/test/rustdoc-ui/doc-without-codeblock.stderr index 3372304f44a3d..aac537e9783cd 100644 --- a/src/test/rustdoc-ui/doc-without-codeblock.stderr +++ b/src/test/rustdoc-ui/doc-without-codeblock.stderr @@ -1,7 +1,7 @@ error: missing code example in this documentation --> $DIR/doc-without-codeblock.rs:1:1 | -LL | / #![deny(missing_doc_code_examples)] +LL | / #![deny(rustdoc::missing_doc_code_examples)] LL | | LL | | /// Some docs. LL | | @@ -13,8 +13,8 @@ LL | | } note: the lint level is defined here --> $DIR/doc-without-codeblock.rs:1:9 | -LL | #![deny(missing_doc_code_examples)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::missing_doc_code_examples)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing code example in this documentation --> $DIR/doc-without-codeblock.rs:7:1 diff --git a/src/test/rustdoc-ui/intra-doc/alias-ice.rs b/src/test/rustdoc-ui/intra-doc/alias-ice.rs index c053e378e7147..51922caeb2543 100644 --- a/src/test/rustdoc-ui/intra-doc/alias-ice.rs +++ b/src/test/rustdoc-ui/intra-doc/alias-ice.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] pub type TypeAlias = usize; diff --git a/src/test/rustdoc-ui/intra-doc/alias-ice.stderr b/src/test/rustdoc-ui/intra-doc/alias-ice.stderr index 3db5fad4cfbdc..5e7ffeeb8a219 100644 --- a/src/test/rustdoc-ui/intra-doc/alias-ice.stderr +++ b/src/test/rustdoc-ui/intra-doc/alias-ice.stderr @@ -7,8 +7,8 @@ LL | /// [broken cross-reference](TypeAlias::hoge) note: the lint level is defined here --> $DIR/alias-ice.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/ambiguity.rs b/src/test/rustdoc-ui/intra-doc/ambiguity.rs index f63435337cfbc..1f3dc722eff8d 100644 --- a/src/test/rustdoc-ui/intra-doc/ambiguity.rs +++ b/src/test/rustdoc-ui/intra-doc/ambiguity.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] diff --git a/src/test/rustdoc-ui/intra-doc/ambiguity.stderr b/src/test/rustdoc-ui/intra-doc/ambiguity.stderr index 7e967dc88bcdd..0f23b9b8adf67 100644 --- a/src/test/rustdoc-ui/intra-doc/ambiguity.stderr +++ b/src/test/rustdoc-ui/intra-doc/ambiguity.stderr @@ -7,8 +7,8 @@ LL | /// [true] note: the lint level is defined here --> $DIR/ambiguity.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to link to the module, prefix with `mod@` | LL | /// [mod@true] diff --git a/src/test/rustdoc-ui/intra-doc/anchors.rs b/src/test/rustdoc-ui/intra-doc/anchors.rs index ccefd2e6fabb5..009b291be1f08 100644 --- a/src/test/rustdoc-ui/intra-doc/anchors.rs +++ b/src/test/rustdoc-ui/intra-doc/anchors.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] // A few tests on anchors. diff --git a/src/test/rustdoc-ui/intra-doc/anchors.stderr b/src/test/rustdoc-ui/intra-doc/anchors.stderr index 5b272d960d50f..97b0cea0c1e4d 100644 --- a/src/test/rustdoc-ui/intra-doc/anchors.stderr +++ b/src/test/rustdoc-ui/intra-doc/anchors.stderr @@ -7,8 +7,8 @@ LL | /// Or maybe [Foo::f#hola]. note: the lint level is defined here --> $DIR/anchors.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `hello#people#!` contains multiple anchors --> $DIR/anchors.rs:31:28 diff --git a/src/test/rustdoc-ui/intra-doc/broken-reexport.rs b/src/test/rustdoc-ui/intra-doc/broken-reexport.rs index ef261359ebd9e..862faa50b4ddd 100644 --- a/src/test/rustdoc-ui/intra-doc/broken-reexport.rs +++ b/src/test/rustdoc-ui/intra-doc/broken-reexport.rs @@ -1,7 +1,7 @@ // aux-build:intra-doc-broken.rs // check-pass -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] extern crate intra_doc_broken; diff --git a/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.rs b/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.rs index b9c8e033b1b21..596623190a33f 100644 --- a/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.rs +++ b/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //~^ NOTE lint level is defined pub enum S {} diff --git a/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr b/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr index 2f5f3daa29785..5d4d4a699e4f3 100644 --- a/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr +++ b/src/test/rustdoc-ui/intra-doc/disambiguator-mismatch.stderr @@ -7,8 +7,8 @@ LL | /// Link to [struct@S] note: the lint level is defined here --> $DIR/disambiguator-mismatch.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this link resolved to an enum, which is not a struct error: incompatible link kind for `S` diff --git a/src/test/rustdoc-ui/intra-doc/double-anchor.stderr b/src/test/rustdoc-ui/intra-doc/double-anchor.stderr index 1cd9231eded4d..c0241b98b78c1 100644 --- a/src/test/rustdoc-ui/intra-doc/double-anchor.stderr +++ b/src/test/rustdoc-ui/intra-doc/double-anchor.stderr @@ -4,7 +4,7 @@ warning: `with#anchor#error` contains multiple anchors LL | /// docs [label][with#anchor#error] | ^^^^^^^^^^^^^^^^^ contains invalid anchor | - = note: `#[warn(broken_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/intra-doc/errors.rs b/src/test/rustdoc-ui/intra-doc/errors.rs index 81e42643ae8fc..b29f7c29b5d86 100644 --- a/src/test/rustdoc-ui/intra-doc/errors.rs +++ b/src/test/rustdoc-ui/intra-doc/errors.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //~^ NOTE lint level is defined // FIXME: this should say that it was skipped (maybe an allowed by default lint?) diff --git a/src/test/rustdoc-ui/intra-doc/errors.stderr b/src/test/rustdoc-ui/intra-doc/errors.stderr index 21c806108e3af..061151720578b 100644 --- a/src/test/rustdoc-ui/intra-doc/errors.stderr +++ b/src/test/rustdoc-ui/intra-doc/errors.stderr @@ -7,8 +7,8 @@ LL | /// [path::to::nonexistent::module] note: the lint level is defined here --> $DIR/errors.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unresolved link to `path::to::nonexistent::macro` --> $DIR/errors.rs:11:6 diff --git a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs index 0d1d5d1134b7b..3088bcd46531e 100644 --- a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs +++ b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.rs @@ -1,3 +1,3 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //! [static@u8::MIN] //~^ ERROR incompatible link kind diff --git a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr index ed1c10f9e0cb8..d4dcc493c8b6a 100644 --- a/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr +++ b/src/test/rustdoc-ui/intra-doc/incompatible-primitive-disambiguator.stderr @@ -7,8 +7,8 @@ LL | //! [static@u8::MIN] note: the lint level is defined here --> $DIR/incompatible-primitive-disambiguator.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this link resolved to an associated constant, which is not a static error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/malformed-generics.rs b/src/test/rustdoc-ui/intra-doc/malformed-generics.rs index 9c54092146fef..15e02925ed90d 100644 --- a/src/test/rustdoc-ui/intra-doc/malformed-generics.rs +++ b/src/test/rustdoc-ui/intra-doc/malformed-generics.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //! [Vec<] //~ ERROR //! [Vec $DIR/malformed-generics.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unresolved link to `Vec $DIR/malformed-generics.rs:4:6 diff --git a/src/test/rustdoc-ui/intra-doc/non-path-primitives.rs b/src/test/rustdoc-ui/intra-doc/non-path-primitives.rs index 6785c4c43f541..75159979e8890 100644 --- a/src/test/rustdoc-ui/intra-doc/non-path-primitives.rs +++ b/src/test/rustdoc-ui/intra-doc/non-path-primitives.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] #![feature(intra_doc_pointers)] // These are links that could reasonably expected to work, but don't. diff --git a/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr b/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr index 174758504ae22..610c830560527 100644 --- a/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr +++ b/src/test/rustdoc-ui/intra-doc/non-path-primitives.stderr @@ -7,8 +7,8 @@ LL | //! [[T]::rotate_left] note: the lint level is defined here --> $DIR/non-path-primitives.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: unresolved link to `Z` diff --git a/src/test/rustdoc-ui/intra-doc/prim-conflict.rs b/src/test/rustdoc-ui/intra-doc/prim-conflict.rs index 85738ceae8e61..2c1a8b5357aa1 100644 --- a/src/test/rustdoc-ui/intra-doc/prim-conflict.rs +++ b/src/test/rustdoc-ui/intra-doc/prim-conflict.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //~^ NOTE lint level is defined /// [char] diff --git a/src/test/rustdoc-ui/intra-doc/prim-conflict.stderr b/src/test/rustdoc-ui/intra-doc/prim-conflict.stderr index 01275f8d9afb0..e4bd9fd4b8f1a 100644 --- a/src/test/rustdoc-ui/intra-doc/prim-conflict.stderr +++ b/src/test/rustdoc-ui/intra-doc/prim-conflict.stderr @@ -7,8 +7,8 @@ LL | /// [char] note: the lint level is defined here --> $DIR/prim-conflict.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: to link to the module, prefix with `mod@` | LL | /// [mod@char] diff --git a/src/test/rustdoc-ui/intra-doc/private.private.stderr b/src/test/rustdoc-ui/intra-doc/private.private.stderr index 94a833fcc1a15..cae5b1f20e6c3 100644 --- a/src/test/rustdoc-ui/intra-doc/private.private.stderr +++ b/src/test/rustdoc-ui/intra-doc/private.private.stderr @@ -4,7 +4,7 @@ warning: public documentation for `DocMe` links to private item `DontDocMe` LL | /// docs [DontDocMe] [DontDocMe::f] | ^^^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link resolves only because you passed `--document-private-items`, but will break without warning: public documentation for `DocMe` links to private item `DontDocMe::f` diff --git a/src/test/rustdoc-ui/intra-doc/private.public.stderr b/src/test/rustdoc-ui/intra-doc/private.public.stderr index 21a60638d5efc..05b202e37fbcb 100644 --- a/src/test/rustdoc-ui/intra-doc/private.public.stderr +++ b/src/test/rustdoc-ui/intra-doc/private.public.stderr @@ -4,7 +4,7 @@ warning: public documentation for `DocMe` links to private item `DontDocMe` LL | /// docs [DontDocMe] [DontDocMe::f] | ^^^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link will resolve properly if you pass `--document-private-items` warning: public documentation for `DocMe` links to private item `DontDocMe::f` diff --git a/src/test/rustdoc-ui/intra-doc/span-ice-55723.rs b/src/test/rustdoc-ui/intra-doc/span-ice-55723.rs index 7764a6df6ee77..041ec29325923 100644 --- a/src/test/rustdoc-ui/intra-doc/span-ice-55723.rs +++ b/src/test/rustdoc-ui/intra-doc/span-ice-55723.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] // An error in calculating spans while reporting intra-doc link resolution errors caused rustdoc to // attempt to slice in the middle of a multibyte character. See diff --git a/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr b/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr index 10ca14e850fd7..bf4ab9fdd18b1 100644 --- a/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr +++ b/src/test/rustdoc-ui/intra-doc/span-ice-55723.stderr @@ -7,8 +7,8 @@ LL | /// (arr[i]) note: the lint level is defined here --> $DIR/span-ice-55723.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs index 186503cf69d3f..9565830930f41 100644 --- a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs @@ -1,5 +1,5 @@ // compile-flags: --extern zip=whatever.rlib -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] /// See [zip] crate. //~^ ERROR unresolved pub struct ArrayZip; diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr index b3b57fd131838..5c0df1d1b9e4f 100644 --- a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr @@ -7,8 +7,8 @@ LL | /// See [zip] crate. note: the lint level is defined here --> $DIR/unused-extern-crate.rs:2:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr b/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr index 01e4282003766..d46df92649d17 100644 --- a/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr +++ b/src/test/rustdoc-ui/intra-doc/warning-crlf.stderr @@ -4,7 +4,7 @@ warning: unresolved link to `error` LL | /// [error] | ^^^^^ no item named `error` in scope | - = note: `#[warn(broken_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `error1` diff --git a/src/test/rustdoc-ui/intra-doc/warning.stderr b/src/test/rustdoc-ui/intra-doc/warning.stderr index 430d18165a005..135c432e05342 100644 --- a/src/test/rustdoc-ui/intra-doc/warning.stderr +++ b/src/test/rustdoc-ui/intra-doc/warning.stderr @@ -4,7 +4,7 @@ warning: unresolved link to `Foo::baz` LL | //! Test with [Foo::baz], [Bar::foo], ... | ^^^^^^^^ the struct `Foo` has no field or associated item named `baz` | - = note: `#[warn(broken_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default warning: unresolved link to `Bar::foo` --> $DIR/warning.rs:3:35 diff --git a/src/test/rustdoc-ui/invalid-html-tags.rs b/src/test/rustdoc-ui/invalid-html-tags.rs index 9c2fc4beb5eb1..cec44b6d2ca62 100644 --- a/src/test/rustdoc-ui/invalid-html-tags.rs +++ b/src/test/rustdoc-ui/invalid-html-tags.rs @@ -1,4 +1,4 @@ -#![deny(invalid_html_tags)] +#![deny(rustdoc::invalid_html_tags)] //!

💩

//~^ ERROR unclosed HTML tag `p` diff --git a/src/test/rustdoc-ui/invalid-html-tags.stderr b/src/test/rustdoc-ui/invalid-html-tags.stderr index aa9ace006bd1a..335e100c89d89 100644 --- a/src/test/rustdoc-ui/invalid-html-tags.stderr +++ b/src/test/rustdoc-ui/invalid-html-tags.stderr @@ -7,8 +7,8 @@ LL | //!

💩

note: the lint level is defined here --> $DIR/invalid-html-tags.rs:1:9 | -LL | #![deny(invalid_html_tags)] - | ^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::invalid_html_tags)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unclosed HTML tag `p` --> $DIR/invalid-html-tags.rs:3:9 diff --git a/src/test/rustdoc-ui/issue-58473-2.rs b/src/test/rustdoc-ui/issue-58473-2.rs index e5f3b4daf5729..000b6a329c1a7 100644 --- a/src/test/rustdoc-ui/issue-58473-2.rs +++ b/src/test/rustdoc-ui/issue-58473-2.rs @@ -1,6 +1,6 @@ // check-pass -#![deny(private_doc_tests)] +#![deny(rustdoc::private_doc_tests)] mod foo { /** diff --git a/src/test/rustdoc-ui/issue-74134.private.stderr b/src/test/rustdoc-ui/issue-74134.private.stderr index b802d7e12523a..457987e207496 100644 --- a/src/test/rustdoc-ui/issue-74134.private.stderr +++ b/src/test/rustdoc-ui/issue-74134.private.stderr @@ -4,7 +4,7 @@ warning: public documentation for `public_item` links to private item `PrivateTy LL | /// [`PrivateType`] | ^^^^^^^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link resolves only because you passed `--document-private-items`, but will break without warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/issue-74134.public.stderr b/src/test/rustdoc-ui/issue-74134.public.stderr index 40aa2ece1a373..07aebc3541fe3 100644 --- a/src/test/rustdoc-ui/issue-74134.public.stderr +++ b/src/test/rustdoc-ui/issue-74134.public.stderr @@ -4,7 +4,7 @@ warning: public documentation for `public_item` links to private item `PrivateTy LL | /// [`PrivateType`] | ^^^^^^^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link will resolve properly if you pass `--document-private-items` warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/lint-group.stderr b/src/test/rustdoc-ui/lint-group.stderr index 0c111a33b6564..6f8a20f7d53f0 100644 --- a/src/test/rustdoc-ui/lint-group.stderr +++ b/src/test/rustdoc-ui/lint-group.stderr @@ -9,7 +9,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(missing_doc_code_examples)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::missing_doc_code_examples)]` implied by `#[deny(rustdoc)]` error: documentation test in private item --> $DIR/lint-group.rs:19:1 @@ -26,7 +26,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(private_doc_tests)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::private_doc_tests)]` implied by `#[deny(rustdoc)]` error: missing code example in this documentation --> $DIR/lint-group.rs:26:1 @@ -45,7 +45,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(broken_intra_doc_links)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::broken_intra_doc_links)]` implied by `#[deny(rustdoc)]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: unclosed HTML tag `unknown` @@ -59,7 +59,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(invalid_html_tags)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(rustdoc::invalid_html_tags)]` implied by `#[deny(rustdoc)]` error: aborting due to 5 previous errors diff --git a/src/test/rustdoc-ui/lint-missing-doc-code-example.rs b/src/test/rustdoc-ui/lint-missing-doc-code-example.rs index ebe7a242211bf..8d727b0d0b550 100644 --- a/src/test/rustdoc-ui/lint-missing-doc-code-example.rs +++ b/src/test/rustdoc-ui/lint-missing-doc-code-example.rs @@ -1,5 +1,5 @@ #![deny(missing_docs)] -#![deny(missing_doc_code_examples)] +#![deny(rustdoc::missing_doc_code_examples)] //! crate level doc //! ``` @@ -19,7 +19,7 @@ fn test() { mod module1 { //~ ERROR } -#[allow(missing_doc_code_examples)] +#[allow(rustdoc::missing_doc_code_examples)] /// doc mod module2 { diff --git a/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr b/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr index e02ed4a056c12..370c577f85d8f 100644 --- a/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr +++ b/src/test/rustdoc-ui/lint-missing-doc-code-example.stderr @@ -8,8 +8,8 @@ LL | | } note: the lint level is defined here --> $DIR/lint-missing-doc-code-example.rs:2:9 | -LL | #![deny(missing_doc_code_examples)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::missing_doc_code_examples)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing code example in this documentation --> $DIR/lint-missing-doc-code-example.rs:37:3 diff --git a/src/test/rustdoc-ui/private-doc-test.rs b/src/test/rustdoc-ui/private-doc-test.rs index 379fa45f9fa3e..a1f9f8dca083e 100644 --- a/src/test/rustdoc-ui/private-doc-test.rs +++ b/src/test/rustdoc-ui/private-doc-test.rs @@ -1,6 +1,6 @@ // check-pass -#![deny(private_doc_tests)] +#![deny(rustdoc::private_doc_tests)] mod foo { /// private doc test diff --git a/src/test/rustdoc-ui/private-item-doc-test.rs b/src/test/rustdoc-ui/private-item-doc-test.rs index 2f1bddc7c75cc..1a3d6cc636d31 100644 --- a/src/test/rustdoc-ui/private-item-doc-test.rs +++ b/src/test/rustdoc-ui/private-item-doc-test.rs @@ -1,4 +1,4 @@ -#![deny(private_doc_tests)] +#![deny(rustdoc::private_doc_tests)] mod foo { /// private doc test diff --git a/src/test/rustdoc-ui/private-item-doc-test.stderr b/src/test/rustdoc-ui/private-item-doc-test.stderr index 70b6638b23711..5df6132987c9f 100644 --- a/src/test/rustdoc-ui/private-item-doc-test.stderr +++ b/src/test/rustdoc-ui/private-item-doc-test.stderr @@ -11,8 +11,8 @@ LL | | /// ``` note: the lint level is defined here --> $DIR/private-item-doc-test.rs:1:9 | -LL | #![deny(private_doc_tests)] - | ^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::private_doc_tests)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc-ui/pub-export-lint.rs b/src/test/rustdoc-ui/pub-export-lint.rs index 3fd3f77400978..f2e66b77bf3ea 100644 --- a/src/test/rustdoc-ui/pub-export-lint.rs +++ b/src/test/rustdoc-ui/pub-export-lint.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] /// [aloha] //~^ ERROR unresolved link to `aloha` diff --git a/src/test/rustdoc-ui/pub-export-lint.stderr b/src/test/rustdoc-ui/pub-export-lint.stderr index c345def794c08..c6be9c6a9f504 100644 --- a/src/test/rustdoc-ui/pub-export-lint.stderr +++ b/src/test/rustdoc-ui/pub-export-lint.stderr @@ -7,8 +7,8 @@ LL | /// [aloha] note: the lint level is defined here --> $DIR/pub-export-lint.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/reference-link-reports-error-once.rs b/src/test/rustdoc-ui/reference-link-reports-error-once.rs index 7957ee373c49e..71bd2c522ff86 100644 --- a/src/test/rustdoc-ui/reference-link-reports-error-once.rs +++ b/src/test/rustdoc-ui/reference-link-reports-error-once.rs @@ -1,4 +1,4 @@ -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] /// Links to [a] [link][a] /// And also a [third link][a] diff --git a/src/test/rustdoc-ui/reference-link-reports-error-once.stderr b/src/test/rustdoc-ui/reference-link-reports-error-once.stderr index 218eb334a6fc3..b46a51e93fb8b 100644 --- a/src/test/rustdoc-ui/reference-link-reports-error-once.stderr +++ b/src/test/rustdoc-ui/reference-link-reports-error-once.stderr @@ -7,8 +7,8 @@ LL | /// [a]: ref note: the lint level is defined here --> $DIR/reference-link-reports-error-once.rs:1:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: unresolved link to `ref2` diff --git a/src/test/rustdoc-ui/reference-links.rs b/src/test/rustdoc-ui/reference-links.rs index 6e00b9f0fa1a9..e81e034465d7f 100644 --- a/src/test/rustdoc-ui/reference-links.rs +++ b/src/test/rustdoc-ui/reference-links.rs @@ -1,5 +1,5 @@ // Test that errors point to the reference, not to the title text. -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] //! Links to [a] [link][a] //! //! [a]: std::process::Comman diff --git a/src/test/rustdoc-ui/reference-links.stderr b/src/test/rustdoc-ui/reference-links.stderr index 3df89df21b4c6..c98a2fd7ce690 100644 --- a/src/test/rustdoc-ui/reference-links.stderr +++ b/src/test/rustdoc-ui/reference-links.stderr @@ -7,8 +7,8 @@ LL | //! [a]: std::process::Comman note: the lint level is defined here --> $DIR/reference-links.rs:2:9 | -LL | #![deny(broken_intra_doc_links)] - | ^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.rs b/src/test/rustdoc-ui/unknown-renamed-lints.rs index 7faa82ea429c2..e2238a4004c1b 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.rs +++ b/src/test/rustdoc-ui/unknown-renamed-lints.rs @@ -4,5 +4,16 @@ //~^ NOTE lint level is defined #![deny(x)] //~^ ERROR unknown lint +#![deny(rustdoc::x)] +//~^ ERROR unknown lint: `rustdoc::x` #![deny(intra_doc_link_resolution_failure)] -//~^ ERROR lint `intra_doc_link_resolution_failure` has been renamed +//~^ ERROR has been renamed + +// This would ideally say 'renamed to rustdoc::non_autolinks', but this is close enough. +#![deny(non_autolinks)] +//~^ ERROR has been removed: use `rustdoc::non_autolinks` instead [renamed_and_removed_lints] + +// This doesn't give you the right code directly, but at least points you on the +// right path. +#![deny(rustdoc::intra_doc_link_resolution_failure)] +//~^ ERROR unknown lint diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.stderr b/src/test/rustdoc-ui/unknown-renamed-lints.stderr index f0917f194bb08..1a45f68ae810f 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.stderr +++ b/src/test/rustdoc-ui/unknown-renamed-lints.stderr @@ -10,11 +10,17 @@ note: the lint level is defined here LL | #![deny(unknown_lints)] | ^^^^^^^^^^^^^ -error: lint `intra_doc_link_resolution_failure` has been renamed to `broken_intra_doc_links` +error: unknown lint: `rustdoc::x` --> $DIR/unknown-renamed-lints.rs:7:9 | +LL | #![deny(rustdoc::x)] + | ^^^^^^^^^^ + +error: lint `intra_doc_link_resolution_failure` has been renamed to `rustdoc::broken_intra_doc_links` + --> $DIR/unknown-renamed-lints.rs:9:9 + | LL | #![deny(intra_doc_link_resolution_failure)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `broken_intra_doc_links` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::broken_intra_doc_links` | note: the lint level is defined here --> $DIR/unknown-renamed-lints.rs:3:9 @@ -22,7 +28,19 @@ note: the lint level is defined here LL | #![deny(renamed_and_removed_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ +error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead + --> $DIR/unknown-renamed-lints.rs:13:9 + | +LL | #![deny(non_autolinks)] + | ^^^^^^^^^^^^^ + +error: unknown lint: `rustdoc::intra_doc_link_resolution_failure` + --> $DIR/unknown-renamed-lints.rs:18:9 + | +LL | #![deny(rustdoc::intra_doc_link_resolution_failure)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: Compilation failed, aborting rustdoc -error: aborting due to 3 previous errors +error: aborting due to 6 previous errors diff --git a/src/test/rustdoc-ui/url-improvements.rs b/src/test/rustdoc-ui/url-improvements.rs index 8531583d38a65..d0b43de2f0e0e 100644 --- a/src/test/rustdoc-ui/url-improvements.rs +++ b/src/test/rustdoc-ui/url-improvements.rs @@ -1,4 +1,4 @@ -#![deny(non_autolinks)] +#![deny(rustdoc::non_autolinks)] /// [http://aa.com](http://aa.com) //~^ ERROR unneeded long form for URL @@ -59,7 +59,7 @@ pub fn c() {} /// [should_not.lint](should_not.lint) pub fn everything_is_fine_here() {} -#[allow(non_autolinks)] +#[allow(rustdoc::non_autolinks)] pub mod foo { /// https://somewhere.com/a?hello=12&bye=11#xyz pub fn bar() {} diff --git a/src/test/rustdoc-ui/url-improvements.stderr b/src/test/rustdoc-ui/url-improvements.stderr index 70ad4b06a515d..f377973656a83 100644 --- a/src/test/rustdoc-ui/url-improvements.stderr +++ b/src/test/rustdoc-ui/url-improvements.stderr @@ -7,8 +7,8 @@ LL | /// [http://aa.com](http://aa.com) note: the lint level is defined here --> $DIR/url-improvements.rs:1:9 | -LL | #![deny(non_autolinks)] - | ^^^^^^^^^^^^^ +LL | #![deny(rustdoc::non_autolinks)] + | ^^^^^^^^^^^^^^^^^^^^^^ error: unneeded long form for URL --> $DIR/url-improvements.rs:5:5 diff --git a/src/test/rustdoc/intra-doc/non-path-primitives.rs b/src/test/rustdoc/intra-doc/non-path-primitives.rs index 48c667ef2d18e..ffa02b0c635b3 100644 --- a/src/test/rustdoc/intra-doc/non-path-primitives.rs +++ b/src/test/rustdoc/intra-doc/non-path-primitives.rs @@ -1,7 +1,7 @@ // ignore-tidy-linelength #![crate_name = "foo"] #![feature(intra_doc_pointers)] -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] // @has foo/index.html '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.rotate_left"]' 'slice::rotate_left' //! [slice::rotate_left] From 37e4cfe5125e1d8d29fd1a66c7f80109c25618fb Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Dec 2020 14:11:15 -0500 Subject: [PATCH 03/19] Move lint machinery into a separate file --- src/librustdoc/core.rs | 175 +----------------- src/librustdoc/doctest.rs | 9 +- src/librustdoc/html/markdown.rs | 2 +- src/librustdoc/lib.rs | 1 + src/librustdoc/lint.rs | 164 ++++++++++++++++ .../passes/collect_intra_doc_links.rs | 2 +- src/librustdoc/passes/doc_test_lints.rs | 6 +- src/librustdoc/passes/html_tags.rs | 2 +- src/librustdoc/passes/non_autolinks.rs | 2 +- 9 files changed, 183 insertions(+), 180 deletions(-) create mode 100644 src/librustdoc/lint.rs diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 0dc762ea27665..5313f8553a894 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -12,8 +12,6 @@ use rustc_hir::{ Path, }; use rustc_interface::{interface, Queries}; -use rustc_lint::LintStore; -use rustc_lint_defs::{declare_tool_lint, Lint, LintId}; use rustc_middle::hir::map::Map; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{ParamEnv, Ty, TyCtxt}; @@ -28,7 +26,6 @@ use rustc_span::DUMMY_SP; use std::cell::RefCell; use std::collections::hash_map::Entry; -use std::lazy::SyncLazy as Lazy; use std::mem; use std::rc::Rc; @@ -232,164 +229,6 @@ crate fn new_handler( ) } -/// This function is used to setup the lint initialization. By default, in rustdoc, everything -/// is "allowed". Depending if we run in test mode or not, we want some of them to be at their -/// default level. For example, the "INVALID_CODEBLOCK_ATTRIBUTES" lint is activated in both -/// modes. -/// -/// A little detail easy to forget is that there is a way to set the lint level for all lints -/// through the "WARNINGS" lint. To prevent this to happen, we set it back to its "normal" level -/// inside this function. -/// -/// It returns a tuple containing: -/// * Vector of tuples of lints' name and their associated "max" level -/// * HashMap of lint id with their associated "max" level -pub(crate) fn init_lints( - mut allowed_lints: Vec, - lint_opts: Vec<(String, lint::Level)>, - filter_call: F, -) -> (Vec<(String, lint::Level)>, FxHashMap) -where - F: Fn(&lint::Lint) -> Option<(String, lint::Level)>, -{ - let warnings_lint_name = lint::builtin::WARNINGS.name; - - allowed_lints.push(warnings_lint_name.to_owned()); - allowed_lints.extend(lint_opts.iter().map(|(lint, _)| lint).cloned()); - - let lints = || { - lint::builtin::HardwiredLints::get_lints() - .into_iter() - .chain(rustc_lint::SoftLints::get_lints().into_iter()) - }; - - let lint_opts = lints() - .filter_map(|lint| { - // Permit feature-gated lints to avoid feature errors when trying to - // allow all lints. - if lint.feature_gate.is_some() || allowed_lints.iter().any(|l| lint.name == l) { - None - } else { - filter_call(lint) - } - }) - .chain(lint_opts.into_iter()) - .collect::>(); - - let lint_caps = lints() - .filter_map(|lint| { - // We don't want to allow *all* lints so let's ignore - // those ones. - if allowed_lints.iter().any(|l| lint.name == l) { - None - } else { - Some((lint::LintId::of(lint), lint::Allow)) - } - }) - .collect(); - (lint_opts, lint_caps) -} - -declare_tool_lint! { - /// The `broken_intra_doc_links` lint detects failures in resolving - /// intra-doc link targets. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links - pub rustdoc::BROKEN_INTRA_DOC_LINKS, - Warn, - "failures in resolving intra-doc link targets" -} - -declare_tool_lint! { - /// This is a subset of `broken_intra_doc_links` that warns when linking from - /// a public item to a private one. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links - pub rustdoc::PRIVATE_INTRA_DOC_LINKS, - Warn, - "linking from a public item to a private one" -} - -declare_tool_lint! { - /// The `invalid_codeblock_attributes` lint detects code block attributes - /// in documentation examples that have potentially mis-typed values. This - /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes - pub rustdoc::INVALID_CODEBLOCK_ATTRIBUTES, - Warn, - "codeblock attribute looks a lot like a known one" -} - -declare_tool_lint! { - /// The `missing_doc_code_examples` lint detects publicly-exported items - /// without code samples in their documentation. This is a `rustdoc` only - /// lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples - pub rustdoc::MISSING_DOC_CODE_EXAMPLES, - Allow, - "detects publicly-exported items without code samples in their documentation" -} - -declare_tool_lint! { - /// The `private_doc_tests` lint detects code samples in docs of private - /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see - /// the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests - pub rustdoc::PRIVATE_DOC_TESTS, - Allow, - "detects code samples in docs of private items not documented by rustdoc" -} - -declare_tool_lint! { - /// The `invalid_html_tags` lint detects invalid HTML tags. This is a - /// `rustdoc` only lint, see the documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags - pub rustdoc::INVALID_HTML_TAGS, - Allow, - "detects invalid HTML tags in doc comments" -} - -declare_tool_lint! { - /// The `non_autolinks` lint detects when a URL could be written using - /// only angle brackets. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks - pub rustdoc::NON_AUTOLINKS, - Warn, - "detects URLs that could be written using only angle brackets" -} - -static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { - vec![ - BROKEN_INTRA_DOC_LINKS, - PRIVATE_INTRA_DOC_LINKS, - MISSING_DOC_CODE_EXAMPLES, - PRIVATE_DOC_TESTS, - INVALID_CODEBLOCK_ATTRIBUTES, - INVALID_HTML_TAGS, - NON_AUTOLINKS, - ] -}); - -crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { - lint_store.register_lints(&**RUSTDOC_LINTS); - lint_store.register_group( - true, - "rustdoc", - None, - RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), - ); - lint_store - .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); -} - /// Parse, resolve, and typecheck the given crate. crate fn create_config( RustdocOptions { @@ -418,8 +257,8 @@ crate fn create_config( let cpath = Some(input.clone()); let input = Input::File(input); - // In addition to those specific lints, we also need to allow those given through - // command line, otherwise they'll get ignored and we don't want that. + // By default, rustdoc ignores all lints. + // Specifically unblock lints relevant to documentation or the lint machinery itself. let mut lints_to_show = vec![ // it's unclear whether these should be part of rustdoc directly rustc_lint::builtin::MISSING_DOCS.name.to_string(), @@ -428,12 +267,12 @@ crate fn create_config( rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(), rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(), ]; - lints_to_show.extend(RUSTDOC_LINTS.iter().map(|lint| lint.name.to_string())); + lints_to_show.extend(crate::lint::RUSTDOC_LINTS.iter().map(|lint| lint.name.to_string())); - let (lint_opts, lint_caps) = init_lints(lints_to_show, lint_opts, |lint| { + let (lint_opts, lint_caps) = crate::lint::init_lints(lints_to_show, lint_opts, |lint| { // FIXME: why is this necessary? - if lint.name == BROKEN_INTRA_DOC_LINKS.name - || lint.name == INVALID_CODEBLOCK_ATTRIBUTES.name + if lint.name == crate::lint::BROKEN_INTRA_DOC_LINKS.name + || lint.name == crate::lint::INVALID_CODEBLOCK_ATTRIBUTES.name { None } else { @@ -474,7 +313,7 @@ crate fn create_config( diagnostic_output: DiagnosticOutput::Default, stderr: None, lint_caps, - register_lints: Some(box register_lints), + register_lints: Some(box crate::lint::register_lints), override_queries: Some(|_sess, providers, _external_providers| { // Most lints will require typechecking, so just don't run them. providers.lint_mod = |_, _| {}; diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index eac0ad688d4a2..27ce064669d2c 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -26,8 +26,8 @@ use std::str; use crate::clean::Attributes; use crate::config::Options; -use crate::core::init_lints; use crate::html::markdown::{self, ErrorCodes, Ignore, LangString}; +use crate::lint::init_lints; use crate::passes::span_of_attrs; #[derive(Clone, Default)] @@ -44,10 +44,9 @@ crate struct TestOptions { crate fn run(options: Options) -> Result<(), ErrorReported> { let input = config::Input::File(options.input.clone()); - let invalid_codeblock_attributes_name = crate::core::INVALID_CODEBLOCK_ATTRIBUTES.name; + let invalid_codeblock_attributes_name = crate::lint::INVALID_CODEBLOCK_ATTRIBUTES.name; - // In addition to those specific lints, we also need to allow those given through - // command line, otherwise they'll get ignored and we don't want that. + // See core::create_config for what's going on here. let allowed_lints = vec![ invalid_codeblock_attributes_name.to_owned(), lint::builtin::UNKNOWN_LINTS.name.to_owned(), @@ -96,7 +95,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> { diagnostic_output: DiagnosticOutput::Default, stderr: None, lint_caps, - register_lints: Some(box crate::core::register_lints), + register_lints: Some(box crate::lint::register_lints), override_queries: None, make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 8c8840e38e6a6..f8ca259fb9ab5 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -720,7 +720,7 @@ impl<'tcx> ExtraInfo<'tcx> { (None, None) => return, }; self.tcx.struct_span_lint_hir( - crate::core::INVALID_CODEBLOCK_ATTRIBUTES, + crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, hir_id, self.sp, |lint| { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 6388733c8b219..c152f0fb7f6a0 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -86,6 +86,7 @@ mod formats; // used by the error-index generator, so it needs to be public pub mod html; mod json; +crate mod lint; mod markdown; mod passes; mod theme; diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs new file mode 100644 index 0000000000000..778983868ea01 --- /dev/null +++ b/src/librustdoc/lint.rs @@ -0,0 +1,164 @@ +use rustc_data_structures::fx::FxHashMap; +use rustc_lint::LintStore; +use rustc_lint_defs::{declare_tool_lint, Lint, LintId}; +use rustc_session::{lint, Session}; + +use std::lazy::SyncLazy as Lazy; + +/// This function is used to setup the lint initialization. By default, in rustdoc, everything +/// is "allowed". Depending if we run in test mode or not, we want some of them to be at their +/// default level. For example, the "INVALID_CODEBLOCK_ATTRIBUTES" lint is activated in both +/// modes. +/// +/// A little detail easy to forget is that there is a way to set the lint level for all lints +/// through the "WARNINGS" lint. To prevent this to happen, we set it back to its "normal" level +/// inside this function. +/// +/// It returns a tuple containing: +/// * Vector of tuples of lints' name and their associated "max" level +/// * HashMap of lint id with their associated "max" level +pub(crate) fn init_lints( + mut allowed_lints: Vec, + lint_opts: Vec<(String, lint::Level)>, + filter_call: F, +) -> (Vec<(String, lint::Level)>, FxHashMap) +where + F: Fn(&lint::Lint) -> Option<(String, lint::Level)>, +{ + let warnings_lint_name = lint::builtin::WARNINGS.name; + + allowed_lints.push(warnings_lint_name.to_owned()); + allowed_lints.extend(lint_opts.iter().map(|(lint, _)| lint).cloned()); + + let lints = || { + lint::builtin::HardwiredLints::get_lints() + .into_iter() + .chain(rustc_lint::SoftLints::get_lints().into_iter()) + }; + + let lint_opts = lints() + .filter_map(|lint| { + // Permit feature-gated lints to avoid feature errors when trying to + // allow all lints. + if lint.feature_gate.is_some() || allowed_lints.iter().any(|l| lint.name == l) { + None + } else { + filter_call(lint) + } + }) + .chain(lint_opts.into_iter()) + .collect::>(); + + let lint_caps = lints() + .filter_map(|lint| { + // We don't want to allow *all* lints so let's ignore + // those ones. + if allowed_lints.iter().any(|l| lint.name == l) { + None + } else { + Some((lint::LintId::of(lint), lint::Allow)) + } + }) + .collect(); + (lint_opts, lint_caps) +} + +declare_tool_lint! { + /// The `broken_intra_doc_links` lint detects failures in resolving + /// intra-doc link targets. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links + pub rustdoc::BROKEN_INTRA_DOC_LINKS, + Warn, + "failures in resolving intra-doc link targets" +} + +declare_tool_lint! { + /// This is a subset of `broken_intra_doc_links` that warns when linking from + /// a public item to a private one. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links + pub rustdoc::PRIVATE_INTRA_DOC_LINKS, + Warn, + "linking from a public item to a private one" +} + +declare_tool_lint! { + /// The `invalid_codeblock_attributes` lint detects code block attributes + /// in documentation examples that have potentially mis-typed values. This + /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes + pub rustdoc::INVALID_CODEBLOCK_ATTRIBUTES, + Warn, + "codeblock attribute looks a lot like a known one" +} + +declare_tool_lint! { + /// The `missing_doc_code_examples` lint detects publicly-exported items + /// without code samples in their documentation. This is a `rustdoc` only + /// lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples + pub rustdoc::MISSING_DOC_CODE_EXAMPLES, + Allow, + "detects publicly-exported items without code samples in their documentation" +} + +declare_tool_lint! { + /// The `private_doc_tests` lint detects code samples in docs of private + /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see + /// the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests + pub rustdoc::PRIVATE_DOC_TESTS, + Allow, + "detects code samples in docs of private items not documented by rustdoc" +} + +declare_tool_lint! { + /// The `invalid_html_tags` lint detects invalid HTML tags. This is a + /// `rustdoc` only lint, see the documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags + pub rustdoc::INVALID_HTML_TAGS, + Allow, + "detects invalid HTML tags in doc comments" +} + +declare_tool_lint! { + /// The `non_autolinks` lint detects when a URL could be written using + /// only angle brackets. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks + pub rustdoc::NON_AUTOLINKS, + Warn, + "detects URLs that could be written using only angle brackets" +} + +crate static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { + vec![ + BROKEN_INTRA_DOC_LINKS, + PRIVATE_INTRA_DOC_LINKS, + MISSING_DOC_CODE_EXAMPLES, + PRIVATE_DOC_TESTS, + INVALID_CODEBLOCK_ATTRIBUTES, + INVALID_HTML_TAGS, + NON_AUTOLINKS, + ] +}); + +crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { + lint_store.register_lints(&**RUSTDOC_LINTS); + lint_store.register_group( + true, + "rustdoc", + None, + RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), + ); + lint_store + .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); +} diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 6619adb5b7650..38efecb393b79 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -32,9 +32,9 @@ use std::ops::Range; use crate::clean::{self, utils::find_nearest_parent_module, Crate, Item, ItemLink, PrimitiveType}; use crate::core::DocContext; -use crate::core::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}; use crate::fold::DocFolder; use crate::html::markdown::{markdown_links, MarkdownLink}; +use crate::lint::{BROKEN_INTRA_DOC_LINKS, PRIVATE_INTRA_DOC_LINKS}; use crate::passes::Pass; use super::span_of_attrs; diff --git a/src/librustdoc/passes/doc_test_lints.rs b/src/librustdoc/passes/doc_test_lints.rs index 85547e557df5b..c6b956c600058 100644 --- a/src/librustdoc/passes/doc_test_lints.rs +++ b/src/librustdoc/passes/doc_test_lints.rs @@ -68,7 +68,7 @@ crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> boo return false; } let hir_id = cx.tcx.hir().local_def_id_to_hir_id(item.def_id.expect_local()); - let (level, source) = cx.tcx.lint_level_at_node(crate::core::MISSING_DOC_CODE_EXAMPLES, hir_id); + let (level, source) = cx.tcx.lint_level_at_node(crate::lint::MISSING_DOC_CODE_EXAMPLES, hir_id); level != lint::Level::Allow || matches!(source, LintLevelSource::Default) } @@ -90,7 +90,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { debug!("reporting error for {:?} (hir_id={:?})", item, hir_id); let sp = span_of_attrs(&item.attrs).unwrap_or(item.source.span()); cx.tcx.struct_span_lint_hir( - crate::core::MISSING_DOC_CODE_EXAMPLES, + crate::lint::MISSING_DOC_CODE_EXAMPLES, hir_id, sp, |lint| lint.build("missing code example in this documentation").emit(), @@ -98,7 +98,7 @@ crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) { } } else if tests.found_tests > 0 && !cx.renderinfo.access_levels.is_public(item.def_id) { cx.tcx.struct_span_lint_hir( - crate::core::PRIVATE_DOC_TESTS, + crate::lint::PRIVATE_DOC_TESTS, hir_id, span_of_attrs(&item.attrs).unwrap_or(item.source.span()), |lint| lint.build("documentation test in private item").emit(), diff --git a/src/librustdoc/passes/html_tags.rs b/src/librustdoc/passes/html_tags.rs index b97872c633392..27e669aa44fc0 100644 --- a/src/librustdoc/passes/html_tags.rs +++ b/src/librustdoc/passes/html_tags.rs @@ -182,7 +182,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> { Some(sp) => sp, None => span_of_attrs(&item.attrs).unwrap_or(item.source.span()), }; - cx.tcx.struct_span_lint_hir(crate::core::INVALID_HTML_TAGS, hir_id, sp, |lint| { + cx.tcx.struct_span_lint_hir(crate::lint::INVALID_HTML_TAGS, hir_id, sp, |lint| { lint.build(msg).emit() }); }; diff --git a/src/librustdoc/passes/non_autolinks.rs b/src/librustdoc/passes/non_autolinks.rs index fe21887fc050b..09a1959fa113c 100644 --- a/src/librustdoc/passes/non_autolinks.rs +++ b/src/librustdoc/passes/non_autolinks.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> DocFolder for NonAutolinksLinter<'a, 'tcx> { let sp = super::source_span_for_markdown_range(cx, &dox, &range, &item.attrs) .or_else(|| span_of_attrs(&item.attrs)) .unwrap_or(item.source.span()); - cx.tcx.struct_span_lint_hir(crate::core::NON_AUTOLINKS, hir_id, sp, |lint| { + cx.tcx.struct_span_lint_hir(crate::lint::NON_AUTOLINKS, hir_id, sp, |lint| { lint.build(msg) .span_suggestion( sp, From 719535576738ee97a866ce7fbf76a42d6399627b Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 30 Dec 2020 14:17:18 -0500 Subject: [PATCH 04/19] Add `declare_rustdoc_lint!` macro --- src/librustdoc/lint.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 778983868ea01..013b7ead5c7c9 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -63,78 +63,86 @@ where (lint_opts, lint_caps) } -declare_tool_lint! { +macro_rules! declare_rustdoc_lint { + ($(#[$attr:meta])* $name: ident, $level: ident, $descr: literal $(,)?) => { + declare_tool_lint! { + $(#[$attr])* pub rustdoc::$name, $level, $descr + } + } +} + +declare_rustdoc_lint! { /// The `broken_intra_doc_links` lint detects failures in resolving /// intra-doc link targets. This is a `rustdoc` only lint, see the /// documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#broken_intra_doc_links - pub rustdoc::BROKEN_INTRA_DOC_LINKS, + BROKEN_INTRA_DOC_LINKS, Warn, "failures in resolving intra-doc link targets" } -declare_tool_lint! { +declare_rustdoc_lint! { /// This is a subset of `broken_intra_doc_links` that warns when linking from /// a public item to a private one. This is a `rustdoc` only lint, see the /// documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#private_intra_doc_links - pub rustdoc::PRIVATE_INTRA_DOC_LINKS, + PRIVATE_INTRA_DOC_LINKS, Warn, "linking from a public item to a private one" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `invalid_codeblock_attributes` lint detects code block attributes /// in documentation examples that have potentially mis-typed values. This /// is a `rustdoc` only lint, see the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_codeblock_attributes - pub rustdoc::INVALID_CODEBLOCK_ATTRIBUTES, + INVALID_CODEBLOCK_ATTRIBUTES, Warn, "codeblock attribute looks a lot like a known one" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `missing_doc_code_examples` lint detects publicly-exported items /// without code samples in their documentation. This is a `rustdoc` only /// lint, see the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#missing_doc_code_examples - pub rustdoc::MISSING_DOC_CODE_EXAMPLES, + MISSING_DOC_CODE_EXAMPLES, Allow, "detects publicly-exported items without code samples in their documentation" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `private_doc_tests` lint detects code samples in docs of private /// items not documented by `rustdoc`. This is a `rustdoc` only lint, see /// the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#private_doc_tests - pub rustdoc::PRIVATE_DOC_TESTS, + PRIVATE_DOC_TESTS, Allow, "detects code samples in docs of private items not documented by rustdoc" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `invalid_html_tags` lint detects invalid HTML tags. This is a /// `rustdoc` only lint, see the documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#invalid_html_tags - pub rustdoc::INVALID_HTML_TAGS, + INVALID_HTML_TAGS, Allow, "detects invalid HTML tags in doc comments" } -declare_tool_lint! { +declare_rustdoc_lint! { /// The `non_autolinks` lint detects when a URL could be written using /// only angle brackets. This is a `rustdoc` only lint, see the /// documentation in the [rustdoc book]. /// /// [rustdoc book]: ../../../rustdoc/lints.html#non_autolinks - pub rustdoc::NON_AUTOLINKS, + NON_AUTOLINKS, Warn, "detects URLs that could be written using only angle brackets" } From e8ddfda8138d9c282eee16cfae892ed232d8b422 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 17 Jan 2021 18:52:19 -0500 Subject: [PATCH 05/19] Improve error messages - Use `register_renamed` when rustdoc is running so the lint will still be active and use a structured suggestion - Test the behavior for rustc, not just for rustdoc (because it differs) --- compiler/rustc_lint/src/lib.rs | 4 ++++ src/librustdoc/lint.rs | 4 ++++ src/test/rustdoc-ui/unknown-renamed-lints.rs | 8 +++----- .../rustdoc-ui/unknown-renamed-lints.stderr | 8 ++++---- src/test/ui/lint/rustdoc-renamed.rs | 14 +++++++++++++ src/test/ui/lint/rustdoc-renamed.stderr | 20 +++++++++++++++++++ 6 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 src/test/ui/lint/rustdoc-renamed.rs create mode 100644 src/test/ui/lint/rustdoc-renamed.stderr diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 67c0e999f5518..86ad73d482f24 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -339,6 +339,10 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { // FIXME: maybe we could get `register_renamed` to work for tool lints? store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint)); } + store.register_removed( + "intra_doc_link_resolution_failure", + "use `rustdoc::broken_intra_doc_links` instead", + ); store.register_removed("unknown_features", "replaced by an error"); store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate"); diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 013b7ead5c7c9..7d95561d039f9 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -167,6 +167,10 @@ crate fn register_lints(_sess: &Session, lint_store: &mut LintStore) { None, RUSTDOC_LINTS.iter().map(|&lint| LintId::of(lint)).collect(), ); + for lint in &*RUSTDOC_LINTS { + let name = lint.name_lower(); + lint_store.register_renamed(&name.replace("rustdoc::", ""), &name); + } lint_store .register_renamed("intra_doc_link_resolution_failure", "rustdoc::broken_intra_doc_links"); } diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.rs b/src/test/rustdoc-ui/unknown-renamed-lints.rs index e2238a4004c1b..d2c78bc477410 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.rs +++ b/src/test/rustdoc-ui/unknown-renamed-lints.rs @@ -7,13 +7,11 @@ #![deny(rustdoc::x)] //~^ ERROR unknown lint: `rustdoc::x` #![deny(intra_doc_link_resolution_failure)] -//~^ ERROR has been renamed +//~^ ERROR renamed to `rustdoc::broken_intra_doc_links` -// This would ideally say 'renamed to rustdoc::non_autolinks', but this is close enough. #![deny(non_autolinks)] -//~^ ERROR has been removed: use `rustdoc::non_autolinks` instead [renamed_and_removed_lints] +//~^ ERROR renamed to `rustdoc::non_autolinks` -// This doesn't give you the right code directly, but at least points you on the -// right path. +// Explicitly don't try to handle this case, it was never valid #![deny(rustdoc::intra_doc_link_resolution_failure)] //~^ ERROR unknown lint diff --git a/src/test/rustdoc-ui/unknown-renamed-lints.stderr b/src/test/rustdoc-ui/unknown-renamed-lints.stderr index 1a45f68ae810f..0f31673fb47f2 100644 --- a/src/test/rustdoc-ui/unknown-renamed-lints.stderr +++ b/src/test/rustdoc-ui/unknown-renamed-lints.stderr @@ -28,14 +28,14 @@ note: the lint level is defined here LL | #![deny(renamed_and_removed_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead - --> $DIR/unknown-renamed-lints.rs:13:9 +error: lint `non_autolinks` has been renamed to `rustdoc::non_autolinks` + --> $DIR/unknown-renamed-lints.rs:12:9 | LL | #![deny(non_autolinks)] - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ help: use the new name: `rustdoc::non_autolinks` error: unknown lint: `rustdoc::intra_doc_link_resolution_failure` - --> $DIR/unknown-renamed-lints.rs:18:9 + --> $DIR/unknown-renamed-lints.rs:16:9 | LL | #![deny(rustdoc::intra_doc_link_resolution_failure)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/lint/rustdoc-renamed.rs b/src/test/ui/lint/rustdoc-renamed.rs new file mode 100644 index 0000000000000..71e88bd7f54a5 --- /dev/null +++ b/src/test/ui/lint/rustdoc-renamed.rs @@ -0,0 +1,14 @@ +#![crate_type = "lib"] + +#![deny(unknown_lints)] +#![deny(renamed_and_removed_lints)] +//~^ NOTE lint level is defined + +// both allowed, since the compiler doesn't yet know what rustdoc lints are valid +#![deny(rustdoc::x)] +#![deny(rustdoc::intra_doc_link_resolution_failure)] + +#![deny(intra_doc_link_resolution_failure)] +//~^ ERROR removed: use `rustdoc::broken_intra_doc_links` +#![deny(non_autolinks)] +//~^ ERROR removed: use `rustdoc::non_autolinks` diff --git a/src/test/ui/lint/rustdoc-renamed.stderr b/src/test/ui/lint/rustdoc-renamed.stderr new file mode 100644 index 0000000000000..a7fe3e29d5be0 --- /dev/null +++ b/src/test/ui/lint/rustdoc-renamed.stderr @@ -0,0 +1,20 @@ +error: lint `intra_doc_link_resolution_failure` has been removed: use `rustdoc::broken_intra_doc_links` instead + --> $DIR/rustdoc-renamed.rs:11:9 + | +LL | #![deny(intra_doc_link_resolution_failure)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/rustdoc-renamed.rs:4:9 + | +LL | #![deny(renamed_and_removed_lints)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: lint `non_autolinks` has been removed: use `rustdoc::non_autolinks` instead + --> $DIR/rustdoc-renamed.rs:13:9 + | +LL | #![deny(non_autolinks)] + | ^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + From 0517ea7cdc0b916b2ab2e7909cbfac355c6b1e1d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 18 Jan 2021 01:14:01 -0500 Subject: [PATCH 06/19] Address review comments - Move MISSING_CRATE_LEVEL_DOCS to rustdoc directly - Update documentation This also takes the opportunity to make the `no-crate-level-doc-lint` test more specific. --- compiler/rustc_lint/src/lib.rs | 1 + compiler/rustc_lint_defs/src/builtin.rs | 12 ------- src/doc/rustdoc/src/lints.md | 35 +++++++++++-------- src/librustdoc/core.rs | 5 ++- src/librustdoc/lint.rs | 12 +++++++ src/test/rustdoc-ui/check.stderr | 13 ++++++- .../rustdoc-ui/no-crate-level-doc-lint.rs | 4 ++- .../rustdoc-ui/no-crate-level-doc-lint.stderr | 6 ++-- 8 files changed, 54 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index 86ad73d482f24..a15a972cce721 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -329,6 +329,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { const RUSTDOC_LINTS: &[&str] = &[ "broken_intra_doc_links", "private_intra_doc_links", + "missing_crate_level_docs", "missing_doc_code_examples", "private_doc_tests", "invalid_codeblock_attributes", diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 53bb0fb28a65b..12d849e3b9466 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1875,17 +1875,6 @@ declare_lint! { "detects labels that are never used" } -declare_lint! { - /// The `missing_crate_level_docs` lint detects if documentation is - /// missing at the crate root. This is a `rustdoc` only lint, see the - /// documentation in the [rustdoc book]. - /// - /// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs - pub MISSING_CRATE_LEVEL_DOCS, - Allow, - "detects crates with no crate-level documentation" -} - declare_lint! { /// The `where_clauses_object_safety` lint detects for [object safety] of /// [where clauses]. @@ -2944,7 +2933,6 @@ declare_lint_pass! { ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, UNSTABLE_NAME_COLLISIONS, IRREFUTABLE_LET_PATTERNS, - MISSING_CRATE_LEVEL_DOCS, WHERE_CLAUSES_OBJECT_SAFETY, PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, MACRO_USE_EXTERN_CRATE, diff --git a/src/doc/rustdoc/src/lints.md b/src/doc/rustdoc/src/lints.md index cce3623dc8f49..174db711bcee7 100644 --- a/src/doc/rustdoc/src/lints.md +++ b/src/doc/rustdoc/src/lints.md @@ -4,12 +4,13 @@ can use them like any other lints by doing this: ```rust -#![allow(missing_docs)] // allows the lint, no diagnostics will be reported -#![warn(missing_docs)] // warn if there are missing docs -#![deny(missing_docs)] // error if there are missing docs -# //! Crate docs. +#![allow(rustdoc::broken_intra_doc_links)] // allows the lint, no diagnostics will be reported +#![warn(rustdoc::broken_intra_doc_links)] // warn if there are broken intra-doc links +#![deny(rustdoc::broken_intra_doc_links)] // error if there are broken intra-doc links ``` +Note that, except for `missing_docs`, these lints are only available when running `rustdoc`, not `rustc`. + Here is the list of the lints provided by `rustdoc`: ## broken_intra_doc_links @@ -51,7 +52,7 @@ warning: `Foo` is both an enum and a function 1 | /// [`Foo`] | ^^^^^ ambiguous link | - = note: `#[warn(broken_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default help: to link to the enum, prefix with the item type | 1 | /// [`enum@Foo`] @@ -83,7 +84,7 @@ warning: public documentation for `public` links to private item `private` 1 | /// [private] | ^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link will resolve properly if you pass `--document-private-items` ``` @@ -97,7 +98,7 @@ warning: public documentation for `public` links to private item `private` 1 | /// [private] | ^^^^^^^ this item is private | - = note: `#[warn(private_intra_doc_links)]` on by default + = note: `#[warn(rustdoc::private_intra_doc_links)]` on by default = note: this link resolves only because you passed `--document-private-items`, but will break without ``` @@ -125,13 +126,15 @@ warning: missing documentation for a function | ^^^^^^^^^^^^^^^^^^^^^ ``` +Note that unlike other rustdoc lints, this lint is also available from `rustc` directly. + ## missing_crate_level_docs This lint is **allowed by default**. It detects if there is no documentation at the crate root. For example: ```rust -#![warn(missing_crate_level_docs)] +#![warn(rustdoc::missing_crate_level_docs)] ``` This will generate the following warning: @@ -155,7 +158,7 @@ This lint is **allowed by default** and is **nightly-only**. It detects when a d is missing a code example. For example: ```rust -#![warn(missing_doc_code_examples)] +#![warn(rustdoc::missing_doc_code_examples)] /// There is no code example! pub fn no_code_example() {} @@ -191,7 +194,7 @@ This lint is **allowed by default**. It detects documentation tests when they are on a private item. For example: ```rust -#![warn(private_doc_tests)] +#![warn(rustdoc::private_doc_tests)] mod foo { /// private doc test @@ -245,7 +248,7 @@ warning: unknown attribute `should-panic`. Did you mean `should_panic`? 5 | | /// ``` | |_______^ | - = note: `#[warn(invalid_codeblock_attributes)]` on by default + = note: `#[warn(rustdoc::invalid_codeblock_attributes)]` on by default = help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running ``` @@ -258,7 +261,7 @@ This lint is **allowed by default** and is **nightly-only**. It detects unclosed or invalid HTML tags. For example: ```rust -#![warn(invalid_html_tags)] +#![warn(rustdoc::invalid_html_tags)] ///

/// @@ -275,7 +278,11 @@ warning: unopened HTML tag `script` 2 | | /// | |_____________^ | - = note: `#[warn(invalid_html_tags)]` on by default + note: the lint level is defined here + --> foo.rs:1:9 + | +1 | #![warn(rustdoc::invalid_html_tags)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: unclosed HTML tag `h1` --> foo.rs:1:1 @@ -310,7 +317,7 @@ warning: this URL is not a hyperlink 1 | /// http://example.org | ^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `` | - = note: `#[warn(non_autolinks)]` on by default + = note: `#[warn(rustdoc::non_autolinks)]` on by default warning: unneeded long form for URL --> foo.rs:2:5 diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 5313f8553a894..9580a6d1ddc82 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -260,9 +260,8 @@ crate fn create_config( // By default, rustdoc ignores all lints. // Specifically unblock lints relevant to documentation or the lint machinery itself. let mut lints_to_show = vec![ - // it's unclear whether these should be part of rustdoc directly + // it's unclear whether this should be part of rustdoc directly (#77364) rustc_lint::builtin::MISSING_DOCS.name.to_string(), - rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS.name.to_string(), // these are definitely not part of rustdoc, but we want to warn on them anyway. rustc_lint::builtin::RENAMED_AND_REMOVED_LINTS.name.to_string(), rustc_lint::builtin::UNKNOWN_LINTS.name.to_string(), @@ -482,7 +481,7 @@ crate fn run_global_ctxt( let help = "The following guide may be of use:\n\ https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html"; tcx.struct_lint_node( - rustc_lint::builtin::MISSING_CRATE_LEVEL_DOCS, + crate::lint::MISSING_CRATE_LEVEL_DOCS, ctxt.as_local_hir_id(m.def_id).unwrap(), |lint| { let mut diag = diff --git a/src/librustdoc/lint.rs b/src/librustdoc/lint.rs index 7d95561d039f9..e8806c1b6d787 100644 --- a/src/librustdoc/lint.rs +++ b/src/librustdoc/lint.rs @@ -104,6 +104,17 @@ declare_rustdoc_lint! { "codeblock attribute looks a lot like a known one" } +declare_rustdoc_lint! { + /// The `missing_crate_level_docs` lint detects if documentation is + /// missing at the crate root. This is a `rustdoc` only lint, see the + /// documentation in the [rustdoc book]. + /// + /// [rustdoc book]: ../../../rustdoc/lints.html#missing_crate_level_docs + MISSING_CRATE_LEVEL_DOCS, + Allow, + "detects crates with no crate-level documentation" +} + declare_rustdoc_lint! { /// The `missing_doc_code_examples` lint detects publicly-exported items /// without code samples in their documentation. This is a `rustdoc` only @@ -156,6 +167,7 @@ crate static RUSTDOC_LINTS: Lazy> = Lazy::new(|| { INVALID_CODEBLOCK_ATTRIBUTES, INVALID_HTML_TAGS, NON_AUTOLINKS, + MISSING_CRATE_LEVEL_DOCS, ] }); diff --git a/src/test/rustdoc-ui/check.stderr b/src/test/rustdoc-ui/check.stderr index 3c29a45a64a98..e6ba9df9b0555 100644 --- a/src/test/rustdoc-ui/check.stderr +++ b/src/test/rustdoc-ui/check.stderr @@ -21,6 +21,17 @@ warning: missing documentation for a function LL | pub fn foo() {} | ^^^^^^^^^^^^ +warning: no documentation found for this crate's top-level module + | +note: the lint level is defined here + --> $DIR/check.rs:7:9 + | +LL | #![warn(rustdoc)] + | ^^^^^^^ + = note: `#[warn(rustdoc::missing_crate_level_docs)]` implied by `#[warn(rustdoc)]` + = help: The following guide may be of use: + https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html + warning: missing code example in this documentation --> $DIR/check.rs:4:1 | @@ -45,5 +56,5 @@ warning: missing code example in this documentation LL | pub fn foo() {} | ^^^^^^^^^^^^^^^ -warning: 4 warnings emitted +warning: 5 warnings emitted diff --git a/src/test/rustdoc-ui/no-crate-level-doc-lint.rs b/src/test/rustdoc-ui/no-crate-level-doc-lint.rs index 152a7cd88bcb1..3939ec6827ade 100644 --- a/src/test/rustdoc-ui/no-crate-level-doc-lint.rs +++ b/src/test/rustdoc-ui/no-crate-level-doc-lint.rs @@ -1,3 +1,5 @@ -#![deny(missing_crate_level_docs)] +// error-pattern: no documentation found +#![deny(rustdoc::missing_crate_level_docs)] +//^~ NOTE defined here pub fn foo() {} diff --git a/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr b/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr index 6e7e2fb3eb73f..55ead1a55cfcd 100644 --- a/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr +++ b/src/test/rustdoc-ui/no-crate-level-doc-lint.stderr @@ -1,10 +1,10 @@ error: no documentation found for this crate's top-level module | note: the lint level is defined here - --> $DIR/no-crate-level-doc-lint.rs:1:9 + --> $DIR/no-crate-level-doc-lint.rs:2:9 | -LL | #![deny(missing_crate_level_docs)] - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(rustdoc::missing_crate_level_docs)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: The following guide may be of use: https://doc.rust-lang.org/nightly/rustdoc/how-to-write-documentation.html From c7535d13617078029f870a5ccc9258b42dc360b8 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Mon, 18 Jan 2021 22:24:16 -0500 Subject: [PATCH 07/19] Update comments Note that the FIXME was removed because this can't be fixed, `register_renamed` calls LintId::of and there's no LintId for rustdoc lints when rustc is running. --- compiler/rustc_lint/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index a15a972cce721..547779dd6856a 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -325,7 +325,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { // These were moved to tool lints, but rustc still sees them when compiling normally, before // tool lints are registered, so `check_tool_name_for_backwards_compat` doesn't work. Use - // `register_renamed` explicitly. + // `register_removed` explicitly. const RUSTDOC_LINTS: &[&str] = &[ "broken_intra_doc_links", "private_intra_doc_links", @@ -337,7 +337,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { "non_autolinks", ]; for rustdoc_lint in RUSTDOC_LINTS { - // FIXME: maybe we could get `register_renamed` to work for tool lints? store.register_removed(rustdoc_lint, &format!("use `rustdoc::{}` instead", rustdoc_lint)); } store.register_removed( From 75efb6efa34adf6436b4cb687f3a57f29bb635c7 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 28 Feb 2021 00:49:15 -0500 Subject: [PATCH 08/19] Test that using the previous lint names still applies the lint --- .../rustdoc-ui/renamed-lint-still-applies.rs | 5 ++++ .../renamed-lint-still-applies.stderr | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/test/rustdoc-ui/renamed-lint-still-applies.rs create mode 100644 src/test/rustdoc-ui/renamed-lint-still-applies.stderr diff --git a/src/test/rustdoc-ui/renamed-lint-still-applies.rs b/src/test/rustdoc-ui/renamed-lint-still-applies.rs new file mode 100644 index 0000000000000..6d4bad16aadc2 --- /dev/null +++ b/src/test/rustdoc-ui/renamed-lint-still-applies.rs @@ -0,0 +1,5 @@ +// compile-args: --crate-type lib +#![deny(broken_intra_doc_links)] +//~^ WARNING renamed +//! [x] +//~^ ERROR unresolved link diff --git a/src/test/rustdoc-ui/renamed-lint-still-applies.stderr b/src/test/rustdoc-ui/renamed-lint-still-applies.stderr new file mode 100644 index 0000000000000..e14cbfa1726c3 --- /dev/null +++ b/src/test/rustdoc-ui/renamed-lint-still-applies.stderr @@ -0,0 +1,23 @@ +warning: lint `broken_intra_doc_links` has been renamed to `rustdoc::broken_intra_doc_links` + --> $DIR/renamed-lint-still-applies.rs:2:9 + | +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `rustdoc::broken_intra_doc_links` + | + = note: `#[warn(renamed_and_removed_lints)]` on by default + +error: unresolved link to `x` + --> $DIR/renamed-lint-still-applies.rs:4:6 + | +LL | //! [x] + | ^ no item named `x` in scope + | +note: the lint level is defined here + --> $DIR/renamed-lint-still-applies.rs:2:9 + | +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ + = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` + +error: aborting due to previous error; 1 warning emitted + From c194849a7569665b3f446eb7c8cbccf1e2e2399a Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 2 Mar 2021 12:54:25 +0100 Subject: [PATCH 09/19] Fix stabilization version of move_ref_pattern --- compiler/rustc_feature/src/accepted.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index aa54ffb132dc9..5012d500cee20 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -272,7 +272,7 @@ declare_features! ( (accepted, doc_alias, "1.48.0", Some(50146), None), /// Allows patterns with concurrent by-move and by-ref bindings. /// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref. - (accepted, move_ref_pattern, "1.48.0", Some(68354), None), + (accepted, move_ref_pattern, "1.49.0", Some(68354), None), /// The smallest useful subset of `const_generics`. (accepted, min_const_generics, "1.51.0", Some(74878), None), From 768d5e950953738a54480e530341964838d29da2 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 19 Feb 2021 17:22:30 -0800 Subject: [PATCH 10/19] Load rustdoc's JS search index on-demand. Instead of being loaded on every page, the JS search index is now loaded when either (a) there is a `?search=` param, or (b) the search input is focused. This saves both CPU and bandwidth. As of Feb 2021, https://doc.rust-lang.org/search-index1.50.0.js is 273,838 bytes gzipped or 2,544,939 bytes uncompressed. Evaluating it takes 445 ms of CPU time in Chrome 88 on a i7-10710U CPU (out of a total ~2,100 ms page reload). Generate separate JS file with crate names. This is much smaller than the full search index, and is used in the "hot path" to draw the page. In particular it's used to crate the dropdown for the search bar, and to append a list of crates to the sidebar (on some pages). Skip early search that can bypass 500ms timeout. This was occurring when someone had typed some text during the load of search-index.js. Their query was usually not ready to execute, and the search itself is fairly expensive, delaying the overall load, which delayed the input / keyup events, which delayed eventually executing the query. --- src/librustdoc/html/layout.rs | 5 +- src/librustdoc/html/render/mod.rs | 17 +++--- src/librustdoc/html/static/main.js | 98 +++++++++++++++++------------- 3 files changed, 69 insertions(+), 51 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index e5a686bd07d07..855934ef4d430 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -58,6 +58,7 @@ crate fn render( {style_files}\ \ \ + \ \ {css_extension}\ {favicon}\ @@ -112,10 +113,10 @@ crate fn render(
\
\ {after_content}\ -
+
\ {extra_scripts}\ - \ \ ", css_extension = if layout.css_file_extension.is_some() { diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 58e9e41e6a53c..dd531f1510220 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1039,10 +1039,12 @@ themePicker.onblur = handleThemeButtonsBlur; cx.shared.fs.write(&dst, v.as_bytes())?; } - // Update the search index + // Update the search index and crate list. let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix)); let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name.as_str()), &dst); all_indexes.push(search_index); + krates.push(krate.name.to_string()); + krates.sort(); // Sort the indexes by crate so the file will be generated identically even // with rustdoc running in parallel. @@ -1050,11 +1052,15 @@ themePicker.onblur = handleThemeButtonsBlur; { let mut v = String::from("var searchIndex = JSON.parse('{\\\n"); v.push_str(&all_indexes.join(",\\\n")); - // "addSearchOptions" has to be called first so the crate filtering can be set before the - // search might start (if it's set into the URL for example). - v.push_str("\\\n}');\naddSearchOptions(searchIndex);initSearch(searchIndex);"); + v.push_str("\\\n}');\ninitSearch(searchIndex);"); cx.shared.fs.write(&dst, &v)?; } + + let crate_list_dst = cx.dst.join(&format!("crates{}.js", cx.shared.resource_suffix)); + let crate_list = + format!("window.ALL_CRATES = [{}];", krates.iter().map(|k| format!("\"{}\"", k)).join(",")); + cx.shared.fs.write(&crate_list_dst, &crate_list)?; + if options.enable_index_page { if let Some(index_page) = options.index_page.clone() { let mut md_opts = options.clone(); @@ -1076,9 +1082,6 @@ themePicker.onblur = handleThemeButtonsBlur; extra_scripts: &[], static_extra_scripts: &[], }; - krates.push(krate.name.to_string()); - krates.sort(); - krates.dedup(); let content = format!( "

\ diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 76449a171d7cc..89b1362b32b63 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -42,6 +42,7 @@ if (!DOMTokenList.prototype.remove) { if (rustdocVars) { window.rootPath = rustdocVars.attributes["data-root-path"].value; window.currentCrate = rustdocVars.attributes["data-current-crate"].value; + window.searchJS = rustdocVars.attributes["data-search-js"].value; } var sidebarVars = document.getElementById("sidebar-vars"); if (sidebarVars) { @@ -1922,8 +1923,8 @@ function defocusSearchBar() { return searchWords; } - function startSearch() { - var callback = function() { + function registerSearchEvents() { + var searchAfter500ms = function() { clearInputTimeout(); if (search_input.value.length === 0) { if (browserSupportsHistoryApi()) { @@ -1935,8 +1936,8 @@ function defocusSearchBar() { searchTimeout = setTimeout(search, 500); } }; - search_input.onkeyup = callback; - search_input.oninput = callback; + search_input.onkeyup = searchAfter500ms; + search_input.oninput = searchAfter500ms; document.getElementsByClassName("search-form")[0].onsubmit = function(e) { e.preventDefault(); clearInputTimeout(); @@ -1999,7 +2000,6 @@ function defocusSearchBar() { } }); } - search(); // This is required in firefox to avoid this problem: Navigating to a search result // with the keyboard, hitting enter, and then hitting back would take you back to @@ -2017,8 +2017,14 @@ function defocusSearchBar() { } index = buildIndex(rawSearchIndex); - startSearch(); + registerSearchEvents(); + // If there's a search term in the URL, execute the search now. + if (getQueryStringParams().search) { + search(); + } + }; + function addSidebarCrates(crates) { // Draw a convenient sidebar of known crates if we have a listing if (window.rootPath === "../" || window.rootPath === "./") { var sidebar = document.getElementsByClassName("sidebar-elems")[0]; @@ -2029,14 +2035,6 @@ function defocusSearchBar() { var ul = document.createElement("ul"); div.appendChild(ul); - var crates = []; - for (var crate in rawSearchIndex) { - if (!hasOwnProperty(rawSearchIndex, crate)) { - continue; - } - crates.push(crate); - } - crates.sort(); for (var i = 0; i < crates.length; ++i) { var klass = "crate"; if (window.rootPath !== "./" && crates[i] === window.currentCrate) { @@ -2044,9 +2042,6 @@ function defocusSearchBar() { } var link = document.createElement("a"); link.href = window.rootPath + crates[i] + "/index.html"; - // The summary in the search index has HTML, so we need to - // dynamically render it as plaintext. - link.title = convertHTMLToPlaintext(rawSearchIndex[crates[i]].doc); link.className = klass; link.textContent = crates[i]; @@ -2057,7 +2052,7 @@ function defocusSearchBar() { sidebar.appendChild(div); } } - }; + } /** * Convert HTML to plaintext: @@ -2862,37 +2857,18 @@ function defocusSearchBar() { } } - window.addSearchOptions = function(crates) { + function addSearchOptions(crates) { var elem = document.getElementById("crate-search"); if (!elem) { enableSearchInput(); return; } - var crates_text = []; - if (Object.keys(crates).length > 1) { - for (var crate in crates) { - if (hasOwnProperty(crates, crate)) { - crates_text.push(crate); - } - } - } - crates_text.sort(function(a, b) { - var lower_a = a.toLowerCase(); - var lower_b = b.toLowerCase(); - - if (lower_a < lower_b) { - return -1; - } else if (lower_a > lower_b) { - return 1; - } - return 0; - }); var savedCrate = getSettingValue("saved-filter-crate"); - for (var i = 0, len = crates_text.length; i < len; ++i) { + for (var i = 0, len = crates.length; i < len; ++i) { var option = document.createElement("option"); - option.value = crates_text[i]; - option.innerText = crates_text[i]; + option.value = crates[i]; + option.innerText = crates[i]; elem.appendChild(option); // Set the crate filter from saved storage, if the current page has the saved crate // filter. @@ -2900,7 +2876,7 @@ function defocusSearchBar() { // If not, ignore the crate filter -- we want to support filtering for crates on sites // like doc.rust-lang.org where the crates may differ from page to page while on the // same domain. - if (crates_text[i] === savedCrate) { + if (crates[i] === savedCrate) { elem.value = savedCrate; } } @@ -2969,6 +2945,44 @@ function defocusSearchBar() { buildHelperPopup = function() {}; } + function loadScript(url) { + var script = document.createElement('script'); + script.src = url; + document.head.append(script); + } + + function setupSearchLoader() { + var searchLoaded = false; + function loadSearch() { + if (!searchLoaded) { + searchLoaded = true; + loadScript(window.searchJS); + } + } + + // `crates{version}.js` should always be loaded before this script, so we can use it safely. + addSearchOptions(window.ALL_CRATES); + addSidebarCrates(window.ALL_CRATES); + + search_input.addEventListener("focus", function() { + search_input.origPlaceholder = search_input.placeholder; + search_input.placeholder = "Type your search here."; + loadSearch(); + }); + search_input.addEventListener("blur", function() { + search_input.placeholder = search_input.origPlaceholder; + }); + enableSearchInput(); + + var crateSearchDropDown = document.getElementById("crate-search"); + crateSearchDropDown.addEventListener("focus", loadSearch); + var params = getQueryStringParams(); + if (params.search !== undefined) { + loadSearch(); + } + } + onHashChange(null); window.onhashchange = onHashChange; + setupSearchLoader(); }()); From 9c4e3af39d5e93b2976afa8062ee5c705ba589c5 Mon Sep 17 00:00:00 2001 From: Waffle Date: Wed, 3 Mar 2021 01:00:59 +0300 Subject: [PATCH 11/19] Add test that Vec::spare_capacity_mut doesn't invalidate pointers --- library/alloc/tests/lib.rs | 1 + library/alloc/tests/vec.rs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs index dd98f806451d8..d40496bfaaba7 100644 --- a/library/alloc/tests/lib.rs +++ b/library/alloc/tests/lib.rs @@ -21,6 +21,7 @@ #![feature(vecdeque_binary_search)] #![feature(slice_group_by)] #![feature(vec_extend_from_within)] +#![feature(vec_spare_capacity)] use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 2969da58d4268..fab450285854d 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1691,6 +1691,10 @@ fn test_stable_pointers() { next_then_drop(v.splice(5..6, vec![1; 10].into_iter().filter(|_| true))); // lower bound not exact assert_eq!(*v0, 13); + // spare_capacity_mut + v.spare_capacity_mut(); + assert_eq!(*v0, 13); + // Smoke test that would fire even outside Miri if an actual relocation happened. *v0 -= 13; assert_eq!(v[0], 0); From a1835bcb01fc345653fd9e9ce02b0d103032c58d Mon Sep 17 00:00:00 2001 From: Waffle Date: Wed, 3 Mar 2021 01:04:20 +0300 Subject: [PATCH 12/19] Make Vec::split_at_spare_mut impl safer & simplier --- library/alloc/src/vec/mod.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index e5545d2a77ff7..ff401b33832ce 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1944,20 +1944,16 @@ impl Vec { #[unstable(feature = "vec_split_at_spare", issue = "81944")] #[inline] pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit]) { - let ptr = self.as_mut_ptr(); - - // SAFETY: - // - `ptr` is guaranteed to be in bounds for `capacity` elements - // - `len` is guaranteed to less or equal to `capacity` - // - `MaybeUninit` has the same layout as `T` - let spare_ptr = unsafe { ptr.cast::>().add(self.len) }; + let Range { start: ptr, end: spare_ptr } = self.as_mut_ptr_range(); + let spare_ptr = spare_ptr.cast::>(); + let spare_len = self.buf.capacity() - self.len; // SAFETY: // - `ptr` is guaranteed to be valid for `len` elements - // - `spare_ptr` is offseted from `ptr` by `len`, so it doesn't overlap `initialized` slice + // - `spare_ptr` is pointing one element past the buffer, so it doesn't overlap with `initialized` slice unsafe { let initialized = slice::from_raw_parts_mut(ptr, self.len); - let spare = slice::from_raw_parts_mut(spare_ptr, self.buf.capacity() - self.len); + let spare = slice::from_raw_parts_mut(spare_ptr, spare_len); (initialized, spare) } From d3e7ffa7f548801d4a5784d314aabdafe9186af7 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Fri, 19 Feb 2021 17:54:41 -0800 Subject: [PATCH 13/19] Improve page load performance in rustdoc. Add font-display: swap. Per https://web.dev/font-display/, this prevents "flash of invisible text" during load by using a system font until the custom font is available. I've noticed this flash of invisible text occasionally when reading Rust docs. Add an explicit height to icons (which already had an explicit width) to allow browsers to lay out the page more accurately before the icons have been loaded. https://web.dev/optimize-cls/. Add min-width: 115px to the crate search dropdown. When the HTML first loads, this dropdown includes only the text "All crates." Later, JS loads the items underneath it, some of which are wider. That causes the dropdown to get wider, causing a distracting reflow. This sets a min-width based on the size that the dropdown eventually becomes based on the crates on doc.rust-lang.org, reducing page movement during load. --- src/doc/rust.css | 6 ++++++ src/librustdoc/html/layout.rs | 4 ++-- src/librustdoc/html/static/rustdoc.css | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/doc/rust.css b/src/doc/rust.css index a92d4ff54db83..ff18e1a8f51cc 100644 --- a/src/doc/rust.css +++ b/src/doc/rust.css @@ -3,30 +3,35 @@ font-style: normal; font-weight: 400; src: local('Fira Sans'), url("FiraSans-Regular.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Fira Sans'; font-style: normal; font-weight: 500; src: local('Fira Sans Medium'), url("FiraSans-Medium.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Source Serif Pro'; font-style: normal; font-weight: 400; src: local('Source Serif Pro'), url("SourceSerifPro-Regular.ttf.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Source Serif Pro'; font-style: italic; font-weight: 400; src: url("SourceSerifPro-It.ttf.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Source Serif Pro'; font-style: normal; font-weight: 700; src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.ttf.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Source Code Pro'; @@ -35,6 +40,7 @@ /* Avoid using locally installed font because bad versions are in circulation: * see https://github.com/rust-lang/rust/issues/24355 */ src: url("SourceCodePro-Regular.woff") format('woff'); + font-display: swap; } *:not(body) { diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index e5a686bd07d07..64b209a46c01d 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -82,7 +82,7 @@ crate fn render(
\ \
\ @@ -102,7 +102,7 @@ crate fn render( \ \"Change\ \
\ diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index e3d63fa2308e2..7da18409d5e0e 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -6,6 +6,7 @@ src: local('Fira Sans'), url("FiraSans-Regular.woff2") format("woff2"), url("FiraSans-Regular.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Fira Sans'; @@ -14,6 +15,7 @@ src: local('Fira Sans Medium'), url("FiraSans-Medium.woff2") format("woff2"), url("FiraSans-Medium.woff") format('woff'); + font-display: swap; } /* See SourceSerifPro-LICENSE.txt for the Source Serif Pro license. */ @@ -22,18 +24,21 @@ font-style: normal; font-weight: 400; src: local('Source Serif Pro'), url("SourceSerifPro-Regular.ttf.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Source Serif Pro'; font-style: italic; font-weight: 400; src: local('Source Serif Pro Italic'), url("SourceSerifPro-It.ttf.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Source Serif Pro'; font-style: normal; font-weight: 700; src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.ttf.woff") format('woff'); + font-display: swap; } /* See SourceCodePro-LICENSE.txt for the Source Code Pro license. */ @@ -44,12 +49,14 @@ /* Avoid using locally installed font because bad versions are in circulation: * see https://github.com/rust-lang/rust/issues/24355 */ src: url("SourceCodePro-Regular.woff") format('woff'); + font-display: swap; } @font-face { font-family: 'Source Code Pro'; font-style: normal; font-weight: 600; src: url("SourceCodePro-Semibold.woff") format('woff'); + font-display: swap; } * { @@ -684,6 +691,7 @@ a { width: calc(100% - 63px); } #crate-search { + min-width: 115px; margin-top: 5px; padding: 6px; padding-right: 19px; From 5824917dbb895a0fec2135d7c448b64317dd0aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 2 Mar 2021 18:24:13 -0800 Subject: [PATCH 14/19] Account for macros when suggesting adding lifetime Fix #70152. --- .../rustc_resolve/src/late/diagnostics.rs | 25 ++++++++---- ...ifetime-used-in-debug-macro-issue-70152.rs | 16 ++++++++ ...ime-used-in-debug-macro-issue-70152.stderr | 38 +++++++++++++++++++ 3 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.rs create mode 100644 src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index d60f929cb8f3f..36707b5938f26 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1645,6 +1645,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { ); err.span_label(lifetime_ref.span, "undeclared lifetime"); let mut suggests_in_band = false; + let mut suggest_note = true; for missing in &self.missing_named_lifetime_spots { match missing { MissingLifetimeSpot::Generics(generics) => { @@ -1664,12 +1665,20 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { suggests_in_band = true; (generics.span, format!("<{}>", lifetime_ref)) }; - err.span_suggestion( - span, - &format!("consider introducing lifetime `{}` here", lifetime_ref), - sugg, - Applicability::MaybeIncorrect, - ); + if !span.from_expansion() { + err.span_suggestion( + span, + &format!("consider introducing lifetime `{}` here", lifetime_ref), + sugg, + Applicability::MaybeIncorrect, + ); + } else if suggest_note { + suggest_note = false; // Avoid displaying the same help multiple times. + err.help(&format!( + "consider introducing lifetime `{}` to the item's generics", + lifetime_ref, + )); + } } MissingLifetimeSpot::HigherRanked { span, span_type } => { err.span_suggestion( @@ -1684,7 +1693,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { ); err.note( "for more information on higher-ranked polymorphism, visit \ - https://doc.rust-lang.org/nomicon/hrtb.html", + https://doc.rust-lang.org/nomicon/hrtb.html", ); } _ => {} @@ -1696,7 +1705,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { { err.help( "if you want to experiment with in-band lifetime bindings, \ - add `#![feature(in_band_lifetimes)]` to the crate attributes", + add `#![feature(in_band_lifetimes)]` to the crate attributes", ); } err.emit(); diff --git a/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.rs b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.rs new file mode 100644 index 0000000000000..cc29f9de7fb4a --- /dev/null +++ b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.rs @@ -0,0 +1,16 @@ +#[derive(Eq, PartialEq)] +struct Test { + a: &'b str, + //~^ ERROR use of undeclared lifetime name `'b` + //~| ERROR use of undeclared lifetime name `'b` +} + +trait T { + fn foo(&'static self) {} +} + +impl T for Test { + fn foo(&'b self) {} //~ ERROR use of undeclared lifetime name `'b` +} + +fn main() {} diff --git a/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr new file mode 100644 index 0000000000000..01dc0edc61eec --- /dev/null +++ b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr @@ -0,0 +1,38 @@ +error[E0261]: use of undeclared lifetime name `'b` + --> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:13:13 + | +LL | fn foo(&'b self) {} + | ^^ undeclared lifetime + | + = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes +help: consider introducing lifetime `'b` here + | +LL | impl<'b> T for Test { + | ^^^^ +help: consider introducing lifetime `'b` here + | +LL | fn foo<'b>(&'b self) {} + | ^^^^ + +error[E0261]: use of undeclared lifetime name `'b` + --> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9 + | +LL | struct Test { + | - help: consider introducing lifetime `'b` here: `<'b>` +LL | a: &'b str, + | ^^ undeclared lifetime + | + = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes + +error[E0261]: use of undeclared lifetime name `'b` + --> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9 + | +LL | a: &'b str, + | ^^ undeclared lifetime + | + = help: consider introducing lifetime `'b` to the item's generics + = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0261`. From f9cfe1583b18052bc5f42d92e8973e18ba404b19 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Tue, 2 Mar 2021 18:27:34 -0800 Subject: [PATCH 15/19] Use Arial as fallback font instead of sans-serif. On most platforms and browsers, `sans-serif` is equivalent to Arial. However, on Firefox on Ubuntu (and possibly other Linuxes), `sans-serif` is DejaVu Sans, a much wider font. This creates a larger shift in text when the custom fonts finally load. Arial is a web-safe font, and specifying it explicitly gives us more cross-platform consistency, as well as reducing the layout shift that happens when fonts load. --- src/librustdoc/html/static/rustdoc.css | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 7da18409d5e0e..94c231cb33a8b 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -136,7 +136,7 @@ h1, h2, h3, h4, #source-sidebar, #sidebar-toggle, /* This selector is for the items listed in the "all items" page. */ #main > ul.docblock > li > a { - font-family: "Fira Sans", sans-serif; + font-family: "Fira Sans", Arial; } .content ul.crate a.crate { @@ -482,7 +482,7 @@ h4 > code, h3 > code, .invisible > code { } #main > .since { top: inherit; - font-family: "Fira Sans", sans-serif; + font-family: "Fira Sans", Arial; } .content table:not(.table-display) { @@ -1301,7 +1301,7 @@ h4 > .notable-traits { .help-button { right: 30px; - font-family: "Fira Sans",sans-serif; + font-family: "Fira Sans", Arial; text-align: center; font-size: 17px; } From 950f12119ef724156a9a4e17e1b375eb28c6af11 Mon Sep 17 00:00:00 2001 From: Waffle Lapkin Date: Wed, 3 Mar 2021 20:04:20 +0300 Subject: [PATCH 16/19] Update library/alloc/src/vec/mod.rs Co-authored-by: Ralf Jung --- library/alloc/src/vec/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index ff401b33832ce..4b992d1756bef 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1950,7 +1950,7 @@ impl Vec { // SAFETY: // - `ptr` is guaranteed to be valid for `len` elements - // - `spare_ptr` is pointing one element past the buffer, so it doesn't overlap with `initialized` slice + // - `spare_ptr` is pointing one element past the buffer, so it doesn't overlap with `initialized` unsafe { let initialized = slice::from_raw_parts_mut(ptr, self.len); let spare = slice::from_raw_parts_mut(spare_ptr, spare_len); From 5d0697b1be074a0774f521baf97492260e2a0737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 3 Mar 2021 12:15:26 -0800 Subject: [PATCH 17/19] reworded message --- compiler/rustc_resolve/src/late/diagnostics.rs | 12 ++++++++---- ...d-lifetime-used-in-debug-macro-issue-70152.stderr | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 36707b5938f26..87bf79d722bde 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1674,10 +1674,14 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { ); } else if suggest_note { suggest_note = false; // Avoid displaying the same help multiple times. - err.help(&format!( - "consider introducing lifetime `{}` to the item's generics", - lifetime_ref, - )); + err.span_label( + span, + &format!( + "lifetime `{}` is missing in item created through this procedural \ + macro", + lifetime_ref, + ), + ); } } MissingLifetimeSpot::HigherRanked { span, span_type } => { diff --git a/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr index 01dc0edc61eec..30142e24cd5f1 100644 --- a/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr +++ b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr @@ -27,10 +27,12 @@ LL | a: &'b str, error[E0261]: use of undeclared lifetime name `'b` --> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9 | +LL | #[derive(Eq, PartialEq)] + | -- lifetime `'b` is missing in item created through this procedural macro +LL | struct Test { LL | a: &'b str, | ^^ undeclared lifetime | - = help: consider introducing lifetime `'b` to the item's generics = help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes error: aborting due to 3 previous errors From a705a58fe953ce95fe482e081a7d843e0b2d9c06 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 3 Mar 2021 22:11:07 -0500 Subject: [PATCH 18/19] Fix commit detected when using `download-rustc` On reflection on the issue in https://github.com/rust-lang/rust/pull/79540#discussion_r572572280, I think the bug was actually using the `compiler/` filter, not using `--author=bors`. https://github.com/rust-lang/rust/commit/9a1d6174c925f54c923599e29b09d6855e6b3a78 has no CI artifacts because it was merged as part of a rollup: ``` $ curl -I https://ci-artifacts.rust-lang.org/rustc-builds/96e843ce6ae42e0aa519ba45e148269de347fd84/rust-std-nightly-x86_64-unknown-linux-gnu.tar.xz HTTP/2 404 ``` So 9a1d6174c925f54c923599e29b09d6855e6b3a78 is the correct commit to download, and that's what `--author=bors` does: $ git log --author=bors 4aec8a5da5547d6e1c24e99dad0003b7cac107f5 commit 9a1d6174c925f54c923599e29b09d6855e6b3a78 Ideally it would look for "the most recent bors commit not followed by a change to `compiler/`", which would exclude things like documentation changes and avoid redownloading more than necessary, but - Redownloading isn't the end of the world, - That metric is hard to implement, and - Documentation-only or library-only changes are very rare anyway since they're usually rolled up with changes to the compiler. --- src/bootstrap/bootstrap.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 62bf4ffd380a0..3e7d1d54f1284 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -647,9 +647,8 @@ def maybe_download_rustc(self): compiler = "{}/compiler/".format(top_level) # Look for a version to compare to based on the current commit. - # Ideally this would just use `merge-base`, but on beta and stable branches that wouldn't - # come up with any commits, so hack it and use `author=bors` instead. - merge_base = ["git", "log", "--author=bors", "--pretty=%H", "-n1", "--", compiler] + # Only commits merged by bors will have CI artifacts. + merge_base = ["git", "log", "--author=bors", "--pretty=%H", "-n1"] commit = subprocess.check_output(merge_base, universal_newlines=True).strip() # Warn if there were changes to the compiler since the ancestor commit. From c79af862401465a7241e6920ba31f34adafa44fd Mon Sep 17 00:00:00 2001 From: Camelid Date: Wed, 3 Mar 2021 20:04:27 -0800 Subject: [PATCH 19/19] Pass `CrateNum` by value instead of by reference It's more idiomatic to pass a small Copy type by value and `CrateNum` is half the size of `&CrateNum` on 64-bit systems. The memory use change is almost certainly insignificant, but why not! --- src/librustdoc/clean/types.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 09ba0e2740f1b..e3f47a85d5154 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -191,7 +191,7 @@ impl Item { } crate fn links(&self, cache: &Cache) -> Vec { - self.attrs.links(&self.def_id.krate, cache) + self.attrs.links(self.def_id.krate, cache) } crate fn is_crate(&self) -> bool { @@ -844,7 +844,7 @@ impl Attributes { /// Gets links as a vector /// /// Cache must be populated before call - crate fn links(&self, krate: &CrateNum, cache: &Cache) -> Vec { + crate fn links(&self, krate: CrateNum, cache: &Cache) -> Vec { use crate::html::format::href; use crate::html::render::CURRENT_DEPTH; @@ -869,7 +869,7 @@ impl Attributes { } None => { if let Some(ref fragment) = *fragment { - let url = match cache.extern_locations.get(krate) { + let url = match cache.extern_locations.get(&krate) { Some(&(_, _, ExternalLocation::Local)) => { let depth = CURRENT_DEPTH.with(|l| l.get()); "../".repeat(depth)