From 0fdd6cc2591e0dca3c55a698444e0e83e07b0ccb Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 10 Jun 2021 14:42:17 +0800 Subject: [PATCH 01/14] Make OR_PATTERNS_BACK_COMPAT be a 2021 future-incompatible lint --- compiler/rustc_lint_defs/src/builtin.rs | 4 ++++ .../macro-or-patterns-back-compat.fixed | 17 +++++++++++++---- .../macros/macro-or-patterns-back-compat.rs | 17 +++++++++++++---- .../macro-or-patterns-back-compat.stderr | 19 +++++++++++++++---- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 352146d64635a..f95d4a6ca5481 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -3239,4 +3239,8 @@ declare_lint! { pub OR_PATTERNS_BACK_COMPAT, Allow, "detects usage of old versions of or-patterns", + @future_incompatible = FutureIncompatibleInfo { + reference: "issue #84869 ", + edition: Some(Edition::Edition2021), + }; } diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.fixed b/src/test/ui/macros/macro-or-patterns-back-compat.fixed index f829129d516b2..f4e81a6be2a89 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.fixed +++ b/src/test/ui/macros/macro-or-patterns-back-compat.fixed @@ -2,13 +2,22 @@ #![deny(or_patterns_back_compat)] #![allow(unused_macros)] -macro_rules! foo { ($x:pat_param | $y:pat) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro -macro_rules! bar { ($($x:pat_param)+ | $($y:pat)+) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro + +macro_rules! foo { ($x:pat_param | $y:pat) => {} } +//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +//~| WARN this was previously accepted +macro_rules! bar { ($($x:pat_param)+ | $($y:pat)+) => {} } +//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +//~| WARN this was previously accepted macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok -macro_rules! ogg { ($x:pat_param | $y:pat_param) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +macro_rules! ogg { ($x:pat_param | $y:pat_param) => {} } +//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +//~| WARN this was previously accepted macro_rules! match_any { - ( $expr:expr , $( $( $pat:pat_param )|+ => $expr_arm:expr ),+ ) => { //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro + ( $expr:expr , $( $( $pat:pat_param )|+ => $expr_arm:expr ),+ ) => { + //~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro + //~| WARN this was previously accepted match $expr { $( $( $pat => $expr_arm, )+ diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.rs b/src/test/ui/macros/macro-or-patterns-back-compat.rs index 1cdaa1cd6317b..49affdd38da9d 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.rs +++ b/src/test/ui/macros/macro-or-patterns-back-compat.rs @@ -2,13 +2,22 @@ #![deny(or_patterns_back_compat)] #![allow(unused_macros)] -macro_rules! foo { ($x:pat | $y:pat) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro -macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro + +macro_rules! foo { ($x:pat | $y:pat) => {} } +//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +//~| WARN this was previously accepted +macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } +//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +//~| WARN this was previously accepted macro_rules! baz { ($x:pat_param | $y:pat_param) => {} } // should be ok macro_rules! qux { ($x:pat_param | $y:pat) => {} } // should be ok -macro_rules! ogg { ($x:pat | $y:pat_param) => {} } //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +macro_rules! ogg { ($x:pat | $y:pat_param) => {} } +//~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro +//~| WARN this was previously accepted macro_rules! match_any { - ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { //~ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro + ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { + //~^ ERROR the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro + //~| WARN this was previously accepted match $expr { $( $( $pat => $expr_arm, )+ diff --git a/src/test/ui/macros/macro-or-patterns-back-compat.stderr b/src/test/ui/macros/macro-or-patterns-back-compat.stderr index 01d220dd0b114..62687eb36b89e 100644 --- a/src/test/ui/macros/macro-or-patterns-back-compat.stderr +++ b/src/test/ui/macros/macro-or-patterns-back-compat.stderr @@ -1,5 +1,5 @@ error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro - --> $DIR/macro-or-patterns-back-compat.rs:5:21 + --> $DIR/macro-or-patterns-back-compat.rs:6:21 | LL | macro_rules! foo { ($x:pat | $y:pat) => {} } | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` @@ -9,24 +9,35 @@ note: the lint level is defined here | LL | #![deny(or_patterns_back_compat)] | ^^^^^^^^^^^^^^^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = note: for more information, see issue #84869 error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro - --> $DIR/macro-or-patterns-back-compat.rs:6:23 + --> $DIR/macro-or-patterns-back-compat.rs:9:23 | LL | macro_rules! bar { ($($x:pat)+ | $($y:pat)+) => {} } | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = note: for more information, see issue #84869 error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro - --> $DIR/macro-or-patterns-back-compat.rs:9:21 + --> $DIR/macro-or-patterns-back-compat.rs:14:21 | LL | macro_rules! ogg { ($x:pat | $y:pat_param) => {} } | ^^^^^^ help: use pat_param to preserve semantics: `$x:pat_param` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = note: for more information, see issue #84869 error: the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro - --> $DIR/macro-or-patterns-back-compat.rs:11:26 + --> $DIR/macro-or-patterns-back-compat.rs:18:26 | LL | ( $expr:expr , $( $( $pat:pat )|+ => $expr_arm:expr ),+ ) => { | ^^^^^^^^ help: use pat_param to preserve semantics: `$pat:pat_param` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2021 edition! + = note: for more information, see issue #84869 error: aborting due to 4 previous errors From c09b6996317b711d6153116c13fd8085f3868f93 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 13 Jun 2021 01:41:35 +0900 Subject: [PATCH 02/14] Add a regression test for issue-85113 --- .../ui/type-alias-impl-trait/issue-85113.rs | 22 +++++++++ .../type-alias-impl-trait/issue-85113.stderr | 48 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/issue-85113.rs create mode 100644 src/test/ui/type-alias-impl-trait/issue-85113.stderr diff --git a/src/test/ui/type-alias-impl-trait/issue-85113.rs b/src/test/ui/type-alias-impl-trait/issue-85113.rs new file mode 100644 index 0000000000000..b09833f3ed014 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-85113.rs @@ -0,0 +1,22 @@ +#![feature(min_type_alias_impl_trait)] +#![feature(impl_trait_in_bindings)] +#![allow(incomplete_features)] + +type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; +//~^ ERROR: hidden type for `impl Trait` captures lifetime that does not appear in bounds +//~| ERROR: the type `&' str` does not fulfill the required lifetime +//~| ERROR: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements + +trait Output<'a> {} + +impl<'a> Output<'a> for &'a str {} + +fn cool_fn<'a>(arg: &'a str) -> OpaqueOutputImpl<'a> { + let out: OpaqueOutputImpl<'a> = arg; + arg +} + +fn main() { + let s = String::from("wassup"); + cool_fn(&s); +} diff --git a/src/test/ui/type-alias-impl-trait/issue-85113.stderr b/src/test/ui/type-alias-impl-trait/issue-85113.stderr new file mode 100644 index 0000000000000..361d66866ef8b --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-85113.stderr @@ -0,0 +1,48 @@ +error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds + --> $DIR/issue-85113.rs:5:29 + | +LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; + | ^^^^^^^^^^^^^^^^^^^^ + | +note: hidden type `&' str` captures lifetime smaller than the function body + --> $DIR/issue-85113.rs:5:29 + | +LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; + | ^^^^^^^^^^^^^^^^^^^^ + +error[E0477]: the type `&' str` does not fulfill the required lifetime + --> $DIR/issue-85113.rs:5:29 + | +LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; + | ^^^^^^^^^^^^^^^^^^^^ + | +note: type must outlive the lifetime `'a` as defined on the item at 5:23 + --> $DIR/issue-85113.rs:5:23 + | +LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; + | ^^ + +error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements + --> $DIR/issue-85113.rs:5:29 + | +LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: first, the lifetime cannot outlive the empty lifetime... +note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the item at 5:23... + --> $DIR/issue-85113.rs:5:23 + | +LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; + | ^^ +note: ...so that the types are compatible + --> $DIR/issue-85113.rs:5:29 + | +LL | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; + | ^^^^^^^^^^^^^^^^^^^^ + = note: expected `Output<'a>` + found `Output<'_>` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0477, E0495, E0700. +For more information about an error, try `rustc --explain E0477`. From 782824c48f79d5fbe6732484e4b5cc4ab9892e41 Mon Sep 17 00:00:00 2001 From: Yerkebulan Tulibergenov Date: Tue, 15 Jun 2021 21:32:13 -0700 Subject: [PATCH 03/14] add regression test for issue #78632 --- src/test/ui/traits/issue-78632.rs | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/test/ui/traits/issue-78632.rs diff --git a/src/test/ui/traits/issue-78632.rs b/src/test/ui/traits/issue-78632.rs new file mode 100644 index 0000000000000..c72a2aef4900f --- /dev/null +++ b/src/test/ui/traits/issue-78632.rs @@ -0,0 +1,59 @@ +// check-pass +// +// Regression test for issue #78632 + +#![crate_type = "lib"] + +pub trait Corge { + type Fred; +} + +impl Corge for () { + type Fred = u32; +} + +pub trait Waldo { + type Quax; +} + +impl Waldo for u32 { + type Quax = u8; +} + +pub trait Grault +where + (): Corge, +{ + type Thud; + fn bar(_: <() as Corge>::Fred) {} +} + +impl Grault for T +where + T: Waldo, + (): Corge, + <() as Corge>::Fred: Waldo, +{ + type Thud = u8; +} + +pub trait Plugh { + fn baz(); +} + +#[derive(Copy, Clone, Debug)] +pub struct Qiz { + foo: T, +} + +impl Plugh<<() as Corge>::Fred> for Qiz +where + T: Grault, + (): Corge, +{ + fn baz() {} +} + +pub fn test() { + as Plugh>::baz(); +} From d2f2237d3127f2da13d6bc610de2af09253c531a Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Thu, 17 Jun 2021 22:35:19 -0500 Subject: [PATCH 04/14] fix(rustfmt): load nested out-of-line mods correctly --- src/tools/rustfmt/src/modules.rs | 2 +- src/tools/rustfmt/src/test/mod.rs | 1 + src/tools/rustfmt/src/test/mod_resolver.rs | 25 +++++++++++++++++++ .../tests/mod-resolver/issue-4874/bar/baz.rs | 5 ++++ .../tests/mod-resolver/issue-4874/foo.rs | 1 + .../tests/mod-resolver/issue-4874/foo/qux.rs | 5 ++++ .../tests/mod-resolver/issue-4874/main.rs | 8 ++++++ 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/tools/rustfmt/src/test/mod_resolver.rs create mode 100644 src/tools/rustfmt/tests/mod-resolver/issue-4874/bar/baz.rs create mode 100644 src/tools/rustfmt/tests/mod-resolver/issue-4874/foo.rs create mode 100644 src/tools/rustfmt/tests/mod-resolver/issue-4874/foo/qux.rs create mode 100644 src/tools/rustfmt/tests/mod-resolver/issue-4874/main.rs diff --git a/src/tools/rustfmt/src/modules.rs b/src/tools/rustfmt/src/modules.rs index c3f4406860135..5de0575b5cd66 100644 --- a/src/tools/rustfmt/src/modules.rs +++ b/src/tools/rustfmt/src/modules.rs @@ -318,7 +318,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { self.directory = directory; } match (sub_mod.ast_mod_kind, sub_mod.items) { - (Some(Cow::Borrowed(ast::ModKind::Loaded(items, ast::Inline::No, _))), _) => { + (Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => { self.visit_mod_from_ast(&items) } (Some(Cow::Owned(..)), Cow::Owned(items)) => self.visit_mod_outside_ast(items), diff --git a/src/tools/rustfmt/src/test/mod.rs b/src/tools/rustfmt/src/test/mod.rs index ce56a223f2b04..cb52346a13a41 100644 --- a/src/tools/rustfmt/src/test/mod.rs +++ b/src/tools/rustfmt/src/test/mod.rs @@ -16,6 +16,7 @@ use crate::source_file; use crate::{is_nightly_channel, FormatReport, FormatReportFormatterBuilder, Input, Session}; mod configuration_snippet; +mod mod_resolver; mod parser; const DIFF_CONTEXT_SIZE: usize = 3; diff --git a/src/tools/rustfmt/src/test/mod_resolver.rs b/src/tools/rustfmt/src/test/mod_resolver.rs new file mode 100644 index 0000000000000..e0b55e3efb2c4 --- /dev/null +++ b/src/tools/rustfmt/src/test/mod_resolver.rs @@ -0,0 +1,25 @@ +use std::io; +use std::path::PathBuf; + +use super::read_config; + +use crate::{FileName, Input, Session}; + +#[test] +fn nested_out_of_line_mods_loaded() { + // See also https://github.com/rust-lang/rustfmt/issues/4874 + let filename = "tests/mod-resolver/issue-4874/main.rs"; + let input_file = PathBuf::from(filename); + let config = read_config(&input_file); + let mut session = Session::::new(config, None); + let report = session + .format(Input::File(filename.into())) + .expect("Should not have had any execution errors"); + let errors_by_file = &report.internal.borrow().0; + assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from( + "tests/mod-resolver/issue-4874/bar/baz.rs", + )))); + assert!(errors_by_file.contains_key(&FileName::Real(PathBuf::from( + "tests/mod-resolver/issue-4874/foo/qux.rs", + )))); +} diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-4874/bar/baz.rs b/src/tools/rustfmt/tests/mod-resolver/issue-4874/bar/baz.rs new file mode 100644 index 0000000000000..d31b675ea260d --- /dev/null +++ b/src/tools/rustfmt/tests/mod-resolver/issue-4874/bar/baz.rs @@ -0,0 +1,5 @@ +fn + fail_fmt_check + ( + + ) {} \ No newline at end of file diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-4874/foo.rs b/src/tools/rustfmt/tests/mod-resolver/issue-4874/foo.rs new file mode 100644 index 0000000000000..246d847869a12 --- /dev/null +++ b/src/tools/rustfmt/tests/mod-resolver/issue-4874/foo.rs @@ -0,0 +1 @@ +mod qux; \ No newline at end of file diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-4874/foo/qux.rs b/src/tools/rustfmt/tests/mod-resolver/issue-4874/foo/qux.rs new file mode 100644 index 0000000000000..d8bb610a64db1 --- /dev/null +++ b/src/tools/rustfmt/tests/mod-resolver/issue-4874/foo/qux.rs @@ -0,0 +1,5 @@ + fn + badly_formatted + ( + + ) {} \ No newline at end of file diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-4874/main.rs b/src/tools/rustfmt/tests/mod-resolver/issue-4874/main.rs new file mode 100644 index 0000000000000..3609415b1468b --- /dev/null +++ b/src/tools/rustfmt/tests/mod-resolver/issue-4874/main.rs @@ -0,0 +1,8 @@ +fn main() { + println!("Hello, world!"); +} + +mod foo; +mod bar { + mod baz; +} \ No newline at end of file From 9c495b30efd1ccbe34bf3a877df0a7a55f6444f9 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 20 Jun 2021 08:13:23 +0800 Subject: [PATCH 05/14] "(const: unstable)" for stable-but-const-unstable --- src/librustdoc/html/render/mod.rs | 36 +++++++++++++++++++----- src/librustdoc/html/render/print_item.rs | 4 +-- src/test/rustdoc/const-display.rs | 2 ++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 62d3c142eeb52..16df17372b011 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -42,7 +42,7 @@ use std::str; use std::string::ToString; use rustc_ast_pretty::pprust; -use rustc_attr::{Deprecation, StabilityLevel}; +use rustc_attr::{ConstStability, Deprecation, StabilityLevel}; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_hir::def::CtorKind; @@ -826,20 +826,42 @@ fn assoc_type( fn render_stability_since_raw( w: &mut Buffer, ver: Option<&str>, - const_ver: Option<&str>, + const_stability: Option<&ConstStability>, containing_ver: Option<&str>, containing_const_ver: Option<&str>, ) { let ver = ver.filter(|inner| !inner.is_empty()); - let const_ver = const_ver.filter(|inner| !inner.is_empty()); - match (ver, const_ver) { - (Some(v), Some(cv)) if const_ver != containing_const_ver => { + match (ver, const_stability) { + (Some(v), Some(ConstStability { level: StabilityLevel::Stable { since }, .. })) + if Some(since.as_str()).as_deref() != containing_const_ver => + { write!( w, "{0} (const: {1})", - v, cv + v, + since.as_str() + ); + } + ( + Some(v), + Some(ConstStability { level: StabilityLevel::Unstable { issue, .. }, feature, .. }), + ) => { + write!( + w, + "{0} (const: ", + v ); + if let Some(n) = issue { + write!( + w, + "unstable", + n, feature + ); + } else { + write!(w, "unstable"); + } + write!(w, ")"); } (Some(v), _) if ver != containing_ver => { write!( @@ -1583,7 +1605,7 @@ fn render_rightside( render_stability_since_raw( w, item.stable_since(tcx).as_deref(), - item.const_stable_since(tcx).as_deref(), + item.const_stability(tcx), containing_item.stable_since(tcx).as_deref(), containing_item.const_stable_since(tcx).as_deref(), ); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 48cbd94ccabfb..1340040fa8f06 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -94,7 +94,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer, render_stability_since_raw( buf, item.stable_since(cx.tcx()).as_deref(), - item.const_stable_since(cx.tcx()).as_deref(), + item.const_stability(cx.tcx()), None, None, ); @@ -1291,7 +1291,7 @@ fn render_stability_since( render_stability_since_raw( w, item.stable_since(tcx).as_deref(), - item.const_stable_since(tcx).as_deref(), + item.const_stability(tcx), containing_item.stable_since(tcx).as_deref(), containing_item.const_stable_since(tcx).as_deref(), ) diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs index 2761f92ef5712..41a511f716581 100644 --- a/src/test/rustdoc/const-display.rs +++ b/src/test/rustdoc/const-display.rs @@ -8,6 +8,7 @@ #![feature(staged_api)] // @has 'foo/fn.foo.html' '//pre' 'pub unsafe fn foo() -> u32' +// @has - '//span[@class="since"]' '1.0.0 (const: unstable)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature="foo", issue = "none")] pub const unsafe fn foo() -> u32 { 42 } @@ -39,6 +40,7 @@ pub struct Foo; impl Foo { // @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/code' 'pub unsafe fn gated() -> u32' + // @has - '//span[@class="since"]' '1.0.0 (const: unstable)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature="foo", issue = "none")] pub const unsafe fn gated() -> u32 { 42 } From f804d8d71b2c2d9b05386950953bf65efebe6454 Mon Sep 17 00:00:00 2001 From: r00ster91 Date: Sun, 20 Jun 2021 22:19:47 +0200 Subject: [PATCH 06/14] Improve documentation --- library/proc_macro/src/lib.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index 53f172717f0a5..c9079b1cbadc2 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -766,7 +766,7 @@ impl fmt::Debug for Group { } } -/// An `Punct` is an single punctuation character like `+`, `-` or `#`. +/// A `Punct` is a single punctuation character such as `+`, `-` or `#`. /// /// Multi-character operators like `+=` are represented as two instances of `Punct` with different /// forms of `Spacing` returned. @@ -779,16 +779,19 @@ impl !Send for Punct {} #[stable(feature = "proc_macro_lib2", since = "1.29.0")] impl !Sync for Punct {} -/// Whether an `Punct` is followed immediately by another `Punct` or -/// followed by another token or whitespace. +/// Describes whether a `Punct` is followed immediately by another `Punct` ([`Spacing::Joint`]) or +/// by a different token or whitespace ([`Spacing::Alone`]). #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[stable(feature = "proc_macro_lib2", since = "1.29.0")] pub enum Spacing { - /// e.g., `+` is `Alone` in `+ =`, `+ident` or `+()`. + /// A `Punct` is not immediately followed by another `Punct`. + /// E.g. `+` is `Alone` in `+ =`, `+ident` and `+()`. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] Alone, - /// e.g., `+` is `Joint` in `+=` or `'#`. - /// Additionally, single quote `'` can join with identifiers to form lifetimes `'ident`. + /// A `Punct` is immediately followed by another `Punct`. + /// E.g. `+` is `Joint` in `+=` and `++`. + /// + /// Additionally, single quote `'` can join with identifiers to form lifetimes: `'ident`. #[stable(feature = "proc_macro_lib2", since = "1.29.0")] Joint, } From 61b453cd1ab28b0dabab3293ee12df7474516eb6 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 19 Jun 2021 10:08:13 -0400 Subject: [PATCH 07/14] Fix CI to fetch master on beta channel --- src/ci/init_repo.sh | 2 +- src/ci/run.sh | 6 +----- src/ci/shared.sh | 8 ++++++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ci/init_repo.sh b/src/ci/init_repo.sh index 060b3079dad5f..3c61dcc9d9c7b 100755 --- a/src/ci/init_repo.sh +++ b/src/ci/init_repo.sh @@ -31,7 +31,7 @@ mkdir "$CACHE_DIR" # On the beta channel we'll be automatically calculating the prerelease version # via the git history, so unshallow our shallow clone from CI. -if grep -q RUST_RELEASE_CHANNEL=beta src/ci/run.sh; then +if [ "$(releaseChannel)" = "beta" ]; then git fetch origin --unshallow beta master fi diff --git a/src/ci/run.sh b/src/ci/run.sh index c5e225c7cd17d..b5019d83af45b 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -65,11 +65,7 @@ fi # Always set the release channel for bootstrap; this is normally not important (i.e., only dist # builds would seem to matter) but in practice bootstrap wants to know whether we're targeting # master, beta, or stable with a build to determine whether to run some checks (notably toolstate). -if [[ -z "${RUST_CI_OVERRIDE_RELEASE_CHANNEL+x}" ]]; then - export RUST_RELEASE_CHANNEL="$(cat "${ci_dir}/channel")" -else - export RUST_RELEASE_CHANNEL="${RUST_CI_OVERRIDE_RELEASE_CHANNEL}" -fi +export RUST_RELEASE_CHANNEL=$(releaseChannel) RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then diff --git a/src/ci/shared.sh b/src/ci/shared.sh index 332a949a4dc51..b095afb542d83 100644 --- a/src/ci/shared.sh +++ b/src/ci/shared.sh @@ -141,3 +141,11 @@ function ciCommandSetEnv { exit 1 fi } + +function releaseChannel { + if [[ -z "${RUST_CI_OVERRIDE_RELEASE_CHANNEL+x}" ]]; then + cat "${ci_dir}/channel" + else + echo $RUST_CI_OVERRIDE_RELEASE_CHANNEL + fi +} From 008d4d6c11ab1855115f80f4f73dc0cf36bb0626 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 20 Jun 2021 18:15:54 -0700 Subject: [PATCH 08/14] Fix rust.css fonts. --- src/doc/rust.css | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/doc/rust.css b/src/doc/rust.css index 06f4df9a9b6da..dba97a067a32c 100644 --- a/src/doc/rust.css +++ b/src/doc/rust.css @@ -1,45 +1,68 @@ +/* See FiraSans-LICENSE.txt for the Fira Sans license. */ @font-face { font-family: 'Fira Sans'; font-style: normal; font-weight: 400; - src: local('Fira Sans'), url("FiraSans-Regular.woff") format('woff'); + 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'; font-style: normal; font-weight: 500; - src: local('Fira Sans Medium'), url("FiraSans-Medium.woff") format('woff'); + src: local('Fira Sans Medium'), + url("FiraSans-Medium.woff2") format("woff2"), + url("FiraSans-Medium.woff") format('woff'); font-display: swap; } + +/* See SourceSerif4-LICENSE.md for the Source Serif 4 license. */ @font-face { - font-family: 'Source Serif Pro'; + font-family: 'Source Serif 4'; font-style: normal; font-weight: 400; - src: local('Source Serif Pro'), url("SourceSerifPro-Regular.ttf.woff") format('woff'); + src: local('Source Serif 4'), url("SourceSerif4-Regular.ttf.woff") format('woff'); font-display: swap; } @font-face { - font-family: 'Source Serif Pro'; + font-family: 'Source Serif 4'; font-style: italic; font-weight: 400; - src: url("SourceSerifPro-It.ttf.woff") format('woff'); + src: local('Source Serif 4 Italic'), url("SourceSerif4-It.ttf.woff") format('woff'); font-display: swap; } @font-face { - font-family: 'Source Serif Pro'; + font-family: 'Source Serif 4'; font-style: normal; font-weight: 700; - src: local('Source Serif Pro Bold'), url("SourceSerifPro-Bold.ttf.woff") format('woff'); + src: local('Source Serif 4 Bold'), url("SourceSerif4-Bold.ttf.woff") format('woff'); font-display: swap; } + +/* See SourceCodePro-LICENSE.txt for the Source Code Pro license. */ @font-face { font-family: 'Source Code Pro'; font-style: normal; font-weight: 400; /* 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'); + src: url("SourceCodePro-Regular.ttf.woff") format('woff'); + font-display: swap; +} +@font-face { + font-family: 'Source Code Pro'; + font-style: italic; + font-weight: 400; + src: url("SourceCodePro-It.ttf.woff") format('woff'); + font-display: swap; +} +@font-face { + font-family: 'Source Code Pro'; + font-style: normal; + font-weight: 600; + src: url("SourceCodePro-Semibold.ttf.woff") format('woff'); font-display: swap; } @@ -55,7 +78,7 @@ body { background-color: white; margin: 0 auto; padding: 0 15px; - font-family: "Source Serif Pro", Georgia, Times, "Times New Roman", serif; + font-family: "Source Serif 4", Georgia, Times, "Times New Roman", serif; font-size: 18px; color: #333; line-height: 1.428571429; From e84c9aed6d82eddcaf96d1c4fe90adcd2182b9a0 Mon Sep 17 00:00:00 2001 From: Alexander Melentyev Date: Mon, 21 Jun 2021 12:11:37 +0300 Subject: [PATCH 09/14] Delete spaces --- .github/ISSUE_TEMPLATE/diagnostics.md | 2 +- README.md | 2 +- RELEASES.md | 2 +- config.toml.example | 4 +-- .../html/static/FiraSans-LICENSE.txt | 4 +-- src/tools/clippy/CONTRIBUTING.md | 2 +- src/tools/clippy/README.md | 2 +- .../clippy/clippy_utils/src/ast_utils.rs | 2 +- src/tools/clippy/doc/basics.md | 4 +-- src/tools/clippy/lintcheck/README.md | 2 +- src/tools/clippy/util/gh-pages/index.html | 8 ++--- src/tools/rustfmt/CHANGELOG.md | 10 +++--- src/tools/rustfmt/Configurations.md | 32 +++++++++---------- src/tools/rustfmt/Contributing.md | 2 +- src/tools/rustfmt/Design.md | 4 +-- src/tools/rustfmt/README.md | 4 +-- src/tools/rustfmt/ci/integration.sh | 2 +- src/tools/rustfmt/docs/index.html | 8 ++--- 18 files changed, 48 insertions(+), 48 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/diagnostics.md b/.github/ISSUE_TEMPLATE/diagnostics.md index 044979f3baec3..a7b70cea927d0 100644 --- a/.github/ISSUE_TEMPLATE/diagnostics.md +++ b/.github/ISSUE_TEMPLATE/diagnostics.md @@ -9,7 +9,7 @@ along with any information you feel relevant to replicating the bug. If you cannot produce a minimal reproduction case (something that would work in isolation), please provide the steps or even link to a repository that causes -the problematic output to occur. +the problematic output to occur. --> Given the following code: diff --git a/README.md b/README.md index af6a4090a27cb..cf75f4184a1c9 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Read ["Installation"] from [The Book]. The Rust build system uses a Python script called `x.py` to build the compiler, which manages the bootstrapping process. It lives in the root of the project. -The `x.py` command can be run directly on most systems in the following format: +The `x.py` command can be run directly on most systems in the following format: ```sh ./x.py [flags] diff --git a/RELEASES.md b/RELEASES.md index 60b3359c1b68a..0a2fa738f9993 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -174,7 +174,7 @@ Language -------- - [You can now parameterize items such as functions, traits, and `struct`s by constant values in addition to by types and lifetimes.][79135] Also known as "const generics" - E.g. you can now write the following. Note: Only values of primitive integers, + E.g. you can now write the following. Note: Only values of primitive integers, `bool`, or `char` types are currently permitted. ```rust struct GenericArray { diff --git a/config.toml.example b/config.toml.example index 7fa5353d09b89..9a820f0803f0a 100644 --- a/config.toml.example +++ b/config.toml.example @@ -567,8 +567,8 @@ changelog-seen = 2 # On Linux target, if crt-static is not enabled, 'no' means dynamic link to # `libgcc_s.so`, 'in-tree' means static link to the in-tree build of llvm libunwind # and 'system' means dynamic link to `libunwind.so`. If crt-static is enabled, -# the behavior is depend on the libc. On musl target, 'no' and 'in-tree' both -# means static link to the in-tree build of llvm libunwind, and 'system' means +# the behavior is depend on the libc. On musl target, 'no' and 'in-tree' both +# means static link to the in-tree build of llvm libunwind, and 'system' means # static link to `libunwind.a` provided by system. Due to the limitation of glibc, # it must link to `libgcc_eh.a` to get a working output, and this option have no effect. #llvm-libunwind = 'no' diff --git a/src/librustdoc/html/static/FiraSans-LICENSE.txt b/src/librustdoc/html/static/FiraSans-LICENSE.txt index d444ea92b6f12..ff9afab064a28 100644 --- a/src/librustdoc/html/static/FiraSans-LICENSE.txt +++ b/src/librustdoc/html/static/FiraSans-LICENSE.txt @@ -1,5 +1,5 @@ Digitized data copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A. -with Reserved Font Name < Fira >, +with Reserved Font Name < Fira >, This Font Software is licensed under the SIL Open Font License, Version 1.1. This license is copied below, and is also available with a FAQ at: @@ -19,7 +19,7 @@ with others. The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, +fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The diff --git a/src/tools/clippy/CONTRIBUTING.md b/src/tools/clippy/CONTRIBUTING.md index 7265d1b832376..7d7b7c811738e 100644 --- a/src/tools/clippy/CONTRIBUTING.md +++ b/src/tools/clippy/CONTRIBUTING.md @@ -342,7 +342,7 @@ We have prioritization labels and a sync-blocker label, which are described belo - [P-low][p-low]: Requires attention (fix/response/evaluation) by a team member but isn't urgent. - [P-medium][p-medium]: Should be addressed by a team member until the next sync. - [P-high][p-high]: Should be immediately addressed and will require an out-of-cycle sync or a backport. -- [L-sync-blocker][l-sync-blocker]: An issue that "blocks" a sync. +- [L-sync-blocker][l-sync-blocker]: An issue that "blocks" a sync. Or rather: before the sync this should be addressed, e.g. by removing a lint again, so it doesn't hit beta/stable. diff --git a/src/tools/clippy/README.md b/src/tools/clippy/README.md index 6c556f579ca4f..bd322cc80702a 100644 --- a/src/tools/clippy/README.md +++ b/src/tools/clippy/README.md @@ -95,7 +95,7 @@ As with `cargo check`, this includes dependencies that are members of the worksp If you want to run Clippy **only** on the given crate, use the `--no-deps` option like this: ```terminal -cargo clippy -p example -- --no-deps +cargo clippy -p example -- --no-deps ``` ### As a rustc replacement (`clippy-driver`) diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index e6d84bc7560ba..90c034bd02a9e 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -178,7 +178,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool { (Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), (Struct(lse), Struct(rse)) => { - eq_maybe_qself(&lse.qself, &rse.qself) + eq_maybe_qself(&lse.qself, &rse.qself) && eq_path(&lse.path, &rse.path) && eq_struct_rest(&lse.rest, &rse.rest) && unordered_over(&lse.fields, &rse.fields, |l, r| eq_field(l, r)) diff --git a/src/tools/clippy/doc/basics.md b/src/tools/clippy/doc/basics.md index e2e307ce4f6cf..ed3a2fff83f16 100644 --- a/src/tools/clippy/doc/basics.md +++ b/src/tools/clippy/doc/basics.md @@ -96,9 +96,9 @@ cargo dev ide_setup ## lintcheck `cargo lintcheck` will build and run clippy on a fixed set of crates and generate a log of the results. -You can `git diff` the updated log against its previous version and +You can `git diff` the updated log against its previous version and see what impact your lint made on a small set of crates. -If you add a new lint, please audit the resulting warnings and make sure +If you add a new lint, please audit the resulting warnings and make sure there are no false positives and that the suggestions are valid. Refer to the tools [README] for more details. diff --git a/src/tools/clippy/lintcheck/README.md b/src/tools/clippy/lintcheck/README.md index 52bbcc0a8317d..a61070d8a80ef 100644 --- a/src/tools/clippy/lintcheck/README.md +++ b/src/tools/clippy/lintcheck/README.md @@ -73,5 +73,5 @@ You can run `./lintcheck/target/debug/lintcheck --fix` which will run Clippy wit print a warning if Clippys suggestions fail to apply (if the resulting code does not build). This lets us spot bad suggestions or false positives automatically in some cases. -Please note that the target dir should be cleaned afterwards since clippy will modify +Please note that the target dir should be cleaned afterwards since clippy will modify the downloaded sources which can lead to unexpected results when running lintcheck again afterwards. diff --git a/src/tools/clippy/util/gh-pages/index.html b/src/tools/clippy/util/gh-pages/index.html index 27ecb532dd00e..0174d3ffcbc2a 100644 --- a/src/tools/clippy/util/gh-pages/index.html +++ b/src/tools/clippy/util/gh-pages/index.html @@ -363,7 +363,7 @@

