From 63c64348372144859c74972e0e4e9a92915f5db6 Mon Sep 17 00:00:00 2001 From: surechen Date: Thu, 22 Aug 2024 17:41:15 +0800 Subject: [PATCH] Fixing span manipulation and indentation of the suggestion introduced by #126187 According to: https://github.com/rust-lang/rust/pull/128084#issuecomment-2295254576 https://github.com/rust-lang/rust/pull/126187/files#r1634897691 I try to add a span field to `Block` which doesn't include brace '{' and '}', because I need to add a suggestion at the end of function's body, and this can help me find the right place. But this will make `Block` larger. I don't want to break the original span field in `Block`, I'm worried that it will cause a lot of code failures and I think it may be more intuitive for span to include braces. --- compiler/rustc_ast/src/ast.rs | 5 +- compiler/rustc_ast/src/mut_visit.rs | 3 +- compiler/rustc_ast/src/visit.rs | 10 ++- compiler/rustc_ast_lowering/src/block.rs | 13 ++- compiler/rustc_ast_lowering/src/delegation.rs | 1 + compiler/rustc_ast_lowering/src/expr.rs | 2 + compiler/rustc_ast_lowering/src/format.rs | 1 + compiler/rustc_ast_lowering/src/lib.rs | 1 + .../rustc_builtin_macros/src/deriving/mod.rs | 1 + compiler/rustc_expand/src/build.rs | 1 + compiler/rustc_hir/src/hir.rs | 6 +- .../rustc_parse/src/parser/diagnostics.rs | 1 + compiler/rustc_parse/src/parser/expr.rs | 5 +- compiler/rustc_parse/src/parser/stmt.rs | 14 ++- .../src/error_reporting/traits/suggestions.rs | 7 +- ...turn-from-residual-sugg-issue-125997.fixed | 16 ++-- ...urn-from-residual-sugg-issue-125997.stderr | 26 ++---- tests/ui/stats/hir-stats.stderr | 86 +++++++++---------- .../ui/try-trait/try-operator-on-main.stderr | 7 +- 19 files changed, 114 insertions(+), 92 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index a44ed82850480..7daeb3e085c96 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -544,6 +544,9 @@ pub struct Block { /// Distinguishes between `unsafe { ... }` and `{ ... }`. pub rules: BlockCheckMode, pub span: Span, + // Only for function or method written by developers that do have a block, + // but not including the blocks automatically inserted by the compiler. + pub no_brace_span: Option, pub tokens: Option, /// The following *isn't* a parse error, but will cause multiple errors in following stages. /// ```compile_fail @@ -3501,7 +3504,7 @@ mod size_asserts { static_assert_size!(AssocItem, 88); static_assert_size!(AssocItemKind, 16); static_assert_size!(Attribute, 32); - static_assert_size!(Block, 32); + static_assert_size!(Block, 48); static_assert_size!(Expr, 72); static_assert_size!(ExprKind, 40); static_assert_size!(Fn, 160); diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 8a66894a35603..5b86f6fad6768 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -1076,7 +1076,8 @@ fn walk_mt(vis: &mut T, MutTy { ty, mutbl: _ }: &mut MutTy) { } pub fn walk_block(vis: &mut T, block: &mut P) { - let Block { id, stmts, rules: _, span, tokens, could_be_bare_literal: _ } = block.deref_mut(); + let Block { id, stmts, rules: _, span, tokens, could_be_bare_literal: _, no_brace_span: _ } = + block.deref_mut(); vis.visit_id(id); stmts.flat_map_in_place(|stmt| vis.flat_map_stmt(stmt)); visit_lazy_tts(vis, tokens); diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index fe07ec48f1f2b..9063b9adfdef1 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -943,7 +943,15 @@ pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) } pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) -> V::Result { - let Block { stmts, id: _, rules: _, span: _, tokens: _, could_be_bare_literal: _ } = block; + let Block { + stmts, + id: _, + rules: _, + span: _, + tokens: _, + could_be_bare_literal: _, + no_brace_span: _, + } = block; walk_list!(visitor, visit_stmt, stmts); V::Result::output() } diff --git a/compiler/rustc_ast_lowering/src/block.rs b/compiler/rustc_ast_lowering/src/block.rs index 9d2b5690c23d9..959318222c9a4 100644 --- a/compiler/rustc_ast_lowering/src/block.rs +++ b/compiler/rustc_ast_lowering/src/block.rs @@ -1,5 +1,6 @@ use rustc_ast::{Block, BlockCheckMode, Local, LocalKind, Stmt, StmtKind}; use rustc_hir as hir; +use rustc_span::Span; use smallvec::SmallVec; use crate::{ImplTraitContext, ImplTraitPosition, LoweringContext}; @@ -21,7 +22,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let (stmts, expr) = self.lower_stmts(&b.stmts); let rules = self.lower_block_check_mode(&b.rules); let hir_id = self.lower_node_id(b.id); - hir::Block { hir_id, stmts, expr, rules, span: self.lower_span(b.span), targeted_by_break } + let lower = |span: Span| -> Option { Some(self.lower_span(span)) }; + let no_brace_span = b.no_brace_span.and_then(lower); + hir::Block { + hir_id, + stmts, + expr, + rules, + span: self.lower_span(b.span), + no_brace_span, + targeted_by_break, + } } fn lower_stmts( diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 9c073130827c8..58b04c8ed0503 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -353,6 +353,7 @@ impl<'hir> LoweringContext<'_, 'hir> { hir_id: self.next_id(), rules: hir::BlockCheckMode::DefaultBlock, span, + no_brace_span: None, targeted_by_break: false, }); diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index b5d8a547a8fb9..ba760f50347e1 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -592,6 +592,7 @@ impl<'hir> LoweringContext<'_, 'hir> { hir_id: self.next_id(), rules: hir::BlockCheckMode::DefaultBlock, span, + no_brace_span: None, targeted_by_break: false, }); self.arena.alloc(hir::Expr { @@ -2116,6 +2117,7 @@ impl<'hir> LoweringContext<'_, 'hir> { hir_id, rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated), span: self.lower_span(span), + no_brace_span: None, targeted_by_break: false, }), None, diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index bf40c9b66c68f..b51386e01a5ba 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -612,6 +612,7 @@ fn expand_format_args<'hir>( hir_id, rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated), span: macsp, + no_brace_span: None, targeted_by_break: false, })); let args = ctx.arena.alloc_from_iter([lit_pieces, args, format_options, unsafe_arg]); diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 81d17a9dec205..009d7d5f39e67 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -2571,6 +2571,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir_id: self.next_id(), rules: hir::BlockCheckMode::DefaultBlock, span: self.lower_span(span), + no_brace_span: None, targeted_by_break: false, }; self.arena.alloc(blk) diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index 32936ac183df9..cd01d497f8673 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -112,6 +112,7 @@ fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> P { id: ast::DUMMY_NODE_ID, rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated), span, + no_brace_span: None, tokens: None, could_be_bare_literal: false, })) diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 8ecdb551342dd..47ad82b38589c 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -247,6 +247,7 @@ impl<'a> ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, rules: BlockCheckMode::Default, span, + no_brace_span: None, tokens: None, could_be_bare_literal: false, }) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 57c47d29857c3..518945af48fc6 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1095,6 +1095,10 @@ pub struct Block<'hir> { pub rules: BlockCheckMode, /// The span includes the curly braces `{` and `}` around the block. pub span: Span, + // The span doesn't include the curly braces `{` and `}` around the block. + // Only for function or method written by developers that do have a block, + // but not including the blocks automatically inserted by the compiler. + pub no_brace_span: Option, /// If true, then there may exist `break 'a` values that aim to /// break out of this block early. /// Used by `'label: {}` blocks and by `try {}` blocks. @@ -4040,7 +4044,7 @@ mod size_asserts { use super::*; // tidy-alphabetical-start - static_assert_size!(Block<'_>, 48); + static_assert_size!(Block<'_>, 56); static_assert_size!(Body<'_>, 24); static_assert_size!(Expr<'_>, 64); static_assert_size!(ExprKind<'_>, 48); diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index ef1387c50fa8c..306f46e8629bb 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -928,6 +928,7 @@ impl<'a> Parser<'a> { thin_vec![self.mk_stmt_err(expr.span, guar)], s, lo.to(self.prev_token.span), + None, ); tail.could_be_bare_literal = true; if maybe_struct_name.is_ident() && can_be_struct_literal { diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 422206ebbce07..98f3ab70e2b7d 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1731,7 +1731,7 @@ impl<'a> Parser<'a> { // Replace `'label: non_block_expr` with `'label: {non_block_expr}` in order to suppress future errors about `break 'label`. let stmt = self.mk_stmt(span, StmtKind::Expr(expr)); - let blk = self.mk_block(thin_vec![stmt], BlockCheckMode::Default, span); + let blk = self.mk_block(thin_vec![stmt], BlockCheckMode::Default, span, None); self.mk_expr(span, ExprKind::Block(blk, label)) }); @@ -2847,7 +2847,8 @@ impl<'a> Parser<'a> { .dcx() .emit_err(errors::MissingExpressionInForLoop { span: expr.span.shrink_to_lo() }); let err_expr = self.mk_expr(expr.span, ExprKind::Err(guar)); - let block = self.mk_block(thin_vec![], BlockCheckMode::Default, self.prev_token.span); + let block = + self.mk_block(thin_vec![], BlockCheckMode::Default, self.prev_token.span, None); return Ok(self.mk_expr( lo.to(self.prev_token.span), ExprKind::ForLoop { pat, iter: err_expr, body: block, label: opt_label, kind }, diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 69044192780bc..ab96b6d1e980b 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -578,6 +578,8 @@ impl<'a> Parser<'a> { ) -> PResult<'a, P> { let mut stmts = ThinVec::new(); let mut snapshot = None; + let start_without_brace_sp = self.token.span; + let mut end_without_brace_sp = self.token.span; while !self.eat(&token::CloseDelim(Delimiter::Brace)) { if self.token == token::Eof { break; @@ -641,8 +643,14 @@ impl<'a> Parser<'a> { // Found only `;` or `}`. continue; }; + end_without_brace_sp = self.prev_token.span; } - Ok(self.mk_block(stmts, s, lo.to(self.prev_token.span))) + Ok(self.mk_block( + stmts, + s, + lo.to(self.prev_token.span), + Some(start_without_brace_sp.to(end_without_brace_sp)), + )) } /// Parses a statement, including the trailing semicolon. @@ -843,12 +851,14 @@ impl<'a> Parser<'a> { stmts: ThinVec, rules: BlockCheckMode, span: Span, + no_brace_span: Option, ) -> P { P(Block { stmts, id: DUMMY_NODE_ID, rules, span, + no_brace_span, tokens: None, could_be_bare_literal: false, }) @@ -863,6 +873,6 @@ impl<'a> Parser<'a> { } pub(super) fn mk_block_err(&self, span: Span, guar: ErrorGuaranteed) -> P { - self.mk_block(thin_vec![self.mk_stmt_err(span, guar)], BlockCheckMode::Default, span) + self.mk_block(thin_vec![self.mk_stmt_err(span, guar)], BlockCheckMode::Default, span, None) } } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index a962be54c3d88..604c715e65f98 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -4666,12 +4666,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let body = self.tcx.hir().body(body_id); if let hir::ExprKind::Block(b, _) = body.value.kind && b.expr.is_none() + && let Some(span) = b.no_brace_span { - sugg_spans.push(( - // The span will point to the closing curly brace `}` of the block. - b.span.shrink_to_hi().with_lo(b.span.hi() - BytePos(1)), - "\n Ok(())\n}".to_string(), - )); + sugg_spans.push((span.shrink_to_hi(), "\n Ok(())".to_string())); } err.multipart_suggestion_verbose( format!("consider adding return type"), diff --git a/tests/ui/return/return-from-residual-sugg-issue-125997.fixed b/tests/ui/return/return-from-residual-sugg-issue-125997.fixed index a5a133998259b..e05e87b73b485 100644 --- a/tests/ui/return/return-from-residual-sugg-issue-125997.fixed +++ b/tests/ui/return/return-from-residual-sugg-issue-125997.fixed @@ -8,16 +8,14 @@ use std::io::prelude::*; fn test1() -> Result<(), Box> { let mut _file = File::create("foo.txt")?; - //~^ ERROR the `?` operator can only be used in a function - Ok(()) + //~^ ERROR the `?` operator can only be used in a function } fn test2() -> Result<(), Box> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a function println!(); - Ok(()) } @@ -27,9 +25,8 @@ macro_rules! mac { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a function println!(); - Ok(()) -} + } }; } @@ -38,24 +35,21 @@ struct A; impl A { fn test4(&self) -> Result<(), Box> { let mut _file = File::create("foo.txt")?; - //~^ ERROR the `?` operator can only be used in a method - Ok(()) -} + //~^ ERROR the `?` operator can only be used in a method + } fn test5(&self) -> Result<(), Box> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a method println!(); - Ok(()) -} + } } fn main() -> Result<(), Box> { let mut _file = File::create("foo.txt")?; //~^ ERROR the `?` operator can only be used in a function mac!(); - Ok(()) } diff --git a/tests/ui/return/return-from-residual-sugg-issue-125997.stderr b/tests/ui/return/return-from-residual-sugg-issue-125997.stderr index a59f38c2ec644..040012656016d 100644 --- a/tests/ui/return/return-from-residual-sugg-issue-125997.stderr +++ b/tests/ui/return/return-from-residual-sugg-issue-125997.stderr @@ -10,11 +10,8 @@ LL | let mut _file = File::create("foo.txt")?; help: consider adding return type | LL ~ fn test1() -> Result<(), Box> { -LL | let mut _file = File::create("foo.txt")?; -LL | -LL + +LL ~ let mut _file = File::create("foo.txt")?; LL + Ok(()) -LL + } | error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) @@ -31,10 +28,8 @@ help: consider adding return type LL ~ fn test2() -> Result<(), Box> { LL | let mut _file = File::create("foo.txt")?; LL | -LL | println!(); -LL + +LL ~ println!(); LL + Ok(()) -LL + } | error[E0277]: the `?` operator can only be used in a method that returns `Result` or `Option` (or another type that implements `FromResidual`) @@ -49,11 +44,8 @@ LL | let mut _file = File::create("foo.txt")?; help: consider adding return type | LL ~ fn test4(&self) -> Result<(), Box> { -LL | let mut _file = File::create("foo.txt")?; -LL | -LL ~ +LL ~ let mut _file = File::create("foo.txt")?; LL + Ok(()) -LL + } | error[E0277]: the `?` operator can only be used in a method that returns `Result` or `Option` (or another type that implements `FromResidual`) @@ -70,10 +62,8 @@ help: consider adding return type LL ~ fn test5(&self) -> Result<(), Box> { LL | let mut _file = File::create("foo.txt")?; LL | -LL | println!(); -LL ~ +LL ~ println!(); LL + Ok(()) -LL + } | error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) @@ -90,10 +80,8 @@ help: consider adding return type LL ~ fn main() -> Result<(), Box> { LL | let mut _file = File::create("foo.txt")?; LL | -LL | mac!(); -LL + +LL ~ mac!(); LL + Ok(()) -LL + } | error[E0277]: the `?` operator can only be used in a function that returns `Result` or `Option` (or another type that implements `FromResidual`) @@ -114,10 +102,8 @@ help: consider adding return type LL ~ fn test3() -> Result<(), Box> { LL | let mut _file = File::create("foo.txt")?; LL | -LL | println!(); -LL ~ +LL ~ println!(); LL + Ok(()) -LL + } | error: aborting due to 6 previous errors diff --git a/tests/ui/stats/hir-stats.stderr b/tests/ui/stats/hir-stats.stderr index b27f769ba34f4..a8e6de887c3d2 100644 --- a/tests/ui/stats/hir-stats.stderr +++ b/tests/ui/stats/hir-stats.stderr @@ -21,39 +21,39 @@ ast-stats-1 - Let 32 ( 0.5%) 1 ast-stats-1 - MacCall 32 ( 0.5%) 1 ast-stats-1 - Expr 96 ( 1.4%) 3 ast-stats-1 Param 160 ( 2.4%) 4 40 -ast-stats-1 Block 192 ( 2.9%) 6 32 ast-stats-1 Variant 208 ( 3.1%) 2 104 -ast-stats-1 GenericBound 352 ( 5.3%) 4 88 -ast-stats-1 - Trait 352 ( 5.3%) 4 -ast-stats-1 AssocItem 352 ( 5.3%) 4 88 -ast-stats-1 - Type 176 ( 2.7%) 2 -ast-stats-1 - Fn 176 ( 2.7%) 2 -ast-stats-1 GenericParam 480 ( 7.2%) 5 96 -ast-stats-1 Pat 504 ( 7.6%) 7 72 +ast-stats-1 Block 288 ( 4.3%) 6 48 +ast-stats-1 GenericBound 352 ( 5.2%) 4 88 +ast-stats-1 - Trait 352 ( 5.2%) 4 +ast-stats-1 AssocItem 352 ( 5.2%) 4 88 +ast-stats-1 - Type 176 ( 2.6%) 2 +ast-stats-1 - Fn 176 ( 2.6%) 2 +ast-stats-1 GenericParam 480 ( 7.1%) 5 96 +ast-stats-1 Pat 504 ( 7.5%) 7 72 ast-stats-1 - Struct 72 ( 1.1%) 1 ast-stats-1 - Wild 72 ( 1.1%) 1 -ast-stats-1 - Ident 360 ( 5.4%) 5 -ast-stats-1 Expr 576 ( 8.7%) 8 72 +ast-stats-1 - Ident 360 ( 5.3%) 5 +ast-stats-1 Expr 576 ( 8.6%) 8 72 ast-stats-1 - Path 72 ( 1.1%) 1 ast-stats-1 - Match 72 ( 1.1%) 1 ast-stats-1 - Struct 72 ( 1.1%) 1 -ast-stats-1 - Lit 144 ( 2.2%) 2 -ast-stats-1 - Block 216 ( 3.3%) 3 -ast-stats-1 PathSegment 744 (11.2%) 31 24 -ast-stats-1 Ty 896 (13.5%) 14 64 +ast-stats-1 - Lit 144 ( 2.1%) 2 +ast-stats-1 - Block 216 ( 3.2%) 3 +ast-stats-1 PathSegment 744 (11.0%) 31 24 +ast-stats-1 Ty 896 (13.3%) 14 64 ast-stats-1 - Ptr 64 ( 1.0%) 1 ast-stats-1 - Ref 64 ( 1.0%) 1 ast-stats-1 - ImplicitSelf 128 ( 1.9%) 2 -ast-stats-1 - Path 640 ( 9.6%) 10 -ast-stats-1 Item 1_224 (18.4%) 9 136 +ast-stats-1 - Path 640 ( 9.5%) 10 +ast-stats-1 Item 1_224 (18.2%) 9 136 ast-stats-1 - Trait 136 ( 2.0%) 1 ast-stats-1 - Enum 136 ( 2.0%) 1 ast-stats-1 - ForeignMod 136 ( 2.0%) 1 ast-stats-1 - Impl 136 ( 2.0%) 1 -ast-stats-1 - Fn 272 ( 4.1%) 2 +ast-stats-1 - Fn 272 ( 4.0%) 2 ast-stats-1 - Use 408 ( 6.1%) 3 ast-stats-1 ---------------------------------------------------------------- -ast-stats-1 Total 6_640 +ast-stats-1 Total 6_736 ast-stats-1 ast-stats-2 POST EXPANSION AST STATS ast-stats-2 Name Accumulated Size Count Item Size @@ -70,7 +70,7 @@ ast-stats-2 - Fn 88 ( 1.2%) 1 ast-stats-2 Arm 96 ( 1.3%) 2 48 ast-stats-2 InlineAsm 120 ( 1.6%) 1 120 ast-stats-2 FnDecl 120 ( 1.6%) 5 24 -ast-stats-2 Attribute 128 ( 1.8%) 4 32 +ast-stats-2 Attribute 128 ( 1.7%) 4 32 ast-stats-2 - DocComment 32 ( 0.4%) 1 ast-stats-2 - Normal 96 ( 1.3%) 3 ast-stats-2 FieldDef 160 ( 2.2%) 2 80 @@ -79,41 +79,41 @@ ast-stats-2 - Let 32 ( 0.4%) 1 ast-stats-2 - Semi 32 ( 0.4%) 1 ast-stats-2 - Expr 96 ( 1.3%) 3 ast-stats-2 Param 160 ( 2.2%) 4 40 -ast-stats-2 Block 192 ( 2.6%) 6 32 -ast-stats-2 Variant 208 ( 2.9%) 2 104 +ast-stats-2 Variant 208 ( 2.8%) 2 104 +ast-stats-2 Block 288 ( 3.9%) 6 48 ast-stats-2 GenericBound 352 ( 4.8%) 4 88 ast-stats-2 - Trait 352 ( 4.8%) 4 ast-stats-2 AssocItem 352 ( 4.8%) 4 88 ast-stats-2 - Type 176 ( 2.4%) 2 ast-stats-2 - Fn 176 ( 2.4%) 2 -ast-stats-2 GenericParam 480 ( 6.6%) 5 96 -ast-stats-2 Pat 504 ( 6.9%) 7 72 +ast-stats-2 GenericParam 480 ( 6.5%) 5 96 +ast-stats-2 Pat 504 ( 6.8%) 7 72 ast-stats-2 - Struct 72 ( 1.0%) 1 ast-stats-2 - Wild 72 ( 1.0%) 1 ast-stats-2 - Ident 360 ( 4.9%) 5 -ast-stats-2 Expr 648 ( 8.9%) 9 72 +ast-stats-2 Expr 648 ( 8.8%) 9 72 ast-stats-2 - Path 72 ( 1.0%) 1 ast-stats-2 - Match 72 ( 1.0%) 1 ast-stats-2 - Struct 72 ( 1.0%) 1 ast-stats-2 - InlineAsm 72 ( 1.0%) 1 ast-stats-2 - Lit 144 ( 2.0%) 2 -ast-stats-2 - Block 216 ( 3.0%) 3 -ast-stats-2 PathSegment 864 (11.9%) 36 24 -ast-stats-2 Ty 896 (12.3%) 14 64 +ast-stats-2 - Block 216 ( 2.9%) 3 +ast-stats-2 PathSegment 864 (11.7%) 36 24 +ast-stats-2 Ty 896 (12.1%) 14 64 ast-stats-2 - Ptr 64 ( 0.9%) 1 ast-stats-2 - Ref 64 ( 0.9%) 1 -ast-stats-2 - ImplicitSelf 128 ( 1.8%) 2 -ast-stats-2 - Path 640 ( 8.8%) 10 -ast-stats-2 Item 1_496 (20.5%) 11 136 -ast-stats-2 - Trait 136 ( 1.9%) 1 -ast-stats-2 - Enum 136 ( 1.9%) 1 -ast-stats-2 - ExternCrate 136 ( 1.9%) 1 -ast-stats-2 - ForeignMod 136 ( 1.9%) 1 -ast-stats-2 - Impl 136 ( 1.9%) 1 +ast-stats-2 - ImplicitSelf 128 ( 1.7%) 2 +ast-stats-2 - Path 640 ( 8.7%) 10 +ast-stats-2 Item 1_496 (20.3%) 11 136 +ast-stats-2 - Trait 136 ( 1.8%) 1 +ast-stats-2 - Enum 136 ( 1.8%) 1 +ast-stats-2 - ExternCrate 136 ( 1.8%) 1 +ast-stats-2 - ForeignMod 136 ( 1.8%) 1 +ast-stats-2 - Impl 136 ( 1.8%) 1 ast-stats-2 - Fn 272 ( 3.7%) 2 -ast-stats-2 - Use 544 ( 7.5%) 4 +ast-stats-2 - Use 544 ( 7.4%) 4 ast-stats-2 ---------------------------------------------------------------- -ast-stats-2 Total 7_288 +ast-stats-2 Total 7_384 ast-stats-2 hir-stats HIR STATS hir-stats Name Accumulated Size Count Item Size @@ -145,7 +145,7 @@ hir-stats GenericBound 192 ( 2.1%) 4 48 hir-stats - Trait 192 ( 2.1%) 4 hir-stats WherePredicate 192 ( 2.1%) 3 64 hir-stats - BoundPredicate 192 ( 2.1%) 3 -hir-stats Block 288 ( 3.2%) 6 48 +hir-stats Block 336 ( 3.7%) 6 56 hir-stats GenericParam 360 ( 4.0%) 5 72 hir-stats Pat 360 ( 4.0%) 5 72 hir-stats - Wild 72 ( 0.8%) 1 @@ -155,15 +155,15 @@ hir-stats Generics 560 ( 6.2%) 10 56 hir-stats Ty 720 ( 8.0%) 15 48 hir-stats - Ptr 48 ( 0.5%) 1 hir-stats - Ref 48 ( 0.5%) 1 -hir-stats - Path 624 ( 7.0%) 13 -hir-stats Expr 768 ( 8.6%) 12 64 +hir-stats - Path 624 ( 6.9%) 13 +hir-stats Expr 768 ( 8.5%) 12 64 hir-stats - Path 64 ( 0.7%) 1 hir-stats - Struct 64 ( 0.7%) 1 hir-stats - Match 64 ( 0.7%) 1 hir-stats - InlineAsm 64 ( 0.7%) 1 hir-stats - Lit 128 ( 1.4%) 2 hir-stats - Block 384 ( 4.3%) 6 -hir-stats Item 968 (10.8%) 11 88 +hir-stats Item 968 (10.7%) 11 88 hir-stats - Trait 88 ( 1.0%) 1 hir-stats - Enum 88 ( 1.0%) 1 hir-stats - ExternCrate 88 ( 1.0%) 1 @@ -172,7 +172,7 @@ hir-stats - Impl 88 ( 1.0%) 1 hir-stats - Fn 176 ( 2.0%) 2 hir-stats - Use 352 ( 3.9%) 4 hir-stats Path 1_240 (13.8%) 31 40 -hir-stats PathSegment 1_920 (21.4%) 40 48 +hir-stats PathSegment 1_920 (21.3%) 40 48 hir-stats ---------------------------------------------------------------- -hir-stats Total 8_960 +hir-stats Total 9_008 hir-stats diff --git a/tests/ui/try-trait/try-operator-on-main.stderr b/tests/ui/try-trait/try-operator-on-main.stderr index d22117165c12b..192d7ee960dc3 100644 --- a/tests/ui/try-trait/try-operator-on-main.stderr +++ b/tests/ui/try-trait/try-operator-on-main.stderr @@ -13,10 +13,9 @@ help: consider adding return type LL ~ fn main() -> Result<(), Box> { LL | // error for a `Try` type on a non-`Try` fn ... -LL | try_trait_generic::<()>(); -LL + -LL + Ok(()) -LL + } +LL | // an unrelated use of `Try` +LL ~ try_trait_generic::<()>(); +LL ~ Ok(()) | error[E0277]: the `?` operator can only be applied to values that implement `Try`