rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.55k stars 12.74k forks source link

The same code, one errors the other passes fine <Rocket> #105042

Open hannydevelop opened 1 year ago

hannydevelop commented 1 year ago

Code

I have the same code, one runs the other returns an error. Here's the code that returns an error below:

// Post request to create an invoice.
#[post("/", format = "json", data = "<invoice>")]
async fn invoice(invoice: Json<Invoice>) {
    // let content = invoice.into_inner();
    let hub = Sheets::new(
        hyper::Client::builder().build(hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_or_http().enable_http1().enable_http2().build()), 
        authenticate().await);

    let invoice = invoice.into_inner();

    let req = ValueRange {
        major_dimension: None,
        range: None,
        values: Some(vec![vec![invoice.invoice_number, invoice.date, invoice.description, invoice.due_date, invoice.recurring, invoice.unit_cost, invoice.qty, invoice.amount, invoice.receiver_address, invoice.paid]]),
    };

    let result = hub.spreadsheets().values_append(req, "1AziHoTYgpvsDLsdZ_28UjgypYWLWKCFfcLPUzLEXcaY", "A:Z")
             .value_input_option("USER_ENTERED")
             .doit().await;

    match result {
        Err(e) => match e {
            // The Error enum provides details about what exactly happened.
            // You can also just use its `Debug`, `Display` or `Error` traits
            sError::HttpError(_)
            | sError::Io(_)
            | sError::MissingAPIKey
            | sError::MissingToken(_)
            | sError::Cancelled
            | sError::UploadSizeLimitExceeded(_, _)
            | sError::Failure(_)
            | sError::BadRequest(_)
            | sError::FieldClash(_)
            | sError::JsonDecodeError(_, _) => println!("{}", e),
        },
        Ok(res) => println!("file:{:?} was copied successfully", res),
    }
}

Here's the one that passes:

// Post request to create an invoice.
#[post("/", format = "json", data = "<invoice>")]
 async fn invoice(invoice: Json<Invoice>) {
     // let content = invoice.into_inner();
     let hub = Sheets::new(
         hyper::Client::builder().build(hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_or_http().enable_http1().enable_http2().build()), 
         authenticate().await);

         let invoice = invoice.into_inner();

         let req = ValueRange {
             major_dimension: None,
             range: None,
             values: Some(vec![vec![invoice.invoice_number, invoice.date, invoice.description, invoice.due_date, invoice.recurring, invoice.unit_cost, invoice.qty, invoice.amount, invoice.receiver_address, invoice.paid]]),
         };

     // write into spreadsheet
     let result = hub.spreadsheets().values_append(req, "1AziHoTYgpvsDLsdZ_28UjgypYWLWKCFfcLPUzLEXcaY", "A:Z")
     .value_input_option("USER_ENTERED")
     .doit().await;

     match result {
         Err(e) => match e {
             // The Error enum provides details about what exactly happened.
             // You can also just use its `Debug`, `Display` or `Error` traits
             sError::HttpError(_)
             | sError::Io(_)
             | sError::MissingAPIKey
             | sError::MissingToken(_)
             | sError::Cancelled
             | sError::UploadSizeLimitExceeded(_, _)
             | sError::Failure(_)
             | sError::BadRequest(_)
             | sError::FieldClash(_)
             | sError::JsonDecodeError(_, _) => println!("{}", e),
         },
         Ok(res) => println!("file:{:?} was copied successfully", res),
     }
 }

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (42325c525 2022-11-11) running on aarch64-apple-darwin

Error output

