Skip to content
Closed
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
22 changes: 21 additions & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2866,7 +2866,27 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
did,
path.segments.last().unwrap(),
);
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))

if self.tcx().generics_of(did).own_synthetic_params_count() == 0 {
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
} else {
let tcx = self.tcx();
let generics = tcx.generics_of(did);

// Use infer tys for synthetic params; otherwise the impl header's trait ref may
// contain callee-owned synthetic params and fail when instantiated with impl args.
// See issue #155834
let args = args.iter().enumerate().map(|(index, arg)| {
let param = generics.param_at(index, tcx);
if param.kind.is_synthetic() {
self.ty_infer(Some(param), span).into()
} else {
arg
}
});

ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
}
}

// Exhaustive match to be clear about what exactly we're considering to be
Expand Down
72 changes: 44 additions & 28 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,39 @@ type LateLintPassFactory =
Box<dyn for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx> + sync::DynSend + sync::DynSync>;

/// Information about the registered lints.
//
// About the pass factories: these should only be called once, but since we
// want to avoid locks or interior mutability, we don't enforce this. Lints
// should, in theory, be compatible with being constructed more than once,
// though not necessarily in a sane manner. This is safe though.
pub struct LintStore {
/// Registered lints.
lints: Vec<&'static Lint>,

/// Constructor functions for each variety of lint pass.
/// This lint pass kind is softly deprecated. It misses expanded code and has caused a few
/// errors in the past. Currently, it is only used in Clippy. New implementations
/// should avoid using this interface, as it might be removed in the future.
///
/// * See [rust#69838](https://github.com/rust-lang/rust/pull/69838)
/// * See [rust-clippy#5518](https://github.com/rust-lang/rust-clippy/pull/5518)
pub(crate) pre_expansion_lint_passes: Vec<EarlyLintPassFactory>,

/// These lint passes run on AST nodes.
pub(crate) early_lint_passes: Vec<EarlyLintPassFactory>,

/// These lint passes run on HIR nodes. Each one processes an entire crate. They don't benefit
/// from incremental compilation. `late_lint_mod_passes` should be used in preference where
/// possible; only use `late_lint_passes` for lints that implement `check_crate` and/or
/// `check_crate_post` and accumulate cross-module state.
///
/// These should only be called once, but since we want to avoid locks or
/// interior mutability, we don't enforce this (and lints should, in theory,
/// be compatible with being constructed more than once, though not
/// necessarily in a sane manner. This is safe though.)
pub pre_expansion_passes: Vec<EarlyLintPassFactory>,
pub early_passes: Vec<EarlyLintPassFactory>,
pub late_passes: Vec<LateLintPassFactory>,
/// This is unique in that we construct them per-module, so not once.
pub late_module_passes: Vec<LateLintPassFactory>,
/// The exception is Clippy, which uses `late_lint_passes` for all late lint passes. It needs
/// `check_crate`/`check_crate_post` for some of its lints and uses late lint passes throughout
/// for consistency. This is ok because Clippy isn't wired for incremental compilation.
pub(crate) late_lint_passes: Vec<LateLintPassFactory>,

/// These lint passes run on HIR nodes, and are constructed per-module (i.e. multiple times).
/// They benefit from incremental compilation.
pub(crate) late_lint_mod_passes: Vec<LateLintPassFactory>,

/// Lints indexed by name.
by_name: UnordMap<String, TargetLint>,
Expand Down Expand Up @@ -136,10 +154,10 @@ impl LintStore {
pub fn new() -> LintStore {
LintStore {
lints: vec![],
pre_expansion_passes: vec![],
early_passes: vec![],
late_passes: vec![],
late_module_passes: vec![],
pre_expansion_lint_passes: vec![],
early_lint_passes: vec![],
late_lint_passes: vec![],
late_lint_mod_passes: vec![],
by_name: Default::default(),
lint_groups: Default::default(),
}
Expand All @@ -166,26 +184,24 @@ impl LintStore {
self.lint_groups.keys().copied()
}

pub fn register_early_pass(&mut self, pass: EarlyLintPassFactory) {
self.early_passes.push(pass);
/// See the comment on `LintStore::pre_expansion_lint_passes`.
pub fn register_pre_expansion_lint_pass(&mut self, pass: EarlyLintPassFactory) {
self.pre_expansion_lint_passes.push(pass);
}

/// This lint pass is softly deprecated. It misses expanded code and has caused a few
/// errors in the past. Currently, it is only used in Clippy. New implementations
/// should avoid using this interface, as it might be removed in the future.
///
/// * See [rust#69838](https://github.com/rust-lang/rust/pull/69838)
/// * See [rust-clippy#5518](https://github.com/rust-lang/rust-clippy/pull/5518)
pub fn register_pre_expansion_pass(&mut self, pass: EarlyLintPassFactory) {
self.pre_expansion_passes.push(pass);
/// See the comment on `LintStore::early_lint_passes`.
pub fn register_early_lint_pass(&mut self, pass: EarlyLintPassFactory) {
self.early_lint_passes.push(pass);
}

pub fn register_late_pass(&mut self, pass: LateLintPassFactory) {
self.late_passes.push(pass);
/// See the comment on `LintStore::late_lint_passes`.
pub fn register_late_lint_pass(&mut self, pass: LateLintPassFactory) {
self.late_lint_passes.push(pass);
}

pub fn register_late_mod_pass(&mut self, pass: LateLintPassFactory) {
self.late_module_passes.push(pass);
/// See the comment on `LintStore::late_lint_mod_passes`.
pub fn register_late_lint_mod_pass(&mut self, pass: LateLintPassFactory) {
self.late_lint_mod_passes.push(pass);
}

/// Helper method for register_early/late_pass
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ pub fn check_ast_node<'a>(

let context = if pre_expansion {
let builtin_lints = crate::BuiltinCombinedPreExpansionLintPass::new();
let passes = &lint_store.pre_expansion_passes;
let passes = &lint_store.pre_expansion_lint_passes;
run_passes(check_node, context, builtin_lints, passes)
} else {
let builtin_lints = crate::BuiltinCombinedEarlyLintPass::new();
let passes = &lint_store.early_passes;
let passes = &lint_store.early_lint_passes;
run_passes(check_node, context, builtin_lints, passes)
};

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
// `builtin_lints` directly rather than bundling it up into the
// `RuntimeCombinedLateLintPass`.
let mut passes: Vec<_> = unerased_lint_store(tcx.sess)
.late_module_passes
.late_lint_mod_passes
.iter()
.map(|mk_pass| mk_pass(tcx))
.filter(|pass| is_lint_pass_required(skippable_lints, &pass.get_lints()))
Expand Down Expand Up @@ -403,7 +403,7 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {

// Note: `passes` is often empty after filtering.
let passes: Vec<_> = unerased_lint_store(tcx.sess)
.late_passes
.late_lint_passes
.iter()
.map(|mk_pass| mk_pass(tcx))
.filter(|pass| is_lint_pass_required(skippable_lints, &pass.get_lints()))
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn provide(providers: &mut Providers) {
}

fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
late_lint_mod(tcx, module_def_id, BuiltinCombinedLateLintModPass::new());
}

early_lint_methods!(
Expand Down Expand Up @@ -207,7 +207,7 @@ early_lint_methods!(
late_lint_methods!(
declare_combined_late_lint_pass,
[
BuiltinCombinedModuleLateLintPass,
BuiltinCombinedLateLintModPass,
[
ForLoopsOverFallibles: ForLoopsOverFallibles,
DefaultCouldBeDerived: DefaultCouldBeDerived,
Expand Down Expand Up @@ -279,7 +279,7 @@ late_lint_methods!(
late_lint_methods!(
declare_combined_late_lint_pass,
[
InternalCombinedModuleLateLintPass,
InternalCombinedLateLintModPass,
[
DefaultHashTypes: DefaultHashTypes,
QueryStability: QueryStability,
Expand Down Expand Up @@ -317,7 +317,7 @@ fn register_builtins(store: &mut LintStore) {

store.register_lints(&BuiltinCombinedPreExpansionLintPass::lint_vec());
store.register_lints(&BuiltinCombinedEarlyLintPass::lint_vec());
store.register_lints(&BuiltinCombinedModuleLateLintPass::lint_vec());
store.register_lints(&BuiltinCombinedLateLintModPass::lint_vec());
store.register_lints(&foreign_modules::lint_vec());
store.register_lints(&hardwired::lint_vec());

Expand Down Expand Up @@ -698,10 +698,12 @@ fn register_builtins(store: &mut LintStore) {

fn register_internals(store: &mut LintStore) {
store.register_lints(&InternalCombinedEarlyLintPass::lint_vec());
store.register_early_pass(Box::new(|| Box::new(InternalCombinedEarlyLintPass::new())));
store.register_early_lint_pass(Box::new(|| Box::new(InternalCombinedEarlyLintPass::new())));

store.register_lints(&InternalCombinedModuleLateLintPass::lint_vec());
store.register_late_mod_pass(Box::new(|_| Box::new(InternalCombinedModuleLateLintPass::new())));
store.register_lints(&InternalCombinedLateLintModPass::lint_vec());
store.register_late_lint_mod_pass(Box::new(|_| {
Box::new(InternalCombinedLateLintModPass::new())
}));

store.register_group(
false,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ macro_rules! expand_combined_early_lint_pass_methods {
/// Combines multiple lints passes into a single lint pass, at compile time,
/// for maximum speed. Each `check_foo` method in `$methods` within this pass
/// simply calls `check_foo` once per `$pass`. Compare with
/// `EarlyLintPassObjects`, which is similar, but combines lint passes at
/// `RuntimeCombinedEarlyLintPass`, which is similar, but combines lint passes at
/// runtime.
#[macro_export]
macro_rules! declare_combined_early_lint_pass {
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ pub const trait Destruct: PointeeSized {}
///
/// The implementation of this trait is built-in and cannot be implemented
/// for any user type.
#[unstable(feature = "tuple_trait", issue = "none")]
#[unstable(feature = "tuple_trait", issue = "157987")]
#[lang = "tuple_trait"]
#[diagnostic::on_unimplemented(message = "`{Self}` is not a tuple")]
#[rustc_deny_explicit_impl]
Expand Down
Loading
Loading