-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking Issue for Rust 2024: Make !
fall back to !
#123748
Comments
!
fall back to !
!
fall back to !
It turned out that this is actually tricky/impossible to implement, because we can loose the relationships between inference variables by unifying them: // easy to lint
// coercion graph edges: [?1t -> ?3t, ?2t -> ?3t]
match true {
false => return /* ?1t */,
true => Default::default() /* ?2t */,
} /* ?3t */;
// impossible to lint
// coercion graph edges: [?2t -> ?1t]
match true {
true => Default::default() /* ?1t */,
false => return /* ?2t */,
} /* ?1t */; Even though these examples are very similar, they have enough of a difference in the coercion graph, that we can't lint them both reliably. I talked with Niko at RustNL and we agreed that given these circumstances this lint can be omitted. |
…rovements, r=compiler-errors Never type unsafe lint improvements - Move linting code to a separate method - Remove mentions of `core::convert::absurd` (rust-lang#124311 was rejected) - Make the lint into FCW The last thing is a bit weird though. On one hand it should be `EditionSemanticsChange(2024)`, but on the other hand it shouldn't, because we also plan to break it on all editions some time later. _Also_, it's weird that we don't have `FutureReleaseSemanticsChangeReportInDeps`, IMO "this might cause UB in a future release" is important enough to be reported in deps... IMO we ought to have three enums instead of [`FutureIncompatibilityReason`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/enum.FutureIncompatibilityReason.html#): ```rust enum IncompatibilityWhen { FutureRelease, Edition(Edition), } enum IncompatibilyWhat { Error, SemanticChange, } enum IncompatibilityReportInDeps { No, Yes, } ``` Tracking: - rust-lang#123748
Rollup merge of rust-lang#125282 - WaffleLapkin:never-type-unsafe-improvements, r=compiler-errors Never type unsafe lint improvements - Move linting code to a separate method - Remove mentions of `core::convert::absurd` (rust-lang#124311 was rejected) - Make the lint into FCW The last thing is a bit weird though. On one hand it should be `EditionSemanticsChange(2024)`, but on the other hand it shouldn't, because we also plan to break it on all editions some time later. _Also_, it's weird that we don't have `FutureReleaseSemanticsChangeReportInDeps`, IMO "this might cause UB in a future release" is important enough to be reported in deps... IMO we ought to have three enums instead of [`FutureIncompatibilityReason`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/enum.FutureIncompatibilityReason.html#): ```rust enum IncompatibilityWhen { FutureRelease, Edition(Edition), } enum IncompatibilyWhat { Error, SemanticChange, } enum IncompatibilityReportInDeps { No, Yes, } ``` Tracking: - rust-lang#123748
zerocopy ran into a potentially sharp edge with the
We ran into this issue when updating to the latest nightly. Here's the error message:
Here's the offending macro: /// Do `t` and `u` have the same size? If not, this macro produces a compile
/// error. It must be invoked in a dead codepath. This is used in
/// `transmute_ref!` and `transmute_mut!`.
#[doc(hidden)] // `#[macro_export]` bypasses this module's `#[doc(hidden)]`.
#[macro_export]
macro_rules! assert_size_eq {
($t:ident, $u:ident) => {{
// The comments here should be read in the context of this macro's
// invocations in `transmute_ref!` and `transmute_mut!`.
if false {
// SAFETY: This code is never run.
$u = unsafe {
// Clippy:
// - It's okay to transmute a type to itself.
// - We can't annotate the types; this macro is designed to
// infer the types from the calling context.
#[allow(clippy::useless_transmute, clippy::missing_transmute_annotations)]
$crate::macro_util::core_reexport::mem::transmute($t)
};
} else {
loop {}
}
}};
} Note that I believe that this lint isn't actually an issue, and we could soundly However, I will admit to being spooked by this since it's new to me and I haven't spent the time to really wrap my head around it to convince myself that it's definitely fine. I might instead just rewrite that macro. In particular, it's always called from dead code, but has the /// Do `t` and `u` have the same size? If not, this macro produces a compile
/// error. It must be invoked in a dead codepath. This is used in
/// `transmute_ref!` and `transmute_mut!`.
///
/// # Safety
///
/// The code generated by this macro must never be executed at runtime.
#[doc(hidden)] // `#[macro_export]` bypasses this module's `#[doc(hidden)]`.
#[macro_export]
macro_rules! assert_size_eq {
($t:ident, $u:ident) => {{
// Clippy:
// - It's okay to transmute a type to itself.
// - We can't annotate the types; this macro is designed to
// infer the types from the calling context.
#[allow(clippy::useless_transmute, clippy::missing_transmute_annotations)]
$crate::macro_util::core_reexport::mem::transmute($t)
}};
} |
Hmmm, confusingly the "remove the |
@joshlf note that this only happens when there is an error already, so I don't think this is a problem. The reason warning is emitted is that compiler can't infer type of |
Okay that makes sense, thanks for investigating! |
Implement lint for obligations broken by never type fallback change This is the second (and probably last major?) lint required for the never type fallback change. The idea is to check if the code errors with `fallback = ()` and if it errors with `fallback = !` and if it went from "ok" to "error", lint. I'm not happy with the diagnostic, ideally we'd highlight what bound is the problem. But I'm really unsure how to do that (cc `@jackh726,` iirc you had some ideas?) r? `@compiler-errors` Thanks `@BoxyUwU` with helping with trait solver stuff when I was implementing the initial version of this lint. Tracking: - rust-lang#123748
…mpiler-errors Implement lint for obligations broken by never type fallback change This is the second (and probably last major?) lint required for the never type fallback change. The idea is to check if the code errors with `fallback = ()` and if it errors with `fallback = !` and if it went from "ok" to "error", lint. I'm not happy with the diagnostic, ideally we'd highlight what bound is the problem. But I'm really unsure how to do that (cc `@jackh726,` iirc you had some ideas?) r? `@compiler-errors` Thanks `@BoxyUwU` with helping with trait solver stuff when I was implementing the initial version of this lint. Tracking: - rust-lang#123748
…mpiler-errors Implement lint for obligations broken by never type fallback change This is the second (and probably last major?) lint required for the never type fallback change. The idea is to check if the code errors with `fallback = ()` and if it errors with `fallback = !` and if it went from "ok" to "error", lint. I'm not happy with the diagnostic, ideally we'd highlight what bound is the problem. But I'm really unsure how to do that (cc `@jackh726,` iirc you had some ideas?) r? `@compiler-errors` Thanks `@BoxyUwU` with helping with trait solver stuff when I was implementing the initial version of this lint. Tracking: - rust-lang#123748
This comment was marked as resolved.
This comment was marked as resolved.
As per <rust-lang/rust#123748> ! will no longer degrades into () which in this situation breaks type deduction; so specify it explicitly.
As per <rust-lang/rust#123748> ! will no longer degrades into () which in this situation breaks type deduction; so specify it explicitly.
As per <rust-lang/rust#123748> ! will no longer degrades into () which in this situation breaks type deduction; so specify it explicitly.
As per <rust-lang/rust#123748> ! will no longer degrades into () which in this situation breaks type deduction; so specify it explicitly.
As per <rust-lang/rust#123748> ! will no longer degrades into () which in this situation breaks type deduction; so specify it explicitly.
rust-lang/rust#123748 Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
rust-lang/rust#123748 Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Apparently inference ran afoul of rust-lang/rust#123748
Apparently inference ran afoul of rust-lang/rust#123748
Summary: Upgrading Rust from `1.80.1` to `1.81.0` ([release notes](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html)) with the following changes affecting `fbsource`: * Feature stabilizations: * `io_slice_advance` ([#62726](rust-lang/rust#62726)) * `panic_info_message` ([#66745](rust-lang/rust#66745)) * `fs_try_exists` ([#83186](rust-lang/rust#83186)) * `lint_reasons` ([#120924](rust-lang/rust#120924)) * `duration_abs_diff` ([#117618](rust-lang/rust#117618)) * `effects` ([#102090](rust-lang/rust#102090)) * New `clippy` lints: * `manual_inspect` ([#12287](rust-lang/rust-clippy#12287)) * `manual_pattern_char_comparison` ([#12849](rust-lang/rust-clippy#12849)) * Other: * `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` became a deny-by-default lint ([#126881](rust-lang/rust#126881) & [#123748](rust-lang/rust#123748)) * Changes to `stringify!` introducing whitespaces between some tokens ([#125174](rust-lang/rust#125174)) * `format!` is now marked with a `must_use` hint ([#127355](rust-lang/rust#127355)) ignore-conflict-markers Reviewed By: zertosh, dtolnay Differential Revision: D63864870 fbshipit-source-id: c8d61f3e9483ec709c8116514cfb030c883ec262
Summary: Upgrading Rust from `1.80.1` to `1.81.0` ([release notes](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html)) with the following changes affecting `fbsource`: * Feature stabilizations: * `io_slice_advance` ([#62726](rust-lang/rust#62726)) * `panic_info_message` ([#66745](rust-lang/rust#66745)) * `fs_try_exists` ([#83186](rust-lang/rust#83186)) * `lint_reasons` ([#120924](rust-lang/rust#120924)) * `duration_abs_diff` ([#117618](rust-lang/rust#117618)) * `effects` ([#102090](rust-lang/rust#102090)) * New `clippy` lints: * `manual_inspect` ([#12287](rust-lang/rust-clippy#12287)) * `manual_pattern_char_comparison` ([#12849](rust-lang/rust-clippy#12849)) * Other: * `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` became a deny-by-default lint ([#126881](rust-lang/rust#126881) & [#123748](rust-lang/rust#123748)) * Changes to `stringify!` introducing whitespaces between some tokens ([#125174](rust-lang/rust#125174)) * `format!` is now marked with a `must_use` hint ([#127355](rust-lang/rust#127355)) ignore-conflict-markers Reviewed By: zertosh, dtolnay Differential Revision: D63864870 fbshipit-source-id: c8d61f3e9483ec709c8116514cfb030c883ec262
Summary: Upgrading Rust from `1.80.1` to `1.81.0` ([release notes](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html)) with the following changes affecting `fbsource`: * Feature stabilizations: * `io_slice_advance` ([#62726](rust-lang/rust#62726)) * `panic_info_message` ([#66745](rust-lang/rust#66745)) * `fs_try_exists` ([#83186](rust-lang/rust#83186)) * `lint_reasons` ([#120924](rust-lang/rust#120924)) * `duration_abs_diff` ([#117618](rust-lang/rust#117618)) * `effects` ([#102090](rust-lang/rust#102090)) * New `clippy` lints: * `manual_inspect` ([#12287](rust-lang/rust-clippy#12287)) * `manual_pattern_char_comparison` ([#12849](rust-lang/rust-clippy#12849)) * Other: * `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` became a deny-by-default lint ([#126881](rust-lang/rust#126881) & [#123748](rust-lang/rust#123748)) * Changes to `stringify!` introducing whitespaces between some tokens ([#125174](rust-lang/rust#125174)) * `format!` is now marked with a `must_use` hint ([#127355](rust-lang/rust#127355)) ignore-conflict-markers Reviewed By: zertosh, dtolnay Differential Revision: D63864870 fbshipit-source-id: c8d61f3e9483ec709c8116514cfb030c883ec262
Summary: Upgrading Rust from `1.80.1` to `1.81.0` ([release notes](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html)) with the following changes affecting `fbsource`: * Feature stabilizations: * `io_slice_advance` ([#62726](rust-lang/rust#62726)) * `panic_info_message` ([#66745](rust-lang/rust#66745)) * `fs_try_exists` ([#83186](rust-lang/rust#83186)) * `lint_reasons` ([#120924](rust-lang/rust#120924)) * `duration_abs_diff` ([#117618](rust-lang/rust#117618)) * `effects` ([#102090](rust-lang/rust#102090)) * New `clippy` lints: * `manual_inspect` ([#12287](rust-lang/rust-clippy#12287)) * `manual_pattern_char_comparison` ([#12849](rust-lang/rust-clippy#12849)) * Other: * `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` became a deny-by-default lint ([#126881](rust-lang/rust#126881) & [#123748](rust-lang/rust#123748)) * Changes to `stringify!` introducing whitespaces between some tokens ([#125174](rust-lang/rust#125174)) * `format!` is now marked with a `must_use` hint ([#127355](rust-lang/rust#127355)) ignore-conflict-markers Reviewed By: zertosh, dtolnay Differential Revision: D63864870 fbshipit-source-id: c8d61f3e9483ec709c8116514cfb030c883ec262
Summary: Upgrading Rust from `1.80.1` to `1.81.0` ([release notes](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html)) with the following changes affecting `fbsource`: * Feature stabilizations: * `io_slice_advance` ([#62726](rust-lang/rust#62726)) * `panic_info_message` ([#66745](rust-lang/rust#66745)) * `fs_try_exists` ([#83186](rust-lang/rust#83186)) * `lint_reasons` ([#120924](rust-lang/rust#120924)) * `duration_abs_diff` ([#117618](rust-lang/rust#117618)) * `effects` ([#102090](rust-lang/rust#102090)) * New `clippy` lints: * `manual_inspect` ([#12287](rust-lang/rust-clippy#12287)) * `manual_pattern_char_comparison` ([#12849](rust-lang/rust-clippy#12849)) * Other: * `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` became a deny-by-default lint ([#126881](rust-lang/rust#126881) & [#123748](rust-lang/rust#123748)) * Changes to `stringify!` introducing whitespaces between some tokens ([#125174](rust-lang/rust#125174)) * `format!` is now marked with a `must_use` hint ([#127355](rust-lang/rust#127355)) ignore-conflict-markers Reviewed By: zertosh, dtolnay Differential Revision: D63864870 fbshipit-source-id: c8d61f3e9483ec709c8116514cfb030c883ec262
Summary: Upgrading Rust from `1.80.1` to `1.81.0` ([release notes](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html)) with the following changes affecting `fbsource`: * Feature stabilizations: * `io_slice_advance` ([#62726](rust-lang/rust#62726)) * `panic_info_message` ([#66745](rust-lang/rust#66745)) * `fs_try_exists` ([#83186](rust-lang/rust#83186)) * `lint_reasons` ([#120924](rust-lang/rust#120924)) * `duration_abs_diff` ([#117618](rust-lang/rust#117618)) * `effects` ([#102090](rust-lang/rust#102090)) * New `clippy` lints: * `manual_inspect` ([#12287](rust-lang/rust-clippy#12287)) * `manual_pattern_char_comparison` ([#12849](rust-lang/rust-clippy#12849)) * Other: * `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` became a deny-by-default lint ([#126881](rust-lang/rust#126881) & [#123748](rust-lang/rust#123748)) * Changes to `stringify!` introducing whitespaces between some tokens ([#125174](rust-lang/rust#125174)) * `format!` is now marked with a `must_use` hint ([#127355](rust-lang/rust#127355)) ignore-conflict-markers Reviewed By: zertosh, dtolnay Differential Revision: D63864870 fbshipit-source-id: c8d61f3e9483ec709c8116514cfb030c883ec262
Summary: Upgrading Rust from `1.80.1` to `1.81.0` ([release notes](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html)) with the following changes affecting `fbsource`: * Feature stabilizations: * `io_slice_advance` ([#62726](rust-lang/rust#62726)) * `panic_info_message` ([#66745](rust-lang/rust#66745)) * `fs_try_exists` ([#83186](rust-lang/rust#83186)) * `lint_reasons` ([#120924](rust-lang/rust#120924)) * `duration_abs_diff` ([#117618](rust-lang/rust#117618)) * `effects` ([#102090](rust-lang/rust#102090)) * New `clippy` lints: * `manual_inspect` ([#12287](rust-lang/rust-clippy#12287)) * `manual_pattern_char_comparison` ([#12849](rust-lang/rust-clippy#12849)) * Other: * `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` became a deny-by-default lint ([#126881](rust-lang/rust#126881) & [#123748](rust-lang/rust#123748)) * Changes to `stringify!` introducing whitespaces between some tokens ([#125174](rust-lang/rust#125174)) * `format!` is now marked with a `must_use` hint ([#127355](rust-lang/rust#127355)) ignore-conflict-markers Reviewed By: zertosh, dtolnay Differential Revision: D63864870 fbshipit-source-id: c8d61f3e9483ec709c8116514cfb030c883ec262
Summary: Upgrading Rust from `1.80.1` to `1.81.0` ([release notes](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html)) with the following changes affecting `fbsource`: * Feature stabilizations: * `io_slice_advance` ([#62726](rust-lang/rust#62726)) * `panic_info_message` ([#66745](rust-lang/rust#66745)) * `fs_try_exists` ([#83186](rust-lang/rust#83186)) * `lint_reasons` ([#120924](rust-lang/rust#120924)) * `duration_abs_diff` ([#117618](rust-lang/rust#117618)) * `effects` ([#102090](rust-lang/rust#102090)) * New `clippy` lints: * `manual_inspect` ([#12287](rust-lang/rust-clippy#12287)) * `manual_pattern_char_comparison` ([#12849](rust-lang/rust-clippy#12849)) * Other: * `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` became a deny-by-default lint ([#126881](rust-lang/rust#126881) & [#123748](rust-lang/rust#123748)) * Changes to `stringify!` introducing whitespaces between some tokens ([#125174](rust-lang/rust#125174)) * `format!` is now marked with a `must_use` hint ([#127355](rust-lang/rust#127355)) ignore-conflict-markers Reviewed By: zertosh, dtolnay Differential Revision: D63864870 fbshipit-source-id: c8d61f3e9483ec709c8116514cfb030c883ec262
Summary: We are now using Rust 1.81.0. The new lint warning: ``` warning: this function depends on never type fallback being `()` ``` Forces us to use explicit types in `try_collect` when we're collecting over fuctions returning unit types. (Previously that was a never type which was implicitly casted to unit type). More context: rust-lang/rust#123748 Reviewed By: diliop Differential Revision: D64007786 fbshipit-source-id: e7da6827b799053a4a37247e80ccf9f36636d20a
This was the warning by clippy 1.82.0, which explains the change: ``` warning: this function depends on never type fallback being `()` --> hg-core/src/dirstate_tree/status.rs:397:5 | 397 | / fn traverse_fs_directory_and_dirstate<'ancestor>( 398 | | &self, 399 | | has_ignored_ancestor: &'ancestor HasIgnoredAncestor<'ancestor>, 400 | | dirstate_nodes: ChildNodesRef<'tree, 'on_disk>, ... | 404 | | is_at_repo_root: bool, 405 | | ) -> Result<bool, DirstateV2ParseError> { | |___________________________________________^ | = 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 <rust-lang/rust#123748> = help: specify the types explicitly note: in edition 2024, the requirement `!: rayon::iter::FromParallelIterator<()>` will fail --> hg-core/src/dirstate_tree/status.rs:453:28 | 453 | .collect::<Result<_, _>>()?; | ^^^^^^^^^^^^ = note: `#[warn(dependency_on_unit_never_type_fallback)]` on by default ```
rust-lang/rust#123748 によると、関数の戻り値が () であることを期待することを暗黙的にすることが期待されていなくなった。
for Rust 2024, ref: rust-lang/rust#123748 Signed-off-by: Chawye Hsu <su+git@chawyehsu.com>
This is a tracking issue for the change to make fallback fall back from
!
to!
(rather than to()
) in Rust 2024. This is part of a plan that leads to eventually stabilizing the never (!
) type.What this change means
This change means that
!
does not spontaneously decay to()
. For example, consider this code:todo!()
"returns"!
, but before this change this!
decayed to()
when being returned from the closure. In general, this can happen at any coercion site, if the type is not set by something else.If your code is broken with errors like
`!: Trait` is not satisfied
, then you need to make sure the type is specified explicitly. For example:Before this change
!
fromreturn
decays to()
, meaning thatcreate_zst
will also return()
, and since()
implementsFrom<()>
this was fine. With this change however,!
fromreturn
keeps being!
and inference makescreate_zst
also return!
, however!
does not implementFrom<()>
causing a compilation error.The easiest fix is to specify the type explicitly:
However, this can also be a sign that you don't care what the type is, and maybe the better solution is to refactor the code.
Also note that this "create something or return" pattern can also be caused by
?
with code like this:Because
deserialize
's output type is not bound to be anything, it gets inferred from?
's desugaring that includes areturn
. (there is a separate initiative to stop?
from affecting inference like this: #122412)About tracking issues
Tracking issues are used to record the overall progress of implementation. They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions. A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature. Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
!
fall back to!
#123508unsafe
functions.?
guiding inference.!
's docs #124419Unresolved Questions
unsafe
function)deny-by-default
or a hard error in Rust 2024.NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE
a deny-by-default lint in edition 2024 #126881Related
!
#123482!
fall back to!
#123508NeverToAny
#123571!
's docs #124419DEPENDENCY_ON_UNIT_NEVER_TYPE_FALLBACK
#126367NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE
a deny-by-default lint in edition 2024 #126881The text was updated successfully, but these errors were encountered: