diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2018-06-04 10:58:56 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-04 10:58:56 +0530 |
| commit | 72f2f1935dbdcac023f2f682226792f2ad79315a (patch) | |
| tree | fe325dfcda1636171bf779081f30c6e1e7163e9e /src/test | |
| parent | bc7416213c20e165ebe723c4328667e8008c0794 (diff) | |
| parent | 6232478d26b0feca02fd6660edbf78a5c6327ec5 (diff) | |
| download | rust-72f2f1935dbdcac023f2f682226792f2ad79315a.tar.gz rust-72f2f1935dbdcac023f2f682226792f2ad79315a.zip | |
Merge branch 'master' into stabilise/termination-test
Diffstat (limited to 'src/test')
44 files changed, 860 insertions, 79 deletions
diff --git a/src/test/compile-fail/auxiliary/some-panic-impl.rs b/src/test/compile-fail/auxiliary/some-panic-impl.rs new file mode 100644 index 00000000000..db16ac325ac --- /dev/null +++ b/src/test/compile-fail/auxiliary/some-panic-impl.rs @@ -0,0 +1,22 @@ +// 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. + +// no-prefer-dynamic + +#![crate_type = "rlib"] +#![feature(panic_implementation)] +#![no_std] + +use core::panic::PanicInfo; + +#[panic_implementation] +fn panic(info: &PanicInfo) -> ! { + loop {} +} diff --git a/src/test/compile-fail/duplicate_entry_error.rs b/src/test/compile-fail/duplicate_entry_error.rs index 485519e8c3d..176aa7cca53 100644 --- a/src/test/compile-fail/duplicate_entry_error.rs +++ b/src/test/compile-fail/duplicate_entry_error.rs @@ -14,9 +14,11 @@ #![feature(lang_items)] -#[lang = "panic_fmt"] -fn panic_fmt() -> ! { -//~^ ERROR: duplicate lang item found: `panic_fmt`. +use std::panic::PanicInfo; + +#[lang = "panic_impl"] +fn panic_impl(info: &PanicInfo) -> ! { +//~^ ERROR: duplicate lang item found: `panic_impl`. loop {} } diff --git a/src/test/compile-fail/edition-extern-crate-allowed.rs b/src/test/compile-fail/edition-extern-crate-allowed.rs index 286ee896161..7368564e250 100644 --- a/src/test/compile-fail/edition-extern-crate-allowed.rs +++ b/src/test/compile-fail/edition-extern-crate-allowed.rs @@ -12,8 +12,9 @@ // compile-flags: --edition 2015 // compile-pass -#![deny(rust_2018_idioms)] +#![warn(rust_2018_idioms)] extern crate edition_extern_crate_allowed; +//~^ WARNING unused extern crate fn main() {} diff --git a/src/test/compile-fail/feature-gate-panic-implementation.rs b/src/test/compile-fail/feature-gate-panic-implementation.rs new file mode 100644 index 00000000000..ae9fbc7b13b --- /dev/null +++ b/src/test/compile-fail/feature-gate-panic-implementation.rs @@ -0,0 +1,21 @@ +// 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:-C panic=abort + +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +#[panic_implementation] //~ ERROR #[panic_implementation] is an unstable feature (see issue #44489) +fn panic(info: &PanicInfo) -> ! { + loop {} +} diff --git a/src/test/compile-fail/no_owned_box_lang_item.rs b/src/test/compile-fail/no_owned_box_lang_item.rs index 72eb687adc6..1c2bf1573dc 100644 --- a/src/test/compile-fail/no_owned_box_lang_item.rs +++ b/src/test/compile-fail/no_owned_box_lang_item.rs @@ -21,4 +21,4 @@ fn main() { #[lang = "eh_personality"] extern fn eh_personality() {} #[lang = "eh_unwind_resume"] extern fn eh_unwind_resume() {} -#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} } +#[lang = "panic_impl"] fn panic_impl() -> ! { loop {} } diff --git a/src/test/compile-fail/panic-implementation-bad-signature-1.rs b/src/test/compile-fail/panic-implementation-bad-signature-1.rs new file mode 100644 index 00000000000..fec11fdbd7b --- /dev/null +++ b/src/test/compile-fail/panic-implementation-bad-signature-1.rs @@ -0,0 +1,24 @@ +// 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:-C panic=abort + +#![feature(panic_implementation)] +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +#[panic_implementation] +fn panic( + info: PanicInfo, //~ ERROR argument should be `&PanicInfo` +) -> () //~ ERROR return type should be `!` +{ +} diff --git a/src/test/compile-fail/panic-implementation-bad-signature-2.rs b/src/test/compile-fail/panic-implementation-bad-signature-2.rs new file mode 100644 index 00000000000..2a628c05699 --- /dev/null +++ b/src/test/compile-fail/panic-implementation-bad-signature-2.rs @@ -0,0 +1,25 @@ +// 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:-C panic=abort + +#![feature(panic_implementation)] +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +#[panic_implementation] +fn panic( + info: &'static PanicInfo, //~ ERROR argument should be `&PanicInfo` +) -> ! +{ + loop {} +} diff --git a/src/test/compile-fail/panic-implementation-bad-signature-3.rs b/src/test/compile-fail/panic-implementation-bad-signature-3.rs new file mode 100644 index 00000000000..29337025b70 --- /dev/null +++ b/src/test/compile-fail/panic-implementation-bad-signature-3.rs @@ -0,0 +1,22 @@ +// 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:-C panic=abort + +#![feature(panic_implementation)] +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +#[panic_implementation] +fn panic() -> ! { //~ ERROR function should have one argument + loop {} +} diff --git a/src/test/compile-fail/panic-implementation-bad-signature-4.rs b/src/test/compile-fail/panic-implementation-bad-signature-4.rs new file mode 100644 index 00000000000..d5f942ba2d6 --- /dev/null +++ b/src/test/compile-fail/panic-implementation-bad-signature-4.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 <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:-C panic=abort + +#![feature(panic_implementation)] +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +#[panic_implementation] +fn panic<T>(pi: &PanicInfo) -> ! { + //~^ ERROR `#[panic_implementation]` function should have no type parameters + loop {} +} diff --git a/src/test/compile-fail/panic-implementation-duplicate.rs b/src/test/compile-fail/panic-implementation-duplicate.rs new file mode 100644 index 00000000000..017113af409 --- /dev/null +++ b/src/test/compile-fail/panic-implementation-duplicate.rs @@ -0,0 +1,28 @@ +// 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:-C panic=abort + +#![feature(lang_items)] +#![feature(panic_implementation)] +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +#[panic_implementation] +fn panic(info: &PanicInfo) -> ! { + loop {} +} + +#[lang = "panic_impl"] +fn panic2(info: &PanicInfo) -> ! { //~ ERROR duplicate lang item found: `panic_impl`. + loop {} +} diff --git a/src/test/compile-fail/panic-implementation-requires-panic-info.rs b/src/test/compile-fail/panic-implementation-requires-panic-info.rs new file mode 100644 index 00000000000..597f44d9832 --- /dev/null +++ b/src/test/compile-fail/panic-implementation-requires-panic-info.rs @@ -0,0 +1,26 @@ +// 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:-C panic=abort +// error-pattern: language item required, but not found: `panic_info` + +#![feature(lang_items)] +#![feature(no_core)] +#![feature(panic_implementation)] +#![no_core] +#![no_main] + +#[panic_implementation] +fn panic() -> ! { + loop {} +} + +#[lang = "sized"] +trait Sized {} diff --git a/src/test/compile-fail/panic-implementation-std.rs b/src/test/compile-fail/panic-implementation-std.rs new file mode 100644 index 00000000000..f25cd3605c1 --- /dev/null +++ b/src/test/compile-fail/panic-implementation-std.rs @@ -0,0 +1,22 @@ +// 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. + +// error-pattern: duplicate lang item found: `panic_impl`. + +#![feature(panic_implementation)] + +use std::panic::PanicInfo; + +#[panic_implementation] +fn panic(info: PanicInfo) -> ! { + loop {} +} + +fn main() {} diff --git a/src/test/compile-fail/panic-implementation-twice.rs b/src/test/compile-fail/panic-implementation-twice.rs new file mode 100644 index 00000000000..78dc545c036 --- /dev/null +++ b/src/test/compile-fail/panic-implementation-twice.rs @@ -0,0 +1,29 @@ +// 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:some-panic-impl.rs + +#![feature(panic_implementation)] +#![feature(lang_items)] +#![no_std] +#![no_main] + +extern crate some_panic_impl; + +use core::panic::PanicInfo; + +#[panic_implementation] +fn panic(info: &PanicInfo) -> ! { + //~^ error duplicate lang item found: `panic_impl` + loop {} +} + +#[lang = "eh_personality"] +fn eh() {} diff --git a/src/test/compile-fail/panic-runtime/auxiliary/panic-runtime-lang-items.rs b/src/test/compile-fail/panic-runtime/auxiliary/panic-runtime-lang-items.rs index fbf70b3d3fe..d9848a554ab 100644 --- a/src/test/compile-fail/panic-runtime/auxiliary/panic-runtime-lang-items.rs +++ b/src/test/compile-fail/panic-runtime/auxiliary/panic-runtime-lang-items.rs @@ -15,8 +15,10 @@ #![no_std] #![feature(lang_items)] -#[lang = "panic_fmt"] -fn panic_fmt() {} +use core::panic::PanicInfo; + +#[lang = "panic_impl"] +fn panic_impl(info: &PanicInfo) -> ! { loop {} } #[lang = "eh_personality"] fn eh_personality() {} #[lang = "eh_unwind_resume"] diff --git a/src/test/compile-fail/weak-lang-item.rs b/src/test/compile-fail/weak-lang-item.rs index 8579611b938..7b988c3595f 100644 --- a/src/test/compile-fail/weak-lang-item.rs +++ b/src/test/compile-fail/weak-lang-item.rs @@ -9,7 +9,7 @@ // except according to those terms. // aux-build:weak-lang-items.rs -// error-pattern: language item required, but not found: `panic_fmt` +// error-pattern: language item required, but not found: `panic_impl` // error-pattern: language item required, but not found: `eh_personality` // ignore-wasm32-bare compiled with panic=abort, personality not required diff --git a/src/test/run-make-fulldeps/issue-36710/Makefile b/src/test/run-make-fulldeps/issue-36710/Makefile new file mode 100644 index 00000000000..928bdf532df --- /dev/null +++ b/src/test/run-make-fulldeps/issue-36710/Makefile @@ -0,0 +1,21 @@ +-include ../tools.mk + +ifeq (musl,$(findstring musl,$(TARGET))) +all: skip +else +all: test +endif + +test: foo + $(call RUN,foo) + +skip: + echo "expected failure" + +foo: foo.rs $(call NATIVE_STATICLIB,foo) + $(RUSTC) $< -lfoo $(EXTRACXXFLAGS) + +$(TMPDIR)/libfoo.o: foo.cpp + $(call COMPILE_OBJ_CXX,$@,$<) + +.PHONY: all test skip diff --git a/src/test/run-make-fulldeps/issue-36710/foo.cpp b/src/test/run-make-fulldeps/issue-36710/foo.cpp new file mode 100644 index 00000000000..fbd0ead7a50 --- /dev/null +++ b/src/test/run-make-fulldeps/issue-36710/foo.cpp @@ -0,0 +1,25 @@ +// 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. + +#include <stdint.h> + +struct A { + A() { v = 1234; } + ~A() { v = 1; } + uint32_t v; +}; + +A a; + +extern "C" { + uint32_t get() { + return a.v; + } +} diff --git a/src/test/run-make-fulldeps/issue-36710/foo.rs b/src/test/run-make-fulldeps/issue-36710/foo.rs new file mode 100644 index 00000000000..6e50566ddfd --- /dev/null +++ b/src/test/run-make-fulldeps/issue-36710/foo.rs @@ -0,0 +1,18 @@ +// 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. + +// Tests that linking to C++ code with global destructors works. + +extern { fn get() -> u32; } + +fn main() { + let i = unsafe { get() }; + assert_eq!(i, 1234); +} diff --git a/src/test/run-make-fulldeps/panic-impl-transitive/Makefile b/src/test/run-make-fulldeps/panic-impl-transitive/Makefile new file mode 100644 index 00000000000..1714578b2ba --- /dev/null +++ b/src/test/run-make-fulldeps/panic-impl-transitive/Makefile @@ -0,0 +1,7 @@ +-include ../../run-make-fulldeps/tools.mk + +# NOTE we use --emit=llvm-ir to avoid running the linker (linking will fail because there's no main +# in this crate) +all: + $(RUSTC) panic-impl-provider.rs + $(RUSTC) panic-impl-consumer.rs -C panic=abort --emit=llvm-ir -L $(TMPDIR) diff --git a/src/test/run-make-fulldeps/panic-impl-transitive/panic-impl-consumer.rs b/src/test/run-make-fulldeps/panic-impl-transitive/panic-impl-consumer.rs new file mode 100644 index 00000000000..592fab8be85 --- /dev/null +++ b/src/test/run-make-fulldeps/panic-impl-transitive/panic-impl-consumer.rs @@ -0,0 +1,15 @@ +// 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. + +#![no_std] +#![no_main] + +// this crate provides the `panic_impl` lang item so we don't need to define it here +extern crate panic_impl_provider; diff --git a/src/test/run-make-fulldeps/panic-impl-transitive/panic-impl-provider.rs b/src/test/run-make-fulldeps/panic-impl-transitive/panic-impl-provider.rs new file mode 100644 index 00000000000..46cdf2e2fa5 --- /dev/null +++ b/src/test/run-make-fulldeps/panic-impl-transitive/panic-impl-provider.rs @@ -0,0 +1,20 @@ +// 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. + +#![crate_type = "rlib"] +#![feature(panic_implementation)] +#![no_std] + +use core::panic::PanicInfo; + +#[panic_implementation] +fn panic(info: &PanicInfo) -> ! { + loop {} +} diff --git a/src/test/run-make-fulldeps/tools.mk b/src/test/run-make-fulldeps/tools.mk index af1707de6c0..3de358fa500 100644 --- a/src/test/run-make-fulldeps/tools.mk +++ b/src/test/run-make-fulldeps/tools.mk @@ -59,12 +59,14 @@ endif ifdef IS_MSVC COMPILE_OBJ = $(CC) -c -Fo:`cygpath -w $(1)` $(2) +COMPILE_OBJ_CXX = $(CXX) -c -Fo:`cygpath -w $(1)` $(2) NATIVE_STATICLIB_FILE = $(1).lib NATIVE_STATICLIB = $(TMPDIR)/$(call NATIVE_STATICLIB_FILE,$(1)) OUT_EXE=-Fe:`cygpath -w $(TMPDIR)/$(call BIN,$(1))` \ -Fo:`cygpath -w $(TMPDIR)/$(1).obj` else COMPILE_OBJ = $(CC) -c -o $(1) $(2) +COMPILE_OBJ_CXX = $(CXX) -c -o $(1) $(2) NATIVE_STATICLIB_FILE = lib$(1).a NATIVE_STATICLIB = $(call STATICLIB,$(1)) OUT_EXE=-o $(TMPDIR)/$(1) diff --git a/src/test/run-pass/const-endianess.rs b/src/test/run-pass/const-endianess.rs new file mode 100644 index 00000000000..fa34b49210a --- /dev/null +++ b/src/test/run-pass/const-endianess.rs @@ -0,0 +1,32 @@ +// 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. + +#![feature(const_int_ops)] +#![feature(test)] + +extern crate test; +use test::black_box as b; + +const BE_U32: u32 = 55u32.to_be(); +const LE_U32: u32 = 55u32.to_le(); + + +fn main() { + assert_eq!(BE_U32, b(55u32).to_be()); + assert_eq!(LE_U32, b(55u32).to_le()); + + #[cfg(not(target_arch = "asmjs"))] + { + const BE_U128: u128 = 999999u128.to_be(); + const LE_I128: i128 = -999999i128.to_le(); + assert_eq!(BE_U128, b(999999u128).to_be()); + assert_eq!(LE_I128, b(-999999i128).to_le()); + } +} diff --git a/src/test/rustdoc-ui/intra-links-warning.rs b/src/test/rustdoc-ui/intra-links-warning.rs index 2a00d31e3d7..830aaabf9d2 100644 --- a/src/test/rustdoc-ui/intra-links-warning.rs +++ b/src/test/rustdoc-ui/intra-links-warning.rs @@ -10,7 +10,9 @@ // compile-pass -//! Test with [Foo::baz], [Bar::foo], [Uniooon::X] +//! Test with [Foo::baz], [Bar::foo], ... +//! +//! and [Uniooon::X]. pub struct Foo { pub bar: usize, diff --git a/src/test/rustdoc-ui/intra-links-warning.stderr b/src/test/rustdoc-ui/intra-links-warning.stderr index 67d7bdd02b3..1e8e9f04c26 100644 --- a/src/test/rustdoc-ui/intra-links-warning.stderr +++ b/src/test/rustdoc-ui/intra-links-warning.stderr @@ -1,6 +1,39 @@ warning: [Foo::baz] cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:13:1 + | +13 | / //! Test with [Foo::baz], [Bar::foo], ... +14 | | //! +15 | | //! and [Uniooon::X]. + | |_____________________^ + | + = note: the link appears in this line: + + Test with [Foo::baz], [Bar::foo], ... + ^^^^^^^^ warning: [Bar::foo] cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:13:1 + | +13 | / //! Test with [Foo::baz], [Bar::foo], ... +14 | | //! +15 | | //! and [Uniooon::X]. + | |_____________________^ + | + = note: the link appears in this line: + + Test with [Foo::baz], [Bar::foo], ... + ^^^^^^^^ warning: [Uniooon::X] cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:13:1 + | +13 | / //! Test with [Foo::baz], [Bar::foo], ... +14 | | //! +15 | | //! and [Uniooon::X]. + | |_____________________^ + | + = note: the link appears in this line: + + and [Uniooon::X]. + ^^^^^^^^^^ diff --git a/src/test/rustdoc/rustc-macro-crate.rs b/src/test/rustdoc/rustc-macro-crate.rs index dc28732b55e..d46f9684411 100644 --- a/src/test/rustdoc/rustc-macro-crate.rs +++ b/src/test/rustdoc/rustc-macro-crate.rs @@ -9,6 +9,7 @@ // except according to those terms. // no-prefer-dynamic +// ignore-stage1 #![crate_type = "proc-macro"] diff --git a/src/test/rustdoc/trait-attributes.rs b/src/test/rustdoc/trait-attributes.rs new file mode 100644 index 00000000000..00d10408b4c --- /dev/null +++ b/src/test/rustdoc/trait-attributes.rs @@ -0,0 +1,32 @@ +// 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. + +#![crate_name = "foo"] + +// ignore-tidy-linelength + +pub trait Foo { + // @has foo/trait.Foo.html '//h3[@id="tymethod.foo"]//div[@class="docblock attributes"]' '#[must_use]' + #[must_use] + fn foo(); +} + +#[must_use] +pub struct Bar; + +impl Bar { + // @has foo/struct.Bar.html '//h4[@id="method.bar"]//div[@class="docblock attributes"]' '#[must_use]' + #[must_use] + pub fn bar() {} + + // @has foo/struct.Bar.html '//h4[@id="method.bar2"]//div[@class="docblock attributes"]' '#[must_use]' + #[must_use] + pub fn bar2() {} +} diff --git a/src/test/ui-fulldeps/unnecessary-extern-crate.rs b/src/test/ui-fulldeps/unnecessary-extern-crate.rs index fc6cb6bd053..0811c79b0a4 100644 --- a/src/test/ui-fulldeps/unnecessary-extern-crate.rs +++ b/src/test/ui-fulldeps/unnecessary-extern-crate.rs @@ -10,48 +10,90 @@ // compile-flags: --edition 2018 -#![deny(unnecessary_extern_crates)] +#![deny(unused_extern_crates)] #![feature(alloc, test, libc)] extern crate alloc; -//~^ ERROR `extern crate` is unnecessary in the new edition +//~^ ERROR unused extern crate //~| HELP remove extern crate alloc as x; -//~^ ERROR `extern crate` is unnecessary in the new edition -//~| HELP use `use` +//~^ ERROR unused extern crate +//~| HELP remove #[macro_use] extern crate test; + pub extern crate test as y; -//~^ ERROR `extern crate` is unnecessary in the new edition -//~| HELP use `pub use` +//~^ ERROR `extern crate` is not idiomatic in the new edition +//~| HELP convert it to a `pub use` + pub extern crate libc; -//~^ ERROR `extern crate` is unnecessary in the new edition -//~| HELP use `pub use` +//~^ ERROR `extern crate` is not idiomatic in the new edition +//~| HELP convert it to a `pub use` + +pub(crate) extern crate libc as a; +//~^ ERROR `extern crate` is not idiomatic in the new edition +//~| HELP convert it to a `pub(crate) use` +crate extern crate libc as b; +//~^ ERROR `extern crate` is not idiomatic in the new edition +//~| HELP convert it to a `crate use` mod foo { + pub(in crate::foo) extern crate libc as c; + //~^ ERROR `extern crate` is not idiomatic in the new edition + //~| HELP convert it to a `pub(in crate::foo) use` + + pub(super) extern crate libc as d; + //~^ ERROR `extern crate` is not idiomatic in the new edition + //~| HELP convert it to a `pub(super) use` + extern crate alloc; - //~^ ERROR `extern crate` is unnecessary in the new edition - //~| HELP use `use` + //~^ ERROR unused extern crate + //~| HELP remove + extern crate alloc as x; - //~^ ERROR `extern crate` is unnecessary in the new edition - //~| HELP use `use` + //~^ ERROR unused extern crate + //~| HELP remove + pub extern crate test; - //~^ ERROR `extern crate` is unnecessary in the new edition - //~| HELP use `pub use` + //~^ ERROR `extern crate` is not idiomatic in the new edition + //~| HELP convert it + pub extern crate test as y; - //~^ ERROR `extern crate` is unnecessary in the new edition - //~| HELP use `pub use` + //~^ ERROR `extern crate` is not idiomatic in the new edition + //~| HELP convert it + mod bar { extern crate alloc; - //~^ ERROR `extern crate` is unnecessary in the new edition - //~| HELP use `use` + //~^ ERROR unused extern crate + //~| HELP remove + extern crate alloc as x; - //~^ ERROR `extern crate` is unnecessary in the new edition - //~| HELP use `use` + //~^ ERROR unused extern crate + //~| HELP remove + + pub(in crate::foo::bar) extern crate libc as e; + //~^ ERROR `extern crate` is not idiomatic in the new edition + //~| HELP convert it to a `pub(in crate::foo::bar) use` + + fn dummy() { + unsafe { + e::getpid(); + } + } + } + + fn dummy() { + unsafe { + c::getpid(); + d::getpid(); + } } } -fn main() {} +fn main() { + unsafe { a::getpid(); } + unsafe { b::getpid(); } +} diff --git a/src/test/ui-fulldeps/unnecessary-extern-crate.stderr b/src/test/ui-fulldeps/unnecessary-extern-crate.stderr index b9ccf5b19e0..a4307112157 100644 --- a/src/test/ui-fulldeps/unnecessary-extern-crate.stderr +++ b/src/test/ui-fulldeps/unnecessary-extern-crate.stderr @@ -1,4 +1,4 @@ -error: `extern crate` is unnecessary in the new edition +error: unused extern crate --> $DIR/unnecessary-extern-crate.rs:16:1 | LL | extern crate alloc; @@ -7,62 +7,92 @@ LL | extern crate alloc; note: lint level defined here --> $DIR/unnecessary-extern-crate.rs:13:9 | -LL | #![deny(unnecessary_extern_crates)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(unused_extern_crates)] + | ^^^^^^^^^^^^^^^^^^^^ -error: `extern crate` is unnecessary in the new edition +error: unused extern crate --> $DIR/unnecessary-extern-crate.rs:19:1 | LL | extern crate alloc as x; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x;` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it -error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:25:1 +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:26:1 | LL | pub extern crate test as y; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y;` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `pub use` -error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:28:1 +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:30:1 | LL | pub extern crate libc; - | ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use libc;` + | ^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `pub use` -error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:34:5 +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:34:1 + | +LL | pub(crate) extern crate libc as a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `pub(crate) use` + +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:38:1 + | +LL | crate extern crate libc as b; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `crate use` + +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:43:5 + | +LL | pub(in crate::foo) extern crate libc as c; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `pub(in crate::foo) use` + +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:47:5 + | +LL | pub(super) extern crate libc as d; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `pub(super) use` + +error: unused extern crate + --> $DIR/unnecessary-extern-crate.rs:51:5 | LL | extern crate alloc; - | ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc;` + | ^^^^^^^^^^^^^^^^^^^ help: remove it -error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:37:5 +error: unused extern crate + --> $DIR/unnecessary-extern-crate.rs:55:5 | LL | extern crate alloc as x; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x;` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it -error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:40:5 +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:59:5 | LL | pub extern crate test; - | ^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test;` + | ^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `pub use` -error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:43:5 +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:63:5 | LL | pub extern crate test as y; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `pub use`: `pub use test as y;` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `pub use` -error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:47:9 +error: unused extern crate + --> $DIR/unnecessary-extern-crate.rs:68:9 | LL | extern crate alloc; - | ^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc;` + | ^^^^^^^^^^^^^^^^^^^ help: remove it -error: `extern crate` is unnecessary in the new edition - --> $DIR/unnecessary-extern-crate.rs:50:9 +error: unused extern crate + --> $DIR/unnecessary-extern-crate.rs:72:9 | LL | extern crate alloc as x; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use alloc as x;` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it + +error: `extern crate` is not idiomatic in the new edition + --> $DIR/unnecessary-extern-crate.rs:76:9 + | +LL | pub(in crate::foo::bar) extern crate libc as e; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `pub(in crate::foo::bar) use` -error: aborting due to 10 previous errors +error: aborting due to 15 previous errors diff --git a/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.nll.stderr b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.nll.stderr new file mode 100644 index 00000000000..95acdab3e80 --- /dev/null +++ b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.nll.stderr @@ -0,0 +1,63 @@ +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:15:21 + | +LL | fn gimme_static_mut_let() -> &'static mut u32 { + | _______________________________________________- +LL | | let ref mut x = 1234543; //~ ERROR + | | ^^^^^^^ temporary value does not live long enough +LL | | x +LL | | } + | | - + | | | + | |_temporary value only lives until here + | borrow later used here + +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:20:25 + | +LL | fn gimme_static_mut_let_nested() -> &'static mut u32 { + | ______________________________________________________- +LL | | let (ref mut x, ) = (1234543, ); //~ ERROR + | | ^^^^^^^^^^^ temporary value does not live long enough +LL | | x +LL | | } + | | - + | | | + | |_temporary value only lives until here + | borrow later used here + +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:25:11 + | +LL | match 1234543 { + | ^^^^^^^ temporary value does not live long enough +... +LL | } + | - temporary value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:31:11 + | +LL | match (123443,) { + | ^^^^^^^^^ temporary value does not live long enough +... +LL | } + | - temporary value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:37:10 + | +LL | &mut 1234543 //~ ERROR + | ^^^^^^^ temporary value does not live long enough +LL | } + | - temporary value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.rs b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.rs new file mode 100644 index 00000000000..4c5f458d6a3 --- /dev/null +++ b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.rs @@ -0,0 +1,41 @@ +// 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. + +// Test that we fail to promote the constant here which has a `ref +// mut` borrow. + +fn gimme_static_mut_let() -> &'static mut u32 { + let ref mut x = 1234543; //~ ERROR + x +} + +fn gimme_static_mut_let_nested() -> &'static mut u32 { + let (ref mut x, ) = (1234543, ); //~ ERROR + x +} + +fn gimme_static_mut_match() -> &'static mut u32 { + match 1234543 { + ref mut x => x //~ ERROR + } +} + +fn gimme_static_mut_match_nested() -> &'static mut u32 { + match (123443,) { + (ref mut x,) => x, //~ ERROR + } +} + +fn gimme_static_mut_ampersand() -> &'static mut u32 { + &mut 1234543 //~ ERROR +} + +fn main() { +} diff --git a/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.stderr b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.stderr new file mode 100644 index 00000000000..931eb7da744 --- /dev/null +++ b/src/test/ui/borrowck/promote-ref-mut-in-let-issue-46557.stderr @@ -0,0 +1,57 @@ +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:15:9 + | +LL | let ref mut x = 1234543; //~ ERROR + | ^^^^^^^^^ temporary value does not live long enough +LL | x +LL | } + | - temporary value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:20:10 + | +LL | let (ref mut x, ) = (1234543, ); //~ ERROR + | ^^^^^^^^^ borrowed value does not live long enough +LL | x +LL | } + | - borrowed value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:26:9 + | +LL | ref mut x => x //~ ERROR + | ^^^^^^^^^ temporary value does not live long enough +LL | } +LL | } + | - temporary value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:32:10 + | +LL | (ref mut x,) => x, //~ ERROR + | ^^^^^^^^^ borrowed value does not live long enough +LL | } +LL | } + | - borrowed value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error[E0597]: borrowed value does not live long enough + --> $DIR/promote-ref-mut-in-let-issue-46557.rs:37:10 + | +LL | &mut 1234543 //~ ERROR + | ^^^^^^^ temporary value does not live long enough +LL | } + | - temporary value only lives until here + | + = note: borrowed value must be valid for the static lifetime... + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/deriving-with-repr-packed.rs b/src/test/ui/deriving-with-repr-packed.rs index 0c52829799e..43375098cb5 100644 --- a/src/test/ui/deriving-with-repr-packed.rs +++ b/src/test/ui/deriving-with-repr-packed.rs @@ -33,7 +33,7 @@ pub struct Bar(u32, u32, u32); struct Y(usize); #[derive(PartialEq)] -//~^ ERROR #[derive] can't be used on a non-Copy #[repr(packed)] +//~^ ERROR #[derive] can't be used //~| hard error #[repr(packed)] struct X(Y); diff --git a/src/test/ui/deriving-with-repr-packed.stderr b/src/test/ui/deriving-with-repr-packed.stderr index 64aefbcd5df..a7599c1e7db 100644 --- a/src/test/ui/deriving-with-repr-packed.stderr +++ b/src/test/ui/deriving-with-repr-packed.stderr @@ -21,7 +21,7 @@ LL | #[derive(Copy, Clone, PartialEq, Eq)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> -error: #[derive] can't be used on a non-Copy #[repr(packed)] struct (error E0133) +error: #[derive] can't be used on a #[repr(packed)] struct that does not derive Copy (error E0133) --> $DIR/deriving-with-repr-packed.rs:26:10 | LL | #[derive(PartialEq, Eq)] @@ -30,7 +30,7 @@ LL | #[derive(PartialEq, Eq)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #46043 <https://github.com/rust-lang/rust/issues/46043> -error: #[derive] can't be used on a non-Copy #[repr(packed)] struct (error E0133) +error: #[derive] can't be used on a #[repr(packed)] struct that does not derive Copy (error E0133) --> $DIR/deriving-with-repr-packed.rs:35:10 | LL | #[derive(PartialEq)] diff --git a/src/test/ui/error-codes/E0152.rs b/src/test/ui/error-codes/E0152.rs index ae501b94e3f..8fbad7b3ff3 100644 --- a/src/test/ui/error-codes/E0152.rs +++ b/src/test/ui/error-codes/E0152.rs @@ -10,7 +10,7 @@ #![feature(lang_items)] -#[lang = "panic_fmt"] +#[lang = "panic_impl"] struct Foo; //~ ERROR E0152 fn main() { diff --git a/src/test/ui/error-codes/E0152.stderr b/src/test/ui/error-codes/E0152.stderr index f67022bd6d3..c7f5f362efb 100644 --- a/src/test/ui/error-codes/E0152.stderr +++ b/src/test/ui/error-codes/E0152.stderr @@ -1,4 +1,4 @@ -error[E0152]: duplicate lang item found: `panic_fmt`. +error[E0152]: duplicate lang item found: `panic_impl`. --> $DIR/E0152.rs:14:1 | LL | struct Foo; //~ ERROR E0152 diff --git a/src/test/ui/issue-23217.stderr b/src/test/ui/issue-23217.stderr index d542a10e9b6..d87f239bca6 100644 --- a/src/test/ui/issue-23217.stderr +++ b/src/test/ui/issue-23217.stderr @@ -6,7 +6,7 @@ LL | pub enum SomeEnum { LL | B = SomeEnum::A, | ^^^^^^^^^^^ variant not found in `SomeEnum` | - = note: did you mean `variant::B`? + = note: did you mean `SomeEnum::B`? error: aborting due to previous error diff --git a/src/test/ui/issue-28971.stderr b/src/test/ui/issue-28971.stderr index df114351ff5..c04e21f7c58 100644 --- a/src/test/ui/issue-28971.stderr +++ b/src/test/ui/issue-28971.stderr @@ -7,7 +7,7 @@ LL | enum Foo { LL | Foo::Baz(..) => (), | ^^^^^^^^^^^^ variant not found in `Foo` | - = note: did you mean `variant::Bar`? + = note: did you mean `Foo::Bar`? error: aborting due to previous error diff --git a/src/test/ui/rfc-2166-underscore-imports/basic.stderr b/src/test/ui/rfc-2166-underscore-imports/basic.stderr index 4530d0fa604..c12c74b50e2 100644 --- a/src/test/ui/rfc-2166-underscore-imports/basic.stderr +++ b/src/test/ui/rfc-2166-underscore-imports/basic.stderr @@ -20,7 +20,7 @@ warning: unused extern crate --> $DIR/basic.rs:33:5 | LL | extern crate core as _; //~ WARN unused extern crate - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | note: lint level defined here --> $DIR/basic.rs:14:25 diff --git a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed new file mode 100644 index 00000000000..4f99c1240f8 --- /dev/null +++ b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.fixed @@ -0,0 +1,36 @@ +// 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-lint-paths.rs +// run-rustfix +// compile-flags:--edition 2018 + +// The "normal case". Ideally we would remove the `extern crate` here, +// but we don't. + +#![feature(rust_2018_preview)] +#![deny(rust_2018_idioms)] +#![allow(dead_code)] + + +//~^ ERROR unused extern crate + +use edition_lint_paths as bar; +//~^ ERROR `extern crate` is not idiomatic in the new edition + +fn main() { + // This is not considered to *use* the `extern crate` in Rust 2018: + use edition_lint_paths::foo; + foo(); + + // But this should be a use of the (renamed) crate: + crate::bar::foo(); +} + diff --git a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs new file mode 100644 index 00000000000..9c1235a2967 --- /dev/null +++ b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.rs @@ -0,0 +1,36 @@ +// 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-lint-paths.rs +// run-rustfix +// compile-flags:--edition 2018 + +// The "normal case". Ideally we would remove the `extern crate` here, +// but we don't. + +#![feature(rust_2018_preview)] +#![deny(rust_2018_idioms)] +#![allow(dead_code)] + +extern crate edition_lint_paths; +//~^ ERROR unused extern crate + +extern crate edition_lint_paths as bar; +//~^ ERROR `extern crate` is not idiomatic in the new edition + +fn main() { + // This is not considered to *use* the `extern crate` in Rust 2018: + use edition_lint_paths::foo; + foo(); + + // But this should be a use of the (renamed) crate: + crate::bar::foo(); +} + diff --git a/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr new file mode 100644 index 00000000000..b3afa2bd1d5 --- /dev/null +++ b/src/test/ui/rust-2018/extern-crate-idiomatic-in-2018.stderr @@ -0,0 +1,21 @@ +error: unused extern crate + --> $DIR/extern-crate-idiomatic-in-2018.rs:22:1 + | +LL | extern crate edition_lint_paths; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it + | +note: lint level defined here + --> $DIR/extern-crate-idiomatic-in-2018.rs:19:9 + | +LL | #![deny(rust_2018_idioms)] + | ^^^^^^^^^^^^^^^^ + = note: #[deny(unused_extern_crates)] implied by #[deny(rust_2018_idioms)] + +error: `extern crate` is not idiomatic in the new edition + --> $DIR/extern-crate-idiomatic-in-2018.rs:25:1 + | +LL | extern crate edition_lint_paths as bar; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert it to a `use` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/suggestions/removing-extern-crate.fixed b/src/test/ui/suggestions/removing-extern-crate.fixed index 723137f5db0..83b35cec809 100644 --- a/src/test/ui/suggestions/removing-extern-crate.fixed +++ b/src/test/ui/suggestions/removing-extern-crate.fixed @@ -16,12 +16,12 @@ #![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.stderr b/src/test/ui/suggestions/removing-extern-crate.stderr index 39d22de0277..f2eed27a266 100644 --- a/src/test/ui/suggestions/removing-extern-crate.stderr +++ b/src/test/ui/suggestions/removing-extern-crate.stderr @@ -1,31 +1,31 @@ -warning: `extern crate` is unnecessary in the new edition +warning: unused extern crate --> $DIR/removing-extern-crate.rs:19:1 | LL | extern crate std as foo; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use std as foo;` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it | note: lint level defined here --> $DIR/removing-extern-crate.rs:16:9 | LL | #![warn(rust_2018_idioms)] | ^^^^^^^^^^^^^^^^ - = note: #[warn(unnecessary_extern_crates)] implied by #[warn(rust_2018_idioms)] + = note: #[warn(unused_extern_crates)] implied by #[warn(rust_2018_idioms)] -warning: `extern crate` is unnecessary in the new edition +warning: unused extern crate --> $DIR/removing-extern-crate.rs:20:1 | LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ help: remove it -warning: `extern crate` is unnecessary in the new edition +warning: unused extern crate --> $DIR/removing-extern-crate.rs:23:5 | LL | extern crate std as foo; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `use`: `use std as foo;` + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it -warning: `extern crate` is unnecessary in the new edition +warning: unused extern crate --> $DIR/removing-extern-crate.rs:24:5 | LL | extern crate std; - | ^^^^^^^^^^^^^^^^^ help: use `use`: `use std;` + | ^^^^^^^^^^^^^^^^^ help: remove it |
