Skip to content

Commit aa30176

Browse files
committed
Auto merge of #149729 - matthiaskrgr:rollup-25plwn0, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #147136 (Add warn-by-default lint for visibility on `const _` declarations) - #149498 (Tidying up `tests/ui/issues` tests [1/N]) - #149721 (rustc book: fix `*-pc-windows-msvc` link label in sidebar) - #149724 (Fix off-by-one staging output when testing the library) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1c5a0cf + 1eef811 commit aa30176

38 files changed

+312
-144
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_session::Session;
3333
use rustc_session::lint::BuiltinLintDiag;
3434
use rustc_session::lint::builtin::{
3535
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, MISSING_UNSAFE_ON_EXTERN,
36-
PATTERNS_IN_FNS_WITHOUT_BODY,
36+
PATTERNS_IN_FNS_WITHOUT_BODY, UNUSED_VISIBILITIES,
3737
};
3838
use rustc_session::parse::feature_err;
3939
use rustc_span::{Ident, Span, kw, sym};
@@ -1339,14 +1339,26 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13391339
}
13401340
});
13411341
}
1342-
ItemKind::Const(box ConstItem { defaultness, rhs, .. }) => {
1342+
ItemKind::Const(box ConstItem { defaultness, ident, rhs, .. }) => {
13431343
self.check_defaultness(item.span, *defaultness);
13441344
if rhs.is_none() {
13451345
self.dcx().emit_err(errors::ConstWithoutBody {
13461346
span: item.span,
13471347
replace_span: self.ending_semi_or_hi(item.span),
13481348
});
13491349
}
1350+
if ident.name == kw::Underscore
1351+
&& !matches!(item.vis.kind, VisibilityKind::Inherited)
1352+
&& ident.span.eq_ctxt(item.vis.span)
1353+
{
1354+
self.lint_buffer.buffer_lint(
1355+
UNUSED_VISIBILITIES,
1356+
item.id,
1357+
item.vis.span,
1358+
BuiltinLintDiag::UnusedVisibility(item.vis.span),
1359+
)
1360+
}
1361+
13501362
visit::walk_item(self, item);
13511363
}
13521364
ItemKind::Static(box StaticItem { expr, safety, .. }) => {

compiler/rustc_lint/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,10 @@ lint_unused_op = unused {$op} that must be used
978978
979979
lint_unused_result = unused result of type `{$ty}`
980980
981+
lint_unused_visibilities = visibility qualifiers have no effect on `const _` declarations
982+
.note = `const _` does not declare a name, so there is nothing for the qualifier to apply to
983+
.suggestion = remove the qualifier
984+
981985
lint_use_let_underscore_ignore_suggestion = use `let _ = ...` to ignore the expression or result
982986
983987
lint_useless_ptr_null_checks_fn_ptr = function pointers are not nullable, so checking them for null will always return false

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ pub fn decorate_builtin_lint(
302302
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
303303
lints::UnusedCrateDependency { extern_crate, local_crate }.decorate_lint(diag)
304304
}
305+
BuiltinLintDiag::UnusedVisibility(span) => {
306+
lints::UnusedVisibility { span }.decorate_lint(diag)
307+
}
305308
BuiltinLintDiag::AttributeLint(kind) => decorate_attribute_lint(sess, tcx, &kind, diag),
306309
}
307310
}

compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ fn register_builtins(store: &mut LintStore) {
291291
"unused",
292292
UNUSED_IMPORTS,
293293
UNUSED_VARIABLES,
294+
UNUSED_VISIBILITIES,
294295
UNUSED_ASSIGNMENTS,
295296
DEAD_CODE,
296297
UNUSED_MUT,

compiler/rustc_lint/src/lints.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3191,3 +3191,11 @@ pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
31913191
#[suggestion_part(code = ")")]
31923192
pub right: Span,
31933193
}
3194+
3195+
#[derive(LintDiagnostic)]
3196+
#[diag(lint_unused_visibilities)]
3197+
#[note]
3198+
pub(crate) struct UnusedVisibility {
3199+
#[suggestion(style = "short", code = "", applicability = "machine-applicable")]
3200+
pub span: Span,
3201+
}

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ declare_lint_pass! {
143143
UNUSED_QUALIFICATIONS,
144144
UNUSED_UNSAFE,
145145
UNUSED_VARIABLES,
146+
UNUSED_VISIBILITIES,
146147
USELESS_DEPRECATED,
147148
VARARGS_WITHOUT_PATTERN,
148149
WARNINGS,
@@ -693,6 +694,26 @@ declare_lint! {
693694
"detect variables which are not used in any way"
694695
}
695696

697+
declare_lint! {
698+
/// The `unused_visibilities` lint detects visibility qualifiers (like `pub`)
699+
/// on a `const _` item.
700+
///
701+
/// ### Example
702+
///
703+
/// ```rust
704+
/// pub const _: () = {};
705+
/// ```
706+
///
707+
/// {{produces}}
708+
///
709+
/// ### Explanation
710+
///
711+
/// These qualifiers have no effect, as `const _` items are unnameable.
712+
pub UNUSED_VISIBILITIES,
713+
Warn,
714+
"detect visibility qualifiers on `const _` items"
715+
}
716+
696717
declare_lint! {
697718
/// The `unused_assignments` lint detects assignments that will never be read.
698719
///

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,7 @@ pub enum BuiltinLintDiag {
696696
extern_crate: Symbol,
697697
local_crate: Symbol,
698698
},
699+
UnusedVisibility(Span),
699700
AttributeLint(AttributeLintKind),
700701
}
701702

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,10 +2818,15 @@ fn run_cargo_test<'a>(
28182818
builder: &Builder<'_>,
28192819
) -> bool {
28202820
let compiler = cargo.compiler();
2821+
let stage = match cargo.mode() {
2822+
Mode::Std => compiler.stage,
2823+
_ => compiler.stage + 1,
2824+
};
2825+
28212826
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
28222827
let _time = helpers::timeit(builder);
2823-
let _group =
2824-
description.into().and_then(|what| builder.msg_test(what, target, compiler.stage + 1));
2828+
2829+
let _group = description.into().and_then(|what| builder.msg_test(what, target, stage));
28252830

28262831
#[cfg(feature = "build-metrics")]
28272832
builder.metrics.begin_test_suite(

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub struct Cargo {
9898
command: BootstrapCommand,
9999
args: Vec<OsString>,
100100
compiler: Compiler,
101+
mode: Mode,
101102
target: TargetSelection,
102103
rustflags: Rustflags,
103104
rustdocflags: Rustflags,
@@ -141,6 +142,10 @@ impl Cargo {
141142
self.compiler
142143
}
143144

145+
pub fn mode(&self) -> Mode {
146+
self.mode
147+
}
148+
144149
pub fn into_cmd(self) -> BootstrapCommand {
145150
self.into()
146151
}
@@ -1404,6 +1409,7 @@ impl Builder<'_> {
14041409
command: cargo,
14051410
args: vec![],
14061411
compiler,
1412+
mode,
14071413
target,
14081414
rustflags,
14091415
rustdocflags,

src/doc/rustc/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
- [\*-unknown-openbsd](platform-support/openbsd.md)
131131
- [\*-unknown-redox](platform-support/redox.md)
132132
- [\*-unknown-uefi](platform-support/unknown-uefi.md)
133-
- [\*-unknown-windows-msvc](platform-support/windows-msvc.md)
133+
- [\*-pc-windows-msvc](platform-support/windows-msvc.md)
134134
- [\*-uwp-windows-msvc](platform-support/uwp-windows-msvc.md)
135135
- [\*-wrs-vxworks](platform-support/vxworks.md)
136136
- [wasm32-wasip1](platform-support/wasm32-wasip1.md)

0 commit comments

Comments
 (0)