From 28e0c5aec8335d34cd84f3970d633860d6bd08a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Fri, 16 Sep 2022 00:06:25 +0200 Subject: [PATCH 1/6] Allow more !Copy impls --- .../rustc_typeck/src/coherence/builtin.rs | 18 ++++------ .../coherence-negative-impls-copy-bad.rs | 11 ++++++ .../coherence-negative-impls-copy-bad.stderr | 36 +++++++++++++++++++ .../coherence-negative-impls-copy.rs | 29 +++++++++++++++ .../ui/coherence/deep-bad-copy-reason.stderr | 4 +-- src/test/ui/opt-in-copy.stderr | 8 ++--- src/test/ui/span/E0204.stderr | 8 ++--- ...missing-bound-in-manual-copy-impl-2.stderr | 4 +-- .../missing-bound-in-manual-copy-impl.stderr | 4 +-- .../traits/copy-impl-cannot-normalize.stderr | 4 +-- src/test/ui/union/union-copy.stderr | 4 +-- 11 files changed, 100 insertions(+), 30 deletions(-) create mode 100644 src/test/ui/coherence/coherence-negative-impls-copy-bad.rs create mode 100644 src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr create mode 100644 src/test/ui/coherence/coherence-negative-impls-copy.rs diff --git a/compiler/rustc_typeck/src/coherence/builtin.rs b/compiler/rustc_typeck/src/coherence/builtin.rs index d08c0d4dbb72a..d4eb826f0b4d3 100644 --- a/compiler/rustc_typeck/src/coherence/builtin.rs +++ b/compiler/rustc_typeck/src/coherence/builtin.rs @@ -70,23 +70,21 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) { let self_type = tcx.type_of(impl_did); debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); - let span = tcx.hir().span(impl_hir_id); let param_env = tcx.param_env(impl_did); assert!(!self_type.has_escaping_bound_vars()); debug!("visit_implementation_of_copy: self_type={:?} (free)", self_type); + let span = match tcx.hir().expect_item(impl_did).kind { + ItemKind::Impl(hir::Impl { polarity: hir::ImplPolarity::Negative(_), .. }) => return, + ItemKind::Impl(impl_) => impl_.self_ty.span, + _ => bug!("expected Copy impl item"), + }; + let cause = traits::ObligationCause::misc(span, impl_hir_id); match can_type_implement_copy(tcx, param_env, self_type, cause) { Ok(()) => {} Err(CopyImplementationError::InfrigingFields(fields)) => { - let item = tcx.hir().expect_item(impl_did); - let span = if let ItemKind::Impl(hir::Impl { of_trait: Some(ref tr), .. }) = item.kind { - tr.path.span - } else { - span - }; - let mut err = struct_span_err!( tcx.sess, span, @@ -166,10 +164,6 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) { err.emit(); } Err(CopyImplementationError::NotAnAdt) => { - let item = tcx.hir().expect_item(impl_did); - let span = - if let ItemKind::Impl(ref impl_) = item.kind { impl_.self_ty.span } else { span }; - tcx.sess.emit_err(CopyImplOnNonAdt { span }); } Err(CopyImplementationError::HasDestructor) => { diff --git a/src/test/ui/coherence/coherence-negative-impls-copy-bad.rs b/src/test/ui/coherence/coherence-negative-impls-copy-bad.rs new file mode 100644 index 0000000000000..563f28e2291d4 --- /dev/null +++ b/src/test/ui/coherence/coherence-negative-impls-copy-bad.rs @@ -0,0 +1,11 @@ +#![feature(negative_impls)] +#![crate_type = "lib"] + +impl !Copy for str {} +//~^ ERROR only traits defined in the current crate can be implemented + +impl !Copy for fn() {} +//~^ ERROR only traits defined in the current crate can be implemented + +impl !Copy for () {} +//~^ ERROR only traits defined in the current crate can be implemented diff --git a/src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr b/src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr new file mode 100644 index 0000000000000..2295d6315d1c2 --- /dev/null +++ b/src/test/ui/coherence/coherence-negative-impls-copy-bad.stderr @@ -0,0 +1,36 @@ +error[E0117]: only traits defined in the current crate can be implemented for arbitrary types + --> $DIR/coherence-negative-impls-copy-bad.rs:4:1 + | +LL | impl !Copy for str {} + | ^^^^^^^^^^^^^^^--- + | | | + | | `str` is not defined in the current crate + | impl doesn't use only types from inside the current crate + | + = note: define and implement a trait or new type instead + +error[E0117]: only traits defined in the current crate can be implemented for arbitrary types + --> $DIR/coherence-negative-impls-copy-bad.rs:7:1 + | +LL | impl !Copy for fn() {} + | ^^^^^^^^^^^^^^^---- + | | | + | | `fn()` is not defined in the current crate + | impl doesn't use only types from inside the current crate + | + = note: define and implement a trait or new type instead + +error[E0117]: only traits defined in the current crate can be implemented for arbitrary types + --> $DIR/coherence-negative-impls-copy-bad.rs:10:1 + | +LL | impl !Copy for () {} + | ^^^^^^^^^^^^^^^-- + | | | + | | this is not defined in the current crate because tuples are always foreign + | impl doesn't use only types from inside the current crate + | + = note: define and implement a trait or new type instead + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0117`. diff --git a/src/test/ui/coherence/coherence-negative-impls-copy.rs b/src/test/ui/coherence/coherence-negative-impls-copy.rs new file mode 100644 index 0000000000000..7b29aade41335 --- /dev/null +++ b/src/test/ui/coherence/coherence-negative-impls-copy.rs @@ -0,0 +1,29 @@ +// check-pass +// regression test for issue #101836 + +#![feature(negative_impls, extern_types)] +#![crate_type = "lib"] + +struct NonCopy; +struct NeverCopy(NonCopy); + +impl !Copy for NeverCopy {} + + +struct WithDrop; +impl Drop for WithDrop { fn drop(&mut self) {} } + +impl !Copy for WithDrop {} + + +struct Type; +trait Trait {} +extern { + type ExternType; +} + +impl !Copy for &mut Type {} + +impl !Copy for dyn Trait {} + +impl !Copy for ExternType {} diff --git a/src/test/ui/coherence/deep-bad-copy-reason.stderr b/src/test/ui/coherence/deep-bad-copy-reason.stderr index 295538cee6096..168ee57263d2a 100644 --- a/src/test/ui/coherence/deep-bad-copy-reason.stderr +++ b/src/test/ui/coherence/deep-bad-copy-reason.stderr @@ -1,11 +1,11 @@ error[E0204]: the trait `Copy` may not be implemented for this type - --> $DIR/deep-bad-copy-reason.rs:33:15 + --> $DIR/deep-bad-copy-reason.rs:33:24 | LL | pub struct List<'tcx, T>(Interned<'tcx, ListS>); | ------------------------ this field does not implement `Copy` ... LL | impl<'tcx, T> Copy for List<'tcx, T> {} - | ^^^^ + | ^^^^^^^^^^^^^ | note: the `Copy` impl for `Interned<'tcx, ListS>` requires that `OpaqueListContents: Sized` --> $DIR/deep-bad-copy-reason.rs:23:26 diff --git a/src/test/ui/opt-in-copy.stderr b/src/test/ui/opt-in-copy.stderr index 0a275f1aa41d7..4461567df0a2a 100644 --- a/src/test/ui/opt-in-copy.stderr +++ b/src/test/ui/opt-in-copy.stderr @@ -1,20 +1,20 @@ error[E0204]: the trait `Copy` may not be implemented for this type - --> $DIR/opt-in-copy.rs:7:6 + --> $DIR/opt-in-copy.rs:7:15 | LL | but_i_cant: CantCopyThis, | ------------------------ this field does not implement `Copy` ... LL | impl Copy for IWantToCopyThis {} - | ^^^^ + | ^^^^^^^^^^^^^^^ error[E0204]: the trait `Copy` may not be implemented for this type - --> $DIR/opt-in-copy.rs:19:6 + --> $DIR/opt-in-copy.rs:19:15 | LL | ButICant(CantCopyThisEither), | ------------------ this field does not implement `Copy` ... LL | impl Copy for IWantToCopyThisToo {} - | ^^^^ + | ^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/span/E0204.stderr b/src/test/ui/span/E0204.stderr index 2575848435206..0b2166eed7ead 100644 --- a/src/test/ui/span/E0204.stderr +++ b/src/test/ui/span/E0204.stderr @@ -1,11 +1,11 @@ error[E0204]: the trait `Copy` may not be implemented for this type - --> $DIR/E0204.rs:5:6 + --> $DIR/E0204.rs:5:15 | LL | foo: Vec, | ------------- this field does not implement `Copy` ... LL | impl Copy for Foo { } - | ^^^^ + | ^^^ error[E0204]: the trait `Copy` may not be implemented for this type --> $DIR/E0204.rs:7:10 @@ -19,13 +19,13 @@ LL | ty: &'a mut bool, = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0204]: the trait `Copy` may not be implemented for this type - --> $DIR/E0204.rs:17:6 + --> $DIR/E0204.rs:17:15 | LL | Bar { x: Vec }, | ----------- this field does not implement `Copy` ... LL | impl Copy for EFoo { } - | ^^^^ + | ^^^^ error[E0204]: the trait `Copy` may not be implemented for this type --> $DIR/E0204.rs:19:10 diff --git a/src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr b/src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr index e0f405eedfa69..9e6f0d9ebbd27 100644 --- a/src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr +++ b/src/test/ui/suggestions/missing-bound-in-manual-copy-impl-2.stderr @@ -1,11 +1,11 @@ error[E0204]: the trait `Copy` may not be implemented for this type - --> $DIR/missing-bound-in-manual-copy-impl-2.rs:16:9 + --> $DIR/missing-bound-in-manual-copy-impl-2.rs:16:18 | LL | struct Wrapper(T); | - this field does not implement `Copy` ... LL | impl Copy for Wrapper> {} - | ^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the `Copy` impl for `OnlyCopyIfDisplay` requires that `S: std::fmt::Display` --> $DIR/missing-bound-in-manual-copy-impl-2.rs:4:19 diff --git a/src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr b/src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr index 218988511dbc3..fe2d133c8aa74 100644 --- a/src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr +++ b/src/test/ui/suggestions/missing-bound-in-manual-copy-impl.stderr @@ -1,11 +1,11 @@ error[E0204]: the trait `Copy` may not be implemented for this type - --> $DIR/missing-bound-in-manual-copy-impl.rs:6:9 + --> $DIR/missing-bound-in-manual-copy-impl.rs:6:18 | LL | struct Wrapper(T); | - this field does not implement `Copy` LL | LL | impl Copy for Wrapper {} - | ^^^^ + | ^^^^^^^^^^ | help: consider restricting type parameter `S` | diff --git a/src/test/ui/traits/copy-impl-cannot-normalize.stderr b/src/test/ui/traits/copy-impl-cannot-normalize.stderr index afdad160919f9..68b95b42b3463 100644 --- a/src/test/ui/traits/copy-impl-cannot-normalize.stderr +++ b/src/test/ui/traits/copy-impl-cannot-normalize.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: TraitFoo` is not satisfied - --> $DIR/copy-impl-cannot-normalize.rs:22:1 + --> $DIR/copy-impl-cannot-normalize.rs:22:18 | LL | impl Copy for Foo {} - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `TraitFoo` is not implemented for `T` + | ^^^^^^ the trait `TraitFoo` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/src/test/ui/union/union-copy.stderr b/src/test/ui/union/union-copy.stderr index 8ecdafdde2045..53ee4dd2e5bdb 100644 --- a/src/test/ui/union/union-copy.stderr +++ b/src/test/ui/union/union-copy.stderr @@ -1,11 +1,11 @@ error[E0204]: the trait `Copy` may not be implemented for this type - --> $DIR/union-copy.rs:12:6 + --> $DIR/union-copy.rs:12:15 | LL | a: std::mem::ManuallyDrop | --------------------------------- this field does not implement `Copy` ... LL | impl Copy for W {} - | ^^^^ + | ^ | note: the `Copy` impl for `ManuallyDrop` requires that `String: Copy` --> $DIR/union-copy.rs:8:8 From ad05b32fee4d9ed08581fabb5c4554f00819b917 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Fri, 23 Sep 2022 03:09:16 -0700 Subject: [PATCH 2/6] Add regression test for issue #100878 --- src/test/ui/consts/const-eval/issue-100878.rs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/test/ui/consts/const-eval/issue-100878.rs diff --git a/src/test/ui/consts/const-eval/issue-100878.rs b/src/test/ui/consts/const-eval/issue-100878.rs new file mode 100644 index 0000000000000..353ce5050359c --- /dev/null +++ b/src/test/ui/consts/const-eval/issue-100878.rs @@ -0,0 +1,8 @@ +// This checks that the const-eval ICE in issue #100878 does not recur. +// +// build-pass +pub fn bitshift_data(data: [u8; 1]) -> u8 { + data[0] << 8 +} + +fn main() {} From 73c52bc4dc8714a058854d113acd5e4a7c9c0785 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 19 Sep 2022 22:53:21 +0200 Subject: [PATCH 3/6] Fix scoping for let-else. --- compiler/rustc_mir_build/src/build/block.rs | 43 +++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/block.rs b/compiler/rustc_mir_build/src/build/block.rs index 4bab583c96018..fc1b301402b73 100644 --- a/compiler/rustc_mir_build/src/build/block.rs +++ b/compiler/rustc_mir_build/src/build/block.rs @@ -221,27 +221,37 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let init = &this.thir[*initializer]; let initializer_span = init.span; - this.declare_bindings( - visibility_scope, - remainder_span, - pattern, - ArmHasGuard(false), - Some((None, initializer_span)), - ); - this.visit_primary_bindings( - pattern, - UserTypeProjections::none(), - &mut |this, _, _, _, node, span, _, _| { - this.storage_live_binding(block, node, span, OutsideGuard, true); - this.schedule_drop_for_binding(node, span, OutsideGuard); - }, - ); let failure = unpack!( block = this.in_opt_scope( opt_destruction_scope.map(|de| (de, source_info)), |this| { let scope = (*init_scope, source_info); this.in_scope(scope, *lint_level, |this| { + this.declare_bindings( + visibility_scope, + remainder_span, + pattern, + ArmHasGuard(false), + Some((None, initializer_span)), + ); + this.visit_primary_bindings( + pattern, + UserTypeProjections::none(), + &mut |this, _, _, _, node, span, _, _| { + this.storage_live_binding( + block, + node, + span, + OutsideGuard, + true, + ); + this.schedule_drop_for_binding( + node, + span, + OutsideGuard, + ); + }, + ); this.ast_let_else( block, init, @@ -306,7 +316,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ArmHasGuard(false), Some((None, initializer_span)), ); - this.expr_into_pattern(block, &pattern, init) // irrefutable pattern + this.expr_into_pattern(block, &pattern, init) + // irrefutable pattern }) }, ) From f8527fdc3fb10c2cd6b23f3492bcc27b837c806d Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Wed, 14 Sep 2022 19:33:00 -0500 Subject: [PATCH 4/6] Make the `c` feature for `compiler-builtins` opt-in instead of inferred The build script for `compiler_builtins` doesn't support cross-compilation. I tried fixing it, but the cc crate itself doesn't appear to support cross-compiling to windows either unless you use the -gnu toolchain: ``` error occurred: Failed to find tool. Is `lib.exe` installed? ``` Rather than trying to fix it or special-case the platforms without bugs, make it opt-in instead of automatic. --- config.toml.example | 4 +++ src/bootstrap/compile.rs | 15 ++++++--- src/bootstrap/config.rs | 4 +++ src/bootstrap/dist.rs | 32 +++++++++---------- .../disabled/dist-x86_64-haiku/Dockerfile | 2 ++ .../host-x86_64/dist-various-2/Dockerfile | 2 ++ .../x86_64-gnu-llvm-13-stage1/Dockerfile | 1 + .../host-x86_64/x86_64-gnu-llvm-13/Dockerfile | 1 + src/ci/run.sh | 5 +++ 9 files changed, 44 insertions(+), 22 deletions(-) diff --git a/config.toml.example b/config.toml.example index a967d881b029b..ff08dfc553d3b 100644 --- a/config.toml.example +++ b/config.toml.example @@ -291,6 +291,10 @@ changelog-seen = 2 # on this runtime, such as `-C profile-generate` or `-C instrument-coverage`). #profiler = false +# Use the optimized LLVM C intrinsics for `compiler_builtins`, rather than Rust intrinsics. +# Requires the LLVM submodule to be managed by bootstrap (i.e. not external). +#optimized-compiler-builtins = false + # Indicates whether the native libraries linked into Cargo will be statically # linked or not. #cargo-native-static = false diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index c13e83f6c8612..58cf3edc3171f 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -299,9 +299,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car // Determine if we're going to compile in optimized C intrinsics to // the `compiler-builtins` crate. These intrinsics live in LLVM's - // `compiler-rt` repository, but our `src/llvm-project` submodule isn't - // always checked out, so we need to conditionally look for this. (e.g. if - // an external LLVM is used we skip the LLVM submodule checkout). + // `compiler-rt` repository. // // Note that this shouldn't affect the correctness of `compiler-builtins`, // but only its speed. Some intrinsics in C haven't been translated to Rust @@ -312,8 +310,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car // If `compiler-rt` is available ensure that the `c` feature of the // `compiler-builtins` crate is enabled and it's configured to learn where // `compiler-rt` is located. - let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt"); - let compiler_builtins_c_feature = if compiler_builtins_root.exists() { + let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins { + if !builder.is_rust_llvm(target) { + panic!( + "need a managed LLVM submodule for optimized intrinsics support; unset `llvm-config` or `optimized-compiler-builtins`" + ); + } + + builder.update_submodule(&Path::new("src").join("llvm-project")); + let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt"); // Note that `libprofiler_builtins/build.rs` also computes this so if // you're changing something here please also change that. cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root); diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 7c062460c4f16..1924ff09d4997 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -73,6 +73,8 @@ pub struct Config { pub color: Color, pub patch_binaries_for_nix: bool, pub stage0_metadata: Stage0Metadata, + /// Whether to use the `c` feature of the `compiler_builtins` crate. + pub optimized_compiler_builtins: bool, pub on_fail: Option, pub stage: u32, @@ -597,6 +599,7 @@ define_config! { bench_stage: Option = "bench-stage", patch_binaries_for_nix: Option = "patch-binaries-for-nix", metrics: Option = "metrics", + optimized_compiler_builtins: Option = "optimized-compiler-builtins", } } @@ -916,6 +919,7 @@ impl Config { set(&mut config.print_step_timings, build.print_step_timings); set(&mut config.print_step_rusage, build.print_step_rusage); set(&mut config.patch_binaries_for_nix, build.patch_binaries_for_nix); + set(&mut config.optimized_compiler_builtins, build.optimized_compiler_builtins); config.verbose = cmp::max(config.verbose, flags.verbose); diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 1a59b3958f106..1daea9d8237a4 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1838,23 +1838,21 @@ fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) { /// /// Returns whether the files were actually copied. fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool { - if let Some(config) = builder.config.target_config.get(&target) { - if config.llvm_config.is_some() && !builder.config.llvm_from_ci { - // If the LLVM was externally provided, then we don't currently copy - // artifacts into the sysroot. This is not necessarily the right - // choice (in particular, it will require the LLVM dylib to be in - // the linker's load path at runtime), but the common use case for - // external LLVMs is distribution provided LLVMs, and in that case - // they're usually in the standard search path (e.g., /usr/lib) and - // copying them here is going to cause problems as we may end up - // with the wrong files and isn't what distributions want. - // - // This behavior may be revisited in the future though. - // - // If the LLVM is coming from ourselves (just from CI) though, we - // still want to install it, as it otherwise won't be available. - return false; - } + if builder.is_rust_llvm(target) { + // If the LLVM was externally provided, then we don't currently copy + // artifacts into the sysroot. This is not necessarily the right + // choice (in particular, it will require the LLVM dylib to be in + // the linker's load path at runtime), but the common use case for + // external LLVMs is distribution provided LLVMs, and in that case + // they're usually in the standard search path (e.g., /usr/lib) and + // copying them here is going to cause problems as we may end up + // with the wrong files and isn't what distributions want. + // + // This behavior may be revisited in the future though. + // + // If the LLVM is coming from ourselves (just from CI) though, we + // still want to install it, as it otherwise won't be available. + return false; } // On macOS, rustc (and LLVM tools) link to an unversioned libLLVM.dylib diff --git a/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile b/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile index 5ddd3f1803964..637b5fa22f974 100644 --- a/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile +++ b/src/ci/docker/host-x86_64/disabled/dist-x86_64-haiku/Dockerfile @@ -47,4 +47,6 @@ ENV RUST_CONFIGURE_ARGS --disable-jemalloc \ --set=$TARGET.cc=x86_64-unknown-haiku-gcc \ --set=$TARGET.cxx=x86_64-unknown-haiku-g++ \ --set=$TARGET.llvm-config=/bin/llvm-config-haiku +ENV EXTERNAL_LLVM 1 + ENV SCRIPT python3 ../x.py dist --host=$HOST --target=$HOST diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index 126c292b38ea1..8250ec0c3119b 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -129,4 +129,6 @@ ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --disable-docs \ --set target.wasm32-wasi.wasi-root=/wasm32-wasi \ --musl-root-armv7=/musl-armv7 +ENV EXTERNAL_LLVM 1 + ENV SCRIPT python3 ../x.py dist --host='' --target $TARGETS diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile index 23f2215c2d93c..1289f116fe9fc 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile +++ b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13-stage1/Dockerfile @@ -29,6 +29,7 @@ RUN sh /scripts/sccache.sh # We are disabling CI LLVM since this builder is intentionally using a host # LLVM, rather than the typical src/llvm-project LLVM. ENV NO_DOWNLOAD_CI_LLVM 1 +ENV EXTERNAL_LLVM 1 # Using llvm-link-shared due to libffi issues -- see #34486 ENV RUST_CONFIGURE_ARGS \ diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile index 8f6831bc54e63..4b89a72baa1c5 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile +++ b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile @@ -40,6 +40,7 @@ RUN sh /scripts/sccache.sh # We are disabling CI LLVM since this builder is intentionally using a host # LLVM, rather than the typical src/llvm-project LLVM. ENV NO_DOWNLOAD_CI_LLVM 1 +ENV EXTERNAL_LLVM 1 # Using llvm-link-shared due to libffi issues -- see #34486 ENV RUST_CONFIGURE_ARGS \ diff --git a/src/ci/run.sh b/src/ci/run.sh index 9a247fb60a8ee..9d98ce22498cd 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -69,6 +69,11 @@ RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.codegen-units-std=1" # space required for CI artifacts. RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --dist-compression-formats=xz" +# Enable the `c` feature for compiler_builtins, but only when the `compiler-rt` source is available. +if [ "$EXTERNAL_LLVM" = "" ]; then + RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.optimized-compiler-builtins" +fi + if [ "$DIST_SRC" = "" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-dist-src" fi From 4d0d688a3cfd3d58cbd5d8065a7af774a7bb82b6 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 25 Sep 2022 22:20:01 +0000 Subject: [PATCH 5/6] Recover some items that expect braces and don't take semicolons --- .../locales/en-US/parser.ftl | 3 ++ .../rustc_parse/src/parser/diagnostics.rs | 8 +++++ compiler/rustc_parse/src/parser/item.rs | 29 ++++++++++++++----- src/test/ui/parser/empty-impl-semicolon.rs | 5 +++- .../ui/parser/empty-impl-semicolon.stderr | 8 +++-- src/test/ui/parser/item-needs-block.rs | 10 +++++++ src/test/ui/parser/item-needs-block.stderr | 26 +++++++++++++++++ 7 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 src/test/ui/parser/item-needs-block.rs create mode 100644 src/test/ui/parser/item-needs-block.stderr diff --git a/compiler/rustc_error_messages/locales/en-US/parser.ftl b/compiler/rustc_error_messages/locales/en-US/parser.ftl index 9459cfebde936..07dd03e6e504e 100644 --- a/compiler/rustc_error_messages/locales/en-US/parser.ftl +++ b/compiler/rustc_error_messages/locales/en-US/parser.ftl @@ -158,3 +158,6 @@ parser_remove_let = expected pattern, found `let` parser_use_eq_instead = unexpected `==` .suggestion = try using `=` instead + +parser_use_empty_block_not_semi = expected { "`{}`" }, found `;` + .suggestion = try using { "`{}`" } instead diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index dcea11eadcbf1..8750873c3a4a3 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -745,6 +745,14 @@ pub(crate) struct UseEqInstead { pub span: Span, } +#[derive(Diagnostic)] +#[diag(parser::use_empty_block_not_semi)] +pub(crate) struct UseEmptyBlockNotSemi { + #[primary_span] + #[suggestion_hidden(applicability = "machine-applicable", code = "{{}}")] + pub span: Span, +} + // SnapshotParser is used to create a snapshot of the parser // without causing duplicate errors being emitted when the `Parser` // is dropped. diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index e55b5ce71cded..802dfc048f825 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1,4 +1,4 @@ -use super::diagnostics::{dummy_arg, ConsumeClosingDelim, Error}; +use super::diagnostics::{dummy_arg, ConsumeClosingDelim, Error, UseEmptyBlockNotSemi}; use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign}; use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken}; @@ -664,6 +664,14 @@ impl<'a> Parser<'a> { mut parse_item: impl FnMut(&mut Parser<'a>) -> PResult<'a, Option>>, ) -> PResult<'a, Vec> { let open_brace_span = self.token.span; + + // Recover `impl Ty;` instead of `impl Ty {}` + if self.token == TokenKind::Semi { + self.sess.emit_err(UseEmptyBlockNotSemi { span: self.token.span }); + self.bump(); + return Ok(vec![]); + } + self.expect(&token::OpenDelim(Delimiter::Brace))?; attrs.extend(self.parse_inner_attributes()?); @@ -1305,12 +1313,19 @@ impl<'a> Parser<'a> { let mut generics = self.parse_generics()?; generics.where_clause = self.parse_where_clause()?; - let (variants, _) = self - .parse_delim_comma_seq(Delimiter::Brace, |p| p.parse_enum_variant()) - .map_err(|e| { - self.recover_stmt(); - e - })?; + // Possibly recover `enum Foo;` instead of `enum Foo {}` + let (variants, _) = if self.token == TokenKind::Semi { + self.sess.emit_err(UseEmptyBlockNotSemi { span: self.token.span }); + self.bump(); + (vec![], false) + } else { + self.parse_delim_comma_seq(Delimiter::Brace, |p| p.parse_enum_variant()).map_err( + |e| { + self.recover_stmt(); + e + }, + )? + }; let enum_definition = EnumDef { variants: variants.into_iter().flatten().collect() }; Ok((id, ItemKind::Enum(enum_definition, generics))) diff --git a/src/test/ui/parser/empty-impl-semicolon.rs b/src/test/ui/parser/empty-impl-semicolon.rs index 207ebef642bfa..2485f5b855202 100644 --- a/src/test/ui/parser/empty-impl-semicolon.rs +++ b/src/test/ui/parser/empty-impl-semicolon.rs @@ -1 +1,4 @@ -impl Foo; //~ ERROR expected one of `!`, `(`, `+`, `::`, `<`, `for`, `where`, or `{`, found `;` +struct Foo; +impl Foo; //~ ERROR expected `{}`, found `;` + +fn main() {} diff --git a/src/test/ui/parser/empty-impl-semicolon.stderr b/src/test/ui/parser/empty-impl-semicolon.stderr index 398eb5c898cdd..6ed309eba9392 100644 --- a/src/test/ui/parser/empty-impl-semicolon.stderr +++ b/src/test/ui/parser/empty-impl-semicolon.stderr @@ -1,8 +1,10 @@ -error: expected one of `!`, `(`, `+`, `::`, `<`, `for`, `where`, or `{`, found `;` - --> $DIR/empty-impl-semicolon.rs:1:9 +error: expected `{}`, found `;` + --> $DIR/empty-impl-semicolon.rs:2:9 | LL | impl Foo; - | ^ expected one of 8 possible tokens + | ^ + | + = help: try using `{}` instead error: aborting due to previous error diff --git a/src/test/ui/parser/item-needs-block.rs b/src/test/ui/parser/item-needs-block.rs new file mode 100644 index 0000000000000..4edac588eee97 --- /dev/null +++ b/src/test/ui/parser/item-needs-block.rs @@ -0,0 +1,10 @@ +trait Trait; +//~^ ERROR expected `{}`, found `;` + +impl Trait for (); +//~^ ERROR expected `{}`, found `;` + +enum Enum; +//~^ ERROR expected `{}`, found `;` + +fn main() {} diff --git a/src/test/ui/parser/item-needs-block.stderr b/src/test/ui/parser/item-needs-block.stderr new file mode 100644 index 0000000000000..3cabd0c73a3c9 --- /dev/null +++ b/src/test/ui/parser/item-needs-block.stderr @@ -0,0 +1,26 @@ +error: expected `{}`, found `;` + --> $DIR/item-needs-block.rs:1:12 + | +LL | trait Trait; + | ^ + | + = help: try using `{}` instead + +error: expected `{}`, found `;` + --> $DIR/item-needs-block.rs:4:18 + | +LL | impl Trait for (); + | ^ + | + = help: try using `{}` instead + +error: expected `{}`, found `;` + --> $DIR/item-needs-block.rs:7:10 + | +LL | enum Enum; + | ^ + | + = help: try using `{}` instead + +error: aborting due to 3 previous errors + From e4b08ab241f19342400f7a1722de5e0d43cbe386 Mon Sep 17 00:00:00 2001 From: woppopo Date: Mon, 26 Sep 2022 05:00:31 +0000 Subject: [PATCH 6/6] Allow `~const` bounds on non-const functions --- .../rustc_ast_passes/src/ast_validation.rs | 7 ++-- .../tilde-const-and-const-params.rs | 34 +++++++++++++++++++ .../tilde-const-invalid-places.rs | 6 ---- .../tilde-const-invalid-places.stderr | 28 ++++----------- 4 files changed, 43 insertions(+), 32 deletions(-) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index b1d10e07ad0fb..ecf74c7602027 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1415,7 +1415,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if !self.is_tilde_const_allowed { self.err_handler() .struct_span_err(bound.span(), "`~const` is not allowed here") - .note("only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions") + .note("only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions") .emit(); } } @@ -1523,9 +1523,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> { }); } - let tilde_const_allowed = - matches!(fk.header(), Some(FnHeader { constness: Const::Yes(_), .. })) - || matches!(fk.ctxt(), Some(FnCtxt::Assoc(_))); + let tilde_const_allowed = matches!(fk.header(), Some(FnHeader { .. })) + || matches!(fk.ctxt(), Some(FnCtxt::Assoc(_))); self.with_tilde_const(tilde_const_allowed, |this| visit::walk_fn(this, fk)); } diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs new file mode 100644 index 0000000000000..b29b633cff644 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-and-const-params.rs @@ -0,0 +1,34 @@ +// check-pass +#![feature(const_trait_impl)] +#![feature(generic_arg_infer)] +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +struct Foo; + +impl Foo { + fn add(self) -> Foo<{ A::add(N) }> { + Foo + } +} + +#[const_trait] +trait Add42 { + fn add(a: usize) -> usize; +} + +impl const Add42 for () { + fn add(a: usize) -> usize { + a + 42 + } +} + +fn bar(_: Foo) -> Foo<{ A::add(N) }> { + Foo +} + +fn main() { + let foo = Foo::<0>; + let foo = bar::<(), _>(foo); + let _foo = bar::<(), _>(foo); +} diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs index b4302f3e75fd4..350be4d8250d6 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs @@ -17,12 +17,6 @@ fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } fn apit_assoc_bound(_: impl IntoIterator) {} //~^ ERROR `~const` is not allowed -fn generic() {} -//~^ ERROR `~const` is not allowed - -fn where_clause

() where P: ~const T {} -//~^ ERROR `~const` is not allowed - struct TildeQuestion(std::marker::PhantomData); //~^ ERROR `~const` and `?` are mutually exclusive diff --git a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr index 033ec21ba8408..8d781d063d1c0 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr @@ -4,7 +4,7 @@ error: `~const` is not allowed here LL | fn rpit() -> impl ~const T { S } | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + = note: only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions error: `~const` is not allowed here --> $DIR/tilde-const-invalid-places.rs:11:17 @@ -12,7 +12,7 @@ error: `~const` is not allowed here LL | fn apit(_: impl ~const T) {} | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + = note: only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions error: `~const` is not allowed here --> $DIR/tilde-const-invalid-places.rs:14:50 @@ -20,7 +20,7 @@ error: `~const` is not allowed here LL | fn rpit_assoc_bound() -> impl IntoIterator { Some(S) } | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + = note: only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions error: `~const` is not allowed here --> $DIR/tilde-const-invalid-places.rs:17:48 @@ -28,29 +28,13 @@ error: `~const` is not allowed here LL | fn apit_assoc_bound(_: impl IntoIterator) {} | ^^^^^^^^ | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions - -error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:20:15 - | -LL | fn generic() {} - | ^^^^^^^^ - | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions - -error: `~const` is not allowed here - --> $DIR/tilde-const-invalid-places.rs:23:31 - | -LL | fn where_clause

() where P: ~const T {} - | ^^^^^^^^ - | - = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + = note: only allowed on bounds on functions, traits' associated types and functions, const impls and its associated functions error: `~const` and `?` are mutually exclusive - --> $DIR/tilde-const-invalid-places.rs:26:25 + --> $DIR/tilde-const-invalid-places.rs:20:25 | LL | struct TildeQuestion(std::marker::PhantomData); | ^^^^^^^^^^^^^ -error: aborting due to 7 previous errors +error: aborting due to 5 previous errors