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

rustc produced incorrect error if code contains syntax errors #61329

Closed
qwerty19106 opened this issue May 29, 2019 · 0 comments · Fixed by #64192
Closed

rustc produced incorrect error if code contains syntax errors #61329

qwerty19106 opened this issue May 29, 2019 · 0 comments · Fixed by #64192
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST

Comments

@qwerty19106
Copy link

qwerty19106 commented May 29, 2019

The some code:

#![feature(arbitrary_self_types)]
#![feature(maybe_uninit_extra)]
#![feature(maybe_uninit_ref)]

use core::cell::UnsafeCell;
use core::mem::MaybeUninit;

#[repr(transparent)]
pub struct Uninit<T>(MaybeUninit<UnsafeCell<T>>);

impl<T> Uninit<T> {
    pub const fn new() -> Self {
        Self(MaybeUninit::uninit())
    }

    /// Init value and return owned pointer
    pub fn init(&mut self, value: T) -> OsBox<T> {
        unsafe {
            // Error, true line:
            // let inner: &mut MaybeUninit<UnsafeCell<T>> = &mut self.0;
            let inner: &mut MaybeUninit<UnsafeCell<T> = &mut self.0;
            
            inner.write(UnsafeCell::new(value));
            
            // Error, true line:
            // OsBox::new_unchecked(inner.get_mut().get())
            OsBox::new_unchecked((inner.get_mut().get())
        }
    }
}

fn main() {
}

The code contains two syntax error (see above):

  • not enough closing >
  • extra opening (

All { and } delimiters is true.

It give many error, the first:

error: incorrect close delimiter: `}`
  --> src/main.rs:28:9
   |
18 |         unsafe {
   |                - close delimiter possibly meant for this
...
27 |             OsBox::new_unchecked((inner.get_mut().get())
   |                                 - un-closed delimiter
28 |         }
   |         ^ incorrect close delimiter

Playground version: rustc 1.37.0-nightly (2019-05-29 37d001e)

playground

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST labels May 29, 2019
@bors bors closed this as completed in fae7bc7 Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants