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

Rollup of 16 pull requests #73939

Closed
wants to merge 47 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
144206e
Don't implement Fn* traits for #[target_feature] functions
calebzulawski Jun 13, 2020
c98b4c8
Add error note when trying fn as Fn trait
calebzulawski Jun 13, 2020
0d0865f
Make `rustc_peek` a safe intrinsic
oli-obk Jun 27, 2020
765bd47
Recover extra trailing angle brackets in struct definition
Aaron1011 Jun 27, 2020
8e899b1
Don't implement Fn* for unsafe #[target_feature] functions
calebzulawski Jun 27, 2020
7055c23
ast_pretty: Pass some token streams and trees by reference
petrochenkov Jun 24, 2020
14d0370
Remove defunct `-Z print-region-graph`
tmiasko Jun 28, 2020
e8f5785
Split and expand nonstandard-style lints unicode unit test.
crlf0710 Jun 28, 2020
824b2bb
Match on `Symbol` instead of `&str` for type-checking intrinsics.
oli-obk Jun 28, 2020
49c1018
Fix markdown rendering in librustc_lexer docs
pierwill Jun 28, 2020
4966272
Add newline to rustc MultiSpan docs
pierwill Jun 28, 2020
844dc31
ci: fix wasm32 broken due to a NodeJS version bump
pietroalbini Jun 30, 2020
f74a7d3
Clean up E0712 explanation
GuillaumeGomez Jun 30, 2020
8ee1dec
Deny unsafe ops in unsafe fns, part 1
LeSeulArtichaut Jun 21, 2020
8a515e9
Deny unsafe ops in unsafe fns, part 2
LeSeulArtichaut Jun 22, 2020
ac7539c
Deny unsafe ops in unsafe fns, part 3
LeSeulArtichaut Jun 24, 2020
c68f478
Deny unsafe ops in unsafe fns, part 4
LeSeulArtichaut Jun 25, 2020
c225e5c
Provide more information on duplicate lang item error.
ehuss Jun 17, 2020
b365233
Deny unsafe ops in unsafe fns, part 5
LeSeulArtichaut Jun 30, 2020
1b3ef66
Switch crate_extern_paths to a query, and tweak wording.
ehuss Jun 27, 2020
a1623ff
Deny unsafe ops in unsafe fns, part 6
LeSeulArtichaut Jun 30, 2020
0889d79
remove duplicate tests
lcnr Jun 30, 2020
6a7a652
Bless failing tests
LeSeulArtichaut Jun 30, 2020
e3cbb62
Rename TypeckTables to TypeckResults.
Lezzz Jun 4, 2020
51858da
Make #[target_feature] Fn trait error message less confusing
calebzulawski Jun 30, 2020
a5764de
expand: Stop using nonterminals for passing tokens to attribute and d…
petrochenkov Jun 14, 2020
b37434e
Remove `token::FlattenGroup`
petrochenkov Jul 1, 2020
5da0576
Insert NoDelim groups around nonterminals when lowering macro_rules
Aaron1011 Jun 21, 2020
c844028
Don't print additional spaces when pretty-printing NoDelim groups
Aaron1011 Jun 21, 2020
1ded7a5
Handle `None`-delimited groups when parsing `macro_rules!` macro
Aaron1011 Jun 29, 2020
eb4ba55
Add an issue number for the pretty_printing_compatibility_hack FIXME
petrochenkov Jul 1, 2020
6b34642
Rollup merge of #72983 - Lezzz:rename-typeck, r=nikomatsakis
Manishearth Jul 1, 2020
88e068b
Rollup merge of #73306 - calebzulawski:target-feature-11-fn-trait-sou…
Manishearth Jul 1, 2020
2071773
Rollup merge of #73345 - petrochenkov:nointerp, r=Aaron1011
Manishearth Jul 1, 2020
3cbcdc4
Rollup merge of #73449 - ehuss:duplicate-lang-item, r=matthewjasper
Manishearth Jul 1, 2020
6e57524
Rollup merge of #73569 - Aaron1011:fix/macro-rules-group, r=petrochenkov
Manishearth Jul 1, 2020
be11c3d
Rollup merge of #73622 - LeSeulArtichaut:unsafe-libcore, r=nikomatsakis
Manishearth Jul 1, 2020
f436a3a
Rollup merge of #73803 - Aaron1011:feature/angle-field-recovery, r=ma…
Manishearth Jul 1, 2020
127b3ba
Rollup merge of #73812 - petrochenkov:prettyref, r=varkor
Manishearth Jul 1, 2020
1b5696f
Rollup merge of #73834 - oli-obk:safe_intrinsics, r=ecstatic-morse
Manishearth Jul 1, 2020
d812bd9
Rollup merge of #73839 - crlf0710:snapshot_the_reality, r=Manishearth
Manishearth Jul 1, 2020
f01c218
Rollup merge of #73841 - tmiasko:print-region-graph, r=Mark-Simulacrum
Manishearth Jul 1, 2020
ee455a6
Rollup merge of #73848 - pierwill:pierwill-lexer-block-doc, r=jonas-s…
Manishearth Jul 1, 2020
f422af7
Rollup merge of #73853 - pierwill:pierwill-multispan-doc, r=jonas-sch…
Manishearth Jul 1, 2020
e663791
Rollup merge of #73885 - pietroalbini:ci-fix-wasm32, r=kennytm
Manishearth Jul 1, 2020
fe1f05c
Rollup merge of #73892 - GuillaumeGomez:cleanup-e0712, r=Dylan-DPC
Manishearth Jul 1, 2020
555397d
Rollup merge of #73898 - lcnr:issue61383, r=jonas-schievink
Manishearth Jul 1, 2020
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
Recover extra trailing angle brackets in struct definition
This commit applies the existing 'extra angle bracket recovery' logic
when parsing fields in struct definitions. This allows us to continue
parsing the struct's fields, avoiding spurious 'missing field' errors in
code that tries to use the struct.
  • Loading branch information
