Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing normalization when checking const generics #114702

Closed

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Aug 10, 2023

Fixes #114217.
Part of #112792.

r? @compiler-errors

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 10, 2023
@compiler-errors
Copy link
Member

I'm not actually totally convinced this is something we want to support. We don't normalize other aliases --

trait Mirror { type Mirror; }
impl<T> Mirror for T { type Mirror = T; }

fn test<const N: <i32 as Mirror>::Mirror>() {}
//~^ `<i32 as Mirror>::Mirror` is forbidden as the type of a const generic parameter

@compiler-errors
Copy link
Member

Even if we were to normalize things here, we should not be using normalize_erasing_regions at all this early in the compiler. We need to use a wf-checking context to normalize things properly.

@compiler-errors compiler-errors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 10, 2023
@GuillaumeGomez
Copy link
Member Author

I'm not actually totally convinced this is something we want to support. We don't normalize other aliases --

trait Mirror { type Mirror; }
impl<T> Mirror for T { type Mirror = T; }

fn test<const N: <i32 as Mirror>::Mirror>() {}
//~^ `<i32 as Mirror>::Mirror` is forbidden as the type of a const generic parameter

Are projections the same as aliases?

Also, sorry, just realized that some context is missing (only present in the issue). Without the feature enabled, the code compiles just fine, meaning that aliases are supposed to work for const generics. But maybe I should only normalize if this is a weak ty alias? As you prefer.

As for using projections in const generics, it was something that was kinda agreed upon in #104443 but it wasn't merged because it was introducing new bugs (hence why I'm suggesting to only normalize if this is a weak ty alias).

Even if we were to normalize things here, we should not be using normalize_erasing_regions at all this early in the compiler. We need to use a wf-checking context to normalize things properly.

Sounds good to me!

So what do you want me to do here? Should I update the PR to use the correct normalization, should I only normalize if it's a weak ty alias or this is not something that the compiler wants at all and then we can close this PR?

@compiler-errors
Copy link
Member

Are projections the same as aliases?

Both "lazy type aliases" ("weak") and projections are forms of alias, so I expect them to act consistently.

Without the feature enabled, the code compiles just fine, meaning that aliases are supposed to work for const generics.

The point of the lazy_type_alias feature is to change the semantics of type aliases. Just because something builds without the flag doesn't mean it will build with the flag.

As for using projections in const generics, it was something that was kinda agreed upon in #104443 but it wasn't merged because it was introducing new bugs (hence why I'm suggesting to only normalize if this is a weak ty alias).

I think we should then probably bring this question back up formally rather than just fix it ad-hoc like this. The more that these features diverge, the more we're gonna have to clean up and reconcile later, imo.

Also, doesn't this lead to the same exact bugs as #104443? Either that, or this PR is incomplete?

@GuillaumeGomez
Copy link
Member Author

Both "lazy type aliases" ("weak") and projections are forms of alias, so I expect them to act consistently.

Thanks for the clarification!

The point of the lazy_type_alias feature is to change the semantics of type aliases. Just because something builds without the flag doesn't mean it will build with the flag.

Makes sense! Just a bit weird. 😸

I think we should then probably bring this question back up formally rather than just fix it ad-hoc like this. The more that these features diverge, the more we're gonna have to clean up and reconcile later, imo.

Also, doesn't this lead to the same exact bugs as #104443? Either that, or this PR is incomplete?

It's not doing the same change (maybe because the code changed a lot since then?) as it doesn't fail the test, so I suppose it's unrelated to supporting projections in const generics. Just an early check I guess.

Anyway, I'll update the code and if the compiler team doesn't want it, I'll close this PR and instead open a new one with the failing code so it's not forgotten.

@GuillaumeGomez
Copy link
Member Author

When changing:

