From 3bb40f2ea00ceac3e91986a01ef5b2ecc8070f29 Mon Sep 17 00:00:00 2001 From: Chris Palmer Date: Tue, 19 Oct 2021 20:40:09 -0700 Subject: [PATCH 1/8] Make printed message match the code comment I think this code is getting L0, not L1 cache size, if I'm reading the Intel manual right. (I might not be.) Either way, the code comment and the printed message should match, whichever way is right. :) --- src/doc/unstable-book/src/library-features/asm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index 5a2cef24870be..e70933b7bae10 100644 --- a/src/doc/unstable-book/src/library-features/asm.md +++ b/src/doc/unstable-book/src/library-features/asm.md @@ -257,7 +257,7 @@ unsafe { } println!( - "L1 Cache: {}", + "L0 Cache: {}", ((ebx >> 22) + 1) * (((ebx >> 12) & 0x3ff) + 1) * ((ebx & 0xfff) + 1) * (ecx + 1) ); ``` From 01e441f8e51a8276ccbc3bda6ac616eac13d01b4 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Wed, 27 Oct 2021 22:18:51 +0200 Subject: [PATCH 2/8] Document clippy on nightly-rustc --- src/bootstrap/builder.rs | 1 + src/bootstrap/doc.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index d5656f0f37e03..6ba1b1b6036ea 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -482,6 +482,7 @@ impl<'a> Builder<'a> { doc::RustByExample, doc::RustcBook, doc::CargoBook, + doc::Clippy, doc::EmbeddedBook, doc::EditionGuide, ), diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 6f2470b706a64..2804e7119fbc1 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -755,6 +755,7 @@ tool_doc!( "src/tools/rustfmt", ["rustfmt-nightly", "rustfmt-config_proc_macro"], ); +tool_doc!(Clippy, "clippy", "src/tools/clippy", ["clippy_utils"]); #[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct ErrorIndex { From b40aa64e48836a8582fd949033342e5c1a20dae4 Mon Sep 17 00:00:00 2001 From: lcnr Date: Sat, 30 Oct 2021 15:56:02 +0200 Subject: [PATCH 3/8] stabilize `relaxed_struct_unsize` --- compiler/rustc_feature/src/accepted.rs | 2 + compiler/rustc_feature/src/active.rs | 3 -- .../src/traits/select/confirmation.rs | 52 +++++-------------- .../feature-gate-relaxed_struct_unsize.rs | 10 ---- .../feature-gate-relaxed_struct_unsize.stderr | 14 ----- src/test/ui/unsized/unchanged-param.rs | 1 - 6 files changed, 14 insertions(+), 68 deletions(-) delete mode 100644 src/test/ui/feature-gates/feature-gate-relaxed_struct_unsize.rs delete mode 100644 src/test/ui/feature-gates/feature-gate-relaxed_struct_unsize.stderr diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 0d7a2afb6367d..941d957103c0c 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -297,6 +297,8 @@ declare_features! ( (accepted, macro_attributes_in_derive_output, "1.57.0", Some(81119), None), /// Allows panicking during const eval (producing compile-time errors). (accepted, const_panic, "1.57.0", Some(51999), None), + /// Lessens the requirements for structs to implement `Unsize`. + (accepted, relaxed_struct_unsize, "1.58.0", Some(81793), None), // ------------------------------------------------------------------------- // feature-group-end: accepted features diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 2bbfb561ba594..16d4b26d9d0b4 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -589,9 +589,6 @@ declare_features! ( /// Allows `extern "C-cmse-nonsecure-call" fn()`. (active, abi_c_cmse_nonsecure_call, "1.51.0", Some(81391), None), - /// Lessens the requirements for structs to implement `Unsize`. - (active, relaxed_struct_unsize, "1.51.0", Some(81793), None), - /// Allows associated types in inherent impls. (incomplete, inherent_associated_types, "1.52.0", Some(8995), None), diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 84721922c8dd7..079828a60fce2 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -948,52 +948,24 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tail_field_ty = tcx.type_of(tail_field.did); let mut unsizing_params = GrowableBitSet::new_empty(); - if tcx.features().relaxed_struct_unsize { - for arg in tail_field_ty.walk(tcx) { - if let Some(i) = maybe_unsizing_param_idx(arg) { - unsizing_params.insert(i); - } - } - - // Ensure none of the other fields mention the parameters used - // in unsizing. - for field in prefix_fields { - for arg in tcx.type_of(field.did).walk(tcx) { - if let Some(i) = maybe_unsizing_param_idx(arg) { - unsizing_params.remove(i); - } - } + for arg in tail_field_ty.walk(tcx) { + if let Some(i) = maybe_unsizing_param_idx(arg) { + unsizing_params.insert(i); } + } - if unsizing_params.is_empty() { - return Err(Unimplemented); - } - } else { - let mut found = false; - for arg in tail_field_ty.walk(tcx) { + // Ensure none of the other fields mention the parameters used + // in unsizing. + for field in prefix_fields { + for arg in tcx.type_of(field.did).walk(tcx) { if let Some(i) = maybe_unsizing_param_idx(arg) { - unsizing_params.insert(i); - found = true; + unsizing_params.remove(i); } } - if !found { - return Err(Unimplemented); - } + } - // Ensure none of the other fields mention the parameters used - // in unsizing. - // FIXME(eddyb) cache this (including computing `unsizing_params`) - // by putting it in a query; it would only need the `DefId` as it - // looks at declared field types, not anything substituted. - for field in prefix_fields { - for arg in tcx.type_of(field.did).walk(tcx) { - if let Some(i) = maybe_unsizing_param_idx(arg) { - if unsizing_params.contains(i) { - return Err(Unimplemented); - } - } - } - } + if unsizing_params.is_empty() { + return Err(Unimplemented); } // Extract `TailField` and `TailField` from `Struct` and `Struct`. diff --git a/src/test/ui/feature-gates/feature-gate-relaxed_struct_unsize.rs b/src/test/ui/feature-gates/feature-gate-relaxed_struct_unsize.rs deleted file mode 100644 index 0cfd0a0b9784c..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-relaxed_struct_unsize.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Test that we allow unsizing even if there is an unchanged param in the -// field getting unsized. -struct A(T, B); -struct B(T, U); - -fn main() { - let x: A<[u32; 1], [u32; 1]> = A([0; 1], B([0; 1], [0; 1])); - let y: &A<[u32; 1], [u32]> = &x; //~ ERROR mismatched types - assert_eq!(y.1.1.len(), 1); -} diff --git a/src/test/ui/feature-gates/feature-gate-relaxed_struct_unsize.stderr b/src/test/ui/feature-gates/feature-gate-relaxed_struct_unsize.stderr deleted file mode 100644 index f62def47726f9..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-relaxed_struct_unsize.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/feature-gate-relaxed_struct_unsize.rs:8:34 - | -LL | let y: &A<[u32; 1], [u32]> = &x; - | ------------------- ^^ expected slice `[u32]`, found array `[u32; 1]` - | | - | expected due to this - | - = note: expected reference `&A<[u32; 1], [u32]>` - found reference `&A<[u32; 1], [u32; 1]>` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/unsized/unchanged-param.rs b/src/test/ui/unsized/unchanged-param.rs index 83199e8112e71..93c7af68ac388 100644 --- a/src/test/ui/unsized/unchanged-param.rs +++ b/src/test/ui/unsized/unchanged-param.rs @@ -1,4 +1,3 @@ -#![feature(relaxed_struct_unsize)] // run-pass // Test that we allow unsizing even if there is an unchanged param in the // field getting unsized. From 597f889e45e3a76b1f5fc22f30ab499490e91862 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 1 Nov 2021 15:34:19 +0100 Subject: [PATCH 4/8] Clarify what to do with accepted feature gates The documentation only referenced `removed.rs`, but feature gates for accepted features move to `accepted.rs`. --- compiler/rustc_feature/src/active.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 2bbfb561ba594..7cf53d40ff693 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -103,7 +103,8 @@ impl Feature { // If you change this, please modify `src/doc/unstable-book` as well. // -// Don't ever remove anything from this list; move them to `removed.rs`. +// Don't ever remove anything from this list; move them to `accepted.rs` if +// accepted or `removed.rs` if removed. // // The version numbers here correspond to the version in which the current status // was set. This is most important for knowing when a particular feature became From fd41336c4cb848225bd11cd2e4242b3099763493 Mon Sep 17 00:00:00 2001 From: xFrednet Date: Tue, 2 Nov 2021 14:19:31 +0100 Subject: [PATCH 5/8] Update clippy dependencies * semver = "0.11" -> "1.0" * cargo_metadata = "0.12" -> "0.14" --- Cargo.lock | 8 ++++---- src/tools/clippy/Cargo.toml | 4 ++-- src/tools/clippy/clippy_lints/Cargo.toml | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf19f5e0ae32f..92e6e6f04e09b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -576,7 +576,7 @@ dependencies = [ name = "clippy" version = "0.1.58" dependencies = [ - "cargo_metadata 0.12.0", + "cargo_metadata 0.14.0", "clippy_lints", "clippy_utils", "compiletest_rs", @@ -588,7 +588,7 @@ dependencies = [ "regex", "rustc-workspace-hack", "rustc_tools_util 0.2.0", - "semver 0.11.0", + "semver 1.0.3", "serde", "syn", "tempfile", @@ -613,7 +613,7 @@ dependencies = [ name = "clippy_lints" version = "0.1.58" dependencies = [ - "cargo_metadata 0.12.0", + "cargo_metadata 0.14.0", "clippy_utils", "if_chain", "itertools 0.10.1", @@ -621,7 +621,7 @@ dependencies = [ "quine-mc_cluskey", "regex-syntax", "rustc-semver", - "semver 0.11.0", + "semver 1.0.3", "serde", "serde_json", "toml", diff --git a/src/tools/clippy/Cargo.toml b/src/tools/clippy/Cargo.toml index ed7fb1440139f..d475aaa3ee067 100644 --- a/src/tools/clippy/Cargo.toml +++ b/src/tools/clippy/Cargo.toml @@ -22,12 +22,12 @@ path = "src/driver.rs" [dependencies] clippy_lints = { version = "0.1", path = "clippy_lints" } -semver = "0.11" +semver = "1.0" rustc_tools_util = { version = "0.2", path = "rustc_tools_util" } tempfile = { version = "3.2", optional = true } [dev-dependencies] -cargo_metadata = "0.12" +cargo_metadata = "0.14" compiletest_rs = { version = "0.7", features = ["tmp"] } tester = "0.9" regex = "1.5" diff --git a/src/tools/clippy/clippy_lints/Cargo.toml b/src/tools/clippy/clippy_lints/Cargo.toml index aaf9ac83d4900..281480b8d9491 100644 --- a/src/tools/clippy/clippy_lints/Cargo.toml +++ b/src/tools/clippy/clippy_lints/Cargo.toml @@ -9,7 +9,7 @@ keywords = ["clippy", "lint", "plugin"] edition = "2021" [dependencies] -cargo_metadata = "0.12" +cargo_metadata = "0.14" clippy_utils = { path = "../clippy_utils" } if_chain = "1.0" itertools = "0.10" @@ -21,7 +21,7 @@ serde_json = { version = "1.0", optional = true } toml = "0.5" unicode-normalization = "0.1" unicode-script = { version = "0.5", default-features = false } -semver = "0.11" +semver = "1.0" rustc-semver = "1.1" # NOTE: cargo requires serde feat in its url dep # see From eb23a7333ff540adac206c80f2416a69e25c924d Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Tue, 2 Nov 2021 15:30:28 +0100 Subject: [PATCH 6/8] Add link to documentation about feature gates --- compiler/rustc_feature/src/active.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 7cf53d40ff693..a55ea31481074 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -101,6 +101,9 @@ impl Feature { } } +// See https://rustc-dev-guide.rust-lang.org/feature-gates.html#feature-gates for more +// documentation about handling feature gates. +// // If you change this, please modify `src/doc/unstable-book` as well. // // Don't ever remove anything from this list; move them to `accepted.rs` if From d50a4753b8cffdb17e2d83282d95b61e266521fb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 2 Nov 2021 14:36:54 +0100 Subject: [PATCH 7/8] Split doc_cfg and doc_auto_cfg features --- compiler/rustc_feature/src/active.rs | 3 +++ compiler/rustc_span/src/symbol.rs | 1 + src/librustdoc/clean/types.rs | 9 ++++++--- src/test/rustdoc/doc-auto-cfg.rs | 8 ++++++++ src/test/rustdoc/doc-cfg-hide.rs | 2 +- src/test/rustdoc/doc-cfg-implicit.rs | 2 +- src/test/rustdoc/feature-gate-doc_auto_cfg.rs | 8 ++++++++ 7 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc/doc-auto-cfg.rs create mode 100644 src/test/rustdoc/feature-gate-doc_auto_cfg.rs diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 2bbfb561ba594..42af8e1faad02 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -688,6 +688,9 @@ declare_features! ( /// not changed from prior instances of the same struct (RFC #2528) (incomplete, type_changing_struct_update, "1.58.0", Some(86555), None), + /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`. + (active, doc_auto_cfg, "1.58.0", Some(43781), None), + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 1b4315896321f..5f71e955e2ad7 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -549,6 +549,7 @@ symbols! { div_assign, doc, doc_alias, + doc_auto_cfg, doc_cfg, doc_cfg_hide, doc_keyword, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 88fffaecb937b..56ae43855de92 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -789,6 +789,7 @@ impl AttributesExt for [ast::Attribute] { fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet) -> Option> { let sess = tcx.sess; let doc_cfg_active = tcx.features().doc_cfg; + let doc_auto_cfg_active = tcx.features().doc_auto_cfg; fn single(it: T) -> Option { let mut iter = it.into_iter(); @@ -799,24 +800,26 @@ impl AttributesExt for [ast::Attribute] { Some(item) } - let mut cfg = if doc_cfg_active { + let mut cfg = if doc_cfg_active || doc_auto_cfg_active { let mut doc_cfg = self .iter() .filter(|attr| attr.has_name(sym::doc)) .flat_map(|attr| attr.meta_item_list().unwrap_or_else(Vec::new)) .filter(|attr| attr.has_name(sym::cfg)) .peekable(); - if doc_cfg.peek().is_some() { + if doc_cfg.peek().is_some() && doc_cfg_active { doc_cfg .filter_map(|attr| Cfg::parse(attr.meta_item()?).ok()) .fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg) - } else { + } else if doc_auto_cfg_active { self.iter() .filter(|attr| attr.has_name(sym::cfg)) .filter_map(|attr| single(attr.meta_item_list()?)) .filter_map(|attr| Cfg::parse(attr.meta_item()?).ok()) .filter(|cfg| !hidden_cfg.contains(cfg)) .fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg) + } else { + Cfg::True } } else { Cfg::True diff --git a/src/test/rustdoc/doc-auto-cfg.rs b/src/test/rustdoc/doc-auto-cfg.rs new file mode 100644 index 0000000000000..fcdd83545696b --- /dev/null +++ b/src/test/rustdoc/doc-auto-cfg.rs @@ -0,0 +1,8 @@ +#![feature(doc_auto_cfg)] + +#![crate_name = "foo"] + +// @has foo/fn.foo.html +// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-test' +#[cfg(not(test))] +pub fn foo() {} diff --git a/src/test/rustdoc/doc-cfg-hide.rs b/src/test/rustdoc/doc-cfg-hide.rs index b9d0d32313723..424fa6d6a911f 100644 --- a/src/test/rustdoc/doc-cfg-hide.rs +++ b/src/test/rustdoc/doc-cfg-hide.rs @@ -1,5 +1,5 @@ #![crate_name = "oud"] -#![feature(doc_cfg, doc_cfg_hide)] +#![feature(doc_auto_cfg, doc_cfg, doc_cfg_hide)] #![doc(cfg_hide(feature = "solecism"))] diff --git a/src/test/rustdoc/doc-cfg-implicit.rs b/src/test/rustdoc/doc-cfg-implicit.rs index 36c2025785d0f..5d17a4ede6adc 100644 --- a/src/test/rustdoc/doc-cfg-implicit.rs +++ b/src/test/rustdoc/doc-cfg-implicit.rs @@ -1,5 +1,5 @@ #![crate_name = "funambulism"] -#![feature(doc_cfg)] +#![feature(doc_auto_cfg, doc_cfg)] // @has 'funambulism/struct.Disorbed.html' // @count - '//*[@class="stab portability"]' 1 diff --git a/src/test/rustdoc/feature-gate-doc_auto_cfg.rs b/src/test/rustdoc/feature-gate-doc_auto_cfg.rs new file mode 100644 index 0000000000000..da76381e48000 --- /dev/null +++ b/src/test/rustdoc/feature-gate-doc_auto_cfg.rs @@ -0,0 +1,8 @@ +#![feature(doc_cfg)] + +#![crate_name = "foo"] + +// @has foo/fn.foo.html +// @count - '//*[@class="item-info"]/*[@class="stab portability"]' 0 +#[cfg(not(test))] +pub fn foo() {} From d7afbf61d87bf345597624cccdfb1036439697b9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 2 Nov 2021 17:15:11 +0100 Subject: [PATCH 8/8] Also check for feature gates in "src/test/rustdoc" --- src/tools/tidy/src/features.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index 338dfd11310aa..129237775fe3f 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -97,6 +97,7 @@ pub fn check( &src_path.join("test/ui"), &src_path.join("test/ui-fulldeps"), &src_path.join("test/rustdoc-ui"), + &src_path.join("test/rustdoc"), ], &mut |path| super::filter_dirs(path), &mut |entry, contents| {