From 1ac727772bd91b6e35b624e3252e6a6bd681c70b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 6 Dec 2018 22:47:09 +0100 Subject: [PATCH 01/41] Remove rustdoc old style files generation --- src/librustdoc/html/render.rs | 22 +--------------------- src/test/rustdoc/issue-19190.rs | 3 --- src/test/rustdoc/issue-21092.rs | 1 - src/test/rustdoc/issue-35169-2.rs | 8 -------- src/test/rustdoc/issue-35169.rs | 8 -------- src/test/rustdoc/macros.rs | 2 -- src/test/rustdoc/old-style-files.rs | 23 +++++++++++++++++++++++ src/test/rustdoc/src-links.rs | 2 -- src/test/rustdoc/structfields.rs | 5 ----- 9 files changed, 24 insertions(+), 50 deletions(-) create mode 100644 src/test/rustdoc/old-style-files.rs diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 86fb51419c270..4f237dc85a5ee 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -33,7 +33,7 @@ use std::default::Default; use std::error; use std::fmt::{self, Display, Formatter, Write as FmtWrite}; use std::ffi::OsStr; -use std::fs::{self, File, OpenOptions}; +use std::fs::{self, File}; use std::io::prelude::*; use std::io::{self, BufWriter, BufReader}; use std::mem; @@ -2229,26 +2229,6 @@ impl Context { if !self.render_redirect_pages { all.append(full_path(self, &item), &item_type); } - // Redirect from a sane URL using the namespace to Rustdoc's - // URL for the page. - let redir_name = format!("{}.{}.html", name, item_type.name_space()); - let redir_dst = self.dst.join(redir_name); - if let Ok(redirect_out) = OpenOptions::new().create_new(true) - .write(true) - .open(&redir_dst) { - let mut redirect_out = BufWriter::new(redirect_out); - try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); - } - - // If the item is a macro, redirect from the old macro URL (with !) - // to the new one (without). - if item_type == ItemType::Macro { - let redir_name = format!("{}.{}!.html", item_type, name); - let redir_dst = self.dst.join(redir_name); - let redirect_out = try_err!(File::create(&redir_dst), &redir_dst); - let mut redirect_out = BufWriter::new(redirect_out); - try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); - } } } Ok(()) diff --git a/src/test/rustdoc/issue-19190.rs b/src/test/rustdoc/issue-19190.rs index a7c25538f7c44..4d3b76229702b 100644 --- a/src/test/rustdoc/issue-19190.rs +++ b/src/test/rustdoc/issue-19190.rs @@ -13,9 +13,6 @@ impl Deref for Bar { fn deref(&self) -> &Foo { loop {} } } -// @has issue_19190/Bar.t.html // @has issue_19190/struct.Bar.html -// @has - '//*[@id="foo.v"]' 'fn foo(&self)' // @has - '//*[@id="method.foo"]' 'fn foo(&self)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-21092.rs b/src/test/rustdoc/issue-21092.rs index 14f547abd9a68..b054145a4831a 100644 --- a/src/test/rustdoc/issue-21092.rs +++ b/src/test/rustdoc/issue-21092.rs @@ -3,7 +3,6 @@ extern crate issue_21092; -// @has issue_21092/Bar.t.html // @has issue_21092/struct.Bar.html // @has - '//*[@id="associatedtype.Bar"]' 'type Bar = i32' pub use issue_21092::{Foo, Bar}; diff --git a/src/test/rustdoc/issue-35169-2.rs b/src/test/rustdoc/issue-35169-2.rs index 0caead100d666..7dea268ec0258 100644 --- a/src/test/rustdoc/issue-35169-2.rs +++ b/src/test/rustdoc/issue-35169-2.rs @@ -23,19 +23,11 @@ impl DerefMut for Bar { fn deref_mut(&mut self) -> &mut Foo { loop {} } } -// @has issue_35169_2/Bar.t.html // @has issue_35169_2/struct.Bar.html -// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' -// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' -// @has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' // @has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' -// @has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' // @has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' -// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' -// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-35169.rs b/src/test/rustdoc/issue-35169.rs index 0978b103076fe..883d5d0158d7e 100644 --- a/src/test/rustdoc/issue-35169.rs +++ b/src/test/rustdoc/issue-35169.rs @@ -18,19 +18,11 @@ impl Deref for Bar { fn deref(&self) -> &Foo { loop {} } } -// @has issue_35169/Bar.t.html // @has issue_35169/struct.Bar.html -// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' -// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' -// @!has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' // @!has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' -// @!has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' // @!has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' -// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' -// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' -// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/macros.rs b/src/test/rustdoc/macros.rs index c66a2c845bfd8..fb4f02ad16052 100644 --- a/src/test/rustdoc/macros.rs +++ b/src/test/rustdoc/macros.rs @@ -2,8 +2,6 @@ // @has - //pre '() => { ... };' // @has - //pre '($a:tt) => { ... };' // @has - //pre '($e:expr) => { ... };' -// @has macros/macro.my_macro!.html -// @has - //a 'macro.my_macro.html' #[macro_export] macro_rules! my_macro { () => []; diff --git a/src/test/rustdoc/old-style-files.rs b/src/test/rustdoc/old-style-files.rs new file mode 100644 index 0000000000000..fb6697e18fbc4 --- /dev/null +++ b/src/test/rustdoc/old-style-files.rs @@ -0,0 +1,23 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_name = "foo"] + +// @has foo/macro.bar.html +// @!has foo/macro.bar!.html +// @!has foo/bar.m.html +#[macro_export] +macro_rules! bar { + () => {} +} + +// @has foo/struct.Bar.html +// @!has foo/Bar.t.html +pub struct Bar; diff --git a/src/test/rustdoc/src-links.rs b/src/test/rustdoc/src-links.rs index 902a319a7b906..353ce10243e00 100644 --- a/src/test/rustdoc/src-links.rs +++ b/src/test/rustdoc/src-links.rs @@ -14,13 +14,11 @@ pub mod bar { // @has foo/bar/baz/index.html '//a/@href' '../../../src/foo/src-links.rs.html' pub mod baz { /// Dox - // @has foo/bar/baz/baz.v.html // @has foo/bar/baz/fn.baz.html '//a/@href' '../../../src/foo/src-links.rs.html' pub fn baz() { } } /// Dox - // @has foo/bar/Foobar.t.html // @has foo/bar/trait.Foobar.html '//a/@href' '../../src/foo/src-links.rs.html' pub trait Foobar { fn dummy(&self) { } } diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index 35cea8afe2146..cd8957aa2ecb9 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -1,6 +1,5 @@ // @has structfields/Foo.t.html // @has - struct.Foo.html -// @has structfields/struct.Foo.html pub struct Foo { // @has - //pre "pub a: ()" pub a: (), @@ -14,8 +13,6 @@ pub struct Foo { pub d: usize, } -// @has structfields/Bar.t.html -// @has - struct.Bar.html // @has structfields/struct.Bar.html pub struct Bar { // @has - //pre "pub a: ()" @@ -23,8 +20,6 @@ pub struct Bar { // @!has - //pre "// some fields omitted" } -// @has structfields/Qux.t.html -// @has - enum.Qux.html // @has structfields/enum.Qux.html pub enum Qux { Quz { From 270151bffb0be259ff20feee3801bb124c2c39ec Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 12 Dec 2018 00:33:00 +0100 Subject: [PATCH 02/41] Add generate-old-style-files option to rustdoc --- src/bootstrap/doc.rs | 4 +++- src/librustdoc/config.rs | 4 ++++ src/librustdoc/html/render.rs | 27 ++++++++++++++++++++++++++- src/librustdoc/lib.rs | 5 +++++ src/test/rustdoc/issue-19190.rs | 5 +++++ src/test/rustdoc/issue-35169-2.rs | 7 +++++++ src/test/rustdoc/issue-35169.rs | 7 +++++++ src/test/rustdoc/old-style-files.rs | 23 ----------------------- src/test/rustdoc/structfields.rs | 7 +++++++ src/test/rustdoc/without-redirect.rs | 13 +++++++++++++ 10 files changed, 77 insertions(+), 25 deletions(-) delete mode 100644 src/test/rustdoc/old-style-files.rs create mode 100644 src/test/rustdoc/without-redirect.rs diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index eec193c21f5db..0028997a7df09 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -317,7 +317,8 @@ fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned Vec { "Directory to persist doctest executables into", "PATH") }), + stable("generate-redirect-pages", |o| { + o.optflag("", + "generate-redirect-pages", + "Generate extra pages to support legacy URLs and tool links") + }), ] } diff --git a/src/test/rustdoc/issue-19190.rs b/src/test/rustdoc/issue-19190.rs index 4d3b76229702b..e023e79fcde6b 100644 --- a/src/test/rustdoc/issue-19190.rs +++ b/src/test/rustdoc/issue-19190.rs @@ -1,3 +1,5 @@ +// compile-flags:--generate-redirect-pages + use std::ops::Deref; pub struct Foo; @@ -13,6 +15,9 @@ impl Deref for Bar { fn deref(&self) -> &Foo { loop {} } } +// @has issue_19190/Bar.t.html // @has issue_19190/struct.Bar.html +// @has - '//*[@id="foo.v"]' 'fn foo(&self)' // @has - '//*[@id="method.foo"]' 'fn foo(&self)' +// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-35169-2.rs b/src/test/rustdoc/issue-35169-2.rs index 7dea268ec0258..33f7646ced68b 100644 --- a/src/test/rustdoc/issue-35169-2.rs +++ b/src/test/rustdoc/issue-35169-2.rs @@ -24,10 +24,17 @@ impl DerefMut for Bar { } // @has issue_35169_2/struct.Bar.html +// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' +// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' +// @has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' // @has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' +// @has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' // @has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' +// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' +// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' +// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/issue-35169.rs b/src/test/rustdoc/issue-35169.rs index 883d5d0158d7e..04fffc40572a6 100644 --- a/src/test/rustdoc/issue-35169.rs +++ b/src/test/rustdoc/issue-35169.rs @@ -19,10 +19,17 @@ impl Deref for Bar { } // @has issue_35169/struct.Bar.html +// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)' // @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)' +// @has - '//*[@id="by_explicit_ref.v"]' 'fn by_explicit_ref(self: &Foo)' // @has - '//*[@id="method.by_explicit_ref"]' 'fn by_explicit_ref(self: &Foo)' +// @!has - '//*[@id="by_mut_ref.v"]' 'fn by_mut_ref(&mut self)' // @!has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)' +// @!has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)' // @!has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)' +// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box)' // @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box)' +// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box)' // @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box)' +// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()' // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()' diff --git a/src/test/rustdoc/old-style-files.rs b/src/test/rustdoc/old-style-files.rs deleted file mode 100644 index fb6697e18fbc4..0000000000000 --- a/src/test/rustdoc/old-style-files.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![crate_name = "foo"] - -// @has foo/macro.bar.html -// @!has foo/macro.bar!.html -// @!has foo/bar.m.html -#[macro_export] -macro_rules! bar { - () => {} -} - -// @has foo/struct.Bar.html -// @!has foo/Bar.t.html -pub struct Bar; diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index cd8957aa2ecb9..bfe116acffc1e 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -1,5 +1,8 @@ +// compile-flags:--generate-redirect-pages + // @has structfields/Foo.t.html // @has - struct.Foo.html +// @has structfields/struct.Foo.html pub struct Foo { // @has - //pre "pub a: ()" pub a: (), @@ -13,6 +16,8 @@ pub struct Foo { pub d: usize, } +// @has structfields/Bar.t.html +// @has - struct.Bar.html // @has structfields/struct.Bar.html pub struct Bar { // @has - //pre "pub a: ()" @@ -20,6 +25,8 @@ pub struct Bar { // @!has - //pre "// some fields omitted" } +// @has structfields/Qux.t.html +// @has - enum.Qux.html // @has structfields/enum.Qux.html pub enum Qux { Quz { diff --git a/src/test/rustdoc/without-redirect.rs b/src/test/rustdoc/without-redirect.rs new file mode 100644 index 0000000000000..d473dd8f428d2 --- /dev/null +++ b/src/test/rustdoc/without-redirect.rs @@ -0,0 +1,13 @@ +#![crate_name = "foo"] + +// @has foo/macro.bar.html +// @!has foo/macro.bar!.html +// @!has foo/bar.m.html +#[macro_export] +macro_rules! bar { + () => {} +} + +// @has foo/struct.Bar.html +// @!has foo/Bar.t.html +pub struct Bar; From 65440a3f4fe42acbe9970638b567ee3fa68d4824 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 27 Jan 2019 00:44:33 +0100 Subject: [PATCH 03/41] Make 'generate-redirect-pages' option unstable --- src/librustdoc/lib.rs | 2 +- src/test/rustdoc/issue-19190.rs | 2 +- src/test/rustdoc/structfields.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 290f958640430..4e0302b0224fe 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -348,7 +348,7 @@ fn opts() -> Vec { "Directory to persist doctest executables into", "PATH") }), - stable("generate-redirect-pages", |o| { + unstable("generate-redirect-pages", |o| { o.optflag("", "generate-redirect-pages", "Generate extra pages to support legacy URLs and tool links") diff --git a/src/test/rustdoc/issue-19190.rs b/src/test/rustdoc/issue-19190.rs index e023e79fcde6b..c6bac51c5740d 100644 --- a/src/test/rustdoc/issue-19190.rs +++ b/src/test/rustdoc/issue-19190.rs @@ -1,4 +1,4 @@ -// compile-flags:--generate-redirect-pages +// compile-flags:-Z unstable-options --generate-redirect-pages use std::ops::Deref; diff --git a/src/test/rustdoc/structfields.rs b/src/test/rustdoc/structfields.rs index bfe116acffc1e..235f0e852da2c 100644 --- a/src/test/rustdoc/structfields.rs +++ b/src/test/rustdoc/structfields.rs @@ -1,4 +1,4 @@ -// compile-flags:--generate-redirect-pages +// compile-flags:-Z unstable-options --generate-redirect-pages // @has structfields/Foo.t.html // @has - struct.Foo.html From e6d5f251f11f4ac74f23748b665a29f0ceddfdda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Wed, 30 Jan 2019 00:50:27 +0100 Subject: [PATCH 04/41] Fix #57730 --- src/librustc_passes/ast_validation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 3deb2ff8d8a0b..bad1367a89af4 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -519,7 +519,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if let Some(ref type_) = data.output { // `-> Foo` syntax is essentially an associated type binding, // so it is also allowed to contain nested `impl Trait`. - self.with_impl_trait(None, |this| visit::walk_ty(this, type_)); + self.with_impl_trait(None, |this| this.visit_ty(type_)); } } } From 397eb4f237b92f77eadf12c0bea7cfea5a31a92a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 30 Jan 2019 11:39:19 +0100 Subject: [PATCH 05/41] Add missing generation for test and proc_macro, remove old macro redirection --- src/bootstrap/bin/rustdoc.rs | 20 +++++++++++++++++--- src/bootstrap/doc.rs | 11 ++++++----- src/librustdoc/html/render.rs | 9 --------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/bootstrap/bin/rustdoc.rs b/src/bootstrap/bin/rustdoc.rs index dec74e60c71f3..aeb15821b0bb7 100644 --- a/src/bootstrap/bin/rustdoc.rs +++ b/src/bootstrap/bin/rustdoc.rs @@ -16,6 +16,7 @@ fn main() { let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set"); let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set"); let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set"); + let mut has_unstable = false; use std::str::FromStr; @@ -54,9 +55,22 @@ fn main() { // it up so we can make rustdoc print this into the docs if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") { // This "unstable-options" can be removed when `--crate-version` is stabilized - cmd.arg("-Z") - .arg("unstable-options") - .arg("--crate-version").arg(version); + if !has_unstable { + cmd.arg("-Z") + .arg("unstable-options"); + } + cmd.arg("--crate-version").arg(version); + has_unstable = true; + } + + // Needed to be able to run all rustdoc tests. + if let Some(_) = env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES") { + // This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized + if !has_unstable { + cmd.arg("-Z") + .arg("unstable-options"); + } + cmd.arg("--generate-redirect-pages"); } if verbose > 1 { diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 0028997a7df09..af95b622e23f3 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -317,8 +317,7 @@ fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned Date: Fri, 1 Feb 2019 12:08:50 -0500 Subject: [PATCH 06/41] add regression test for #57979 --- src/test/ui/issues/issue-57979.rs | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/ui/issues/issue-57979.rs diff --git a/src/test/ui/issues/issue-57979.rs b/src/test/ui/issues/issue-57979.rs new file mode 100644 index 0000000000000..abd46b60ab194 --- /dev/null +++ b/src/test/ui/issues/issue-57979.rs @@ -0,0 +1,42 @@ +// Regression test for #57979. This situation is meant to be an error. +// As noted in the issue thread, we decided to forbid nested impl +// trait of this kind: +// +// ```rust +// fn foo() -> impl Foo { .. } +// ``` +// +// Basically there are two hidden variables here, let's call them `X` +// and `Y`, and we must prove that: +// +// ``` +// X: Foo +// Y: Bar +// ``` +// +// However, the user is only giving us the return type `X`. It's true +// that in some cases, we can infer `Y` from `X`, because `X` only +// implements `Foo` for one type (and indeed the compiler does +// inference of this kind), but I do recall that we intended to forbid +// this -- in part because such inference is fragile, and there is not +// necessarily a way for the user to be more explicit should the +// inference fail (so you could get stuck with no way to port your +// code forward if, for example, more impls are added to an existing +// type). +// +// The same seems to apply in this situation. Here there are three impl traits, so we have +// +// ``` +// X: IntoIterator +// Y: Borrow> +// Z: AsRef<[u8]> +// ``` + +use std::borrow::Borrow; + +pub struct Data(TBody); + +pub fn collect(_: impl IntoIterator>>>) { + //~^ ERROR + unimplemented!() +} From 0d28a24c9463891fe2fe51356c8bcb7e1454298a Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Fri, 8 Feb 2019 09:43:15 +0100 Subject: [PATCH 07/41] Remove code for updating copyright years in generate-deriving-span-tests It's no longer necessary, as there is no license header anymore. --- src/etc/generate-deriving-span-tests.py | 28 ++++++------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/etc/generate-deriving-span-tests.py b/src/etc/generate-deriving-span-tests.py index 3d35ae07fbd68..9bd99dc4ceccf 100755 --- a/src/etc/generate-deriving-span-tests.py +++ b/src/etc/generate-deriving-span-tests.py @@ -8,13 +8,11 @@ sample usage: src/etc/generate-deriving-span-tests.py """ -import os, datetime, stat, re +import os, stat TEST_DIR = os.path.abspath( os.path.join(os.path.dirname(__file__), '../test/ui/derives/')) -YEAR = datetime.datetime.now().year - TEMPLATE = """ // This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' @@ -63,19 +61,11 @@ def create_test_case(type, trait, super_traits, error_count): errors = '\n'.join('//~%s ERROR' % ('^' * n) for n in range(error_count)) code = string.format(traits = all_traits, errors = errors) - return TEMPLATE.format(year = YEAR, error_deriving=error_deriving, code = code) + return TEMPLATE.format(error_deriving=error_deriving, code = code) def write_file(name, string): test_file = os.path.join(TEST_DIR, 'derives-span-%s.rs' % name) - with open(test_file) as f: - old_str = f.read() - old_str_ignoring_date = re.sub(r'^// Copyright \d+', - '// Copyright {year}'.format(year = YEAR), old_str) - if old_str_ignoring_date == string: - # if all we're doing is updating the copyright year, ignore it - return 0 - # set write permission if file exists, so it can be changed if os.path.exists(test_file): os.chmod(test_file, stat.S_IWUSR) @@ -86,8 +76,6 @@ def write_file(name, string): # mark file read-only os.chmod(test_file, stat.S_IRUSR|stat.S_IRGRP|stat.S_IROTH) - return 1 - ENUM = 1 STRUCT = 2 @@ -110,15 +98,11 @@ def write_file(name, string): ('Hash', [], 1)]: traits[trait] = (ALL, supers, errs) -files = 0 - for (trait, (types, super_traits, error_count)) in traits.items(): mk = lambda ty: create_test_case(ty, trait, super_traits, error_count) if types & ENUM: - files += write_file(trait + '-enum', mk(ENUM_TUPLE)) - files += write_file(trait + '-enum-struct-variant', mk(ENUM_STRUCT)) + write_file(trait + '-enum', mk(ENUM_TUPLE)) + write_file(trait + '-enum-struct-variant', mk(ENUM_STRUCT)) if types & STRUCT: - files += write_file(trait + '-struct', mk(STRUCT_FIELDS)) - files += write_file(trait + '-tuple-struct', mk(STRUCT_TUPLE)) - -print('Generated {files} deriving span test{}.'.format('s' if files != 1 else '', files = files)) + write_file(trait + '-struct', mk(STRUCT_FIELDS)) + write_file(trait + '-tuple-struct', mk(STRUCT_TUPLE)) From df420aa783f7f6e89d9004552db4d7625c3beb0f Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Fri, 8 Feb 2019 09:48:12 +0100 Subject: [PATCH 08/41] Remove initial newline from automatically generated span tests This change was accidentally introduced while removing license headers. --- src/etc/generate-deriving-span-tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc/generate-deriving-span-tests.py b/src/etc/generate-deriving-span-tests.py index 9bd99dc4ceccf..1c525101c76f6 100755 --- a/src/etc/generate-deriving-span-tests.py +++ b/src/etc/generate-deriving-span-tests.py @@ -13,7 +13,7 @@ TEST_DIR = os.path.abspath( os.path.join(os.path.dirname(__file__), '../test/ui/derives/')) -TEMPLATE = """ +TEMPLATE = """\ // This file was auto-generated using 'src/etc/generate-deriving-span-tests.py' {error_deriving} From 8f6d05b819bfadfad8f3fea9ba83deb7522dac78 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 8 Feb 2019 16:05:33 +0100 Subject: [PATCH 09/41] Don't default on std crate when manipulating browser history --- src/librustdoc/html/static/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index d6c05de0df6f2..41af44040f4cf 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1598,7 +1598,7 @@ if (!DOMTokenList.prototype.remove) { clearTimeout(searchTimeout); if (search_input.value.length === 0) { if (browserSupportsHistoryApi()) { - history.replaceState("", "std - Rust", "?search="); + history.replaceState("", window.currentCrate + " - Rust", "?search="); } if (hasClass(main, "content")) { removeClass(main, "hidden"); From d26475505b4c2bfc6299d3c6c38b1963c3bd86e0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 9 Feb 2019 01:07:38 +0100 Subject: [PATCH 10/41] put back macro redirect --- src/librustdoc/html/render.rs | 9 +++++++++ src/test/rustdoc/without-redirect.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index ecc5bcff12dba..105bf611282f7 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2245,6 +2245,15 @@ impl Context { try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); } } + // If the item is a macro, redirect from the old macro URL (with !) + // to the new one (without). + if item_type == ItemType::Macro { + let redir_name = format!("{}.{}!.html", item_type, name); + let redir_dst = self.dst.join(redir_name); + let redirect_out = try_err!(File::create(&redir_dst), &redir_dst); + let mut redirect_out = BufWriter::new(redirect_out); + try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst); + } } } Ok(()) diff --git a/src/test/rustdoc/without-redirect.rs b/src/test/rustdoc/without-redirect.rs index d473dd8f428d2..a076f8a3c5ec7 100644 --- a/src/test/rustdoc/without-redirect.rs +++ b/src/test/rustdoc/without-redirect.rs @@ -1,7 +1,7 @@ #![crate_name = "foo"] // @has foo/macro.bar.html -// @!has foo/macro.bar!.html +// @has foo/macro.bar!.html // @!has foo/bar.m.html #[macro_export] macro_rules! bar { From 6156defd516aad7002fb88f3003cd549fca9f084 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 11 Feb 2019 01:58:47 +0900 Subject: [PATCH 11/41] librustc_mir: use ? in impl_snapshot_for! macro --- src/librustc_mir/interpret/snapshot.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/librustc_mir/interpret/snapshot.rs b/src/librustc_mir/interpret/snapshot.rs index ee295116ba962..0168e1301fa7a 100644 --- a/src/librustc_mir/interpret/snapshot.rs +++ b/src/librustc_mir/interpret/snapshot.rs @@ -101,9 +101,8 @@ macro_rules! __impl_snapshot_field { // This assumes the type has two type parameters, first for the tag (set to `()`), // then for the id macro_rules! impl_snapshot_for { - // FIXME(mark-i-m): Some of these should be `?` rather than `*`. (enum $enum_name:ident { - $( $variant:ident $( ( $($field:ident $(-> $delegate:expr)*),* ) )* ),* $(,)* + $( $variant:ident $( ( $($field:ident $(-> $delegate:expr)?),* ) )? ),* $(,)? }) => { impl<'a, Ctx> self::Snapshot<'a, Ctx> for $enum_name @@ -115,18 +114,17 @@ macro_rules! impl_snapshot_for { fn snapshot(&self, __ctx: &'a Ctx) -> Self::Item { match *self { $( - $enum_name::$variant $( ( $(ref $field),* ) )* => + $enum_name::$variant $( ( $(ref $field),* ) )? => $enum_name::$variant $( - ( $( __impl_snapshot_field!($field, __ctx $(, $delegate)*) ),* ), - )* + ( $( __impl_snapshot_field!($field, __ctx $(, $delegate)?) ),* ), + )? )* } } } }; - // FIXME(mark-i-m): same here. - (struct $struct_name:ident { $($field:ident $(-> $delegate:expr)*),* $(,)* }) => { + (struct $struct_name:ident { $($field:ident $(-> $delegate:expr)?),* $(,)? }) => { impl<'a, Ctx> self::Snapshot<'a, Ctx> for $struct_name where Ctx: self::SnapshotContext<'a>, { @@ -139,7 +137,7 @@ macro_rules! impl_snapshot_for { } = *self; $struct_name { - $( $field: __impl_snapshot_field!($field, __ctx $(, $delegate)*) ),* + $( $field: __impl_snapshot_field!($field, __ctx $(, $delegate)?) ),* } } } From 7b2a08cf494563c1867200cd994193d1855719f2 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Tue, 12 Feb 2019 10:56:26 +0300 Subject: [PATCH 12/41] Add Instant::checked_duration_since, address #58402. --- src/libstd/lib.rs | 1 + src/libstd/time.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 8ecba3ecd68fd..38fc0bb80d0ba 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -295,6 +295,7 @@ #![feature(non_exhaustive)] #![feature(alloc_layout_extra)] #![feature(maybe_uninit)] +#![feature(checked_duration_since)] #![cfg_attr(all(target_vendor = "fortanix", target_env = "sgx"), feature(global_asm, range_contains, slice_index_methods, decl_macro, coerce_unsized, sgx_platform, ptr_wrapping_offset_from))] diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 23924559fcc24..973edb5479e8d 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -218,6 +218,30 @@ impl Instant { self.0.sub_instant(&earlier.0) } + /// Returns the amount of time elapsed from another instant to this one, + /// or None if that instant is earlier than this one. + /// + /// # Examples + /// + /// ```no_run + /// use std::time::{Duration, Instant}; + /// use std::thread::sleep; + /// + /// let now = Instant::now(); + /// sleep(Duration::new(1, 0)); + /// let new_now = Instant::now(); + /// println!("{:?}", new_now.checked_duration_since(now)); + /// println!("{:?}", now.checked_duration_since(new_now)); // None + /// ``` + #[unstable(feature = "checked_duration_since", issue = "58402")] + pub fn checked_duration_since(&self, earlier: Instant) -> Option { + if self >= &earlier { + Some(self.0.sub_instant(&earlier.0)) + } else { + None + } + } + /// Returns the amount of time elapsed since this instant was created. /// /// # Panics @@ -626,6 +650,12 @@ mod tests { (a - Duration::new(1, 0)).duration_since(a); } + #[test] + fn checked_instant_duration_nopanic() { + let a = Instant::now(); + (a - Duration::new(1, 0)).checked_duration_since(a); + } + #[test] fn system_time_math() { let a = SystemTime::now(); From 3777b86f9b79306d16982ed693a5e4634be13a0e Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Thu, 31 Jan 2019 12:47:31 -0800 Subject: [PATCH 13/41] Stabilize slice_sort_by_cached_key --- src/liballoc/benches/lib.rs | 1 - src/liballoc/slice.rs | 3 +-- src/liballoc/tests/lib.rs | 1 - src/librustc/lib.rs | 1 - src/librustc_codegen_llvm/lib.rs | 1 - src/librustc_codegen_ssa/lib.rs | 1 - src/librustc_driver/lib.rs | 1 - src/librustc_metadata/lib.rs | 1 - src/librustc_mir/lib.rs | 1 - src/librustc_resolve/lib.rs | 1 - src/librustc_typeck/lib.rs | 1 - src/librustdoc/lib.rs | 1 - src/libsyntax/lib.rs | 1 - 13 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/liballoc/benches/lib.rs b/src/liballoc/benches/lib.rs index 08c69ee6e8507..a1884b7d54852 100644 --- a/src/liballoc/benches/lib.rs +++ b/src/liballoc/benches/lib.rs @@ -1,5 +1,4 @@ #![feature(repr_simd)] -#![feature(slice_sort_by_cached_key)] #![feature(test)] extern crate rand; diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index c4f4a80a017df..1f68efd019bc8 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -312,7 +312,6 @@ impl [T] { /// # Examples /// /// ``` - /// #![feature(slice_sort_by_cached_key)] /// let mut v = [-5i32, 4, 32, -3, 2]; /// /// v.sort_by_cached_key(|k| k.to_string()); @@ -320,7 +319,7 @@ impl [T] { /// ``` /// /// [pdqsort]: https://github.com/orlp/pdqsort - #[unstable(feature = "slice_sort_by_cached_key", issue = "34447")] + #[stable(feature = "slice_sort_by_cached_key", since = "1.34.0")] #[inline] pub fn sort_by_cached_key(&mut self, f: F) where F: FnMut(&T) -> K, K: Ord diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 2b63ac5c7d2f9..2361a7db1f7a7 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -4,7 +4,6 @@ #![feature(exact_size_is_empty)] #![feature(pattern)] #![feature(repeat_generic_slice)] -#![feature(slice_sort_by_cached_key)] #![feature(try_reserve)] #![feature(unboxed_closures)] #![feature(vecdeque_rotate)] diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index be1475564778a..a49f0d68a48f0 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -47,7 +47,6 @@ #![feature(rustc_diagnostic_macros)] #![feature(rustc_attrs)] #![feature(slice_patterns)] -#![feature(slice_sort_by_cached_key)] #![feature(specialization)] #![feature(unboxed_closures)] #![feature(thread_local)] diff --git a/src/librustc_codegen_llvm/lib.rs b/src/librustc_codegen_llvm/lib.rs index ad8db25ee95a0..cf6c6c57bd982 100644 --- a/src/librustc_codegen_llvm/lib.rs +++ b/src/librustc_codegen_llvm/lib.rs @@ -17,7 +17,6 @@ #![feature(nll)] #![feature(range_contains)] #![feature(rustc_diagnostic_macros)] -#![feature(slice_sort_by_cached_key)] #![feature(optin_builtin_traits)] #![feature(concat_idents)] #![feature(link_args)] diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index a083bd5d8d18a..9e1744451465d 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -6,7 +6,6 @@ #![feature(libc)] #![feature(rustc_diagnostic_macros)] #![feature(in_band_lifetimes)] -#![feature(slice_sort_by_cached_key)] #![feature(nll)] #![allow(unused_attributes)] #![allow(dead_code)] diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 990ad4ada01a2..e022d3a3818a5 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -10,7 +10,6 @@ #![cfg_attr(unix, feature(libc))] #![feature(nll)] #![feature(rustc_diagnostic_macros)] -#![feature(slice_sort_by_cached_key)] #![feature(set_stdio)] #![feature(no_debug)] #![feature(integer_atomics)] diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index a3490b7fea5b5..b4f68399d9feb 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -6,7 +6,6 @@ #![feature(proc_macro_internals)] #![feature(proc_macro_quote)] #![feature(rustc_diagnostic_macros)] -#![feature(slice_sort_by_cached_key)] #![feature(crate_visibility_modifier)] #![feature(specialization)] #![feature(rustc_private)] diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 909f96956695d..e0fee10cd008c 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -7,7 +7,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(nll)] #![feature(in_band_lifetimes)] #![feature(slice_patterns)] -#![feature(slice_sort_by_cached_key)] #![feature(box_patterns)] #![feature(box_syntax)] #![feature(crate_visibility_modifier)] diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index ab2ae4a843519..4b5cf3b8fa6a4 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4,7 +4,6 @@ #![feature(label_break_value)] #![feature(nll)] #![feature(rustc_diagnostic_macros)] -#![feature(slice_sort_by_cached_key)] #![recursion_limit="256"] diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 931621fb53701..b0c47a49131e7 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -67,7 +67,6 @@ This API is completely unstable and subject to change. #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] #![feature(slice_patterns)] -#![feature(slice_sort_by_cached_key)] #![feature(never_type)] #![recursion_limit="256"] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index ddb730672d294..0b34a27794f0f 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -7,7 +7,6 @@ #![feature(box_syntax)] #![feature(nll)] #![feature(set_stdio)] -#![feature(slice_sort_by_cached_key)] #![feature(test)] #![feature(vec_remove_item)] #![feature(ptr_offset_from)] diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index a56cdf623bf43..48c06c381de00 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -14,7 +14,6 @@ #![feature(nll)] #![feature(rustc_attrs)] #![feature(rustc_diagnostic_macros)] -#![feature(slice_sort_by_cached_key)] #![feature(step_trait)] #![feature(try_trait)] #![feature(unicode_internals)] From 317f15304e6091a1f3cc58c52d36df037ef50db0 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 2 Feb 2019 01:32:56 -0800 Subject: [PATCH 14/41] Revert "Remove mentions of unstable sort_by_cached key from stable documentation" This reverts commit 9c7b69e17909ceb090a1c4b8882a4e0924a2a755. --- src/liballoc/slice.rs | 4 ++++ src/libcore/slice/mod.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 1f68efd019bc8..f4b2d463778a9 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -257,6 +257,10 @@ impl [T] { /// This sort is stable (i.e., does not reorder equal elements) and `O(m n log(m n))` /// worst-case, where the key function is `O(m)`. /// + /// For expensive key functions (e.g. functions that are not simple property accesses or + /// basic operations), [`sort_by_cached_key`](#method.sort_by_cached_key) is likely to be + /// significantly faster, as it does not recompute element keys. + /// /// When applicable, unstable sorting is preferred because it is generally faster than stable /// sorting and it doesn't allocate auxiliary memory. /// See [`sort_unstable_by_key`](#method.sort_unstable_by_key). diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index acca9748372ca..a628fd0cfa4b2 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1563,6 +1563,10 @@ impl [T] { /// randomization to avoid degenerate cases, but with a fixed seed to always provide /// deterministic behavior. /// + /// Due to its key calling strategy, [`sort_unstable_by_key`](#method.sort_unstable_by_key) + /// is likely to be slower than [`sort_by_cached_key`](#method.sort_by_cached_key) in + /// cases where the key function is expensive. + /// /// # Examples /// /// ``` From d15c35800032e58c17ef1da3577dacc01ef82bb1 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Wed, 13 Feb 2019 13:17:33 +0300 Subject: [PATCH 15/41] Fix tests for checked_duration_since --- src/libstd/time.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 973edb5479e8d..eefb84f697f1f 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -224,6 +224,7 @@ impl Instant { /// # Examples /// /// ```no_run + /// #![feature(checked_duration_since)] /// use std::time::{Duration, Instant}; /// use std::thread::sleep; /// @@ -653,7 +654,8 @@ mod tests { #[test] fn checked_instant_duration_nopanic() { let a = Instant::now(); - (a - Duration::new(1, 0)).checked_duration_since(a); + let ret = (a - Duration::new(1, 0)).checked_duration_since(a); + assert_eq!(ret, None); } #[test] From 91f67fd1a75d7cc1b1ac5fc957ff30f16d01232e Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Wed, 13 Feb 2019 15:08:44 +0300 Subject: [PATCH 16/41] Add Instant::saturating_duration_since --- src/libstd/time.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/libstd/time.rs b/src/libstd/time.rs index eefb84f697f1f..db2630e88d0bc 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -243,6 +243,27 @@ impl Instant { } } + /// Returns the amount of time elapsed from another instant to this one, + /// or zero duration if that instant is earlier than this one. + /// + /// # Examples + /// + /// ```no_run + /// #![feature(checked_duration_since)] + /// use std::time::{Duration, Instant}; + /// use std::thread::sleep; + /// + /// let now = Instant::now(); + /// sleep(Duration::new(1, 0)); + /// let new_now = Instant::now(); + /// println!("{:?}", new_now.saturating_duration_since(now)); + /// println!("{:?}", now.saturating_duration_since(new_now)); // 0ns + /// ``` + #[unstable(feature = "checked_duration_since", issue = "58402")] + pub fn saturating_duration_since(&self, earlier: Instant) -> Duration { + self.checked_duration_since(earlier).unwrap_or(Duration::new(0, 0)) + } + /// Returns the amount of time elapsed since this instant was created. /// /// # Panics @@ -658,6 +679,13 @@ mod tests { assert_eq!(ret, None); } + #[test] + fn saturating_instant_duration_nopanic() { + let a = Instant::now(); + let ret = (a - Duration::new(1, 0)).saturating_duration_since(a); + assert_eq!(ret, Duration::new(0,0)); + } + #[test] fn system_time_math() { let a = SystemTime::now(); From 719be246ae708508a19436a0b8ee1be29882e21e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 13 Feb 2019 16:26:13 +0100 Subject: [PATCH 17/41] fix Box::into_unique effecitvely transmuting to a raw ptr --- src/liballoc/boxed.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 8e01e12e0b8de..f6411a3db872b 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -202,10 +202,15 @@ impl Box { #[unstable(feature = "ptr_internals", issue = "0", reason = "use into_raw_non_null instead")] #[inline] #[doc(hidden)] - pub fn into_unique(b: Box) -> Unique { - let unique = b.0; + pub fn into_unique(mut b: Box) -> Unique { + // Box is kind-of a library type, but recognized as a "unique pointer" by + // Stacked Borrows. This function here corresponds to "reborrowing to + // a raw pointer", but there is no actual reborrow here -- so + // without some care, the pointer we are returning here still carries + // the `Uniq` tag. We round-trip through a mutable reference to avoid that. + let unique = unsafe { b.0.as_mut() as *mut T }; mem::forget(b); - unique + unsafe { Unique::new_unchecked(unique) } } /// Consumes and leaks the `Box`, returning a mutable reference, From 26ade1cfaa095350f27c90a144779a250312cb26 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 9 Feb 2019 11:32:09 +0100 Subject: [PATCH 18/41] mark failures expected due to panics --- src/libcore/tests/iter.rs | 4 ++-- src/libcore/tests/option.rs | 6 +++--- src/libcore/tests/result.rs | 6 +++--- src/libcore/tests/slice.rs | 14 +++++++------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 51a6017de1b5f..04c5bf7e95b41 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -255,7 +255,7 @@ fn test_iterator_step_by_nth_overflow() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_iterator_step_by_zero() { let mut it = (0..).step_by(0); it.next(); @@ -1417,7 +1417,7 @@ fn test_rposition() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_rposition_panic() { let v: [(Box<_>, Box<_>); 4] = [(box 0, box 0), (box 0, box 0), diff --git a/src/libcore/tests/option.rs b/src/libcore/tests/option.rs index 1ba886ce037ee..87ce2720c5918 100644 --- a/src/libcore/tests/option.rs +++ b/src/libcore/tests/option.rs @@ -69,7 +69,7 @@ fn test_option_dance() { } #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_option_too_much_dance() { struct A; let mut y = Some(A); @@ -130,7 +130,7 @@ fn test_unwrap() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_unwrap_panic1() { let x: Option = None; x.unwrap(); @@ -138,7 +138,7 @@ fn test_unwrap_panic1() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_unwrap_panic2() { let x: Option = None; x.unwrap(); diff --git a/src/libcore/tests/result.rs b/src/libcore/tests/result.rs index 7bfd396f68d17..bbc8568517667 100644 --- a/src/libcore/tests/result.rs +++ b/src/libcore/tests/result.rs @@ -117,7 +117,7 @@ fn test_unwrap_or_else() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics pub fn test_unwrap_or_else_panic() { fn handler(msg: &'static str) -> isize { if msg == "I got this." { @@ -139,7 +139,7 @@ pub fn test_expect_ok() { } #[test] #[should_panic(expected="Got expected error: \"All good\"")] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics pub fn test_expect_err() { let err: Result = Err("All good"); err.expect("Got expected error"); @@ -153,7 +153,7 @@ pub fn test_expect_err_err() { } #[test] #[should_panic(expected="Got expected ok: \"All good\"")] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics pub fn test_expect_err_ok() { let err: Result<&'static str, isize> = Ok("All good"); err.expect_err("Got expected ok"); diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index 04d646ea01d03..454c1235c813a 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -782,7 +782,7 @@ mod slice_index { // to be used in `should_panic`) #[test] #[should_panic(expected = "out of range")] - #[cfg(not(miri))] + #[cfg(not(miri))] // Miri does not support panics fn assert_range_eq_can_fail_by_panic() { assert_range_eq!([0, 1, 2], 0..5, [0, 1, 2]); } @@ -792,7 +792,7 @@ mod slice_index { // to be used in `should_panic`) #[test] #[should_panic(expected = "==")] - #[cfg(not(miri))] + #[cfg(not(miri))] // Miri does not support panics fn assert_range_eq_can_fail_by_inequality() { assert_range_eq!([0, 1, 2], 0..2, [0, 1, 2]); } @@ -842,7 +842,7 @@ mod slice_index { #[test] #[should_panic(expected = $expect_msg)] - #[cfg(not(miri))] + #[cfg(not(miri))] // Miri does not support panics fn index_fail() { let v = $data; let v: &[_] = &v; @@ -851,7 +851,7 @@ mod slice_index { #[test] #[should_panic(expected = $expect_msg)] - #[cfg(not(miri))] + #[cfg(not(miri))] // Miri does not support panics fn index_mut_fail() { let mut v = $data; let v: &mut [_] = &mut v; @@ -1306,7 +1306,7 @@ fn test_copy_within() { #[test] #[should_panic(expected = "src is out of bounds")] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_copy_within_panics_src_too_long() { let mut bytes = *b"Hello, World!"; // The length is only 13, so 14 is out of bounds. @@ -1315,7 +1315,7 @@ fn test_copy_within_panics_src_too_long() { #[test] #[should_panic(expected = "dest is out of bounds")] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_copy_within_panics_dest_too_long() { let mut bytes = *b"Hello, World!"; // The length is only 13, so a slice of length 4 starting at index 10 is out of bounds. @@ -1323,7 +1323,7 @@ fn test_copy_within_panics_dest_too_long() { } #[test] #[should_panic(expected = "src end is before src start")] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_copy_within_panics_src_inverted() { let mut bytes = *b"Hello, World!"; // 2 is greater than 1, so this range is invalid. From 7f5dc49214b05a469c5c4974fc4e605cb72822ea Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 9 Feb 2019 13:16:23 +0100 Subject: [PATCH 19/41] review or fix miri failures in iter, slice, cell, time --- src/libcore/tests/cell.rs | 5 +++-- src/libcore/tests/iter.rs | 8 ++------ src/libcore/tests/slice.rs | 8 +++----- src/libcore/tests/time.rs | 5 +++-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/libcore/tests/cell.rs b/src/libcore/tests/cell.rs index 73bdaab5861e6..b16416022c04e 100644 --- a/src/libcore/tests/cell.rs +++ b/src/libcore/tests/cell.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use core::cell::*; use core::default::Default; use std::mem::drop; @@ -111,6 +109,7 @@ fn double_borrow_single_release_no_borrow_mut() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn discard_doesnt_unborrow() { let x = RefCell::new(0); let _b = x.borrow(); @@ -351,6 +350,7 @@ fn refcell_ref_coercion() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn refcell_swap_borrows() { let x = RefCell::new(0); let _b = x.borrow(); @@ -360,6 +360,7 @@ fn refcell_swap_borrows() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn refcell_replace_borrows() { let x = RefCell::new(0); let _b = x.borrow(); diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index 04c5bf7e95b41..bc951829bd7b9 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -190,7 +190,6 @@ fn test_iterator_step_by() { } #[test] -#[cfg(not(miri))] fn test_iterator_step_by_nth() { let mut it = (0..16).step_by(5); assert_eq!(it.nth(0), Some(0)); @@ -209,7 +208,6 @@ fn test_iterator_step_by_nth() { } #[test] -#[cfg(not(miri))] fn test_iterator_step_by_nth_overflow() { #[cfg(target_pointer_width = "8")] type Bigger = u16; @@ -262,7 +260,6 @@ fn test_iterator_step_by_zero() { } #[test] -#[cfg(not(miri))] fn test_iterator_step_by_size_hint() { struct StubSizeHint(usize, Option); impl Iterator for StubSizeHint { @@ -1657,7 +1654,6 @@ fn test_range_inclusive_nth() { } #[test] -#[cfg(not(miri))] fn test_range_step() { #![allow(deprecated)] @@ -1665,7 +1661,9 @@ fn test_range_step() { assert_eq!((1..21).rev().step_by(5).collect::>(), [20, 15, 10, 5]); assert_eq!((1..21).rev().step_by(6).collect::>(), [20, 14, 8, 2]); assert_eq!((200..255).step_by(50).collect::>(), [200, 250]); + #[cfg(not(miri))] // Miri cannot compare empty slices assert_eq!((200..-5).step_by(1).collect::>(), []); + #[cfg(not(miri))] // Miri cannot compare empty slices assert_eq!((200..200).step_by(1).collect::>(), []); assert_eq!((0..20).step_by(1).size_hint(), (20, Some(20))); @@ -1681,7 +1679,6 @@ fn test_range_step() { } #[test] -#[cfg(not(miri))] fn test_step_by_skip() { assert_eq!((0..640).step_by(128).skip(1).collect::>(), [128, 256, 384, 512]); assert_eq!((0..=50).step_by(10).nth(3), Some(30)); @@ -1689,7 +1686,6 @@ fn test_step_by_skip() { } #[test] -#[cfg(not(miri))] fn test_range_inclusive_step() { assert_eq!((0..=50).step_by(10).collect::>(), [0, 10, 20, 30, 40, 50]); assert_eq!((0..=5).step_by(1).collect::>(), [0, 1, 2, 3, 4, 5]); diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs index 454c1235c813a..31d16e0e32057 100644 --- a/src/libcore/tests/slice.rs +++ b/src/libcore/tests/slice.rs @@ -1015,7 +1015,7 @@ fn test_rotate_right() { #[test] #[cfg(not(target_arch = "wasm32"))] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support entropy fn sort_unstable() { use core::cmp::Ordering::{Equal, Greater, Less}; use core::slice::heapsort; @@ -1171,7 +1171,7 @@ pub mod memchr { } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri cannot compute actual alignment of an allocation fn test_align_to_simple() { let bytes = [1u8, 2, 3, 4, 5, 6, 7]; let (prefix, aligned, suffix) = unsafe { bytes.align_to::() }; @@ -1187,7 +1187,6 @@ fn test_align_to_simple() { } #[test] -#[cfg(not(miri))] fn test_align_to_zst() { let bytes = [1, 2, 3, 4, 5, 6, 7]; let (prefix, aligned, suffix) = unsafe { bytes.align_to::<()>() }; @@ -1196,7 +1195,7 @@ fn test_align_to_zst() { } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri cannot compute actual alignment of an allocation fn test_align_to_non_trivial() { #[repr(align(8))] struct U64(u64, u64); #[repr(align(8))] struct U64U64U32(u64, u64, u32); @@ -1208,7 +1207,6 @@ fn test_align_to_non_trivial() { } #[test] -#[cfg(not(miri))] fn test_align_to_empty_mid() { use core::mem; diff --git a/src/libcore/tests/time.rs b/src/libcore/tests/time.rs index d39bd06930a36..f7d00304df5b6 100644 --- a/src/libcore/tests/time.rs +++ b/src/libcore/tests/time.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use core::time::Duration; #[test] @@ -109,12 +107,14 @@ fn checked_sub() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn sub_bad1() { let _ = Duration::new(0, 0) - Duration::new(0, 1); } #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn sub_bad2() { let _ = Duration::new(0, 0) - Duration::new(1, 0); } @@ -287,6 +287,7 @@ fn debug_formatting_precision_two() { } #[test] +#[cfg(not(miri))] // FIXME: A bug in Miri breaks padding in string formatting fn debug_formatting_precision_high() { assert_eq!(format!("{:.5?}", Duration::new(0, 23_678)), "23.67800µs"); From 72be9a607bd127cdd5cdb3f1f53af725f4eeef98 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 9 Feb 2019 16:19:21 +0100 Subject: [PATCH 20/41] review or fix remaining miri failures in libcore --- src/libcore/tests/fmt/mod.rs | 2 +- src/libcore/tests/hash/mod.rs | 4 ++-- src/libcore/tests/iter.rs | 2 -- src/libcore/tests/num/bignum.rs | 14 ++++++++++++++ src/libcore/tests/num/dec2flt/mod.rs | 2 ++ src/libcore/tests/num/flt2dec/mod.rs | 2 ++ src/libcore/tests/num/mod.rs | 2 -- src/libcore/tests/ptr.rs | 9 +++++++-- 8 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/libcore/tests/fmt/mod.rs b/src/libcore/tests/fmt/mod.rs index b10b63fc484cb..3baa445e652f8 100644 --- a/src/libcore/tests/fmt/mod.rs +++ b/src/libcore/tests/fmt/mod.rs @@ -1,4 +1,4 @@ -#![cfg(not(miri))] +#![cfg(not(miri))] // FIXME: A bug in Miri breaks padding in string formatting mod builders; mod float; diff --git a/src/libcore/tests/hash/mod.rs b/src/libcore/tests/hash/mod.rs index bf3039a7e51e8..1000088e6b063 100644 --- a/src/libcore/tests/hash/mod.rs +++ b/src/libcore/tests/hash/mod.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - mod sip; use std::hash::{Hash, Hasher}; @@ -75,9 +73,11 @@ fn test_writer_hasher() { let cs: &mut [u8] = &mut [1, 2, 3]; let ptr = cs.as_ptr(); let slice_ptr = cs as *const [u8]; + #[cfg(not(miri))] // Miri cannot hash pointers assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64); let slice_ptr = cs as *mut [u8]; + #[cfg(not(miri))] // Miri cannot hash pointers assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64); } diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs index bc951829bd7b9..9b76a4af98824 100644 --- a/src/libcore/tests/iter.rs +++ b/src/libcore/tests/iter.rs @@ -1661,9 +1661,7 @@ fn test_range_step() { assert_eq!((1..21).rev().step_by(5).collect::>(), [20, 15, 10, 5]); assert_eq!((1..21).rev().step_by(6).collect::>(), [20, 14, 8, 2]); assert_eq!((200..255).step_by(50).collect::>(), [200, 250]); - #[cfg(not(miri))] // Miri cannot compare empty slices assert_eq!((200..-5).step_by(1).collect::>(), []); - #[cfg(not(miri))] // Miri cannot compare empty slices assert_eq!((200..200).step_by(1).collect::>(), []); assert_eq!((0..20).step_by(1).size_hint(), (20, Some(20))); diff --git a/src/libcore/tests/num/bignum.rs b/src/libcore/tests/num/bignum.rs index b873f1dd0652f..956c22c998219 100644 --- a/src/libcore/tests/num/bignum.rs +++ b/src/libcore/tests/num/bignum.rs @@ -3,6 +3,7 @@ use core::num::bignum::tests::Big8x3 as Big; #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_from_u64_overflow() { Big::from_u64(0x1000000); } @@ -19,12 +20,14 @@ fn test_add() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_add_overflow_1() { Big::from_small(1).add(&Big::from_u64(0xffffff)); } #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_add_overflow_2() { Big::from_u64(0xffffff).add(&Big::from_small(1)); } @@ -42,6 +45,7 @@ fn test_add_small() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_add_small_overflow() { Big::from_u64(0xffffff).add_small(1); } @@ -57,12 +61,14 @@ fn test_sub() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_sub_underflow_1() { Big::from_u64(0x10665).sub(&Big::from_u64(0x10666)); } #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_sub_underflow_2() { Big::from_small(0).sub(&Big::from_u64(0x123456)); } @@ -76,6 +82,7 @@ fn test_mul_small() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mul_small_overflow() { Big::from_u64(0x800000).mul_small(2); } @@ -94,12 +101,14 @@ fn test_mul_pow2() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mul_pow2_overflow_1() { Big::from_u64(0x1).mul_pow2(24); } #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mul_pow2_overflow_2() { Big::from_u64(0x123).mul_pow2(16); } @@ -118,12 +127,14 @@ fn test_mul_pow5() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mul_pow5_overflow_1() { Big::from_small(1).mul_pow5(12); } #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mul_pow5_overflow_2() { Big::from_small(230).mul_pow5(8); } @@ -141,12 +152,14 @@ fn test_mul_digits() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mul_digits_overflow_1() { Big::from_u64(0x800000).mul_digits(&[2]); } #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mul_digits_overflow_2() { Big::from_u64(0x1000).mul_digits(&[0, 0x10]); } @@ -206,6 +219,7 @@ fn test_get_bit() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_get_bit_out_of_range() { Big::from_small(42).get_bit(24); } diff --git a/src/libcore/tests/num/dec2flt/mod.rs b/src/libcore/tests/num/dec2flt/mod.rs index 8f1cd32c3563c..faeaabbf95ada 100644 --- a/src/libcore/tests/num/dec2flt/mod.rs +++ b/src/libcore/tests/num/dec2flt/mod.rs @@ -52,6 +52,7 @@ fn large() { } #[test] +#[cfg(not(miri))] // Miri is too slow fn subnormals() { test_literal!(5e-324); test_literal!(91e-324); @@ -63,6 +64,7 @@ fn subnormals() { } #[test] +#[cfg(not(miri))] // Miri is too slow fn infinity() { test_literal!(1e400); test_literal!(1e309); diff --git a/src/libcore/tests/num/flt2dec/mod.rs b/src/libcore/tests/num/flt2dec/mod.rs index fed9ce73b2a8e..d362c7994d806 100644 --- a/src/libcore/tests/num/flt2dec/mod.rs +++ b/src/libcore/tests/num/flt2dec/mod.rs @@ -1,3 +1,5 @@ +#![cfg(not(miri))] // Miri does not implement ldexp, which most tests here need + use std::prelude::v1::*; use std::{str, i16, f32, f64, fmt}; diff --git a/src/libcore/tests/num/mod.rs b/src/libcore/tests/num/mod.rs index ab638e06cc10d..a17c094679ea8 100644 --- a/src/libcore/tests/num/mod.rs +++ b/src/libcore/tests/num/mod.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use core::convert::{TryFrom, TryInto}; use core::cmp::PartialEq; use core::fmt::Debug; diff --git a/src/libcore/tests/ptr.rs b/src/libcore/tests/ptr.rs index 5784559082266..2c53e4832a8cc 100644 --- a/src/libcore/tests/ptr.rs +++ b/src/libcore/tests/ptr.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use core::ptr::*; use core::cell::RefCell; @@ -42,6 +40,7 @@ fn test() { } #[test] +#[cfg(not(miri))] // This test performs invalid OOB pointer arithmetic fn test_is_null() { let p: *const isize = null(); assert!(p.is_null()); @@ -147,6 +146,7 @@ fn test_as_ref() { } #[test] +#[cfg(not(miri))] // This test is UB according to Stacked Borrows fn test_as_mut() { unsafe { let p: *mut isize = null_mut(); @@ -208,6 +208,7 @@ fn test_ptr_addition() { } #[test] +#[cfg(not(miri))] // This test performs invalid OOB pointer arithmetic fn test_ptr_subtraction() { unsafe { let xs = vec![0,1,2,3,4,5,6,7,8,9]; @@ -251,6 +252,7 @@ fn test_unsized_nonnull() { #[test] #[allow(warnings)] +#[cfg(not(miri))] // Miri cannot hash pointers // Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the // ABI, or even point to an actual executable code, because the function itself is never invoked. #[no_mangle] @@ -290,6 +292,7 @@ fn write_unaligned_drop() { } #[test] +#[cfg(not(miri))] // Miri cannot compute actual alignment of an allocation fn align_offset_zst() { // For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at // all, because no amount of elements will align the pointer. @@ -304,6 +307,7 @@ fn align_offset_zst() { } #[test] +#[cfg(not(miri))] // Miri cannot compute actual alignment of an allocation fn align_offset_stride1() { // For pointers of stride = 1, the pointer can always be aligned. The offset is equal to // number of bytes. @@ -320,6 +324,7 @@ fn align_offset_stride1() { } #[test] +#[cfg(not(miri))] // Miri is too slow fn align_offset_weird_strides() { #[repr(packed)] struct A3(u16, u8); From e24af6c2b32679e398b2a2b1bc81ab9c258d8765 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 13 Feb 2019 13:25:46 +0100 Subject: [PATCH 21/41] the formatting issue got fixed --- src/libcore/tests/fmt/builders.rs | 1 + src/libcore/tests/fmt/mod.rs | 4 ++-- src/libcore/tests/time.rs | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcore/tests/fmt/builders.rs b/src/libcore/tests/fmt/builders.rs index fd7192cc15119..391250f998640 100644 --- a/src/libcore/tests/fmt/builders.rs +++ b/src/libcore/tests/fmt/builders.rs @@ -488,6 +488,7 @@ mod debug_list { } #[test] +#[cfg(not(miri))] // FIXME uses code in liballoc, investigate Stacked Borrows failure fn test_formatting_parameters_are_forwarded() { use std::collections::{BTreeMap, BTreeSet}; #[derive(Debug)] diff --git a/src/libcore/tests/fmt/mod.rs b/src/libcore/tests/fmt/mod.rs index 3baa445e652f8..df1deeaeb97b7 100644 --- a/src/libcore/tests/fmt/mod.rs +++ b/src/libcore/tests/fmt/mod.rs @@ -1,10 +1,9 @@ -#![cfg(not(miri))] // FIXME: A bug in Miri breaks padding in string formatting - mod builders; mod float; mod num; #[test] +#[cfg(not(miri))] // Miri cannot print pointers fn test_format_flags() { // No residual flags left by pointer formatting let p = "".as_ptr(); @@ -14,6 +13,7 @@ fn test_format_flags() { } #[test] +#[cfg(not(miri))] // Miri cannot print pointers fn test_pointer_formats_data_pointer() { let b: &[u8] = b""; let s: &str = ""; diff --git a/src/libcore/tests/time.rs b/src/libcore/tests/time.rs index f7d00304df5b6..09aae4583482f 100644 --- a/src/libcore/tests/time.rs +++ b/src/libcore/tests/time.rs @@ -287,7 +287,6 @@ fn debug_formatting_precision_two() { } #[test] -#[cfg(not(miri))] // FIXME: A bug in Miri breaks padding in string formatting fn debug_formatting_precision_high() { assert_eq!(format!("{:.5?}", Duration::new(0, 23_678)), "23.67800µs"); From b17ca0107755f60a1760f1dca17240cd70d15c5f Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 13 Feb 2019 13:59:51 +0100 Subject: [PATCH 22/41] review failures in binary_heap, str, vec_deque --- src/liballoc/tests/arc.rs | 2 -- src/liballoc/tests/binary_heap.rs | 2 +- src/liballoc/tests/rc.rs | 2 -- src/liballoc/tests/str.rs | 39 ++++++++++++++----------------- src/liballoc/tests/vec_deque.rs | 11 ++++----- 5 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/liballoc/tests/arc.rs b/src/liballoc/tests/arc.rs index 7c5a8926126e3..2759b1b1cac27 100644 --- a/src/liballoc/tests/arc.rs +++ b/src/liballoc/tests/arc.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use std::any::Any; use std::sync::{Arc, Weak}; use std::cell::RefCell; diff --git a/src/liballoc/tests/binary_heap.rs b/src/liballoc/tests/binary_heap.rs index c1a1c5d88781f..1d4a3edc1ac42 100644 --- a/src/liballoc/tests/binary_heap.rs +++ b/src/liballoc/tests/binary_heap.rs @@ -282,7 +282,7 @@ fn assert_covariance() { // // Destructors must be called exactly once per element. #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn panic_safe() { static DROP_COUNTER: AtomicUsize = AtomicUsize::new(0); diff --git a/src/liballoc/tests/rc.rs b/src/liballoc/tests/rc.rs index 1be01d1a7ce1a..18f82e8041008 100644 --- a/src/liballoc/tests/rc.rs +++ b/src/liballoc/tests/rc.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use std::any::Any; use std::rc::{Rc, Weak}; use std::cell::RefCell; diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index a1dc763f6d8ff..b33a564218888 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -31,7 +31,6 @@ fn test_rfind() { } #[test] -#[cfg(not(miri))] fn test_collect() { let empty = ""; let s: String = empty.chars().collect(); @@ -119,7 +118,6 @@ fn test_concat_for_different_types() { #[test] fn test_concat_for_different_lengths() { let empty: &[&str] = &[]; - #[cfg(not(miri))] test_concat!("", empty); test_concat!("a", ["a"]); test_concat!("ab", ["a", "b"]); @@ -148,7 +146,6 @@ fn test_join_for_different_types() { #[test] fn test_join_for_different_lengths() { let empty: &[&str] = &[]; - #[cfg(not(miri))] test_join!("", empty, "-"); test_join!("a", ["a"], "-"); test_join!("a-b", ["a", "b"], "-"); @@ -162,7 +159,6 @@ fn test_join_for_different_lengths_with_long_separator() { assert_eq!("~~~~~".len(), 15); let empty: &[&str] = &[]; - #[cfg(not(miri))] test_join!("", empty, "~~~~~"); test_join!("a", ["a"], "~~~~~"); test_join!("a~~~~~b", ["a", "b"], "~~~~~"); @@ -170,7 +166,7 @@ fn test_join_for_different_lengths_with_long_separator() { } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri is too slow fn test_unsafe_slice() { assert_eq!("ab", unsafe {"abc".get_unchecked(0..2)}); assert_eq!("bc", unsafe {"abc".get_unchecked(1..3)}); @@ -243,7 +239,6 @@ fn test_replacen() { #[test] fn test_replace() { let a = "a"; - #[cfg(not(miri))] assert_eq!("".replace(a, "b"), ""); assert_eq!("a".replace(a, "b"), "b"); assert_eq!("ab".replace(a, "b"), "bb"); @@ -303,7 +298,6 @@ fn test_replace_pattern() { // The current implementation of SliceIndex fails to handle methods // orthogonally from range types; therefore, it is worth testing // all of the indexing operations on each input. -#[cfg(not(miri))] mod slice_index { // Test a slicing operation **that should succeed,** // testing it on all of the indexing methods. @@ -357,6 +351,7 @@ mod slice_index { // to be used in `should_panic`) #[test] #[should_panic(expected = "out of bounds")] + #[cfg(not(miri))] // Miri does not support panics fn assert_range_eq_can_fail_by_panic() { assert_range_eq!("abc", 0..5, "abc"); } @@ -366,6 +361,7 @@ mod slice_index { // to be used in `should_panic`) #[test] #[should_panic(expected = "==")] + #[cfg(not(miri))] // Miri does not support panics fn assert_range_eq_can_fail_by_inequality() { assert_range_eq!("abc", 0..2, "abc"); } @@ -413,6 +409,7 @@ mod slice_index { #[test] #[should_panic(expected = $expect_msg)] + #[cfg(not(miri))] // Miri does not support panics fn index_fail() { let v: String = $data.into(); let v: &str = &v; @@ -421,6 +418,7 @@ mod slice_index { #[test] #[should_panic(expected = $expect_msg)] + #[cfg(not(miri))] // Miri does not support panics fn index_mut_fail() { let mut v: String = $data.into(); let v: &mut str = &mut v; @@ -490,6 +488,7 @@ mod slice_index { #[test] #[cfg(not(target_arch = "asmjs"))] // hits an OOM + #[cfg(not(miri))] // Miri is too slow fn simple_big() { fn a_million_letter_x() -> String { let mut i = 0; @@ -515,6 +514,7 @@ mod slice_index { #[test] #[should_panic] + #[cfg(not(miri))] // Miri does not support panics fn test_slice_fail() { &"中华Việt Nam"[0..2]; } @@ -666,12 +666,14 @@ mod slice_index { // check the panic includes the prefix of the sliced string #[test] #[should_panic(expected="byte index 1024 is out of bounds of `Lorem ipsum dolor sit amet")] + #[cfg(not(miri))] // Miri does not support panics fn test_slice_fail_truncated_1() { &LOREM_PARAGRAPH[..1024]; } // check the truncation in the panic message #[test] #[should_panic(expected="luctus, im`[...]")] + #[cfg(not(miri))] // Miri does not support panics fn test_slice_fail_truncated_2() { &LOREM_PARAGRAPH[..1024]; } @@ -686,7 +688,7 @@ fn test_str_slice_rangetoinclusive_ok() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_str_slice_rangetoinclusive_notok() { let s = "abcαβγ"; &s[..=3]; @@ -702,7 +704,7 @@ fn test_str_slicemut_rangetoinclusive_ok() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_str_slicemut_rangetoinclusive_notok() { let mut s = "abcαβγ".to_owned(); let s: &mut str = &mut s; @@ -892,7 +894,7 @@ fn test_as_bytes() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_as_bytes_fail() { // Don't double free. (I'm not sure if this exercises the // original problem code path anymore.) @@ -982,7 +984,7 @@ fn test_split_at_mut() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_split_at_boundscheck() { let s = "ศไทย中华Việt Nam"; s.split_at(1); @@ -1078,7 +1080,7 @@ fn test_rev_iterator() { } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri is too slow fn test_chars_decoding() { let mut bytes = [0; 4]; for c in (0..0x110000).filter_map(std::char::from_u32) { @@ -1090,7 +1092,7 @@ fn test_chars_decoding() { } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri is too slow fn test_chars_rev_decoding() { let mut bytes = [0; 4]; for c in (0..0x110000).filter_map(std::char::from_u32) { @@ -1320,7 +1322,6 @@ fn test_splitator() { } #[test] -#[cfg(not(miri))] fn test_str_default() { use std::default::Default; @@ -1380,7 +1381,7 @@ fn test_bool_from_str() { assert_eq!("not even a boolean".parse::().ok(), None); } -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri is too slow fn check_contains_all_substrings(s: &str) { assert!(s.contains("")); for i in 0..s.len() { @@ -1391,7 +1392,7 @@ fn check_contains_all_substrings(s: &str) { } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri is too slow fn strslice_issue_16589() { assert!("bananas".contains("nana")); @@ -1401,7 +1402,6 @@ fn strslice_issue_16589() { } #[test] -#[cfg(not(miri))] fn strslice_issue_16878() { assert!(!"1234567ah012345678901ah".contains("hah")); assert!(!"00abc01234567890123456789abc".contains("bcabc")); @@ -1409,7 +1409,7 @@ fn strslice_issue_16878() { #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri is too slow fn test_strslice_contains() { let x = "There are moments, Jeeves, when one asks oneself, 'Do trousers matter?'"; check_contains_all_substrings(x); @@ -1547,7 +1547,6 @@ fn trim_ws() { #[test] fn to_lowercase() { - #[cfg(not(miri))] assert_eq!("".to_lowercase(), ""); assert_eq!("AÉDžaé ".to_lowercase(), "aédžaé "); @@ -1581,7 +1580,6 @@ fn to_lowercase() { #[test] fn to_uppercase() { - #[cfg(not(miri))] assert_eq!("".to_uppercase(), ""); assert_eq!("aéDžßfiᾀ".to_uppercase(), "AÉDŽSSFIἈΙ"); } @@ -1613,7 +1611,6 @@ fn test_cow_from() { } #[test] -#[cfg(not(miri))] fn test_repeat() { assert_eq!("".repeat(3), ""); assert_eq!("abc".repeat(0), ""); diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index b47e7c867e675..d3439fed3cf3c 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -108,7 +108,7 @@ fn test_index() { #[test] #[should_panic] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support panics fn test_index_out_of_bounds() { let mut deq = VecDeque::new(); for i in 1..4 { @@ -907,24 +907,21 @@ fn test_append() { // normal append a.append(&mut b); assert_eq!(a.iter().cloned().collect::>(), [1, 2, 3, 4, 5, 6]); - #[cfg(not(miri))] assert_eq!(b.iter().cloned().collect::>(), []); // append nothing to something a.append(&mut b); assert_eq!(a.iter().cloned().collect::>(), [1, 2, 3, 4, 5, 6]); - #[cfg(not(miri))] assert_eq!(b.iter().cloned().collect::>(), []); // append something to nothing b.append(&mut a); assert_eq!(b.iter().cloned().collect::>(), [1, 2, 3, 4, 5, 6]); - #[cfg(not(miri))] assert_eq!(a.iter().cloned().collect::>(), []); } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri is too slow fn test_append_permutations() { fn construct_vec_deque( push_back: usize, @@ -1125,7 +1122,7 @@ fn test_reserve_exact_2() { } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support signalling OOM fn test_try_reserve() { // These are the interesting cases: @@ -1227,7 +1224,7 @@ fn test_try_reserve() { } #[test] -#[cfg(not(miri))] +#[cfg(not(miri))] // Miri does not support signalling OOM fn test_try_reserve_exact() { // This is exactly the same as test_try_reserve with the method changed. From 4c1a1c38305d72fc564f554ae980105d74331108 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 13 Feb 2019 17:18:47 +0100 Subject: [PATCH 23/41] review failures in btree, string --- src/liballoc/tests/btree/map.rs | 28 ++++++++++++++++++++++++++++ src/liballoc/tests/btree/mod.rs | 2 -- src/liballoc/tests/string.rs | 13 +++++++++++-- src/liballoc/tests/vec_deque.rs | 4 +++- src/libcore/tests/fmt/builders.rs | 1 - 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/liballoc/tests/btree/map.rs b/src/liballoc/tests/btree/map.rs index aaf504073285d..a92e747904895 100644 --- a/src/liballoc/tests/btree/map.rs +++ b/src/liballoc/tests/btree/map.rs @@ -7,6 +7,7 @@ use std::iter::FromIterator; use super::DeterministicRng; #[test] +#[cfg(not(miri))] // Miri is too slow fn test_basic_large() { let mut map = BTreeMap::new(); let size = 10000; @@ -69,7 +70,10 @@ fn test_basic_small() { #[test] fn test_iter() { + #[cfg(not(miri))] // Miri is too slow let size = 10000; + #[cfg(miri)] + let size = 100; // Forwards let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); @@ -91,7 +95,10 @@ fn test_iter() { #[test] fn test_iter_rev() { + #[cfg(not(miri))] // Miri is too slow let size = 10000; + #[cfg(miri)] + let size = 100; // Forwards let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); @@ -127,7 +134,10 @@ fn test_values_mut() { #[test] fn test_iter_mixed() { + #[cfg(not(miri))] // Miri is too slow let size = 10000; + #[cfg(miri)] + let size = 100; // Forwards let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); @@ -214,6 +224,7 @@ fn test_range_equal_empty_cases() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_range_equal_excluded() { let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect(); map.range((Excluded(2), Excluded(2))); @@ -221,6 +232,7 @@ fn test_range_equal_excluded() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_range_backwards_1() { let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect(); map.range((Included(3), Included(2))); @@ -228,6 +240,7 @@ fn test_range_backwards_1() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_range_backwards_2() { let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect(); map.range((Included(3), Excluded(2))); @@ -235,6 +248,7 @@ fn test_range_backwards_2() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_range_backwards_3() { let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect(); map.range((Excluded(3), Included(2))); @@ -242,6 +256,7 @@ fn test_range_backwards_3() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_range_backwards_4() { let map: BTreeMap<_, _> = (0..5).map(|i| (i, i)).collect(); map.range((Excluded(3), Excluded(2))); @@ -249,7 +264,10 @@ fn test_range_backwards_4() { #[test] fn test_range_1000() { + #[cfg(not(miri))] // Miri is too slow let size = 1000; + #[cfg(miri)] + let size = 100; let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); fn test(map: &BTreeMap, size: u32, min: Bound<&u32>, max: Bound<&u32>) { @@ -286,7 +304,10 @@ fn test_range_borrowed_key() { #[test] fn test_range() { + #[cfg(not(miri))] // Miri is too slow let size = 200; + #[cfg(miri)] + let size = 20; let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); for i in 0..size { @@ -305,7 +326,10 @@ fn test_range() { #[test] fn test_range_mut() { + #[cfg(not(miri))] // Miri is too slow let size = 200; + #[cfg(miri)] + let size = 20; let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); for i in 0..size { @@ -479,7 +503,10 @@ fn test_bad_zst() { #[test] fn test_clone() { let mut map = BTreeMap::new(); + #[cfg(not(miri))] // Miri is too slow let size = 100; + #[cfg(miri)] + let size = 20; assert_eq!(map.len(), 0); for i in 0..size { @@ -631,6 +658,7 @@ create_append_test!(test_append_145, 145); create_append_test!(test_append_170, 170); create_append_test!(test_append_181, 181); create_append_test!(test_append_239, 239); +#[cfg(not(miri))] // Miri is too slow create_append_test!(test_append_1700, 1700); fn rand_data(len: usize) -> Vec<(u32, u32)> { diff --git a/src/liballoc/tests/btree/mod.rs b/src/liballoc/tests/btree/mod.rs index 653b3f5bcb49d..4c704d0f8c28f 100644 --- a/src/liballoc/tests/btree/mod.rs +++ b/src/liballoc/tests/btree/mod.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - mod map; mod set; diff --git a/src/liballoc/tests/string.rs b/src/liballoc/tests/string.rs index e6ca54c408865..7e93d84fe3b97 100644 --- a/src/liballoc/tests/string.rs +++ b/src/liballoc/tests/string.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use std::borrow::Cow; use std::collections::CollectionAllocErr::*; use std::mem::size_of; @@ -233,6 +231,7 @@ fn test_split_off_empty() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_split_off_past_end() { let orig = "Hello, world!"; let mut split = String::from(orig); @@ -241,6 +240,7 @@ fn test_split_off_past_end() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_split_off_mid_char() { let mut orig = String::from("山"); orig.split_off(1); @@ -289,6 +289,7 @@ fn test_str_truncate_invalid_len() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_str_truncate_split_codepoint() { let mut s = String::from("\u{FC}"); // ü s.truncate(1); @@ -323,6 +324,7 @@ fn remove() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn remove_bad() { "ศ".to_string().remove(1); } @@ -358,11 +360,13 @@ fn insert() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn insert_bad1() { "".to_string().insert(1, 't'); } #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn insert_bad2() { "ệ".to_string().insert(1, 't'); } @@ -443,6 +447,7 @@ fn test_replace_range() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_replace_range_char_boundary() { let mut s = "Hello, 世界!".to_owned(); s.replace_range(..8, ""); @@ -459,6 +464,7 @@ fn test_replace_range_inclusive_range() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_replace_range_out_of_bounds() { let mut s = String::from("12345"); s.replace_range(5..6, "789"); @@ -466,6 +472,7 @@ fn test_replace_range_out_of_bounds() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_replace_range_inclusive_out_of_bounds() { let mut s = String::from("12345"); s.replace_range(5..=5, "789"); @@ -525,6 +532,7 @@ fn test_reserve_exact() { } #[test] +#[cfg(not(miri))] // Miri does not support signalling OOM fn test_try_reserve() { // These are the interesting cases: @@ -602,6 +610,7 @@ fn test_try_reserve() { } #[test] +#[cfg(not(miri))] // Miri does not support signalling OOM fn test_try_reserve_exact() { // This is exactly the same as test_try_reserve with the method changed. diff --git a/src/liballoc/tests/vec_deque.rs b/src/liballoc/tests/vec_deque.rs index d3439fed3cf3c..e0cb0e7a9e70c 100644 --- a/src/liballoc/tests/vec_deque.rs +++ b/src/liballoc/tests/vec_deque.rs @@ -921,7 +921,6 @@ fn test_append() { } #[test] -#[cfg(not(miri))] // Miri is too slow fn test_append_permutations() { fn construct_vec_deque( push_back: usize, @@ -945,7 +944,10 @@ fn test_append_permutations() { out } + #[cfg(not(miri))] // Miri is too slow const MAX: usize = 5; + #[cfg(miri)] + const MAX: usize = 3; // Many different permutations of both the `VecDeque` getting appended to // and the one getting appended are generated to check `append`. diff --git a/src/libcore/tests/fmt/builders.rs b/src/libcore/tests/fmt/builders.rs index 391250f998640..fd7192cc15119 100644 --- a/src/libcore/tests/fmt/builders.rs +++ b/src/libcore/tests/fmt/builders.rs @@ -488,7 +488,6 @@ mod debug_list { } #[test] -#[cfg(not(miri))] // FIXME uses code in liballoc, investigate Stacked Borrows failure fn test_formatting_parameters_are_forwarded() { use std::collections::{BTreeMap, BTreeSet}; #[derive(Debug)] From 767dadf8e0fb435ced260e8633add31d8fa7ccff Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 13 Feb 2019 17:49:11 +0100 Subject: [PATCH 24/41] review failures in heap, slice, vec --- src/liballoc/tests/heap.rs | 2 -- src/liballoc/tests/slice.rs | 22 ++++++++++++++++++++-- src/liballoc/tests/vec.rs | 12 ++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/liballoc/tests/heap.rs b/src/liballoc/tests/heap.rs index 7bc1aac7c8b59..c225ebfa96b91 100644 --- a/src/liballoc/tests/heap.rs +++ b/src/liballoc/tests/heap.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use std::alloc::{Global, Alloc, Layout, System}; /// Issue #45955. diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index 2a9fdfa9324d5..feba46b0fad78 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] - use std::cell::Cell; use std::cmp::Ordering::{self, Equal, Greater, Less}; use std::mem; @@ -260,6 +258,7 @@ fn test_swap_remove() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_swap_remove_fail() { let mut v = vec![1]; let _ = v.swap_remove(0); @@ -391,6 +390,7 @@ fn test_reverse() { } #[test] +#[cfg(not(miri))] // Miri does not support entropy fn test_sort() { let mut rng = thread_rng(); @@ -467,6 +467,7 @@ fn test_sort() { } #[test] +#[cfg(not(miri))] // Miri does not support entropy fn test_sort_stability() { for len in (2..25).chain(500..510) { for _ in 0..10 { @@ -631,6 +632,7 @@ fn test_insert() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_insert_oob() { let mut a = vec![1, 2, 3]; a.insert(4, 5); @@ -655,6 +657,7 @@ fn test_remove() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_remove_fail() { let mut a = vec![1]; let _ = a.remove(0); @@ -936,6 +939,7 @@ fn test_windowsator() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_windowsator_0() { let v = &[1, 2, 3, 4]; let _it = v.windows(0); @@ -960,6 +964,7 @@ fn test_chunksator() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_chunksator_0() { let v = &[1, 2, 3, 4]; let _it = v.chunks(0); @@ -984,6 +989,7 @@ fn test_chunks_exactator() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_chunks_exactator_0() { let v = &[1, 2, 3, 4]; let _it = v.chunks_exact(0); @@ -1008,6 +1014,7 @@ fn test_rchunksator() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_rchunksator_0() { let v = &[1, 2, 3, 4]; let _it = v.rchunks(0); @@ -1032,6 +1039,7 @@ fn test_rchunks_exactator() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_rchunks_exactator_0() { let v = &[1, 2, 3, 4]; let _it = v.rchunks_exact(0); @@ -1084,6 +1092,7 @@ fn test_vec_default() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_overflow_does_not_cause_segfault() { let mut v = vec![]; v.reserve_exact(!0); @@ -1093,6 +1102,7 @@ fn test_overflow_does_not_cause_segfault() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_overflow_does_not_cause_segfault_managed() { let mut v = vec![Rc::new(1)]; v.reserve_exact(!0); @@ -1268,6 +1278,7 @@ fn test_mut_chunks_rev() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mut_chunks_0() { let mut v = [1, 2, 3, 4]; let _it = v.chunks_mut(0); @@ -1300,6 +1311,7 @@ fn test_mut_chunks_exact_rev() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mut_chunks_exact_0() { let mut v = [1, 2, 3, 4]; let _it = v.chunks_exact_mut(0); @@ -1332,6 +1344,7 @@ fn test_mut_rchunks_rev() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mut_rchunks_0() { let mut v = [1, 2, 3, 4]; let _it = v.rchunks_mut(0); @@ -1364,6 +1377,7 @@ fn test_mut_rchunks_exact_rev() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_mut_rchunks_exact_0() { let mut v = [1, 2, 3, 4]; let _it = v.rchunks_exact_mut(0); @@ -1397,6 +1411,7 @@ fn test_box_slice_clone() { #[test] #[allow(unused_must_use)] // here, we care about the side effects of `.clone()` #[cfg_attr(target_os = "emscripten", ignore)] +#[cfg(not(miri))] // Miri does not support panics fn test_box_slice_clone_panics() { use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -1461,6 +1476,7 @@ fn test_copy_from_slice() { #[test] #[should_panic(expected = "destination and source slices have different lengths")] +#[cfg(not(miri))] // Miri does not support panics fn test_copy_from_slice_dst_longer() { let src = [0, 1, 2, 3]; let mut dst = [0; 5]; @@ -1469,6 +1485,7 @@ fn test_copy_from_slice_dst_longer() { #[test] #[should_panic(expected = "destination and source slices have different lengths")] +#[cfg(not(miri))] // Miri does not support panics fn test_copy_from_slice_dst_shorter() { let src = [0, 1, 2, 3]; let mut dst = [0; 3]; @@ -1588,6 +1605,7 @@ thread_local!(static SILENCE_PANIC: Cell = Cell::new(false)); #[test] #[cfg_attr(target_os = "emscripten", ignore)] // no threads +#[cfg(not(miri))] // Miri does not support panics fn panic_safe() { let prev = panic::take_hook(); panic::set_hook(Box::new(move |info| { diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 545332bcd6a2f..6e4ca1d90e642 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -368,6 +368,7 @@ fn test_vec_truncate_drop() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_vec_truncate_fail() { struct BadElem(i32); impl Drop for BadElem { @@ -391,6 +392,7 @@ fn test_index() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_index_out_of_bounds() { let vec = vec![1, 2, 3]; let _ = vec[3]; @@ -398,6 +400,7 @@ fn test_index_out_of_bounds() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_slice_out_of_bounds_1() { let x = vec![1, 2, 3, 4, 5]; &x[!0..]; @@ -405,6 +408,7 @@ fn test_slice_out_of_bounds_1() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_slice_out_of_bounds_2() { let x = vec![1, 2, 3, 4, 5]; &x[..6]; @@ -412,6 +416,7 @@ fn test_slice_out_of_bounds_2() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_slice_out_of_bounds_3() { let x = vec![1, 2, 3, 4, 5]; &x[!0..4]; @@ -419,6 +424,7 @@ fn test_slice_out_of_bounds_3() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_slice_out_of_bounds_4() { let x = vec![1, 2, 3, 4, 5]; &x[1..6]; @@ -426,6 +432,7 @@ fn test_slice_out_of_bounds_4() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_slice_out_of_bounds_5() { let x = vec![1, 2, 3, 4, 5]; &x[3..2]; @@ -433,6 +440,7 @@ fn test_slice_out_of_bounds_5() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_swap_remove_empty() { let mut vec = Vec::::new(); vec.swap_remove(0); @@ -503,6 +511,7 @@ fn test_drain_items_zero_sized() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_drain_out_of_bounds() { let mut v = vec![1, 2, 3, 4, 5]; v.drain(5..6); @@ -576,6 +585,7 @@ fn test_drain_max_vec_size() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_drain_inclusive_out_of_bounds() { let mut v = vec![1, 2, 3, 4, 5]; v.drain(5..=5); @@ -605,6 +615,7 @@ fn test_splice_inclusive_range() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_splice_out_of_bounds() { let mut v = vec![1, 2, 3, 4, 5]; let a = [10, 11, 12]; @@ -613,6 +624,7 @@ fn test_splice_out_of_bounds() { #[test] #[should_panic] +#[cfg(not(miri))] // Miri does not support panics fn test_splice_inclusive_out_of_bounds() { let mut v = vec![1, 2, 3, 4, 5]; let a = [10, 11, 12]; From c154bf7db4d5737b55c6f85c69df136c374db3a5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 13 Feb 2019 18:11:57 +0100 Subject: [PATCH 25/41] miri: test with slightly larger BTrees --- src/liballoc/tests/btree/map.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/liballoc/tests/btree/map.rs b/src/liballoc/tests/btree/map.rs index a92e747904895..f14750089c956 100644 --- a/src/liballoc/tests/btree/map.rs +++ b/src/liballoc/tests/btree/map.rs @@ -7,10 +7,12 @@ use std::iter::FromIterator; use super::DeterministicRng; #[test] -#[cfg(not(miri))] // Miri is too slow fn test_basic_large() { let mut map = BTreeMap::new(); + #[cfg(not(miri))] // Miri is too slow let size = 10000; + #[cfg(miri)] + let size = 200; assert_eq!(map.len(), 0); for i in 0..size { @@ -73,7 +75,7 @@ fn test_iter() { #[cfg(not(miri))] // Miri is too slow let size = 10000; #[cfg(miri)] - let size = 100; + let size = 200; // Forwards let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); @@ -98,7 +100,7 @@ fn test_iter_rev() { #[cfg(not(miri))] // Miri is too slow let size = 10000; #[cfg(miri)] - let size = 100; + let size = 200; // Forwards let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); @@ -137,7 +139,7 @@ fn test_iter_mixed() { #[cfg(not(miri))] // Miri is too slow let size = 10000; #[cfg(miri)] - let size = 100; + let size = 200; // Forwards let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); @@ -267,7 +269,7 @@ fn test_range_1000() { #[cfg(not(miri))] // Miri is too slow let size = 1000; #[cfg(miri)] - let size = 100; + let size = 200; let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); fn test(map: &BTreeMap, size: u32, min: Bound<&u32>, max: Bound<&u32>) { @@ -307,7 +309,7 @@ fn test_range() { #[cfg(not(miri))] // Miri is too slow let size = 200; #[cfg(miri)] - let size = 20; + let size = 30; let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); for i in 0..size { @@ -329,7 +331,7 @@ fn test_range_mut() { #[cfg(not(miri))] // Miri is too slow let size = 200; #[cfg(miri)] - let size = 20; + let size = 30; let mut map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect(); for i in 0..size { @@ -506,7 +508,7 @@ fn test_clone() { #[cfg(not(miri))] // Miri is too slow let size = 100; #[cfg(miri)] - let size = 20; + let size = 30; assert_eq!(map.len(), 0); for i in 0..size { From a301655c8aed20e5cea9a062663820fc29c5e80c Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 13 Feb 2019 12:20:23 -0800 Subject: [PATCH 26/41] Use posix_spawn_file_actions_addchdir_np when possible This is a non-POSIX extension implemented in Solaris and in glibc 2.29. With this we can still use `posix_spawn()` when `Command::current_dir()` has been set, otherwise we fallback to `fork(); chdir(); exec()`. --- src/libstd/sys/unix/process/process_unix.rs | 24 +++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/process/process_unix.rs b/src/libstd/sys/unix/process/process_unix.rs index 12d3e9b13b115..6fbbbb349b171 100644 --- a/src/libstd/sys/unix/process/process_unix.rs +++ b/src/libstd/sys/unix/process/process_unix.rs @@ -281,8 +281,7 @@ impl Command { use mem; use sys; - if self.get_cwd().is_some() || - self.get_gid().is_some() || + if self.get_gid().is_some() || self.get_uid().is_some() || self.env_saw_path() || self.get_closures().len() != 0 { @@ -301,6 +300,24 @@ impl Command { } } + // Solaris and glibc 2.29+ can set a new working directory, and maybe + // others will gain this non-POSIX function too. We'll check for this + // weak symbol as soon as it's needed, so we can return early otherwise + // to do a manual chdir before exec. + weak! { + fn posix_spawn_file_actions_addchdir_np( + *mut libc::posix_spawn_file_actions_t, + *const libc::c_char + ) -> libc::c_int + } + let addchdir = match self.get_cwd() { + Some(cwd) => match posix_spawn_file_actions_addchdir_np.get() { + Some(f) => Some((f, cwd)), + None => return Ok(None), + }, + None => None, + }; + let mut p = Process { pid: 0, status: None }; struct PosixSpawnFileActions(libc::posix_spawn_file_actions_t); @@ -345,6 +362,9 @@ impl Command { fd, libc::STDERR_FILENO))?; } + if let Some((f, cwd)) = addchdir { + cvt(f(&mut file_actions.0, cwd.as_ptr()))?; + } let mut set: libc::sigset_t = mem::uninitialized(); cvt(libc::sigemptyset(&mut set))?; From 6bce2b81986a1a8da930c11b9b9d907a792b3f61 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Wed, 13 Feb 2019 22:29:27 +0100 Subject: [PATCH 27/41] Whitelist the ARM v6 target-feature --- src/librustc_codegen_llvm/llvm_util.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_codegen_llvm/llvm_util.rs b/src/librustc_codegen_llvm/llvm_util.rs index b46e6ef84b98b..9fe0a4c45f9f4 100644 --- a/src/librustc_codegen_llvm/llvm_util.rs +++ b/src/librustc_codegen_llvm/llvm_util.rs @@ -100,6 +100,7 @@ const ARM_WHITELIST: &[(&str, Option<&str>)] = &[ ("dsp", Some("arm_target_feature")), ("neon", Some("arm_target_feature")), ("v5te", Some("arm_target_feature")), + ("v6", Some("arm_target_feature")), ("v6k", Some("arm_target_feature")), ("v6t2", Some("arm_target_feature")), ("v7", Some("arm_target_feature")), From f565efd617fc2b74bca7fa637faf9c6241008442 Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Wed, 13 Feb 2019 19:57:12 -0500 Subject: [PATCH 28/41] mask `compiler_builtins` docs Since `compiler_builtins` is being injected automatically, its docs aren't masked. This commit masks the crate's docs if it's brought in as an extern crate. --- src/librustdoc/clean/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b0bb033b94b25..3044704718b4a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -165,7 +165,12 @@ impl<'a, 'tcx, 'rcx> Clean for visit_ast::RustdocVisitor<'a, 'tcx, 'rcx> match module.inner { ModuleItem(ref module) => { for it in &module.items { - if it.is_extern_crate() && it.attrs.has_doc_flag("masked") { + // `compiler_builtins` should be masked too, but we can't apply + // `#[doc(masked)]` to the injected `extern crate` because it's unstable. + if it.is_extern_crate() + && (it.attrs.has_doc_flag("masked") + || self.cx.tcx.is_compiler_builtins(it.def_id.krate)) + { masked_crates.insert(it.def_id.krate); } } From 2c339aeb7bec40777b606889b9bd256fcea1dece Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 5 Feb 2019 21:27:26 +0100 Subject: [PATCH 29/41] Add specific error for unstable const fn features --- src/librustc_mir/diagnostics.rs | 31 ++++++++++++++++++++ src/librustc_mir/transform/qualify_consts.rs | 12 +++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index 31aa3c2782697..084a6529908df 100644 --- a/src/librustc_mir/diagnostics.rs +++ b/src/librustc_mir/diagnostics.rs @@ -2370,6 +2370,37 @@ let value = (&foo(), &foo()); ``` "##, +E0723: r##" +An feature unstable in `const` contexts was used. + +Erroneous code example: + +```compile_fail,E0723 +trait T {} + +impl T for () {} + +const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable + () +} +``` + +To enable this feature on a nightly version of rustc, add the `const_fn` +feature flag: + +```compile_fail,E0723 +#![feature(const_fn)] + +trait T {} + +impl T for () {} + +const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable + () +} +``` +"##, + } register_diagnostics! { diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index c593be4e67f45..2066a50e7fbb8 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1206,7 +1206,17 @@ impl MirPass for QualifyAndPromoteConstants { // enforce `min_const_fn` for stable const fns use super::qualify_min_const_fn::is_min_const_fn; if let Err((span, err)) = is_min_const_fn(tcx, def_id, mir) { - tcx.sess.span_err(span, &err); + let mut diag = struct_span_err!( + tcx.sess, + span, + E0723, + "{} (see issue #57563)", + err, + ); + diag.help( + "add #![feature(const_fn)] to the crate attributes to enable", + ); + diag.emit(); } else { // this should not produce any errors, but better safe than sorry // FIXME(#53819) From feb3408f112cb362e15f5a33bdcc1e01724244ee Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 5 Feb 2019 21:27:44 +0100 Subject: [PATCH 30/41] Update const fn tests --- .../min_const_fn/bad_const_fn_body_ice.stderr | 4 +- .../ui/consts/min_const_fn/cast_errors.stderr | 21 ++- .../min_const_fn/cmp_fn_pointers.stderr | 5 +- .../ui/consts/min_const_fn/loop_ice.stderr | 5 +- .../consts/min_const_fn/min_const_fn.stderr | 135 +++++++++++++----- .../min_const_fn/min_const_fn_dyn.stderr | 9 +- .../min_const_fn/min_const_fn_fn_ptr.stderr | 9 +- .../min_const_fn_libstd_stability.stderr | 17 ++- ...in_const_unsafe_fn_libstd_stability.stderr | 17 ++- ...n_const_unsafe_fn_libstd_stability2.stderr | 13 +- .../consts/min_const_fn/mutable_borrow.stderr | 9 +- .../ui/consts/single_variant_match_ice.stderr | 7 +- src/test/ui/issues/issue-37550.stderr | 5 +- src/test/ui/unsafe/ranged_ints2_const.stderr | 11 +- 14 files changed, 202 insertions(+), 65 deletions(-) diff --git a/src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr b/src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr index f6b704370b6f2..62f678790d21f 100644 --- a/src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr +++ b/src/test/ui/consts/min_const_fn/bad_const_fn_body_ice.stderr @@ -1,10 +1,12 @@ -error: heap allocations are not allowed in const fn +error[E0723]: heap allocations are not allowed in const fn (see issue #57563) --> $DIR/bad_const_fn_body_ice.rs:2:5 | LL | vec![1, 2, 3] //~ ERROR heap allocations are not allowed in const fn | ^^^^^^^^^^^^^ | + = help: add #![feature(const_fn)] to the crate attributes to enable = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to previous error +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/cast_errors.stderr b/src/test/ui/consts/min_const_fn/cast_errors.stderr index ba980b7aacb6c..b5af3e7ee4665 100644 --- a/src/test/ui/consts/min_const_fn/cast_errors.stderr +++ b/src/test/ui/consts/min_const_fn/cast_errors.stderr @@ -1,32 +1,43 @@ -error: unsizing casts are not allowed in const fn +error[E0723]: unsizing casts are not allowed in const fn (see issue #57563) --> $DIR/cast_errors.rs:3:41 | LL | const fn unsize(x: &[u8; 3]) -> &[u8] { x } | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/cast_errors.rs:5:23 | LL | const fn closure() -> fn() { || {} } | ^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/cast_errors.rs:8:5 | LL | (|| {}) as fn(); | ^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/cast_errors.rs:11:28 | LL | const fn reify(f: fn()) -> unsafe fn() { f } | ^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/cast_errors.rs:13:21 | LL | const fn reify2() { main as unsafe fn(); } | ^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 5 previous errors +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr b/src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr index a050c10e02cf9..d84e2651d4fc4 100644 --- a/src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr +++ b/src/test/ui/consts/min_const_fn/cmp_fn_pointers.stderr @@ -1,8 +1,11 @@ -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/cmp_fn_pointers.rs:1:14 | LL | const fn cmp(x: fn(), y: fn()) -> bool { //~ ERROR function pointers in const fn are unstable | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to previous error +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/loop_ice.stderr b/src/test/ui/consts/min_const_fn/loop_ice.stderr index 1424cea65afd5..716e8380c45da 100644 --- a/src/test/ui/consts/min_const_fn/loop_ice.stderr +++ b/src/test/ui/consts/min_const_fn/loop_ice.stderr @@ -1,8 +1,11 @@ -error: loops are not allowed in const fn +error[E0723]: loops are not allowed in const fn (see issue #57563) --> $DIR/loop_ice.rs:2:5 | LL | loop {} //~ ERROR loops are not allowed in const fn | ^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to previous error +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.stderr index 52c60c57b8fb3..e095ccaf20e29 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn.stderr @@ -4,11 +4,13 @@ error[E0493]: destructors cannot be evaluated at compile-time LL | const fn into_inner(self) -> T { self.0 } //~ destructors cannot be evaluated | ^^^^ constant functions cannot evaluate destructors -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:39:36 | LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error[E0493]: destructors cannot be evaluated at compile-time --> $DIR/min_const_fn.rs:44:28 @@ -16,11 +18,13 @@ error[E0493]: destructors cannot be evaluated at compile-time LL | const fn into_inner_lt(self) -> T { self.0 } //~ destructors cannot be evaluated | ^^^^ constant functions cannot evaluate destructors -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:46:42 | LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error[E0493]: destructors cannot be evaluated at compile-time --> $DIR/min_const_fn.rs:51:27 @@ -28,192 +32,255 @@ error[E0493]: destructors cannot be evaluated at compile-time LL | const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructors | ^^^^ constant functions cannot evaluate destructors -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:53:38 | LL | const fn get_mut_s(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:58:39 | LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:76:16 | LL | const fn foo11(t: T) -> T { t } | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:78:18 | LL | const fn foo11_2(t: T) -> T { t } | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int, `bool` and `char` operations are stable in const fn +error[E0723]: only int, `bool` and `char` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:80:33 | LL | const fn foo19(f: f32) -> f32 { f * 2.0 } | ^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int, `bool` and `char` operations are stable in const fn +error[E0723]: only int, `bool` and `char` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:82:35 | LL | const fn foo19_2(f: f32) -> f32 { 2.0 - f } | ^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int and `bool` operations are stable in const fn +error[E0723]: only int and `bool` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:84:35 | LL | const fn foo19_3(f: f32) -> f32 { -f } | ^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int, `bool` and `char` operations are stable in const fn +error[E0723]: only int, `bool` and `char` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:86:43 | LL | const fn foo19_4(f: f32, g: f32) -> f32 { f / g } | ^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: cannot access `static` items in const fn +error[E0723]: cannot access `static` items in const fn (see issue #57563) --> $DIR/min_const_fn.rs:90:27 | LL | const fn foo25() -> u32 { BAR } //~ ERROR cannot access `static` items in const fn | ^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: cannot access `static` items in const fn +error[E0723]: cannot access `static` items in const fn (see issue #57563) --> $DIR/min_const_fn.rs:91:36 | LL | const fn foo26() -> &'static u32 { &BAR } //~ ERROR cannot access `static` items | ^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: casting pointers to ints is unstable in const fn +error[E0723]: casting pointers to ints is unstable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:92:42 | LL | const fn foo30(x: *const u32) -> usize { x as usize } | ^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: casting pointers to ints is unstable in const fn +error[E0723]: casting pointers to ints is unstable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:94:63 | LL | const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } } | ^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: casting pointers to ints is unstable in const fn +error[E0723]: casting pointers to ints is unstable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:96:42 | LL | const fn foo30_2(x: *mut u32) -> usize { x as usize } | ^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: casting pointers to ints is unstable in const fn +error[E0723]: casting pointers to ints is unstable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:98:63 | LL | const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } } | ^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:100:38 | LL | const fn foo30_4(b: bool) -> usize { if b { 1 } else { 42 } } | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:102:29 | LL | const fn foo30_5(b: bool) { while b { } } //~ ERROR not stable in const fn | ^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:104:44 | LL | const fn foo36(a: bool, b: bool) -> bool { a && b } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:106:44 | LL | const fn foo37(a: bool, b: bool) -> bool { a || b } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:108:14 | LL | const fn inc(x: &mut i32) { *x += 1 } | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:113:6 | LL | impl Foo { | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:118:6 | LL | impl Foo { | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:123:6 | LL | impl Foo { | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `impl Trait` in const fn is unstable +error[E0723]: `impl Trait` in const fn is unstable (see issue #57563) --> $DIR/min_const_fn.rs:129:24 | LL | const fn no_rpit2() -> AlanTuring { AlanTuring(0) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:131:34 | LL | const fn no_apit2(_x: AlanTuring) {} | ^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:133:22 | LL | const fn no_apit(_x: impl std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized` | ^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `impl Trait` in const fn is unstable +error[E0723]: `impl Trait` in const fn is unstable (see issue #57563) --> $DIR/min_const_fn.rs:134:23 | LL | const fn no_rpit() -> impl std::fmt::Debug {} //~ ERROR `impl Trait` in const fn is unstable | ^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:135:23 | LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized` | ^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:136:32 | LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:141:41 | LL | const fn really_no_traits_i_mean_it() { (&() as &std::fmt::Debug, ()).1 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:144:21 | LL | const fn no_fn_ptrs(_x: fn()) {} | ^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:146:27 | LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo } | ^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 36 previous errors -For more information about this error, try `rustc --explain E0493`. +Some errors occurred: E0493, E0723. +For more information about an error, try `rustc --explain E0493`. diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr index 8179cf795b48c..8ff963722cf15 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr @@ -1,14 +1,19 @@ -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn_dyn.rs:9:5 | LL | x.0.field; | ^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn_dyn.rs:12:66 | LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) } | ^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_fn_ptr.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_fn_ptr.stderr index c1cb19180a5ee..8838ababe2c0e 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_fn_ptr.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_fn_ptr.stderr @@ -1,14 +1,19 @@ -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/min_const_fn_fn_ptr.rs:11:5 | LL | x.0.field; | ^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/min_const_fn_fn_ptr.rs:14:59 | LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasPtr { field }) } | ^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr index 9640105d25c54..1e6f698b3c8e3 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_libstd_stability.stderr @@ -1,26 +1,35 @@ -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_fn_libstd_stability.rs:15:25 | LL | const fn bar() -> u32 { foo() } //~ ERROR can only call other `min_const_fn` | ^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_fn_libstd_stability.rs:22:26 | LL | const fn bar2() -> u32 { foo2() } //~ ERROR can only call other `min_const_fn` | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int, `bool` and `char` operations are stable in const fn +error[E0723]: only int, `bool` and `char` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn_libstd_stability.rs:26:26 | LL | const fn bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool` and `char` operations | ^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_fn_libstd_stability.rs:34:32 | LL | const fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `min_const_fn` | ^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr index 049c25e71913d..07d10984392d8 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr @@ -1,26 +1,35 @@ -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_unsafe_fn_libstd_stability.rs:15:41 | LL | const unsafe fn bar() -> u32 { unsafe { foo() } } //~ ERROR can only call other `min_const_fn` | ^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_unsafe_fn_libstd_stability.rs:22:42 | LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } } //~ ERROR can only call other `min_const_fn` | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int, `bool` and `char` operations are stable in const fn +error[E0723]: only int, `bool` and `char` operations are stable in const fn (see issue #57563) --> $DIR/min_const_unsafe_fn_libstd_stability.rs:26:33 | LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool` and `char` op | ^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_unsafe_fn_libstd_stability.rs:34:48 | LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } } //~ ERROR can only call other | ^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr index 89509f813e107..7cb8c6e62ec60 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr @@ -1,20 +1,27 @@ -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:15:32 | LL | const unsafe fn bar() -> u32 { foo() } //~ ERROR can only call other `min_const_fn` | ^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:22:33 | LL | const unsafe fn bar2() -> u32 { foo2() } //~ ERROR can only call other `min_const_fn` | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: can only call other `min_const_fn` within a `min_const_fn` +error[E0723]: can only call other `min_const_fn` within a `min_const_fn` (see issue #57563) --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:30:39 | LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `min_const_fn` | ^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/min_const_fn/mutable_borrow.stderr b/src/test/ui/consts/min_const_fn/mutable_borrow.stderr index 5ce0f30dc6e1f..e5a3502a3dc52 100644 --- a/src/test/ui/consts/min_const_fn/mutable_borrow.stderr +++ b/src/test/ui/consts/min_const_fn/mutable_borrow.stderr @@ -1,14 +1,19 @@ -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/mutable_borrow.rs:3:9 | LL | let b = &mut a; //~ ERROR mutable references in const fn | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/mutable_borrow.rs:12:13 | LL | let b = &mut a; //~ ERROR mutable references in const fn | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/consts/single_variant_match_ice.stderr b/src/test/ui/consts/single_variant_match_ice.stderr index f5c2cb5e0e9dc..5272062ccfc14 100644 --- a/src/test/ui/consts/single_variant_match_ice.stderr +++ b/src/test/ui/consts/single_variant_match_ice.stderr @@ -10,12 +10,15 @@ error[E0019]: constant contains unimplemented expression type LL | x => 42, //~ ERROR unimplemented expression type | ^ -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/single_variant_match_ice.rs:18:13 | LL | Prob => 0x1, //~ ERROR `if`, `match`, `&&` and `||` are not stable in const fn | ^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0019`. +Some errors occurred: E0019, E0723. +For more information about an error, try `rustc --explain E0019`. diff --git a/src/test/ui/issues/issue-37550.stderr b/src/test/ui/issues/issue-37550.stderr index d2b03416cb73c..97160af43bee4 100644 --- a/src/test/ui/issues/issue-37550.stderr +++ b/src/test/ui/issues/issue-37550.stderr @@ -1,8 +1,11 @@ -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/issue-37550.rs:3:9 | LL | let x = || t; //~ ERROR function pointers in const fn are unstable | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to previous error +For more information about this error, try `rustc --explain E0723`. diff --git a/src/test/ui/unsafe/ranged_ints2_const.stderr b/src/test/ui/unsafe/ranged_ints2_const.stderr index 39a55190b17de..fb3841948f11f 100644 --- a/src/test/ui/unsafe/ranged_ints2_const.stderr +++ b/src/test/ui/unsafe/ranged_ints2_const.stderr @@ -1,14 +1,18 @@ -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/ranged_ints2_const.rs:11:9 | LL | let y = &mut x.0; //~ ERROR references in const fn are unstable | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/ranged_ints2_const.rs:18:9 | LL | let y = unsafe { &mut x.0 }; //~ ERROR mutable references in const fn are unstable | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block --> $DIR/ranged_ints2_const.rs:11:13 @@ -20,4 +24,5 @@ LL | let y = &mut x.0; //~ ERROR references in const fn are unstable error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0133`. +Some errors occurred: E0133, E0723. +For more information about an error, try `rustc --explain E0133`. From 519783adb3e7f1d32c2758ca4c111a58892b78cc Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 5 Feb 2019 22:03:01 +0100 Subject: [PATCH 31/41] Fix documentation typo --- src/librustc_mir/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index 084a6529908df..4df3004a9ada6 100644 --- a/src/librustc_mir/diagnostics.rs +++ b/src/librustc_mir/diagnostics.rs @@ -2388,14 +2388,14 @@ const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable To enable this feature on a nightly version of rustc, add the `const_fn` feature flag: -```compile_fail,E0723 +``` #![feature(const_fn)] trait T {} impl T for () {} -const fn foo() -> impl T { // error: `impl Trait` in const fn is unstable +const fn foo() -> impl T { () } ``` From cce2c89e3bb7cb91610ea6891290491bf763bee3 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 14 Feb 2019 10:26:02 -0500 Subject: [PATCH 32/41] add .stderr file --- src/test/ui/issues/issue-57979.stderr | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/ui/issues/issue-57979.stderr diff --git a/src/test/ui/issues/issue-57979.stderr b/src/test/ui/issues/issue-57979.stderr new file mode 100644 index 0000000000000..488f30ab7c5a7 --- /dev/null +++ b/src/test/ui/issues/issue-57979.stderr @@ -0,0 +1,17 @@ +error[E0666]: nested `impl Trait` is not allowed + --> $DIR/issue-57979.rs:39:61 + | +LL | pub fn collect(_: impl IntoIterator>>>) { + | -----------------^^^^^^^^^^^^^^^^-- + | | | + | | nested `impl Trait` here + | outer `impl Trait` + +error[E0601]: `main` function not found in crate `issue_57979` + | + = note: consider adding a `main` function to `$DIR/issue-57979.rs` + +error: aborting due to 2 previous errors + +Some errors occurred: E0601, E0666. +For more information about an error, try `rustc --explain E0601`. From 8ca44069bbd8df4d88b08a0fb9fdb63895d60560 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 14 Feb 2019 15:47:37 +0000 Subject: [PATCH 33/41] Add updated NLL tests --- .../min_const_fn/min_const_fn.nll.stderr | 134 +++++++++++++----- .../min_const_fn/min_const_fn_dyn.nll.stderr | 11 +- 2 files changed, 108 insertions(+), 37 deletions(-) diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.nll.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.nll.stderr index 763c69e805030..feb4960e0c746 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn.nll.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn.nll.stderr @@ -4,11 +4,13 @@ error[E0493]: destructors cannot be evaluated at compile-time LL | const fn into_inner(self) -> T { self.0 } //~ destructors cannot be evaluated | ^^^^ constant functions cannot evaluate destructors -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:39:36 | LL | const fn get_mut(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error[E0493]: destructors cannot be evaluated at compile-time --> $DIR/min_const_fn.rs:44:28 @@ -16,11 +18,13 @@ error[E0493]: destructors cannot be evaluated at compile-time LL | const fn into_inner_lt(self) -> T { self.0 } //~ destructors cannot be evaluated | ^^^^ constant functions cannot evaluate destructors -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:46:42 | LL | const fn get_mut_lt(&'a mut self) -> &mut T { &mut self.0 } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error[E0493]: destructors cannot be evaluated at compile-time --> $DIR/min_const_fn.rs:51:27 @@ -28,173 +32,229 @@ error[E0493]: destructors cannot be evaluated at compile-time LL | const fn into_inner_s(self) -> T { self.0 } //~ ERROR destructors | ^^^^ constant functions cannot evaluate destructors -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:53:38 | LL | const fn get_mut_s(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:58:39 | LL | const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:76:16 | LL | const fn foo11(t: T) -> T { t } | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:78:18 | LL | const fn foo11_2(t: T) -> T { t } | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int, `bool` and `char` operations are stable in const fn +error[E0723]: only int, `bool` and `char` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:80:33 | LL | const fn foo19(f: f32) -> f32 { f * 2.0 } | ^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int, `bool` and `char` operations are stable in const fn +error[E0723]: only int, `bool` and `char` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:82:35 | LL | const fn foo19_2(f: f32) -> f32 { 2.0 - f } | ^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int and `bool` operations are stable in const fn +error[E0723]: only int and `bool` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:84:35 | LL | const fn foo19_3(f: f32) -> f32 { -f } | ^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: only int, `bool` and `char` operations are stable in const fn +error[E0723]: only int, `bool` and `char` operations are stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:86:43 | LL | const fn foo19_4(f: f32, g: f32) -> f32 { f / g } | ^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: cannot access `static` items in const fn +error[E0723]: cannot access `static` items in const fn (see issue #57563) --> $DIR/min_const_fn.rs:90:27 | LL | const fn foo25() -> u32 { BAR } //~ ERROR cannot access `static` items in const fn | ^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: cannot access `static` items in const fn +error[E0723]: cannot access `static` items in const fn (see issue #57563) --> $DIR/min_const_fn.rs:91:36 | LL | const fn foo26() -> &'static u32 { &BAR } //~ ERROR cannot access `static` items | ^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: casting pointers to ints is unstable in const fn +error[E0723]: casting pointers to ints is unstable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:92:42 | LL | const fn foo30(x: *const u32) -> usize { x as usize } | ^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: casting pointers to ints is unstable in const fn +error[E0723]: casting pointers to ints is unstable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:94:63 | LL | const fn foo30_with_unsafe(x: *const u32) -> usize { unsafe { x as usize } } | ^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: casting pointers to ints is unstable in const fn +error[E0723]: casting pointers to ints is unstable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:96:42 | LL | const fn foo30_2(x: *mut u32) -> usize { x as usize } | ^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: casting pointers to ints is unstable in const fn +error[E0723]: casting pointers to ints is unstable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:98:63 | LL | const fn foo30_2_with_unsafe(x: *mut u32) -> usize { unsafe { x as usize } } | ^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:100:38 | LL | const fn foo30_4(b: bool) -> usize { if b { 1 } else { 42 } } | ^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:102:29 | LL | const fn foo30_5(b: bool) { while b { } } //~ ERROR not stable in const fn | ^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:104:44 | LL | const fn foo36(a: bool, b: bool) -> bool { a && b } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `if`, `match`, `&&` and `||` are not stable in const fn +error[E0723]: `if`, `match`, `&&` and `||` are not stable in const fn (see issue #57563) --> $DIR/min_const_fn.rs:106:44 | LL | const fn foo37(a: bool, b: bool) -> bool { a || b } | ^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: mutable references in const fn are unstable +error[E0723]: mutable references in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:108:14 | LL | const fn inc(x: &mut i32) { *x += 1 } | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:113:6 | LL | impl Foo { | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:118:6 | LL | impl Foo { | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:123:6 | LL | impl Foo { | ^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `impl Trait` in const fn is unstable +error[E0723]: `impl Trait` in const fn is unstable (see issue #57563) --> $DIR/min_const_fn.rs:129:24 | LL | const fn no_rpit2() -> AlanTuring { AlanTuring(0) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:131:34 | LL | const fn no_apit2(_x: AlanTuring) {} | ^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:133:22 | LL | const fn no_apit(_x: impl std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized` | ^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: `impl Trait` in const fn is unstable +error[E0723]: `impl Trait` in const fn is unstable (see issue #57563) --> $DIR/min_const_fn.rs:134:23 | LL | const fn no_rpit() -> impl std::fmt::Debug {} //~ ERROR `impl Trait` in const fn is unstable | ^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:135:23 | LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {} //~ ERROR trait bounds other than `Sized` | ^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:136:32 | LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable warning[E0515]: cannot return reference to temporary value --> $DIR/min_const_fn.rs:136:63 @@ -208,25 +268,31 @@ LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() } = warning: this error has been downgraded to a warning for backwards compatibility with previous releases = warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn.rs:141:41 | LL | const fn really_no_traits_i_mean_it() { (&() as &std::fmt::Debug, ()).1 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:144:21 | LL | const fn no_fn_ptrs(_x: fn()) {} | ^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: function pointers in const fn are unstable +error[E0723]: function pointers in const fn are unstable (see issue #57563) --> $DIR/min_const_fn.rs:146:27 | LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo } | ^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable error: aborting due to 36 previous errors -Some errors occurred: E0493, E0515. +Some errors occurred: E0493, E0515, E0723. For more information about an error, try `rustc --explain E0493`. diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.nll.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.nll.stderr index 6dbe9b1c6ab10..2800d622f5353 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.nll.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.nll.stderr @@ -1,14 +1,18 @@ -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn_dyn.rs:9:5 | LL | x.0.field; | ^^^^^^^^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable -error: trait bounds other than `Sized` on const fn parameters are unstable +error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable (see issue #57563) --> $DIR/min_const_fn_dyn.rs:12:66 | LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) } | ^^ + | + = help: add #![feature(const_fn)] to the crate attributes to enable warning[E0716]: temporary value dropped while borrowed --> $DIR/min_const_fn_dyn.rs:12:67 @@ -24,4 +28,5 @@ LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) } error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0716`. +Some errors occurred: E0716, E0723. +For more information about an error, try `rustc --explain E0716`. From b5ab2c7f1cf31a642c826047ed1025f4fc13d879 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 14 Feb 2019 20:00:16 +0100 Subject: [PATCH 34/41] split MaybeUninit into several features, expand docs a bit --- src/liballoc/collections/btree/node.rs | 4 +- src/liballoc/lib.rs | 2 +- src/libcore/lib.rs | 2 +- src/libcore/macros.rs | 4 +- src/libcore/mem.rs | 76 +++++++++++++++++--------- 5 files changed, 55 insertions(+), 33 deletions(-) diff --git a/src/liballoc/collections/btree/node.rs b/src/liballoc/collections/btree/node.rs index eb0667228d1ff..fc1c187892471 100644 --- a/src/liballoc/collections/btree/node.rs +++ b/src/liballoc/collections/btree/node.rs @@ -453,7 +453,7 @@ impl NodeRef { root: self.root, _marker: PhantomData }, - idx: unsafe { usize::from(*self.as_header().parent_idx.get_ref()) }, + idx: unsafe { usize::from(*self.as_header().parent_idx.as_ptr()) }, _marker: PhantomData }) } else { @@ -1143,7 +1143,7 @@ impl NodeRef { height: self.node.height - 1, node: unsafe { - self.node.as_internal().edges.get_unchecked(self.idx).get_ref().as_ptr() + (&*self.node.as_internal().edges.get_unchecked(self.idx).as_ptr()).as_ptr() }, root: self.node.root, _marker: PhantomData diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index d4ee428a3b5c7..2f23a697a58c1 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -112,7 +112,7 @@ #![feature(rustc_const_unstable)] #![feature(const_vec_new)] #![feature(slice_partition_dedup)] -#![feature(maybe_uninit)] +#![feature(maybe_uninit, maybe_uninit_slice)] #![feature(alloc_layout_extra)] #![feature(try_trait)] diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 227fb22bc7d93..2c0d0dd149072 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -122,7 +122,7 @@ #![feature(structural_match)] #![feature(abi_unadjusted)] #![feature(adx_target_feature)] -#![feature(maybe_uninit)] +#![feature(maybe_uninit, maybe_uninit_slice)] #![feature(unrestricted_attribute_tokens)] #[prelude_import] diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index b9b235969dad8..02f8065eb210d 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -563,11 +563,11 @@ macro_rules! unimplemented { /// A macro to create an array of [`MaybeUninit`] /// -/// This macro constructs and uninitialized array of the type `[MaybeUninit; N]`. +/// This macro constructs an uninitialized array of the type `[MaybeUninit; N]`. /// /// [`MaybeUninit`]: mem/union.MaybeUninit.html #[macro_export] -#[unstable(feature = "maybe_uninit", issue = "53491")] +#[unstable(feature = "maybe_uninit_slice", issue = "53491")] macro_rules! uninitialized_array { // This `into_initialized` is safe because an array of `MaybeUninit` does not // require initialization. diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 2a493e88fe896..c4443a25d8c2d 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -1045,17 +1045,34 @@ impl DerefMut for ManuallyDrop { /// ever gets used to access memory: /// /// ```rust,no_run -/// use std::mem; +/// #![feature(maybe_uninit)] +/// use std::mem::{self, MaybeUninit}; /// /// let x: &i32 = unsafe { mem::zeroed() }; // undefined behavior! +/// // equivalent code with `MaybeUninit` +/// let x: &i32 = unsafe { MaybeUninit::zeroed().into_initialized() }; // undefined behavior! /// ``` /// /// This is exploited by the compiler for various optimizations, such as eliding /// run-time checks and optimizing `enum` layout. /// -/// Not initializing memory at all (instead of zero--initializing it) causes the same +/// Not initializing memory at all (instead of zero-initializing it) causes the same /// issue: after all, the initial value of the variable might just happen to be -/// one that violates the invariant. +/// one that violates the invariant. Moreover, uninitialized memory is special +/// in that the compiler knows that it does not have a fixed value. This makes +/// it undefined behavior to have uninitialized data in a variable even if that +/// variable has otherwise no restrictions about which values are valid: +/// +/// ```rust,no_run +/// #![feature(maybe_uninit)] +/// use std::mem::{self, MaybeUninit}; +/// +/// let x: i32 = unsafe { mem::uninitialized() }; // undefined behavior! +/// // equivalent code with `MaybeUninit` +/// let x: i32 = unsafe { MaybeUninit::uninitialized().into_initialized() }; // undefined behavior! +/// ``` +/// (Notice that the rules around uninitialized integers are not finalized yet, but +/// until they are, it is advisable to avoid them.) /// /// `MaybeUninit` serves to enable unsafe code to deal with uninitialized data: /// it is a signal to the compiler indicating that the data here might *not* @@ -1065,7 +1082,8 @@ impl DerefMut for ManuallyDrop { /// #![feature(maybe_uninit)] /// use std::mem::MaybeUninit; /// -/// // Create an explicitly uninitialized reference. +/// // Create an explicitly uninitialized reference. The compiler knows that data inside +/// // a `MaybeUninit` may be invalid, and hence this is not UB: /// let mut x = MaybeUninit::<&i32>::uninitialized(); /// // Set it to a valid value. /// x.set(&0); @@ -1075,6 +1093,7 @@ impl DerefMut for ManuallyDrop { /// ``` /// /// The compiler then knows to not optimize this code. +// FIXME before stabilizing, explain how to initialize a struct field-by-field. #[allow(missing_debug_implementations)] #[unstable(feature = "maybe_uninit", issue = "53491")] // NOTE after stabilizing `MaybeUninit` proceed to deprecate `mem::{uninitialized,zeroed}` @@ -1134,6 +1153,22 @@ impl MaybeUninit { } } + /// Gets a pointer to the contained value. Reading from this pointer or turning it + /// into a reference will be undefined behavior unless the `MaybeUninit` is initialized. + #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] + pub fn as_ptr(&self) -> *const T { + unsafe { &*self.value as *const T } + } + + /// Gets a mutable pointer to the contained value. Reading from this pointer or turning it + /// into a reference will be undefined behavior unless the `MaybeUninit` is initialized. + #[unstable(feature = "maybe_uninit", issue = "53491")] + #[inline(always)] + pub fn as_mut_ptr(&mut self) -> *mut T { + unsafe { &mut *self.value as *mut T } + } + /// Extracts the value from the `MaybeUninit` container. This is a great way /// to ensure that the data will get dropped, because the resulting `T` is /// subject to the usual drop handling. @@ -1141,7 +1176,8 @@ impl MaybeUninit { /// # Unsafety /// /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized - /// state, otherwise this will immediately cause undefined behavior. + /// state. Calling this when the content is not yet fully initialized causes undefined + /// behavior. #[unstable(feature = "maybe_uninit", issue = "53491")] #[inline(always)] pub unsafe fn into_initialized(self) -> T { @@ -1162,8 +1198,9 @@ impl MaybeUninit { /// # Unsafety /// /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized - /// state, otherwise this will immediately cause undefined behavior. - #[unstable(feature = "maybe_uninit", issue = "53491")] + /// state. Calling this when the content is not yet fully initialized causes undefined + /// behavior. + #[unstable(feature = "maybe_uninit_ref", issue = "53491")] #[inline(always)] pub unsafe fn get_ref(&self) -> &T { &*self.value @@ -1174,41 +1211,26 @@ impl MaybeUninit { /// # Unsafety /// /// It is up to the caller to guarantee that the `MaybeUninit` really is in an initialized - /// state, otherwise this will immediately cause undefined behavior. + /// state. Calling this when the content is not yet fully initialized causes undefined + /// behavior. // FIXME(#53491): We currently rely on the above being incorrect, i.e., we have references // to uninitialized data (e.g., in `libcore/fmt/float.rs`). We should make // a final decision about the rules before stabilization. - #[unstable(feature = "maybe_uninit", issue = "53491")] + #[unstable(feature = "maybe_uninit_ref", issue = "53491")] #[inline(always)] pub unsafe fn get_mut(&mut self) -> &mut T { &mut *self.value } - /// Gets a pointer to the contained value. Reading from this pointer or turning it - /// into a reference will be undefined behavior unless the `MaybeUninit` is initialized. - #[unstable(feature = "maybe_uninit", issue = "53491")] - #[inline(always)] - pub fn as_ptr(&self) -> *const T { - unsafe { &*self.value as *const T } - } - - /// Get sa mutable pointer to the contained value. Reading from this pointer or turning it - /// into a reference will be undefined behavior unless the `MaybeUninit` is initialized. - #[unstable(feature = "maybe_uninit", issue = "53491")] - #[inline(always)] - pub fn as_mut_ptr(&mut self) -> *mut T { - unsafe { &mut *self.value as *mut T } - } - /// Gets a pointer to the first element of the array. - #[unstable(feature = "maybe_uninit", issue = "53491")] + #[unstable(feature = "maybe_uninit_slice", issue = "53491")] #[inline(always)] pub fn first_ptr(this: &[MaybeUninit]) -> *const T { this as *const [MaybeUninit] as *const T } /// Gets a mutable pointer to the first element of the array. - #[unstable(feature = "maybe_uninit", issue = "53491")] + #[unstable(feature = "maybe_uninit_slice", issue = "53491")] #[inline(always)] pub fn first_ptr_mut(this: &mut [MaybeUninit]) -> *mut T { this as *mut [MaybeUninit] as *mut T From 1d6ce5228efe0d69f57c02f36ee27e1f9bd89616 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 14 Feb 2019 22:00:33 +0100 Subject: [PATCH 35/41] Whitelist the ARM v8 target-feature --- src/librustc_codegen_llvm/llvm_util.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_codegen_llvm/llvm_util.rs b/src/librustc_codegen_llvm/llvm_util.rs index 9fe0a4c45f9f4..ecca45a4d4281 100644 --- a/src/librustc_codegen_llvm/llvm_util.rs +++ b/src/librustc_codegen_llvm/llvm_util.rs @@ -104,6 +104,7 @@ const ARM_WHITELIST: &[(&str, Option<&str>)] = &[ ("v6k", Some("arm_target_feature")), ("v6t2", Some("arm_target_feature")), ("v7", Some("arm_target_feature")), + ("v8", Some("arm_target_feature")), ("vfp2", Some("arm_target_feature")), ("vfp3", Some("arm_target_feature")), ("vfp4", Some("arm_target_feature")), From 95ef9b4fc28ad2f5db078eb1ae233fd5be76806b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 14 Feb 2019 22:31:06 +0100 Subject: [PATCH 36/41] make Centril happy --- src/liballoc/lib.rs | 2 +- src/libcore/lib.rs | 2 +- src/libcore/macros.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 2f23a697a58c1..d0b06d6bae5d9 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -112,7 +112,7 @@ #![feature(rustc_const_unstable)] #![feature(const_vec_new)] #![feature(slice_partition_dedup)] -#![feature(maybe_uninit, maybe_uninit_slice)] +#![feature(maybe_uninit, maybe_uninit_slice, maybe_uninit_array)] #![feature(alloc_layout_extra)] #![feature(try_trait)] diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 2c0d0dd149072..d046236b5353a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -122,7 +122,7 @@ #![feature(structural_match)] #![feature(abi_unadjusted)] #![feature(adx_target_feature)] -#![feature(maybe_uninit, maybe_uninit_slice)] +#![feature(maybe_uninit, maybe_uninit_slice, maybe_uninit_array)] #![feature(unrestricted_attribute_tokens)] #[prelude_import] diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 02f8065eb210d..fdbfa56000b8e 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -567,7 +567,7 @@ macro_rules! unimplemented { /// /// [`MaybeUninit`]: mem/union.MaybeUninit.html #[macro_export] -#[unstable(feature = "maybe_uninit_slice", issue = "53491")] +#[unstable(feature = "maybe_uninit_array", issue = "53491")] macro_rules! uninitialized_array { // This `into_initialized` is safe because an array of `MaybeUninit` does not // require initialization. From d21026e3e0d47ecf42c380a25166cb8cd7d7bd63 Mon Sep 17 00:00:00 2001 From: kennytm Date: Fri, 15 Feb 2019 14:26:27 +0800 Subject: [PATCH 37/41] Fix the syntax error in publish_toolstate.py --- src/tools/publish_toolstate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index 24d6fd5b19ba9..75b1db8045d25 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -140,12 +140,12 @@ def update_latest( tool, MAINTAINERS.get(tool), relevant_pr_number, relevant_pr_user, pr_reviewer, ) - except IOError as (errno, strerror): + except IOError as e: # network errors will simply end up not creating an issue, but that's better # than failing the entire build job - print "I/O error({0}): {1}".format(errno, strerror) + print("I/O error: {0}".format(e)) except: - print "Unexpected error:", sys.exc_info()[0] + print("Unexpected error: {0}".format(sys.exc_info()[0])) raise if changed: From 2c8e7082f16bf57ec3d9b68df9c92bc7dd5429df Mon Sep 17 00:00:00 2001 From: Saleem Jaffer Date: Fri, 15 Feb 2019 14:22:17 +0530 Subject: [PATCH 38/41] compile-pass test for #53606 --- src/test/ui/consts/promote_evaluation_unused_result.rs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/test/ui/consts/promote_evaluation_unused_result.rs diff --git a/src/test/ui/consts/promote_evaluation_unused_result.rs b/src/test/ui/consts/promote_evaluation_unused_result.rs new file mode 100644 index 0000000000000..d199e34775e4b --- /dev/null +++ b/src/test/ui/consts/promote_evaluation_unused_result.rs @@ -0,0 +1,8 @@ +//compile-pass + +#![feature(nll)] + +fn main() { + + let _: &'static usize = &(loop {}, 1).1; +} From 14001e8a7b3e7772ac589d69d8badeb4330226f6 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Fri, 15 Feb 2019 14:48:21 +0100 Subject: [PATCH 39/41] Fix runtime error in generate-keyword-tests The script was made unusable after removing license headers. --- src/etc/generate-keyword-tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/etc/generate-keyword-tests.py b/src/etc/generate-keyword-tests.py index 9936ce71b76bc..bc046a8f42d0b 100755 --- a/src/etc/generate-keyword-tests.py +++ b/src/etc/generate-keyword-tests.py @@ -15,7 +15,7 @@ import stat -template = """ +template = """\ // This file was auto-generated using 'src/etc/generate-keyword-tests.py %s' fn main() { @@ -35,7 +35,7 @@ os.chmod(test_file, stat.S_IWUSR) with open(test_file, 'wt') as f: - f.write(template % (datetime.datetime.now().year, kw, kw, kw)) + f.write(template % (kw, kw, kw)) # mark file read-only os.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) From 4ad8770b26ea9804da15149284403c85362e316f Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 15 Feb 2019 12:19:15 -0500 Subject: [PATCH 40/41] Fix documentation for std::path::PathBuf::pop Closes #58474. --- src/libstd/path.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 0f1d627fa1e85..0a9796d1a9c20 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1230,12 +1230,11 @@ impl PathBuf { /// Truncates `self` to [`self.parent`]. /// - /// Returns `false` and does nothing if [`self.file_name`] is [`None`]. + /// Returns `false` and does nothing if [`self.parent`] is [`None`]. /// Otherwise, returns `true`. /// /// [`None`]: ../../std/option/enum.Option.html#variant.None /// [`self.parent`]: struct.PathBuf.html#method.parent - /// [`self.file_name`]: struct.PathBuf.html#method.file_name /// /// # Examples /// From d6a98f4b3afeb2e793e96a6603d3c3aa7c5c4f37 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Sat, 16 Feb 2019 11:56:32 +0100 Subject: [PATCH 41/41] Notify myself when Clippy toolstate changes --- src/tools/publish_toolstate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index 24d6fd5b19ba9..3688812fe0a6e 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -15,7 +15,7 @@ # List of people to ping when the status of a tool changed. MAINTAINERS = { 'miri': '@oli-obk @RalfJung @eddyb', - 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk', + 'clippy-driver': '@Manishearth @llogiq @mcarton @oli-obk @phansch', 'rls': '@nrc @Xanewok', 'rustfmt': '@nrc @topecongiro', 'book': '@carols10cents @steveklabnik',