-            let param_env = tcx.param_env(param.def_id);
-            let ty = tcx.normalize_erasing_regions(param_env, ty);
+            enter_wf_checking_ctxt(tcx, hir_ty.span, param.def_id, |wfcx| {
+                let ty = wfcx.normalize(hir_ty.span, Some(WellFormedLoc::Ty(param.def_id)), ty);

tests/ui/const-generics/projection-as-arg-const.rs panics:

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: Const::from_anon_const: couldn't lit_to_const TypeError
  --> /home/imperio/rust/rust/tests/ui/const-generics/projection-as-arg-const.rs:19:11
   |
LL |     foo::<12>();
   |           ^^
   |
note: delayed at compiler/rustc_middle/src/ty/consts.rs:213:30
         0: <rustc_errors::HandlerInner>::emit_diagnostic
         1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         2: <rustc_middle::ty::consts::Const>::from_anon_const
         3: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path::CreateCtorSubstsContext as rustc_hir_analysis::astconv::CreateSubstsForGenericArgsCtxt>::provided_kind
         4: rustc_hir_analysis::astconv::generics::create_args_for_parent_generic_args::<<rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path::CreateCtorSubstsContext>
         5: <rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path
         6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_path
         7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
         8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
         9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
        10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_stmt
        12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
        13: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
        15: rustc_hir_typeck::check::check_fn
        16: rustc_hir_typeck::typeck
        17: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        18: <rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
        19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        20: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
        21: <core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::par_for_each_in<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}>::{closure#0}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
        22: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}>
        23: rustc_hir_analysis::check_crate
        24: rustc_interface::passes::analysis
        25: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        26: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        28: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        29: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}::{closure#6}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        30: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
        31: rustc_span::set_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
        32: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        33: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        34: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        35: std::sys::unix::thread::Thread::new::thread_start
        36: start_thread
                   at ./nptl/pthread_create.c:442:8
        37: clone3
                   at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  --> /home/imperio/rust/rust/tests/ui/const-generics/projection-as-arg-const.rs:19:11
   |
LL |     foo::<12>();
   |           ^^

note: we would appreciate a bug report: https:/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

So I suppose either this fix is incomplete or it's simply wrong to change it. I updated the code, but I guess it'll just be closed for now.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-15 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
##[endgroup]
Built container sha256:985e94482ac3075fb5e5dac4a69c21d6d8cc0b1b7fed1ab7753e5fcd8ab69151
Uploading finished image to https://ci-caches.rust-lang.org/docker/81ffb10956977f61179e4c596a0e3b6b2e7d3e589c46ba41f8b60297a95ab1bc4f59e3f20a6f9fe7b17273bb168d9d6e8419853543fb546bcc96155689743fc6

<botocore.awsrequest.AWSRequest object at 0x7f24909d9d90>
gzip: stdout: Broken pipe
xargs: docker: terminated by signal 13
[CI_JOB_NAME=x86_64-gnu-llvm-15]
[CI_JOB_NAME=x86_64-gnu-llvm-15]
---
...................................................................................i....  2376/15426
.....................................................................F..................  2464/15426
........................................................................................  2552/15426
........................................................................................  2640/15426
................................F......................................F................  2728/15426
F..F......F..............................................................F..............  2816/15426
.............F.............................................i............................  2904/15426
........................................................................................  3080/15426
........................................................................................  3168/15426
........................................................................................  3256/15426
........................................................................................  3344/15426
---

14    |
15    = note: const parameters may not be used in the type of const parameters
16 
- error: `[u8; N]` is forbidden as the type of a const generic parameter
+ error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
19    |
19    |
20 LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);

23    = note: the only supported types are integers, `bool` and `char`
24    = help: more complex types are supported with `#![feature(adt_const_params)]`
25 
- error: `[u8; N]` is forbidden as the type of a const generic parameter
+ error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
28    |
28    |
29 LL | pub struct SelfDependent<const N: [u8; N]>;

The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/const-param-type-depends-on-const-param.min/const-param-type-depends-on-const-param.min.stderr
To only update this specific test, also pass `--test-args const-generics/const-param-type-depends-on-const-param.rs`


error in revision `min`: 1 errors occurred comparing output.
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/const-param-type-depends-on-const-param.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--cfg" "min" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/const-param-type-depends-on-const-param.min" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/const-param-type-depends-on-const-param.min/auxiliary"
--- stderr -------------------------------
error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/const-param-type-depends-on-const-param.rs:11:52
   |
   |
LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
   |                                                    ^ the type must not depend on the parameter `N`
   = note: const parameters may not be used in the type of const parameters

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/const-param-type-depends-on-const-param.rs:15:40
##[error]  --> /checkout/tests/ui/const-generics/const-param-type-depends-on-const-param.rs:15:40
   |
LL | pub struct SelfDependent<const N: [u8; N]>;
   |                                        ^ the type must not depend on the parameter `N`
   = note: const parameters may not be used in the type of const parameters


error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
   |
   |
LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`

error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
   |
   |
LL | pub struct SelfDependent<const N: [u8; N]>;
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0770`.
------------------------------------------
---

6    |
7    = note: const parameters may not be used in the type of const parameters
8 
- error: `[u8; N]` is forbidden as the type of a const generic parameter
+ error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
11    |
Build completed unsuccessfully in 0:10:49
Build completed unsuccessfully in 0:10:49
12 LL | fn foo<const N: usize, const A: [u8; N]>() {}

