Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
877c5e9
[BETA] Update cargo
ehuss Mar 15, 2019
b72af83
Include bounds from promoted constants in NLL
matthewjasper Jan 17, 2019
1824067
Remove unnecessary parameter
matthewjasper Jan 17, 2019
e2a0a83
Handle type annotations in promoted MIR correctly
matthewjasper Feb 27, 2019
11bd998
Temporarily emulate the (accidentally) omitted recursion during impl …
pnkfelix Feb 20, 2019
a35c8e8
Unit (and regression) tests for warning cycle code.
pnkfelix Feb 22, 2019
1d6d40b
Revised warning-downgrade strategy for nested impl trait.
pnkfelix Mar 11, 2019
7f31bab
Test illustrating that the nested_impl_trait lint should only catch s…
pnkfelix Mar 11, 2019
8df3fb6
Addressed review feedback regarding comment phrasing.
pnkfelix Mar 12, 2019
4e1c03b
Don't promote function calls to nonpromotable things
oli-obk Feb 27, 2019
eedebbc
Schedule the demolition of `IsNotPromotable`
oli-obk Mar 1, 2019
ad293f1
Make migrate mode work at item level granularity
matthewjasper Feb 27, 2019
363024d
Expand where negative supertrait specific error is shown
estebank Mar 1, 2019
d954246
Do not panic on missing close paren
estebank Mar 2, 2019
8470916
Bail when encountering a second unexpected token in the same span
estebank Mar 2, 2019
d60f22c
Emit unclosed delimiters during recovery
estebank Mar 2, 2019
a5c464a
Reduce test case
estebank Mar 2, 2019
d5b3606
Panic when unmatched delimiters aren't emitted
estebank Mar 3, 2019
d21b852
Emit missing unclosed delimiter errors
estebank Mar 3, 2019
a460b4b
Collect unclosed delimiters in parent parser
estebank Mar 3, 2019
51c47f3
Always emit mismatched delim errors, never panic
estebank Mar 3, 2019
e808e1e
Add regression test for #58886
estebank Mar 4, 2019
78554ed
Simplify code
estebank Mar 4, 2019
159cc95
Rely on drop to emit unclosed delims
estebank Mar 7, 2019
0e9e6ec
Rollup merge of #59217 - ehuss:update-beta-cargo, r=alexcrichton
pietroalbini Mar 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Emit missing unclosed delimiter errors
  • Loading branch information
estebank authored and pietroalbini committed Mar 16, 2019
commit d21b8522ea06699d6037432adef4df5f1d66bbbb
4 changes: 2 additions & 2 deletions src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ impl cstore::CStore {

let source_file = sess.parse_sess.source_map().new_source_file(source_name, def.body);
let local_span = Span::new(source_file.start_pos, source_file.end_pos, NO_EXPANSION);
let (body, errors) = source_file_to_stream(&sess.parse_sess, source_file, None);
emit_unclosed_delims(&errors, &sess.diagnostic());
let (body, mut errors) = source_file_to_stream(&sess.parse_sess, source_file, None);
emit_unclosed_delims(&mut errors, &sess.diagnostic());

// Mark the attrs as used
let attrs = data.get_item_attrs(id.index, sess);
Expand Down
14 changes: 9 additions & 5 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7785,7 +7785,10 @@ impl<'a> Parser<'a> {
attributes_allowed: bool,
) -> PResult<'a, Option<P<Item>>> {
let (ret, tokens) = self.collect_tokens(|this| {
this.parse_item_implementation(attrs, macros_allowed, attributes_allowed)
let item = this.parse_item_implementation(attrs, macros_allowed, attributes_allowed);
let diag = this.diagnostic();
emit_unclosed_delims(&mut this.unclosed_delims, diag);
item
})?;

// Once we've parsed an item and recorded the tokens we got while
Expand Down Expand Up @@ -8532,8 +8535,8 @@ impl<'a> Parser<'a> {
module: self.parse_mod_items(&token::Eof, lo)?,
span: lo.to(self.span),
});
emit_unclosed_delims(&self.unclosed_delims, self.diagnostic());
self.unclosed_delims.clear();
let diag = self.diagnostic();
emit_unclosed_delims(&mut self.unclosed_delims, diag);
krate
}

Expand Down Expand Up @@ -8564,8 +8567,8 @@ impl<'a> Parser<'a> {
}
}