$scope.bySearch = function (lint, index, array) { let searchStr = $scope.search; - // It can be `null` I haven't missed this value + // It can be `null` I haven't missed this value if (searchStr == null || searchStr.length < 3) { return true; } @@ -375,7 +375,7 @@

} // Search the description - // The use of `for`-loops instead of `foreach` enables us to return early + // The use of `for`-loops instead of `foreach` enables us to return early let terms = searchStr.split(" "); for (index = 0; index < terms.length; index++) { if (lint.id.indexOf(terms[index]) !== -1) { @@ -463,7 +463,7 @@

let children = themeMenu.children; for (let index = 0; index < children.length; index++) { - let child = children[index]; + let child = children[index]; child.addEventListener("click", function(e) { setTheme(child.id, true); }); @@ -476,7 +476,7 @@

let enableHighlight = false; let enableNight = false; let enableAyu = false; - + if (theme == "ayu") { enableAyu = true; } else if (theme == "coal" || theme == "navy") { diff --git a/src/tools/rustfmt/CHANGELOG.md b/src/tools/rustfmt/CHANGELOG.md index 0f23663d6c2f9..68354b6ceaf25 100644 --- a/src/tools/rustfmt/CHANGELOG.md +++ b/src/tools/rustfmt/CHANGELOG.md @@ -176,7 +176,7 @@ https://rust-lang.github.io/rustfmt/?version=v1.4.33&search=#imports_granularity ### Changed -- Original comment indentation for trailing comments within an `if` is now taken into account when determining the indentation level to use for the trailing comment in formatted code. This does not modify any existing code formatted with rustfmt; it simply gives the programmer discretion to specify whether the comment is associated to the `else` block, or if the trailing comment is just a member of the `if` block. ([#1575](https://github.com/rust-lang/rustfmt/issues/1575), [#4120](https://github.com/rust-lang/rustfmt/issues/4120), [#4506](https://github.com/rust-lang/rustfmt/issues/4506)) +- Original comment indentation for trailing comments within an `if` is now taken into account when determining the indentation level to use for the trailing comment in formatted code. This does not modify any existing code formatted with rustfmt; it simply gives the programmer discretion to specify whether the comment is associated to the `else` block, or if the trailing comment is just a member of the `if` block. ([#1575](https://github.com/rust-lang/rustfmt/issues/1575), [#4120](https://github.com/rust-lang/rustfmt/issues/4120), [#4506](https://github.com/rust-lang/rustfmt/issues/4506)) In this example the `// else comment` refers to the `else`: ```rust @@ -213,7 +213,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels" ### Fixed - Formatting of empty blocks with attributes which only contained comments is no longer butchered.([#4475](https://github.com/rust-lang/rustfmt/issues/4475), [#4467](https://github.com/rust-lang/rustfmt/issues/4467), [#4452](https://github.com/rust-lang/rustfmt/issues/4452#issuecomment-705886282), [#4522](https://github.com/rust-lang/rustfmt/issues/4522)) -- Indentation of trailing comments in non-empty extern blocks is now correct. ([#4120](https://github.com/rust-lang/rustfmt/issues/4120#issuecomment-696491872)) +- Indentation of trailing comments in non-empty extern blocks is now correct. ([#4120](https://github.com/rust-lang/rustfmt/issues/4120#issuecomment-696491872)) ### Install/Download Options - **crates.io package** - *pending* @@ -297,7 +297,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels" - Fix aligning comments of different group - Fix flattening imports with a single `self`. - Fix removing attributes on function parameters. -- Fix removing `impl` keyword from opaque type. +- Fix removing `impl` keyword from opaque type. ## [1.4.8] 2019-09-08 @@ -329,7 +329,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels" - Add `--message-format` command line option to `cargo-fmt`. - Add `-l,--files-with-diff` command line option to `rustfmt`. -- Add `json` emit mode. +- Add `json` emit mode. ### Fixed @@ -380,7 +380,7 @@ if toks.eat_token(Token::Word("modify"))? && toks.eat_token(Token::Word("labels" ### Added -- Add new attribute `rustfmt::skip::attributes` to prevent rustfmt +- Add new attribute `rustfmt::skip::attributes` to prevent rustfmt from formatting an attribute #3665 ### Changed diff --git a/src/tools/rustfmt/Configurations.md b/src/tools/rustfmt/Configurations.md index 37cb7474130c8..9daa706537976 100644 --- a/src/tools/rustfmt/Configurations.md +++ b/src/tools/rustfmt/Configurations.md @@ -17,7 +17,7 @@ To enable unstable options, set `unstable_features = true` in `rustfmt.toml` or Below you find a detailed visual guide on all the supported configuration options of rustfmt: -## `array_width` +## `array_width` Maximum width of an array literal before falling back to vertical formatting. @@ -25,11 +25,11 @@ Maximum width of an array literal before falling back to vertical formatting. - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `array_width` will take precedence. +By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `array_width` will take precedence. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) -## `attr_fn_like_width` +## `attr_fn_like_width` Maximum width of the args of a function-like attributes before falling back to vertical formatting. @@ -37,7 +37,7 @@ Maximum width of the args of a function-like attributes before falling back to v - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `attr_fn_like_width` will take precedence. +By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `attr_fn_like_width` will take precedence. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -295,7 +295,7 @@ where } ``` -## `chain_width` +## `chain_width` Maximum width of a chain to fit on one line. @@ -303,7 +303,7 @@ Maximum width of a chain to fit on one line. - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `chain_width` will take precedence. +By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `chain_width` will take precedence. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -751,7 +751,7 @@ trait Lorem { } ``` -## `fn_call_width` +## `fn_call_width` Maximum width of the args of a function call before falling back to vertical formatting. @@ -759,7 +759,7 @@ Maximum width of the args of a function call before falling back to vertical for - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `fn_call_width` will take precedence. +By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `fn_call_width` will take precedence. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -2124,7 +2124,7 @@ Don't reformat out of line modules - **Possible values**: `true`, `false` - **Stable**: No (tracking issue: #3389) -## `single_line_if_else_max_width` +## `single_line_if_else_max_width` Maximum line length for single line if-else expressions. A value of `0` (zero) results in if-else expressions always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off`. @@ -2132,7 +2132,7 @@ Maximum line length for single line if-else expressions. A value of `0` (zero) r - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `single_line_if_else_max_width` will take precedence. +By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `single_line_if_else_max_width` will take precedence. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -2313,7 +2313,7 @@ fn main() { See also: [`indent_style`](#indent_style). -## `struct_lit_width` +## `struct_lit_width` Maximum width in the body of a struct literal before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off`. @@ -2321,11 +2321,11 @@ Maximum width in the body of a struct literal before falling back to vertical fo - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_lit_width` will take precedence. +By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_lit_width` will take precedence. See also [`max_width`](#max_width), [`use_small_heuristics`](#use_small_heuristics), and [`struct_lit_single_line`](#struct_lit_single_line) -## `struct_variant_width` +## `struct_variant_width` Maximum width in the body of a struct variant before falling back to vertical formatting. A value of `0` (zero) results in struct literals always being broken into multiple lines. Note this occurs when `use_small_heuristics` is set to `Off`. @@ -2333,7 +2333,7 @@ Maximum width in the body of a struct variant before falling back to vertical fo - **Possible values**: any positive integer that is less than or equal to the value specified for [`max_width`](#max_width) - **Stable**: Yes -By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_variant_width` will take precedence. +By default this option is set as a percentage of [`max_width`](#max_width) provided by [`use_small_heuristics`](#use_small_heuristics), but a value set directly for `struct_variant_width` will take precedence. See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) @@ -2530,7 +2530,7 @@ fn main() { This option can be used to simplify the management and bulk updates of the granular width configuration settings ([`fn_call_width`](#fn_call_width), [`attr_fn_like_width`](#attr_fn_like_width), [`struct_lit_width`](#struct_lit_width), [`struct_variant_width`](#struct_variant_width), [`array_width`](#array_width), [`chain_width`](#chain_width), [`single_line_if_else_max_width`](#single_line_if_else_max_width)), that respectively control when formatted constructs are multi-lined/vertical based on width. -Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`. +Note that explicitly provided values for the width configuration settings take precedence and override the calculated values determined by `use_small_heuristics`. - **Default value**: `"Default"` - **Possible values**: `"Default"`, `"Off"`, `"Max"` @@ -2595,7 +2595,7 @@ fn main() { ``` #### `Off`: -When `use_small_heuristics` is set to `Off`, the granular width settings are functionally disabled and ignored. See the documentation for the respective width config options for specifics. +When `use_small_heuristics` is set to `Off`, the granular width settings are functionally disabled and ignored. See the documentation for the respective width config options for specifics. ```rust enum Lorem { diff --git a/src/tools/rustfmt/Contributing.md b/src/tools/rustfmt/Contributing.md index 131f38dd06a2b..1b77dad11f0fe 100644 --- a/src/tools/rustfmt/Contributing.md +++ b/src/tools/rustfmt/Contributing.md @@ -38,7 +38,7 @@ colourised diff will be printed so that the offending line(s) can quickly be identified. Without explicit settings, the tests will be run using rustfmt's default -configuration. It is possible to run a test using non-default settings in several +configuration. It is possible to run a test using non-default settings in several ways. Firstly, you can include configuration parameters in comments at the top of the file. For example: to use 3 spaces per tab, start your test with `// rustfmt-tab_spaces: 3`. Just remember that the comment is part of the input, diff --git a/src/tools/rustfmt/Design.md b/src/tools/rustfmt/Design.md index 00a7652aee0dc..7a4dcf8773b61 100644 --- a/src/tools/rustfmt/Design.md +++ b/src/tools/rustfmt/Design.md @@ -150,8 +150,8 @@ for its configuration. Our visitor keeps track of the desired current indent due to blocks ( `block_indent`). Each `visit_*` method reformats code according to this indent, -`config.comment_width()` and `config.max_width()`. Most reformatting that is done -in the `visit_*` methods is a bit hacky and is meant to be temporary until it can +`config.comment_width()` and `config.max_width()`. Most reformatting that is done +in the `visit_*` methods is a bit hacky and is meant to be temporary until it can be done properly. There are a bunch of methods called `rewrite_*`. They do the bulk of the diff --git a/src/tools/rustfmt/README.md b/src/tools/rustfmt/README.md index 7a97d31bab9c7..500a9f9a37c8c 100644 --- a/src/tools/rustfmt/README.md +++ b/src/tools/rustfmt/README.md @@ -180,13 +180,13 @@ needs to be specified in `rustfmt.toml`, e.g., with `edition = "2018"`. * For things you do not want rustfmt to mangle, use `#[rustfmt::skip]` * To prevent rustfmt from formatting a macro or an attribute, - use `#[rustfmt::skip::macros(target_macro_name)]` or + use `#[rustfmt::skip::macros(target_macro_name)]` or `#[rustfmt::skip::attributes(target_attribute_name)]` Example: ```rust - #![rustfmt::skip::attributes(custom_attribute)] + #![rustfmt::skip::attributes(custom_attribute)] #[custom_attribute(formatting , here , should , be , Skipped)] #[rustfmt::skip::macros(html)] diff --git a/src/tools/rustfmt/ci/integration.sh b/src/tools/rustfmt/ci/integration.sh index 13a3ecaa1961c..0269e3ee4af93 100755 --- a/src/tools/rustfmt/ci/integration.sh +++ b/src/tools/rustfmt/ci/integration.sh @@ -15,7 +15,7 @@ set -ex # it again. # #which cargo-fmt || cargo install --force -CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force +CFG_RELEASE=nightly CFG_RELEASE_CHANNEL=nightly cargo install --path . --force echo "Integration tests for: ${INTEGRATION}" cargo fmt -- --version diff --git a/src/tools/rustfmt/docs/index.html b/src/tools/rustfmt/docs/index.html index 2a12da3881f05..56d1917e2b61b 100644 --- a/src/tools/rustfmt/docs/index.html +++ b/src/tools/rustfmt/docs/index.html @@ -85,7 +85,7 @@ outputHtml() { const ast = this.configurationDescriptions .filter(({ head, text, stable }) => { - + if ( text.includes(this.searchCondition) === false && head.includes(this.searchCondition) === false @@ -105,7 +105,7 @@ }, created: async function() { const res = await axios.get(ConfigurationMdUrl); - const { + const { about, configurationAbout, configurationDescriptions @@ -144,7 +144,7 @@ const lastIndex = stack.length - 1; stack[lastIndex].push(next); return stack; - }, + }, [[]]); }); } @@ -179,7 +179,7 @@ configurationAbout, ...configurationDescriptions ] = configurations; configurationAbout.value.links = {}; - + return { about, configurationAbout: configurationAbout.value, From 5fb27bca6cb88f1ad3cb7eac07c7e075b1a225f9 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 20 Jun 2021 08:39:54 +0800 Subject: [PATCH 10/14] Check for const_unstable before printing `const` --- src/librustdoc/html/format.rs | 26 +++++++++----- src/librustdoc/html/render/mod.rs | 30 +++++++++------- src/librustdoc/html/render/print_item.rs | 45 ++++++++++++++---------- src/test/rustdoc/const-display.rs | 8 ++--- 4 files changed, 65 insertions(+), 44 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 918a5cb509430..488d5a583943d 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -9,6 +9,7 @@ use std::cell::Cell; use std::fmt; use std::iter; +use rustc_attr::{ConstStability, StabilityLevel}; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; @@ -1253,15 +1254,6 @@ impl PrintWithSpace for hir::Unsafety { } } -impl PrintWithSpace for hir::Constness { - fn print_with_space(&self) -> &str { - match self { - hir::Constness::Const => "const ", - hir::Constness::NotConst => "", - } - } -} - impl PrintWithSpace for hir::IsAsync { fn print_with_space(&self) -> &str { match self { @@ -1280,6 +1272,22 @@ impl PrintWithSpace for hir::Mutability { } } +crate fn print_constness_with_space( + c: &hir::Constness, + s: Option<&ConstStability>, +) -> &'static str { + match (c, s) { + // const stable or no stability attribute + ( + hir::Constness::Const, + Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }), + ) + | (hir::Constness::Const, None) => "const ", + // const unstable or not const + (hir::Constness::Const, _) | (hir::Constness::NotConst, _) => "", + } +} + impl clean::Import { crate fn print<'a, 'tcx: 'a>( &'a self, diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 16df17372b011..03b607c2d2cb7 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -61,8 +61,8 @@ use crate::formats::item_type::ItemType; use crate::formats::{AssocItemRender, Impl, RenderMode}; use crate::html::escape::Escape; use crate::html::format::{ - href, print_abi_with_space, print_default_space, print_generic_bounds, print_where_clause, - Buffer, PrintWithSpace, + href, print_abi_with_space, print_constness_with_space, print_default_space, + print_generic_bounds, print_where_clause, Buffer, PrintWithSpace, }; use crate::html::markdown::{Markdown, MarkdownHtml, MarkdownSummaryLine}; @@ -833,16 +833,17 @@ fn render_stability_since_raw( let ver = ver.filter(|inner| !inner.is_empty()); match (ver, const_stability) { + // stable and const stable (Some(v), Some(ConstStability { level: StabilityLevel::Stable { since }, .. })) if Some(since.as_str()).as_deref() != containing_const_ver => { write!( w, "{0} (const: {1})", - v, - since.as_str() + v, since ); } + // stable and const unstable ( Some(v), Some(ConstStability { level: StabilityLevel::Unstable { issue, .. }, feature, .. }), @@ -863,6 +864,7 @@ fn render_stability_since_raw( } write!(w, ")"); } + // stable (Some(v), _) if ver != containing_ver => { write!( w, @@ -910,11 +912,13 @@ fn render_assoc_item( } }; let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string(); - let constness = header.constness.print_with_space(); + let constness = + print_constness_with_space(&header.constness, meth.const_stability(cx.tcx())); let asyncness = header.asyncness.print_with_space(); let unsafety = header.unsafety.print_with_space(); let defaultness = print_default_space(meth.is_default()); let abi = print_abi_with_space(header.abi).to_string(); + // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`. let generics_len = format!("{:#}", g.print(cx)).len(); let mut header_len = "fn ".len() @@ -939,15 +943,15 @@ fn render_assoc_item( w.reserve(header_len + "{".len() + "".len()); write!( w, - "{}{}{}{}{}{}{}fn {name}\ + "{indent}{vis}{constness}{asyncness}{unsafety}{defaultness}{abi}fn {name}\ {generics}{decl}{notable_traits}{where_clause}", - indent_str, - vis, - constness, - asyncness, - unsafety, - defaultness, - abi, + indent = indent_str, + vis = vis, + constness = constness, + asyncness = asyncness, + unsafety = unsafety, + defaultness = defaultness, + abi = abi, href = href, name = name, generics = g.print(cx), diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 1340040fa8f06..0174bfec32d7e 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -22,7 +22,9 @@ use crate::clean::{self, GetDefId}; use crate::formats::item_type::ItemType; use crate::formats::{AssocItemRender, Impl, RenderMode}; use crate::html::escape::Escape; -use crate::html::format::{print_abi_with_space, print_where_clause, Buffer, PrintWithSpace}; +use crate::html::format::{ + print_abi_with_space, print_constness_with_space, print_where_clause, Buffer, PrintWithSpace, +}; use crate::html::highlight; use crate::html::layout::Page; use crate::html::markdown::MarkdownSummaryLine; @@ -430,29 +432,36 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) -> } fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) { - let header_len = format!( - "{}{}{}{}{:#}fn {}{:#}", - it.visibility.print_with_space(it.def_id, cx), - f.header.constness.print_with_space(), - f.header.asyncness.print_with_space(), - f.header.unsafety.print_with_space(), - print_abi_with_space(f.header.abi), - it.name.as_ref().unwrap(), - f.generics.print(cx), - ) - .len(); + let vis = it.visibility.print_with_space(it.def_id, cx).to_string(); + let constness = print_constness_with_space(&f.header.constness, it.const_stability(cx.tcx())); + let asyncness = f.header.asyncness.print_with_space(); + let unsafety = f.header.unsafety.print_with_space(); + let abi = print_abi_with_space(f.header.abi).to_string(); + let name = it.name.as_ref().unwrap(); + + let generics_len = format!("{:#}", f.generics.print(cx)).len(); + let header_len = "fn ".len() + + vis.len() + + constness.len() + + asyncness.len() + + unsafety.len() + + abi.len() + + name.as_str().len() + + generics_len; + w.write_str("
");
     render_attributes_in_pre(w, it, "");
+    w.reserve(header_len);
     write!(
         w,
         "{vis}{constness}{asyncness}{unsafety}{abi}fn \
          {name}{generics}{decl}{notable_traits}{where_clause}
", - vis = it.visibility.print_with_space(it.def_id, cx), - constness = f.header.constness.print_with_space(), - asyncness = f.header.asyncness.print_with_space(), - unsafety = f.header.unsafety.print_with_space(), - abi = print_abi_with_space(f.header.abi), - name = it.name.as_ref().unwrap(), + vis = vis, + constness = constness, + asyncness = asyncness, + unsafety = unsafety, + abi = abi, + name = name, generics = f.generics.print(cx), where_clause = print_where_clause(&f.generics, cx, 0, true), decl = f.decl.full_print(header_len, 0, f.header.asyncness, cx), diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs index 41a511f716581..fd7ff1c11c01c 100644 --- a/src/test/rustdoc/const-display.rs +++ b/src/test/rustdoc/const-display.rs @@ -7,11 +7,11 @@ #![feature(foo, foo2)] #![feature(staged_api)] -// @has 'foo/fn.foo.html' '//pre' 'pub unsafe fn foo() -> u32' +// @has 'foo/fn.foo.html' '//pre' 'pub fn foo() -> u32' // @has - '//span[@class="since"]' '1.0.0 (const: unstable)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature="foo", issue = "none")] -pub const unsafe fn foo() -> u32 { 42 } +pub const fn foo() -> u32 { 42 } // @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32' #[unstable(feature = "humans", issue = "none")] @@ -39,11 +39,11 @@ pub const unsafe fn bar_not_gated() -> u32 { 42 } pub struct Foo; impl Foo { - // @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/code' 'pub unsafe fn gated() -> u32' + // @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/code' 'pub fn gated() -> u32' // @has - '//span[@class="since"]' '1.0.0 (const: unstable)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature="foo", issue = "none")] - pub const unsafe fn gated() -> u32 { 42 } + pub const fn gated() -> u32 { 42 } // @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl"]/code' 'pub const fn stable_impl() -> u32' // @has - '//span[@class="since"]' '1.0.0 (const: 1.2.0)' From c4396f476e65ad6d687df414e74b94d1caaacb2b Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 21 Jun 2021 19:17:07 +0800 Subject: [PATCH 11/14] Added some tests for `unsafe` in const-dispay.rs --- src/test/rustdoc/const-display.rs | 53 +++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs index fd7ff1c11c01c..e98d82b7bf430 100644 --- a/src/test/rustdoc/const-display.rs +++ b/src/test/rustdoc/const-display.rs @@ -13,28 +13,57 @@ #[rustc_const_unstable(feature="foo", issue = "none")] pub const fn foo() -> u32 { 42 } +// @has 'foo/fn.foo_unsafe.html' '//pre' 'pub unsafe fn foo_unsafe() -> u32' +// @has - '//span[@class="since"]' '1.0.0 (const: unstable)' +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature="foo", issue = "none")] +pub const unsafe fn foo_unsafe() -> u32 { 42 } + // @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32' #[unstable(feature = "humans", issue = "none")] pub const fn foo2() -> u32 { 42 } +// @has 'foo/fn.foo2_unsafe.html' '//pre' 'pub const unsafe fn foo2_unsafe() -> u32' +#[unstable(feature = "humans", issue = "none")] +pub const unsafe fn foo2_unsafe() -> u32 { 42 } + // @has 'foo/fn.bar2.html' '//pre' 'pub const fn bar2() -> u32' // @has - //span '1.0.0 (const: 1.0.0)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.0.0")] pub const fn bar2() -> u32 { 42 } -// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const unsafe fn foo2_gated() -> u32' +// @has 'foo/fn.bar2_unsafe.html' '//pre' 'pub const unsafe fn bar2_unsafe() -> u32' +// @has - //span '1.0.0 (const: 1.0.0)' +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] +pub const unsafe fn bar2_unsafe() -> u32 { 42 } + +// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const fn foo2_gated() -> u32' #[unstable(feature = "foo2", issue = "none")] -pub const unsafe fn foo2_gated() -> u32 { 42 } +pub const fn foo2_gated() -> u32 { 42 } -// @has 'foo/fn.bar2_gated.html' '//pre' 'pub const unsafe fn bar2_gated() -> u32' +// @has 'foo/fn.foo2_gated_unsafe.html' '//pre' 'pub const unsafe fn foo2_gated_unsafe() -> u32' +#[unstable(feature = "foo2", issue = "none")] +pub const unsafe fn foo2_gated_unsafe() -> u32 { 42 } + +// @has 'foo/fn.bar2_gated.html' '//pre' 'pub const fn bar2_gated() -> u32' // @has - '//span[@class="since"]' '1.0.0 (const: 1.0.0)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.0.0")] -pub const unsafe fn bar2_gated() -> u32 { 42 } +pub const fn bar2_gated() -> u32 { 42 } -// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const unsafe fn bar_not_gated() -> u32' -pub const unsafe fn bar_not_gated() -> u32 { 42 } +// @has 'foo/fn.bar2_gated_unsafe.html' '//pre' 'pub const unsafe fn bar2_gated_unsafe() -> u32' +// @has - '//span[@class="since"]' '1.0.0 (const: 1.0.0)' +#[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_stable(feature = "rust1", since = "1.0.0")] +pub const unsafe fn bar2_gated_unsafe() -> u32 { 42 } + +// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const fn bar_not_gated() -> u32' +pub const fn bar_not_gated() -> u32 { 42 } + +// @has 'foo/fn.bar_not_gated_unsafe.html' '//pre' 'pub const unsafe fn bar_not_gated_unsafe() -> u32' +pub const unsafe fn bar_not_gated_unsafe() -> u32 { 42 } pub struct Foo; @@ -45,9 +74,21 @@ impl Foo { #[rustc_const_unstable(feature="foo", issue = "none")] pub const fn gated() -> u32 { 42 } + // @has 'foo/struct.Foo.html' '//div[@id="method.gated_unsafe"]/code' 'pub unsafe fn gated_unsafe() -> u32' + // @has - '//span[@class="since"]' '1.0.0 (const: unstable)' + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature="foo", issue = "none")] + pub const unsafe fn gated_unsafe() -> u32 { 42 } + // @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl"]/code' 'pub const fn stable_impl() -> u32' // @has - '//span[@class="since"]' '1.0.0 (const: 1.2.0)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.2.0")] pub const fn stable_impl() -> u32 { 42 } + + // @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl_unsafe"]/code' 'pub const unsafe fn stable_impl_unsafe() -> u32' + // @has - '//span[@class="since"]' '1.0.0 (const: 1.2.0)' + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "rust1", since = "1.2.0")] + pub const unsafe fn stable_impl_unsafe() -> u32 { 42 } } From 0d69a02c31f781568ce11c877b2add7b5deea1b9 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 21 Jun 2021 20:15:27 +0800 Subject: [PATCH 12/14] Removed/Updated some cases and simplified `match` --- src/librustdoc/html/format.rs | 2 +- src/test/rustdoc/const-display.rs | 31 +++---------------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 488d5a583943d..11d40d9898c08 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1284,7 +1284,7 @@ crate fn print_constness_with_space( ) | (hir::Constness::Const, None) => "const ", // const unstable or not const - (hir::Constness::Const, _) | (hir::Constness::NotConst, _) => "", + _ => "", } } diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs index e98d82b7bf430..33b65bb596fd5 100644 --- a/src/test/rustdoc/const-display.rs +++ b/src/test/rustdoc/const-display.rs @@ -20,51 +20,32 @@ pub const fn foo() -> u32 { 42 } pub const unsafe fn foo_unsafe() -> u32 { 42 } // @has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32' +// @!has - '//span[@class="since"]' #[unstable(feature = "humans", issue = "none")] pub const fn foo2() -> u32 { 42 } -// @has 'foo/fn.foo2_unsafe.html' '//pre' 'pub const unsafe fn foo2_unsafe() -> u32' -#[unstable(feature = "humans", issue = "none")] -pub const unsafe fn foo2_unsafe() -> u32 { 42 } - // @has 'foo/fn.bar2.html' '//pre' 'pub const fn bar2() -> u32' // @has - //span '1.0.0 (const: 1.0.0)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.0.0")] pub const fn bar2() -> u32 { 42 } -// @has 'foo/fn.bar2_unsafe.html' '//pre' 'pub const unsafe fn bar2_unsafe() -> u32' -// @has - //span '1.0.0 (const: 1.0.0)' -#[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_stable(feature = "rust1", since = "1.0.0")] -pub const unsafe fn bar2_unsafe() -> u32 { 42 } // @has 'foo/fn.foo2_gated.html' '//pre' 'pub const fn foo2_gated() -> u32' +// @!has - '//span[@class="since"]' #[unstable(feature = "foo2", issue = "none")] pub const fn foo2_gated() -> u32 { 42 } -// @has 'foo/fn.foo2_gated_unsafe.html' '//pre' 'pub const unsafe fn foo2_gated_unsafe() -> u32' -#[unstable(feature = "foo2", issue = "none")] -pub const unsafe fn foo2_gated_unsafe() -> u32 { 42 } - // @has 'foo/fn.bar2_gated.html' '//pre' 'pub const fn bar2_gated() -> u32' // @has - '//span[@class="since"]' '1.0.0 (const: 1.0.0)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.0.0")] pub const fn bar2_gated() -> u32 { 42 } -// @has 'foo/fn.bar2_gated_unsafe.html' '//pre' 'pub const unsafe fn bar2_gated_unsafe() -> u32' -// @has - '//span[@class="since"]' '1.0.0 (const: 1.0.0)' -#[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_stable(feature = "rust1", since = "1.0.0")] -pub const unsafe fn bar2_gated_unsafe() -> u32 { 42 } - // @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const fn bar_not_gated() -> u32' +// @!has - '//span[@class="since"]' pub const fn bar_not_gated() -> u32 { 42 } -// @has 'foo/fn.bar_not_gated_unsafe.html' '//pre' 'pub const unsafe fn bar_not_gated_unsafe() -> u32' -pub const unsafe fn bar_not_gated_unsafe() -> u32 { 42 } - pub struct Foo; impl Foo { @@ -85,10 +66,4 @@ impl Foo { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.2.0")] pub const fn stable_impl() -> u32 { 42 } - - // @has 'foo/struct.Foo.html' '//div[@id="method.stable_impl_unsafe"]/code' 'pub const unsafe fn stable_impl_unsafe() -> u32' - // @has - '//span[@class="since"]' '1.0.0 (const: 1.2.0)' - #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "rust1", since = "1.2.0")] - pub const unsafe fn stable_impl_unsafe() -> u32 { 42 } } From f82fb308af00567f80d0cbb23361a7fa8327d5df Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 21 Jun 2021 20:21:37 +0800 Subject: [PATCH 13/14] Update comment regarding staged_api --- src/librustdoc/html/format.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 11d40d9898c08..58c609cf252cf 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -1277,7 +1277,7 @@ crate fn print_constness_with_space( s: Option<&ConstStability>, ) -> &'static str { match (c, s) { - // const stable or no stability attribute + // const stable or when feature(staged_api) is not set ( hir::Constness::Const, Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }), From b57077bbf02c463308359330444cf219d3f04d17 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 21 Jun 2021 20:42:57 +0800 Subject: [PATCH 14/14] Readd `unsafe` keyword in tests --- src/test/rustdoc/const-display.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs index 33b65bb596fd5..8c995b9426bbb 100644 --- a/src/test/rustdoc/const-display.rs +++ b/src/test/rustdoc/const-display.rs @@ -31,20 +31,20 @@ pub const fn foo2() -> u32 { 42 } pub const fn bar2() -> u32 { 42 } -// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const fn foo2_gated() -> u32' +// @has 'foo/fn.foo2_gated.html' '//pre' 'pub const unsafe fn foo2_gated() -> u32' // @!has - '//span[@class="since"]' #[unstable(feature = "foo2", issue = "none")] -pub const fn foo2_gated() -> u32 { 42 } +pub const unsafe fn foo2_gated() -> u32 { 42 } -// @has 'foo/fn.bar2_gated.html' '//pre' 'pub const fn bar2_gated() -> u32' +// @has 'foo/fn.bar2_gated.html' '//pre' 'pub const unsafe fn bar2_gated() -> u32' // @has - '//span[@class="since"]' '1.0.0 (const: 1.0.0)' #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rust1", since = "1.0.0")] -pub const fn bar2_gated() -> u32 { 42 } +pub const unsafe fn bar2_gated() -> u32 { 42 } -// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const fn bar_not_gated() -> u32' +// @has 'foo/fn.bar_not_gated.html' '//pre' 'pub const unsafe fn bar_not_gated() -> u32' // @!has - '//span[@class="since"]' -pub const fn bar_not_gated() -> u32 { 42 } +pub const unsafe fn bar_not_gated() -> u32 { 42 } pub struct Foo;