From 1f20966e90cd964842054c284fb0ec5e8de6df7b Mon Sep 17 00:00:00 2001 From: hamidreza kalbasi Date: Tue, 11 May 2021 08:50:43 +0430 Subject: [PATCH] Fix CI problems --- .../diagnostics/mutability_errors.rs | 78 +++++++++---------- src/test/ui/suggestions/issue-68049-1.rs | 2 +- src/test/ui/suggestions/issue-68049-2.rs | 4 +- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs index 85c5ee71748..1e2714a2c1b 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs @@ -515,10 +515,10 @@ pub(crate) fn report_mutability_error( err.buffer(&mut self.errors_buffer); } - + /// User cannot make signature of a trait mutable without changing the /// trait. So we find if this error belongs to a trait and if so we move - /// suggestion to the trait or disable it if it is out of scope of this crate + /// suggestion to the trait or disable it if it is out of scope of this crate fn is_error_in_trait(&self, local: Local) -> (bool, Option) { if self.body.local_kind(local) != LocalKind::Arg { return (false, None); @@ -526,57 +526,53 @@ fn is_error_in_trait(&self, local: Local) -> (bool, Option) { let hir_map = self.infcx.tcx.hir(); let my_def = self.body.source.def_id(); let my_hir = hir_map.local_def_id_to_hir_id(my_def.as_local().unwrap()); - let td = if let Some(a) = self.infcx.tcx.impl_of_method(my_def).and_then(|x| { - self.infcx.tcx.trait_id_of_impl(x) - }) { + let td = if let Some(a) = + self.infcx.tcx.impl_of_method(my_def).and_then(|x| self.infcx.tcx.trait_id_of_impl(x)) + { a } else { return (false, None); }; - (true, td.as_local().and_then(|tld| { - let h = hir_map.local_def_id_to_hir_id(tld); - match hir_map.find(h) { - Some(Node::Item(hir::Item { - kind: hir::ItemKind::Trait( - _, _, _, _, - items - ), - .. - })) => { - let mut f_in_trait_opt = None; - for hir::TraitItemRef { id: fi, kind: k, .. } in *items { - let hi = fi.hir_id(); - if !matches!(k, hir::AssocItemKind::Fn { .. }) { - continue; + ( + true, + td.as_local().and_then(|tld| { + let h = hir_map.local_def_id_to_hir_id(tld); + match hir_map.find(h) { + Some(Node::Item(hir::Item { + kind: hir::ItemKind::Trait(_, _, _, _, items), + .. + })) => { + let mut f_in_trait_opt = None; + for hir::TraitItemRef { id: fi, kind: k, .. } in *items { + let hi = fi.hir_id(); + if !matches!(k, hir::AssocItemKind::Fn { .. }) { + continue; + } + if hir_map.name(hi) != hir_map.name(my_hir) { + continue; + } + f_in_trait_opt = Some(hi); + break; } - if hir_map.name(hi) != hir_map.name(my_hir) { - continue; - } - f_in_trait_opt = Some(hi); - break; - } - f_in_trait_opt.and_then(|f_in_trait| { - match hir_map.find(f_in_trait) { + f_in_trait_opt.and_then(|f_in_trait| match hir_map.find(f_in_trait) { Some(Node::TraitItem(hir::TraitItem { - kind: hir::TraitItemKind::Fn(hir::FnSig { - decl: hir::FnDecl { - inputs, - .. - }, - .. - }, _), + kind: + hir::TraitItemKind::Fn( + hir::FnSig { decl: hir::FnDecl { inputs, .. }, .. }, + _, + ), .. })) => { let hir::Ty { span, .. } = inputs[local.index() - 1]; Some(span) - }, + } _ => None, - } - }) + }) + } + _ => None, } - _ => None - } - })) + }), + ) } // point to span of upvar making closure call require mutable borrow diff --git a/src/test/ui/suggestions/issue-68049-1.rs b/src/test/ui/suggestions/issue-68049-1.rs index 9b9ae429aeb..0acb7b1bf2b 100644 --- a/src/test/ui/suggestions/issue-68049-1.rs +++ b/src/test/ui/suggestions/issue-68049-1.rs @@ -4,7 +4,7 @@ unsafe impl GlobalAlloc for Test { unsafe fn alloc(&self, _layout: Layout) -> *mut u8 { - self.0 += 1; + self.0 += 1; //~ ERROR cannot assign 0 as *mut u8 } diff --git a/src/test/ui/suggestions/issue-68049-2.rs b/src/test/ui/suggestions/issue-68049-2.rs index 22bb6b85d6f..1c3430c14e9 100644 --- a/src/test/ui/suggestions/issue-68049-2.rs +++ b/src/test/ui/suggestions/issue-68049-2.rs @@ -6,7 +6,7 @@ trait Hello { impl Hello for Test1 { fn example(&self, input: &i32) { // should not suggest here - *input = self.0; + *input = self.0; //~ ERROR cannot assign } } @@ -14,7 +14,7 @@ fn example(&self, input: &i32) { // should not suggest here impl Hello for Test2 { fn example(&self, input: &i32) { // should not suggest here - self.0 += *input; + self.0 += *input; //~ ERROR cannot assign } }