Repository: rust
Issue: Rocket FromForm derive crash after adding incorrect types
Labels: I-ICE,T-compiler,C-bug,T-types

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

When I have `start_date` and `end_date` using `Option<String>` there is no problems. But when I change it to `NaiveDate` as shown in the code. It says the trait `FromForm<'r>` is not implemented for `std::option::Option<NaiveDate>` and crashes the compiler at the same time. The problem stems from the `FromForm` derive because only when I remove it does the compiler stop crashing.

```Rust
use chrono::NaiveDate;
use rocket::FromForm;

#[derive(FromForm)]
pub struct HistoryRequest {
    pub start_date: Option<NaiveDate>,
    pub end_date: Option<NaiveDate>,
    pub order_by: Option<String>,
    pub page: Option<i32>,
    pub page_size: Option<i32>,
}
```


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7
```

### Error output

```
error[E0277]: the trait bound `std::option::Option<NaiveDate>: FromForm<'r>` is not satisfied
 --> src/model/request/history_request.rs:4:10
  |
4 | #[derive(FromForm)]
  |          ^^^^^^^^ the trait `FromForm<'r>` is not implemented for `std::option::Option<NaiveDate>`
  |
  = help: the trait `FromForm<'v>` is implemented for `std::option::Option<T>`
  = note: this error originates in the derive macro `FromForm` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `std::option::Option<NaiveDate>: FromForm<'r>` is not satisfied
 --> src/model/request/history_request.rs:6:21
  |
6 |     pub start_date: Option<NaiveDate>,
  |                     ^^^^^^^^^^^^^^^^^ the trait `FromForm<'r>` is not implemented for `std::option::Option<NaiveDate>`
  |
  = help: the trait `FromForm<'v>` is implemented for `std::option::Option<T>`

error[E0277]: the trait bound `std::option::Option<NaiveDate>: FromForm<'r>` is not satisfied
 --> src/model/request/history_request.rs:6:9
  |
6 |     pub start_date: Option<NaiveDate>,
  |         ^^^^^^^^^^^^^^^^^^ the trait `FromForm<'r>` is not implemented for `std::option::Option<NaiveDate>`
  |
  = help: the trait `FromForm<'v>` is implemented for `std::option::Option<T>`

error[E0277]: the trait bound `std::option::Option<NaiveDate>: FromForm<'r>` is not satisfied
 --> src/model/request/history_request.rs:7:19
  |
7 |     pub end_date: Option<NaiveDate>,
  |                   ^^^^^^^^^^^^^^^^^ the trait `FromForm<'r>` is not implemented for `std::option::Option<NaiveDate>`
  |
  = help: the trait `FromForm<'v>` is implemented for `std::option::Option<T>`

error[E0277]: the trait bound `std::option::Option<NaiveDate>: FromForm<'r>` is not satisfied
 --> src/model/request/history_request.rs:7:9
  |
7 |     pub end_date: Option<NaiveDate>,
  |         ^^^^^^^^^^^^^^^^ the trait `FromForm<'r>` is not implemented for `std::option::Option<NaiveDate>`
  |
  = help: the trait `FromForm<'v>` is implemented for `std::option::Option<T>

error: internal compiler error: compiler/rustc_infer/src/infer/at.rs:364:21: relating different kinds: (?47t,) 'r/#0
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
error: internal compiler error: compiler/rustc_infer/src/infer/at.rs:364:21: relating different kinds: (?47t,) 'r/#0

thread 'rustc' panicked at compiler/rustc_infer/src/infer/at.rs:364:21:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_middle::ty::generic_args::GenericArg as rustc_infer::infer::at::ToTrace>::to_trace
   7: <rustc_infer::infer::at::At>::eq::<rustc_middle::ty::generic_args::GenericArg>
   8: <rustc_infer::infer::InferCtxt>::enter_forall::<rustc_type_ir::predicate::TraitPredicate<rustc_middle::ty::context::TyCtxt>, (), <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt>::note_function_argument_obligation<rustc_span::ErrorGuaranteed>::{closure#1}>
   9: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt>::note_function_argument_obligation::<rustc_span::ErrorGuaranteed>
  10: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt>::note_obligation_cause_code::<rustc_span::ErrorGuaranteed, rustc_middle::ty::predicate::Predicate>
  11: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::note_obligation_cause
  12: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_selection_error
  13: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::report_fulfillment_error
  14: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_fulfillment_errors
  15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_method_argument_types
  16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  18: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  19: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  20: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  21: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_match::{closure#0}
  22: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_decl
  24: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
  25: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26: rustc_hir_typeck::check::check_fn
  27: rustc_hir_typeck::typeck
      [... omitted 1 frame ...]
  28: rustc_hir_analysis::check_crate
  29: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  30: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.80.1 (3f5fd8dd4 2024-08-06) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck] type-checking `model::request::history_request::_::<impl at src/model/request/history_request.rs:4:10: 4:18>::finalize`
#1 [analysis] running analysis passes on this crate
end of query stack
```

</p>
</details>

### Cargo.toml dependencies
```toml
[dependencies]
diesel = { version = "2.2.1", features = ["postgres", "r2d2", "chrono"] }
prometheus = "0.13.4"
rocket_prometheus = "0.10.1"
rocket = { version = "0.5.0", features = ["json"] }
serde = "1.0.203"
rocket_sync_db_pools = { version = "0.1.0", features = ["diesel_postgres_pool"] }
async-std = "1.12.0"
rocket_okapi = { version = "0.8.0", features = ["rapidoc"] }
schemars = { version = "0.8.21", features = ["chrono"] }
rocket_oauth2 = "0.5.0"
chrono = { version = "0.4.38", features = ["serde"] }
rand = "0.8.5"
bcrypt = "0.15.1"
reqwest = { version = "0.12.5", features = ["json"] }
validator = { version = "0.18.1", features = ["derive"] }
lazy_static = "1.5.0"
regex = "1.10.5"
uuid = { version = "1.10.0", features = ["v4", "serde"] }
rust-argon2 = "2.1.0"
strum = "0.26.3"
strum_macros = "0.26.4"
```