Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
175c8f5
Implement `#[diagnostic_on_unknown]` for modules.
mejrs Jun 15, 2026
2d2e0a7
implement `Unresolved` format argument for diagnostic::on_unknown
mejrs Jun 15, 2026
b74e8ff
Properly handle multiple import errors in the same use tree
mejrs Jun 15, 2026
e0db479
gently massage the imports
mejrs Jun 15, 2026
42fdfb2
Move `throw_unresolved_import_error` to `rustc_resolve/error_helper.rs`
mejrs Jun 16, 2026
5d1d926
lazily load `diagnostic::on_unknown` from foreign modules
mejrs Jun 17, 2026
f46a9da
Point to the unstable segment of an import path instead of to the who…
oli-obk Jun 18, 2026
443c0ba
Move `on_unknown` attribute data to resolver
mejrs Jun 18, 2026
b130dd1
`-Znext-solver` Emit error instead of ICE when combining {int, float}…
ShoyuVanilla Jun 18, 2026
fd26bd9
std: use correct low surrogate range in Windows standard I/O code
joboet Jun 19, 2026
2203dd7
std: correctly report file size on UWP
joboet Jun 19, 2026
1f15206
ensure the new solver bootstraps
lqd Jun 19, 2026
c390ede
change pre-stabilization job name
lqd Jun 19, 2026
c06ec63
Rename `lint-rust-version` to `hint-msrv`
jamie-osec Jun 19, 2026
0d72821
Remove redundant check for `#[loop_match]`
obeis Jun 19, 2026
620bf09
Remove redundant check for `#[const_continue]`
obeis Jun 19, 2026
4b0167b
Rollup merge of #158129 - lqd:bootstrap-new-solver, r=Kobzol
JonathanBrouwer Jun 19, 2026
a3d0568
Rollup merge of #158134 - clubby789:update-msrv-flag, r=JonathanBrouwer
JonathanBrouwer Jun 19, 2026
fae6884
Rollup merge of #157926 - mejrs:on_unknown_module, r=petrochenkov
JonathanBrouwer Jun 19, 2026
d7e8f9f
Rollup merge of #158075 - oli-obk:confusing-stability, r=mejrs
JonathanBrouwer Jun 19, 2026
b2b7df3
Rollup merge of #158084 - ShoyuVanilla:issue-158064, r=lcnr
JonathanBrouwer Jun 19, 2026
b10255a
Rollup merge of #158128 - joboet:windows_low_surrogate, r=ChrisDenton
JonathanBrouwer Jun 19, 2026
0c1cae8
Rollup merge of #158132 - joboet:windows-uwp-filesize, r=ChrisDenton
JonathanBrouwer Jun 19, 2026
2c5fdb9
Rollup merge of #158138 - obeis:move-check-loop-match, r=JonathanBrouwer
JonathanBrouwer Jun 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ fn parse_arg(

(Mode::DiagnosticOnTypeError, sym::Found) => FormatArg::Found,
(Mode::DiagnosticOnTypeError, sym::Expected) => FormatArg::Expected,
(Mode::DiagnosticOnUnknown, sym::Unresolved) => FormatArg::Unresolved,

// Some diagnostic attributes can use `{This}` to refer to the annotated item.
// For those that don't, we continue and maybe use it as a generic parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
use crate::ShouldEmit;
use crate::attributes::diagnostic::*;
use crate::attributes::prelude::*;
use crate::diagnostics::DiagnosticOnUnknownOnlyForImports;
use crate::diagnostics::DiagnosticOnUnknownInvalidTarget;

#[derive(Default)]
pub(crate) struct OnUnknownParser {
Expand All @@ -29,11 +29,11 @@ impl OnUnknownParser {
// Therefore, only do target checking if we can emit.
let early = matches!(cx.should_emit, ShouldEmit::Nothing);

if !early && !matches!(cx.target, Target::Use) {
if !early && !matches!(cx.target, Target::Use | Target::Mod | Target::Crate) {
let target_span = cx.target_span;
cx.emit_lint(
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
DiagnosticOnUnknownOnlyForImports { target_span },
DiagnosticOnUnknownInvalidTarget { target_span },
span,
);
return;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/loop_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl NoArgsAttributeParser for LoopMatchParser {
pub(crate) struct ConstContinueParser;
impl NoArgsAttributeParser for ConstContinueParser {
const PATH: &[Symbol] = &[sym::const_continue];
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Expression)]);
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Break)]);
const STABILITY: AttributeStability = unstable!(loop_match);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::ConstContinue;
}
8 changes: 5 additions & 3 deletions compiler/rustc_attr_parsing/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ pub(crate) struct DiagnosticOnMoveOnlyForAdt;
pub(crate) struct DiagnosticOnUnimplementedOnlyForTraits;

#[derive(Diagnostic)]
#[diag("`#[diagnostic::on_unknown]` can only be applied to `use` statements")]
pub(crate) struct DiagnosticOnUnknownOnlyForImports {
#[label("not an import")]
#[diag(
"`#[diagnostic::on_unknown]` can only be applied to `use` statements and module declarations"
)]
pub(crate) struct DiagnosticOnUnknownInvalidTarget {
#[label("not an import or module")]
pub target_span: Span,
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/target_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,5 +527,6 @@ pub(crate) const ALL_TARGETS: &'static [Policy] = {
Allow(Target::Loop),
Allow(Target::ForLoop),
Allow(Target::While),
Allow(Target::Break),
]
};
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ struct DiagCtxtInner {
/// stored along side the main panic backtrace.
ice_file: Option<PathBuf>,

/// Controlled by `-Z lint-rust-version`; this allows avoiding emitting lints which would raise MSRV.
/// Controlled by `-Z hint-msrv`; this allows avoiding emitting lints which would raise MSRV.
msrv: Option<RustcVersion>,
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ impl<'a> ExtCtxt<'a> {
pub fn std_path(&self, components: &[Symbol]) -> Vec<Ident> {
let def_site = self.with_def_site_ctxt(DUMMY_SP);
iter::once(Ident::new(kw::DollarCrate, def_site))
.chain(components.iter().map(|&s| Ident::with_dummy_span(s)))
.chain(components.iter().map(|&s| Ident::new(s, def_site)))
.collect()
}
pub fn def_site_path(&self, components: &[Symbol]) -> Vec<Ident> {
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_hir/src/attrs/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub struct CustomDiagnostic {
}

impl CustomDiagnostic {
fn update(&mut self, di: &Directive, args: &FormatArgs) {
pub fn update(&mut self, di: &Directive, args: &FormatArgs) {
if self.message.is_none() {
self.message = di.message.as_ref().map(|m| m.1.format(args));
}
Expand Down Expand Up @@ -153,6 +153,9 @@ impl FormatString {
Piece::Arg(FormatArg::Found) => ret.push_str(&args.found),
Piece::Arg(FormatArg::Expected) => ret.push_str(&args.expected),

// only for on_unknown
Piece::Arg(FormatArg::Unresolved) => ret.push_str(&args.unresolved),

// It's only `rustc_onunimplemented` from here
Piece::Arg(FormatArg::ThisPath) => ret.push_str(&args.this_path),
Piece::Arg(FormatArg::ThisResolved) => {
Expand Down Expand Up @@ -215,6 +218,7 @@ pub struct FormatArgs {
pub this_path: String = String::new(),
pub found: String = String::new(),
pub expected: String = String::new(),
pub unresolved: String = String::new(),
pub item_context: &'static str = "",
pub generic_args: Vec<(Symbol, String)> = Vec::new(),
}
Expand Down Expand Up @@ -248,6 +252,8 @@ pub enum FormatArg {
Found,
/// {Expected} in diagnostic::on_type_error
Expected,
/// {Unresolved} in diagnostic::on_unknown
Unresolved,
}

/// Represents the `on` filter in `#[rustc_on_unimplemented]`.
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_hir/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub enum Target {
ForLoop,
While,
Loop,
Break,
}

impl Display for Target {
Expand Down Expand Up @@ -119,7 +120,8 @@ impl Target {
| Target::Delegation { .. }
| Target::Loop
| Target::While
| Target::ForLoop => false,
| Target::ForLoop
| Target::Break => false,
}
}

Expand Down Expand Up @@ -265,6 +267,7 @@ impl Target {
ast::ExprKind::ForLoop { .. } => Self::ForLoop,
ast::ExprKind::Loop(..) => Self::Loop,
ast::ExprKind::While(..) => Self::While,
ast::ExprKind::Break(..) => Self::Break,
_ => Self::Expression,
}
}
Expand Down Expand Up @@ -319,6 +322,7 @@ impl Target {
Target::Loop => "loop",
Target::ForLoop => "for loop",
Target::While => "while loop",
Target::Break => "break expression",
}
}

Expand Down Expand Up @@ -373,6 +377,7 @@ impl Target {
Target::ForLoop => "for loops",
Target::Loop => "loops",
Target::While => "while loops",
Target::Break => "break expressions",
}
}
}
37 changes: 5 additions & 32 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
AttributeKind::Inline(kind, attr_span) => {
self.check_inline(hir_id, *attr_span, kind, target)
}
AttributeKind::LoopMatch(attr_span) => {
self.check_loop_match(hir_id, *attr_span, target)
}
AttributeKind::ConstContinue(attr_span) => {
self.check_const_continue(hir_id, *attr_span, target)
}
AttributeKind::AllowInternalUnsafe(attr_span)
| AttributeKind::AllowInternalUnstable(.., attr_span) => {
self.check_macro_only_attr(*attr_span, span, target, attrs)
Expand All @@ -218,7 +212,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
&AttributeKind::RustcPubTransparent(attr_span) => {
self.check_rustc_pub_transparent(attr_span, span, attrs)
}
AttributeKind::RustcAlign { .. } => {}
AttributeKind::Naked(..) => self.check_naked(hir_id, target),
AttributeKind::TrackCaller(attr_span) => {
self.check_track_caller(hir_id, *attr_span, attrs, target)
Expand Down Expand Up @@ -262,6 +255,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
AttributeKind::Cold => (),
AttributeKind::CollapseDebugInfo(..) => (),
AttributeKind::CompilerBuiltins => (),
AttributeKind::ConstContinue(..) => {}
AttributeKind::Coroutine => (),
AttributeKind::Coverage(..) => (),
AttributeKind::CrateName { .. } => (),
Expand All @@ -286,6 +280,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
AttributeKind::LinkOrdinal { .. } => (),
AttributeKind::LinkSection { .. } => (),
AttributeKind::Linkage(..) => (),
AttributeKind::LoopMatch(..) => {}
AttributeKind::MacroEscape => (),
AttributeKind::MacroUse { .. } => (),
AttributeKind::Marker => (),
Expand Down Expand Up @@ -317,6 +312,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
// handled below this loop and elsewhere
AttributeKind::Repr { .. } => (),
AttributeKind::RustcAbi { .. } => (),
AttributeKind::RustcAlign { .. } => {}
AttributeKind::RustcAllocator => (),
AttributeKind::RustcAllocatorZeroed => (),
AttributeKind::RustcAllocatorZeroedVariant { .. } => (),
Expand Down Expand Up @@ -891,7 +887,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| Target::Delegation { .. }
| Target::Loop
| Target::ForLoop
| Target::While => None,
| Target::While
| Target::Break => None,
} {
self.tcx.dcx().emit_err(diagnostics::DocAliasBadLocation { span, location });
return;
Expand Down Expand Up @@ -1662,30 +1659,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
.emit_err(diagnostics::BothOptimizeNoneAndInline { optimize_span, inline_span });
}
}

fn check_loop_match(&self, hir_id: HirId, attr_span: Span, target: Target) {
let node_span = self.tcx.hir_span(hir_id);

if !matches!(target, Target::Expression) {
return; // Handled in target checking during attr parse
}

if !matches!(self.tcx.hir_expect_expr(hir_id).kind, hir::ExprKind::Loop(..)) {
self.dcx().emit_err(diagnostics::LoopMatchAttr { attr_span, node_span });
};
}

fn check_const_continue(&self, hir_id: HirId, attr_span: Span, target: Target) {
let node_span = self.tcx.hir_span(hir_id);

if !matches!(target, Target::Expression) {
return; // Handled in target checking during attr parse
}

if !matches!(self.tcx.hir_expect_expr(hir_id).kind, hir::ExprKind::Break(..)) {
self.dcx().emit_err(diagnostics::ConstContinueAttr { attr_span, node_span });
};
}
}

impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
Expand Down
18 changes: 0 additions & 18 deletions compiler/rustc_passes/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,6 @@ use rustc_span::{DUMMY_SP, Ident, Span, Symbol};
use crate::check_attr::ProcMacroKind;
use crate::lang_items::Duplicate;

#[derive(Diagnostic)]
#[diag("`#[loop_match]` should be applied to a loop")]
pub(crate) struct LoopMatchAttr {
#[primary_span]
pub attr_span: Span,
#[label("not a loop")]
pub node_span: Span,
}

#[derive(Diagnostic)]
#[diag("`#[const_continue]` should be applied to a break expression")]
pub(crate) struct ConstContinueAttr {
#[primary_span]
pub attr_span: Span,
#[label("not a break expression")]
pub node_span: Span,
}

#[derive(Diagnostic)]
#[diag("`{$no_mangle_attr}` attribute may not be used in combination with `{$export_name_attr}`")]
pub(crate) struct MixedExportNameAndNoMangle {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
self.tcx.check_stability_allow_unstable(
def_id,
None,
path.span,
path_segment.ident.span,
None,
if is_unstable_reexport(self.tcx, id) {
AllowUnstable::Yes
Expand Down
15 changes: 9 additions & 6 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use tracing::debug;

use crate::Namespace::{MacroNS, TypeNS, ValueNS};
use crate::def_collector::DefCollector;
use crate::error_helper::StructCtor;
use crate::imports::{ImportData, ImportKind, OnUnknownData};
use crate::error_helper::{OnUnknownData, StructCtor};
use crate::imports::{ImportData, ImportKind};
use crate::macros::{MacroRulesDecl, MacroRulesScope, MacroRulesScopeRef};
use crate::ref_mut::CmCell;
use crate::{
Expand Down Expand Up @@ -548,7 +548,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
root_id,
vis,
vis_span: item.vis.span,
on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, item),
on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, &item.attrs),
});

self.r.indeterminate_imports.push(import);
Expand Down Expand Up @@ -863,6 +863,9 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
|| ast::attr::contains_name(&item.attrs, sym::no_implicit_prelude),
);
self.parent_scope.module = module.to_module();
if let Some(directive) = OnUnknownData::from_attrs(self.r.tcx, &item.attrs) {
self.r.on_unknown_data.insert(local_def_id, directive);
}
}

// These items live in the value namespace.
Expand Down Expand Up @@ -1037,7 +1040,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
module_path: Vec::new(),
vis,
vis_span: item.vis.span,
on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, item),
on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, &item.attrs),
});
if used {
self.r.import_use_map.insert(import, Used::Other);
Expand Down Expand Up @@ -1169,7 +1172,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
module_path: Vec::new(),
vis: Visibility::Restricted(CRATE_DEF_ID),
vis_span: item.vis.span,
on_unknown_attr: OnUnknownData::from_attrs(this.r.tcx, item),
on_unknown_attr: OnUnknownData::from_attrs(this.r.tcx, &item.attrs),
})
};

Expand Down Expand Up @@ -1350,7 +1353,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
module_path: Vec::new(),
vis,
vis_span: item.vis.span,
on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, item),
on_unknown_attr: OnUnknownData::from_attrs(self.r.tcx, &item.attrs),
});
self.r.import_use_map.insert(import, Used::Other);
let import_decl = self.r.new_import_decl(decl, import);
Expand Down
Loading
Loading