diff options
| author | Esteban Kuber <esteban@kuber.com.ar> | 2021-09-02 18:34:03 +0000 |
|---|---|---|
| committer | Esteban Kuber <esteban@kuber.com.ar> | 2021-09-03 14:43:04 +0000 |
| commit | 12ce6e9c60c662dc7181b70021145f191c0f9f3e (patch) | |
| tree | 2d25c254eeec0782df8dced3f020e4cff9ef6785 /src | |
| parent | fcce644119cf4e8e36001368e514bb5ed67cb855 (diff) | |
| download | rust-12ce6e9c60c662dc7181b70021145f191c0f9f3e.tar.gz rust-12ce6e9c60c662dc7181b70021145f191c0f9f3e.zip | |
Detect bare blocks with type ascription that were meant to be a `struct` literal
Address part of #34255. Potential improvement: silence the other knock down errors in `issue-34255-1.rs`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui-fulldeps/pprust-expr-roundtrip.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/type/ascription/issue-34255-1.stderr | 10 | ||||
| -rw-r--r-- | src/tools/rustfmt/src/closures.rs | 1 |
3 files changed, 12 insertions, 0 deletions
diff --git a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs index ed8e498b6b7..8b0cebfa60e 100644 --- a/src/test/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/src/test/ui-fulldeps/pprust-expr-roundtrip.rs @@ -106,6 +106,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { rules: BlockCheckMode::Default, span: DUMMY_SP, tokens: None, + could_be_bare_literal: false, }); iter_exprs(depth - 1, &mut |e| g(ExprKind::If(e, block.clone(), None))); } diff --git a/src/test/ui/type/ascription/issue-34255-1.stderr b/src/test/ui/type/ascription/issue-34255-1.stderr index 96ee422b7b9..43f0fbbc4e3 100644 --- a/src/test/ui/type/ascription/issue-34255-1.stderr +++ b/src/test/ui/type/ascription/issue-34255-1.stderr @@ -3,6 +3,16 @@ error[E0425]: cannot find value `input_cells` in this scope | LL | input_cells: Vec::new() | ^^^^^^^^^^^ a field by this name exists in `Self` + | +help: you might have meant to write a `struct` literal + | +LL ~ pub fn new() -> Self { SomeStruct { +LL | input_cells: Vec::new() +LL | +LL | +LL | +LL ~ }} + | error[E0214]: parenthesized type parameters may only be used with a `Fn` trait --> $DIR/issue-34255-1.rs:7:27 diff --git a/src/tools/rustfmt/src/closures.rs b/src/tools/rustfmt/src/closures.rs index c9d46aef294..34d73a77fd3 100644 --- a/src/tools/rustfmt/src/closures.rs +++ b/src/tools/rustfmt/src/closures.rs @@ -160,6 +160,7 @@ fn rewrite_closure_with_block( .first() .map(|attr| attr.span.to(body.span)) .unwrap_or(body.span), + could_be_bare_literal: false, }; let block = crate::expr::rewrite_block_with_visitor( context, |
