From fe18afe48caa890fc343d99a176db8fe8310dbfc Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Apr 2024 10:07:11 +0000 Subject: [PATCH 1/3] Unset test env vars before setting new ones. If you want to override an env var, don't unset it, just set it --- src/tools/compiletest/src/runtest.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 38d22fef1132..1dd639a89188 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2173,8 +2173,8 @@ impl<'test> TestCx<'test> { let aux_dir = self.aux_output_dir(); self.build_all_auxiliary(&self.testpaths, &aux_dir, &mut rustc); - self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove); rustc.envs(self.props.rustc_env.clone()); + self.props.unset_rustc_env.iter().fold(&mut rustc, Command::env_remove); self.compose_and_run( rustc, self.config.compile_lib_path.to_str().unwrap(), @@ -2220,10 +2220,10 @@ impl<'test> TestCx<'test> { ); aux_cx.build_all_auxiliary(of, &aux_dir, &mut aux_rustc); + aux_rustc.envs(aux_props.rustc_env.clone()); for key in &aux_props.unset_rustc_env { aux_rustc.env_remove(key); } - aux_rustc.envs(aux_props.rustc_env.clone()); let (aux_type, crate_type) = if is_bin { (AuxType::Bin, Some("bin")) From 4f75d67b6fd0bd677c17d5060facd31c70dd4afe Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Apr 2024 10:07:56 +0000 Subject: [PATCH 2/3] Make ui_test backtraces short by default --- src/tools/compiletest/src/header.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index f78e0363f55b..daa605f6d03a 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -265,7 +265,10 @@ impl TestProps { aux_bins: vec![], aux_crates: vec![], revisions: vec![], - rustc_env: vec![("RUSTC_ICE".to_string(), "0".to_string())], + rustc_env: vec![ + ("RUSTC_ICE".to_string(), "0".to_string()), + ("RUST_BACKTRACE".to_string(), "short".to_string()), + ], unset_rustc_env: vec![("RUSTC_LOG_COLOR".to_string())], exec_env: vec![], unset_exec_env: vec![], From 0a88339a57557152bb32c4969f2f76955793133e Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 9 Apr 2024 10:08:20 +0000 Subject: [PATCH 3/3] Don't ICE for kind mismatches during error rendering --- .../error_reporting/type_err_ctxt_ext.rs | 3 ++ tests/ui/const-generics/kind_mismatch.rs | 24 ++++++++++++ tests/ui/const-generics/kind_mismatch.stderr | 39 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tests/ui/const-generics/kind_mismatch.rs create mode 100644 tests/ui/const-generics/kind_mismatch.stderr diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 3dc54b338017..4aa5f9752ab2 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -1974,6 +1974,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { for (obligation_arg, impl_arg) in std::iter::zip(obligation_trait_ref.args, impl_trait_ref.args) { + if (obligation_arg, impl_arg).references_error() { + return false; + } if let Err(terr) = ocx.eq(&ObligationCause::dummy(), param_env, impl_arg, obligation_arg) { diff --git a/tests/ui/const-generics/kind_mismatch.rs b/tests/ui/const-generics/kind_mismatch.rs new file mode 100644 index 000000000000..bab58d5952a5 --- /dev/null +++ b/tests/ui/const-generics/kind_mismatch.rs @@ -0,0 +1,24 @@ +//! This test used to ICE in typeck because of the type/const mismatch, +//! even though wfcheck already errored. +//! issue: rust-lang/rust#123457 + +pub struct KeyHolder {} + +pub trait ContainsKey {} + +pub trait SubsetExcept

{} + +impl ContainsKey for KeyHolder {} +//~^ ERROR: type provided when a constant was expected +//~| ERROR: type provided when a constant was expected + +impl> SubsetExcept

for T {} + +pub fn remove_key>() -> S { + loop {} +} + +fn main() { + let map: KeyHolder<0> = remove_key::<_, _>(); + //~^ ERROR: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied +} diff --git a/tests/ui/const-generics/kind_mismatch.stderr b/tests/ui/const-generics/kind_mismatch.stderr new file mode 100644 index 000000000000..80968ebea687 --- /dev/null +++ b/tests/ui/const-generics/kind_mismatch.stderr @@ -0,0 +1,39 @@ +error[E0747]: type provided when a constant was expected + --> $DIR/kind_mismatch.rs:11:38 + | +LL | impl ContainsKey for KeyHolder {} + | - ^ + | | + | help: consider changing this type parameter to a const parameter: `const K: u8` + +error[E0747]: type provided when a constant was expected + --> $DIR/kind_mismatch.rs:11:21 + | +LL | impl ContainsKey for KeyHolder {} + | - ^ + | | + | help: consider changing this type parameter to a const parameter: `const K: u8` + +error[E0277]: the trait bound `KeyHolder<0>: SubsetExcept<_>` is not satisfied + --> $DIR/kind_mismatch.rs:22:45 + | +LL | let map: KeyHolder<0> = remove_key::<_, _>(); + | ^ the trait `ContainsKey<0>` is not implemented for `KeyHolder<0>`, which is required by `KeyHolder<0>: SubsetExcept<_>` + | +note: required for `KeyHolder<0>` to implement `SubsetExcept<_>` + --> $DIR/kind_mismatch.rs:15:28 + | +LL | impl> SubsetExcept

for T {} + | -------------- ^^^^^^^^^^^^^^^ ^ + | | + | unsatisfied trait bound introduced here +note: required by a bound in `remove_key` + --> $DIR/kind_mismatch.rs:17:25 + | +LL | pub fn remove_key>() -> S { + | ^^^^^^^^^^^^^^^ required by this bound in `remove_key` + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0747. +For more information about an error, try `rustc --explain E0277`.