Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d4fe955
Implement partial error recovery for `let` with `BinOpEq`
mibac138 May 7, 2020
48ff12a
Expand partial error recovery for `let` with `BinOpEq`
mibac138 May 7, 2020
05d6531
Error recovery for `let` with `+=`
mibac138 May 7, 2020
6ad24ba
Adjust according to estebank's review comments
mibac138 May 7, 2020
98532a3
Adjust according to petrochenkov's review comments
mibac138 May 20, 2020
3da3d15
[RISC-V] Do not force frame pointers
lenary May 30, 2020
f0d2e78
add raw_ref macros
RalfJung Jun 12, 2020
724dfba
Clean up some weird command strings
GuillaumeGomez Jun 13, 2020
d5ea0e9
Report error when casting an C-like enum implementing Drop
oddg May 15, 2020
a40156e
UI test for deprecation warning of casting enum implementing Drop
oddg Jun 14, 2020
0906066
Test that bounds checks are elided when slice len is checked up-front
erikdesjardins Jun 15, 2020
81c9094
Suggest substituting `'static` lifetime in impl/dyn `Trait + 'static`…
estebank May 29, 2020
4e90f17
When `'static` is explicit, suggest constraining argument with it
estebank May 30, 2020
921f35f
Reduce verbosity of suggestion message and mention lifetime in label
estebank May 30, 2020
e755889
Move overlapping span to a note
estebank May 30, 2020
bc15790
Tweak output for overlapping required/captured spans
estebank May 30, 2020
539e978
Tweak wording and add error code
estebank May 30, 2020
31ea589
review comments: wording
estebank Jun 1, 2020
10d9bf1
Use note for requirement source span
estebank Jun 2, 2020
34d8692
Register new eror code
estebank Jun 2, 2020
e31367d
small tweaks
estebank Jun 2, 2020
f7a1f97
Change E0758 to E0759 to avoid conflict with #72912
estebank Jun 3, 2020
bfe1434
fix rebase
estebank Jun 15, 2020
b5809b0
Update src/librustc_typeck/check/cast.rs
nikomatsakis Jun 15, 2020
e0975b9
elaborate, add check for exact bounds
erikdesjardins Jun 15, 2020
f3dfe80
Adjust error message
oddg Jun 16, 2020
0265e4e
add tracking issue
RalfJung Jun 16, 2020
a19dfb5
Create new E0763 error code for unterminated byte constant
GuillaumeGomez Jun 12, 2020
bad252c
Update ui tests
GuillaumeGomez Jun 12, 2020
1990f97
Disallow loading crates with non-ascii identifier name.
crlf0710 Jun 13, 2020
7a9f29d
Add initial asm!() support for hexagon
androm3da Jun 9, 2020
9f2e8ad
Fix typo in librustc_ast docs
pierwill Jun 17, 2020
fd44ac7
Rollup merge of #69890 - lenary:lenary/riscv-frame-pointers, r=hanna-…
Dylan-DPC Jun 17, 2020
519a69c
Rollup merge of #71976 - mibac138:let-recovery, r=estebank
Dylan-DPC Jun 17, 2020
f9036e6
Rollup merge of #72279 - RalfJung:raw-ref-macros, r=nikomatsakis
Dylan-DPC Jun 17, 2020
b5af8a2
Rollup merge of #72331 - oddg:forbid-cast-of-cenum-implementing-drop,…
Dylan-DPC Jun 17, 2020
ba2be2b
Rollup merge of #72804 - estebank:opaque-missing-lts-in-fn-2, r=nikom…
Dylan-DPC Jun 17, 2020
6fbaa35
Rollup merge of #73214 - androm3da:hex_inline_asm_00, r=Amanieu
Dylan-DPC Jun 17, 2020
211537c
Rollup merge of #73280 - GuillaumeGomez:add-e0763, r=petrochenkov
Dylan-DPC Jun 17, 2020
8743c17
Rollup merge of #73305 - crlf0710:disallow_loading_monsters, r=petroc…
Dylan-DPC Jun 17, 2020
6441486
Rollup merge of #73315 - GuillaumeGomez:clean-up-config-strs, r=kinnison
Dylan-DPC Jun 17, 2020
b73f9fa
Rollup merge of #73362 - erikdesjardins:bounds, r=nikomatsakis
Dylan-DPC Jun 17, 2020
edb339b
Rollup merge of #73428 - pierwill:patch-1, r=jonas-schievink
Dylan-DPC Jun 17, 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
Adjust according to petrochenkov's review comments
  • Loading branch information
mibac138 committed May 21, 2020
commit 98532a30901d7544c49fe82f499db53699645de0
65 changes: 22 additions & 43 deletions src/librustc_parse/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_ast::ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKin
use rustc_ast::ptr::P;
use rustc_ast::token::{self, TokenKind};
use rustc_ast::util::classify;
use rustc_errors::{struct_span_err, Applicability, PResult};
use rustc_errors::{Applicability, PResult};
use rustc_span::source_map::{BytePos, Span};
use rustc_span::symbol::{kw, sym};

Expand Down Expand Up @@ -145,12 +145,12 @@ impl<'a> Parser<'a> {
}

fn parse_local_mk(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, Stmt> {
let local = self.parse_local(lo, attrs)?;
let local = self.parse_local(attrs)?;
Ok(self.mk_stmt(lo.to(self.prev_token.span), StmtKind::Local(local)))
}

/// Parses a local variable declaration.
fn parse_local(&mut self, let_span: Span, attrs: AttrVec) -> PResult<'a, P<Local>> {
fn parse_local(&mut self, attrs: AttrVec) -> PResult<'a, P<Local>> {
let lo = self.prev_token.span;
let pat = self.parse_top_pat(GateOr::Yes)?;

Expand All @@ -174,10 +174,7 @@ impl<'a> Parser<'a> {
} else {
(None, None)
};
let init = match (
self.parse_initializer(let_span.until(pat.span), ty.is_some(), err.is_some()),
err,
) {
let init = match (self.parse_initializer(err.is_some()), err) {
(Ok(init), None) => {
// init parsed, ty parsed
init
Expand Down Expand Up @@ -219,46 +216,28 @@ impl<'a> Parser<'a> {
}

/// Parses the RHS of a local variable declaration (e.g., '= 14;').
fn parse_initializer(
&mut self,
let_span: Span,
has_ty: bool,
skip_eq: bool,
) -> PResult<'a, Option<P<Expr>>> {
// In case of code like `let x: i8 += 1`, `i8` is interpreted as a trait consuming the `+`
// from `+=`.
let ate_plus = self.prev_token.is_like_plus() && has_ty;
let parse = if !skip_eq && (ate_plus || matches!(self.token.kind, TokenKind::BinOpEq(_))) {
// Error recovery for `let x += 1`
let mut err = struct_span_err!(
self.sess.span_diagnostic,
self.token.span,
E0067,
"can't reassign to an uninitialized variable"
);
err.span_suggestion_short(
self.token.span,
"initialize the variable",
"=".to_string(),
Applicability::MaybeIncorrect,
);
// In case of code like `let x += 1` it's possible the user may have meant to write `x += 1`
if !has_ty {
err.span_suggestion_short(
let_span,
"otherwise, reassign to a previously initialized variable",
"".to_string(),
fn parse_initializer(&mut self, eq_optional: bool) -> PResult<'a, Option<P<Expr>>> {
let eq_consumed = match self.token.kind {
token::BinOpEq(..) => {
// Recover `let x <op>= 1` as `let x = 1`
self.struct_span_err(
self.token.span,
"can't reassign to an uninitialized variable",
)
.span_suggestion_short(
self.token.span,
"initialize the variable",
"=".to_string(),
Applicability::MaybeIncorrect,
);
)
.emit();
self.bump();
true
}
err.emit();
self.bump();
true
} else {
self.eat(&token::Eq) || skip_eq
_ => self.eat(&token::Eq),
};

if parse { Ok(Some(self.parse_expr()?)) } else { Ok(None) }
Ok(if eq_consumed || eq_optional { Some(self.parse_expr()?) } else { None })
}

/// Parses a block. No inner attributes are allowed.
Expand Down
8 changes: 0 additions & 8 deletions src/test/ui/parser/let-binop-plus.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/ui/parser/let-binop-plus.stderr

This file was deleted.

29 changes: 5 additions & 24 deletions src/test/ui/parser/let-binop.stderr
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
error[E0067]: can't reassign to an uninitialized variable
error: can't reassign to an uninitialized variable
--> $DIR/let-binop.rs:2:15
|
LL | let a: i8 *= 1;
| ^^ help: initialize the variable

error[E0067]: can't reassign to an uninitialized variable
error: can't reassign to an uninitialized variable
--> $DIR/let-binop.rs:4:11
|
LL | let b += 1;
| ^^
|
help: initialize the variable
|
LL | let b = 1;
| ^
help: otherwise, reassign to a previously initialized variable
|
LL | b += 1;
| --
| ^^ help: initialize the variable

error[E0067]: can't reassign to an uninitialized variable
error: can't reassign to an uninitialized variable
--> $DIR/let-binop.rs:6:11
|
LL | let c *= 1;
| ^^
|
help: initialize the variable
|
LL | let c = 1;
| ^
help: otherwise, reassign to a previously initialized variable
|
LL | c *= 1;
| --
| ^^ help: initialize the variable

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0067`.