Skip to content

Rollup of 7 pull requests #133085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
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: 13 additions & 3 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
@@ -268,8 +268,8 @@ pub trait Visitor<'ast>: Sized {
fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) -> Self::Result {
walk_fn_ret_ty(self, ret_ty)
}
fn visit_fn_header(&mut self, _header: &'ast FnHeader) -> Self::Result {
Self::Result::output()
fn visit_fn_header(&mut self, header: &'ast FnHeader) -> Self::Result {
walk_fn_header(self, header)
}
fn visit_expr_field(&mut self, f: &'ast ExprField) -> Self::Result {
walk_expr_field(self, f)
@@ -292,6 +292,9 @@ pub trait Visitor<'ast>: Sized {
fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) -> Self::Result {
Self::Result::output()
}
fn visit_coroutine_kind(&mut self, _coroutine_kind: &'ast CoroutineKind) -> Self::Result {
Self::Result::output()
}
}

pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
@@ -813,6 +816,12 @@ pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy)
V::Result::output()
}

pub fn walk_fn_header<'a, V: Visitor<'a>>(visitor: &mut V, fn_header: &'a FnHeader) -> V::Result {
let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header;
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
V::Result::output()
}

pub fn walk_fn_decl<'a, V: Visitor<'a>>(
visitor: &mut V,
FnDecl { inputs, output }: &'a FnDecl,
@@ -830,8 +839,9 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
try_visit!(walk_fn_decl(visitor, decl));
visit_opt!(visitor, visit_block, body);
}
FnKind::Closure(binder, _coroutine_kind, decl, body) => {
FnKind::Closure(binder, coroutine_kind, decl, body) => {
try_visit!(visitor.visit_closure_binder(binder));
visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
try_visit!(walk_fn_decl(visitor, decl));
try_visit!(visitor.visit_expr(body));
}
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
@@ -738,7 +738,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
allow_internal_unstable: Option<Lrc<[Symbol]>>,
) -> Span {
self.tcx.with_stable_hashing_context(|hcx| {
span.mark_with_reason(allow_internal_unstable, reason, self.tcx.sess.edition(), hcx)
span.mark_with_reason(allow_internal_unstable, reason, span.edition(), hcx)
})
}

23 changes: 4 additions & 19 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
@@ -68,6 +68,10 @@ impl<'a, T: EarlyLintPass> EarlyContextAndPass<'a, T> {
}

impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T> {
fn visit_coroutine_kind(&mut self, coroutine_kind: &'a ast::CoroutineKind) -> Self::Result {
self.check_id(coroutine_kind.closure_id());
}

fn visit_param(&mut self, param: &'a ast::Param) {
self.with_lint_attrs(param.id, &param.attrs, |cx| {
lint_callback!(cx, check_param, param);
@@ -111,17 +115,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
self.with_lint_attrs(e.id, &e.attrs, |cx| {
lint_callback!(cx, check_expr, e);
ast_visit::walk_expr(cx, e);
// Explicitly check for lints associated with 'closure_id', since
// it does not have a corresponding AST node
match e.kind {
ast::ExprKind::Closure(box ast::Closure {
coroutine_kind: Some(coroutine_kind),
..
}) => {
cx.check_id(coroutine_kind.closure_id());
}
_ => {}
}
lint_callback!(cx, check_expr_post, e);
})
}
@@ -156,14 +149,6 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
lint_callback!(self, check_fn, fk, span, id);
self.check_id(id);
ast_visit::walk_fn(self, fk);

// Explicitly check for lints associated with 'closure_id', since
// it does not have a corresponding AST node
if let ast_visit::FnKind::Fn(_, _, sig, _, _, _) = fk {
if let Some(coroutine_kind) = sig.header.coroutine_kind {
self.check_id(coroutine_kind.closure_id());
}
}
}

fn visit_variant_data(&mut self, s: &'a ast::VariantData) {
9 changes: 9 additions & 0 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
@@ -584,6 +584,7 @@ enum UnusedDelimsCtx {
MatchScrutineeExpr,
ReturnValue,
BlockRetValue,
BreakValue,
LetScrutineeExpr,
ArrayLenExpr,
AnonConst,
@@ -605,6 +606,7 @@ impl From<UnusedDelimsCtx> for &'static str {
UnusedDelimsCtx::MatchScrutineeExpr => "`match` scrutinee expression",
UnusedDelimsCtx::ReturnValue => "`return` value",
UnusedDelimsCtx::BlockRetValue => "block return value",
UnusedDelimsCtx::BreakValue => "`break` value",
UnusedDelimsCtx::LetScrutineeExpr => "`let` scrutinee expression",
UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
UnusedDelimsCtx::MatchArmExpr => "match arm expression",
@@ -913,6 +915,10 @@ trait UnusedDelimLint {
(value, UnusedDelimsCtx::ReturnValue, false, Some(left), None, true)
}

Break(_, Some(ref value)) => {
(value, UnusedDelimsCtx::BreakValue, false, None, None, true)
}

Index(_, ref value, _) => (value, UnusedDelimsCtx::IndexExpr, false, None, None, false),

Assign(_, ref value, _) | AssignOp(.., ref value) => {
@@ -1063,6 +1069,9 @@ impl UnusedDelimLint for UnusedParens {
_,
_,
) if node.is_lazy()))
&& !((ctx == UnusedDelimsCtx::ReturnValue
|| ctx == UnusedDelimsCtx::BreakValue)
&& matches!(inner.kind, ast::ExprKind::Assign(_, _, _)))
{
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos, is_kw)
}
4 changes: 2 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
@@ -4185,7 +4185,7 @@ declare_lint! {
Warn,
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseSemanticsChange,
reason: FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(Edition::Edition2024),
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
};
@edition Edition2024 => Deny;
@@ -4239,7 +4239,7 @@ declare_lint! {
Warn,
"never type fallback affecting unsafe function calls",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
reason: FutureIncompatibilityReason::EditionAndFutureReleaseError(Edition::Edition2024),
reference: "issue #123748 <https://github.com/rust-lang/rust/issues/123748>",
};
report_in_external_macro
36 changes: 33 additions & 3 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -381,6 +381,8 @@ pub enum FutureIncompatibilityReason {
/// hard errors (and the lint removed). Preferably when there is some
/// confidence that the number of impacted projects is very small (few
/// should have a broken dependency in their dependency tree).
///
/// [`EditionAndFutureReleaseError`]: FutureIncompatibilityReason::EditionAndFutureReleaseError
FutureReleaseErrorReportInDeps,
/// Code that changes meaning in some way in a
/// future release.
@@ -419,6 +421,28 @@ pub enum FutureIncompatibilityReason {
/// slightly changes the text of the diagnostic, but is otherwise the
/// same.
EditionSemanticsChange(Edition),
/// This will be an error in the provided edition *and* in a future
/// release.
///
/// This variant a combination of [`FutureReleaseErrorDontReportInDeps`]
/// and [`EditionError`]. This is useful in rare cases when we
/// want to have "preview" of a breaking change in an edition, but do a
/// breaking change later on all editions anyway.
///
/// [`EditionError`]: FutureIncompatibilityReason::EditionError
/// [`FutureReleaseErrorDontReportInDeps`]: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
EditionAndFutureReleaseError(Edition),
/// This will change meaning in the provided edition *and* in a future
/// release.
///
/// This variant a combination of [`FutureReleaseSemanticsChange`]
/// and [`EditionSemanticsChange`]. This is useful in rare cases when we
/// want to have "preview" of a breaking change in an edition, but do a
/// breaking change later on all editions anyway.
///
/// [`EditionSemanticsChange`]: FutureIncompatibilityReason::EditionSemanticsChange
/// [`FutureReleaseSemanticsChange`]: FutureIncompatibilityReason::FutureReleaseSemanticsChange
EditionAndFutureReleaseSemanticsChange(Edition),
/// A custom reason.
///
/// Choose this variant if the built-in text of the diagnostic of the
@@ -431,9 +455,15 @@ pub enum FutureIncompatibilityReason {
impl FutureIncompatibilityReason {
pub fn edition(self) -> Option<Edition> {
match self {
Self::EditionError(e) => Some(e),
Self::EditionSemanticsChange(e) => Some(e),
_ => None,
Self::EditionError(e)
| Self::EditionSemanticsChange(e)
| Self::EditionAndFutureReleaseError(e)
| Self::EditionAndFutureReleaseSemanticsChange(e) => Some(e),

FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps
| FutureIncompatibilityReason::FutureReleaseErrorReportInDeps
| FutureIncompatibilityReason::FutureReleaseSemanticsChange
| FutureIncompatibilityReason::Custom(_) => None,
}
}
}
11 changes: 11 additions & 0 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
@@ -382,6 +382,17 @@ pub fn lint_level(
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
format!("this changes meaning in Rust {edition}")
}
FutureIncompatibilityReason::EditionAndFutureReleaseError(edition) => {
format!(
"this was previously accepted by the compiler but is being phased out; \
it will become a hard error in Rust {edition} and in a future release in all editions!"
)
}
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(edition) => {
format!(
"this changes meaning in Rust {edition} and in a future release in all editions!"
)
}
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
};

8 changes: 2 additions & 6 deletions tests/ui/delegation/unsupported.rs
Original file line number Diff line number Diff line change
@@ -10,15 +10,11 @@ mod opaque {
mod to_reuse {
use super::Trait;

pub fn opaque_ret() -> impl Trait { unimplemented!() }
//~^ warn: this function depends on never type fallback being `()`
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
pub fn opaque_ret() -> impl Trait { () }
}

trait ToReuse {
fn opaque_ret() -> impl Trait { unimplemented!() }
//~^ warn: this function depends on never type fallback being `()`
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
fn opaque_ret() -> impl Trait { () }
}

// FIXME: Inherited `impl Trait`s create query cycles when used inside trait impls.
61 changes: 15 additions & 46 deletions tests/ui/delegation/unsupported.stderr
Original file line number Diff line number Diff line change
@@ -1,74 +1,43 @@
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>::{synthetic#0}`
--> $DIR/unsupported.rs:26:25
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{synthetic#0}`
--> $DIR/unsupported.rs:22:25
|
LL | reuse to_reuse::opaque_ret;
| ^^^^^^^^^^
|
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
--> $DIR/unsupported.rs:26:25
--> $DIR/unsupported.rs:22:25
|
LL | reuse to_reuse::opaque_ret;
| ^^^^^^^^^^
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>::{synthetic#0}`, completing the cycle
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:25:5: 25:24>` is well-formed
--> $DIR/unsupported.rs:25:5
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>::{synthetic#0}`, completing the cycle
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:21:5: 21:24>` is well-formed
--> $DIR/unsupported.rs:21:5
|
LL | impl ToReuse for u8 {
| ^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

warning: this function depends on never type fallback being `()`
--> $DIR/unsupported.rs:13:9
|
LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: opaque::Trait` will fail
--> $DIR/unsupported.rs:13:32
|
LL | pub fn opaque_ret() -> impl Trait { unimplemented!() }
| ^^^^^^^^^^
= note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default

warning: this function depends on never type fallback being `()`
--> $DIR/unsupported.rs:19:9
|
LL | fn opaque_ret() -> impl Trait { unimplemented!() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: opaque::Trait` will fail
--> $DIR/unsupported.rs:19:28
|
LL | fn opaque_ret() -> impl Trait { unimplemented!() }
| ^^^^^^^^^^

error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>::{synthetic#0}`
--> $DIR/unsupported.rs:29:24
error[E0391]: cycle detected when computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{synthetic#0}`
--> $DIR/unsupported.rs:25:24
|
LL | reuse ToReuse::opaque_ret;
| ^^^^^^^^^^
|
note: ...which requires comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process...
--> $DIR/unsupported.rs:29:24
--> $DIR/unsupported.rs:25:24
|
LL | reuse ToReuse::opaque_ret;
| ^^^^^^^^^^
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>::{synthetic#0}`, completing the cycle
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:28:5: 28:25>` is well-formed
--> $DIR/unsupported.rs:28:5
= note: ...which again requires computing type of `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>::{synthetic#0}`, completing the cycle
note: cycle used when checking that `opaque::<impl at $DIR/unsupported.rs:24:5: 24:25>` is well-formed
--> $DIR/unsupported.rs:24:5
|
LL | impl ToReuse for u16 {
| ^^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error: recursive delegation is not supported yet
--> $DIR/unsupported.rs:42:22
--> $DIR/unsupported.rs:38:22
|
LL | pub reuse to_reuse2::foo;
| --- callee defined here
@@ -77,14 +46,14 @@ LL | reuse to_reuse1::foo;
| ^^^

error[E0283]: type annotations needed
--> $DIR/unsupported.rs:52:18
--> $DIR/unsupported.rs:48:18
|
LL | reuse Trait::foo;
| ^^^ cannot infer type
|
= note: cannot satisfy `_: effects::Trait`

error: aborting due to 4 previous errors; 2 warnings emitted
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0283, E0391.
For more information about an error, try `rustc --explain E0283`.
6 changes: 3 additions & 3 deletions tests/ui/editions/never-type-fallback-breaking.e2021.fixed
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ fn main() {

fn m() {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
let x: () = match true {
true => Default::default(),
//[e2024]~^ error: the trait bound `!: Default` is not satisfied
@@ -28,7 +28,7 @@ fn m() {

fn q() -> Option<()> {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
fn deserialize<T: Default>() -> Option<T> {
Some(T::default())
}
@@ -45,7 +45,7 @@ fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
}
fn meow() -> Result<(), ()> {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
help::<(), _>(1)?;
//[e2024]~^ error: the trait bound `(): From<!>` is not satisfied
Ok(())
6 changes: 3 additions & 3 deletions tests/ui/editions/never-type-fallback-breaking.e2021.stderr
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn m() {
| ^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
@@ -24,7 +24,7 @@ warning: this function depends on never type fallback being `()`
LL | fn q() -> Option<()> {
| ^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
@@ -43,7 +43,7 @@ warning: this function depends on never type fallback being `()`
LL | fn meow() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `(): From<!>` will fail
6 changes: 3 additions & 3 deletions tests/ui/editions/never-type-fallback-breaking.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ fn main() {

fn m() {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
let x = match true {
true => Default::default(),
//[e2024]~^ error: the trait bound `!: Default` is not satisfied
@@ -28,7 +28,7 @@ fn m() {

fn q() -> Option<()> {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
fn deserialize<T: Default>() -> Option<T> {
Some(T::default())
}
@@ -45,7 +45,7 @@ fn help<'a: 'a, T: Into<()>, U>(_: U) -> Result<T, ()> {
}
fn meow() -> Result<(), ()> {
//[e2021]~^ this function depends on never type fallback being `()`
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[e2021]~| this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
help(1)?;
//[e2024]~^ error: the trait bound `(): From<!>` is not satisfied
Ok(())
20 changes: 20 additions & 0 deletions tests/ui/impl-trait/precise-capturing/auxiliary/no-use-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// A macro_rules macro in 2015 that has an RPIT without `use<>` that would
// cause a problem with 2024 capturing rules.

#[macro_export]
macro_rules! macro_rpit {
() => {
fn test_mbe(x: &Vec<i32>) -> impl std::fmt::Display {
x[0]
}

pub fn from_mbe() {
let mut x = vec![];
x.push(1);

let element = test_mbe(&x);
x.push(2);
println!("{element}");
}
};
}
29 changes: 29 additions & 0 deletions tests/ui/impl-trait/precise-capturing/auxiliary/no-use-pm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// A proc-macro in 2015 that has an RPIT without `use<>` that would cause a
// problem with 2024 capturing rules.

//@ force-host
//@ no-prefer-dynamic

#![crate_type = "proc-macro"]

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
pub fn pm_rpit(input: TokenStream) -> TokenStream {
"fn test_pm(x: &Vec<i32>) -> impl std::fmt::Display {
x[0]
}
pub fn from_pm() {
let mut x = vec![];
x.push(1);
let element = test_pm(&x);
x.push(2);
println!(\"{element}\");
}
"
.parse()
.unwrap()
}
26 changes: 26 additions & 0 deletions tests/ui/impl-trait/precise-capturing/external-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Tests that code generated from an external macro (MBE and proc-macro) that
// has an RPIT will not fail when the call-site is 2024.
// https://github.com/rust-lang/rust/issues/132917

//@ aux-crate: no_use_pm=no-use-pm.rs
//@ aux-crate: no_use_macro=no-use-macro.rs
//@ edition: 2024
//@ compile-flags:-Z unstable-options
//@ check-pass

no_use_pm::pm_rpit!{}

no_use_macro::macro_rpit!{}

fn main() {
let mut x = vec![];
x.push(1);

let element = test_pm(&x);
x.push(2);
println!("{element}");

let element = test_mbe(&x);
x.push(2);
println!("{element}");
}
8 changes: 5 additions & 3 deletions tests/ui/lint/unused/issue-54538-unused-parens-lint.fixed
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
unused_mut,
unused_variables
)]
#![deny(unused_parens)]
#![deny(unused_parens, unused_braces)]

fn lint_on_top_level() {
let a = 0; //~ ERROR unnecessary parentheses around pattern
@@ -43,8 +43,10 @@ fn no_lint_ops() {
fn lint_break_if_not_followed_by_block() {
#![allow(unreachable_code)]
loop { if break {} } //~ ERROR unnecessary parentheses
loop { if break ({ println!("hello") }) {} } //~ ERROR unnecessary parentheses
loop { if (break { println!("hello") }) {} }
loop { if break { println!("hello") } {} }
//~^ ERROR unnecessary parentheses around `if` condition
//~| ERROR unnecessary parentheses around `break` value
loop { if (break println!("hello")) {} } //~ ERROR unnecessary braces around `break` value
}

// Don't lint in these cases (#64106).
8 changes: 5 additions & 3 deletions tests/ui/lint/unused/issue-54538-unused-parens-lint.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
unused_mut,
unused_variables
)]
#![deny(unused_parens)]
#![deny(unused_parens, unused_braces)]

fn lint_on_top_level() {
let (a) = 0; //~ ERROR unnecessary parentheses around pattern
@@ -43,8 +43,10 @@ fn no_lint_ops() {
fn lint_break_if_not_followed_by_block() {
#![allow(unreachable_code)]
loop { if (break) {} } //~ ERROR unnecessary parentheses
loop { if (break ({ println!("hello") })) {} } //~ ERROR unnecessary parentheses
loop { if (break { println!("hello") }) {} }
loop { if (break ({ println!("hello") })) {} }
//~^ ERROR unnecessary parentheses around `if` condition
//~| ERROR unnecessary parentheses around `break` value
loop { if (break { println!("hello") }) {} } //~ ERROR unnecessary braces around `break` value
}

// Don't lint in these cases (#64106).
69 changes: 49 additions & 20 deletions tests/ui/lint/unused/issue-54538-unused-parens-lint.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | let (a) = 0;
note: the lint level is defined here
--> $DIR/issue-54538-unused-parens-lint.rs:13:9
|
LL | #![deny(unused_parens)]
LL | #![deny(unused_parens, unused_braces)]
| ^^^^^^^^^^^^^
help: remove these parentheses
|
@@ -99,8 +99,37 @@ LL - loop { if (break ({ println!("hello") })) {} }
LL + loop { if break ({ println!("hello") }) {} }
|

error: unnecessary parentheses around `break` value
--> $DIR/issue-54538-unused-parens-lint.rs:46:22
|
LL | loop { if (break ({ println!("hello") })) {} }
| ^ ^
|
help: remove these parentheses
|
LL - loop { if (break ({ println!("hello") })) {} }
LL + loop { if (break { println!("hello") }) {} }
|

error: unnecessary braces around `break` value
--> $DIR/issue-54538-unused-parens-lint.rs:49:22
|
LL | loop { if (break { println!("hello") }) {} }
| ^^ ^^
|
note: the lint level is defined here
--> $DIR/issue-54538-unused-parens-lint.rs:13:24
|
LL | #![deny(unused_parens, unused_braces)]
| ^^^^^^^^^^^^^
help: remove these braces
|
LL - loop { if (break { println!("hello") }) {} }
LL + loop { if (break println!("hello")) {} }
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:71:12
--> $DIR/issue-54538-unused-parens-lint.rs:73:12
|
LL | if let (0 | 1) = 0 {}
| ^ ^
@@ -112,7 +141,7 @@ LL + if let 0 | 1 = 0 {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:72:13
--> $DIR/issue-54538-unused-parens-lint.rs:74:13
|
LL | if let ((0 | 1),) = (0,) {}
| ^ ^
@@ -124,7 +153,7 @@ LL + if let (0 | 1,) = (0,) {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:73:13
--> $DIR/issue-54538-unused-parens-lint.rs:75:13
|
LL | if let [(0 | 1)] = [0] {}
| ^ ^
@@ -136,7 +165,7 @@ LL + if let [0 | 1] = [0] {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:74:16
--> $DIR/issue-54538-unused-parens-lint.rs:76:16
|
LL | if let 0 | (1 | 2) = 0 {}
| ^ ^
@@ -148,7 +177,7 @@ LL + if let 0 | 1 | 2 = 0 {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:76:15
--> $DIR/issue-54538-unused-parens-lint.rs:78:15
|
LL | if let TS((0 | 1)) = TS(0) {}
| ^ ^
@@ -160,7 +189,7 @@ LL + if let TS(0 | 1) = TS(0) {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:78:20
--> $DIR/issue-54538-unused-parens-lint.rs:80:20
|
LL | if let NS { f: (0 | 1) } = (NS { f: 0 }) {}
| ^ ^
@@ -172,7 +201,7 @@ LL + if let NS { f: 0 | 1 } = (NS { f: 0 }) {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:88:9
--> $DIR/issue-54538-unused-parens-lint.rs:90:9
|
LL | (_) => {}
| ^ ^
@@ -184,7 +213,7 @@ LL + _ => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:89:9
--> $DIR/issue-54538-unused-parens-lint.rs:91:9
|
LL | (y) => {}
| ^ ^
@@ -196,7 +225,7 @@ LL + y => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:90:9
--> $DIR/issue-54538-unused-parens-lint.rs:92:9
|
LL | (ref r) => {}
| ^ ^
@@ -208,7 +237,7 @@ LL + ref r => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:91:9
--> $DIR/issue-54538-unused-parens-lint.rs:93:9
|
LL | (e @ 1...2) => {}
| ^ ^
@@ -220,7 +249,7 @@ LL + e @ 1...2 => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:97:9
--> $DIR/issue-54538-unused-parens-lint.rs:99:9
|
LL | (e @ &(1...2)) => {}
| ^ ^
@@ -232,7 +261,7 @@ LL + e @ &(1...2) => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:98:10
--> $DIR/issue-54538-unused-parens-lint.rs:100:10
|
LL | &(_) => {}
| ^ ^
@@ -244,7 +273,7 @@ LL + &_ => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:109:9
--> $DIR/issue-54538-unused-parens-lint.rs:111:9
|
LL | (_) => {}
| ^ ^
@@ -256,7 +285,7 @@ LL + _ => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:110:9
--> $DIR/issue-54538-unused-parens-lint.rs:112:9
|
LL | (y) => {}
| ^ ^
@@ -268,7 +297,7 @@ LL + y => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:111:9
--> $DIR/issue-54538-unused-parens-lint.rs:113:9
|
LL | (ref r) => {}
| ^ ^
@@ -280,7 +309,7 @@ LL + ref r => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:112:9
--> $DIR/issue-54538-unused-parens-lint.rs:114:9
|
LL | (e @ 1..=2) => {}
| ^ ^
@@ -292,7 +321,7 @@ LL + e @ 1..=2 => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:118:9
--> $DIR/issue-54538-unused-parens-lint.rs:120:9
|
LL | (e @ &(1..=2)) => {}
| ^ ^
@@ -304,7 +333,7 @@ LL + e @ &(1..=2) => {}
|

error: unnecessary parentheses around pattern
--> $DIR/issue-54538-unused-parens-lint.rs:119:10
--> $DIR/issue-54538-unused-parens-lint.rs:121:10
|
LL | &(_) => {}
| ^ ^
@@ -315,5 +344,5 @@ LL - &(_) => {}
LL + &_ => {}
|

error: aborting due to 26 previous errors
error: aborting due to 28 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@ run-rustfix
#![deny(unused_parens)]
#![allow(unreachable_code)]

fn foo() {
loop {
break (_ = 42);
// lint unused_parens should not be triggered here.
}

let _ = loop {
let a = 1;
let b = 2;
break a + b; //~ERROR unnecessary parentheses
};

loop {
if break return () {
//~^ ERROR unnecessary parentheses
}
if break return () {
//~^ ERROR unnecessary parentheses
}
}

return (_ = 42);
// lint unused_parens should not be triggered here.
}

fn main() {
let _ = foo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//@ run-rustfix
#![deny(unused_parens)]
#![allow(unreachable_code)]

fn foo() {
loop {
break (_ = 42);
// lint unused_parens should not be triggered here.
}

let _ = loop {
let a = 1;
let b = 2;
break (a + b); //~ERROR unnecessary parentheses
};

loop {
if (break return ()) {
//~^ ERROR unnecessary parentheses
}
if break (return ()) {
//~^ ERROR unnecessary parentheses
}
}

return (_ = 42);
// lint unused_parens should not be triggered here.
}

fn main() {
let _ = foo();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
error: unnecessary parentheses around `break` value
--> $DIR/unused-parens-assign-expr-in-ret-issue-131989.rs:14:15
|
LL | break (a + b);
| ^ ^
|
note: the lint level is defined here
--> $DIR/unused-parens-assign-expr-in-ret-issue-131989.rs:2:9
|
LL | #![deny(unused_parens)]
| ^^^^^^^^^^^^^
help: remove these parentheses
|
LL - break (a + b);
LL + break a + b;
|

error: unnecessary parentheses around `if` condition
--> $DIR/unused-parens-assign-expr-in-ret-issue-131989.rs:18:12
|
LL | if (break return ()) {
| ^ ^
|
help: remove these parentheses
|
LL - if (break return ()) {
LL + if break return () {
|

error: unnecessary parentheses around `break` value
--> $DIR/unused-parens-assign-expr-in-ret-issue-131989.rs:21:18
|
LL | if break (return ()) {
| ^ ^
|
help: remove these parentheses
|
LL - if break (return ()) {
LL + if break return () {
|

error: aborting due to 3 previous errors

2 changes: 1 addition & 1 deletion tests/ui/lint/unused_parens_json_suggestion.fixed
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
// test of the JSON error format.

#![deny(unused_parens)]
#![allow(unreachable_code)]
#![allow(unreachable_code, unused_braces)]

fn main() {
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
2 changes: 1 addition & 1 deletion tests/ui/lint/unused_parens_json_suggestion.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
// test of the JSON error format.

#![deny(unused_parens)]
#![allow(unreachable_code)]
#![allow(unreachable_code, unused_braces)]

fn main() {
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
2 changes: 1 addition & 1 deletion tests/ui/lint/unused_parens_json_suggestion.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"$message_type":"diagnostic","message":"unnecessary parentheses around assigned value","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":15}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":633,"byte_end":634,"line_start":17,"line_end":17,"column_start":26,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":26,"highlight_end":27}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the lint level is defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":439,"byte_end":452,"line_start":11,"line_end":11,"column_start":9,"column_end":22,"is_primary":true,"text":[{"text":"#![deny(unused_parens)]","highlight_start":9,"highlight_end":22}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null},{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":621,"byte_end":622,"line_start":17,"line_end":17,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":15}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null},{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":633,"byte_end":634,"line_start":17,"line_end":17,"column_start":26,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":26,"highlight_end":27}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"error: unnecessary parentheses around assigned value
{"$message_type":"diagnostic","message":"unnecessary parentheses around assigned value","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":636,"byte_end":637,"line_start":17,"line_end":17,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":15}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":648,"byte_end":649,"line_start":17,"line_end":17,"column_start":26,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":26,"highlight_end":27}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"the lint level is defined here","code":null,"level":"note","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":439,"byte_end":452,"line_start":11,"line_end":11,"column_start":9,"column_end":22,"is_primary":true,"text":[{"text":"#![deny(unused_parens)]","highlight_start":9,"highlight_end":22}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null},{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":636,"byte_end":637,"line_start":17,"line_end":17,"column_start":14,"column_end":15,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":15}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null},{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":648,"byte_end":649,"line_start":17,"line_end":17,"column_start":26,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":26,"highlight_end":27}],"label":null,"suggested_replacement":"","suggestion_applicability":"MachineApplicable","expansion":null}],"children":[],"rendered":null}],"rendered":"error: unnecessary parentheses around assigned value
--> $DIR/unused_parens_json_suggestion.rs:17:14
|
LL | let _a = (1 / (2 + 3));
2 changes: 1 addition & 1 deletion tests/ui/lint/unused_parens_remove_json_suggestion.fixed
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
// test of the JSON error format.

#![deny(unused_parens)]
#![allow(unreachable_code)]
#![allow(unreachable_code, unused_braces)]

fn main() {

2 changes: 1 addition & 1 deletion tests/ui/lint/unused_parens_remove_json_suggestion.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
// test of the JSON error format.

#![deny(unused_parens)]
#![allow(unreachable_code)]
#![allow(unreachable_code, unused_braces)]

fn main() {

18 changes: 9 additions & 9 deletions tests/ui/lint/unused_parens_remove_json_suggestion.stderr

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/ui/never_type/defaulted-never-note.nofallback.stderr
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn smeg() {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: ImplementedForUnitButNotNever` will fail
2 changes: 1 addition & 1 deletion tests/ui/never_type/defaulted-never-note.rs
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ fn foo<T: ImplementedForUnitButNotNever>(_t: T) {}
//[fallback]~| NOTE required by a bound in `foo`
fn smeg() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
let _x = return;
foo(_x);
//[fallback]~^ ERROR the trait bound
4 changes: 2 additions & 2 deletions tests/ui/never_type/dependency-on-fallback-to-unit.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ fn main() {

fn def() {
//~^ warn: this function depends on never type fallback being `()`
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
match true {
false => <_>::default(),
true => return,
@@ -18,7 +18,7 @@ fn def() {
// <https://github.com/rust-lang/rust/issues/39216>
fn question_mark() -> Result<(), ()> {
//~^ warn: this function depends on never type fallback being `()`
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
deserialize()?;
Ok(())
}
4 changes: 2 additions & 2 deletions tests/ui/never_type/dependency-on-fallback-to-unit.stderr
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn def() {
| ^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
@@ -24,7 +24,7 @@ warning: this function depends on never type fallback being `()`
LL | fn question_mark() -> Result<(), ()> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Default` will fail
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn assignment() {
| ^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitDefault` will fail
@@ -24,7 +24,7 @@ warning: this function depends on never type fallback being `()`
LL | fn assignment_rev() {
| ^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitDefault` will fail
4 changes: 2 additions & 2 deletions tests/ui/never_type/diverging-fallback-control-flow.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ impl UnitDefault for () {

fn assignment() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
let x;

if true {
@@ -41,7 +41,7 @@ fn assignment() {

fn assignment_rev() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
let x;

if true {
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn main() {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Test` will fail
2 changes: 1 addition & 1 deletion tests/ui/never_type/diverging-fallback-no-leak.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ fn unconstrained_arg<T: Test>(_: T) {}

fn main() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!

// Here the type variable falls back to `!`,
// and hence we get a type error.
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn main() {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: UnitReturn` will fail
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ fn unconstrained_return<T: UnitReturn>() -> T {

fn main() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!

// In Ye Olde Days, the `T` parameter of `unconstrained_return`
// winds up "entangled" with the `!` type that results from
2 changes: 1 addition & 1 deletion tests/ui/never_type/fallback-closure-ret.nofallback.stderr
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn main() {
| ^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: Bar` will fail
2 changes: 1 addition & 1 deletion tests/ui/never_type/fallback-closure-ret.rs
Original file line number Diff line number Diff line change
@@ -20,6 +20,6 @@ fn foo<R: Bar>(_: impl Fn() -> R) {}

fn main() {
//[nofallback]~^ warn: this function depends on never type fallback being `()`
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//[nofallback]~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
foo(|| panic!());
}
2 changes: 1 addition & 1 deletion tests/ui/never_type/impl_trait_fallback.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@ impl T for () {}

fn should_ret_unit() -> impl T {
//~^ warn: this function depends on never type fallback being `()`
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
//~| warn: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
panic!()
}
2 changes: 1 addition & 1 deletion tests/ui/never_type/impl_trait_fallback.stderr
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: this function depends on never type fallback being `()`
LL | fn should_ret_unit() -> impl T {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the types explicitly
note: in edition 2024, the requirement `!: T` will fail
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ warning: never type fallback affects this call to an `unsafe` function
LL | unsafe { mem::zeroed() }
| ^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
= note: `#[warn(never_type_fallback_flowing_into_unsafe)]` on by default
@@ -19,7 +19,7 @@ warning: never type fallback affects this call to an `unsafe` function
LL | core::mem::transmute(Zst)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -33,7 +33,7 @@ warning: never type fallback affects this union access
LL | unsafe { Union { a: () }.b }
| ^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly

@@ -43,7 +43,7 @@ warning: never type fallback affects this raw pointer dereference
LL | unsafe { *ptr::from_ref(&()).cast() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -57,7 +57,7 @@ warning: never type fallback affects this call to an `unsafe` function
LL | unsafe { internally_create(x) }
| ^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -71,7 +71,7 @@ warning: never type fallback affects this call to an `unsafe` function
LL | unsafe { zeroed() }
| ^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -85,7 +85,7 @@ warning: never type fallback affects this `unsafe` function
LL | let zeroed = mem::zeroed;
| ^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -99,7 +99,7 @@ warning: never type fallback affects this `unsafe` function
LL | let f = internally_create;
| ^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -113,7 +113,7 @@ warning: never type fallback affects this call to an `unsafe` method
LL | S(marker::PhantomData).create_out_of_thin_air()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly

@@ -126,7 +126,7 @@ LL | match send_message::<_ /* ?0 */>() {
LL | msg_send!();
| ----------- in this macro invocation
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
= note: this warning originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ error: never type fallback affects this call to an `unsafe` function
LL | unsafe { mem::zeroed() }
| ^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
= note: `#[deny(never_type_fallback_flowing_into_unsafe)]` on by default
@@ -19,7 +19,7 @@ error: never type fallback affects this call to an `unsafe` function
LL | core::mem::transmute(Zst)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -33,7 +33,7 @@ error: never type fallback affects this union access
LL | unsafe { Union { a: () }.b }
| ^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly

@@ -43,7 +43,7 @@ error: never type fallback affects this raw pointer dereference
LL | unsafe { *ptr::from_ref(&()).cast() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -57,7 +57,7 @@ error: never type fallback affects this call to an `unsafe` function
LL | unsafe { internally_create(x) }
| ^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -71,7 +71,7 @@ error: never type fallback affects this call to an `unsafe` function
LL | unsafe { zeroed() }
| ^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -85,7 +85,7 @@ error: never type fallback affects this `unsafe` function
LL | let zeroed = mem::zeroed;
| ^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -99,7 +99,7 @@ error: never type fallback affects this `unsafe` function
LL | let f = internally_create;
| ^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
help: use `()` annotations to avoid fallback changes
@@ -113,7 +113,7 @@ error: never type fallback affects this call to an `unsafe` method
LL | S(marker::PhantomData).create_out_of_thin_air()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly

@@ -126,7 +126,7 @@ LL | match send_message::<_ /* ?0 */>() {
LL | msg_send!();
| ----------- in this macro invocation
|
= warning: this will change its meaning in a future release!
= warning: this changes meaning in Rust 2024 and in a future release in all editions!
= note: for more information, see issue #123748 <https://github.com/rust-lang/rust/issues/123748>
= help: specify the type explicitly
= note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
20 changes: 10 additions & 10 deletions tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ fn _zero() {
unsafe { mem::zeroed() }
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
//[e2024]~| warning: the type `!` does not permit zero-initialization
} else {
return;
@@ -30,7 +30,7 @@ fn _trans() {
core::mem::transmute(Zst)
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
}
} else {
return;
@@ -47,7 +47,7 @@ fn _union() {
unsafe { Union { a: () }.b }
//[e2015]~^ warn: never type fallback affects this union access
//[e2024]~^^ error: never type fallback affects this union access
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
} else {
return;
};
@@ -58,7 +58,7 @@ fn _deref() {
unsafe { *ptr::from_ref(&()).cast() }
//[e2015]~^ warn: never type fallback affects this raw pointer dereference
//[e2024]~^^ error: never type fallback affects this raw pointer dereference
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
} else {
return;
};
@@ -79,7 +79,7 @@ fn _only_generics() {
unsafe { internally_create(x) }
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!

x.unwrap()
} else {
@@ -92,12 +92,12 @@ fn _stored_function() {
let zeroed = mem::zeroed;
//[e2015]~^ warn: never type fallback affects this `unsafe` function
//[e2024]~^^ error: never type fallback affects this `unsafe` function
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!

unsafe { zeroed() }
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
} else {
return;
};
@@ -115,7 +115,7 @@ fn _only_generics_stored_function() {
let f = internally_create;
//[e2015]~^ warn: never type fallback affects this `unsafe` function
//[e2024]~^^ error: never type fallback affects this `unsafe` function
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!

unsafe { f(x) }

@@ -140,7 +140,7 @@ fn _method() {
S(marker::PhantomData).create_out_of_thin_air()
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` method
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` method
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
}
} else {
return;
@@ -158,7 +158,7 @@ fn _objc() {
match send_message::<_ /* ?0 */>() {
//[e2015]~^ warn: never type fallback affects this call to an `unsafe` function
//[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
//~| warn: this will change its meaning in a future release!
//~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
Ok(x) => x,
Err(_) => loop {},
}
6 changes: 2 additions & 4 deletions tests/ui/structs-enums/enum-rec/issue-17431-6.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//@ ignore-apple: cycle error does not appear on apple
use std::cell::UnsafeCell;

use std::sync::Mutex;

enum Foo { X(Mutex<Option<Foo>>) }
enum Foo { X(UnsafeCell<Option<Foo>>) }
//~^ ERROR recursive type `Foo` has infinite size
//~| ERROR cycle detected

14 changes: 7 additions & 7 deletions tests/ui/structs-enums/enum-rec/issue-17431-6.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
error[E0072]: recursive type `Foo` has infinite size
--> $DIR/issue-17431-6.rs:5:1
--> $DIR/issue-17431-6.rs:3:1
|
LL | enum Foo { X(Mutex<Option<Foo>>) }
| ^^^^^^^^ --- recursive without indirection
LL | enum Foo { X(UnsafeCell<Option<Foo>>) }
| ^^^^^^^^ --- recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | enum Foo { X(Mutex<Option<Box<Foo>>>) }
| ++++ +
LL | enum Foo { X(UnsafeCell<Option<Box<Foo>>>) }
| ++++ +

error[E0391]: cycle detected when computing when `Foo` needs drop
--> $DIR/issue-17431-6.rs:5:1
--> $DIR/issue-17431-6.rs:3:1
|
LL | enum Foo { X(Mutex<Option<Foo>>) }
LL | enum Foo { X(UnsafeCell<Option<Foo>>) }
| ^^^^^^^^
|
= note: ...which immediately requires computing when `Foo` needs drop again