Skip to content

Rust incorrectly accepts unbalanced parentheses #58886

Description

@mjbshaw

Rust incorrectly accepts the following code (which is missing a )):

pub struct Value {
}

pub fn new() -> Result<Value, ()> {
    Ok(Value {
    } // Look ma, no `)`!
}

So far this seems to only happen if the code is inside a submodule. Shell script to reproduce:

#!/bin/bash

cargo new --lib this_should_not_build
mkdir this_should_not_build/src/foo

cat >> this_should_not_build/src/lib.rs <<-'EOF'
    pub mod foo;
EOF

cat > this_should_not_build/src/foo/mod.rs <<-'EOF'
    pub struct Value {
    }

    pub fn new() -> Result<Value, ()> {
        Ok(Value {
        }
    }
EOF

cd this_should_not_build
cargo build

My compiler version: rustc 1.34.0-nightly (0ea22717a 2019-03-02)

Activity

  1. self-assigned this
    on Mar 3, 2019
  2. estebank commented on Mar 3, 2019

    @estebank
    Contributor

    Likely introduced in #57944. I'll take a look at it tomorrow. It's likely me forgetting to call emit_unclosed_delims in some scope.

  3. added
    A-parserArea: The lexing & parsing of Rust source code to an AST
    C-bugCategory: This is a bug.
    P-highHigh priority
    and removed on Mar 3, 2019
  4. dekellum commented on Mar 5, 2019

    @dekellum

    Thanks for reporting this and fixing, with tests! This can be a bit disconcerting if you dev on nightly, but target some stable (which will then fail to build): dekellum/body-image@dc78182b66

  5. added a commit that references this issue on Mar 8, 2019
    b58a006
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.P-highHigh priorityregression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions