From d8db5299fae13a5ef321fd8f7be7364d735fecbb Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 17 Oct 2018 00:47:28 +0200 Subject: [PATCH] Don't buffer lints. When lints are emitted from the AST borrow checker, they do not signal an error as it is not known at that time whether, due to attributes, that lint will error or warn. This means that when lints are buffered in the MIR they will always be downgraded, as the AST borrowck will not have been marked as having errored, even if a lint was upgraded to an error after being emitted from the AST borrowck. The simple solution to this is to not buffer any lints from the MIR borrowck. --- src/librustc_mir/borrow_check/mod.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 9cbaf35acd33f..fe80447e4a84f 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -321,20 +321,20 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( continue; } - let mut err = tcx.struct_span_lint_node( + let mut_span = tcx.sess.source_map().span_until_non_whitespace(span); + tcx.struct_span_lint_node( UNUSED_MUT, vsi[local_decl.source_info.scope].lint_root, span, "variable does not need to be mutable", - ); - let mut_span = tcx.sess.source_map().span_until_non_whitespace(span); - err.span_suggestion_short_with_applicability( + ) + .span_suggestion_short_with_applicability( mut_span, "remove this `mut`", String::new(), - Applicability::MachineApplicable); - - err.buffer(&mut mbcx.errors_buffer); + Applicability::MachineApplicable, + ) + .emit(); } }