Auto merge of #33333 - birkenfeld:issue-30318, r=Manishearth

parser: show a helpful note on unexpected inner comment

Fixes: #30318.
This commit is contained in:
bors 2016-05-07 03:01:44 -07:00
commit 0d61bb3b49
2 changed files with 23 additions and 1 deletions

View File

@ -35,7 +35,10 @@ impl<'a> Parser<'a> {
self.span.hi
);
if attr.node.style != ast::AttrStyle::Outer {
return Err(self.fatal("expected outer comment"));
let mut err = self.fatal("expected outer doc comment");
err.note("inner doc comments like this (starting with \
`//!` or `/*!`) can only appear before items");
return Err(err);
}
attrs.push(attr);
self.bump();

View File

@ -0,0 +1,19 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -Z parse-only
fn foo() { }
//! Misplaced comment...
//~^ ERROR expected outer doc comment
//~| NOTE inner doc comments like this (starting with `//!` or `/*!`) can only appear before items
fn main() { }