From e421cb153ed136e3bebb5b1a75e54a0e47bfcf3f Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 4 Aug 2020 17:46:10 +0900 Subject: [PATCH 01/15] Forbid non-derefable types explicitly in unsizing casts --- src/librustc_mir/transform/qualify_min_const_fn.rs | 10 +++++++++- src/test/ui/consts/unsizing-cast-non-null.rs | 10 ++++++++++ src/test/ui/consts/unsizing-cast-non-null.stderr | 12 ++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/unsizing-cast-non-null.rs create mode 100644 src/test/ui/consts/unsizing-cast-non-null.stderr diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 52b1eba3b93c2..7b0fc2322fb6b 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -193,7 +193,15 @@ fn check_rvalue( _, ) => Err((span, "function pointer casts are not allowed in const fn".into())), Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), op, cast_ty) => { - let pointee_ty = cast_ty.builtin_deref(true).unwrap().ty; + let pointee_ty = if let Some(deref_ty) = cast_ty.builtin_deref(true) { + deref_ty.ty + } else { + // We cannot allow this for now. + return Err(( + span, + "unsizing casts are only allowed for references right now".into(), + )); + }; let unsized_ty = tcx.struct_tail_erasing_lifetimes(pointee_ty, tcx.param_env(def_id)); if let ty::Slice(_) | ty::Str = unsized_ty.kind { check_operand(tcx, op, span, def_id, body)?; diff --git a/src/test/ui/consts/unsizing-cast-non-null.rs b/src/test/ui/consts/unsizing-cast-non-null.rs new file mode 100644 index 0000000000000..67d9f6baca5b4 --- /dev/null +++ b/src/test/ui/consts/unsizing-cast-non-null.rs @@ -0,0 +1,10 @@ +// Regression test for #75118. + +use std::ptr::NonNull; + +pub const fn dangling_slice() -> NonNull<[T]> { + NonNull::<[T; 0]>::dangling() + //~^ ERROR: unsizing casts are only allowed for references right now +} + +fn main() {} diff --git a/src/test/ui/consts/unsizing-cast-non-null.stderr b/src/test/ui/consts/unsizing-cast-non-null.stderr new file mode 100644 index 0000000000000..6575355daadd7 --- /dev/null +++ b/src/test/ui/consts/unsizing-cast-non-null.stderr @@ -0,0 +1,12 @@ +error[E0723]: unsizing casts are only allowed for references right now + --> $DIR/unsizing-cast-non-null.rs:6:5 + | +LL | NonNull::<[T; 0]>::dangling() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #57563 for more information + = 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`. From 3accd067ae436ad90e2c22d7586a4856398eb4cd Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 4 Aug 2020 07:30:04 +0200 Subject: [PATCH 02/15] forbid `#[track_caller]` on main --- src/librustc_typeck/lib.rs | 36 ++++++++++++++++++- .../rfc-2091-track-caller/error-with-main.rs | 4 +++ .../error-with-main.stderr | 12 +++++++ .../rfc-2091-track-caller/error-with-start.rs | 7 ++++ .../error-with-start.stderr | 12 +++++++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rfc-2091-track-caller/error-with-main.rs create mode 100644 src/test/ui/rfc-2091-track-caller/error-with-main.stderr create mode 100644 src/test/ui/rfc-2091-track-caller/error-with-start.rs create mode 100644 src/test/ui/rfc-2091-track-caller/error-with-start.stderr diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 9ba2545ba63cb..016f68bfc6b3b 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -100,7 +100,7 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::util; use rustc_session::config::EntryFnType; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::{symbol::sym, Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits::error_reporting::InferCtxtExt as _; use rustc_trait_selection::traits::{ @@ -194,6 +194,23 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: LocalDefId) { .emit(); error = true; } + + for attr in it.attrs { + if attr.check_name(sym::track_caller) { + tcx.sess + .struct_span_err( + attr.span, + "`main` function is not allowed to be `#[track_caller]`", + ) + .span_label( + main_span, + "`main` function is not allowed to be `#[track_caller]`", + ) + .emit(); + error = true; + } + } + if error { return; } @@ -274,6 +291,23 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) { .emit(); error = true; } + + for attr in it.attrs { + if attr.check_name(sym::track_caller) { + tcx.sess + .struct_span_err( + attr.span, + "start is not allowed to be `#[track_caller]`", + ) + .span_label( + start_span, + "start is not allowed to be `#[track_caller]`", + ) + .emit(); + error = true; + } + } + if error { return; } diff --git a/src/test/ui/rfc-2091-track-caller/error-with-main.rs b/src/test/ui/rfc-2091-track-caller/error-with-main.rs new file mode 100644 index 0000000000000..b2ea31bb5178b --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/error-with-main.rs @@ -0,0 +1,4 @@ +#[track_caller] //~ ERROR `main` function is not allowed to be +fn main() { + panic!("{}: oh no", std::panic::Location::caller()); +} diff --git a/src/test/ui/rfc-2091-track-caller/error-with-main.stderr b/src/test/ui/rfc-2091-track-caller/error-with-main.stderr new file mode 100644 index 0000000000000..f05f88e7d71ea --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/error-with-main.stderr @@ -0,0 +1,12 @@ +error: `main` function is not allowed to be `#[track_caller]` + --> $DIR/error-with-main.rs:1:1 + | +LL | #[track_caller] + | ^^^^^^^^^^^^^^^ +LL | / fn main() { +LL | | panic!("{}: oh no", std::panic::Location::caller()); +LL | | } + | |_- `main` function is not allowed to be `#[track_caller]` + +error: aborting due to previous error + diff --git a/src/test/ui/rfc-2091-track-caller/error-with-start.rs b/src/test/ui/rfc-2091-track-caller/error-with-start.rs new file mode 100644 index 0000000000000..678cb7fa404f5 --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/error-with-start.rs @@ -0,0 +1,7 @@ +#![feature(start)] + +#[start] +#[track_caller] //~ ERROR start is not allowed to be `#[track_caller]` +fn start(_argc: isize, _argv: *const *const u8) -> isize { + panic!("{}: oh no", std::panic::Location::caller()); +} diff --git a/src/test/ui/rfc-2091-track-caller/error-with-start.stderr b/src/test/ui/rfc-2091-track-caller/error-with-start.stderr new file mode 100644 index 0000000000000..03b2ce5514f55 --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/error-with-start.stderr @@ -0,0 +1,12 @@ +error: start is not allowed to be `#[track_caller]` + --> $DIR/error-with-start.rs:4:1 + | +LL | #[track_caller] + | ^^^^^^^^^^^^^^^ +LL | / fn start(_argc: isize, _argv: *const *const u8) -> isize { +LL | | panic!("{}: oh no", std::panic::Location::caller()); +LL | | } + | |_- start is not allowed to be `#[track_caller]` + +error: aborting due to previous error + From c5d167a4b1e25b63da9c735a14ab51ac73db7f96 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 4 Aug 2020 21:36:21 +0200 Subject: [PATCH 03/15] tweak error message --- src/librustc_typeck/lib.rs | 8 ++++---- src/test/ui/async-await/issue-68523-start.rs | 2 +- src/test/ui/async-await/issue-68523-start.stderr | 4 ++-- src/test/ui/rfc-2091-track-caller/error-with-start.rs | 2 +- src/test/ui/rfc-2091-track-caller/error-with-start.stderr | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 016f68bfc6b3b..e203d51f612aa 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -285,9 +285,9 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) { tcx.sess, span, E0752, - "start is not allowed to be `async`" + "`start` is not allowed to be `async`" ) - .span_label(span, "start is not allowed to be `async`") + .span_label(span, "`start` is not allowed to be `async`") .emit(); error = true; } @@ -297,11 +297,11 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: LocalDefId) { tcx.sess .struct_span_err( attr.span, - "start is not allowed to be `#[track_caller]`", + "`start` is not allowed to be `#[track_caller]`", ) .span_label( start_span, - "start is not allowed to be `#[track_caller]`", + "`start` is not allowed to be `#[track_caller]`", ) .emit(); error = true; diff --git a/src/test/ui/async-await/issue-68523-start.rs b/src/test/ui/async-await/issue-68523-start.rs index 5988dffd68fa7..2ced88a16cc45 100644 --- a/src/test/ui/async-await/issue-68523-start.rs +++ b/src/test/ui/async-await/issue-68523-start.rs @@ -4,6 +4,6 @@ #[start] pub async fn start(_: isize, _: *const *const u8) -> isize { -//~^ ERROR start is not allowed to be `async` +//~^ ERROR `start` is not allowed to be `async` 0 } diff --git a/src/test/ui/async-await/issue-68523-start.stderr b/src/test/ui/async-await/issue-68523-start.stderr index e471945900e7d..3a0a3b5dece10 100644 --- a/src/test/ui/async-await/issue-68523-start.stderr +++ b/src/test/ui/async-await/issue-68523-start.stderr @@ -1,8 +1,8 @@ -error[E0752]: start is not allowed to be `async` +error[E0752]: `start` is not allowed to be `async` --> $DIR/issue-68523-start.rs:6:1 | LL | pub async fn start(_: isize, _: *const *const u8) -> isize { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ start is not allowed to be `async` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `start` is not allowed to be `async` error: aborting due to previous error diff --git a/src/test/ui/rfc-2091-track-caller/error-with-start.rs b/src/test/ui/rfc-2091-track-caller/error-with-start.rs index 678cb7fa404f5..0cab47170631b 100644 --- a/src/test/ui/rfc-2091-track-caller/error-with-start.rs +++ b/src/test/ui/rfc-2091-track-caller/error-with-start.rs @@ -1,7 +1,7 @@ #![feature(start)] #[start] -#[track_caller] //~ ERROR start is not allowed to be `#[track_caller]` +#[track_caller] //~ ERROR `start` is not allowed to be `#[track_caller]` fn start(_argc: isize, _argv: *const *const u8) -> isize { panic!("{}: oh no", std::panic::Location::caller()); } diff --git a/src/test/ui/rfc-2091-track-caller/error-with-start.stderr b/src/test/ui/rfc-2091-track-caller/error-with-start.stderr index 03b2ce5514f55..1a1f3e0449136 100644 --- a/src/test/ui/rfc-2091-track-caller/error-with-start.stderr +++ b/src/test/ui/rfc-2091-track-caller/error-with-start.stderr @@ -1,4 +1,4 @@ -error: start is not allowed to be `#[track_caller]` +error: `start` is not allowed to be `#[track_caller]` --> $DIR/error-with-start.rs:4:1 | LL | #[track_caller] @@ -6,7 +6,7 @@ LL | #[track_caller] LL | / fn start(_argc: isize, _argv: *const *const u8) -> isize { LL | | panic!("{}: oh no", std::panic::Location::caller()); LL | | } - | |_- start is not allowed to be `#[track_caller]` + | |_- `start` is not allowed to be `#[track_caller]` error: aborting due to previous error From e69dd7ad3b561bf77f92503c48d5ba49be5130b7 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Sun, 26 Jul 2020 09:53:24 -0700 Subject: [PATCH 04/15] Fix #[track_caller] shims for trait objects. We were missing an Instance::resolve_for_fn_ptr in resolve_for_vtable. Closes #74764. --- src/librustc_middle/ty/instance.rs | 2 +- .../tracked-trait-obj.rs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index d628d6783d5b0..374e5a83453e7 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -375,7 +375,7 @@ impl<'tcx> Instance<'tcx> { debug!(" => associated item with unsizeable self: Self"); Some(Instance { def: InstanceDef::VtableShim(def_id), substs }) } else { - Instance::resolve(tcx, param_env, def_id, substs).ok().flatten() + Instance::resolve_for_fn_ptr(tcx, param_env, def_id, substs) } } diff --git a/src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs b/src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs new file mode 100644 index 0000000000000..3b2a2238fa82d --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/tracked-trait-obj.rs @@ -0,0 +1,23 @@ +// run-pass + +trait Tracked { + #[track_caller] + fn handle(&self) { + let location = std::panic::Location::caller(); + assert_eq!(location.file(), file!()); + // we only call this via trait object, so the def site should *always* be returned + assert_eq!(location.line(), line!() - 4); + assert_eq!(location.column(), 5); + } +} + +impl Tracked for () {} +impl Tracked for u8 {} + +fn main() { + let tracked: &dyn Tracked = &5u8; + tracked.handle(); + + const TRACKED: &dyn Tracked = &(); + TRACKED.handle(); +} From 346dc2ff9c4f152e229ef6886a5c2357f12e4587 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 22 Jul 2020 15:49:04 +0300 Subject: [PATCH 05/15] rustc_target: Add a target spec option for disabling `--eh-frame-hdr` --- src/librustc_codegen_ssa/back/link.rs | 4 +++- src/librustc_codegen_ssa/back/linker.rs | 8 +------- src/librustc_target/spec/apple_base.rs | 1 + src/librustc_target/spec/freestanding_base.rs | 1 + src/librustc_target/spec/illumos_base.rs | 1 + src/librustc_target/spec/mod.rs | 8 ++++++++ src/librustc_target/spec/msp430_none_elf.rs | 2 ++ src/librustc_target/spec/riscv32i_unknown_none_elf.rs | 1 + src/librustc_target/spec/riscv32imac_unknown_none_elf.rs | 1 + src/librustc_target/spec/riscv32imc_unknown_none_elf.rs | 1 + src/librustc_target/spec/riscv64gc_unknown_none_elf.rs | 1 + src/librustc_target/spec/riscv64imac_unknown_none_elf.rs | 1 + src/librustc_target/spec/solaris_base.rs | 1 + src/librustc_target/spec/windows_gnu_base.rs | 1 + 14 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 3adaa07db91b0..eed068e2933af 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1598,7 +1598,9 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( } // NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER - cmd.add_eh_frame_header(); + if sess.target.target.options.eh_frame_header { + cmd.add_eh_frame_header(); + } // NO-OPT-OUT, OBJECT-FILES-NO if crt_objects_fallback { diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs index e64aafa599fd8..d1ae9e372695f 100644 --- a/src/librustc_codegen_ssa/back/linker.rs +++ b/src/librustc_codegen_ssa/back/linker.rs @@ -619,13 +619,7 @@ impl<'a> Linker for GccLinker<'a> { // Some versions of `gcc` add it implicitly, some (e.g. `musl-gcc`) don't, // so we just always add it. fn add_eh_frame_header(&mut self) { - if !self.sess.target.target.options.is_like_osx - && !self.sess.target.target.options.is_like_windows - && !self.sess.target.target.options.is_like_solaris - && self.sess.target.target.target_os != "uefi" - { - self.linker_arg("--eh-frame-hdr"); - } + self.linker_arg("--eh-frame-hdr"); } } diff --git a/src/librustc_target/spec/apple_base.rs b/src/librustc_target/spec/apple_base.rs index bdd5a893d34e2..e7b565ae9cad9 100644 --- a/src/librustc_target/spec/apple_base.rs +++ b/src/librustc_target/spec/apple_base.rs @@ -31,6 +31,7 @@ pub fn opts() -> TargetOptions { has_elf_tls: version >= (10, 7), abi_return_struct_as_int: true, emit_debug_gdb_scripts: false, + eh_frame_header: false, // This environment variable is pretty magical but is intended for // producing deterministic builds. This was first discovered to be used diff --git a/src/librustc_target/spec/freestanding_base.rs b/src/librustc_target/spec/freestanding_base.rs index 5402ea074fae1..c338856228dc6 100644 --- a/src/librustc_target/spec/freestanding_base.rs +++ b/src/librustc_target/spec/freestanding_base.rs @@ -25,6 +25,7 @@ pub fn opts() -> TargetOptions { has_rpath: false, pre_link_args: args, position_independent_executables: false, + eh_frame_header: false, ..Default::default() } } diff --git a/src/librustc_target/spec/illumos_base.rs b/src/librustc_target/spec/illumos_base.rs index 35ac346fb3f6f..214142b88fc2c 100644 --- a/src/librustc_target/spec/illumos_base.rs +++ b/src/librustc_target/spec/illumos_base.rs @@ -23,6 +23,7 @@ pub fn opts() -> TargetOptions { is_like_solaris: true, limit_rdylib_exports: false, // Linker doesn't support this eliminate_frame_pointer: false, + eh_frame_header: false, late_link_args, // While we support ELF TLS, rust requires a way to register diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 4a2dd8913185f..712dc51a83af1 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -989,6 +989,11 @@ pub struct TargetOptions { /// Whether to use legacy .ctors initialization hooks rather than .init_array. Defaults /// to false (uses .init_array). pub use_ctors_section: bool, + + /// Whether the linker is instructed to add a `GNU_EH_FRAME` ELF header + /// used to locate unwinding information is passed + /// (only has effect if the linker is `ld`-like). + pub eh_frame_header: bool, } impl Default for TargetOptions { @@ -1081,6 +1086,7 @@ impl Default for TargetOptions { relax_elf_relocations: false, llvm_args: vec![], use_ctors_section: false, + eh_frame_header: true, } } } @@ -1474,6 +1480,7 @@ impl Target { key!(relax_elf_relocations, bool); key!(llvm_args, list); key!(use_ctors_section, bool); + key!(eh_frame_header, bool); // NB: The old name is deprecated, but support for it is retained for // compatibility. @@ -1712,6 +1719,7 @@ impl ToJson for Target { target_option_val!(relax_elf_relocations); target_option_val!(llvm_args); target_option_val!(use_ctors_section); + target_option_val!(eh_frame_header); if default.unsupported_abis != self.options.unsupported_abis { d.insert( diff --git a/src/librustc_target/spec/msp430_none_elf.rs b/src/librustc_target/spec/msp430_none_elf.rs index c6d0308f8f82f..f75697996ac78 100644 --- a/src/librustc_target/spec/msp430_none_elf.rs +++ b/src/librustc_target/spec/msp430_none_elf.rs @@ -56,6 +56,8 @@ pub fn target() -> TargetResult { // See the thumb_base.rs file for an explanation of this value emit_debug_gdb_scripts: false, + eh_frame_header: false, + ..Default::default() }, }) diff --git a/src/librustc_target/spec/riscv32i_unknown_none_elf.rs b/src/librustc_target/spec/riscv32i_unknown_none_elf.rs index 977aa896f2520..5b5e342000b55 100644 --- a/src/librustc_target/spec/riscv32i_unknown_none_elf.rs +++ b/src/librustc_target/spec/riscv32i_unknown_none_elf.rs @@ -25,6 +25,7 @@ pub fn target() -> TargetResult { relocation_model: RelocModel::Static, emit_debug_gdb_scripts: false, unsupported_abis: super::riscv_base::unsupported_abis(), + eh_frame_header: false, ..Default::default() }, }) diff --git a/src/librustc_target/spec/riscv32imac_unknown_none_elf.rs b/src/librustc_target/spec/riscv32imac_unknown_none_elf.rs index 1a85cdff1315c..4cef5c42d8ddf 100644 --- a/src/librustc_target/spec/riscv32imac_unknown_none_elf.rs +++ b/src/librustc_target/spec/riscv32imac_unknown_none_elf.rs @@ -25,6 +25,7 @@ pub fn target() -> TargetResult { relocation_model: RelocModel::Static, emit_debug_gdb_scripts: false, unsupported_abis: super::riscv_base::unsupported_abis(), + eh_frame_header: false, ..Default::default() }, }) diff --git a/src/librustc_target/spec/riscv32imc_unknown_none_elf.rs b/src/librustc_target/spec/riscv32imc_unknown_none_elf.rs index e3c1c6908a23a..8ad563e441de3 100644 --- a/src/librustc_target/spec/riscv32imc_unknown_none_elf.rs +++ b/src/librustc_target/spec/riscv32imc_unknown_none_elf.rs @@ -25,6 +25,7 @@ pub fn target() -> TargetResult { relocation_model: RelocModel::Static, emit_debug_gdb_scripts: false, unsupported_abis: super::riscv_base::unsupported_abis(), + eh_frame_header: false, ..Default::default() }, }) diff --git a/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs b/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs index 857af4ceb0d9f..3aeb3f3ca72b2 100644 --- a/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs +++ b/src/librustc_target/spec/riscv64gc_unknown_none_elf.rs @@ -26,6 +26,7 @@ pub fn target() -> TargetResult { code_model: Some(CodeModel::Medium), emit_debug_gdb_scripts: false, unsupported_abis: super::riscv_base::unsupported_abis(), + eh_frame_header: false, ..Default::default() }, }) diff --git a/src/librustc_target/spec/riscv64imac_unknown_none_elf.rs b/src/librustc_target/spec/riscv64imac_unknown_none_elf.rs index 36fe7730f95bf..d8144964dc913 100644 --- a/src/librustc_target/spec/riscv64imac_unknown_none_elf.rs +++ b/src/librustc_target/spec/riscv64imac_unknown_none_elf.rs @@ -26,6 +26,7 @@ pub fn target() -> TargetResult { code_model: Some(CodeModel::Medium), emit_debug_gdb_scripts: false, unsupported_abis: super::riscv_base::unsupported_abis(), + eh_frame_header: false, ..Default::default() }, }) diff --git a/src/librustc_target/spec/solaris_base.rs b/src/librustc_target/spec/solaris_base.rs index 8d3a3563f4164..3d7f0034b8b10 100644 --- a/src/librustc_target/spec/solaris_base.rs +++ b/src/librustc_target/spec/solaris_base.rs @@ -8,6 +8,7 @@ pub fn opts() -> TargetOptions { target_family: Some("unix".to_string()), is_like_solaris: true, limit_rdylib_exports: false, // Linker doesn't support this + eh_frame_header: false, ..Default::default() } diff --git a/src/librustc_target/spec/windows_gnu_base.rs b/src/librustc_target/spec/windows_gnu_base.rs index 680dbbad4b0a0..69236e98e58d7 100644 --- a/src/librustc_target/spec/windows_gnu_base.rs +++ b/src/librustc_target/spec/windows_gnu_base.rs @@ -91,6 +91,7 @@ pub fn opts() -> TargetOptions { abi_return_struct_as_int: true, emit_debug_gdb_scripts: false, requires_uwtable: true, + eh_frame_header: false, ..Default::default() } From d3aaac0c86475a8a7a71bcd796cf7f12a53b7428 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 20 Jul 2020 17:11:30 +0200 Subject: [PATCH 06/15] ci: allow RLA to pick the right PR number --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ src/ci/github-actions/ci.yml | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1a2505883106..b3d6d0badf8a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,11 @@ jobs: with: github_token: "${{ secrets.github_token }}" if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try'" + - name: configure the PR in which the error message will be posted + run: "echo \"[CI_PR_NUMBER=$num]\"" + env: + num: "${{ github.event.number }}" + if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'" - name: add extra environment variables run: src/ci/scripts/setup-environment.sh env: @@ -162,6 +167,11 @@ jobs: with: github_token: "${{ secrets.github_token }}" if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try'" + - name: configure the PR in which the error message will be posted + run: "echo \"[CI_PR_NUMBER=$num]\"" + env: + num: "${{ github.event.number }}" + if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'" - name: add extra environment variables run: src/ci/scripts/setup-environment.sh env: @@ -473,6 +483,11 @@ jobs: with: github_token: "${{ secrets.github_token }}" if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try'" + - name: configure the PR in which the error message will be posted + run: "echo \"[CI_PR_NUMBER=$num]\"" + env: + num: "${{ github.event.number }}" + if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'" - name: add extra environment variables run: src/ci/scripts/setup-environment.sh env: @@ -598,6 +613,11 @@ jobs: with: github_token: "${{ secrets.github_token }}" if: "success() && !env.SKIP_JOB && github.ref != 'refs/heads/try'" + - name: configure the PR in which the error message will be posted + run: "echo \"[CI_PR_NUMBER=$num]\"" + env: + num: "${{ github.event.number }}" + if: "success() && !env.SKIP_JOBS && github.event_name == 'pull_request'" - name: add extra environment variables run: src/ci/scripts/setup-environment.sh env: diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 978a0c56eb672..5db94b56e504d 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -92,6 +92,15 @@ x--expand-yaml-anchors--remove: if: success() && !env.SKIP_JOB && github.ref != 'refs/heads/try' <<: *step + # Rust Log Analyzer can't currently detect the PR number of a GitHub + # Actions build on its own, so a hint in the log message is needed to + # point it in the right direction. + - name: configure the PR in which the error message will be posted + run: echo "[CI_PR_NUMBER=$num]" + env: + num: ${{ github.event.number }} + if: success() && !env.SKIP_JOBS && github.event_name == 'pull_request' + - name: add extra environment variables run: src/ci/scripts/setup-environment.sh env: From b5ad15b6ebc6fac580dfd56aaf056102f1958e77 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Mon, 20 Jul 2020 17:43:48 +0200 Subject: [PATCH 07/15] ci: upload non-macOS from GHA instead of Azure Pipelines --- .github/workflows/ci.yml | 48 +++++++++++++++---------------- src/ci/azure-pipelines/auto.yml | 5 +++- src/ci/azure-pipelines/master.yml | 2 +- src/ci/azure-pipelines/try.yml | 2 +- src/ci/github-actions/ci.yml | 23 ++++++++++++--- 5 files changed, 49 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3d6d0badf8a6..214de914b097c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,9 +32,9 @@ jobs: name: PR env: CI_JOB_NAME: "${{ matrix.name }}" - SCCACHE_BUCKET: rust-lang-gha-caches - TOOLSTATE_REPO: "https://github.com/pietroalbini/rust-toolstate" - CACHE_DOMAIN: ci-caches-gha.rust-lang.org + SCCACHE_BUCKET: rust-lang-ci-sccache2 + TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" + CACHE_DOMAIN: ci-caches.rust-lang.org if: "github.event_name == 'pull_request'" strategy: matrix: @@ -138,14 +138,14 @@ jobs: name: try env: CI_JOB_NAME: "${{ matrix.name }}" - SCCACHE_BUCKET: rust-lang-gha-caches - DEPLOY_BUCKET: rust-lang-gha - TOOLSTATE_REPO: "https://github.com/pietroalbini/rust-toolstate" - TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/pietroalbini/rust-toolstate/issues" + SCCACHE_BUCKET: rust-lang-ci-sccache2 + DEPLOY_BUCKET: rust-lang-ci2 + TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" + TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" TOOLSTATE_PUBLISH: 1 - CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZOMUQATD5 - ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZH5AYXDVF - CACHE_DOMAIN: ci-caches-gha.rust-lang.org + CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL + ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 + CACHE_DOMAIN: ci-caches.rust-lang.org if: "github.event_name == 'push' && github.ref == 'refs/heads/try' && github.repository == 'rust-lang-ci/rust'" strategy: matrix: @@ -242,14 +242,14 @@ jobs: name: auto env: CI_JOB_NAME: "${{ matrix.name }}" - SCCACHE_BUCKET: rust-lang-gha-caches - DEPLOY_BUCKET: rust-lang-gha - TOOLSTATE_REPO: "https://github.com/pietroalbini/rust-toolstate" - TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/pietroalbini/rust-toolstate/issues" + SCCACHE_BUCKET: rust-lang-ci-sccache2 + DEPLOY_BUCKET: rust-lang-ci2 + TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" + TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" TOOLSTATE_PUBLISH: 1 - CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZOMUQATD5 - ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZH5AYXDVF - CACHE_DOMAIN: ci-caches-gha.rust-lang.org + CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL + ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 + CACHE_DOMAIN: ci-caches.rust-lang.org if: "github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'" strategy: matrix: @@ -688,14 +688,14 @@ jobs: name: master runs-on: ubuntu-latest env: - SCCACHE_BUCKET: rust-lang-gha-caches - DEPLOY_BUCKET: rust-lang-gha - TOOLSTATE_REPO: "https://github.com/pietroalbini/rust-toolstate" - TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/pietroalbini/rust-toolstate/issues" + SCCACHE_BUCKET: rust-lang-ci-sccache2 + DEPLOY_BUCKET: rust-lang-ci2 + TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate" + TOOLSTATE_ISSUES_API_URL: "https://api.github.com/repos/rust-lang/rust/issues" TOOLSTATE_PUBLISH: 1 - CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZOMUQATD5 - ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZH5AYXDVF - CACHE_DOMAIN: ci-caches-gha.rust-lang.org + CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL + ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 + CACHE_DOMAIN: ci-caches.rust-lang.org if: "github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'rust-lang-ci/rust'" steps: - name: checkout the source code diff --git a/src/ci/azure-pipelines/auto.yml b/src/ci/azure-pipelines/auto.yml index 3de5a19f85164..2e9cff1413a01 100644 --- a/src/ci/azure-pipelines/auto.yml +++ b/src/ci/azure-pipelines/auto.yml @@ -18,7 +18,7 @@ trigger: - auto variables: -- group: prod-credentials +- group: dummy-credentials jobs: - job: Linux @@ -77,6 +77,9 @@ jobs: vmImage: macos-10.15 steps: - template: steps/run.yml + variables: + # We're still uploading macOS builds from Azure Pipelines. + - group: prod-credentials strategy: matrix: # OSX builders running tests, these run the full test suite. diff --git a/src/ci/azure-pipelines/master.yml b/src/ci/azure-pipelines/master.yml index 485b80398c8e4..13c55610e1a46 100644 --- a/src/ci/azure-pipelines/master.yml +++ b/src/ci/azure-pipelines/master.yml @@ -18,7 +18,7 @@ trigger: - master variables: -- group: prod-credentials +- group: dummy-credentials pool: vmImage: ubuntu-16.04 diff --git a/src/ci/azure-pipelines/try.yml b/src/ci/azure-pipelines/try.yml index 818306a009229..eebc5ccdaf69c 100644 --- a/src/ci/azure-pipelines/try.yml +++ b/src/ci/azure-pipelines/try.yml @@ -14,7 +14,7 @@ trigger: - try variables: -- group: prod-credentials +- group: dummy-credentials jobs: - job: Linux diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml index 5db94b56e504d..7783d3b4963e9 100644 --- a/src/ci/github-actions/ci.yml +++ b/src/ci/github-actions/ci.yml @@ -35,11 +35,26 @@ x--expand-yaml-anchors--remove: CI_JOB_NAME: ${{ matrix.name }} - &public-variables - SCCACHE_BUCKET: rust-lang-gha-caches - TOOLSTATE_REPO: https://github.com/pietroalbini/rust-toolstate - CACHE_DOMAIN: ci-caches-gha.rust-lang.org + SCCACHE_BUCKET: rust-lang-ci-sccache2 + TOOLSTATE_REPO: https://github.com/rust-lang-nursery/rust-toolstate + CACHE_DOMAIN: ci-caches.rust-lang.org - &prod-variables + SCCACHE_BUCKET: rust-lang-ci-sccache2 + DEPLOY_BUCKET: rust-lang-ci2 + TOOLSTATE_REPO: https://github.com/rust-lang-nursery/rust-toolstate + TOOLSTATE_ISSUES_API_URL: https://api.github.com/repos/rust-lang/rust/issues + TOOLSTATE_PUBLISH: 1 + # AWS_SECRET_ACCESS_KEYs are stored in GitHub's secrets storage, named + # AWS_SECRET_ACCESS_KEY_. Including the key id in the name allows to + # rotate them in a single branch while keeping the old key in another + # branch, which wouldn't be possible if the key was named with the kind + # (caches, artifacts...). + CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL + ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55 + CACHE_DOMAIN: ci-caches.rust-lang.org + + - &dummy-variables SCCACHE_BUCKET: rust-lang-gha-caches DEPLOY_BUCKET: rust-lang-gha TOOLSTATE_REPO: https://github.com/pietroalbini/rust-toolstate @@ -559,7 +574,7 @@ jobs: <<: *base-ci-job name: auto-fallible env: - <<: [*shared-ci-variables, *prod-variables] + <<: [*shared-ci-variables, *dummy-variables] if: github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust' strategy: matrix: From ec98df7e67ffa0784194dec8df9a0a388158519b Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 22 Jul 2020 11:00:56 +0200 Subject: [PATCH 08/15] ci: disable Azure Pipelines except for macOS --- src/ci/azure-pipelines/auto.yml | 167 +----------------------------- src/ci/azure-pipelines/master.yml | 33 ------ src/ci/azure-pipelines/pr.yml | 35 ------- src/ci/azure-pipelines/try.yml | 64 +----------- 4 files changed, 3 insertions(+), 296 deletions(-) delete mode 100644 src/ci/azure-pipelines/master.yml delete mode 100644 src/ci/azure-pipelines/pr.yml diff --git a/src/ci/azure-pipelines/auto.yml b/src/ci/azure-pipelines/auto.yml index 2e9cff1413a01..06e284c763c15 100644 --- a/src/ci/azure-pipelines/auto.yml +++ b/src/ci/azure-pipelines/auto.yml @@ -10,67 +10,14 @@ ##################################### # -# Azure Pipelines "auto" branch build for Rust on Linux, macOS, and Windows. +# Azure Pipelines "auto" branch build for Rust on macOS # pr: none trigger: - auto -variables: -- group: dummy-credentials - jobs: -- job: Linux - timeoutInMinutes: 600 - pool: - vmImage: ubuntu-16.04 - steps: - - template: steps/run.yml - strategy: - matrix: - x86_64-gnu-llvm-8: - RUST_BACKTRACE: 1 - dist-x86_64-linux: {} - dist-x86_64-linux-alt: - IMAGE: dist-x86_64-linux - arm-android: {} - armhf-gnu: {} - dist-various-1: {} - dist-various-2: {} - dist-aarch64-linux: {} - dist-android: {} - dist-arm-linux: {} - dist-armhf-linux: {} - dist-armv7-linux: {} - dist-i586-gnu-i586-i686-musl: {} - dist-i686-freebsd: {} - dist-i686-linux: {} - dist-mips-linux: {} - dist-mips64-linux: {} - dist-mips64el-linux: {} - dist-mipsel-linux: {} - dist-powerpc-linux: {} - dist-powerpc64-linux: {} - dist-powerpc64le-linux: {} - dist-s390x-linux: {} - dist-x86_64-freebsd: {} - dist-x86_64-musl: {} - dist-x86_64-netbsd: {} - i686-gnu: {} - i686-gnu-nopt: {} - test-various: {} - wasm32: {} - x86_64-gnu: {} - x86_64-gnu-full-bootstrap: {} - x86_64-gnu-aux: {} - x86_64-gnu-tools: - DEPLOY_TOOLSTATES_JSON: toolstates-linux.json - x86_64-gnu-debug: {} - x86_64-gnu-nopt: {} - x86_64-gnu-distcheck: {} - mingw-check: {} - - job: macOS timeoutInMinutes: 600 pool: @@ -113,115 +60,3 @@ jobs: MACOSX_DEPLOYMENT_TARGET: 10.7 NO_LLVM_ASSERTIONS: 1 NO_DEBUG_ASSERTIONS: 1 - - -- job: Windows - timeoutInMinutes: 600 - pool: - vmImage: 'vs2017-win2016' - steps: - - template: steps/run.yml - strategy: - matrix: - # 32/64 bit MSVC tests - x86_64-msvc-1: - INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-profiler - SCRIPT: make ci-subset-1 - # FIXME(#59637) - NO_DEBUG_ASSERTIONS: 1 - NO_LLVM_ASSERTIONS: 1 - x86_64-msvc-2: - INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-profiler - SCRIPT: make ci-subset-2 - i686-msvc-1: - INITIAL_RUST_CONFIGURE_ARGS: --build=i686-pc-windows-msvc - SCRIPT: make ci-subset-1 - # FIXME(#59637) - NO_DEBUG_ASSERTIONS: 1 - NO_LLVM_ASSERTIONS: 1 - i686-msvc-2: - INITIAL_RUST_CONFIGURE_ARGS: --build=i686-pc-windows-msvc - SCRIPT: make ci-subset-2 - # FIXME(#59637) - NO_DEBUG_ASSERTIONS: 1 - NO_LLVM_ASSERTIONS: 1 - x86_64-msvc-cargo: - SCRIPT: python x.py test src/tools/cargotest src/tools/cargo - INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-lld - VCVARS_BAT: vcvars64.bat - # FIXME(#59637) - NO_DEBUG_ASSERTIONS: 1 - NO_LLVM_ASSERTIONS: 1 - # MSVC tools tests - x86_64-msvc-tools: - SCRIPT: src/ci/docker/host-x86_64/x86_64-gnu-tools/checktools.sh x.py - INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --save-toolstates=/tmp/toolstate/toolstates.json - - # 32/64-bit MinGW builds. - # - # We are using MinGW with posix threads since LLVM does not compile with - # the win32 threads version due to missing support for C++'s std::thread. - # - # Instead of relying on the MinGW version installed on appveryor we download - # and install one ourselves so we won't be surprised by changes to appveyor's - # build image. - # - # Finally, note that the downloads below are all in the `rust-lang-ci` S3 - # bucket, but they cleraly didn't originate there! The downloads originally - # came from the mingw-w64 SourceForge download site. Unfortunately - # SourceForge is notoriously flaky, so we mirror it on our own infrastructure. - i686-mingw-1: - INITIAL_RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu - SCRIPT: make ci-mingw-subset-1 - CUSTOM_MINGW: 1 - # FIXME(#59637) - NO_DEBUG_ASSERTIONS: 1 - NO_LLVM_ASSERTIONS: 1 - i686-mingw-2: - INITIAL_RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu - SCRIPT: make ci-mingw-subset-2 - CUSTOM_MINGW: 1 - x86_64-mingw-1: - SCRIPT: make ci-mingw-subset-1 - INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu - CUSTOM_MINGW: 1 - # FIXME(#59637) - NO_DEBUG_ASSERTIONS: 1 - NO_LLVM_ASSERTIONS: 1 - x86_64-mingw-2: - SCRIPT: make ci-mingw-subset-2 - INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu - CUSTOM_MINGW: 1 - - # 32/64 bit MSVC and GNU deployment - dist-x86_64-msvc: - INITIAL_RUST_CONFIGURE_ARGS: >- - --build=x86_64-pc-windows-msvc - --target=x86_64-pc-windows-msvc,aarch64-pc-windows-msvc - --enable-full-tools - --enable-profiler - SCRIPT: python x.py dist - DIST_REQUIRE_ALL_TOOLS: 1 - dist-i686-msvc: - INITIAL_RUST_CONFIGURE_ARGS: >- - --build=i686-pc-windows-msvc - --target=i586-pc-windows-msvc - --enable-full-tools - --enable-profiler - SCRIPT: python x.py dist - DIST_REQUIRE_ALL_TOOLS: 1 - dist-i686-mingw: - INITIAL_RUST_CONFIGURE_ARGS: --build=i686-pc-windows-gnu --enable-full-tools --enable-profiler - SCRIPT: python x.py dist - CUSTOM_MINGW: 1 - DIST_REQUIRE_ALL_TOOLS: 1 - dist-x86_64-mingw: - SCRIPT: python x.py dist - INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-gnu --enable-full-tools --enable-profiler - CUSTOM_MINGW: 1 - DIST_REQUIRE_ALL_TOOLS: 1 - - # "alternate" deployment, see .travis.yml for more info - dist-x86_64-msvc-alt: - INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler - SCRIPT: python x.py dist diff --git a/src/ci/azure-pipelines/master.yml b/src/ci/azure-pipelines/master.yml deleted file mode 100644 index 13c55610e1a46..0000000000000 --- a/src/ci/azure-pipelines/master.yml +++ /dev/null @@ -1,33 +0,0 @@ -##################################### -## READ BEFORE CHANGING THIS ## -##################################### - -# We're in the process of evaluating GitHub Actions as a possible replacement -# for Azure Pipelines, and at the moment the configuration is duplicated -# between the two CI providers. Be sure to also change the configuration in -# src/ci/github-actions when changing this file. - -##################################### - -# -# Azure Pipelines job to publish toolstate. Only triggers on pushes to master. -# - -pr: none -trigger: - - master - -variables: -- group: dummy-credentials - -pool: - vmImage: ubuntu-16.04 - -steps: -- checkout: self - fetchDepth: 2 - -- script: src/ci/publish_toolstate.sh - displayName: Publish toolstate - env: - TOOLSTATE_REPO_ACCESS_TOKEN: $(TOOLSTATE_REPO_ACCESS_TOKEN) diff --git a/src/ci/azure-pipelines/pr.yml b/src/ci/azure-pipelines/pr.yml deleted file mode 100644 index 1fc8d187242f8..0000000000000 --- a/src/ci/azure-pipelines/pr.yml +++ /dev/null @@ -1,35 +0,0 @@ -##################################### -## READ BEFORE CHANGING THIS ## -##################################### - -# We're in the process of evaluating GitHub Actions as a possible replacement -# for Azure Pipelines, and at the moment the configuration is duplicated -# between the two CI providers. Be sure to also change the configuration in -# src/ci/github-actions when changing this file. - -##################################### - -# -# Azure Pipelines pull request build for Rust -# - -trigger: none -pr: -- master - -variables: -- group: public-credentials - -jobs: -- job: Linux - timeoutInMinutes: 600 - pool: - vmImage: ubuntu-16.04 - steps: - - template: steps/run.yml - strategy: - matrix: - x86_64-gnu-llvm-8: {} - mingw-check: {} - x86_64-gnu-tools: - CI_ONLY_WHEN_SUBMODULES_CHANGED: 1 diff --git a/src/ci/azure-pipelines/try.yml b/src/ci/azure-pipelines/try.yml index eebc5ccdaf69c..62bb6f4733412 100644 --- a/src/ci/azure-pipelines/try.yml +++ b/src/ci/azure-pipelines/try.yml @@ -13,70 +13,10 @@ pr: none trigger: - try -variables: -- group: dummy-credentials - jobs: -- job: Linux +- job: Dummy timeoutInMinutes: 600 pool: vmImage: ubuntu-16.04 steps: - - template: steps/run.yml - strategy: - matrix: - dist-x86_64-linux: {} - -# The macOS and Windows builds here are currently disabled due to them not being -# overly necessary on `try` builds. We also don't actually have anything that -# consumes the artifacts currently. Perhaps one day we can re-enable, but for now -# it helps free up capacity on Azure. -# - job: macOS -# timeoutInMinutes: 600 -# pool: -# vmImage: macos-10.15 -# steps: -# - template: steps/run.yml -# strategy: -# matrix: -# dist-x86_64-apple: -# SCRIPT: ./x.py dist -# INITIAL_RUST_CONFIGURE_ARGS: --target=aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios --enable-full-tools --enable-sanitizers --enable-profiler --set rust.jemalloc -# DEPLOY: 1 -# RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 -# MACOSX_DEPLOYMENT_TARGET: 10.7 -# NO_LLVM_ASSERTIONS: 1 -# NO_DEBUG_ASSERTIONS: 1 -# DIST_REQUIRE_ALL_TOOLS: 1 -# -# dist-x86_64-apple-alt: -# SCRIPT: ./x.py dist -# INITIAL_RUST_CONFIGURE_ARGS: --enable-extended --enable-profiler --set rust.jemalloc -# DEPLOY_ALT: 1 -# RUSTC_RETRY_LINKER_ON_SEGFAULT: 1 -# MACOSX_DEPLOYMENT_TARGET: 10.7 -# NO_LLVM_ASSERTIONS: 1 -# NO_DEBUG_ASSERTIONS: 1 -# -# - job: Windows -# timeoutInMinutes: 600 -# pool: -# vmImage: 'vs2017-win2016' -# steps: -# - template: steps/run.yml -# strategy: -# matrix: -# dist-x86_64-msvc: -# INITIAL_RUST_CONFIGURE_ARGS: > -# --build=x86_64-pc-windows-msvc -# --target=x86_64-pc-windows-msvc,aarch64-pc-windows-msvc -# --enable-full-tools -# --enable-profiler -# SCRIPT: python x.py dist -# DIST_REQUIRE_ALL_TOOLS: 1 -# DEPLOY: 1 -# -# dist-x86_64-msvc-alt: -# INITIAL_RUST_CONFIGURE_ARGS: --build=x86_64-pc-windows-msvc --enable-extended --enable-profiler -# SCRIPT: python x.py dist -# DEPLOY_ALT: 1 + - bash: echo "We're running this job since bors is still gating on Azure" From 9452bd72051eda1d723afc7104de6b3b4762bd4b Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Sat, 11 Jul 2020 14:50:03 -0400 Subject: [PATCH 09/15] Add the aarch64-apple-darwin target This is a basic copy-paste-modify from the existing x86_64-apple-darwin target. --- .../spec/aarch64_apple_darwin.rs | 30 +++++++++++++++++++ src/librustc_target/spec/mod.rs | 1 + .../spec/x86_64_apple_darwin.rs | 5 +++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/librustc_target/spec/aarch64_apple_darwin.rs diff --git a/src/librustc_target/spec/aarch64_apple_darwin.rs b/src/librustc_target/spec/aarch64_apple_darwin.rs new file mode 100644 index 0000000000000..60daf10b36afe --- /dev/null +++ b/src/librustc_target/spec/aarch64_apple_darwin.rs @@ -0,0 +1,30 @@ +use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::apple_base::opts(); + base.cpu = "apple-a12".to_string(); + base.max_atomic_width = Some(128); + base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-arch".to_string(), "arm64".to_string()]); + + base.link_env_remove.extend(super::apple_base::macos_link_env_remove()); + + // Clang automatically chooses a more specific target based on + // MACOSX_DEPLOYMENT_TARGET. To enable cross-language LTO to work + // correctly, we do too. + let arch = "aarch64"; + let llvm_target = super::apple_base::macos_llvm_target(&arch); + + Ok(Target { + llvm_target, + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), + arch: arch.to_string(), + target_os: "macos".to_string(), + target_env: String::new(), + target_vendor: "apple".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: TargetOptions { target_mcount: "\u{1}mcount".to_string(), ..base }, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 712dc51a83af1..4fc53b5989e53 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -574,6 +574,7 @@ supported_targets! { ("i686-unknown-haiku", i686_unknown_haiku), ("x86_64-unknown-haiku", x86_64_unknown_haiku), + ("aarch64-apple-darwin", aarch64_apple_darwin), ("x86_64-apple-darwin", x86_64_apple_darwin), ("i686-apple-darwin", i686_apple_darwin), diff --git a/src/librustc_target/spec/x86_64_apple_darwin.rs b/src/librustc_target/spec/x86_64_apple_darwin.rs index 31011e8474958..909aebec70b58 100644 --- a/src/librustc_target/spec/x86_64_apple_darwin.rs +++ b/src/librustc_target/spec/x86_64_apple_darwin.rs @@ -5,7 +5,10 @@ pub fn target() -> TargetResult { base.cpu = "core2".to_string(); base.max_atomic_width = Some(128); // core2 support cmpxchg16b base.eliminate_frame_pointer = false; - base.pre_link_args.insert(LinkerFlavor::Gcc, vec!["-m64".to_string()]); + base.pre_link_args.insert( + LinkerFlavor::Gcc, + vec!["-m64".to_string(), "-arch".to_string(), "x86_64".to_string()], + ); base.link_env_remove.extend(super::apple_base::macos_link_env_remove()); base.stack_probes = true; From ca9eb24ee9df646a9567d23f93761f5a0956b5e8 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sun, 19 Jul 2020 12:31:42 +0100 Subject: [PATCH 10/15] Use `ReEmpty(U0)` as the implicit region bound in typeck --- src/librustc_typeck/check/mod.rs | 9 --- src/librustc_typeck/check/regionck.rs | 2 +- ...pe-param-outlives-reempty-issue-74429-2.rs | 66 +++++++++++++++++++ ...type-param-outlives-reempty-issue-74429.rs | 35 ++++++++++ 4 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 src/test/ui/regions/type-param-outlives-reempty-issue-74429-2.rs create mode 100644 src/test/ui/regions/type-param-outlives-reempty-issue-74429.rs diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index fa7360ce90051..e00c9b324ddac 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -252,14 +252,6 @@ pub struct Inherited<'a, 'tcx> { /// opaque type. opaque_types_vars: RefCell, Ty<'tcx>>>, - /// Each type parameter has an implicit region bound that - /// indicates it must outlive at least the function body (the user - /// may specify stronger requirements). This field indicates the - /// region of the callee. If it is `None`, then the parameter - /// environment is for an item or something where the "callee" is - /// not clear. - implicit_region_bound: Option>, - body_id: Option, } @@ -678,7 +670,6 @@ impl Inherited<'a, 'tcx> { deferred_generator_interiors: RefCell::new(Vec::new()), opaque_types: RefCell::new(Default::default()), opaque_types_vars: RefCell::new(Default::default()), - implicit_region_bound: None, body_id, } } diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 199f49ca323e0..803589247c2ca 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -308,7 +308,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { fn resolve_regions_and_report_errors(&self, mode: RegionckMode) { self.infcx.process_registered_region_obligations( self.outlives_environment.region_bound_pairs_map(), - self.implicit_region_bound, + Some(self.tcx.lifetimes.re_root_empty), self.param_env, ); diff --git a/src/test/ui/regions/type-param-outlives-reempty-issue-74429-2.rs b/src/test/ui/regions/type-param-outlives-reempty-issue-74429-2.rs new file mode 100644 index 0000000000000..a65c17e0efc3c --- /dev/null +++ b/src/test/ui/regions/type-param-outlives-reempty-issue-74429-2.rs @@ -0,0 +1,66 @@ +// Regression test for #74429, where we didn't think that a type parameter +// outlived `ReEmpty`. + +// check-pass + +use std::marker::PhantomData; +use std::ptr::NonNull; + +pub unsafe trait RawData { + type Elem; +} + +unsafe impl RawData for OwnedRepr { + type Elem = A; +} + +unsafe impl<'a, A> RawData for ViewRepr<&'a A> { + type Elem = A; +} + +pub struct OwnedRepr { + ptr: PhantomData, +} + +// these Copy impls are not necessary for the repro, but allow the code to compile without error +// on 1.44.1 +#[derive(Copy, Clone)] +pub struct ViewRepr { + life: PhantomData, +} + +#[derive(Copy, Clone)] +pub struct ArrayBase +where + S: RawData, +{ + ptr: NonNull, +} + +pub type Array = ArrayBase>; + +pub type ArrayView<'a, A> = ArrayBase>; + +impl ArrayBase +where + S: RawData, +{ + pub fn index_axis(&self) -> ArrayView<'_, A> { + unimplemented!() + } + + pub fn axis_iter<'a>(&'a self) -> std::iter::Empty<&'a A> { + unimplemented!() + } +} + +pub fn x(a: Array) { + // drop just avoids a must_use warning + drop((0..1).filter(|_| true)); + let y = a.index_axis(); + a.axis_iter().for_each(|_| { + drop(y); + }); +} + +fn main() {} diff --git a/src/test/ui/regions/type-param-outlives-reempty-issue-74429.rs b/src/test/ui/regions/type-param-outlives-reempty-issue-74429.rs new file mode 100644 index 0000000000000..d463f311c34e9 --- /dev/null +++ b/src/test/ui/regions/type-param-outlives-reempty-issue-74429.rs @@ -0,0 +1,35 @@ +// Regression test for #74429, where we didn't think that a type parameter +// outlived `ReEmpty`. + +// check-pass + +use std::marker::PhantomData; + +fn apply(_: T, _: F) {} + +#[derive(Clone, Copy)] +struct Invariant { + t: T, + p: PhantomData T>, +} + +fn verify_reempty(x: T) { + // r is inferred to have type `Invariant<&ReEmpty(U0) T>` + let r = Invariant { t: &x, p: PhantomData }; + // Creates a new universe, all variables from now on are in `U1`, say. + let _: fn(&()) = |_| {}; + // Closure parameter is of type `&ReEmpty(U1) T`, so the closure has an implied + // bound of `T: ReEmpty(U1)` + apply(&x, |_| { + // Requires `typeof(r)` is well-formed, i.e. `T: ReEmpty(U0)`. If we + // only have the implied bound from the closure parameter to use this + // requires `ReEmpty(U1): ReEmpty(U0)`, which isn't true so we reported + // an error. + // + // This doesn't happen any more because we ensure that `T: ReEmpty(U0)` + // is an implicit bound for all type parameters. + drop(r); + }); +} + +fn main() {} From 1a2f6d5d6fd46054f59852c052d12f2f3711e5b8 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Fri, 17 Jul 2020 22:10:37 +0200 Subject: [PATCH 11/15] rustbuild: drop tool::should_install Always install when the build succeeds Fixes #74431 Signed-off-by: Marc-Antoine Perennou --- src/bootstrap/install.rs | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 7026b25d1b984..b4a817738ff3f 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -159,11 +159,6 @@ macro_rules! install { config.extended && config.tools.as_ref() .map_or(true, |t| t.contains($path)) } - - #[allow(dead_code)] - fn should_install(builder: &Builder<'_>) -> bool { - builder.config.tools.as_ref().map_or(false, |t| t.contains($path)) - } } impl Step for $name { @@ -210,8 +205,7 @@ install!((self, builder, _config), install_cargo(builder, self.compiler.stage, self.target); }; Rls, "rls", Self::should_build(_config), only_hosts: true, { - if builder.ensure(dist::Rls { compiler: self.compiler, target: self.target }).is_some() || - Self::should_install(builder) { + if builder.ensure(dist::Rls { compiler: self.compiler, target: self.target }).is_some() { install_rls(builder, self.compiler.stage, self.target); } else { builder.info( @@ -221,27 +215,14 @@ install!((self, builder, _config), }; RustAnalyzer, "rust-analyzer", Self::should_build(_config), only_hosts: true, { builder.ensure(dist::RustAnalyzer { compiler: self.compiler, target: self.target }); - if Self::should_install(builder) { - install_rust_analyzer(builder, self.compiler.stage, self.target); - } else { - builder.info( - &format!("skipping Install rust-analyzer stage{} ({})", self.compiler.stage, self.target), - ); - } + install_rust_analyzer(builder, self.compiler.stage, self.target); }; Clippy, "clippy", Self::should_build(_config), only_hosts: true, { builder.ensure(dist::Clippy { compiler: self.compiler, target: self.target }); - if Self::should_install(builder) { - install_clippy(builder, self.compiler.stage, self.target); - } else { - builder.info( - &format!("skipping Install clippy stage{} ({})", self.compiler.stage, self.target), - ); - } + install_clippy(builder, self.compiler.stage, self.target); }; Miri, "miri", Self::should_build(_config), only_hosts: true, { - if builder.ensure(dist::Miri { compiler: self.compiler, target: self.target }).is_some() || - Self::should_install(builder) { + if builder.ensure(dist::Miri { compiler: self.compiler, target: self.target }).is_some() { install_miri(builder, self.compiler.stage, self.target); } else { builder.info( @@ -253,7 +234,7 @@ install!((self, builder, _config), if builder.ensure(dist::Rustfmt { compiler: self.compiler, target: self.target - }).is_some() || Self::should_install(builder) { + }).is_some() { install_rustfmt(builder, self.compiler.stage, self.target); } else { builder.info( From 34c9ac319282f93e148df27db030a99f5a9402f0 Mon Sep 17 00:00:00 2001 From: David Wood Date: Tue, 14 Jul 2020 19:26:34 +0100 Subject: [PATCH 12/15] lint: use `transparent_newtype_field` to avoid ICE This commit re-uses the `transparent_newtype_field` function instead of manually calling `is_zst` on normalized fields to determine which field in a transparent type is the non-zero-sized field, thus avoiding an ICE. Signed-off-by: David Wood --- src/librustc_lint/types.rs | 32 +++++++++++++-------------- src/test/ui/lint/lint-ctypes-73747.rs | 14 ++++++++++++ 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 src/test/ui/lint/lint-ctypes-73747.rs diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index b3015dcc2aee8..46741fcf2ba0c 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -531,23 +531,23 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { match ty.kind { ty::FnPtr(_) => true, ty::Ref(..) => true, - ty::Adt(field_def, substs) if field_def.repr.transparent() && !field_def.is_union() => { - for field in field_def.all_fields() { - let field_ty = self.cx.tcx.normalize_erasing_regions( - self.cx.param_env, - field.ty(self.cx.tcx, substs), - ); - if field_ty.is_zst(self.cx.tcx, field.did) { - continue; - } + ty::Adt(def, substs) if def.repr.transparent() && !def.is_union() => { + let guaranteed_nonnull_optimization = self + .cx + .tcx + .get_attrs(def.did) + .iter() + .any(|a| a.check_name(sym::rustc_nonnull_optimization_guaranteed)); + + if guaranteed_nonnull_optimization { + return true; + } - let attrs = self.cx.tcx.get_attrs(field_def.did); - if attrs - .iter() - .any(|a| a.check_name(sym::rustc_nonnull_optimization_guaranteed)) - || self.ty_is_known_nonnull(field_ty) - { - return true; + for variant in &def.variants { + if let Some(field) = variant.transparent_newtype_field(self.cx.tcx) { + if self.ty_is_known_nonnull(field.ty(self.cx.tcx, substs)) { + return true; + } } } diff --git a/src/test/ui/lint/lint-ctypes-73747.rs b/src/test/ui/lint/lint-ctypes-73747.rs new file mode 100644 index 0000000000000..293ffd5c28e10 --- /dev/null +++ b/src/test/ui/lint/lint-ctypes-73747.rs @@ -0,0 +1,14 @@ +// check-pass + +#[repr(transparent)] +struct NonNullRawComPtr { + inner: std::ptr::NonNull<::VTable>, +} + +trait ComInterface { + type VTable; +} + +extern "C" fn invoke(_: Option>) {} + +fn main() {} From 83f16cb66a40f0a009fedb1017863f6cebb2d992 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 10 Jul 2020 19:00:38 +0200 Subject: [PATCH 13/15] Don't panic if the lhs of a div by zero is not statically known --- src/librustc_mir/transform/const_prop.rs | 26 +++++++++++++++---- .../const_prop/ice-assert-fail-div-by-zero.rs | 11 +++++--- .../ice-assert-fail-div-by-zero.stderr | 14 ++++++++++ 3 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index fbe3377d87500..237a5a64f8bf8 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -484,7 +484,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { lint: &'static lint::Lint, source_info: SourceInfo, message: &'static str, - panic: AssertKind, + panic: AssertKind, ) -> Option<()> { let lint_root = self.lint_root(source_info)?; self.tcx.struct_span_lint_hir(lint, lint_root, source_info.span, |lint| { @@ -1004,11 +1004,27 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { let expected = ScalarMaybeUninit::from(Scalar::from_bool(*expected)); let value_const = self.ecx.read_scalar(value).unwrap(); if expected != value_const { + enum DbgVal { + Val(T), + Underscore, + } + impl std::fmt::Debug for DbgVal { + fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Val(val) => val.fmt(fmt), + Self::Underscore => fmt.write_str("_"), + } + } + } let mut eval_to_int = |op| { - let op = self - .eval_operand(op, source_info) - .expect("if we got here, it must be const"); - self.ecx.read_immediate(op).unwrap().to_const_int() + // This can be `None` if the lhs wasn't const propagated and we just + // triggered the assert on the value of the rhs. + match self.eval_operand(op, source_info) { + Some(op) => { + DbgVal::Val(self.ecx.read_immediate(op).unwrap().to_const_int()) + } + None => DbgVal::Underscore, + } }; let msg = match msg { AssertKind::DivisionByZero(op) => { diff --git a/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs index 5f2d5e80243fe..d19cf00eb9ce4 100644 --- a/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs +++ b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs @@ -1,9 +1,12 @@ // check-pass +// compile-flags: --crate-type lib + +#![warn(unconditional_panic)] + pub struct Fixed64(i64); -pub fn div(f: Fixed64) { - f.0 / 0; +// HACK: this test passes only because this is a const fn that is written to metadata +pub const fn div(f: Fixed64) { + f.0 / 0; //~ WARN will panic at runtime } - -fn main() {} diff --git a/src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr new file mode 100644 index 0000000000000..e2a3e4db8abd1 --- /dev/null +++ b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr @@ -0,0 +1,14 @@ +warning: this operation will panic at runtime + --> $DIR/ice-assert-fail-div-by-zero.rs:11:5 + | +LL | f.0 / 0; + | ^^^^^^^ attempt to divide _ by zero + | +note: the lint level is defined here + --> $DIR/ice-assert-fail-div-by-zero.rs:5:9 + | +LL | #![warn(unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + From 887c4c92ee2d57d1828c84db51a6be9f4490ca38 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 17 Jul 2020 17:23:18 +0100 Subject: [PATCH 14/15] improper_ctypes_definitions: allow `Box` This commit stops linting against `Box` in `extern "C" fn`s for the `improper_ctypes_definitions` lint - boxes are documented to be FFI-safe. Signed-off-by: David Wood --- src/librustc_lint/types.rs | 13 +++++- src/test/ui/lint/lint-ctypes-fn.rs | 5 +-- src/test/ui/lint/lint-ctypes-fn.stderr | 55 +++++++------------------- src/test/ui/lint/lint-ctypes.rs | 2 + src/test/ui/lint/lint-ctypes.stderr | 47 +++++++++++++--------- 5 files changed, 58 insertions(+), 64 deletions(-) diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 46741fcf2ba0c..7014722bab824 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -531,6 +531,11 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { match ty.kind { ty::FnPtr(_) => true, ty::Ref(..) => true, + ty::Adt(def, _) + if def.is_box() && matches!(self.mode, ImproperCTypesMode::Definitions) => + { + true + } ty::Adt(def, substs) if def.repr.transparent() && !def.is_union() => { let guaranteed_nonnull_optimization = self .cx @@ -558,7 +563,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } /// Check if this enum can be safely exported based on the "nullable pointer optimization". - /// Currently restricted to function pointers, references, `core::num::NonZero*`, + /// Currently restricted to function pointers, boxes, references, `core::num::NonZero*`, /// `core::ptr::NonNull`, and `#[repr(transparent)]` newtypes. fn is_repr_nullable_ptr( &self, @@ -692,6 +697,12 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } match ty.kind { + ty::Adt(def, _) + if def.is_box() && matches!(self.mode, ImproperCTypesMode::Definitions) => + { + FfiSafe + } + ty::Adt(def, substs) => { if def.is_phantom_data() { return FfiPhantom(ty); diff --git a/src/test/ui/lint/lint-ctypes-fn.rs b/src/test/ui/lint/lint-ctypes-fn.rs index 67dd7abcf79ef..aa02e57866328 100644 --- a/src/test/ui/lint/lint-ctypes-fn.rs +++ b/src/test/ui/lint/lint-ctypes-fn.rs @@ -71,7 +71,8 @@ pub extern "C" fn str_type(p: &str) { } //~^ ERROR: uses type `str` pub extern "C" fn box_type(p: Box) { } -//~^ ERROR uses type `std::boxed::Box` + +pub extern "C" fn opt_box_type(p: Option>) { } pub extern "C" fn char_type(p: char) { } //~^ ERROR uses type `char` @@ -106,7 +107,6 @@ pub extern "C" fn fn_type2(p: fn()) { } //~^ ERROR uses type `fn()` pub extern "C" fn fn_contained(p: RustBadRet) { } -//~^ ERROR: uses type `std::boxed::Box` pub extern "C" fn transparent_i128(p: TransparentI128) { } //~^ ERROR: uses type `i128` @@ -115,7 +115,6 @@ pub extern "C" fn transparent_str(p: TransparentStr) { } //~^ ERROR: uses type `str` pub extern "C" fn transparent_fn(p: TransparentBadFn) { } -//~^ ERROR: uses type `std::boxed::Box` pub extern "C" fn good3(fptr: Option) { } diff --git a/src/test/ui/lint/lint-ctypes-fn.stderr b/src/test/ui/lint/lint-ctypes-fn.stderr index 66cf195327890..d0a449514e50e 100644 --- a/src/test/ui/lint/lint-ctypes-fn.stderr +++ b/src/test/ui/lint/lint-ctypes-fn.stderr @@ -21,17 +21,8 @@ LL | pub extern "C" fn str_type(p: &str) { } = help: consider using `*const u8` and a length instead = note: string slices have no C equivalent -error: `extern` fn uses type `std::boxed::Box`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:73:31 - | -LL | pub extern "C" fn box_type(p: Box) { } - | ^^^^^^^^ not FFI-safe - | - = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct - = note: this struct has unspecified layout - error: `extern` fn uses type `char`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:76:32 + --> $DIR/lint-ctypes-fn.rs:77:32 | LL | pub extern "C" fn char_type(p: char) { } | ^^^^ not FFI-safe @@ -40,7 +31,7 @@ LL | pub extern "C" fn char_type(p: char) { } = note: the `char` type has no C equivalent error: `extern` fn uses type `i128`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:79:32 + --> $DIR/lint-ctypes-fn.rs:80:32 | LL | pub extern "C" fn i128_type(p: i128) { } | ^^^^ not FFI-safe @@ -48,7 +39,7 @@ LL | pub extern "C" fn i128_type(p: i128) { } = note: 128-bit integers don't currently have a known stable ABI error: `extern` fn uses type `u128`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:82:32 + --> $DIR/lint-ctypes-fn.rs:83:32 | LL | pub extern "C" fn u128_type(p: u128) { } | ^^^^ not FFI-safe @@ -56,7 +47,7 @@ LL | pub extern "C" fn u128_type(p: u128) { } = note: 128-bit integers don't currently have a known stable ABI error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:85:33 + --> $DIR/lint-ctypes-fn.rs:86:33 | LL | pub extern "C" fn tuple_type(p: (i32, i32)) { } | ^^^^^^^^^^ not FFI-safe @@ -65,7 +56,7 @@ LL | pub extern "C" fn tuple_type(p: (i32, i32)) { } = note: tuples have unspecified layout error: `extern` fn uses type `(i32, i32)`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:88:34 + --> $DIR/lint-ctypes-fn.rs:89:34 | LL | pub extern "C" fn tuple_type2(p: I32Pair) { } | ^^^^^^^ not FFI-safe @@ -74,7 +65,7 @@ LL | pub extern "C" fn tuple_type2(p: I32Pair) { } = note: tuples have unspecified layout error: `extern` fn uses type `ZeroSize`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:91:32 + --> $DIR/lint-ctypes-fn.rs:92:32 | LL | pub extern "C" fn zero_size(p: ZeroSize) { } | ^^^^^^^^ not FFI-safe @@ -88,7 +79,7 @@ LL | pub struct ZeroSize; | ^^^^^^^^^^^^^^^^^^^^ error: `extern` fn uses type `ZeroSizeWithPhantomData`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:94:40 + --> $DIR/lint-ctypes-fn.rs:95:40 | LL | pub extern "C" fn zero_size_phantom(p: ZeroSizeWithPhantomData) { } | ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -101,7 +92,7 @@ LL | pub struct ZeroSizeWithPhantomData(PhantomData); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `extern` fn uses type `std::marker::PhantomData`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:97:51 + --> $DIR/lint-ctypes-fn.rs:98:51 | LL | pub extern "C" fn zero_size_phantom_toplevel() -> PhantomData { | ^^^^^^^^^^^^^^^^^ not FFI-safe @@ -109,7 +100,7 @@ LL | pub extern "C" fn zero_size_phantom_toplevel() -> PhantomData { = note: composed only of `PhantomData` error: `extern` fn uses type `fn()`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:102:30 + --> $DIR/lint-ctypes-fn.rs:103:30 | LL | pub extern "C" fn fn_type(p: RustFn) { } | ^^^^^^ not FFI-safe @@ -118,7 +109,7 @@ LL | pub extern "C" fn fn_type(p: RustFn) { } = note: this function pointer has Rust-specific calling convention error: `extern` fn uses type `fn()`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:105:31 + --> $DIR/lint-ctypes-fn.rs:106:31 | LL | pub extern "C" fn fn_type2(p: fn()) { } | ^^^^ not FFI-safe @@ -126,15 +117,6 @@ LL | pub extern "C" fn fn_type2(p: fn()) { } = help: consider using an `extern fn(...) -> ...` function pointer instead = note: this function pointer has Rust-specific calling convention -error: `extern` fn uses type `std::boxed::Box`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:108:35 - | -LL | pub extern "C" fn fn_contained(p: RustBadRet) { } - | ^^^^^^^^^^ not FFI-safe - | - = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct - = note: this struct has unspecified layout - error: `extern` fn uses type `i128`, which is not FFI-safe --> $DIR/lint-ctypes-fn.rs:111:39 | @@ -152,17 +134,8 @@ LL | pub extern "C" fn transparent_str(p: TransparentStr) { } = help: consider using `*const u8` and a length instead = note: string slices have no C equivalent -error: `extern` fn uses type `std::boxed::Box`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:117:37 - | -LL | pub extern "C" fn transparent_fn(p: TransparentBadFn) { } - | ^^^^^^^^^^^^^^^^ not FFI-safe - | - = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct - = note: this struct has unspecified layout - error: `extern` fn uses type `std::marker::PhantomData`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:161:43 + --> $DIR/lint-ctypes-fn.rs:160:43 | LL | pub extern "C" fn unused_generic2() -> PhantomData { | ^^^^^^^^^^^^^^^^^ not FFI-safe @@ -170,7 +143,7 @@ LL | pub extern "C" fn unused_generic2() -> PhantomData { = note: composed only of `PhantomData` error: `extern` fn uses type `std::vec::Vec`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:174:39 + --> $DIR/lint-ctypes-fn.rs:173:39 | LL | pub extern "C" fn used_generic4(x: Vec) { } | ^^^^^^ not FFI-safe @@ -179,7 +152,7 @@ LL | pub extern "C" fn used_generic4(x: Vec) { } = note: this struct has unspecified layout error: `extern` fn uses type `std::vec::Vec`, which is not FFI-safe - --> $DIR/lint-ctypes-fn.rs:177:41 + --> $DIR/lint-ctypes-fn.rs:176:41 | LL | pub extern "C" fn used_generic5() -> Vec { | ^^^^^^ not FFI-safe @@ -187,5 +160,5 @@ LL | pub extern "C" fn used_generic5() -> Vec { = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout -error: aborting due to 20 previous errors +error: aborting due to 17 previous errors diff --git a/src/test/ui/lint/lint-ctypes.rs b/src/test/ui/lint/lint-ctypes.rs index a439a1f339aea..bdf95350c7045 100644 --- a/src/test/ui/lint/lint-ctypes.rs +++ b/src/test/ui/lint/lint-ctypes.rs @@ -48,6 +48,8 @@ extern { pub fn slice_type(p: &[u32]); //~ ERROR: uses type `[u32]` pub fn str_type(p: &str); //~ ERROR: uses type `str` pub fn box_type(p: Box); //~ ERROR uses type `std::boxed::Box` + pub fn opt_box_type(p: Option>); + //~^ ERROR uses type `std::option::Option>` pub fn char_type(p: char); //~ ERROR uses type `char` pub fn i128_type(p: i128); //~ ERROR uses type `i128` pub fn u128_type(p: u128); //~ ERROR uses type `u128` diff --git a/src/test/ui/lint/lint-ctypes.stderr b/src/test/ui/lint/lint-ctypes.stderr index 9821f858d9caf..13b9adca3f9f5 100644 --- a/src/test/ui/lint/lint-ctypes.stderr +++ b/src/test/ui/lint/lint-ctypes.stderr @@ -58,8 +58,17 @@ LL | pub fn box_type(p: Box); = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct = note: this struct has unspecified layout +error: `extern` block uses type `std::option::Option>`, which is not FFI-safe + --> $DIR/lint-ctypes.rs:51:28 + | +LL | pub fn opt_box_type(p: Option>); + | ^^^^^^^^^^^^^^^^ not FFI-safe + | + = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum + = note: enum has no representation hint + error: `extern` block uses type `char`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:51:25 + --> $DIR/lint-ctypes.rs:53:25 | LL | pub fn char_type(p: char); | ^^^^ not FFI-safe @@ -68,7 +77,7 @@ LL | pub fn char_type(p: char); = note: the `char` type has no C equivalent error: `extern` block uses type `i128`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:52:25 + --> $DIR/lint-ctypes.rs:54:25 | LL | pub fn i128_type(p: i128); | ^^^^ not FFI-safe @@ -76,7 +85,7 @@ LL | pub fn i128_type(p: i128); = note: 128-bit integers don't currently have a known stable ABI error: `extern` block uses type `u128`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:53:25 + --> $DIR/lint-ctypes.rs:55:25 | LL | pub fn u128_type(p: u128); | ^^^^ not FFI-safe @@ -84,7 +93,7 @@ LL | pub fn u128_type(p: u128); = note: 128-bit integers don't currently have a known stable ABI error: `extern` block uses type `dyn std::clone::Clone`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:54:26 + --> $DIR/lint-ctypes.rs:56:26 | LL | pub fn trait_type(p: &dyn Clone); | ^^^^^^^^^^ not FFI-safe @@ -92,7 +101,7 @@ LL | pub fn trait_type(p: &dyn Clone); = note: trait objects have no C equivalent error: `extern` block uses type `(i32, i32)`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:55:26 + --> $DIR/lint-ctypes.rs:57:26 | LL | pub fn tuple_type(p: (i32, i32)); | ^^^^^^^^^^ not FFI-safe @@ -101,7 +110,7 @@ LL | pub fn tuple_type(p: (i32, i32)); = note: tuples have unspecified layout error: `extern` block uses type `(i32, i32)`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:56:27 + --> $DIR/lint-ctypes.rs:58:27 | LL | pub fn tuple_type2(p: I32Pair); | ^^^^^^^ not FFI-safe @@ -110,7 +119,7 @@ LL | pub fn tuple_type2(p: I32Pair); = note: tuples have unspecified layout error: `extern` block uses type `ZeroSize`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:57:25 + --> $DIR/lint-ctypes.rs:59:25 | LL | pub fn zero_size(p: ZeroSize); | ^^^^^^^^ not FFI-safe @@ -124,7 +133,7 @@ LL | pub struct ZeroSize; | ^^^^^^^^^^^^^^^^^^^^ error: `extern` block uses type `ZeroSizeWithPhantomData`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:58:33 + --> $DIR/lint-ctypes.rs:60:33 | LL | pub fn zero_size_phantom(p: ZeroSizeWithPhantomData); | ^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -137,7 +146,7 @@ LL | pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `extern` block uses type `std::marker::PhantomData`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:61:12 + --> $DIR/lint-ctypes.rs:63:12 | LL | -> ::std::marker::PhantomData; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe @@ -145,7 +154,7 @@ LL | -> ::std::marker::PhantomData; = note: composed only of `PhantomData` error: `extern` block uses type `fn()`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:62:23 + --> $DIR/lint-ctypes.rs:64:23 | LL | pub fn fn_type(p: RustFn); | ^^^^^^ not FFI-safe @@ -154,7 +163,7 @@ LL | pub fn fn_type(p: RustFn); = note: this function pointer has Rust-specific calling convention error: `extern` block uses type `fn()`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:63:24 + --> $DIR/lint-ctypes.rs:65:24 | LL | pub fn fn_type2(p: fn()); | ^^^^ not FFI-safe @@ -163,7 +172,7 @@ LL | pub fn fn_type2(p: fn()); = note: this function pointer has Rust-specific calling convention error: `extern` block uses type `std::boxed::Box`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:64:28 + --> $DIR/lint-ctypes.rs:66:28 | LL | pub fn fn_contained(p: RustBadRet); | ^^^^^^^^^^ not FFI-safe @@ -172,7 +181,7 @@ LL | pub fn fn_contained(p: RustBadRet); = note: this struct has unspecified layout error: `extern` block uses type `i128`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:65:32 + --> $DIR/lint-ctypes.rs:67:32 | LL | pub fn transparent_i128(p: TransparentI128); | ^^^^^^^^^^^^^^^ not FFI-safe @@ -180,7 +189,7 @@ LL | pub fn transparent_i128(p: TransparentI128); = note: 128-bit integers don't currently have a known stable ABI error: `extern` block uses type `str`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:66:31 + --> $DIR/lint-ctypes.rs:68:31 | LL | pub fn transparent_str(p: TransparentStr); | ^^^^^^^^^^^^^^ not FFI-safe @@ -189,7 +198,7 @@ LL | pub fn transparent_str(p: TransparentStr); = note: string slices have no C equivalent error: `extern` block uses type `std::boxed::Box`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:67:30 + --> $DIR/lint-ctypes.rs:69:30 | LL | pub fn transparent_fn(p: TransparentBadFn); | ^^^^^^^^^^^^^^^^ not FFI-safe @@ -198,7 +207,7 @@ LL | pub fn transparent_fn(p: TransparentBadFn); = note: this struct has unspecified layout error: `extern` block uses type `[u8; 8]`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:68:27 + --> $DIR/lint-ctypes.rs:70:27 | LL | pub fn raw_array(arr: [u8; 8]); | ^^^^^^^ not FFI-safe @@ -207,7 +216,7 @@ LL | pub fn raw_array(arr: [u8; 8]); = note: passing raw arrays by value is not FFI-safe error: `extern` block uses type `u128`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:70:34 + --> $DIR/lint-ctypes.rs:72:34 | LL | pub static static_u128_type: u128; | ^^^^ not FFI-safe @@ -215,12 +224,12 @@ LL | pub static static_u128_type: u128; = note: 128-bit integers don't currently have a known stable ABI error: `extern` block uses type `u128`, which is not FFI-safe - --> $DIR/lint-ctypes.rs:71:40 + --> $DIR/lint-ctypes.rs:73:40 | LL | pub static static_u128_array_type: [u128; 16]; | ^^^^^^^^^^ not FFI-safe | = note: 128-bit integers don't currently have a known stable ABI -error: aborting due to 23 previous errors +error: aborting due to 24 previous errors From ed591d00401f3b258f9939e8d3a668a9f11a1b24 Mon Sep 17 00:00:00 2001 From: David Wood Date: Thu, 2 Jul 2020 14:13:39 +0100 Subject: [PATCH 15/15] typeck: check for infer before type impls trait This commit checks that the target type of the cast (an error related to which is being reported) does not have types to be inferred before checking if it implements the `From` trait. Signed-off-by: David Wood --- src/librustc_typeck/check/cast.rs | 1 + src/test/ui/issues/issue-73886.rs | 6 ++++++ src/test/ui/issues/issue-73886.stderr | 15 +++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 src/test/ui/issues/issue-73886.rs create mode 100644 src/test/ui/issues/issue-73886.stderr diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 1ea7bf25ef2ed..8948e5a3e00db 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -387,6 +387,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // Check for infer types because cases like `Option<{integer}>` would // panic otherwise. if !expr_ty.has_infer_types() + && !ty.has_infer_types() && fcx.tcx.type_implements_trait(( from_trait, ty, diff --git a/src/test/ui/issues/issue-73886.rs b/src/test/ui/issues/issue-73886.rs new file mode 100644 index 0000000000000..2f1ec8c6d6227 --- /dev/null +++ b/src/test/ui/issues/issue-73886.rs @@ -0,0 +1,6 @@ +fn main() { + let _ = &&[0] as &[_]; + //~^ ERROR non-primitive cast: `&&[i32; 1]` as `&[_]` + let _ = 7u32 as Option<_>; + //~^ ERROR non-primitive cast: `u32` as `std::option::Option<_>` +} diff --git a/src/test/ui/issues/issue-73886.stderr b/src/test/ui/issues/issue-73886.stderr new file mode 100644 index 0000000000000..e8ab7db6b82c2 --- /dev/null +++ b/src/test/ui/issues/issue-73886.stderr @@ -0,0 +1,15 @@ +error[E0605]: non-primitive cast: `&&[i32; 1]` as `&[_]` + --> $DIR/issue-73886.rs:2:13 + | +LL | let _ = &&[0] as &[_]; + | ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object + +error[E0605]: non-primitive cast: `u32` as `std::option::Option<_>` + --> $DIR/issue-73886.rs:4:13 + | +LL | let _ = 7u32 as Option<_>; + | ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0605`.