Aaron1011 committed Jun 27, 2020
commit 765bd47fa0f0e0d5d893283a94c76e2b1009d680
19 changes: 14 additions & 5 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -376,7 +376,14 @@ impl<'a> Parser<'a> {
/// let _ = vec![1, 2, 3].into_iter().collect::<Vec<usize>>>>();
/// ^^ help: remove extra angle brackets
/// ```
pub(super) fn check_trailing_angle_brackets(&mut self, segment: &PathSegment, end: TokenKind) {
///
/// If `true` is returned, then trailing brackets were recovered, tokens were consumed
/// up until one of the tokens in 'end' was encountered, and an error was emitted.
pub(super) fn check_trailing_angle_brackets(
&mut self,
segment: &PathSegment,
end: &[&TokenKind],
) -> bool {
// This function is intended to be invoked after parsing a path segment where there are two
// cases:
//
@@ -409,7 +416,7 @@ impl<'a> Parser<'a> {
parsed_angle_bracket_args,
);
if !parsed_angle_bracket_args {
return;
return false;
}

// Keep the span at the start so we can highlight the sequence of `>` characters to be
@@ -447,18 +454,18 @@ impl<'a> Parser<'a> {
number_of_gt, number_of_shr,
);
if number_of_gt < 1 && number_of_shr < 1 {
return;
return false;
}

// Finally, double check that we have our end token as otherwise this is the
// second case.
if self.look_ahead(position, |t| {
trace!("check_trailing_angle_brackets: t={:?}", t);
*t == end
end.contains(&&t.kind)
}) {
// Eat from where we started until the end token so that parsing can continue
// as if we didn't have those extra angle brackets.
self.eat_to_tokens(&[&end]);
self.eat_to_tokens(end);
let span = lo.until(self.token.span);

let total_num_of_gt = number_of_gt + number_of_shr * 2;
@@ -473,7 +480,9 @@ impl<'a> Parser<'a> {
Applicability::MachineApplicable,
)
.emit();
return true;
}
false
}

/// Check to see if a pair of chained operators looks like an attempt at chained comparison,
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
@@ -867,7 +867,7 @@ impl<'a> Parser<'a> {

let fn_span_lo = self.token.span;
let segment = self.parse_path_segment(PathStyle::Expr)?;
self.check_trailing_angle_brackets(&segment, token::OpenDelim(token::Paren));
self.check_trailing_angle_brackets(&segment, &[&token::OpenDelim(token::Paren)]);

if self.check(&token::OpenDelim(token::Paren)) {
// Method call `expr.f()`
29 changes: 28 additions & 1 deletion src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use rustc_ast::ast::{AssocItem, AssocItemKind, ForeignItemKind, Item, ItemKind,
use rustc_ast::ast::{Async, Const, Defaultness, IsAuto, Mutability, Unsafe, UseTree, UseTreeKind};
use rustc_ast::ast::{BindingMode, Block, FnDecl, FnSig, Param, SelfKind};
use rustc_ast::ast::{EnumDef, Generics, StructField, TraitRef, Ty, TyKind, Variant, VariantData};
use rustc_ast::ast::{FnHeader, ForeignItem, PathSegment, Visibility, VisibilityKind};
use rustc_ast::ast::{FnHeader, ForeignItem, Path, PathSegment, Visibility, VisibilityKind};
use rustc_ast::ast::{MacArgs, MacCall, MacDelimiter};
use rustc_ast::ptr::P;
use rustc_ast::token::{self, TokenKind};
@@ -1262,6 +1262,25 @@ impl<'a> Parser<'a> {
sp,
&format!("expected `,`, or `}}`, found {}", super::token_descr(&self.token)),
);

// Try to recover extra trailing angle brackets
let mut recovered = false;
if let TyKind::Path(_, Path { segments, .. }) = &a_var.ty.kind {
if let Some(last_segment) = segments.last() {
recovered = self.check_trailing_angle_brackets(
last_segment,
&[&token::Comma, &token::CloseDelim(token::Brace)],
);
if recovered {
// Handle a case like `Vec<u8>>,` where we can continue parsing fields
// after the comma
self.eat(&token::Comma);
// `check_trailing_angle_brackets` already emitted a nicer error
err.cancel();
}
}
}

if self.token.is_ident() {
// This is likely another field; emit the diagnostic and keep going
err.span_suggestion(
@@ -1271,6 +1290,14 @@ impl<'a> Parser<'a> {
Applicability::MachineApplicable,
);
err.emit();
recovered = true;
}

if recovered {
// Make sure an error was emitted (either by recovering an angle bracket,
// or by finding an identifier as the next token), since we're
// going to continue parsing
assert!(self.sess.span_diagnostic.has_errors());
} else {
return Err(err);
}
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/path.rs
Original file line number Diff line number Diff line change
@@ -169,7 +169,7 @@ impl<'a> Parser<'a> {
// `PathStyle::Expr` is only provided at the root invocation and never in
// `parse_path_segment` to recurse and therefore can be checked to maintain
// this invariant.
self.check_trailing_angle_brackets(&segment, token::ModSep);
self.check_trailing_angle_brackets(&segment, &[&token::ModSep]);
}
segments.push(segment);

14 changes: 14 additions & 0 deletions src/test/ui/parser/recover-field-extra-angle-brackets.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Tests that we recover from extra trailing angle brackets
// in a struct field

struct BadStruct {
first: Vec<u8>>, //~ ERROR unmatched angle bracket
second: bool
}

fn bar(val: BadStruct) {
val.first;
val.second;
}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/parser/recover-field-extra-angle-brackets.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: unmatched angle bracket
--> $DIR/recover-field-extra-angle-brackets.rs:5:19
|
LL | first: Vec<u8>>,
| ^ help: remove extra angle bracket

error: aborting due to previous error