Skip to content

Commit f428d12

Browse files
committed
Auto merge of #158145 - JonathanBrouwer:rollup-89qzt8B, r=JonathanBrouwer
Rollup of 8 pull requests Successful merges: - #158129 (ensure the new solver bootstraps on CI) - #158134 (Rename `lint-rust-version` to `hint-msrv`) - #157926 (Implement `#[diagnostic::on_unknown]` for modules.) - #158075 (Point to the unstable segment of an import path instead of to the whole path) - #158084 (`-Znext-solver` Emit error instead of ICE when combining {int, float} var with alias) - #158128 (std: use correct low surrogate range in Windows standard I/O code) - #158132 (std: correctly report file size on UWP) - #158138 (Remove redundant check for `#[loop_match]` and `#[const_continue]`)
2 parents d806608 + 2c5fdb9 commit f428d12

60 files changed

Lines changed: 836 additions & 355 deletions

File tree

Some content is hidden

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

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ fn parse_arg(
460460

461461
(Mode::DiagnosticOnTypeError, sym::Found) => FormatArg::Found,
462462
(Mode::DiagnosticOnTypeError, sym::Expected) => FormatArg::Expected,
463+
(Mode::DiagnosticOnUnknown, sym::Unresolved) => FormatArg::Unresolved,
463464

464465
// Some diagnostic attributes can use `{This}` to refer to the annotated item.
465466
// For those that don't, we continue and maybe use it as a generic parameter.

compiler/rustc_attr_parsing/src/attributes/diagnostic/on_unknown.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;
55
use crate::ShouldEmit;
66
use crate::attributes::diagnostic::*;
77
use crate::attributes::prelude::*;
8-
use crate::diagnostics::DiagnosticOnUnknownOnlyForImports;
8+
use crate::diagnostics::DiagnosticOnUnknownInvalidTarget;
99

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

32-
if !early && !matches!(cx.target, Target::Use) {
32+
if !early && !matches!(cx.target, Target::Use | Target::Mod | Target::Crate) {
3333
let target_span = cx.target_span;
3434
cx.emit_lint(
3535
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
36-
DiagnosticOnUnknownOnlyForImports { target_span },
36+
DiagnosticOnUnknownInvalidTarget { target_span },
3737
span,
3838
);
3939
return;

compiler/rustc_attr_parsing/src/attributes/loop_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl NoArgsAttributeParser for LoopMatchParser {
1313
pub(crate) struct ConstContinueParser;
1414
impl NoArgsAttributeParser for ConstContinueParser {
1515
const PATH: &[Symbol] = &[sym::const_continue];
16-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Expression)]);
16+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Break)]);
1717
const STABILITY: AttributeStability = unstable!(loop_match);
1818
const CREATE: fn(Span) -> AttributeKind = AttributeKind::ConstContinue;
1919
}

compiler/rustc_attr_parsing/src/diagnostics.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,11 @@ pub(crate) struct DiagnosticOnMoveOnlyForAdt;
295295
pub(crate) struct DiagnosticOnUnimplementedOnlyForTraits;
296296