{ var: 422, kind: BrAnon(422, None) }), ReLateBound(DebruijnIndex(1), BoundRegion { var: 421, kind: BrAnon(421, None) })), []), BoringNoLocation), (Binder(OutlivesPredicate(ReLateBound(DebruijnIndex(1), BoundRegion { var: 440, kind: BrAnon(440, None) }), ReLateBound(DebruijnIndex(1), BoundRegion { var: 439, kind: BrAnon(439, None) })), []), BoringNoLocation), (Binder(OutlivesPredicate(ReLateBound(DebruijnIndex(1), BoundRegion { var: 438, kind: BrAnon(438, None) }), ReLateBound(DebruijnIndex(1), BoundRegion { var: 437, kind: BrAnon(437, None) })), []), BoringNoLocation), (Binder(OutlivesPredicate(impl std::future::Future<Output = rocket::outcome::Outcome<rocket::Response<'_>, rocket::http::Status, rocket::Data<'_>>>, ReLateBound(DebruijnIndex(1), BoundRegion { var: 5, kind: BrAnon(5, None) })), []), BoringNoLocation), (Binder(OutlivesPredicate(bytes::bytes::Vtable, ReLateBound(DebruijnIndex(1), BoundRegion { var: 12, kind: BrAnon(12, None) })), []), BoringNoLocation)], member_constraints: [] }, certainty: Proven, opaque_types: [], value: () } })', compiler/rustc_query_system/src/query/plumbing.rs:664:9
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: rustc_query_system::query::plumbing::incremental_verify_ich_failed
   3: rustc_query_system::query::plumbing::incremental_verify_ich::<rustc_query_impl::plumbing::QueryCtxt, rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ProvePredicate>>, core::result::Result<&rustc_middle::infer::canonical::Canonical<rustc_middle::infer::canonical::QueryResponse<()>>, rustc_middle::traits::query::NoSolution>>
   4: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl::plumbing::QueryCtxt, rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ProvePredicate>>, core::result::Result<&rustc_middle::infer::canonical::Canonical<rustc_middle::infer::canonical::QueryResponse<()>>, rustc_middle::traits::query::NoSolution>>
   5: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ProvePredicate>>, core::result::Result<&rustc_middle::infer::canonical::Canonical<rustc_middle::infer::canonical::QueryResponse<()>>, rustc_middle::traits::query::NoSolution>>>
   6: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::type_op_prove_predicate, rustc_query_impl::plumbing::QueryCtxt>
   7: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_op_prove_predicate
   8: <rustc_middle::traits::query::type_op::ProvePredicate as rustc_trait_selection::traits::query::type_op::QueryTypeOp>::perform_query
   9: <rustc_middle::traits::query::type_op::ProvePredicate as rustc_trait_selection::traits::query::type_op::QueryTypeOp>::fully_perform_into
  10: <rustc_middle::ty::ParamEnvAnd<rustc_middle::traits::query::type_op::ProvePredicate> as rustc_trait_selection::traits::query::type_op::TypeOp>::fully_perform
  11: <rustc_borrowck::type_check::TypeChecker>::prove_predicate
  12: <rustc_borrowck::type_check::TypeChecker>::prove_trait_ref
  13: <rustc_borrowck::type_check::TypeChecker>::check_rvalue
  14: <rustc_borrowck::type_check::TypeChecker>::typeck_mir
  15: rustc_borrowck::type_check::type_check
  16: rustc_borrowck::nll::compute_regions
  17: rustc_borrowck::do_mir_borrowck
  18: rustc_borrowck::mir_borrowck
  19: <rustc_borrowck::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
  20: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::mir::query::BorrowCheckResult>
  21: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::mir::query::BorrowCheckResult>>
  22: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::mir_borrowck, rustc_query_impl::plumbing::QueryCtxt>
  23: <rustc_middle::ty::context::TyCtxt>::mir_borrowck_opt_const_arg
  24: rustc_mir_transform::mir_drops_elaborated_and_const_checked
  25: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::with_deps::<<rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task_impl<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::WithOptConstParam<rustc_span::def_id::LocalDefId>, &rustc_data_structures::steal::Steal<rustc_middle::mir::Body>>::{closure#0}, &rustc_data_structures::steal::Steal<rustc_middle::mir::Body>>
  26: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::WithOptConstParam<rustc_span::def_id::LocalDefId>, &rustc_data_structures::steal::Steal<rustc_middle::mir::Body>>
  27: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::WithOptConstParam<rustc_span::def_id::LocalDefId>, &rustc_data_structures::steal::Steal<rustc_middle::mir::Body>>>
  28: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::mir_drops_elaborated_and_const_checked, rustc_query_impl::plumbing::QueryCtxt>
  29: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_drops_elaborated_and_const_checked
  30: rustc_mir_transform::optimized_mir
  31: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::DefId, &rustc_middle::mir::Body>
  32: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::DefId, &rustc_middle::mir::Body>>
  33: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::optimized_mir, rustc_query_impl::plumbing::QueryCtxt>
  34: <rustc_middle::ty::context::TyCtxt>::instance_mir
  35: rustc_monomorphize::collector::collect_neighbours
  36: rustc_monomorphize::collector::collect_items_rec
  37: rustc_monomorphize::collector::collect_items_rec
  38: rustc_monomorphize::collector::collect_items_rec
  39: rustc_monomorphize::collector::collect_items_rec
  40: rustc_monomorphize::collector::collect_items_rec
  41: rustc_monomorphize::collector::collect_items_rec
  42: rustc_monomorphize::collector::collect_items_rec
  43: rustc_monomorphize::collector::collect_items_rec
  44: rustc_monomorphize::collector::collect_items_rec
  45: rustc_monomorphize::collector::collect_items_rec
  46: rustc_monomorphize::collector::collect_items_rec
  47: rustc_monomorphize::collector::collect_items_rec
  48: rustc_monomorphize::collector::collect_items_rec
  49: rustc_monomorphize::collector::collect_items_rec
  50: rustc_monomorphize::collector::collect_items_rec
  51: <core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::par_for_each_in<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
  52: std::panicking::try::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::par_for_each_in<alloc::vec::Vec<rustc_middle::mir::mono::MonoItem>, rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>
  53: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  54: rustc_monomorphize::collector::collect_crate_mono_items
  55: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  56: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>
  57: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>>
  58: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_and_partition_mono_items, rustc_query_impl::plumbing::QueryCtxt>
  59: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  60: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  61: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  62: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  63: rustc_interface::passes::start_codegen
  64: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorGuaranteed>>
  65: <rustc_interface::queries::Queries>::ongoing_codegen
  66: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  67: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

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.67.0-nightly (42325c525 2022-11-11) running on aarch64-apple-darwin

note: compiler flags: --crate-type bin -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [type_op_prove_predicate] evaluating `type_op_prove_predicate` `ProvePredicate { predicate: Binder(TraitPredicate(<core::pin::Pin<alloc::boxed::Box<impl core::future::future::Future<Output = rocket::outcome::Outcome<rocket::response::response::Response<'_>, rocket_http::status::Status, rocket::data::data::Data<'_>>>>> as core::ops::unsize::CoerceUnsized<core::pin::Pin<alloc::boxed::Box<dyn core::future::future::Future<Output = rocket::outcome::Outcome<rocket::response::response::Response<'a>, rocket_http::status::Status, rocket::data::data::Data<'b>>> + core::marker::Send>>>>, polarity:Positive), []) }`
#1 [mir_borrowck] borrow-checking `<impl at src/main.rs:75:1: 75:50>::into_info::monomorphized_function`
#2 [mir_drops_elaborated_and_const_checked] elaborating drops for `<impl at src/main.rs:75:1: 75:50>::into_info::monomorphized_function`
#3 [optimized_mir] optimizing MIR for `<impl at src/main.rs:75:1: 75:50>::into_info::monomorphized_function`
#4 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
Backtrace

``` stack backtrace: 0: _rust_begin_unwind 1: core::panicking::panic_fmt 2: rustc_query_system::query::plumbing::incremental_verify_ich_failed 3: rustc_query_system::query::plumbing::incremental_verify_ich::>, core::result::Result<&rustc_middle::infer::canonical::Canonical>, rustc_middle::traits::query::NoSolution>> 4: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory::>, core::result::Result<&rustc_middle::infer::canonical::Canonical>, rustc_middle::traits::query::NoSolution>> 5: rustc_query_system::query::plumbing::try_execute_query::>, core::result::Result<&rustc_middle::infer::canonical::Canonical>, rustc_middle::traits::query::NoSolution>>> 6: rustc_query_system::query::plumbing::get_query:: 7: ::type_op_prove_predicate 8: ::perform_query 9: ::fully_perform_into 10: as rustc_trait_selection::traits::query::type_op::TypeOp>::fully_perform 11: ::prove_predicate 12: ::prove_trait_ref 13: ::check_rvalue 14: ::typeck_mir 15: rustc_borrowck::type_check::type_check 16: rustc_borrowck::nll::compute_regions 17: rustc_borrowck::do_mir_borrowck 18: rustc_borrowck::mir_borrowck 19: >::call_once 20: >::with_task:: 21: rustc_query_system::query::plumbing::try_execute_query::> 22: rustc_query_system::query::plumbing::get_query:: 23: ::time::<(), rustc_interface::passes::analysis::{closure#2}> 24: rustc_interface::passes::analysis 25: >::with_task::> 26: rustc_query_system::query::plumbing::try_execute_query::>> 27: rustc_query_system::query::plumbing::get_query:: 28: ::enter::> 29: rustc_span::with_source_map::, rustc_interface::interface::run_compiler, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#1}> 30: >::set::, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>> note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: internal compiler error: unexpected panic note: the compiler unexpectedly panicked. this is a bug. 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.67.0-nightly (42325c525 2022-11-11) running on aarch64-apple-darwin note: compiler flags: --crate-type bin -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental=[REDACTED] note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [type_op_prove_predicate] evaluating `type_op_prove_predicate` `ProvePredicate { predicate: Binder(TraitPredicate(, rocket_http::status::Status, rocket::data::data::Data<'_>>>>> as core::ops::unsize::CoerceUnsized, rocket_http::status::Status, rocket::data::data::Data<'b>>> + core::marker::Send>>>>, polarity:Positive), []) }` #1 [mir_borrowck] borrow-checking `::into_info::monomorphized_function` #2 [analysis] running analysis passes on this crate end of query stack ```

hannydevelop commented 1 year ago

oof! turns out this has to do with encoding. I believe I held down the shift + space bar button. This effect created a whitespace with weird encoding.

STEPS TO REPRODUCE Hold down the shift + space bar button anywhere in the code that works. Run or build code, it'll throw an error.

jieyouxu commented 8 months ago

oof! turns out this has to do with encoding. I believe I held down the shift + space bar button. This effect created a whitespace with weird encoding.

STEPS TO REPRODUCE Hold down the shift + space bar button anywhere in the code that works. Run or build code, it'll throw an error.

Hi, does this still crash for you in latest stable?