Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

more LocalDefIds #72299

Merged
merged 1 commit into from
May 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {

sess.time("MIR_effect_checking", || {
for def_id in tcx.body_owners() {
mir::transform::check_unsafety::check_unsafety(tcx, def_id.to_def_id())
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
}
});

Expand Down
10 changes: 8 additions & 2 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,14 @@ rustc_queries! {
storage(ArenaCacheSelector<'tcx>)
}

/// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
query unsafe_derive_on_repr_packed(_: DefId) -> () {}
/// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error.
///
/// Unsafety checking is executed for each method separately, but we only want
/// to emit this error once per derive. As there are some impls with multiple
/// methods, we use a query for deduplication.
query unsafe_derive_on_repr_packed(key: LocalDefId) -> () {
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) }
}

/// The signature of functions and closures.
query fn_sig(_: DefId) -> ty::PolyFnSig<'tcx> {}
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,8 @@ fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckRe
}
}

fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: DefId) {
let lint_hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let lint_hir_id = tcx.hir().as_local_hir_id(def_id);

tcx.struct_span_lint_hir(SAFE_PACKED_BORROWS, lint_hir_id, tcx.def_span(def_id), |lint| {
// FIXME: when we make this a hard error, this should have its
Expand Down Expand Up @@ -659,16 +659,15 @@ fn builtin_derive_def_id(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
}
}

pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: LocalDefId) {
debug!("check_unsafety({:?})", def_id);

// closures are handled by their parent fn.
if tcx.is_closure(def_id) {
if tcx.is_closure(def_id.to_def_id()) {
return;
}

let UnsafetyCheckResult { violations, unsafe_blocks } =
tcx.unsafety_check_result(def_id.expect_local());
let UnsafetyCheckResult { violations, unsafe_blocks } = tcx.unsafety_check_result(def_id);

for &UnsafetyViolation { source_info, lint_root, description, details, kind } in
violations.iter()
Expand All @@ -693,8 +692,10 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) {
.emit();
}
UnsafetyViolationKind::BorrowPacked => {
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) {
tcx.ensure().unsafe_derive_on_repr_packed(impl_def_id);
if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id.to_def_id()) {
// If a method is defined in the local crate,
// the impl containing that method should also be.
tcx.ensure().unsafe_derive_on_repr_packed(impl_def_id.expect_local());
} else {
tcx.struct_span_lint_hir(
SAFE_PACKED_BORROWS,
Expand Down