pub fn emit_unclosed_delims(unclosed_delims: &[UnmatchedBrace], handler: &errors::Handler) {
for unmatched in unclosed_delims {
pub fn emit_unclosed_delims(unclosed_delims: &mut Vec<UnmatchedBrace>, handler: &errors::Handler) {
for unmatched in unclosed_delims.iter() {
let mut err = handler.struct_span_err(unmatched.found_span, &format!(
"incorrect close delimiter: `{}`",
pprust::token_to_string(&token::Token::CloseDelim(unmatched.found_delim)),
Expand All @@ -8579,4 +8582,5 @@ pub fn emit_unclosed_delims(unclosed_delims: &[UnmatchedBrace], handler: &errors
}
err.emit();
}
unclosed_delims.clear();
}
12 changes: 6 additions & 6 deletions src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,9 @@ impl Nonterminal {
// FIXME(#43081): Avoid this pretty-print + reparse hack
let source = pprust::nonterminal_to_string(self);
let filename = FileName::macro_expansion_source_code(&source);
let (tokens_for_real, errors) =
let (tokens_for_real, mut errors) =
parse_stream_from_source_str(filename, source, sess, Some(span));
emit_unclosed_delims(&errors, &sess.span_diagnostic);
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);

// During early phases of the compiler the AST could get modified
// directly (e.g., attributes added or removed) and the internal cache
Expand Down Expand Up @@ -740,13 +740,13 @@ fn prepend_attrs(sess: &ParseSess,
let source = pprust::attr_to_string(attr);
let macro_filename = FileName::macro_expansion_source_code(&source);
if attr.is_sugared_doc {
let (stream, errors) = parse_stream_from_source_str(
let (stream, mut errors) = parse_stream_from_source_str(
macro_filename,
source,
sess,
Some(span),
);
emit_unclosed_delims(&errors, &sess.span_diagnostic);
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
builder.push(stream);
continue
}
Expand All @@ -763,13 +763,13 @@ fn prepend_attrs(sess: &ParseSess,
// ... and for more complicated paths, fall back to a reparse hack that
// should eventually be removed.
} else {
let (stream, errors) = parse_stream_from_source_str(
let (stream, mut errors) = parse_stream_from_source_str(
macro_filename,
source,
sess,
Some(span),
);
emit_unclosed_delims(&errors, &sess.span_diagnostic);
emit_unclosed_delims(&mut errors, &sess.span_diagnostic);
brackets.push(stream);
}

Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_ext/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ impl server::TokenStream for Rustc<'_> {
stream.is_empty()
}
fn from_str(&mut self, src: &str) -> Self::TokenStream {
let (tokens, errors) = parse::parse_stream_from_source_str(
let (tokens, mut errors) = parse::parse_stream_from_source_str(
FileName::proc_macro_source_code(src.clone()),
src.to_string(),
self.sess,
Some(self.call_site),
);
emit_unclosed_delims(&errors, &self.sess.span_diagnostic);
emit_unclosed_delims(&mut errors, &self.sess.span_diagnostic);
tokens
}
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/parser-recovery-2.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
error: unexpected token: `;`
--> $DIR/parser-recovery-2.rs:12:15
|
LL | let x = y.; //~ ERROR unexpected token
| ^

error: incorrect close delimiter: `)`
--> $DIR/parser-recovery-2.rs:8:5
|
Expand All @@ -13,6 +7,12 @@ LL | let x = foo(); //~ ERROR cannot find function `foo` in this scope
LL | ) //~ ERROR incorrect close delimiter: `)`
| ^ incorrect close delimiter

error: unexpected token: `;`
--> $DIR/parser-recovery-2.rs:12:15
|
LL | let x = y.; //~ ERROR unexpected token
| ^

error[E0425]: cannot find function `foo` in this scope
--> $DIR/parser-recovery-2.rs:7:17
|
Expand Down
16 changes: 7 additions & 9 deletions src/test/ui/resolve/token-error-correct-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ pub mod raw {
pub fn ensure_dir_exists<P: AsRef<Path>, F: FnOnce(&Path)>(path: P,
callback: F)
-> io::Result<bool> {
if !is_directory(path.as_ref()) { //~ ERROR: cannot find function `is_directory`
callback(path.as_ref(); //~ ERROR expected one of
fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
//~^ expected (), found enum `std::result::Result`
//~| expected type `()`
//~| found type `std::result::Result<bool, std::io::Error>`
//~| expected one of
if !is_directory(path.as_ref()) {
//~^ ERROR cannot find function `is_directory`
callback(path.as_ref();
//~^ ERROR expected one of
//~| ERROR this function takes 1 parameter but 2 parameters were supplied
fs::create_dir_all(path.as_ref()).map(|()| true)
} else {
//~^ ERROR: expected one of
//~| unexpected token
//~^ ERROR incorrect close delimiter: `}`
Ok(false);
}

Expand Down
49 changes: 24 additions & 25 deletions src/test/ui/resolve/token-error-correct-3.stderr
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> $DIR/token-error-correct-3.rs:14:35
|
LL | callback(path.as_ref(); //~ ERROR expected one of
| - ^
| | |
| | help: `)` may belong here
| unclosed delimiter

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
--> $DIR/token-error-correct-3.rs:20:9
error: incorrect close delimiter: `}`
--> $DIR/token-error-correct-3.rs:19:9
|
LL | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
| - expected one of `.`, `;`, `?`, `}`, or an operator here
LL | if !is_directory(path.as_ref()) {
| - close delimiter possibly meant for this
LL | //~^ ERROR cannot find function `is_directory`
LL | callback(path.as_ref();
| - un-closed delimiter
...
LL | } else {
| ^ unexpected token
| ^ incorrect close delimiter

error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> $DIR/token-error-correct-3.rs:15:35
|
LL | callback(path.as_ref();
| ^ expected one of `)`, `,`, `.`, `?`, or an operator here

error[E0425]: cannot find function `is_directory` in this scope
--> $DIR/token-error-correct-3.rs:13:13
|
LL | if !is_directory(path.as_ref()) { //~ ERROR: cannot find function `is_directory`
LL | if !is_directory(path.as_ref()) {
| ^^^^^^^^^^^^ not found in this scope

error[E0308]: mismatched types
error[E0057]: this function takes 1 parameter but 2 parameters were supplied
--> $DIR/token-error-correct-3.rs:15:13
|
LL | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
| |
| expected (), found enum `std::result::Result`
|
= note: expected type `()`
found type `std::result::Result<bool, std::io::Error>`
LL | / callback(path.as_ref();
LL | | //~^ ERROR expected one of
LL | | //~| ERROR this function takes 1 parameter but 2 parameters were supplied
LL | | fs::create_dir_all(path.as_ref()).map(|()| true)
LL | | } else {
| |_________^ expected 1 parameter

error: aborting due to 4 previous errors

Some errors occurred: E0308, E0425.
For more information about an error, try `rustc --explain E0308`.
Some errors occurred: E0057, E0425.
For more information about an error, try `rustc --explain E0057`.