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

Generic arguments are not disambiguated on error propagation expressions #3001

Closed
CohenArthur opened this issue May 14, 2024 · 0 comments · Fixed by #3163
Closed

Generic arguments are not disambiguated on error propagation expressions #3001

CohenArthur opened this issue May 14, 2024 · 0 comments · Fixed by #3163

Comments

@CohenArthur
Copy link
Member

CohenArthur commented May 14, 2024

I tried this code:

#[lang = "sized"]
trait Sized {}

enum Result<T, E> {
    Ok(T),
    Err(E),
}

pub struct Layout {
    // size of the requested block of memory, measured in bytes.
    size_: usize,
}

impl Layout {
    /// Constructs a `Layout` suitable for holding a value of type `T`.
    #[stable(feature = "alloc_layout", since = "1.28.0")]
    #[inline]
    pub const fn new<T>() -> Self {
        Layout { size_: 14 }
    }

    pub fn repeat(&self, n: usize) -> Result<(Self, usize), ()> {
        unsafe { Result::Ok((Layout { size_: 14 }, n + 12)) }
    }

    /// Creates a layout describing the record for a `[T; n]`.
    ///
    /// On arithmetic overflow, returns `LayoutErr`.
    #[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
    #[inline]
    pub fn array<T>(n: usize) -> Self {
        let (layout, offset) = Layout::new::<T>().repeat(n)?;

        layout
    }
}

fn main() {}

https://godbolt.org/z/he1WPf9G1

I expected to see this happen: no error

Instead, this happened:

crab1: internal compiler error: in lower_generic_args, at rust/hir/rust-ast-lower-base.cc:642
0x249d4f1 Rust::HIR::ASTLoweringBase::lower_generic_args(Rust::AST::GenericArgs&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-base.cc:642
0x249d039 Rust::HIR::ASTLoweringBase::lower_path_expr_seg(Rust::AST::PathExprSegment&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-base.cc:590
0x2496f93 Rust::HIR::ASTLowerPathInExpression::visit(Rust::AST::PathInExpression&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower.cc:413
0x228f4fd Rust::AST::PathInExpression::accept_vis(Rust::AST::ASTVisitor&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-path.cc:189
0x249fd5f Rust::HIR::ASTLowerPathInExpression::translate(Rust::AST::PathInExpression&)
	../../gcc/rust/hir/rust-ast-lower-expr.h:36
0x24b67d0 Rust::HIR::ASTLoweringExpr::visit(Rust::AST::PathInExpression&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-expr.cc:135
0x228f4fd Rust::AST::PathInExpression::accept_vis(Rust::AST::ASTVisitor&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-path.cc:189
0x24b6126 Rust::HIR::ASTLoweringExpr::translate(Rust::AST::Expr&, bool*)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-expr.cc:40
0x24b6a5b Rust::HIR::ASTLoweringExpr::visit(Rust::AST::CallExpr&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-expr.cc:165
0x21ae790 Rust::AST::CallExpr::accept_vis(Rust::AST::ASTVisitor&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-ast.cc:4479
0x24b6126 Rust::HIR::ASTLoweringExpr::translate(Rust::AST::Expr&, bool*)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-expr.cc:40
0x24b6cfd Rust::HIR::ASTLoweringExpr::visit(Rust::AST::MethodCallExpr&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-expr.cc:191
0x21ae7c0 Rust::AST::MethodCallExpr::accept_vis(Rust::AST::ASTVisitor&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-ast.cc:4485
0x24b6126 Rust::HIR::ASTLoweringExpr::translate(Rust::AST::Expr&, bool*)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-expr.cc:40
0x24b9ca5 Rust::HIR::ASTLoweringExpr::visit(Rust::AST::ErrorPropagationExpr&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-expr.cc:676
0x21ae3d0 Rust::AST::ErrorPropagationExpr::accept_vis(Rust::AST::ASTVisitor&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-ast.cc:4359
0x24b6126 Rust::HIR::ASTLoweringExpr::translate(Rust::AST::Expr&, bool*)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-expr.cc:40
0x24c3e2d Rust::HIR::ASTLoweringStmt::visit(Rust::AST::LetStmt&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-stmt.cc:75
0x21af460 Rust::AST::LetStmt::accept_vis(Rust::AST::ASTVisitor&)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/ast/rust-ast.cc:4851
0x24c3b43 Rust::HIR::ASTLoweringStmt::translate(Rust::AST::Stmt*, bool*)
	/home/kagounard/Git/rust-gcc/gccrs/build/gcc/../../gcc/rust/hir/rust-ast-lower-stmt.cc:32
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.

the ICE happens because lower_generic_args sees a GenericArg::Ambiguous and calls rust_unreachable. at this point in time, all generic args should have been disambiguated to a type or a const generic - but we don't do that disambiguation in error propagation expressions (<expr> ?)

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

Successfully merging a pull request may close this issue.

1 participant