297297
#[derive(Diagnostic)]
298-
#[diag("`#[diagnostic::on_unknown]` can only be applied to `use` statements")]
299-
pub(crate) struct DiagnosticOnUnknownOnlyForImports {
300-
#[label("not an import")]
298+
#[diag(
299+
"`#[diagnostic::on_unknown]` can only be applied to `use` statements and module declarations"
300+
)]
301+
pub(crate) struct DiagnosticOnUnknownInvalidTarget {
302+
#[label("not an import or module")]
301303
pub target_span: Span,
302304
}
303305

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,5 +527,6 @@ pub(crate) const ALL_TARGETS: &'static [Policy] = {
527527
Allow(Target::Loop),
528528
Allow(Target::ForLoop),
529529
Allow(Target::While),
530+
Allow(Target::Break),
530531
]
531532
};

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ struct DiagCtxtInner {
366366
/// stored along side the main panic backtrace.
367367
ice_file: Option<PathBuf>,
368368

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

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ impl<'a> ExtCtxt<'a> {
13761376
pub fn std_path(&self, components: &[Symbol]) -> Vec<Ident> {
13771377
let def_site = self.with_def_site_ctxt(DUMMY_SP);
13781378
iter::once(Ident::new(kw::DollarCrate, def_site))
1379-
.chain(components.iter().map(|&s| Ident::with_dummy_span(s)))
1379+
.chain(components.iter().map(|&s| Ident::new(s, def_site)))
13801380
.collect()
13811381
}
13821382
pub fn def_site_path(&self, components: &[Symbol]) -> Vec<Ident> {

compiler/rustc_hir/src/attrs/diagnostic.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct CustomDiagnostic {
9292
}
9393

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

156+
// only for on_unknown
157+
Piece::Arg(FormatArg::Unresolved) => ret.push_str(&args.unresolved),
158+
156159
// It's only `rustc_onunimplemented` from here
157160
Piece::Arg(FormatArg::ThisPath) => ret.push_str(&args.this_path),
158161
Piece::Arg(FormatArg::ThisResolved) => {
@@ -215,6 +218,7 @@ pub struct FormatArgs {
215218
pub this_path: String = String::new(),
216219
pub found: String = String::new(),
217220
pub expected: String = String::new(),
221+
pub unresolved: String = String::new(),
218222
pub item_context: &'static str = "",
219223
pub generic_args: Vec<(Symbol, String)> = Vec::new(),
220224
}
@@ -248,6 +252,8 @@ pub enum FormatArg {
248252
Found,
249253
/// {Expected} in diagnostic::on_type_error
250254
Expected,
255+
/// {Unresolved} in diagnostic::on_unknown
256+
Unresolved,
251257
}
252258

253259
/// Represents the `on` filter in `#[rustc_on_unimplemented]`.

compiler/rustc_hir/src/target.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub enum Target {
7070
ForLoop,
7171
While,
7272
Loop,
73+
Break,
7374
}
7475

7576
impl Display for Target {
@@ -119,7 +120,8 @@ impl Target {
119120
| Target::Delegation { .. }
120121
| Target::Loop
121122
| Target::While
122-
| Target::ForLoop => false,
123+
| Target::ForLoop
124+
| Target::Break => false,
123125
}
124126
}
125127

@@ -265,6 +267,7 @@ impl Target {
265267
ast::ExprKind::ForLoop { .. } => Self::ForLoop,
266268
ast::ExprKind::Loop(..) => Self::Loop,
267269
ast::ExprKind::While(..) => Self::While,
270+
ast::ExprKind::Break(..) => Self::Break,
268271
_ => Self::Expression,
269272
}
270273
}
@@ -319,6 +322,7 @@ impl Target {
319322
Target::Loop => "loop",
320323
Target::ForLoop => "for loop",
321324
Target::While => "while loop",
325+
Target::Break => "break expression",
322326
}
323327
}
324328

@@ -373,6 +377,7 @@ impl Target {
373377
Target::ForLoop => "for loops",
374378
Target::Loop => "loops",
375379
Target::While => "while loops",
380+
Target::Break => "break expressions",
376381
}
377382
}
378383
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
193193
AttributeKind::Inline(kind, attr_span) => {
194194
self.check_inline(hir_id, *attr_span, kind, target)
195195
}
196-
AttributeKind::LoopMatch(attr_span) => {
197-
self.check_loop_match(hir_id, *attr_span, target)
198-
}
199-
AttributeKind::ConstContinue(attr_span) => {
200-
self.check_const_continue(hir_id, *attr_span, target)
201-
}
202196
AttributeKind::AllowInternalUnsafe(attr_span)
203197
| AttributeKind::AllowInternalUnstable(.., attr_span) => {
204198
self.check_macro_only_attr(*attr_span, span, target, attrs)
@@ -218,7 +212,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
218212
&AttributeKind::RustcPubTransparent(attr_span) => {
219213
self.check_rustc_pub_transparent(attr_span, span, attrs)
220214
}
221-
AttributeKind::RustcAlign { .. } => {}
222215
AttributeKind::Naked(..) => self.check_naked(hir_id, target),
223216
AttributeKind::TrackCaller(attr_span) => {
224217
self.check_track_caller(hir_id, *attr_span, attrs, target)
@@ -262,6 +255,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
262255
AttributeKind::Cold => (),
263256
AttributeKind::CollapseDebugInfo(..) => (),
264257
AttributeKind::CompilerBuiltins => (),
258+
AttributeKind::ConstContinue(..) => {}
265259
AttributeKind::Coroutine => (),
266260
AttributeKind::Coverage(..) => (),
267261
AttributeKind::CrateName { .. } => (),
@@ -286,6 +280,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
286280
AttributeKind::LinkOrdinal { .. } => (),
287281
AttributeKind::LinkSection { .. } => (),
288282
AttributeKind::Linkage(..) => (),
283+
AttributeKind::LoopMatch(..) => {}
289284
AttributeKind::MacroEscape => (),
290285
AttributeKind::MacroUse { .. } => (),
291286
AttributeKind::Marker => (),
@@ -317,6 +312,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
317312
// handled below this loop and elsewhere
318313
AttributeKind::Repr { .. } => (),
319314
AttributeKind::RustcAbi { .. } => (),
315+
AttributeKind::RustcAlign { .. } => {}
320316
AttributeKind::RustcAllocator => (),
321317
AttributeKind::RustcAllocatorZeroed => (),
322318
AttributeKind::RustcAllocatorZeroedVariant { .. } => (),
@@ -891,7 +887,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
891887
| Target::Delegation { .. }
892888
| Target::Loop
893889
| Target::ForLoop
894-
| Target::While => None,
890+
| Target::While
891+
| Target::Break => None,
895892
} {
896893
self.tcx.dcx().emit_err(diagnostics::DocAliasBadLocation { span, location });
897894
return;
@@ -1662,30 +1659,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16621659
.emit_err(diagnostics::BothOptimizeNoneAndInline { optimize_span, inline_span });
16631660
}
16641661
}
1665-
1666-
fn check_loop_match(&self, hir_id: HirId, attr_span: Span, target: Target) {
1667-
let node_span = self.tcx.hir_span(hir_id);
1668-
1669-
if !matches!(target, Target::Expression) {
1670-
return; // Handled in target checking during attr parse
1671-
}
1672-
1673-
if !matches!(self.tcx.hir_expect_expr(hir_id).kind, hir::ExprKind::Loop(..)) {
1674-
self.dcx().emit_err(diagnostics::LoopMatchAttr { attr_span, node_span });
1675-
};
1676-
}
1677-
1678-
fn check_const_continue(&self, hir_id: HirId, attr_span: Span, target: Target) {
1679-
let node_span = self.tcx.hir_span(hir_id);
1680-
1681-
if !matches!(target, Target::Expression) {
1682-
return; // Handled in target checking during attr parse
1683-
}
1684-
1685-
if !matches!(self.tcx.hir_expect_expr(hir_id).kind, hir::ExprKind::Break(..)) {
1686-
self.dcx().emit_err(diagnostics::ConstContinueAttr { attr_span, node_span });
1687-
};
1688-
}
16891662
}
16901663

16911664
impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {

0 commit comments

Comments
 (0)