From 2ae8accd24bec0c4eadba7b02a0a2422b1f1247e Mon Sep 17 00:00:00 2001 From: Aaron DeVore <aaron.devore@gmail.com> Date: Thu, 10 May 2018 11:47:31 -0700 Subject: [PATCH 01/10] fs::write: Add example writing a &str --- src/libstd/fs.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 7bd1adc411ae..ab44723217ea 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -331,6 +331,7 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> { /// /// fn main() -> std::io::Result<()> { /// fs::write("foo.txt", b"Lorem ipsum")?; +/// fs::write("bar.txt", "dolor sit")?; /// Ok(()) /// } /// ``` From c3b23b3b1413c92137b329fd63f95abc1cd7a8b1 Mon Sep 17 00:00:00 2001 From: kennytm <kennytm@gmail.com> Date: Fri, 11 May 2018 12:30:50 +0800 Subject: [PATCH 02/10] AppVeyor: Dump crash log on failure. --- appveyor.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index a92f4a178118..60f5b4be8def 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -211,6 +211,11 @@ test_script: - set NO_CCACHE=1 - sh src/ci/run.sh +on_failure: + # Dump crash log + - set PATH=%PATH%;"C:\Program Files (x86)\Windows Kits\10\Debuggers\X64" + - if exist %LOCALAPPDATA%\CrashDumps for %%f in (%LOCALAPPDATA%\CrashDumps\*) do cdb -c "k;q" -G -z "%%f" + branches: only: - auto From fd85de14599d0ad8bbe5750d2fa83b806b2dbc5e Mon Sep 17 00:00:00 2001 From: varkor <github@varkor.com> Date: Fri, 11 May 2018 17:04:50 +0100 Subject: [PATCH 03/10] Ignore non .rs files for tidy libcoretest Previously, any file would be read, which is both unnecessary, and causes issues if irrelevant non-Unicode files were read (e.g. `.DS_STORE`). --- src/tools/tidy/src/libcoretest.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/tools/tidy/src/libcoretest.rs b/src/tools/tidy/src/libcoretest.rs index ef8b55186b10..f6864c7f84e5 100644 --- a/src/tools/tidy/src/libcoretest.rs +++ b/src/tools/tidy/src/libcoretest.rs @@ -22,12 +22,15 @@ pub fn check(path: &Path, bad: &mut bool) { &libcore_path, &mut |subpath| t!(subpath.strip_prefix(&libcore_path)).starts_with("tests"), &mut |subpath| { - if t!(read_to_string(subpath)).contains("#[test]") { - tidy_error!( - bad, - "{} contains #[test]; libcore tests must be placed inside `src/libcore/tests/`", - subpath.display() - ); + if subpath.ends_with(".rs") { + if t!(read_to_string(subpath)).contains("#[test]") { + tidy_error!( + bad, + "{} contains #[test]; libcore tests must be placed inside \ + `src/libcore/tests/`", + subpath.display() + ); + } } }, ); From 0588bcadf81ef7ac88914c0f8dd2bbfbb164f09c Mon Sep 17 00:00:00 2001 From: Alex Crichton <alex@alexcrichton.com> Date: Fri, 11 May 2018 09:14:23 -0700 Subject: [PATCH 04/10] rustc: Allow an edition's feature on that edition This commit fixes a hard error where the `#![feature(rust_2018_preview)]` feature was forbidden to be mentioned when the `--edition 2018` flag was passed. This instead silently accepts that feature gate despite it not being necessary. It's intended that this will help ease the transition into the 2018 edition as users will, for the time being, start off with the `rust_2018_preview` feature and no longer immediately need to remove it. Closes #50662 --- src/libsyntax/feature_gate.rs | 87 +++++++++++---------- src/test/compile-fail/edition-feature-ok.rs | 16 ++++ 2 files changed, 62 insertions(+), 41 deletions(-) create mode 100644 src/test/compile-fail/edition-feature-ok.rs diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index a137faf689fb..b27568a61f85 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1861,56 +1861,61 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], continue } - match attr.meta_item_list() { + let list = match attr.meta_item_list() { + Some(list) => list, None => { span_err!(span_handler, attr.span, E0555, "malformed feature attribute, expected #![feature(...)]"); + continue + } + }; + + for mi in list { + let name = if let Some(word) = mi.word() { + word.name() + } else { + span_err!(span_handler, mi.span, E0556, + "malformed feature, expected just one word"); + continue + }; + + if let Some((.., set)) = ACTIVE_FEATURES.iter().find(|f| name == f.0) { + set(&mut features, mi.span); + feature_checker.collect(&features, mi.span); + continue } - Some(list) => { - for mi in list { - let name = if let Some(word) = mi.word() { - word.name() - } else { - span_err!(span_handler, mi.span, E0556, - "malformed feature, expected just one word"); - continue - }; - - if let Some(&(_, _, _, _, set)) = ACTIVE_FEATURES.iter() - .find(|& &(n, ..)| name == n) { - set(&mut features, mi.span); - feature_checker.collect(&features, mi.span); - } - else if let Some(&(.., reason)) = REMOVED_FEATURES.iter() - .find(|& &(n, ..)| name == n) - .or_else(|| STABLE_REMOVED_FEATURES.iter() - .find(|& &(n, ..)| name == n)) { - feature_removed(span_handler, mi.span, reason); - } - else if let Some(&(..)) = ACCEPTED_FEATURES.iter() - .find(|& &(n, ..)| name == n) { - features.declared_stable_lang_features.push((name, mi.span)); - } else if let Some(&edition) = ALL_EDITIONS.iter() - .find(|e| name == e.feature_name()) { - if edition <= crate_edition { - feature_removed(span_handler, mi.span, None); - } else { - for &(.., f_edition, set) in ACTIVE_FEATURES.iter() { - if let Some(f_edition) = f_edition { - if edition >= f_edition { - // FIXME(Manishearth) there is currently no way to set - // lib features by edition - set(&mut features, DUMMY_SP); - } - } - } + let removed = REMOVED_FEATURES.iter().find(|f| name == f.0); + let stable_removed = STABLE_REMOVED_FEATURES.iter().find(|f| name == f.0); + if let Some((.., reason)) = removed.or(stable_removed) { + feature_removed(span_handler, mi.span, *reason); + continue + } + + if ACCEPTED_FEATURES.iter().any(|f| name == f.0) { + features.declared_stable_lang_features.push((name, mi.span)); + continue + } + + if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) { + if *edition <= crate_edition { + continue + } + + for &(.., f_edition, set) in ACTIVE_FEATURES.iter() { + if let Some(f_edition) = f_edition { + if *edition >= f_edition { + // FIXME(Manishearth) there is currently no way to set + // lib features by edition + set(&mut features, DUMMY_SP); } - } else { - features.declared_lib_features.push((name, mi.span)); } } + + continue } + + features.declared_lib_features.push((name, mi.span)); } } diff --git a/src/test/compile-fail/edition-feature-ok.rs b/src/test/compile-fail/edition-feature-ok.rs new file mode 100644 index 000000000000..3a3a6ff95f97 --- /dev/null +++ b/src/test/compile-fail/edition-feature-ok.rs @@ -0,0 +1,16 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags:--edition 2018 +// compile-pass + +#![feature(rust_2018_preview)] + +fn main() {} From 6de899f42db1901a637dd8c7d7b3c976d58200a2 Mon Sep 17 00:00:00 2001 From: Alex Crichton <alex@alexcrichton.com> Date: Fri, 11 May 2018 12:34:56 -0700 Subject: [PATCH 05/10] rustc: Include semicolon when removing `extern crate` Currently the lint for removing `extern crate` suggests removing `extern crate` most of the time, but the rest of the time it suggest replacing it with `use crate_name`. Unfortunately though when spliced into the original code you're replacing extern crate foo; with use foo which is syntactically invalid! This commit ensure that the trailing semicolon is included in rustc's suggestion to ensure that the code continues to compile afterwards. --- src/librustc_lint/builtin.rs | 4 +-- .../unnecessary-extern-crate.stderr | 18 +++++------ .../auxiliary/removing-extern-crate.rs | 11 +++++++ .../suggestions/removing-extern-crate.fixed | 27 ++++++++++++++++ .../ui/suggestions/removing-extern-crate.rs | 27 ++++++++++++++++ .../suggestions/removing-extern-crate.stderr | 31 +++++++++++++++++++ 6 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 src/test/ui/suggestions/auxiliary/removing-extern-crate.rs create mode 100644 src/test/ui/suggestions/removing-extern-crate.fixed create mode 100644 src/test/ui/suggestions/removing-extern-crate.rs create mode 100644 src/test/ui/suggestions/removing-extern-crate.stderr diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 5102bfe766ee..a12b28ee8883 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1560,10 +1560,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExternCrate { if let Some(orig) = orig { err.span_suggestion(it.span, &help, - format!("{}use {} as {}", pub_, orig, it.name)); + format!("{}use {} as {};", pub_, orig, it.name)); } else { err.span_suggestion(it.span, &help, - format!("{}use {}", pub_, it.name)); + format!("{}use {};", pub_, it.name)); } } else { err.span_suggestion(it.span, "remove it", "".into()); diff --git a/src/test/ui-fulldeps/unnecessary-extern-crate.stderr b/src/test/ui-fulldeps/unnecessary-extern-crate.stderr index 7718808be58b..e27ccaeba0c2 100644 --- a/src/test/ui-fulldeps/unnecessary-extern-crate.stderr +++ b/src/test/ui-fulldeps/unnecessary-extern-crate.stderr @@ -14,55 +14,55 @@ error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:17:1 | LL | extern crate alloc as x; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x;` error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:23:1 | LL | pub extern crate test as y; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y;` error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:26:1 | LL | pub extern crate libc; - | ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use libc` + | ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use libc;` error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:32:5 | LL | extern crate alloc; - | ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc` + | ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc;` error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:35:5 | LL | extern crate alloc as x; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x;` error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:38:5 | LL | pub extern crate test; - | ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test` + | ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test;` error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:41:5 | LL | pub extern crate test as y; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y;` error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:45:9 | LL | extern crate alloc; - | ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc` + | ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc;` error: `extern crate` is unnecessary in the new edition --> $DIR/unnecessary-extern-crate.rs:48:9 | LL | extern crate alloc as x; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x;` error: aborting due to 10 previous errors diff --git a/src/test/ui/suggestions/auxiliary/removing-extern-crate.rs b/src/test/ui/suggestions/auxiliary/removing-extern-crate.rs new file mode 100644 index 000000000000..4275e80e7fe8 --- /dev/null +++ b/src/test/ui/suggestions/auxiliary/removing-extern-crate.rs @@ -0,0 +1,11 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// intentionally blank diff --git a/src/test/ui/suggestions/removing-extern-crate.fixed b/src/test/ui/suggestions/removing-extern-crate.fixed new file mode 100644 index 000000000000..723137f5db0c --- /dev/null +++ b/src/test/ui/suggestions/removing-extern-crate.fixed @@ -0,0 +1,27 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --edition 2018 +// aux-build:removing-extern-crate.rs +// run-rustfix +// compile-pass + +#![warn(rust_2018_idioms)] +#![allow(unused_imports)] + +use std as foo; + + +mod another { + use std as foo; + use std; +} + +fn main() {} diff --git a/src/test/ui/suggestions/removing-extern-crate.rs b/src/test/ui/suggestions/removing-extern-crate.rs new file mode 100644 index 000000000000..29479086460e --- /dev/null +++ b/src/test/ui/suggestions/removing-extern-crate.rs @@ -0,0 +1,27 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: --edition 2018 +// aux-build:removing-extern-crate.rs +// run-rustfix +// compile-pass + +#![warn(rust_2018_idioms)] +#![allow(unused_imports)] + +extern crate std as foo; +extern crate core; + +mod another { + extern crate std as foo; + extern crate std; +} + +fn main() {} diff --git a/src/test/ui/suggestions/removing-extern-crate.stderr b/src/test/ui/suggestions/removing-extern-crate.stderr new file mode 100644 index 000000000000..317703d0caa5 --- /dev/null +++ b/src/test/ui/suggestions/removing-extern-crate.stderr @@ -0,0 +1,31 @@ +warning: `extern crate` is unnecessary in the new edition + --> $DIR/removing-extern-crate.rs:19:1 + | +LL | extern crate std as foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use std as foo;` + | +note: lint level defined here + --> $DIR/removing-extern-crate.rs:16:9 + | +LL | #![warn(rust_2018_idioms)] + | ^^^^^^^^^^^^^^^^ + = note: #[warn(unnecessary_extern_crate)] implied by #[warn(rust_2018_idioms)] + +warning: `extern crate` is unnecessary in the new edition + --> $DIR/removing-extern-crate.rs:20:1 + | +LL | extern crate core; + | ^^^^^^^^^^^^^^^^^^ help: remove it + +warning: `extern crate` is unnecessary in the new edition + --> $DIR/removing-extern-crate.rs:23:5 + | +LL | extern crate std as foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use std as foo;` + +warning: `extern crate` is unnecessary in the new edition + --> $DIR/removing-extern-crate.rs:24:5 + | +LL | extern crate std; + | ^^^^^^^^^^^^^^^^^ help: use `use`: `use std;` + From 12f92e9640df926da70911b31d0fd2967be5fec3 Mon Sep 17 00:00:00 2001 From: Alex Crichton <alex@alexcrichton.com> Date: Fri, 11 May 2018 11:31:08 -0700 Subject: [PATCH 06/10] rustc: Only suggest deleting `extern crate` if it works This commit updates one of the edition lints to only suggest deleting `extern crate` if it actually works. Otherwise this can yield some confusing behavior with rustfix specifically where if you accidentally deny the `rust_2018_idioms` lint in the 2015 edition it's suggesting features that don't work! --- src/librustc_lint/builtin.rs | 3 +++ .../auxiliary/edition-extern-crate-allowed.rs | 11 ++++++++++ .../edition-extern-crate-allowed.rs | 19 ++++++++++++++++ .../ui-fulldeps/unnecessary-extern-crate.rs | 2 ++ .../unnecessary-extern-crate.stderr | 22 +++++++++---------- 5 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 src/test/compile-fail/auxiliary/edition-extern-crate-allowed.rs create mode 100644 src/test/compile-fail/edition-extern-crate-allowed.rs diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 5102bfe766ee..7788b852f42a 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1543,6 +1543,9 @@ impl LintPass for ExternCrate { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExternCrate { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { + if !cx.tcx.features().extern_absolute_paths { + return + } if let hir::ItemExternCrate(ref orig) = it.node { if it.attrs.iter().any(|a| a.check_name("macro_use")) { return diff --git a/src/test/compile-fail/auxiliary/edition-extern-crate-allowed.rs b/src/test/compile-fail/auxiliary/edition-extern-crate-allowed.rs new file mode 100644 index 000000000000..d26ab6d35183 --- /dev/null +++ b/src/test/compile-fail/auxiliary/edition-extern-crate-allowed.rs @@ -0,0 +1,11 @@ +// Copyright 2014 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// intentionally empty diff --git a/src/test/compile-fail/edition-extern-crate-allowed.rs b/src/test/compile-fail/edition-extern-crate-allowed.rs new file mode 100644 index 000000000000..286ee896161a --- /dev/null +++ b/src/test/compile-fail/edition-extern-crate-allowed.rs @@ -0,0 +1,19 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:edition-extern-crate-allowed.rs +// compile-flags: --edition 2015 +// compile-pass + +#![deny(rust_2018_idioms)] + +extern crate edition_extern_crate_allowed; + +fn main() {} diff --git a/src/test/ui-fulldeps/unnecessary-extern-crate.rs b/src/test/ui-fulldeps/unnecessary-extern-crate.rs index 9d678d91578b..0f532d3da6a7 100644 --- a/src/test/ui-fulldeps/unnecessary-extern-crate.rs +++ b/src/test/ui-fulldeps/unnecessary-extern-crate.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: --edition 2018 + #![deny(unnecessary_extern_crate)] #![feature(alloc, test, libc)] diff --git a/src/test/ui-fulldeps/unnecessary-extern-crate.stderr b/src/test/ui-fulldeps/unnecessary-extern-crate.stderr index 7718808be58b..b0b56f527e64 100644 --- a/src/test/ui-fulldeps/unnecessary-extern-crate.stderr +++ b/src/test/ui-fulldeps/unnecessary-extern-crate.stderr @@ -1,65 +1,65 @@ error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:14:1 + --> $DIR/unnecessary-extern-crate.rs:16:1 | LL | extern crate alloc; | ^^^^^^^^^^^^^^^^^^^ help: remove it | note: lint level defined here - --> $DIR/unnecessary-extern-crate.rs:11:9 + --> $DIR/unnecessary-extern-crate.rs:13:9 | LL | #![deny(unnecessary_extern_crate)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:17:1 + --> $DIR/unnecessary-extern-crate.rs:19:1 | LL | extern crate alloc as x; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:23:1 + --> $DIR/unnecessary-extern-crate.rs:25:1 | LL | pub extern crate test as y; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y` error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:26:1 + --> $DIR/unnecessary-extern-crate.rs:28:1 | LL | pub extern crate libc; | ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use libc` error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:32:5 + --> $DIR/unnecessary-extern-crate.rs:34:5 | LL | extern crate alloc; | ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc` error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:35:5 + --> $DIR/unnecessary-extern-crate.rs:37:5 | LL | extern crate alloc as x; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:38:5 + --> $DIR/unnecessary-extern-crate.rs:40:5 | LL | pub extern crate test; | ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test` error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:41:5 + --> $DIR/unnecessary-extern-crate.rs:43:5 | LL | pub extern crate test as y; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y` error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:45:9 + --> $DIR/unnecessary-extern-crate.rs:47:9 | LL | extern crate alloc; | ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc` error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:48:9 + --> $DIR/unnecessary-extern-crate.rs:50:9 | LL | extern crate alloc as x; | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x` From 16c088d3254bf5fc75ae3ce9f498bfc522098db8 Mon Sep 17 00:00:00 2001 From: varkor <github@varkor.com> Date: Fri, 11 May 2018 21:36:24 +0100 Subject: [PATCH 07/10] Display the name of the failed file in tidy/libcoretest --- src/tools/tidy/src/libcoretest.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/tools/tidy/src/libcoretest.rs b/src/tools/tidy/src/libcoretest.rs index f6864c7f84e5..363d01d964eb 100644 --- a/src/tools/tidy/src/libcoretest.rs +++ b/src/tools/tidy/src/libcoretest.rs @@ -22,14 +22,21 @@ pub fn check(path: &Path, bad: &mut bool) { &libcore_path, &mut |subpath| t!(subpath.strip_prefix(&libcore_path)).starts_with("tests"), &mut |subpath| { - if subpath.ends_with(".rs") { - if t!(read_to_string(subpath)).contains("#[test]") { - tidy_error!( - bad, - "{} contains #[test]; libcore tests must be placed inside \ - `src/libcore/tests/`", - subpath.display() - ); + if let Some("rs") = subpath.extension().and_then(|e| e.to_str()) { + match read_to_string(subpath) { + Ok(contents) => { + if contents.contains("#[test]") { + tidy_error!( + bad, + "{} contains #[test]; libcore tests must be placed inside \ + `src/libcore/tests/`", + subpath.display() + ); + } + } + Err(err) => { + panic!("failed to read file {:?}: {}", subpath, err); + } } } }, From 4ce24269bb498b799ad14bd1fe3fb11900c1ce64 Mon Sep 17 00:00:00 2001 From: Tobias Bucher <tobiasbucher5991@gmail.com> Date: Sat, 12 May 2018 02:31:38 +0200 Subject: [PATCH 08/10] Do not silently truncate offsets for `read_at`/`write_at` on emscripten Generate an IO error if the offset is out of bounds for the system call. --- src/libstd/sys/unix/fd.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index 5dafc3251e75..67546d06b4e5 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -75,8 +75,15 @@ impl FileDesc { unsafe fn cvt_pread64(fd: c_int, buf: *mut c_void, count: usize, offset: i64) -> io::Result<isize> { + use convert::TryInto; use libc::pread64; - cvt(pread64(fd, buf, count, offset as i32)) + // pread64 on emscripten actually takes a 32 bit offset + if let Ok(o) = offset.try_into() { + cvt(pread64(fd, buf, count, o)) + } else { + Err(io::Error::new(io::ErrorKind::InvalidInput, + "cannot pread >2GB")) + } } #[cfg(not(any(target_os = "android", target_os = "emscripten")))] @@ -116,8 +123,15 @@ impl FileDesc { unsafe fn cvt_pwrite64(fd: c_int, buf: *const c_void, count: usize, offset: i64) -> io::Result<isize> { + use convert::TryInto; use libc::pwrite64; - cvt(pwrite64(fd, buf, count, offset as i32)) + // pwrite64 on emscripten actually takes a 32 bit offset + if let Ok(o) = offset.try_into() { + cvt(pwrite64(fd, buf, count, o)) + } else { + Err(io::Error::new(io::ErrorKind::InvalidInput, + "cannot pwrite >2GB")) + } } #[cfg(not(any(target_os = "android", target_os = "emscripten")))] From 0bef2402772218a20c7572e0d606e529844b527d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= <semarie@users.noreply.github.com> Date: Sat, 12 May 2018 09:46:07 +0200 Subject: [PATCH 09/10] openbsd-i686: use lld as linker by default standard binutils on openbsd is too old to do proper job with i128 code. --- src/librustc_target/spec/i686_unknown_openbsd.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_target/spec/i686_unknown_openbsd.rs b/src/librustc_target/spec/i686_unknown_openbsd.rs index 79c059c8f952..f22bf2abe450 100644 --- a/src/librustc_target/spec/i686_unknown_openbsd.rs +++ b/src/librustc_target/spec/i686_unknown_openbsd.rs @@ -15,6 +15,7 @@ pub fn target() -> TargetResult { base.cpu = "pentium4".to_string(); base.max_atomic_width = Some(64); base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m32".to_string()); + base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-fuse-ld=lld".to_string()); base.stack_probes = true; Ok(Target { From f430d7c3c781c48827a1c28fb391d90a0f5ee710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= <semarie@users.noreply.github.com> Date: Sat, 12 May 2018 09:45:35 +0200 Subject: [PATCH 10/10] add aarch64-unknown-openbsd support --- .../spec/aarch64_unknown_openbsd.rs | 31 +++++++++++++++++++ src/librustc_target/spec/mod.rs | 1 + 2 files changed, 32 insertions(+) create mode 100644 src/librustc_target/spec/aarch64_unknown_openbsd.rs diff --git a/src/librustc_target/spec/aarch64_unknown_openbsd.rs b/src/librustc_target/spec/aarch64_unknown_openbsd.rs new file mode 100644 index 000000000000..25817fce5ce6 --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_openbsd.rs @@ -0,0 +1,31 @@ +// 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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use spec::{LinkerFlavor, Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::openbsd_base::opts(); + base.max_atomic_width = Some(128); + base.abi_blacklist = super::arm_base::abi_blacklist(); + + Ok(Target { + llvm_target: "aarch64-unknown-openbsd".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + target_os: "openbsd".to_string(), + target_env: "".to_string(), + target_vendor: "unknown".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: base, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 708a3865b23b..fb20fe9c8918 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -313,6 +313,7 @@ supported_targets! { ("x86_64-unknown-bitrig", x86_64_unknown_bitrig), + ("aarch64-unknown-openbsd", aarch64_unknown_openbsd), ("i686-unknown-openbsd", i686_unknown_openbsd), ("x86_64-unknown-openbsd", x86_64_unknown_openbsd),