Skip to content
Merged
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
16 changes: 14 additions & 2 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rustc_session::Session;
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::lint::builtin::{
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, MISSING_UNSAFE_ON_EXTERN,
PATTERNS_IN_FNS_WITHOUT_BODY,
PATTERNS_IN_FNS_WITHOUT_BODY, UNUSED_VISIBILITIES,
};
use rustc_session::parse::feature_err;
use rustc_span::{Ident, Span, kw, sym};
Expand Down Expand Up @@ -1339,14 +1339,26 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
});
}
ItemKind::Const(box ConstItem { defaultness, rhs, .. }) => {
ItemKind::Const(box ConstItem { defaultness, ident, rhs, .. }) => {
self.check_defaultness(item.span, *defaultness);
if rhs.is_none() {
self.dcx().emit_err(errors::ConstWithoutBody {
span: item.span,
replace_span: self.ending_semi_or_hi(item.span),
});
}
if ident.name == kw::Underscore
&& !matches!(item.vis.kind, VisibilityKind::Inherited)
&& ident.span.eq_ctxt(item.vis.span)
{
self.lint_buffer.buffer_lint(
UNUSED_VISIBILITIES,
item.id,
item.vis.span,
BuiltinLintDiag::UnusedVisibility(item.vis.span),
)
}

visit::walk_item(self, item);
}
ItemKind::Static(box StaticItem { expr, safety, .. }) => {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,10 @@ lint_unused_op = unused {$op} that must be used
lint_unused_result = unused result of type `{$ty}`
lint_unused_visibilities = visibility qualifiers have no effect on `const _` declarations
.note = `const _` does not declare a name, so there is nothing for the qualifier to apply to
.suggestion = remove the qualifier
lint_use_let_underscore_ignore_suggestion = use `let _ = ...` to ignore the expression or result
lint_useless_ptr_null_checks_fn_ptr = function pointers are not nullable, so checking them for null will always return false
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ pub fn decorate_builtin_lint(
BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => {
lints::UnusedCrateDependency { extern_crate, local_crate }.decorate_lint(diag)
}
BuiltinLintDiag::UnusedVisibility(span) => {
lints::UnusedVisibility { span }.decorate_lint(diag)
}
BuiltinLintDiag::AttributeLint(kind) => decorate_attribute_lint(sess, tcx, &kind, diag),
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ fn register_builtins(store: &mut LintStore) {
"unused",
UNUSED_IMPORTS,
UNUSED_VARIABLES,
UNUSED_VISIBILITIES,
UNUSED_ASSIGNMENTS,
DEAD_CODE,
UNUSED_MUT,
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3191,3 +3191,11 @@ pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
#[suggestion_part(code = ")")]
pub right: Span,
}

#[derive(LintDiagnostic)]
#[diag(lint_unused_visibilities)]
#[note]
pub(crate) struct UnusedVisibility {
#[suggestion(style = "short", code = "", applicability = "machine-applicable")]
pub span: Span,
}
21 changes: 21 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ declare_lint_pass! {
UNUSED_QUALIFICATIONS,
UNUSED_UNSAFE,
UNUSED_VARIABLES,
UNUSED_VISIBILITIES,
USELESS_DEPRECATED,
VARARGS_WITHOUT_PATTERN,
WARNINGS,
Expand Down Expand Up @@ -693,6 +694,26 @@ declare_lint! {
"detect variables which are not used in any way"
}

declare_lint! {
/// The `unused_visibilities` lint detects visibility qualifiers (like `pub`)
/// on a `const _` item.
///
/// ### Example
///
/// ```rust
/// pub const _: () = {};
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// These qualifiers have no effect, as `const _` items are unnameable.
pub UNUSED_VISIBILITIES,
Warn,
"detect visibility qualifiers on `const _` items"
}

declare_lint! {
/// The `unused_assignments` lint detects assignments that will never be read.
///
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ pub enum BuiltinLintDiag {
extern_crate: Symbol,
local_crate: Symbol,
},
UnusedVisibility(Span),
AttributeLint(AttributeLintKind),
}

Expand Down
9 changes: 7 additions & 2 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2818,10 +2818,15 @@ fn run_cargo_test<'a>(
builder: &Builder<'_>,
) -> bool {
let compiler = cargo.compiler();
let stage = match cargo.mode() {
Mode::Std => compiler.stage,
_ => compiler.stage + 1,
};

let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
let _time = helpers::timeit(builder);
let _group =
description.into().and_then(|what| builder.msg_test(what, target, compiler.stage + 1));

let _group = description.into().and_then(|what| builder.msg_test(what, target, stage));

#[cfg(feature = "build-metrics")]
builder.metrics.begin_test_suite(
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub struct Cargo {
command: BootstrapCommand,
args: Vec<OsString>,
compiler: Compiler,
mode: Mode,
target: TargetSelection,
rustflags: Rustflags,
rustdocflags: Rustflags,
Expand Down Expand Up @@ -141,6 +142,10 @@ impl Cargo {
self.compiler
}

pub fn mode(&self) -> Mode {
self.mode
}

pub fn into_cmd(self) -> BootstrapCommand {
self.into()
}
Expand Down Expand Up @@ -1404,6 +1409,7 @@ impl Builder<'_> {
command: cargo,
args: vec![],
compiler,
mode,
target,
rustflags,
rustdocflags,
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
- [\*-unknown-openbsd](platform-support/openbsd.md)
- [\*-unknown-redox](platform-support/redox.md)
- [\*-unknown-uefi](platform-support/unknown-uefi.md)
- [\*-unknown-windows-msvc](platform-support/windows-msvc.md)
- [\*-pc-windows-msvc](platform-support/windows-msvc.md)
- [\*-uwp-windows-msvc](platform-support/uwp-windows-msvc.md)
- [\*-wrs-vxworks](platform-support/vxworks.md)
- [wasm32-wasip1](platform-support/wasm32-wasip1.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ LL | impl<T: core::cmp::Eq> core::fmt::Display for X<T>
| ^^^^^^^^^^^^^^^^^^

error: consider bringing this path into scope with the `use` keyword
--> tests/ui-toml/absolute_paths/absolute_paths.rs:113:14
--> tests/ui-toml/absolute_paths/absolute_paths.rs:113:10
|
LL | pub const _: crate::S = {
| ^^^^^^^^
LL | const _: crate::S = {
| ^^^^^^^^

error: consider bringing this path into scope with the `use` keyword
--> tests/ui-toml/absolute_paths/absolute_paths.rs:114:9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ mod m1 {
}

//~[no_short]v absolute_paths
pub const _: crate::S = {
const _: crate::S = {
let crate::S = m1::S; //~[no_short] absolute_paths

crate::m1::S
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/box/self-assignment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ run-pass
//! regression test for <https://github.com/rust-lang/rust/issues/3290>
#![allow(dead_code)]

pub fn main() {
let mut x: Box<_> = Box::new(3);
x = x;
assert_eq!(*x, 3);
}
4 changes: 2 additions & 2 deletions tests/ui/consts/promoted_const_call3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ pub const C: () = {
//~^ ERROR: destructor of `String` cannot be evaluated at compile-time
};

pub const _: () = {
const _: () = {
let _: &'static _ = &id(&String::new());
//~^ ERROR: destructor of `String` cannot be evaluated at compile-time
};

pub const _: () = {
const _: () = {
let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
//~^ ERROR: temporary value dropped while borrowed
};
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/consts/ptr_is_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

const FOO: &usize = &42;

pub const _: () = assert!(!(FOO as *const usize).is_null());
const _: () = assert!(!(FOO as *const usize).is_null());

pub const _: () = assert!(!(42 as *const usize).is_null());
const _: () = assert!(!(42 as *const usize).is_null());

pub const _: () = assert!((0 as *const usize).is_null());
const _: () = assert!((0 as *const usize).is_null());

pub const _: () = assert!(std::ptr::null::<usize>().is_null());
const _: () = assert!(std::ptr::null::<usize>().is_null());

pub const _: () = assert!(!("foo" as *const str).is_null());
const _: () = assert!(!("foo" as *const str).is_null());
3 changes: 2 additions & 1 deletion tests/ui/empty/empty-struct-unit-expr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Can't use unit struct as constructor function
// related issue <https://github.com/rust-lang/rust/issues/20714>

//@ aux-build:empty-struct.rs

Expand All @@ -8,7 +9,7 @@ use empty_struct::*;
struct Empty2;

enum E {
Empty4
Empty4,
}

fn main() {
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/empty/empty-struct-unit-expr.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0618]: expected function, found struct `Empty2`
--> $DIR/empty-struct-unit-expr.rs:15:14
--> $DIR/empty-struct-unit-expr.rs:16:14
|
LL | struct Empty2;
| ------------- struct `Empty2` defined here
Expand All @@ -16,9 +16,9 @@ LL + let e2 = Empty2;
|

error[E0618]: expected function, found enum variant `E::Empty4`
--> $DIR/empty-struct-unit-expr.rs:16:14
--> $DIR/empty-struct-unit-expr.rs:17:14
|
LL | Empty4
LL | Empty4,
| ------ enum variant `E::Empty4` defined here
...
LL | let e4 = E::Empty4();
Expand All @@ -33,7 +33,7 @@ LL + let e4 = E::Empty4;
|

error[E0618]: expected function, found struct `XEmpty2`
--> $DIR/empty-struct-unit-expr.rs:18:15
--> $DIR/empty-struct-unit-expr.rs:19:15
|
LL | let xe2 = XEmpty2();
| ^^^^^^^--
Expand All @@ -47,7 +47,7 @@ LL + let xe2 = XEmpty2;
|

error[E0618]: expected function, found enum variant `XE::XEmpty4`
--> $DIR/empty-struct-unit-expr.rs:19:15
--> $DIR/empty-struct-unit-expr.rs:20:15
|
LL | let xe4 = XE::XEmpty4();
| ^^^^^^^^^^^--
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! regression test for #37576, #50802
//! Tests that using unlabeled `break` or `continue` within a loop or while's condition.

fn main() {
'test_1: while break 'test_1 {}
while break {}
Expand All @@ -7,9 +10,13 @@ fn main() {
while let true = break {}
//~^ ERROR `break` or `continue` with no label

loop { 'test_3: while break 'test_3 {} }
loop { while break {} }
//~^ ERROR `break` or `continue` with no label
loop {
'test_3: while break 'test_3 {}
}
loop {
while break {}
//~^ ERROR `break` or `continue` with no label
}

loop {
'test_4: while break 'test_4 {}
Expand All @@ -29,9 +36,13 @@ fn main() {
while let true = continue {}
//~^ ERROR `break` or `continue` with no label

loop { 'test_7: while continue 'test_7 {} }
loop { while continue {} }
//~^ ERROR `break` or `continue` with no label
loop {
'test_7: while continue 'test_7 {}
}
loop {
while continue {}
//~^ ERROR `break` or `continue` with no label
}

loop {
'test_8: while continue 'test_8 {}
Expand All @@ -42,4 +53,13 @@ fn main() {
//~^ ERROR `break` or `continue` with no label
continue;
}

'test_9: loop {
break while continue 'test_9 {};
}
loop {
break while continue {
//~^ ERROR `break` or `continue` with no label
};
}
}
Loading
Loading