diff --git a/Cargo.lock b/Cargo.lock index 43da32df5d9ca..06444b76e56d7 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/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..1c6f1344e8a1e 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -101,9 +101,13 @@ 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 `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 @@ -589,9 +593,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), @@ -688,6 +689,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/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/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 { diff --git a/src/doc/unstable-book/src/library-features/asm.md b/src/doc/unstable-book/src/library-features/asm.md index bd7234522e1fe..6bf21e8f58b25 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) ); ``` 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() {} 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. 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 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| {