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

ICE on FnOnce #2953

Open
P-E-P opened this issue Apr 19, 2024 · 0 comments
Open

ICE on FnOnce #2953

P-E-P opened this issue Apr 19, 2024 · 0 comments

Comments

@P-E-P
Copy link
Member

P-E-P commented Apr 19, 2024

The provided code gives an ICE

Code

#[lang = "sized"]
pub trait Sized {
    // Empty.
}

#[lang = "fn_once"]
pub trait FnOnce<Args> {
    /// The returned type after the call operator is used.
    #[lang = "fn_once_output"]
    type Output;

    /// Performs the call operation.
    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}

pub enum Ordering {
    /// An ordering where a compared value is less than another.
    Less = -1,
    /// An ordering where a compared value is equal to another.
    Equal = 0,
    /// An ordering where a compared value is greater than another.
    Greater = 1,
}

pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
    match compare(&v1, &v2) {
        Ordering::Less | Ordering::Equal => v2,
        Ordering::Greater => v1,
    }
}

pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
    match compare(&v1, &v2) {
        Ordering::Less | Ordering::Equal => v1,
        Ordering::Greater => v2,
    }
}

https://godbolt.org/z/4Gjbbd4dK

Meta

Error output

crab1: internal compiler error: in TyVar, at rust/typecheck/rust-tyty-util.cc:31
Backtrace

crab1: internal compiler error: in TyVar, at rust/typecheck/rust-tyty-util.cc:31
0x1574d65 Rust::TyTy::TyVar::TyVar(unsigned int)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-tyty-util.cc:31
0x155897a Rust::TyTy::PlaceholderType::resolve() const
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-tyty.cc:3561
0x155784e Rust::TyTy::BaseType::destructure() const
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-tyty.cc:538
0x155a534 Rust::TyTy::BaseType::needs_generic_substitutions() const
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-tyty.cc:831
0x155f5fa Rust::TyTy::FnType::handle_substitions(Rust::TyTy::SubstitutionArgumentMappings&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-tyty.cc:2018
0x161fa00 Rust::Resolver::SubstMapperInternal::visit(Rust::TyTy::FnType&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-substitution-mapper.cc:198
0x155e91d Rust::TyTy::FnType::accept_vis(Rust::TyTy::TyVisitor&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-tyty.cc:1879
0x161f7d1 Rust::Resolver::SubstMapperInternal::Resolve(Rust::TyTy::BaseType*, Rust::TyTy::SubstitutionArgumentMappings&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-substitution-mapper.cc:146
0x15a151a Rust::TyTy::TypeBoundPredicateItem::get_tyty_for_receiver(Rust::TyTy::BaseType const*)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-tyty-bounds.cc:600
0x1603c6e Rust::Resolver::MethodResolver::get_predicate_items(Rust::HIR::PathIdentSegment const&, Rust::TyTy::BaseType const&, std::vector<Rust::TyTy::TypeBoundPredicate, std::allocator<Rust::TyTy::TypeBoundPredicate> > const&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-dot-operator.cc:472
0x1603ab2 Rust::Resolver::MethodResolver::try_hook(Rust::TyTy::BaseType const&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-dot-operator.cc:89
0x161ebc7 Rust::Resolver::AutoderefCycle::try_autoderefed(Rust::TyTy::BaseType*)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-autoderef.cc:421
0x161e77a Rust::Resolver::AutoderefCycle::cycle(Rust::TyTy::BaseType*)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-autoderef.cc:330
0x16037aa Rust::Resolver::MethodResolver::Probe(Rust::TyTy::BaseType*, Rust::HIR::PathIdentSegment const&, bool)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-dot-operator.cc:40
0x15cd048 Rust::Resolver::TypeCheckExpr::resolve_fn_trait_call(Rust::HIR::CallExpr&, Rust::TyTy::BaseType*, Rust::TyTy::BaseType**)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:1896
0x15ccef9 Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::CallExpr&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:217
0x14429f0 Rust::HIR::CallExpr::accept_vis(Rust::HIR::HIRExpressionVisitor&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/hir/tree/rust-hir.cc:4831
0x15cc3c9 Rust::Resolver::TypeCheckExpr::Resolve(Rust::HIR::Expr*)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:42
0x15d4726 Rust::Resolver::TypeCheckExpr::visit(Rust::HIR::MatchExpr&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/typecheck/rust-hir-type-check-expr.cc:1469
0x14428a0 Rust::HIR::MatchExpr::accept_vis(Rust::HIR::HIRExpressionVisitor&)
  /home/patryp/Documents/gccrs/build/gcc/../../gcc/rust/hir/tree/rust-hir.cc:4789
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants