Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
11c867e
Rename `negated` to `is_negated_pat`.
theemathas Jun 23, 2026
dcac715
Refactor negation handling in `TypeLimits` lints.
theemathas Jun 23, 2026
dd1bdbb
Add literal overflow lint test with repeated negations.
theemathas Jun 23, 2026
8d254b8
Fix `overflowing_literals` lint with repeated negation
theemathas Jun 23, 2026
9192337
semicolon_in_expressions_from_macros: Lint on non-local macros too
joshtriplett Jul 13, 2026
d376c08
chore: add codegen test for remainder match
amirHdev Jul 13, 2026
aa53fee
std_detect: Eliminate incorrect symlink in macro arm
joshtriplett Jul 13, 2026
1f5e4ba
Add Into<DefId> to is_descendant_of
camsteffen Jul 12, 2026
d26029d
Inline typed_def_id macro
camsteffen Jul 12, 2026
df3766d
Rename ModDefId to ModId
camsteffen Jul 12, 2026
3c0923a
Use ModId more
camsteffen Jul 12, 2026
60d52ca
Fix rustdoc with ModId refactors
camsteffen Jul 14, 2026
2c70f93
Fix clippy with ModId refactors
camsteffen Jul 14, 2026
e3f1e56
Implement `bool::toggle`
CenTdemeern1 Jul 14, 2026
b5a975d
Add tracking issue for `bool_toggle`
CenTdemeern1 Jul 14, 2026
3e03dd3
Apply suggested doc improvement for `bool::toggle`
CenTdemeern1 Jul 14, 2026
5724e6e
fix use-self-at-end in 2021 edition
jyn514 Jul 15, 2026
53c2cdd
limit tait-normalize to edition < 2021
jyn514 Jul 15, 2026
012970d
fix bad edition on 155202 delegation test
jyn514 Jul 15, 2026
0858f89
Add documentation for the `cold` and `track_caller` attributes
valentynkit Jun 27, 2026
9e25e3a
Fix ignore-llvm-version directive in codegen-llvm/array-equality.rs
zmodem Jul 15, 2026
8fdc29c
Rollup merge of #159197 - camsteffen:more-modid, r=petrochenkov
JonathanBrouwer Jul 15, 2026
ac05d38
Rollup merge of #159222 - joshtriplett:main, r=petrochenkov
JonathanBrouwer Jul 15, 2026
3e648f7
Rollup merge of #159296 - CenTdemeern1:bool_toggle, r=chenyukang
JonathanBrouwer Jul 15, 2026
68bc4b1
Rollup merge of #158302 - theemathas:neg-lit-lint, r=adwinwhite
JonathanBrouwer Jul 15, 2026
915f8ed
Rollup merge of #158484 - valentynkit:docs-cold-track-caller-attribut…
JonathanBrouwer Jul 15, 2026
298175f
Rollup merge of #159239 - amirHdev:add-codegen-test-rem-match-unreach…
JonathanBrouwer Jul 15, 2026
bd05c01
Rollup merge of #159330 - ferrocene:jyn/edition-fixes, r=nnethercote
JonathanBrouwer Jul 15, 2026
be99e06
Rollup merge of #159331 - zmodem:ignore_llvm_version_fix, r=mati865
JonathanBrouwer Jul 15, 2026
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
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ fn visibility_di_flags<'ll, 'tcx>(
match visibility {
Visibility::Public => DIFlags::FlagPublic,
// Private fields have a restricted visibility of the module containing the type.
Visibility::Restricted(did) if did == parent_did => DIFlags::FlagPrivate,
Visibility::Restricted(did) if did.to_def_id() == parent_did => DIFlags::FlagPrivate,
// `pub(crate)`/`pub(super)` visibilities are any other restricted visibility.
Visibility::Restricted(..) => DIFlags::FlagProtected,
}
Expand Down
10 changes: 3 additions & 7 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc_parse::MACRO_ARGUMENTS;
use rustc_parse::parser::Parser;
use rustc_session::Session;
use rustc_session::parse::ParseSess;
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
use rustc_span::def_id::{CrateNum, DefId, LocalDefId, ModId};
use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
use rustc_span::source_map::SourceMap;
Expand Down Expand Up @@ -274,11 +274,7 @@ impl<'cx> MacroExpanderResult<'cx> {
arm_span: Span,
macro_ident: Ident,
) -> Self {
// Emit the SEMICOLON_IN_EXPRESSIONS_FROM_MACROS deprecation lint.
let is_local = true;

let parser =
ParserAnyMacro::from_tts(cx, tts, site_span, arm_span, is_local, macro_ident, &[], &[]);
let parser = ParserAnyMacro::from_tts(cx, tts, site_span, arm_span, macro_ident, &[], &[]);
ExpandResult::Ready(Box::new(parser))
}
}
Expand Down Expand Up @@ -998,7 +994,7 @@ impl SyntaxExtension {
descr: Symbol,
kind: MacroKind,
macro_def_id: Option<DefId>,
parent_module: Option<DefId>,
parent_module: Option<ModId>,
) -> ExpnData {
ExpnData::new(
ExpnKind::Macro(kind, descr),
Expand Down
24 changes: 8 additions & 16 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ pub(crate) struct ParserAnyMacro<'a, 'b> {
lint_node_id: NodeId,
is_trailing_mac: bool,
arm_span: Span,
/// Whether or not this macro is defined in the current crate
is_local: bool,
bindings: &'b [MacroRule],
matched_rule_bindings: &'b [MatcherLoc],
}
Expand All @@ -73,7 +71,6 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> {
lint_node_id,
arm_span,
is_trailing_mac,
is_local,
bindings,
matched_rule_bindings,
} = *self;
Expand All @@ -99,14 +96,12 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> {
// `macro_rules! m { () => { panic!(); } }` isn't parsed by `.parse_expr()`,
// but `m!()` is allowed in expression positions (cf. issue #34706).
if kind == AstFragmentKind::Expr && parser.token == token::Semi {
if is_local {
parser.psess.buffer_lint(
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
parser.token.span,
lint_node_id,
diagnostics::TrailingMacro { is_trailing: is_trailing_mac, name: macro_ident },
);
}
parser.psess.buffer_lint(
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
parser.token.span,
lint_node_id,
diagnostics::TrailingMacro { is_trailing: is_trailing_mac, name: macro_ident },
);
parser.bump();
}

Expand All @@ -122,7 +117,6 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> {
tts: TokenStream,
site_span: Span,
arm_span: Span,
is_local: bool,
macro_ident: Ident,
// bindings and lhs is for diagnostics
bindings: &'b [MacroRule],
Expand All @@ -139,7 +133,6 @@ impl<'a, 'b> ParserAnyMacro<'a, 'b> {
lint_node_id: cx.current_expansion.lint_node_id,
is_trailing_mac: cx.current_expansion.is_trailing_mac,
arm_span,
is_local,
bindings,
matched_rule_bindings,
}
Expand Down Expand Up @@ -471,13 +464,12 @@ fn expand_macro<'cx, 'a: 'cx>(
trace_macros_note(&mut cx.expansions, sp, msg);
}

let is_local = is_defined_in_current_crate(node_id);
if is_local {
if is_defined_in_current_crate(node_id) {
cx.resolver.record_macro_rule_usage(node_id, rule_index);
}

// Let the context choose how to interpret the result. Weird, but useful for X-macros.
Box::new(ParserAnyMacro::from_tts(cx, tts, sp, arm_span, is_local, name, rules, lhs))
Box::new(ParserAnyMacro::from_tts(cx, tts, sp, arm_span, name, rules, lhs))
}
Err(CanRetry::No(guar)) => {
debug!("Will not retry matching as an error was emitted already");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub trait Visitor<'v>: Sized {
fn visit_pat_expr(&mut self, expr: &'v PatExpr<'v>) -> Self::Result {
walk_pat_expr(self, expr)
}
fn visit_lit(&mut self, _hir_id: HirId, _lit: Lit, _negated: bool) -> Self::Result {
fn visit_lit(&mut self, _hir_id: HirId, _lit: Lit, _is_negated_pat: bool) -> Self::Result {
Self::Result::output()
}
fn visit_anon_const(&mut self, c: &'v AnonConst) -> Self::Result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_middle::ty::{
TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized,
};
use rustc_span::Span;
use rustc_span::def_id::ModId;
use rustc_trait_selection::regions::InferCtxtRegionExt;
use rustc_trait_selection::traits::{ObligationCtxt, elaborate, normalize_param_env_or_error};

Expand Down Expand Up @@ -380,7 +381,7 @@ fn report_mismatched_rpitit_signature<'tcx>(
);
}

fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibility<DefId>> {
fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<ty::Visibility<ModId>> {
match *ty.kind() {
ty::Ref(_, ty, _) => type_visibility(tcx, ty),
ty::Adt(def, args) => {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use rustc_middle::ty::{
use rustc_middle::{bug, span_bug};
use rustc_session::diagnostics::feature_err;
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
use rustc_span::def_id::ModId;
use rustc_span::{DUMMY_SP, Ident, Span, kw, sym};
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::{self, FulfillmentError};
Expand Down Expand Up @@ -116,7 +117,7 @@ pub enum RegionInferReason<'a> {
pub struct InherentAssocCandidate {
pub impl_: DefId,
pub assoc_item: DefId,
pub scope: DefId,
pub scope: ModId,
}

pub struct ResolvedStructPath<'tcx> {
Expand Down Expand Up @@ -1806,7 +1807,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
ident: Ident,
assoc_tag: ty::AssocTag,
scope: DefId,
) -> Option<(ty::AssocItem, /*scope*/ DefId)> {
) -> Option<(ty::AssocItem, /*scope*/ ModId)> {
let tcx = self.tcx();

let (ident, def_scope) = tcx.adjust_ident_and_get_scope(ident, scope, self.item_def_id());
Expand All @@ -1826,7 +1827,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&self,
item_def_id: DefId,
ident: Ident,
scope: DefId,
scope: ModId,
block: HirId,
span: Span,
) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ impl UnreachablePub {
&& let parent_parent = cx
.tcx
.parent_module_from_def_id(cx.tcx.parent_module_from_def_id(def_id).into())
&& *restricted_did == parent_parent.to_local_def_id()
&& *restricted_did == parent_parent
&& !restricted_did.to_def_id().is_crate_root()
{
"pub(super)"
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::cell::Cell;

use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_data_structures::sync::par_join;
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
use rustc_hir::def_id::{LocalDefId, LocalModId};
use rustc_hir::{self as hir, AmbigArg, HirId, intravisit as hir_visit};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, TyCtxt};
Expand Down Expand Up @@ -151,8 +151,8 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
hir_visit::walk_pat(self, p);
}

fn visit_lit(&mut self, hir_id: HirId, lit: hir::Lit, negated: bool) {
lint_callback!(self, check_lit, hir_id, lit, negated);
fn visit_lit(&mut self, hir_id: HirId, lit: hir::Lit, is_negated_pat: bool) {
lint_callback!(self, check_lit, hir_id, lit, is_negated_pat);
}

fn visit_expr_field(&mut self, field: &'tcx hir::ExprField<'tcx>) {
Expand Down Expand Up @@ -335,7 +335,7 @@ crate::late_lint_methods!(impl_late_lint_pass, []);

pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
tcx: TyCtxt<'tcx>,
module_def_id: LocalModDefId,
mod_id: LocalModId,
builtin_lints: T,
) {
let context = LateContext {
Expand All @@ -344,7 +344,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
cached_typeck_results: Cell::new(None),
param_env: ty::ParamEnv::empty(),
effective_visibilities: tcx.effective_visibilities(()),
last_node_with_lint_attrs: tcx.local_def_id_to_hir_id(module_def_id),
last_node_with_lint_attrs: tcx.local_def_id_to_hir_id(mod_id),
generics: None,
only_module: true,
};
Expand All @@ -363,26 +363,26 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
let builtin_lints_must_run = is_lint_pass_required(skippable_lints, &builtin_lints.get_lints());
if passes.is_empty() {
if builtin_lints_must_run {
late_lint_mod_inner(tcx, module_def_id, context, builtin_lints);
late_lint_mod_inner(tcx, mod_id, context, builtin_lints);
}
} else {
if builtin_lints_must_run {
passes.push(Box::new(builtin_lints) as Box<dyn LateLintPass<'tcx>>);
}
let pass = RuntimeCombinedLateLintPass { passes };
late_lint_mod_inner(tcx, module_def_id, context, pass);
late_lint_mod_inner(tcx, mod_id, context, pass);
}
}

fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
tcx: TyCtxt<'tcx>,
module_def_id: LocalModDefId,
mod_id: LocalModId,
context: LateContext<'tcx>,
pass: T,
) {
let mut cx = LateContextAndPass { context, pass };

let (module, _span, hir_id) = tcx.hir_get_module(module_def_id);
let (module, _span, hir_id) = tcx.hir_get_module(mod_id);

cx.with_lint_attrs(hir_id, |cx| {
// There is no module lint that will have the crate itself as an item, so check it here.
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ use redundant_semicolon::*;
use reference_casting::*;
use runtime_symbols::*;
use rustc_data_structures::unord::UnordSet;
use rustc_hir::def_id::LocalModDefId;
use rustc_hir::def_id::LocalModId;
use rustc_middle::query::Providers;
use rustc_middle::ty::TyCtxt;
use shadowed_into_iter::ShadowedIntoIter;
Expand Down Expand Up @@ -154,8 +154,8 @@ pub fn provide(providers: &mut Providers) {
*providers = Providers { lint_mod, ..*providers };
}

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

early_lint_methods!(
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 @@ -21,7 +21,7 @@ macro_rules! late_lint_methods {
fn check_stmt(a: &'tcx rustc_hir::Stmt<'tcx>);
fn check_arm(a: &'tcx rustc_hir::Arm<'tcx>);
fn check_pat(a: &'tcx rustc_hir::Pat<'tcx>);
fn check_lit(hir_id: rustc_hir::HirId, a: rustc_hir::Lit, negated: bool);
fn check_lit(hir_id: rustc_hir::HirId, a: rustc_hir::Lit, is_negated_pat: bool);
fn check_expr(a: &'tcx rustc_hir::Expr<'tcx>);
fn check_expr_post(a: &'tcx rustc_hir::Expr<'tcx>);
fn check_ty(a: &'tcx rustc_hir::Ty<'tcx, rustc_hir::AmbigArg>);
Expand Down
47 changes: 31 additions & 16 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,15 @@ declare_lint! {

#[derive(Copy, Clone, Default)]
pub(crate) struct TypeLimits {
/// Id of the last visited negated expression
negated_expr_id: Option<hir::HirId>,
/// Span of the last visited negated expression
negated_expr_span: Option<Span>,
last_visited_negation: Option<NegationInfo>,
}

#[derive(Copy, Clone)]
struct NegationInfo {
/// A negation expression (a `rustc_hir::ExprKind::Unary`)
negation_span: Span,
/// The operand of the negation expression.
negated_id: hir::HirId,
}

impl_lint_pass!(TypeLimits => [
Expand All @@ -210,7 +215,7 @@ impl_lint_pass!(TypeLimits => [

impl TypeLimits {
pub(crate) fn new() -> TypeLimits {
TypeLimits { negated_expr_id: None, negated_expr_span: None }
TypeLimits { last_visited_negation: None }
}
}

Expand Down Expand Up @@ -539,22 +544,32 @@ fn lint_fn_pointer<'tcx>(
}

impl<'tcx> LateLintPass<'tcx> for TypeLimits {
fn check_lit(&mut self, cx: &LateContext<'tcx>, hir_id: HirId, lit: hir::Lit, negated: bool) {
if negated {
self.negated_expr_id = Some(hir_id);
self.negated_expr_span = Some(lit.span);
}
lint_literal(cx, self, hir_id, lit.span, &lit, negated);
fn check_lit(
&mut self,
cx: &LateContext<'tcx>,
hir_id: HirId,
lit: hir::Lit,
is_negated_pat: bool,
) {
let surrounding_negation = if is_negated_pat {
// In this case, lit.span refers to a `rustc_hir::hir::PatExprKind::Lit`,
// which includes the minus sign in front.
Some(lit.span)
} else if let Some(negation_info) = self.last_visited_negation
&& negation_info.negated_id == hir_id
{
Some(negation_info.negation_span)
} else {
None
};
lint_literal(cx, hir_id, lit.span, &lit, surrounding_negation);
}

fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) {
match e.kind {
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
// Propagate negation, if the negation itself isn't negated
if self.negated_expr_id != Some(e.hir_id) {
self.negated_expr_id = Some(expr.hir_id);
self.negated_expr_span = Some(e.span);
}
self.last_visited_negation =
Some(NegationInfo { negation_span: e.span, negated_id: expr.hir_id });
}
hir::ExprKind::Binary(binop, ref l, ref r) => {
if is_comparison(binop.node) {
Expand Down
Loading
Loading