Skip to content

Commit

Permalink
Address code reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
VulnBandit committed Oct 3, 2024
1 parent eb67ab7 commit e4a1ac5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_middle::ty::{self, Ty};
use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex};
use rustc_span::{BytePos, ExpnKind, MacroKind, Span};
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
use rustc_trait_selection::infer::InferCtxtExt;
use tracing::debug;

use crate::MirBorrowckCtxt;
Expand Down Expand Up @@ -270,6 +271,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if self.maybe_copy(original_path.ty(self.body, self.infcx.tcx).ty) {
// If the type may implement Copy, skip the error.
// It's an error with the Copy implementation (e.g. duplicate Copy) rather than borrow check
self.span_delayed_bug(
span,
"Type may implement copy, but there is no other error.",
);
return;
}
(
Expand Down Expand Up @@ -297,8 +302,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}

fn maybe_copy(&mut self, ty: Ty<'tcx>) -> bool {
use rustc_trait_selection::infer::InferCtxtExt;
let Some(copy_trait_def) = self.infcx.tcx.lang_items().copy_trait() else { return false };
// This is only going to be ambiguous if there are incoherent impls, because otherwise
// ambiguity should never happen in MIR.
self.infcx.type_implements_trait(copy_trait_def, [ty], self.param_env).may_apply()
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/derives/duplicate-derive-copy-clone-diagnostics.rs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
//~^ ERROR conflicting implementations of trait `Copy`
enum E {}

fn main() {}
fn main() {}
Empty file modified tests/ui/derives/duplicate-derive-copy-clone-diagnostics.stderr
100755 → 100644
Empty file.

0 comments on commit e4a1ac5

Please sign in to comment.