Address unused tuple struct fields in the compiler

This commit is contained in:
Jake Goulding 2023-11-25 15:45:44 -05:00
parent 9f15a889f0
commit 87380cbc0c
4 changed files with 8 additions and 9 deletions

View File

@ -42,6 +42,7 @@ use rustc_target::abi::FieldIdx;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::marker::PhantomData;
use std::ops::Deref; use std::ops::Deref;
use std::rc::Rc; use std::rc::Rc;
@ -100,7 +101,7 @@ use renumber::RegionCtxt;
rustc_fluent_macro::fluent_messages! { "../messages.ftl" } rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
/// Associate some local constants with the `'tcx` lifetime /// Associate some local constants with the `'tcx` lifetime
struct TyCtxtConsts<'tcx>(TyCtxt<'tcx>); struct TyCtxtConsts<'tcx>(PhantomData<&'tcx ()>);
impl<'tcx> TyCtxtConsts<'tcx> { impl<'tcx> TyCtxtConsts<'tcx> {
const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref]; const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] = &[ProjectionElem::Deref];
} }

View File

@ -385,7 +385,7 @@ pub(crate) fn provide(providers: &mut Providers) {
enum Context { enum Context {
Safe, Safe,
/// in an `unsafe fn` /// in an `unsafe fn`
UnsafeFn(HirId), UnsafeFn,
/// in a *used* `unsafe` block /// in a *used* `unsafe` block
/// (i.e. a block without unused-unsafe warning) /// (i.e. a block without unused-unsafe warning)
UnsafeBlock(HirId), UnsafeBlock(HirId),
@ -407,7 +407,7 @@ impl<'tcx> intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'_, 'tcx> {
}; };
let unused_unsafe = match (self.context, used) { let unused_unsafe = match (self.context, used) {
(_, false) => UnusedUnsafe::Unused, (_, false) => UnusedUnsafe::Unused,
(Context::Safe, true) | (Context::UnsafeFn(_), true) => { (Context::Safe, true) | (Context::UnsafeFn, true) => {
let previous_context = self.context; let previous_context = self.context;
self.context = Context::UnsafeBlock(block.hir_id); self.context = Context::UnsafeBlock(block.hir_id);
intravisit::walk_block(self, block); intravisit::walk_block(self, block);
@ -454,7 +454,7 @@ fn check_unused_unsafe(
let body = tcx.hir().body(body_id); let body = tcx.hir().body(body_id);
let hir_id = tcx.local_def_id_to_hir_id(def_id); let hir_id = tcx.local_def_id_to_hir_id(def_id);
let context = match tcx.hir().fn_sig_by_hir_id(hir_id) { let context = match tcx.hir().fn_sig_by_hir_id(hir_id) {
Some(sig) if sig.header.unsafety == hir::Unsafety::Unsafe => Context::UnsafeFn(hir_id), Some(sig) if sig.header.unsafety == hir::Unsafety::Unsafe => Context::UnsafeFn,
_ => Context::Safe, _ => Context::Safe,
}; };

View File

@ -223,7 +223,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
// ``` // ```
// //
// In that case, the impl-trait is lowered as an additional generic parameter. // In that case, the impl-trait is lowered as an additional generic parameter.
self.with_impl_trait(ImplTraitContext::Universal(self.parent_def), |this| { self.with_impl_trait(ImplTraitContext::Universal, |this| {
visit::walk_generic_param(this, param) visit::walk_generic_param(this, param)
}); });
} }
@ -310,9 +310,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
if p.is_placeholder { if p.is_placeholder {
self.visit_macro_invoc(p.id) self.visit_macro_invoc(p.id)
} else { } else {
self.with_impl_trait(ImplTraitContext::Universal(self.parent_def), |this| { self.with_impl_trait(ImplTraitContext::Universal, |this| visit::walk_param(this, p))
visit::walk_param(this, p)
})
} }
} }

View File

@ -172,7 +172,7 @@ impl<'a> ParentScope<'a> {
#[derive(Copy, Debug, Clone)] #[derive(Copy, Debug, Clone)]
enum ImplTraitContext { enum ImplTraitContext {
Existential, Existential,
Universal(LocalDefId), Universal,
} }
#[derive(Debug)] #[derive(Debug)]