Skip to content

Commit d6bfca2

Browse files
authored
Rollup merge of #73753 - eddyb:extraneous-lifetime, r=Manishearth
Use 'tcx for references to AccessLevels wherever possible. Most of the changes are just fallout from removing a lifetime parameter from structs, and mostly in clippy. r? @Manishearth
2 parents 2d83cbb + 874f406 commit d6bfca2

File tree

173 files changed

+1143
-1267
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+1143
-1267
lines changed

src/librustc_lint/array_into_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ declare_lint_pass!(
2121
ArrayIntoIter => [ARRAY_INTO_ITER]
2222
);
2323

24-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter {
25-
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'tcx>) {
24+
impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
25+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
2626
// We only care about method call expressions.
2727
if let hir::ExprKind::MethodCall(call, span, args, _) = &expr.kind {
2828
if call.ident.name != sym::into_iter {

src/librustc_lint/builtin.rs

+53-61
Large diffs are not rendered by default.

src/librustc_lint/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl LintStore {
421421
}
422422

423423
/// Context for lint checking after type checking.
424-
pub struct LateContext<'a, 'tcx> {
424+
pub struct LateContext<'tcx> {
425425
/// Type context we're checking in.
426426
pub tcx: TyCtxt<'tcx>,
427427

@@ -438,7 +438,7 @@ pub struct LateContext<'a, 'tcx> {
438438
pub param_env: ty::ParamEnv<'tcx>,
439439

440440
/// Items accessible from the crate being checked.
441-
pub access_levels: &'a AccessLevels,
441+
pub access_levels: &'tcx AccessLevels,
442442

443443
/// The store of registered lints and the lint levels.
444444
pub lint_store: &'tcx LintStore,
@@ -624,7 +624,7 @@ impl<'a> EarlyContext<'a> {
624624
}
625625
}
626626

627-
impl LintContext for LateContext<'_, '_> {
627+
impl LintContext for LateContext<'_> {
628628
type PassObject = LateLintPassObject;
629629

630630
/// Gets the overall compiler `Session` object.
@@ -673,7 +673,7 @@ impl LintContext for EarlyContext<'_> {
673673
}
674674
}
675675

676-
impl<'a, 'tcx> LateContext<'a, 'tcx> {
676+
impl<'tcx> LateContext<'tcx> {
677677
/// Gets the type-checking side-tables for the current body,
678678
/// or `None` if outside a body.
679679
pub fn maybe_typeck_tables(&self) -> Option<&'tcx ty::TypeckTables<'tcx>> {
@@ -849,7 +849,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
849849
}
850850
}
851851

852-
impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> {
852+
impl<'tcx> LayoutOf for LateContext<'tcx> {
853853
type Ty = Ty<'tcx>;
854854
type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
855855

src/librustc_lint/internal.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ declare_lint_pass!(TyTyKind => [
8484
USAGE_OF_QUALIFIED_TY,
8585
]);
8686

87-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
88-
fn check_path(&mut self, cx: &LateContext<'_, '_>, path: &'tcx Path<'tcx>, _: HirId) {
87+
impl<'tcx> LateLintPass<'tcx> for TyTyKind {
88+
fn check_path(&mut self, cx: &LateContext<'_>, path: &'tcx Path<'tcx>, _: HirId) {
8989
let segments = path.segments.iter().rev().skip(1).rev();
9090

9191
if let Some(last) = segments.last() {
@@ -105,7 +105,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
105105
}
106106
}
107107

108-
fn check_ty(&mut self, cx: &LateContext<'_, '_>, ty: &'tcx Ty<'tcx>) {
108+
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx Ty<'tcx>) {
109109
match &ty.kind {
110110
TyKind::Path(qpath) => {
111111
if let QPath::Resolved(_, path) = qpath {
@@ -164,7 +164,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TyTyKind {
164164
}
165165
}
166166

167-
fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment<'_>) -> bool {
167+
fn lint_ty_kind_usage(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> bool {
168168
if let Some(res) = segment.res {
169169
if let Some(did) = res.opt_def_id() {
170170
return cx.tcx.is_diagnostic_item(sym::TyKind, did);
@@ -174,7 +174,7 @@ fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment<'_>) -> bo
174174
false
175175
}
176176

177-
fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty<'_>) -> Option<String> {
177+
fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, ty: &Ty<'_>) -> Option<String> {
178178
if let TyKind::Path(qpath) = &ty.kind {
179179
if let QPath::Resolved(_, path) = qpath {
180180
let did = path.res.opt_def_id()?;

src/librustc_lint/late.rs

+15-17
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
4444
$cx.pass.$f(&$cx.context, $($args),*);
4545
}) }
4646

47-
struct LateContextAndPass<'a, 'tcx, T: LateLintPass<'a, 'tcx>> {
48-
context: LateContext<'a, 'tcx>,
47+
struct LateContextAndPass<'tcx, T: LateLintPass<'tcx>> {
48+
context: LateContext<'tcx>,
4949
pass: T,
5050
}
5151

52-
impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {
52+
impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
5353
/// Merge the lints specified by any lint attributes into the
5454
/// current lint context, call the provided function, then reset the
5555
/// lints in effect to their previous state.
@@ -93,9 +93,7 @@ impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> LateContextAndPass<'a, 'tcx, T> {
9393
}
9494
}
9595

96-
impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
97-
for LateContextAndPass<'a, 'tcx, T>
98-
{
96+
impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPass<'tcx, T> {
9997
type Map = Map<'tcx>;
10098

10199
/// Because lints are scoped lexically, we want to walk nested
@@ -348,8 +346,8 @@ impl LintPass for LateLintPassObjects<'_> {
348346
}
349347

350348
macro_rules! expand_late_lint_pass_impl_methods {
351-
([$a:tt, $hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
352-
$(fn $name(&mut self, context: &LateContext<$a, $hir>, $($param: $arg),*) {
349+
([$hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
350+
$(fn $name(&mut self, context: &LateContext<$hir>, $($param: $arg),*) {
353351
for obj in self.lints.iter_mut() {
354352
obj.$name(context, $($param),*);
355353
}
@@ -358,16 +356,16 @@ macro_rules! expand_late_lint_pass_impl_methods {
358356
}
359357

360358
macro_rules! late_lint_pass_impl {
361-
([], [$hir:tt], $methods:tt) => (
362-
impl<'a, $hir> LateLintPass<'a, $hir> for LateLintPassObjects<'_> {
363-
expand_late_lint_pass_impl_methods!(['a, $hir], $methods);
359+
([], [$hir:tt], $methods:tt) => {
360+
impl<$hir> LateLintPass<$hir> for LateLintPassObjects<'_> {
361+
expand_late_lint_pass_impl_methods!([$hir], $methods);
364362
}
365-
)
363+
};
366364
}
367365

368366
crate::late_lint_methods!(late_lint_pass_impl, [], ['tcx]);
369367

370-
fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
368+
fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
371369
tcx: TyCtxt<'tcx>,
372370
module_def_id: LocalDefId,
373371
pass: T,
@@ -397,7 +395,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
397395
}
398396
}
399397

400-
pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
398+
pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx>>(
401399
tcx: TyCtxt<'tcx>,
402400
module_def_id: LocalDefId,
403401
builtin_lints: T,
@@ -417,7 +415,7 @@ pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
417415
}
418416
}
419417

420-
fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx>, pass: T) {
418+
fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T) {
421419
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
422420

423421
let krate = tcx.hir().krate();
@@ -448,7 +446,7 @@ fn late_lint_pass_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tc
448446
})
449447
}
450448

451-
fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints: T) {
449+
fn late_lint_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints: T) {
452450
let mut passes = unerased_lint_store(tcx).late_passes.iter().map(|p| (p)()).collect::<Vec<_>>();
453451

454452
if !tcx.sess.opts.debugging_opts.no_interleave_lints {
@@ -478,7 +476,7 @@ fn late_lint_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(tcx: TyCtxt<'tcx>, b
478476
}
479477

480478
/// Performs lint checking on a crate.
481-
pub fn check_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
479+
pub fn check_crate<'tcx, T: LateLintPass<'tcx>>(
482480
tcx: TyCtxt<'tcx>,
483481
builtin_lints: impl FnOnce() -> T + Send,
484482
) {

src/librustc_lint/nonstandard_style.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub enum MethodLateContext {
1818
PlainImpl,
1919
}
2020

21-
pub fn method_context(cx: &LateContext<'_, '_>, id: hir::HirId) -> MethodLateContext {
21+
pub fn method_context(cx: &LateContext<'_>, id: hir::HirId) -> MethodLateContext {
2222
let def_id = cx.tcx.hir().local_def_id(id);
2323
let item = cx.tcx.associated_item(def_id);
2424
match item.container {
@@ -200,7 +200,7 @@ impl NonSnakeCase {
200200
}
201201

202202
/// Checks if a given identifier is snake case, and reports a diagnostic if not.
203-
fn check_snake_case(&self, cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
203+
fn check_snake_case(&self, cx: &LateContext<'_>, sort: &str, ident: &Ident) {
204204
fn is_snake_case(ident: &str) -> bool {
205205
if ident.is_empty() {
206206
return true;
@@ -248,10 +248,10 @@ impl NonSnakeCase {
248248
}
249249
}
250250

251-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
251+
impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
252252
fn check_mod(
253253
&mut self,
254-
cx: &LateContext<'_, '_>,
254+
cx: &LateContext<'_>,
255255
_: &'tcx hir::Mod<'tcx>,
256256
_: Span,
257257
id: hir::HirId,
@@ -300,15 +300,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
300300
}
301301
}
302302

303-
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam<'_>) {
303+
fn check_generic_param(&mut self, cx: &LateContext<'_>, param: &hir::GenericParam<'_>) {
304304
if let GenericParamKind::Lifetime { .. } = param.kind {
305305
self.check_snake_case(cx, "lifetime", &param.name.ident());
306306
}
307307
}
308308

309309
fn check_fn(
310310
&mut self,
311-
cx: &LateContext<'_, '_>,
311+
cx: &LateContext<'_>,
312312
fk: FnKind<'_>,
313313
_: &hir::FnDecl<'_>,
314314
_: &hir::Body<'_>,
@@ -336,13 +336,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
336336
}
337337
}
338338

339-
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
339+
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
340340
if let hir::ItemKind::Mod(_) = it.kind {
341341
self.check_snake_case(cx, "module", &it.ident);
342342
}
343343
}
344344

345-
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, item: &hir::TraitItem<'_>) {
345+
fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &hir::TraitItem<'_>) {
346346
if let hir::TraitItemKind::Fn(_, hir::TraitFn::Required(pnames)) = item.kind {
347347
self.check_snake_case(cx, "trait method", &item.ident);
348348
for param_name in pnames {
@@ -351,7 +351,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
351351
}
352352
}
353353

354-
fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat<'_>) {
354+
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
355355
if let &PatKind::Binding(_, hid, ident, _) = &p.kind {
356356
if let hir::Node::Pat(parent_pat) = cx.tcx.hir().get(cx.tcx.hir().get_parent_node(hid))
357357
{
@@ -370,7 +370,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
370370
}
371371
}
372372

373-
fn check_struct_def(&mut self, cx: &LateContext<'_, '_>, s: &hir::VariantData<'_>) {
373+
fn check_struct_def(&mut self, cx: &LateContext<'_>, s: &hir::VariantData<'_>) {
374374
for sf in s.fields() {
375375
self.check_snake_case(cx, "structure field", &sf.ident);
376376
}
@@ -386,7 +386,7 @@ declare_lint! {
386386
declare_lint_pass!(NonUpperCaseGlobals => [NON_UPPER_CASE_GLOBALS]);
387387

388388
impl NonUpperCaseGlobals {
389-
fn check_upper_case(cx: &LateContext<'_, '_>, sort: &str, ident: &Ident) {
389+
fn check_upper_case(cx: &LateContext<'_>, sort: &str, ident: &Ident) {
390390
let name = &ident.name.as_str();
391391
if name.chars().any(|c| c.is_lowercase()) {
392392
cx.struct_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, |lint| {
@@ -404,8 +404,8 @@ impl NonUpperCaseGlobals {
404404
}
405405
}
406406

407-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
408-
fn check_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::Item<'_>) {
407+
impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
408+
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
409409
match it.kind {
410410
hir::ItemKind::Static(..) if !attr::contains_name(&it.attrs, sym::no_mangle) => {
411411
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &it.ident);
@@ -417,19 +417,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
417417
}
418418
}
419419

420-
fn check_trait_item(&mut self, cx: &LateContext<'_, '_>, ti: &hir::TraitItem<'_>) {
420+
fn check_trait_item(&mut self, cx: &LateContext<'_>, ti: &hir::TraitItem<'_>) {
421421
if let hir::TraitItemKind::Const(..) = ti.kind {
422422
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ti.ident);
423423
}
424424
}
425425

426-
fn check_impl_item(&mut self, cx: &LateContext<'_, '_>, ii: &hir::ImplItem<'_>) {
426+
fn check_impl_item(&mut self, cx: &LateContext<'_>, ii: &hir::ImplItem<'_>) {
427427
if let hir::ImplItemKind::Const(..) = ii.kind {
428428
NonUpperCaseGlobals::check_upper_case(cx, "associated constant", &ii.ident);
429429
}
430430
}
431431

432-
fn check_pat(&mut self, cx: &LateContext<'_, '_>, p: &hir::Pat<'_>) {
432+
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
433433
// Lint for constants that look like binding identifiers (#7526)
434434
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.kind {
435435
if let Res::Def(DefKind::Const, _) = path.res {
@@ -444,7 +444,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals {
444444
}
445445
}
446446

447-
fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam<'_>) {
447+
fn check_generic_param(&mut self, cx: &LateContext<'_>, param: &hir::GenericParam<'_>) {
448448
if let GenericParamKind::Const { .. } = param.kind {
449449
NonUpperCaseGlobals::check_upper_case(cx, "const parameter", &param.name.ident());
450450
}

src/librustc_lint/passes.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ macro_rules! expand_lint_pass_methods {
9090

9191
macro_rules! declare_late_lint_pass {
9292
([], [$hir:tt], [$($methods:tt)*]) => (
93-
pub trait LateLintPass<'a, $hir>: LintPass {
94-
expand_lint_pass_methods!(&LateContext<'a, $hir>, [$($methods)*]);
93+
pub trait LateLintPass<$hir>: LintPass {
94+
expand_lint_pass_methods!(&LateContext<$hir>, [$($methods)*]);
9595
}
9696
)
9797
}
9898

9999
late_lint_methods!(declare_late_lint_pass, [], ['tcx]);
100100

101-
impl LateLintPass<'_, '_> for HardwiredLints {}
101+
impl LateLintPass<'_> for HardwiredLints {}
102102

103103
#[macro_export]
104104
macro_rules! expand_combined_late_lint_pass_method {
@@ -110,7 +110,7 @@ macro_rules! expand_combined_late_lint_pass_method {
110110
#[macro_export]
111111
macro_rules! expand_combined_late_lint_pass_methods {
112112
($passes:tt, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
113-
$(fn $name(&mut self, context: &LateContext<'a, 'tcx>, $($param: $arg),*) {
113+
$(fn $name(&mut self, context: &LateContext<'tcx>, $($param: $arg),*) {
114114
expand_combined_late_lint_pass_method!($passes, self, $name, (context, $($param),*));
115115
})*
116116
)
@@ -138,7 +138,7 @@ macro_rules! declare_combined_late_lint_pass {
138138
}
139139
}
140140

141-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $name {
141+
impl<'tcx> LateLintPass<'tcx> for $name {
142142
expand_combined_late_lint_pass_methods!([$($passes),*], $methods);
143143
}
144144

@@ -282,4 +282,4 @@ macro_rules! declare_combined_early_lint_pass {
282282
/// A lint pass boxed up as a trait object.
283283
pub type EarlyLintPassObject = Box<dyn EarlyLintPass + sync::Send + sync::Sync + 'static>;
284284
pub type LateLintPassObject =
285-
Box<dyn for<'a, 'tcx> LateLintPass<'a, 'tcx> + sync::Send + sync::Sync + 'static>;
285+
Box<dyn for<'tcx> LateLintPass<'tcx> + sync::Send + sync::Sync + 'static>;

0 commit comments

Comments
 (0)