Checks for fields that are references used only to read one copyable subfield, and whose lifetimes are not used elsewhere.
Storing the reference instead of a copy of the subfield adds an unnecessary lifetime parameter to the struct. It also creates an unnecessary pointer dereference at runtime.
struct V<'cx, 'tcx> {
cx: &'cx LateContext<'tcx>,
}
impl<'cx, 'tcx> Visitor<'tcx> for V<'cx, 'tcx> {
type Map = rustc_middle::hir::map::Map<'tcx>;
type NestedFilter = rustc_middle::hir::nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map {
self.cx.tcx.hir()
}
}
Use instead:
struct V<'tcx> {
tcx: TyCtxt<'tcx>,
}
impl<'tcx> Visitor<'tcx> for V<'tcx> {
type Map = rustc_middle::hir::map::Map<'tcx>;
type NestedFilter = rustc_middle::hir::nested_filter::All;
fn nested_visit_map(&mut self) -> Self::Map {
self.tcx.hir()
}
}
lifetime_check: bool
(defaulttrue
): Setting this tofalse
disables the check that the lifetime use is unique. That is, the lint becomes a check for: fields that are references used only to read one copyable subfield.