Skip to content

Rust incorrectly accepts unbalanced parentheses #58886

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mjbshaw opened this issue Mar 3, 2019 · 2 comments
Closed

Rust incorrectly accepts unbalanced parentheses #58886

mjbshaw opened this issue Mar 3, 2019 · 2 comments
Assignees
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta.

Comments

@mjbshaw
Copy link
Contributor

mjbshaw commented Mar 3, 2019

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)

@estebank estebank self-assigned this Mar 3, 2019
@estebank
Copy link
Contributor

estebank commented Mar 3, 2019

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.

@estebank estebank added A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. P-high High priority labels Mar 3, 2019
@estebank estebank added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Mar 4, 2019
@dekellum
Copy link

dekellum commented Mar 5, 2019

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

estebank added a commit to estebank/rust that referenced this issue Mar 7, 2019
bors added a commit that referenced this issue Mar 8, 2019
Always emit unclosed delimiter diagnostics

Fix #58886.
pietroalbini pushed a commit to pietroalbini/rust that referenced this issue Mar 16, 2019
est31 added a commit to est31/mimas that referenced this issue Sep 3, 2020
There was a compiler bug [1] which made it accept code
with bad delimiters. I wrote commit [2] with a compiler
that included the bug and thus didn't notice the wrongly
placed delimiters. Therefore, on any non-buggy compilers,
the build is broken between that commit and this one.

This commit fixes this.

[1]: rust-lang/rust#58886
[2]: a9b4a2c "id_src actually isn't needed"
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug. P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Projects
None yet
Development

No branches or pull requests

3 participants