The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-62878.min/issue-62878.min.stderr
To only update this specific test, also pass `--test-args const-generics/issues/issue-62878.rs`


error in revision `min`: 1 errors occurred comparing output.
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/issues/issue-62878.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--cfg" "min" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-62878.min" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-62878.min/auxiliary"
--- stderr -------------------------------
error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/issues/issue-62878.rs:5:38
   |
   |
LL | fn foo<const N: usize, const A: [u8; N]>() {}
   |                                      ^ the type must not depend on the parameter `N`
   = note: const parameters may not be used in the type of const parameters


error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
   |
   |
LL | fn foo<const N: usize, const A: [u8; N]>() {}
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0770`.
------------------------------------------
---

6    |
7    = note: const parameters may not be used in the type of const parameters
8 
- error: `[u8; LEN]` is forbidden as the type of a const generic parameter
+ error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
11    |
11    |
12 LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}

The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-71169.min/issue-71169.min.stderr
To only update this specific test, also pass `--test-args const-generics/issues/issue-71169.rs`


error in revision `min`: 1 errors occurred comparing output.
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/issues/issue-71169.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--cfg" "min" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-71169.min" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-71169.min/auxiliary"
--- stderr -------------------------------
error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/issues/issue-71169.rs:5:43
   |
   |
LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
   |                                           ^^^ the type must not depend on the parameter `LEN`
   = note: const parameters may not be used in the type of const parameters


error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
   |
   |
LL | fn foo<const LEN: usize, const DATA: [u8; LEN]>() {}
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0770`.
------------------------------------------
------------------------------------------


---- [ui] tests/ui/const-generics/issues/issue-73491.rs#min stdout ----
diff of stderr:

- error: `[u32; LEN]` is forbidden as the type of a const generic parameter
+ error: `[u32; 1024]` is forbidden as the type of a const generic parameter
3    |
3    |
4 LL | fn hoge<const IN: [u32; LEN]>() {}

The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-73491.min/issue-73491.min.stderr
To only update this specific test, also pass `--test-args const-generics/issues/issue-73491.rs`


error in revision `min`: 1 errors occurred comparing output.
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/issues/issue-73491.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--cfg" "min" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-73491.min" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-73491.min/auxiliary"
--- stderr -------------------------------
--- stderr -------------------------------
error: `[u32; 1024]` is forbidden as the type of a const generic parameter
   |
   |
LL | fn hoge<const IN: [u32; LEN]>() {}
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`
error: aborting due to previous error
------------------------------------------



---- [ui] tests/ui/const-generics/issues/issue-74101.rs#min stdout ----
diff of stderr:

- error: `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
+ error: `[u8; 3]` is forbidden as the type of a const generic parameter
3    |
3    |
4 LL | fn test<const N: [u8; 1 + 2]>() {}

7    = note: the only supported types are integers, `bool` and `char`
8    = help: more complex types are supported with `#![feature(adt_const_params)]`
9 
- error: `[u8; 1 + 2]` is forbidden as the type of a const generic parameter
+ error: `[u8; 3]` is forbidden as the type of a const generic parameter
12    |
12    |
13 LL | struct Foo<const N: [u8; 1 + 2]>;

The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-74101.min/issue-74101.min.stderr
To only update this specific test, also pass `--test-args const-generics/issues/issue-74101.rs`


error in revision `min`: 1 errors occurred comparing output.
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/issues/issue-74101.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--cfg" "min" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-74101.min" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-74101.min/auxiliary"
--- stderr -------------------------------
--- stderr -------------------------------
error: `[u8; 3]` is forbidden as the type of a const generic parameter
   |
   |
LL | fn test<const N: [u8; 1 + 2]>() {}
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`

error: `[u8; 3]` is forbidden as the type of a const generic parameter
   |
   |
LL | struct Foo<const N: [u8; 1 + 2]>;
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`
error: aborting due to 2 previous errors
------------------------------------------



---- [ui] tests/ui/const-generics/issues/issue-75047.rs#min stdout ----
diff of stderr:

- error: `[u8; Bar::<u32>::value()]` is forbidden as the type of a const generic parameter
+ error: `[u8; 42]` is forbidden as the type of a const generic parameter
3    |
3    |
4 LL | struct Foo<const N: [u8; Bar::<u32>::value()]>;

The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-75047.min/issue-75047.min.stderr
To only update this specific test, also pass `--test-args const-generics/issues/issue-75047.rs`


error in revision `min`: 1 errors occurred comparing output.
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/issues/issue-75047.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--cfg" "min" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-75047.min" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/issues/issue-75047.min/auxiliary"
--- stderr -------------------------------
--- stderr -------------------------------
error: `[u8; 42]` is forbidden as the type of a const generic parameter
   |
   |
LL | struct Foo<const N: [u8; Bar::<u32>::value()]>;
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`
error: aborting due to previous error
------------------------------------------



---- [ui] tests/ui/const-generics/nested-type.rs#min stdout ----
diff of stderr:

6    |
7    = note: calls in constants are limited to constant functions, tuple structs and tuple variants
8 
- error: `[u8; {
-            struct Foo<const N: usize>;
-        
-            impl<const N: usize> Foo<N> {
-                    N
-                }
-            }
-        
-        
-            Foo::<17>::value()
-        }]` is forbidden as the type of a const generic parameter
+ error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
21    |
21    |
22 LL |   struct Foo<const N: [u8; {

The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/nested-type.min/nested-type.min.stderr
To only update this specific test, also pass `--test-args const-generics/nested-type.rs`


error in revision `min`: 1 errors occurred comparing output.
status: exit status: 1
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/nested-type.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--cfg" "min" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/nested-type.min" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/nested-type.min/auxiliary"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17>::value` in constants
   |
   |
LL |     Foo::<17>::value()
   |
   = note: calls in constants are limited to constant functions, tuple structs and tuple variants


error: `[u8; {const error}]` is forbidden as the type of a const generic parameter
   |
   |
LL |   struct Foo<const N: [u8; {
   |  _____________________^
LL | |     struct Foo<const N: usize>;
LL | |
LL | |     impl<const N: usize> Foo<N> {
...  |
LL | |     //~^ ERROR cannot call non-const fn
LL | | }]>;
   |
   |
   = note: the only supported types are integers, `bool` and `char`
   = help: more complex types are supported with `#![feature(adt_const_params)]`
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0015`.
------------------------------------------
------------------------------------------


---- [ui] tests/ui/const-generics/projection-as-arg-const.rs stdout ----

error: Error: expected failure status (Some(1)) but received status Some(101).
command: RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/projection-as-arg-const.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/projection-as-arg-const" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/projection-as-arg-const/auxiliary"
stdout: none
--- stderr -------------------------------
--- stderr -------------------------------
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: Const::from_anon_const: couldn't lit_to_const TypeError
   |
   |
LL |     foo::<12>();
   |
note: delayed at compiler/rustc_middle/src/ty/consts.rs:213:30
         0: <rustc_errors::HandlerInner>::emit_diagnostic
         1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         1: <rustc_errors::Handler>::delay_span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         2: <rustc_middle::ty::consts::Const>::from_anon_const
         3: <rustc_hir_typeck::fn_ctxt::FnCtxt>::const_arg_to_const
         4: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path::CreateCtorSubstsContext as rustc_hir_analysis::astconv::CreateSubstsForGenericArgsCtxt>::provided_kind
         5: rustc_hir_analysis::astconv::generics::create_args_for_parent_generic_args::<<rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path::CreateCtorSubstsContext>
         6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::instantiate_value_path
         7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_path
         8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
         9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_call
        10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
        11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation
        13: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_stmt
        14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
        15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
        16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation
        18: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
        19: rustc_hir_typeck::check::check_fn
        20: rustc_hir_typeck::typeck
        21: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        22: <rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
        23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        24: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
        25: <core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::par_for_each_in<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}>::{closure#0}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
        26: std::panicking::try::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::par_for_each_in<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}>::{closure#0}::{closure#0}>>
        27: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_hir_analysis::check_crate::{closure#7}>::{closure#0}>
        29: rustc_interface::passes::analysis
        30: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        31: <rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
        32: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
---
        39: <unknown>
        40: <unknown>
  --> /checkout/tests/ui/const-generics/projection-as-arg-const.rs:19:11
   |
LL |     foo::<12>();

note: we would appreciate a bug report: https:/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.73.0-nightly (79461e1ae 2023-08-11) running on x86_64-unknown-linux-gnu
note: rustc 1.73.0-nightly (79461e1ae 2023-08-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -C rpath -C debuginfo=0
query stack during panic:
end of query stack
error: aborting due to 2 previous errors
------------------------------------------

@GuillaumeGomez GuillaumeGomez deleted the fix-issue-114217 branch August 14, 2023 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lazy_type_alias: type is forbidden as the type of a const generic parameter
4 participants