Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Use 'tcx for references to AccessLevels wherever possible. #73753

Merged
merged 1 commit into from
Jul 3, 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
4 changes: 2 additions & 2 deletions src/librustc_lint/array_into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ declare_lint_pass!(
ArrayIntoIter => [ARRAY_INTO_ITER]
);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIntoIter {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr<'tcx>) {
impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
// We only care about method call expressions.
if let hir::ExprKind::MethodCall(call, span, args, _) = &expr.kind {
if call.ident.name != sym::into_iter {
Expand Down
114 changes: 53 additions & 61 deletions src/librustc_lint/builtin.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/librustc_lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl LintStore {
}

/// Context for lint checking after type checking.
pub struct LateContext<'a, 'tcx> {
pub struct LateContext<'tcx> {
/// Type context we're checking in.
pub tcx: TyCtxt<'tcx>,

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

/// Items accessible from the crate being checked.
pub access_levels: &'a AccessLevels,
pub access_levels: &'tcx AccessLevels,

/// The store of registered lints and the lint levels.
pub lint_store: &'tcx LintStore,
Expand Down Expand Up @@ -624,7 +624,7 @@ impl<'a> EarlyContext<'a> {
}
}

impl LintContext for LateContext<'_, '_> {
impl LintContext for LateContext<'_> {
type PassObject = LateLintPassObject;

/// Gets the overall compiler `Session` object.
Expand Down Expand Up @@ -673,7 +673,7 @@ impl LintContext for EarlyContext<'_> {
}
}

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

impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> {
impl<'tcx> LayoutOf for LateContext<'tcx> {
type Ty = Ty<'tcx>;
type TyAndLayout = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;

Expand Down
10 changes: 5 additions & 5 deletions src/librustc_lint/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ declare_lint_pass!(TyTyKind => [
USAGE_OF_QUALIFIED_TY,
]);

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

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

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

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

fn is_ty_or_ty_ctxt(cx: &LateContext<'_, '_>, ty: &Ty<'_>) -> Option<String> {
fn is_ty_or_ty_ctxt(cx: &LateContext<'_>, ty: &Ty<'_>) -> Option<String> {
if let TyKind::Path(qpath) = &ty.kind {
if let QPath::Resolved(_, path) = qpath {
let did = path.res.opt_def_id()?;
Expand Down
32 changes: 15 additions & 17 deletions src/librustc_lint/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ macro_rules! lint_callback { ($cx:expr, $f:ident, $($args:expr),*) => ({
$cx.pass.$f(&$cx.context, $($args),*);
}) }

struct LateContextAndPass<'a, 'tcx, T: LateLintPass<'a, 'tcx>> {
context: LateContext<'a, 'tcx>,
struct LateContextAndPass<'tcx, T: LateLintPass<'tcx>> {
context: LateContext<'tcx>,
pass: T,
}

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

impl<'a, 'tcx, T: LateLintPass<'a, 'tcx>> hir_visit::Visitor<'tcx>
for LateContextAndPass<'a, 'tcx, T>
{
impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPass<'tcx, T> {
type Map = Map<'tcx>;

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

macro_rules! expand_late_lint_pass_impl_methods {
([$a:tt, $hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
$(fn $name(&mut self, context: &LateContext<$a, $hir>, $($param: $arg),*) {
([$hir:tt], [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
$(fn $name(&mut self, context: &LateContext<$hir>, $($param: $arg),*) {
for obj in self.lints.iter_mut() {
obj.$name(context, $($param),*);
}
Expand All @@ -358,16 +356,16 @@ macro_rules! expand_late_lint_pass_impl_methods {
}

macro_rules! late_lint_pass_impl {
([], [$hir:tt], $methods:tt) => (
impl<'a, $hir> LateLintPass<'a, $hir> for LateLintPassObjects<'_> {
expand_late_lint_pass_impl_methods!(['a, $hir], $methods);
([], [$hir:tt], $methods:tt) => {
impl<$hir> LateLintPass<$hir> for LateLintPassObjects<'_> {
expand_late_lint_pass_impl_methods!([$hir], $methods);
}
)
};
}

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

fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
module_def_id: LocalDefId,
pass: T,
Expand Down Expand Up @@ -397,7 +395,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
}
}

pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
module_def_id: LocalDefId,
builtin_lints: T,
Expand All @@ -417,7 +415,7 @@ pub fn late_lint_mod<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
}
}

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

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

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

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

/// Performs lint checking on a crate.
pub fn check_crate<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>(
pub fn check_crate<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
builtin_lints: impl FnOnce() -> T + Send,
) {
Expand Down
34 changes: 17 additions & 17 deletions src/librustc_lint/nonstandard_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum MethodLateContext {
PlainImpl,
}

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

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

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
fn check_mod(
&mut self,
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
_: &'tcx hir::Mod<'tcx>,
_: Span,
id: hir::HirId,
Expand Down Expand Up @@ -300,15 +300,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
}

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

fn check_fn(
&mut self,
cx: &LateContext<'_, '_>,
cx: &LateContext<'_>,
fk: FnKind<'_>,
_: &hir::FnDecl<'_>,
_: &hir::Body<'_>,
Expand Down Expand Up @@ -336,13 +336,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase {
}
}

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

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

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

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

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

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

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

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

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

fn check_generic_param(&mut self, cx: &LateContext<'_, '_>, param: &hir::GenericParam<'_>) {
fn check_generic_param(&mut self, cx: &LateContext<'_>, param: &hir::GenericParam<'_>) {
if let GenericParamKind::Const { .. } = param.kind {
NonUpperCaseGlobals::check_upper_case(cx, "const parameter", &param.name.ident());
}
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_lint/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ macro_rules! expand_lint_pass_methods {

macro_rules! declare_late_lint_pass {
([], [$hir:tt], [$($methods:tt)*]) => (
pub trait LateLintPass<'a, $hir>: LintPass {
expand_lint_pass_methods!(&LateContext<'a, $hir>, [$($methods)*]);
pub trait LateLintPass<$hir>: LintPass {
expand_lint_pass_methods!(&LateContext<$hir>, [$($methods)*]);
}
)
}

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

impl LateLintPass<'_, '_> for HardwiredLints {}
impl LateLintPass<'_> for HardwiredLints {}

#[macro_export]
macro_rules! expand_combined_late_lint_pass_method {
Expand All @@ -110,7 +110,7 @@ macro_rules! expand_combined_late_lint_pass_method {
#[macro_export]
macro_rules! expand_combined_late_lint_pass_methods {
($passes:tt, [$($(#[$attr:meta])* fn $name:ident($($param:ident: $arg:ty),*);)*]) => (
$(fn $name(&mut self, context: &LateContext<'a, 'tcx>, $($param: $arg),*) {
$(fn $name(&mut self, context: &LateContext<'tcx>, $($param: $arg),*) {
expand_combined_late_lint_pass_method!($passes, self, $name, (context, $($param),*));
})*
)
Expand Down Expand Up @@ -138,7 +138,7 @@ macro_rules! declare_combined_late_lint_pass {
}
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $name {
impl<'tcx> LateLintPass<'tcx> for $name {
expand_combined_late_lint_pass_methods!([$($passes),*], $methods);
}

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