Skip to content

rustc produced incorrect error if code contains syntax errors #61329

Closed
@qwerty19106

Description

@qwerty19106

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions