authorbors <bors@rust-lang.org> 2026-03-07 03:26:12 UTC
committerbors <bors@rust-lang.org> 2026-03-07 03:26:12 UTC
logea5573a6c6e5e932f917ec4a8e6d8efdeb9f394d
tree9db4e1de400e41c0f5e07726678d8388dab99530
parent80282b130679a654eaa22f028a908c51be53d436
parentf540b27f90f9f0d407f9b9b60165c8bd5e07cdb6

Auto merge of #153519 - JonathanBrouwer:rollup-Soq8THm, r=JonathanBrouwer

Rollup of 5 pull requests Successful merges: - rust-lang/rust#149937 (spliit out `linker-info` from `linker-messages`) - rust-lang/rust#153503 (Fallback to fat LTO for -Clto=thin in cg_gcc) - rust-lang/rust#153346 (move never type tests to subdirectories and add some comments) - rust-lang/rust#153371 (Fix LegacyKeyValueFormat report from docker build: arm) - rust-lang/rust#153508 (Clean up the eager formatting API)

219 files changed, 3058 insertions(+), 2993 deletions(-)

compiler/rustc_borrowck/src/diagnostics/mod.rs+4-6
......@@ -4,6 +4,7 @@ use std::collections::BTreeMap;
44
55use rustc_abi::{FieldIdx, VariantIdx};
66use rustc_data_structures::fx::FxIndexMap;
7use rustc_errors::formatting::DiagMessageAddArg;
78use rustc_errors::{Applicability, Diag, DiagMessage, EmissionGuarantee, MultiSpan, listify, msg};
89use rustc_hir::def::{CtorKind, Namespace};
910use rustc_hir::{
......@@ -1309,12 +1310,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13091310 && !spans.is_empty()
13101311 {
13111312 let mut span: MultiSpan = spans.clone().into();
1312 err.arg("ty", param_ty.to_string());
1313 let msg = err.dcx.eagerly_format_to_string(
1314 msg!("`{$ty}` is made to be an `FnOnce` closure here"),
1315 err.args.iter(),
1316 );
1317 err.remove_arg("ty");
1313 let msg = msg!("`{$ty}` is made to be an `FnOnce` closure here")
1314 .arg("ty", param_ty.to_string())
1315 .format();
13181316 for sp in spans {
13191317 span.push_span_label(sp, msg.clone());
13201318 }
compiler/rustc_builtin_macros/src/errors.rs+14-14
......@@ -1,4 +1,5 @@
11use rustc_errors::codes::*;
2use rustc_errors::formatting::DiagMessageAddArg;
23use rustc_errors::{
34 Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
45 Subdiagnostic, msg,
......@@ -763,15 +764,17 @@ pub(crate) struct FormatUnusedArg {
763764// form of diagnostic.
764765impl Subdiagnostic for FormatUnusedArg {
765766 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
766 diag.arg("named", self.named);
767 let msg = diag.eagerly_format(msg!(
768 "{$named ->
769 [true] named argument
770 *[false] argument
771 } never used"
772 ));
773 diag.remove_arg("named");
774 diag.span_label(self.span, msg);
767 diag.span_label(
768 self.span,
769 msg!(
770 "{$named ->
771 [true] named argument
772 *[false] argument
773 } never used"
774 )
775 .arg("named", self.named)
776 .format(),
777 );
775778 }
776779}
777780
......@@ -946,17 +949,14 @@ pub(crate) struct AsmClobberNoReg {
946949
947950impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AsmClobberNoReg {
948951 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
949 // eager translation as `span_labels` takes `AsRef<str>`
950 let lbl1 = dcx.eagerly_format_to_string(msg!("clobber_abi"), [].into_iter());
951 let lbl2 = dcx.eagerly_format_to_string(msg!("generic outputs"), [].into_iter());
952952 Diag::new(
953953 dcx,
954954 level,
955955 msg!("asm with `clobber_abi` must specify explicit registers for outputs"),
956956 )
957957 .with_span(self.spans.clone())
958 .with_span_labels(self.clobbers, &lbl1)
959 .with_span_labels(self.spans, &lbl2)
958 .with_span_labels(self.clobbers, "clobber_abi")
959 .with_span_labels(self.spans, "generic outputs")
960960 }
961961}
962962
compiler/rustc_codegen_llvm/src/errors.rs+4-2
......@@ -2,7 +2,9 @@ use std::ffi::CString;
22use std::path::Path;
33
44use rustc_data_structures::small_c_str::SmallCStr;
5use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, msg};
5use rustc_errors::{
6 Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, format_diag_message, msg,
7};
68use rustc_macros::Diagnostic;
79use rustc_span::Span;
810
......@@ -24,7 +26,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
2426 fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> {
2527 let diag: Diag<'_, G> = self.0.into_diag(dcx, level);
2628 let (message, _) = diag.messages.first().expect("`LlvmError` with no message");
27 let message = dcx.eagerly_format_to_string(message.clone(), diag.args.iter());
29 let message = format_diag_message(message, &diag.args);
2830 Diag::new(
2931 dcx,
3032 level,
compiler/rustc_codegen_ssa/src/back/link.rs+147-47
......@@ -22,6 +22,7 @@ use rustc_errors::DiagCtxtHandle;
2222use rustc_fs_util::{TempDirBuilder, fix_windows_verbatim_for_gcc, try_canonicalize};
2323use rustc_hir::attrs::NativeLibKind;
2424use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
25use rustc_lint_defs::builtin::LINKER_INFO;
2526use rustc_macros::Diagnostic;
2627use rustc_metadata::fs::{METADATA_FILENAME, copy_to_stdout, emit_wrapper_file};
2728use rustc_metadata::{
......@@ -60,7 +61,8 @@ use super::rpath::{self, RPathConfig};
6061use super::{apple, versioned_llvm_target};
6162use crate::base::needs_allocator_shim_for_linking;
6263use crate::{
63 CompiledModule, CompiledModules, CrateInfo, NativeLib, errors, looks_like_rust_object_file,
64 CodegenLintLevels, CompiledModule, CompiledModules, CrateInfo, NativeLib, errors,
65 looks_like_rust_object_file,
6466};
6567
6668pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
......@@ -672,6 +674,147 @@ struct LinkerOutput {
672674 inner: String,
673675}
674676
677fn is_msvc_link_exe(sess: &Session) -> bool {
678 let (linker_path, flavor) = linker_and_flavor(sess);
679 sess.target.is_like_msvc
680 && flavor == LinkerFlavor::Msvc(Lld::No)
681 // Match exactly "link.exe"
682 && linker_path.to_str() == Some("link.exe")
683}
684
685fn is_macos_ld(sess: &Session) -> bool {
686 let (_, flavor) = linker_and_flavor(sess);
687 sess.target.is_like_darwin && matches!(flavor, LinkerFlavor::Darwin(_, Lld::No))
688}
689
690fn is_windows_gnu_ld(sess: &Session) -> bool {
691 let (_, flavor) = linker_and_flavor(sess);
692 sess.target.is_like_windows
693 && !sess.target.is_like_msvc
694 && matches!(flavor, LinkerFlavor::Gnu(_, Lld::No))
695}
696
697fn report_linker_output(sess: &Session, levels: CodegenLintLevels, stdout: &[u8], stderr: &[u8]) {
698 let mut escaped_stderr = escape_string(&stderr);
699 let mut escaped_stdout = escape_string(&stdout);
700 let mut linker_info = String::new();
701
702 info!("linker stderr:\n{}", &escaped_stderr);
703 info!("linker stdout:\n{}", &escaped_stdout);
704
705 fn for_each(bytes: &[u8], mut f: impl FnMut(&str, &mut String)) -> String {
706 let mut output = String::new();
707 if let Ok(str) = str::from_utf8(bytes) {
708 info!("line: {str}");
709 output = String::with_capacity(str.len());
710 for line in str.lines() {
711 f(line.trim(), &mut output);
712 }
713 }
714 escape_string(output.trim().as_bytes())
715 }
716
717 if is_msvc_link_exe(sess) {
718 info!("inferred MSVC link.exe");
719
720 escaped_stdout = for_each(&stdout, |line, output| {
721 // Hide some progress messages from link.exe that we don't care about.
722 // See https://github.com/chromium/chromium/blob/bfa41e41145ffc85f041384280caf2949bb7bd72/build/toolchain/win/tool_wrapper.py#L144-L146
723 if line.starts_with(" Creating library")
724 || line.starts_with("Generating code")
725 || line.starts_with("Finished generating code")
726 {
727 linker_info += line;
728 linker_info += "\r\n";
729 } else {
730 *output += line;
731 *output += "\r\n"
732 }
733 });
734 } else if is_macos_ld(sess) {
735 info!("inferred macOS LD");
736
737 // FIXME: Tracked by https://github.com/rust-lang/rust/issues/136113
738 let deployment_mismatch = |line: &str| {
739 line.starts_with("ld: warning: object file (")
740 && line.contains("was built for newer 'macOS' version")
741 && line.contains("than being linked")
742 };
743 // FIXME: This is a real warning we would like to show, but it hits too many crates
744 // to want to turn it on immediately.
745 let search_path = |line: &str| {
746 line.starts_with("ld: warning: search path '") && line.ends_with("' not found")
747 };
748 escaped_stderr = for_each(&stderr, |line, output| {
749 // This duplicate library warning is just not helpful at all.
750 if line.starts_with("ld: warning: ignoring duplicate libraries: ")
751 || deployment_mismatch(line)
752 || search_path(line)
753 {
754 linker_info += line;
755 linker_info += "\n";
756 } else {
757 *output += line;
758 *output += "\n"
759 }
760 });
761 } else if is_windows_gnu_ld(sess) {
762 info!("inferred Windows GNU LD");
763
764 let mut saw_exclude_symbol = false;
765 // See https://github.com/rust-lang/rust/issues/112368.
766 // FIXME: maybe check that binutils is older than 2.40 before downgrading this warning?
767 let exclude_symbols = |line: &str| {
768 line.starts_with("Warning: .drectve `-exclude-symbols:")
769 && line.ends_with("' unrecognized")
770 };
771 escaped_stderr = for_each(&stderr, |line, output| {
772 if exclude_symbols(line) {
773 saw_exclude_symbol = true;
774 linker_info += line;
775 linker_info += "\n";
776 } else if saw_exclude_symbol && line == "Warning: corrupt .drectve at end of def file" {
777 linker_info += line;
778 linker_info += "\n";
779 } else {
780 *output += line;
781 *output += "\n"
782 }
783 });
784 }
785
786 let lint_msg = |msg| {
787 diag_lint_level(
788 sess,
789 LINKER_MESSAGES,
790 levels.linker_messages,
791 None,
792 LinkerOutput { inner: msg },
793 );
794 };
795 let lint_info = |msg| {
796 diag_lint_level(sess, LINKER_INFO, levels.linker_info, None, LinkerOutput { inner: msg });
797 };
798
799 if !escaped_stderr.is_empty() {
800 // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
801 escaped_stderr =
802 escaped_stderr.strip_prefix("warning: ").unwrap_or(&escaped_stderr).to_owned();
803 // Windows GNU LD prints uppercase Warning
804 escaped_stderr = escaped_stderr
805 .strip_prefix("Warning: ")
806 .unwrap_or(&escaped_stderr)
807 .replace(": warning: ", ": ");
808 lint_msg(format!("linker stderr: {escaped_stderr}"));
809 }
810 if !escaped_stdout.is_empty() {
811 lint_msg(format!("linker stdout: {}", escaped_stdout))
812 }
813 if !linker_info.is_empty() {
814 lint_info(linker_info);
815 }
816}
817
675818/// Create a dynamic library or executable.
676819///
677820/// This will invoke the system linker/cc to create the resulting file. This links to all upstream
......@@ -860,11 +1003,6 @@ fn link_natively(
8601003
8611004 match prog {
8621005 Ok(prog) => {
863 let is_msvc_link_exe = sess.target.is_like_msvc
864 && flavor == LinkerFlavor::Msvc(Lld::No)
865 // Match exactly "link.exe"
866 && linker_path.to_str() == Some("link.exe");
867
8681006 if !prog.status.success() {
8691007 let mut output = prog.stderr.clone();
8701008 output.extend_from_slice(&prog.stdout);
......@@ -884,7 +1022,7 @@ fn link_natively(
8841022 if let Some(code) = prog.status.code() {
8851023 // All Microsoft `link.exe` linking ror codes are
8861024 // four digit numbers in the range 1000 to 9999 inclusive
887 if is_msvc_link_exe && (code < 1000 || code > 9999) {
1025 if is_msvc_link_exe(sess) && (code < 1000 || code > 9999) {
8881026 let is_vs_installed = find_msvc_tools::find_vs_version().is_ok();
8891027 let has_linker =
8901028 find_msvc_tools::find_tool(sess.target.arch.desc(), "link.exe")
......@@ -916,46 +1054,8 @@ fn link_natively(
9161054 sess.dcx().abort_if_errors();
9171055 }
9181056
919 let stderr = escape_string(&prog.stderr);
920 let mut stdout = escape_string(&prog.stdout);
921 info!("linker stderr:\n{}", &stderr);
922 info!("linker stdout:\n{}", &stdout);
923
924 // Hide some progress messages from link.exe that we don't care about.
925 // See https://github.com/chromium/chromium/blob/bfa41e41145ffc85f041384280caf2949bb7bd72/build/toolchain/win/tool_wrapper.py#L144-L146
926 if is_msvc_link_exe {
927 if let Ok(str) = str::from_utf8(&prog.stdout) {
928 let mut output = String::with_capacity(str.len());
929 for line in stdout.lines() {
930 if line.starts_with(" Creating library")
931 || line.starts_with("Generating code")
932 || line.starts_with("Finished generating code")
933 {
934 continue;
935 }
936 output += line;
937 output += "\r\n"
938 }
939 stdout = escape_string(output.trim().as_bytes())
940 }
941 }
942
943 let level = crate_info.lint_levels.linker_messages;
944 let lint = |msg| {
945 diag_lint_level(sess, LINKER_MESSAGES, level, None, LinkerOutput { inner: msg });
946 };
947
948 if !prog.stderr.is_empty() {
949 // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
950 let stderr = stderr
951 .strip_prefix("warning: ")
952 .unwrap_or(&stderr)
953 .replace(": warning: ", ": ");
954 lint(format!("linker stderr: {stderr}"));
955 }
956 if !stdout.is_empty() {
957 lint(format!("linker stdout: {}", stdout))
958 }
1057 info!("reporting linker output: flavor={flavor:?}");
1058 report_linker_output(sess, crate_info.lint_levels, &prog.stdout, &prog.stderr);
9591059 }
9601060 Err(e) => {
9611061 let linker_not_found = e.kind() == io::ErrorKind::NotFound;
compiler/rustc_codegen_ssa/src/lib.rs+6-1
......@@ -24,6 +24,7 @@ use rustc_data_structures::unord::UnordMap;
2424use rustc_hir::CRATE_HIR_ID;
2525use rustc_hir::attrs::{CfgEntry, NativeLibKind, WindowsSubsystemKind};
2626use rustc_hir::def_id::CrateNum;
27use rustc_lint_defs::builtin::LINKER_INFO;
2728use rustc_macros::{Decodable, Encodable};
2829use rustc_metadata::EncodedMetadata;
2930use rustc_middle::dep_graph::WorkProduct;
......@@ -364,10 +365,14 @@ impl CompiledModules {
364365#[derive(Copy, Clone, Debug, Encodable, Decodable)]
365366pub struct CodegenLintLevels {
366367 linker_messages: LevelAndSource,
368 linker_info: LevelAndSource,
367369}
368370
369371impl CodegenLintLevels {
370372 pub fn from_tcx(tcx: TyCtxt<'_>) -> Self {
371 Self { linker_messages: tcx.lint_level_at_node(LINKER_MESSAGES, CRATE_HIR_ID) }
373 Self {
374 linker_messages: tcx.lint_level_at_node(LINKER_MESSAGES, CRATE_HIR_ID),
375 linker_info: tcx.lint_level_at_node(LINKER_INFO, CRATE_HIR_ID),
376 }
372377 }
373378}
compiler/rustc_const_eval/src/check_consts/ops.rs+3-2
......@@ -265,6 +265,7 @@ fn build_error_for_const_call<'tcx>(
265265 }
266266 }
267267 CallKind::FnCall { fn_trait_id, self_ty } => {
268 let kind = ccx.const_kind();
268269 let note = match self_ty.kind() {
269270 FnDef(def_id, ..) => {
270271 let span = tcx.def_span(*def_id);
......@@ -274,8 +275,8 @@ fn build_error_for_const_call<'tcx>(
274275
275276 Some(errors::NonConstClosureNote::FnDef { span })
276277 }
277 FnPtr(..) => Some(errors::NonConstClosureNote::FnPtr),
278 Closure(..) => Some(errors::NonConstClosureNote::Closure),
278 FnPtr(..) => Some(errors::NonConstClosureNote::FnPtr { kind }),
279 Closure(..) => Some(errors::NonConstClosureNote::Closure { kind }),
279280 _ => None,
280281 };
281282
compiler/rustc_const_eval/src/errors.rs+34-35
......@@ -4,9 +4,10 @@ use std::fmt::Write;
44use either::Either;
55use rustc_abi::WrappingRange;
66use rustc_errors::codes::*;
7use rustc_errors::formatting::DiagMessageAddArg;
78use rustc_errors::{
8 Diag, DiagArgValue, DiagMessage, Diagnostic, EmissionGuarantee, Level, MultiSpan,
9 Subdiagnostic, msg,
9 Diag, DiagArgMap, DiagArgValue, DiagMessage, Diagnostic, EmissionGuarantee, Level, MultiSpan,
10 Subdiagnostic, format_diag_message, msg,
1011};
1112use rustc_hir::ConstContext;
1213use rustc_macros::{Diagnostic, Subdiagnostic};
......@@ -359,14 +360,11 @@ pub struct FrameNote {
359360
360361impl Subdiagnostic for FrameNote {
361362 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
362 diag.arg("times", self.times);
363 diag.arg("where_", self.where_);
364 diag.arg("instance", self.instance);
365363 let mut span: MultiSpan = self.span.into();
366364 if self.has_label && !self.span.is_dummy() {
367365 span.push_span_label(self.span, msg!("the failure occurred here"));
368366 }
369 let msg = diag.eagerly_format(msg!(
367 let msg = msg!(
370368 r#"{$times ->
371369 [0] inside {$where_ ->
372370 [closure] closure
......@@ -379,10 +377,11 @@ impl Subdiagnostic for FrameNote {
379377 *[other] {""}
380378 } ...]
381379 }"#
382 ));
383 diag.remove_arg("times");
384 diag.remove_arg("where_");
385 diag.remove_arg("instance");
380 )
381 .arg("times", self.times)
382 .arg("where_", self.where_)
383 .arg("instance", self.instance)
384 .format();
386385 diag.span_note(span, msg);
387386 }
388387}
......@@ -534,7 +533,7 @@ pub enum NonConstClosureNote {
534533 *[other] {""}
535534 }s"#
536535 )]
537 FnPtr,
536 FnPtr { kind: ConstContext },
538537 #[note(
539538 r#"closures need an RFC before allowed to be called in {$kind ->
540539 [const] constant
......@@ -543,7 +542,7 @@ pub enum NonConstClosureNote {
543542 *[other] {""}
544543 }s"#
545544 )]
546 Closure,
545 Closure { kind: ConstContext },
547546}
548547
549548#[derive(Subdiagnostic)]
......@@ -624,7 +623,7 @@ pub trait ReportErrorExt {
624623 let mut diag = dcx.struct_allow(DiagMessage::Str(String::new().into()));
625624 let message = self.diagnostic_message();
626625 self.add_args(&mut diag);
627 let s = dcx.eagerly_format_to_string(message, diag.args.iter());
626 let s = format_diag_message(&message, &diag.args).into_owned();
628627 diag.cancel();
629628 s
630629 })
......@@ -1086,12 +1085,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
10861085 }
10871086
10881087 let message = if let Some(path) = self.path {
1089 err.dcx.eagerly_format_to_string(
1090 msg!("constructing invalid value at {$path}"),
1091 [("path".into(), DiagArgValue::Str(path.into()))].iter().map(|(a, b)| (a, b)),
1088 format_diag_message(
1089 &msg!("constructing invalid value at {$path}"),
1090 &DiagArgMap::from_iter([("path".into(), DiagArgValue::Str(path.into()))]),
10921091 )
10931092 } else {
1094 err.dcx.eagerly_format_to_string(msg!("constructing invalid value"), [].into_iter())
1093 Cow::Borrowed("constructing invalid value")
10951094 };
10961095
10971096 err.arg("front_matter", message);
......@@ -1117,12 +1116,13 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
11171116 msg!("in the range {$lo}..={$hi}")
11181117 };
11191118
1120 let args = [
1121 ("lo".into(), DiagArgValue::Str(lo.to_string().into())),
1122 ("hi".into(), DiagArgValue::Str(hi.to_string().into())),
1123 ];
1124 let args = args.iter().map(|(a, b)| (a, b));
1125 let message = err.dcx.eagerly_format_to_string(msg, args);
1119 let message = format_diag_message(
1120 &msg,
1121 &DiagArgMap::from_iter([
1122 ("lo".into(), DiagArgValue::Str(lo.to_string().into())),
1123 ("hi".into(), DiagArgValue::Str(hi.to_string().into())),
1124 ]),
1125 );
11261126 err.arg("in_range", message);
11271127 }
11281128
......@@ -1132,19 +1132,18 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
11321132 }
11331133 PointerAsInt { expected } | Uninit { expected } => {
11341134 let msg = match expected {
1135 ExpectedKind::Reference => msg!("expected a reference"),
1136 ExpectedKind::Box => msg!("expected a box"),
1137 ExpectedKind::RawPtr => msg!("expected a raw pointer"),
1138 ExpectedKind::InitScalar => msg!("expected initialized scalar value"),
1139 ExpectedKind::Bool => msg!("expected a boolean"),
1140 ExpectedKind::Char => msg!("expected a unicode scalar value"),
1141 ExpectedKind::Float => msg!("expected a floating point number"),
1142 ExpectedKind::Int => msg!("expected an integer"),
1143 ExpectedKind::FnPtr => msg!("expected a function pointer"),
1144 ExpectedKind::EnumTag => msg!("expected a valid enum tag"),
1145 ExpectedKind::Str => msg!("expected a string"),
1135 ExpectedKind::Reference => "expected a reference",
1136 ExpectedKind::Box => "expected a box",
1137 ExpectedKind::RawPtr => "expected a raw pointer",
1138 ExpectedKind::InitScalar => "expected initialized scalar value",
1139 ExpectedKind::Bool => "expected a boolean",
1140 ExpectedKind::Char => "expected a unicode scalar value",
1141 ExpectedKind::Float => "expected a floating point number",
1142 ExpectedKind::Int => "expected an integer",
1143 ExpectedKind::FnPtr => "expected a function pointer",
1144 ExpectedKind::EnumTag => "expected a valid enum tag",
1145 ExpectedKind::Str => "expected a string",
11461146 };
1147 let msg = err.dcx.eagerly_format_to_string(msg, [].into_iter());
11481147 err.arg("expected", msg);
11491148 }
11501149 InvalidEnumTag { value }
compiler/rustc_const_eval/src/interpret/eval_context.rs+3-3
......@@ -1,7 +1,7 @@
11use either::{Left, Right};
22use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout};
33use rustc_data_structures::debug_assert_matches;
4use rustc_errors::{DiagCtxtHandle, msg};
4use rustc_errors::{DiagCtxtHandle, format_diag_message, msg};
55use rustc_hir::def_id::DefId;
66use rustc_hir::limit::Limit;
77use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo};
......@@ -235,9 +235,9 @@ pub fn format_interp_error<'tcx>(dcx: DiagCtxtHandle<'_>, e: InterpErrorInfo<'tc
235235 let mut diag = dcx.struct_allow("");
236236 let msg = e.diagnostic_message();
237237 e.add_args(&mut diag);
238 let s = dcx.eagerly_format_to_string(msg, diag.args.iter());
238 let msg = format_diag_message(&msg, &diag.args).into_owned();
239239 diag.cancel();
240 s
240 msg
241241}
242242
243243impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
compiler/rustc_errors/src/diagnostic.rs-28
......@@ -236,9 +236,6 @@ pub struct DiagInner {
236236 pub suggestions: Suggestions,
237237 pub args: DiagArgMap,
238238
239 // This is used to store args and restore them after a subdiagnostic is rendered.
240 pub reserved_args: DiagArgMap,
241
242239 /// This is not used for highlighting or rendering any error message. Rather, it can be used
243240 /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of
244241 /// `span` if there is one. Otherwise, it is `DUMMY_SP`.
......@@ -269,7 +266,6 @@ impl DiagInner {
269266 children: vec![],
270267 suggestions: Suggestions::Enabled(vec![]),
271268 args: Default::default(),
272 reserved_args: Default::default(),
273269 sort_span: DUMMY_SP,
274270 is_lint: None,
275271 long_ty_path: None,
......@@ -334,14 +330,6 @@ impl DiagInner {
334330 self.args.swap_remove(name);
335331 }
336332
337 pub fn store_args(&mut self) {
338 self.reserved_args = self.args.clone();
339 }
340
341 pub fn restore_args(&mut self) {
342 self.args = std::mem::take(&mut self.reserved_args);
343 }
344
345333 pub fn emitted_at_sub_diag(&self) -> Subdiag {
346334 let track = format!("-Ztrack-diagnostics: created at {}", self.emitted_at);
347335 Subdiag {
......@@ -1144,16 +1132,6 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
11441132 self
11451133 }
11461134
1147 /// Fluent variables are not namespaced from each other, so when
1148 /// `Diagnostic`s and `Subdiagnostic`s use the same variable name,
1149 /// one value will clobber the other. Eagerly formatting the
1150 /// diagnostic uses the variables defined right then, before the
1151 /// clobbering occurs.
1152 pub fn eagerly_format(&self, msg: impl Into<DiagMessage>) -> DiagMessage {
1153 let args = self.args.iter();
1154 self.dcx.eagerly_format(msg.into(), args)
1155 }
1156
11571135 with_fn! { with_span,
11581136 /// Add a span.
11591137 pub fn span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self {
......@@ -1341,12 +1319,6 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
13411319 self.downgrade_to_delayed_bug();
13421320 self.emit()
13431321 }
1344
1345 pub fn remove_arg(&mut self, name: &str) {
1346 if let Some(diag) = self.diag.as_mut() {
1347 diag.remove_arg(name);
1348 }
1349 }
13501322}
13511323
13521324/// Destructor bomb: every `Diag` must be consumed (emitted, cancelled, etc.)
compiler/rustc_errors/src/formatting.rs+66-24
......@@ -1,7 +1,7 @@
11use std::borrow::Cow;
22
33pub use rustc_error_messages::FluentArgs;
4use rustc_error_messages::{DiagArgMap, langid, register_functions};
4use rustc_error_messages::{DiagArgMap, DiagArgName, IntoDiagArg, langid, register_functions};
55use tracing::{debug, trace};
66
77use crate::fluent_bundle::FluentResource;
......@@ -33,30 +33,72 @@ pub fn format_diag_messages(
3333
3434/// Convert a `DiagMessage` to a string
3535pub fn format_diag_message<'a>(message: &'a DiagMessage, args: &DiagArgMap) -> Cow<'a, str> {
36 trace!(?message, ?args);
37
3836 match message {
3937 DiagMessage::Str(msg) => Cow::Borrowed(msg),
40 DiagMessage::Inline(msg) => {
41 const GENERATED_MSG_ID: &str = "generated_msg";
42 let resource =
43 FluentResource::try_new(format!("{GENERATED_MSG_ID} = {msg}\n")).unwrap();
44 let mut bundle = fluent_bundle::FluentBundle::new(vec![langid!("en-US")]);
45 bundle.set_use_isolating(false);
46 bundle.add_resource(resource).unwrap();
47 register_functions(&mut bundle);
48 let message = bundle.get_message(GENERATED_MSG_ID).unwrap();
49 let value = message.value().unwrap();
50 let args = to_fluent_args(args.iter());
51
52 let mut errs = vec![];
53 let formatted = bundle.format_pattern(value, Some(&args), &mut errs).to_string();
54 debug!(?formatted, ?errs);
55 if errs.is_empty() {
56 Cow::Owned(formatted)
57 } else {
58 panic!("Fluent errors while formatting message: {errs:?}");
59 }
60 }
38 DiagMessage::Inline(msg) => format_fluent_str(msg, args),
39 }
40}
41
42fn format_fluent_str(message: &str, args: &DiagArgMap) -> Cow<'static, str> {
43 trace!(?message, ?args);
44 const GENERATED_MSG_ID: &str = "generated_msg";
45 let resource = FluentResource::try_new(format!("{GENERATED_MSG_ID} = {message}\n")).unwrap();
46 let mut bundle = fluent_bundle::FluentBundle::new(vec![langid!("en-US")]);
47 bundle.set_use_isolating(false);
48 bundle.add_resource(resource).unwrap();
49 register_functions(&mut bundle);
50 let message = bundle.get_message(GENERATED_MSG_ID).unwrap();
51 let value = message.value().unwrap();
52 let args = to_fluent_args(args.iter());
53
54 let mut errs = vec![];
55 let formatted = bundle.format_pattern(value, Some(&args), &mut errs).to_string();
56 debug!(?formatted, ?errs);
57 if errs.is_empty() {
58 Cow::Owned(formatted)
59 } else {
60 panic!("Fluent errors while formatting message: {errs:?}");
61 }
62}
63
64pub trait DiagMessageAddArg {
65 fn arg(self, name: impl Into<DiagArgName>, arg: impl IntoDiagArg) -> EagerDiagMessageBuilder;
66}
67
68pub struct EagerDiagMessageBuilder {
69 fluent_str: Cow<'static, str>,
70 args: DiagArgMap,
71}
72
73impl DiagMessageAddArg for EagerDiagMessageBuilder {
74 fn arg(
75 mut self,
76 name: impl Into<DiagArgName>,
77 arg: impl IntoDiagArg,
78 ) -> EagerDiagMessageBuilder {
79 let name = name.into();
80 let value = arg.into_diag_arg(&mut None);
81 debug_assert!(
82 !self.args.contains_key(&name) || self.args.get(&name) == Some(&value),
83 "arg {} already exists",
84 name
85 );
86 self.args.insert(name, value);
87 self
88 }
89}
90
91impl DiagMessageAddArg for DiagMessage {
92 fn arg(self, name: impl Into<DiagArgName>, arg: impl IntoDiagArg) -> EagerDiagMessageBuilder {
93 let DiagMessage::Inline(fluent_str) = self else {
94 panic!("Tried to eagerly format an already formatted message")
95 };
96 EagerDiagMessageBuilder { fluent_str, args: Default::default() }.arg(name, arg)
97 }
98}
99
100impl EagerDiagMessageBuilder {
101 pub fn format(self) -> DiagMessage {
102 DiagMessage::Str(format_fluent_str(&self.fluent_str, &self.args))
61103 }
62104}
compiler/rustc_errors/src/lib.rs+9-57
......@@ -66,7 +66,8 @@ use rustc_span::{DUMMY_SP, Span};
6666use tracing::debug;
6767
6868use crate::emitter::TimingEvent;
69use crate::formatting::format_diag_message;
69use crate::formatting::DiagMessageAddArg;
70pub use crate::formatting::format_diag_message;
7071use crate::timings::TimingRecord;
7172
7273pub mod annotate_snippet_emitter_writer;
......@@ -482,26 +483,6 @@ impl DiagCtxt {
482483 self.inner.borrow_mut().emitter = emitter;
483484 }
484485
485 /// Format `message` eagerly with `args` to `DiagMessage::Eager`.
486 pub fn eagerly_format<'a>(
487 &self,
488 message: DiagMessage,
489 args: impl Iterator<Item = DiagArg<'a>>,
490 ) -> DiagMessage {
491 let inner = self.inner.borrow();
492 inner.eagerly_format(message, args)
493 }
494
495 /// Format `message` eagerly with `args` to `String`.
496 pub fn eagerly_format_to_string<'a>(
497 &self,
498 message: DiagMessage,
499 args: impl Iterator<Item = DiagArg<'a>>,
500 ) -> String {
501 let inner = self.inner.borrow();
502 inner.eagerly_format_to_string(message, args)
503 }
504
505486 // This is here to not allow mutation of flags;
506487 // as of this writing it's used in Session::consider_optimizing and
507488 // in tests in rustc_interface.
......@@ -1417,33 +1398,6 @@ impl DiagCtxtInner {
14171398 self.has_errors().or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied())
14181399 }
14191400
1420 /// Format `message` eagerly with `args` to `DiagMessage::Eager`.
1421 fn eagerly_format<'a>(
1422 &self,
1423 message: DiagMessage,
1424 args: impl Iterator<Item = DiagArg<'a>>,
1425 ) -> DiagMessage {
1426 DiagMessage::Str(Cow::from(self.eagerly_format_to_string(message, args)))
1427 }
1428
1429 /// Format `message` eagerly with `args` to `String`.
1430 fn eagerly_format_to_string<'a>(
1431 &self,
1432 message: DiagMessage,
1433 args: impl Iterator<Item = DiagArg<'a>>,
1434 ) -> String {
1435 let args = args.map(|(name, val)| (name.clone(), val.clone())).collect();
1436 format_diag_message(&message, &args).to_string()
1437 }
1438
1439 fn eagerly_format_for_subdiag(
1440 &self,
1441 diag: &DiagInner,
1442 msg: impl Into<DiagMessage>,
1443 ) -> DiagMessage {
1444 self.eagerly_format(msg.into(), diag.args.iter())
1445 }
1446
14471401 fn flush_delayed(&mut self) {
14481402 // Stashed diagnostics must be emitted before delayed bugs are flushed.
14491403 // Otherwise, we might ICE prematurely when errors would have
......@@ -1493,7 +1447,7 @@ impl DiagCtxtInner {
14931447 );
14941448 }
14951449
1496 let mut bug = if decorate { bug.decorate(self) } else { bug.inner };
1450 let mut bug = if decorate { bug.decorate() } else { bug.inner };
14971451
14981452 // "Undelay" the delayed bugs into plain bugs.
14991453 if bug.level != DelayedBug {
......@@ -1503,11 +1457,9 @@ impl DiagCtxtInner {
15031457 // We are at the `DiagInner`/`DiagCtxtInner` level rather than
15041458 // the usual `Diag`/`DiagCtxt` level, so we must augment `bug`
15051459 // in a lower-level fashion.
1506 bug.arg("level", bug.level);
15071460 let msg = msg!(
15081461 "`flushed_delayed` got diagnostic with level {$level}, instead of the expected `DelayedBug`"
1509 );
1510 let msg = self.eagerly_format_for_subdiag(&bug, msg); // after the `arg` call
1462 ).arg("level", bug.level).format();
15111463 bug.sub(Note, msg, bug.span.primary_span().unwrap().into());
15121464 }
15131465 bug.level = Bug;
......@@ -1542,7 +1494,7 @@ impl DelayedDiagInner {
15421494 DelayedDiagInner { inner: diagnostic, note: backtrace }
15431495 }
15441496
1545 fn decorate(self, dcx: &DiagCtxtInner) -> DiagInner {
1497 fn decorate(self) -> DiagInner {
15461498 // We are at the `DiagInner`/`DiagCtxtInner` level rather than the
15471499 // usual `Diag`/`DiagCtxt` level, so we must construct `diag` in a
15481500 // lower-level fashion.
......@@ -1555,10 +1507,10 @@ impl DelayedDiagInner {
15551507 // Avoid the needless newline when no backtrace has been captured,
15561508 // the display impl should just be a single line.
15571509 _ => msg!("delayed at {$emitted_at} - {$note}"),
1558 };
1559 diag.arg("emitted_at", diag.emitted_at.clone());
1560 diag.arg("note", self.note);
1561 let msg = dcx.eagerly_format_for_subdiag(&diag, msg); // after the `arg` calls
1510 }
1511 .arg("emitted_at", diag.emitted_at.clone())
1512 .arg("note", self.note)
1513 .format();
15621514 diag.sub(Note, msg, diag.span.primary_span().unwrap_or(DUMMY_SP).into());
15631515 diag
15641516 }
compiler/rustc_hir_typeck/src/errors.rs+7-3
......@@ -987,13 +987,17 @@ impl rustc_errors::Subdiagnostic for CastUnknownPointerSub {
987987 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
988988 match self {
989989 CastUnknownPointerSub::To(span) => {
990 let msg = diag.eagerly_format(msg!("needs more type information"));
990 let msg = msg!("needs more type information");
991991 diag.span_label(span, msg);
992 let msg = diag.eagerly_format(msg!("the type information given here is insufficient to check whether the pointer cast is valid"));
992 let msg = msg!(
993 "the type information given here is insufficient to check whether the pointer cast is valid"
994 );
993995 diag.note(msg);
994996 }
995997 CastUnknownPointerSub::From(span) => {
996 let msg = diag.eagerly_format(msg!("the type information given here is insufficient to check whether the pointer cast is valid"));
998 let msg = msg!(
999 "the type information given here is insufficient to check whether the pointer cast is valid"
1000 );
9971001 diag.span_label(span, msg);
9981002 }
9991003 }
compiler/rustc_lint/src/builtin.rs+1-1
......@@ -2242,10 +2242,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
22422242 EXPLICIT_OUTLIVES_REQUIREMENTS,
22432243 lint_spans.clone(),
22442244 BuiltinExplicitOutlives {
2245 count: bound_count,
22462245 suggestion: BuiltinExplicitOutlivesSuggestion {
22472246 spans: lint_spans,
22482247 applicability,
2248 count: bound_count,
22492249 },
22502250 },
22512251 );
compiler/rustc_lint/src/if_let_rescope.rs+2-3
......@@ -354,9 +354,8 @@ impl Subdiagnostic for IfLetRescopeRewrite {
354354 .chain(repeat_n('}', closing_brackets.count))
355355 .collect(),
356356 ));
357 let msg = diag.eagerly_format(msg!(
358 "a `match` with a single arm can preserve the drop order up to Edition 2021"
359 ));
357 let msg =
358 msg!("a `match` with a single arm can preserve the drop order up to Edition 2021");
360359 diag.multipart_suggestion_with_style(
361360 msg,
362361 suggestions,
compiler/rustc_lint/src/lints.rs+5-4
......@@ -3,6 +3,7 @@
33use std::num::NonZero;
44
55use rustc_errors::codes::*;
6use rustc_errors::formatting::DiagMessageAddArg;
67use rustc_errors::{
78 Applicability, Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
89 ElidedLifetimeInPathSubdiag, EmissionGuarantee, Level, MultiSpan, Subdiagnostic,
......@@ -492,7 +493,6 @@ pub(crate) struct BuiltinKeywordIdents {
492493#[derive(Diagnostic)]
493494#[diag("outlives requirements can be inferred")]
494495pub(crate) struct BuiltinExplicitOutlives {
495 pub count: usize,
496496 #[subdiagnostic]
497497 pub suggestion: BuiltinExplicitOutlivesSuggestion,
498498}
......@@ -509,6 +509,7 @@ pub(crate) struct BuiltinExplicitOutlivesSuggestion {
509509 pub spans: Vec<Span>,
510510 #[applicability]
511511 pub applicability: Applicability,
512 pub count: usize,
512513}
513514
514515#[derive(Diagnostic)]
......@@ -3628,9 +3629,9 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
36283629 }
36293630
36303631 Explicit { lifetime_name, suggestions, optional_alternative } => {
3631 diag.arg("lifetime_name", lifetime_name);
3632 let msg = diag.eagerly_format(msg!("consistently use `{$lifetime_name}`"));
3633 diag.remove_arg("lifetime_name");
3632 let msg = msg!("consistently use `{$lifetime_name}`")
3633 .arg("lifetime_name", lifetime_name)
3634 .format();
36343635 diag.multipart_suggestion_with_style(
36353636 msg,
36363637 suggestions,
compiler/rustc_lint_defs/src/builtin.rs+35
......@@ -61,6 +61,7 @@ declare_lint_pass! {
6161 LARGE_ASSIGNMENTS,
6262 LATE_BOUND_LIFETIME_ARGUMENTS,
6363 LEGACY_DERIVE_HELPERS,
64 LINKER_INFO,
6465 LINKER_MESSAGES,
6566 LONG_RUNNING_CONST_EVAL,
6667 LOSSY_PROVENANCE_CASTS,
......@@ -4062,6 +4063,40 @@ declare_lint! {
40624063 "warnings emitted at runtime by the target-specific linker program"
40634064}
40644065
4066declare_lint! {
4067 /// The `linker_info` lint forwards warnings from the linker that are known to be informational-only.
4068 ///
4069 /// ### Example
4070 ///
4071 /// ```rust,ignore (needs CLI args, platform-specific)
4072 /// #[warn(linker_info)]
4073 /// fn main () {}
4074 /// ```
4075 ///
4076 /// On MacOS, using `-C link-arg=-lc` and the default linker, this will produce
4077 ///
4078 /// ```text
4079 /// warning: linker stderr: ld: ignoring duplicate libraries: '-lc'
4080 /// |
4081 /// note: the lint level is defined here
4082 /// --> ex.rs:1:9
4083 /// |
4084 /// 1 | #![warn(linker_info)]
4085 /// | ^^^^^^^^^^^^^^^
4086 /// ```
4087 ///
4088 /// ### Explanation
4089 ///
4090 /// Many linkers are very "chatty" and print lots of information that is not necessarily
4091 /// indicative of an issue. This output has been ignored for many years and is often not
4092 /// actionable by developers. It is silenced unless the developer specifically requests for it
4093 /// to be printed. See this tracking issue for more details:
4094 /// <https://github.com/rust-lang/rust/issues/136096>.
4095 pub LINKER_INFO,
4096 Allow,
4097 "linker warnings known to be informational-only and not indicative of a problem"
4098}
4099
40654100declare_lint! {
40664101 /// The `named_arguments_used_positionally` lint detects cases where named arguments are only
40674102 /// used positionally in format strings. This usage is valid but potentially very confusing.
compiler/rustc_macros/src/diagnostics/message.rs+31-11
......@@ -64,26 +64,46 @@ fn verify_variables_used(msg_span: Span, message_str: &str, variant: Option<&Var
6464
6565fn variable_references<'a>(msg: &fluent_syntax::ast::Message<&'a str>) -> Vec<&'a str> {
6666 let mut refs = vec![];
67
6768 if let Some(Pattern { elements }) = &msg.value {
6869 for elt in elements {
69 if let PatternElement::Placeable {
70 expression: Expression::Inline(InlineExpression::VariableReference { id }),
71 } = elt
72 {
73 refs.push(id.name);
74 }
70 traverse_pattern(elt, &mut refs);
7571 }
7672 }
7773 for attr in &msg.attributes {
7874 for elt in &attr.value.elements {
79 if let PatternElement::Placeable {
80 expression: Expression::Inline(InlineExpression::VariableReference { id }),
81 } = elt
82 {
83 refs.push(id.name);
75 traverse_pattern(elt, &mut refs);
76 }
77 }
78
79 fn traverse_pattern<'a>(elem: &PatternElement<&'a str>, refs: &mut Vec<&'a str>) {
80 match elem {
81 PatternElement::TextElement { .. } => {}
82 PatternElement::Placeable { expression } => traverse_expression(expression, refs),
83 }
84 }
85 fn traverse_expression<'a>(expr: &Expression<&'a str>, refs: &mut Vec<&'a str>) {
86 match expr {
87 Expression::Select { selector, variants } => {
88 traverse_inline_expr(selector, refs);
89 for variant in variants {
90 for pattern in &variant.value.elements {
91 traverse_pattern(pattern, refs);
92 }
93 }
94 }
95 Expression::Inline(expr) => {
96 traverse_inline_expr(expr, refs);
8497 }
8598 }
8699 }
100 fn traverse_inline_expr<'a>(elem: &InlineExpression<&'a str>, refs: &mut Vec<&'a str>) {
101 match elem {
102 InlineExpression::VariableReference { id } => refs.push(id.name),
103 _ => {}
104 }
105 }
106
87107 refs
88108}
89109
compiler/rustc_macros/src/diagnostics/subdiagnostic.rs+18-20
......@@ -227,9 +227,9 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
227227 let ident = format_ident!("{}", ident); // strip `r#` prefix, if present
228228
229229 quote! {
230 #diag.arg(
231 stringify!(#ident),
232 #field_binding
230 sub_args.insert(
231 stringify!(#ident).into(),
232 rustc_errors::IntoDiagArg::into_diag_arg(#field_binding, &mut #diag.long_ty_path)
233233 );
234234 }
235235 }
......@@ -529,14 +529,25 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
529529 }
530530 };
531531
532 let span_field = self.span_field.value_ref();
532 let plain_args: TokenStream = self
533 .variant
534 .bindings()
535 .iter()
536 .filter(|binding| should_generate_arg(binding.ast()))
537 .map(|binding| self.generate_field_arg(binding))
538 .collect();
539 let plain_args = quote! {
540 let mut sub_args = rustc_errors::DiagArgMap::default();
541 #plain_args
542 };
533543
544 let span_field = self.span_field.value_ref();
534545 let diag = &self.parent.diag;
535546 let mut calls = TokenStream::new();
536547 for (kind, messages) in kind_messages {
537548 let message = format_ident!("__message");
538549 let message_stream = messages.diag_message(Some(self.variant));
539 calls.extend(quote! { let #message = #diag.eagerly_format(#message_stream); });
550 calls.extend(quote! { let #message = rustc_errors::format_diag_message(&#message_stream, &sub_args); });
540551
541552 let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind);
542553 let call = match kind {
......@@ -600,19 +611,6 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
600611
601612 calls.extend(call);
602613 }
603 let store_args = quote! {
604 #diag.store_args();
605 };
606 let restore_args = quote! {
607 #diag.restore_args();
608 };
609 let plain_args: TokenStream = self
610 .variant
611 .bindings()
612 .iter()
613 .filter(|binding| should_generate_arg(binding.ast()))
614 .map(|binding| self.generate_field_arg(binding))
615 .collect();
616614
617615 let formatting_init = &self.formatting_init;
618616
......@@ -626,10 +624,10 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> {
626624 #init
627625 #formatting_init
628626 #attr_args
629 #store_args
627 // #store_args
630628 #plain_args
631629 #calls
632 #restore_args
630 // #restore_args
633631 })
634632 }
635633}
compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs+22-22
......@@ -5,6 +5,7 @@ use std::rc::Rc;
55use itertools::Itertools as _;
66use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
77use rustc_data_structures::unord::{UnordMap, UnordSet};
8use rustc_errors::formatting::DiagMessageAddArg;
89use rustc_errors::{Subdiagnostic, msg};
910use rustc_hir::CRATE_HIR_ID;
1011use rustc_hir::def_id::LocalDefId;
......@@ -524,31 +525,30 @@ struct LocalLabel<'a> {
524525/// A custom `Subdiagnostic` implementation so that the notes are delivered in a specific order
525526impl Subdiagnostic for LocalLabel<'_> {
526527 fn add_to_diag<G: rustc_errors::EmissionGuarantee>(self, diag: &mut rustc_errors::Diag<'_, G>) {
527 // Because parent uses this field , we need to remove it delay before adding it.
528 diag.remove_arg("name");
529 diag.arg("name", self.name);
530 diag.remove_arg("is_generated_name");
531 diag.arg("is_generated_name", self.is_generated_name);
532 diag.remove_arg("is_dropped_first_edition_2024");
533 diag.arg("is_dropped_first_edition_2024", self.is_dropped_first_edition_2024);
534 let msg = diag.eagerly_format(msg!(
535 "{$is_generated_name ->
536 [true] this value will be stored in a temporary; let us call it `{$name}`
537 *[false] `{$name}` calls a custom destructor
538 }"
539 ));
540 diag.span_label(self.span, msg);
528 diag.span_label(
529 self.span,
530 msg!(
531 "{$is_generated_name ->
532 [true] this value will be stored in a temporary; let us call it `{$name}`
533 *[false] `{$name}` calls a custom destructor
534 }"
535 )
536 .arg("name", self.name)
537 .arg("is_generated_name", self.is_generated_name)
538 .format(),
539 );
541540 for dtor in self.destructors {
542541 dtor.add_to_diag(diag);
543542 }
544 let msg =
545 diag.eagerly_format(msg!(
546 "{$is_dropped_first_edition_2024 ->
547 [true] up until Edition 2021 `{$name}` is dropped last but will be dropped earlier in Edition 2024
548 *[false] `{$name}` will be dropped later as of Edition 2024
549 }"
550 ));
551 diag.span_label(self.span, msg);
543 diag.span_label(self.span, msg!(
544 "{$is_dropped_first_edition_2024 ->
545 [true] up until Edition 2021 `{$name}` is dropped last but will be dropped earlier in Edition 2024
546 *[false] `{$name}` will be dropped later as of Edition 2024
547 }"
548 )
549 .arg("is_dropped_first_edition_2024", self.is_dropped_first_edition_2024)
550 .arg("name", self.name)
551 .format());
552552 }
553553}
554554
compiler/rustc_parse/src/errors.rs+1
......@@ -1179,6 +1179,7 @@ pub(crate) enum MatchArmBodyWithoutBracesSugg {
11791179 left: Span,
11801180 #[suggestion_part(code = " }}")]
11811181 right: Span,
1182 num_statements: usize,
11821183 },
11831184 #[suggestion(
11841185 "replace `;` with `,` to end a `match` arm expression",
compiler/rustc_parse/src/parser/expr.rs+1
......@@ -3207,6 +3207,7 @@ impl<'a> Parser<'a> {
32073207 errors::MatchArmBodyWithoutBracesSugg::AddBraces {
32083208 left: span.shrink_to_lo(),
32093209 right: span.shrink_to_hi(),
3210 num_statements: stmts.len(),
32103211 }
32113212 } else {
32123213 errors::MatchArmBodyWithoutBracesSugg::UseComma { semicolon: semi_sp }
compiler/rustc_passes/src/check_attr.rs+3-1
......@@ -1598,7 +1598,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
15981598 sym::expect,
15991599 ]) && let Some(meta) = attr.meta_item_list()
16001600 && meta.iter().any(|meta| {
1601 meta.meta_item().map_or(false, |item| item.path == sym::linker_messages)
1601 meta.meta_item().map_or(false, |item| {
1602 item.path == sym::linker_messages || item.path == sym::linker_info
1603 })
16021604 })
16031605 {
16041606 if hir_id != CRATE_HIR_ID {
compiler/rustc_passes/src/errors.rs+1-1
......@@ -301,7 +301,7 @@ pub(crate) enum UnusedNote {
301301 #[note("`default_method_body_is_const` has been replaced with `const` on traits")]
302302 DefaultMethodBodyConst,
303303 #[note(
304 "the `linker_messages` lint can only be controlled at the root of a crate that needs to be linked"
304 "the `linker_messages` and `linker_info` lints can only be controlled at the root of a crate that needs to be linked"
305305 )]
306306 LinkerMessagesBinaryCrateOnly,
307307}
compiler/rustc_resolve/src/diagnostics.rs+2
......@@ -1,3 +1,4 @@
1// ignore-tidy-filelength
12use std::ops::ControlFlow;
23
34use itertools::Itertools as _;
......@@ -579,6 +580,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
579580 errs::GenericParamsFromOuterItemInnerItem {
580581 span: *span,
581582 descr: kind.descr().to_string(),
583 is_self,
582584 }
583585 }),
584586 };
compiler/rustc_resolve/src/errors.rs+5-5
......@@ -1,4 +1,5 @@
11use rustc_errors::codes::*;
2use rustc_errors::formatting::DiagMessageAddArg;
23use rustc_errors::{
34 Applicability, Diag, DiagCtxtHandle, DiagMessage, Diagnostic, ElidedLifetimeInPathSubdiag,
45 EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg,
......@@ -51,6 +52,7 @@ pub(crate) struct GenericParamsFromOuterItemInnerItem {
5152 #[primary_span]
5253 pub(crate) span: Span,
5354 pub(crate) descr: String,
55 pub(crate) is_self: bool,
5456}
5557
5658#[derive(Subdiagnostic)]
......@@ -1364,12 +1366,10 @@ impl Subdiagnostic for FoundItemConfigureOut {
13641366 let mut multispan: MultiSpan = self.span.into();
13651367 match self.item_was {
13661368 ItemWas::BehindFeature { feature, span } => {
1367 let key = "feature".into();
13681369 let value = feature.into_diag_arg(&mut None);
1369 let msg = diag.dcx.eagerly_format_to_string(
1370 msg!("the item is gated behind the `{$feature}` feature"),
1371 [(&key, &value)].into_iter(),
1372 );
1370 let msg = msg!("the item is gated behind the `{$feature}` feature")
1371 .arg("feature", value)
1372 .format();
13731373 multispan.push_span_label(span, msg);
13741374 }
13751375 ItemWas::CfgOut { span } => {
compiler/rustc_session/src/errors.rs+1-1
......@@ -539,5 +539,5 @@ pub(crate) struct UnexpectedBuiltinCfg {
539539}
540540
541541#[derive(Diagnostic)]
542#[diag("ThinLTO is not supported by the codegen backend")]
542#[diag("ThinLTO is not supported by the codegen backend, using fat LTO instead")]
543543pub(crate) struct ThinLtoNotSupportedByBackend;
compiler/rustc_session/src/session.rs+2-2
......@@ -620,9 +620,9 @@ impl Session {
620620 config::LtoCli::Thin => {
621621 // The user explicitly asked for ThinLTO
622622 if !self.thin_lto_supported {
623 // Backend doesn't support ThinLTO, disable LTO.
623 // Backend doesn't support ThinLTO, fallback to fat LTO.
624624 self.dcx().emit_warn(errors::ThinLtoNotSupportedByBackend);
625 return config::Lto::No;
625 return config::Lto::Fat;
626626 }
627627 return config::Lto::Thin;
628628 }
compiler/rustc_span/src/symbol.rs+1
......@@ -1152,6 +1152,7 @@ symbols! {
11521152 link_section,
11531153 linkage,
11541154 linker,
1155 linker_info,
11551156 linker_messages,
11561157 linkonce,
11571158 linkonce_odr,
compiler/rustc_trait_selection/src/errors.rs+28-65
......@@ -1,5 +1,6 @@
11use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
22use rustc_errors::codes::*;
3use rustc_errors::formatting::DiagMessageAddArg;
34use rustc_errors::{
45 Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic,
56 EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg,
......@@ -450,28 +451,23 @@ impl Subdiagnostic for RegionOriginNote<'_> {
450451 requirement,
451452 expected_found: Some((expected, found)),
452453 } => {
453 // `RegionOriginNote` can appear multiple times on one diagnostic with different
454 // `requirement` values. Scope args per-note and eagerly translate to avoid
455 // cross-note arg collisions.
456 // See https://github.com/rust-lang/rust/issues/143872 for details.
457 diag.store_args();
458 diag.arg("requirement", requirement);
459 let msg = diag.eagerly_format(msg!(
454 let msg = msg!(
460455 "...so that the {$requirement ->
461 [method_compat] method type is compatible with trait
462 [type_compat] associated type is compatible with trait
463 [const_compat] const is compatible with trait
464 [expr_assignable] expression is assignable
465 [if_else_different] `if` and `else` have incompatible types
466 [no_else] `if` missing an `else` returns `()`
467 [fn_main_correct_type] `main` function has the correct type
468 [fn_lang_correct_type] lang item function has the correct type
469 [intrinsic_correct_type] intrinsic has the correct type
470 [method_correct_type] method receiver has the correct type
471 *[other] types are compatible
472 }"
473 ));
474 diag.restore_args();
456 [method_compat] method type is compatible with trait
457 [type_compat] associated type is compatible with trait
458 [const_compat] const is compatible with trait
459 [expr_assignable] expression is assignable
460 [if_else_different] `if` and `else` have incompatible types
461 [no_else] `if` missing an `else` returns `()`
462 [fn_main_correct_type] `main` function has the correct type
463 [fn_lang_correct_type] lang item function has the correct type
464 [intrinsic_correct_type] intrinsic has the correct type
465 [method_correct_type] method receiver has the correct type
466 *[other] types are compatible
467 }"
468 )
469 .arg("requirement", requirement)
470 .format();
475471 label_or_note(diag, span, msg);
476472
477473 diag.note_expected_found("", expected, "", found);
......@@ -480,9 +476,7 @@ impl Subdiagnostic for RegionOriginNote<'_> {
480476 // FIXME: this really should be handled at some earlier stage. Our
481477 // handling of region checking when type errors are present is
482478 // *terrible*.
483 diag.store_args();
484 diag.arg("requirement", requirement);
485 let msg = diag.eagerly_format(msg!(
479 let msg = msg!(
486480 "...so that {$requirement ->
487481 [method_compat] method type is compatible with trait
488482 [type_compat] associated type is compatible with trait
......@@ -496,8 +490,9 @@ impl Subdiagnostic for RegionOriginNote<'_> {
496490 [method_correct_type] method receiver has the correct type
497491 *[other] types are compatible
498492 }"
499 ));
500 diag.restore_args();
493 )
494 .arg("requirement", requirement)
495 .format();
501496 label_or_note(diag, span, msg);
502497 }
503498 };
......@@ -1174,7 +1169,9 @@ impl Subdiagnostic for ConsiderBorrowingParamHelp {
11741169 type_param_span
11751170 .push_span_label(span, msg!("consider borrowing this type parameter in the trait"));
11761171 }
1177 let msg = diag.eagerly_format(msg!("the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"));
1172 let msg = msg!(
1173 "the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`"
1174 );
11781175 diag.span_help(type_param_span, msg);
11791176 }
11801177}
......@@ -1218,9 +1215,9 @@ impl Subdiagnostic for DynTraitConstraintSuggestion {
12181215 self.ident.span,
12191216 msg!("calling this method introduces the `impl`'s `'static` requirement"),
12201217 );
1221 let msg = diag.eagerly_format(msg!("the used `impl` has a `'static` requirement"));
1218 let msg = msg!("the used `impl` has a `'static` requirement");
12221219 diag.span_note(multi_span, msg);
1223 let msg = diag.eagerly_format(msg!("consider relaxing the implicit `'static` requirement"));
1220 let msg = msg!("consider relaxing the implicit `'static` requirement");
12241221 diag.span_suggestion_verbose(
12251222 self.span.shrink_to_hi(),
12261223 msg,
......@@ -1230,38 +1227,6 @@ impl Subdiagnostic for DynTraitConstraintSuggestion {
12301227 }
12311228}
12321229
1233#[derive(Diagnostic)]
1234#[diag("{$has_param_name ->
1235 [true] `{$param_name}`
1236 *[false] `fn` parameter
1237} has {$lifetime_kind ->
1238 [true] lifetime `{$lifetime}`
1239 *[false] an anonymous lifetime `'_`
1240} but calling `{$assoc_item}` introduces an implicit `'static` lifetime requirement", code = E0772)]
1241pub struct ButCallingIntroduces {
1242 #[label(
1243 "{$has_lifetime ->
1244 [true] lifetime `{$lifetime}`
1245 *[false] an anonymous lifetime `'_`
1246 }"
1247 )]
1248 pub param_ty_span: Span,
1249 #[primary_span]
1250 #[label("...is used and required to live as long as `'static` here because of an implicit lifetime bound on the {$has_impl_path ->
1251 [true] `impl` of `{$impl_path}`
1252 *[false] inherent `impl`
1253 }")]
1254 pub cause_span: Span,
1255
1256 pub has_param_name: bool,
1257 pub param_name: String,
1258 pub has_lifetime: bool,
1259 pub lifetime: String,
1260 pub assoc_item: Symbol,
1261 pub has_impl_path: bool,
1262 pub impl_path: String,
1263}
1264
12651230pub struct ReqIntroducedLocations {
12661231 pub span: MultiSpan,
12671232 pub spans: Vec<Span>,
......@@ -1283,8 +1248,7 @@ impl Subdiagnostic for ReqIntroducedLocations {
12831248 );
12841249 }
12851250 self.span.push_span_label(self.cause_span, msg!("because of this returned expression"));
1286 let msg = diag
1287 .eagerly_format(msg!("\"`'static` lifetime requirement introduced by the return type"));
1251 let msg = msg!("\"`'static` lifetime requirement introduced by the return type");
12881252 diag.span_note(self.span, msg);
12891253 }
12901254}
......@@ -1724,8 +1688,7 @@ pub struct SuggestTuplePatternMany {
17241688impl Subdiagnostic for SuggestTuplePatternMany {
17251689 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
17261690 diag.arg("path", self.path);
1727 let message =
1728 diag.eagerly_format(msg!("try wrapping the pattern in a variant of `{$path}`"));
1691 let message = msg!("try wrapping the pattern in a variant of `{$path}`");
17291692 diag.multipart_suggestions(
17301693 message,
17311694 self.compatible_variants.into_iter().map(|variant| {
compiler/rustc_trait_selection/src/errors/note_and_explain.rs+10-9
......@@ -1,3 +1,4 @@
1use rustc_errors::formatting::DiagMessageAddArg;
12use rustc_errors::{Diag, EmissionGuarantee, IntoDiagArg, Subdiagnostic, msg};
23use rustc_hir::def_id::LocalDefId;
34use rustc_middle::bug;
......@@ -163,13 +164,7 @@ impl RegionExplanation<'_> {
163164
164165impl Subdiagnostic for RegionExplanation<'_> {
165166 fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
166 diag.store_args();
167 diag.arg("pref_kind", self.prefix);
168 diag.arg("suff_kind", self.suffix);
169 diag.arg("desc_kind", self.desc.kind);
170 diag.arg("desc_arg", self.desc.arg);
171
172 let msg = diag.eagerly_format(msg!(
167 let msg = msg!(
173168 "{$pref_kind ->
174169 *[should_not_happen] [{$pref_kind}]
175170 [ref_valid_for] ...the reference is valid for
......@@ -202,8 +197,14 @@ impl Subdiagnostic for RegionExplanation<'_> {
202197 [continues] ...
203198 [req_by_binding] {\" \"}as required by this binding
204199 }"
205 ));
206 diag.restore_args();
200 )
201 .arg("pref_kind", self.prefix)
202 .arg("suff_kind", self.suffix)
203 .arg("desc_kind", self.desc.kind)
204 .arg("desc_arg", self.desc.arg)
205 .format();
206
207 // diag.restore_args();
207208 if let Some(span) = self.desc.span {
208209 diag.span_note(span, msg);
209210 } else {
src/ci/docker/host-x86_64/arm-android/Dockerfile+2-2
......@@ -32,9 +32,9 @@ ENV PATH=$PATH:/android/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin
3232
3333ENV TARGETS=arm-linux-androideabi
3434
35ENV RUST_CONFIGURE_ARGS --android-ndk=/android/ndk/
35ENV RUST_CONFIGURE_ARGS="--android-ndk=/android/ndk/"
3636
37ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target $TARGETS
37ENV SCRIPT="python3 ../x.py --stage 2 test --host= --target $TARGETS"
3838
3939COPY scripts/sccache.sh /scripts/
4040RUN sh /scripts/sccache.sh
src/ci/docker/host-x86_64/armhf-gnu/Dockerfile+2-2
......@@ -82,7 +82,7 @@ RUN sh /scripts/sccache.sh
8282
8383COPY static/gitconfig /etc/gitconfig
8484
85ENV RUST_CONFIGURE_ARGS --qemu-armhf-rootfs=/tmp/rootfs
86ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target arm-unknown-linux-gnueabihf
85ENV RUST_CONFIGURE_ARGS="--qemu-armhf-rootfs=/tmp/rootfs"
86ENV SCRIPT="python3 ../x.py --stage 2 test --host= --target arm-unknown-linux-gnueabihf"
8787
8888ENV NO_CHANGE_USER=1
src/ci/docker/host-x86_64/dist-arm-linux-gnueabi/Dockerfile+3-4
......@@ -27,9 +27,8 @@ ENV CC_arm_unknown_linux_gnueabi=arm-unknown-linux-gnueabi-gcc \
2727
2828ENV HOSTS=arm-unknown-linux-gnueabi
2929
30ENV RUST_CONFIGURE_ARGS \
31 --enable-full-tools \
30ENV RUST_CONFIGURE_ARGS="--enable-full-tools \
3231 --disable-docs \
3332 --enable-sanitizers \
34 --enable-profiler
35ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
33 --enable-profiler"
34ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS"
src/ci/docker/host-x86_64/dist-arm-linux-musl/Dockerfile+3-4
......@@ -18,11 +18,10 @@ RUN sh /scripts/sccache.sh
1818
1919ENV HOSTS=aarch64-unknown-linux-musl
2020
21ENV RUST_CONFIGURE_ARGS \
22 --enable-full-tools \
21ENV RUST_CONFIGURE_ARGS="--enable-full-tools \
2322 --disable-docs \
2423 --musl-root-aarch64=/usr/local/aarch64-linux-musl \
2524 --enable-sanitizers \
2625 --enable-profiler \
27 --set target.aarch64-unknown-linux-musl.crt-static=false
28ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
26 --set target.aarch64-unknown-linux-musl.crt-static=false"
27ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS"
src/ci/docker/host-x86_64/dist-armhf-linux/Dockerfile+2-2
......@@ -25,5 +25,5 @@ ENV CC_arm_unknown_linux_gnueabihf=arm-unknown-linux-gnueabihf-gcc \
2525
2626ENV HOSTS=arm-unknown-linux-gnueabihf
2727
28ENV RUST_CONFIGURE_ARGS --enable-full-tools --enable-profiler --disable-docs
29ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
28ENV RUST_CONFIGURE_ARGS="--enable-full-tools --enable-profiler --disable-docs"
29ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS"
src/ci/docker/host-x86_64/dist-armv7-linux/Dockerfile+2-2
......@@ -25,5 +25,5 @@ ENV CC_armv7_unknown_linux_gnueabihf=armv7-unknown-linux-gnueabihf-gcc \
2525
2626ENV HOSTS=armv7-unknown-linux-gnueabihf
2727
28ENV RUST_CONFIGURE_ARGS --enable-full-tools --enable-profiler --disable-docs
29ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
28ENV RUST_CONFIGURE_ARGS="--enable-full-tools --enable-profiler --disable-docs"
29ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS"
src/ci/docker/host-x86_64/dist-ohos-armv7/Dockerfile+3-4
......@@ -40,14 +40,13 @@ ENV \
4040 AR_armv7_unknown_linux_ohos=/opt/ohos-sdk/native/llvm/bin/llvm-ar \
4141 CXX_armv7_unknown_linux_ohos=/usr/local/bin/armv7-unknown-linux-ohos-clang++.sh
4242
43ENV RUST_CONFIGURE_ARGS \
44 --enable-profiler \
43ENV RUST_CONFIGURE_ARGS="--enable-profiler \
4544 --disable-docs \
4645 --tools=cargo,clippy,rustdocs,rustfmt,rust-analyzer,rust-analyzer-proc-macro-srv,analysis,src,wasm-component-ld \
4746 --enable-extended \
48 --enable-sanitizers
47 --enable-sanitizers"
4948
50ENV SCRIPT python3 ../x.py dist --host=$TARGETS --target $TARGETS
49ENV SCRIPT="python3 ../x.py dist --host=$TARGETS --target $TARGETS"
5150
5251COPY scripts/sccache.sh /scripts/
5352RUN sh /scripts/sccache.sh
src/tools/tidy/src/issues.txt-8
......@@ -1726,14 +1726,6 @@ ui/moves/issue-46099-move-in-macro.rs
17261726ui/moves/issue-72649-uninit-in-loop.rs
17271727ui/moves/issue-75904-move-closure-loop.rs
17281728ui/moves/issue-99470-move-out-of-some.rs
1729ui/never_type/issue-10176.rs
1730ui/never_type/issue-13352.rs
1731ui/never_type/issue-2149.rs
1732ui/never_type/issue-44402.rs
1733ui/never_type/issue-51506.rs
1734ui/never_type/issue-52443.rs
1735ui/never_type/issue-5500-1.rs
1736ui/never_type/issue-96335.rs
17371729ui/nll/closure-requirements/issue-58127-mutliple-requirements.rs
17381730ui/nll/issue-112604-closure-output-normalize.rs
17391731ui/nll/issue-16223.rs
tests/run-make/linker-warning/fake-linker.sh deleted-17
......@@ -1,17 +0,0 @@
1#!/bin/sh
2
3code=0
4while ! [ $# = 0 ]; do
5 case "$1" in
6 run_make_info) echo "foo"
7 ;;
8 run_make_warn) echo "warning: bar" >&2
9 ;;
10 run_make_error) echo "error: baz" >&2; code=1
11 ;;
12 *) ;; # rustc passes lots of args we don't care about
13 esac
14 shift
15done
16
17exit $code
tests/run-make/macos-deployment-target-warning/foo.c created+1
......@@ -0,0 +1 @@
1void foo() {}
tests/run-make/macos-deployment-target-warning/main.rs created+8
......@@ -0,0 +1,8 @@
1#![warn(linker_info, linker_messages)]
2unsafe extern "C" {
3 safe fn foo();
4}
5
6fn main() {
7 foo();
8}
tests/run-make/macos-deployment-target-warning/rmake.rs created+29
......@@ -0,0 +1,29 @@
1//@ only-apple
2//! Tests that deployment target linker warnings are shown as `linker-info`, not `linker-messages`
3
4use run_make_support::external_deps::c_cxx_compiler::cc;
5use run_make_support::external_deps::llvm::llvm_ar;
6use run_make_support::{bare_rustc, diff};
7
8fn main() {
9 let cwd = std::env::current_dir().unwrap().to_str().unwrap().to_owned();
10
11 cc().arg("-c").arg("-mmacosx-version-min=15.5").output("foo.o").input("foo.c").run();
12 llvm_ar().obj_to_ar().output_input("libfoo.a", "foo.o").run();
13
14 let warnings = bare_rustc()
15 .arg("-L")
16 .arg(format!("native={cwd}"))
17 .arg("-lstatic=foo")
18 .link_arg("-mmacosx-version-min=11.2")
19 .input("main.rs")
20 .crate_type("bin")
21 .run()
22 .stderr_utf8();
23
24 diff()
25 .expected_file("warnings.txt")
26 .actual_text("(rustc -W linker-info)", &warnings)
27 .normalize(r"\(.*/rmake_out/", "(TEST_DIR/")
28 .run()
29}
tests/run-make/macos-deployment-target-warning/warnings.txt created+11
......@@ -0,0 +1,11 @@
1warning: ld: warning: object file (TEST_DIR/libfoo.a[2](foo.o)) was built for newer 'macOS' version (15.5) than being linked (11.2)
2
3 |
4note: the lint level is defined here
5 --> main.rs:1:9
6 |
71 | #![warn(linker_info, linker_messages)]
8 | ^^^^^^^^^^^
9
10warning: 1 warning emitted
11
tests/run-make/windows-gnu-corrupt-drective/fake-linker.rs created+8
......@@ -0,0 +1,8 @@
1// ignore-tidy-linelength
2
3fn main() {
4 println!(
5 "Warning: .drectve `-exclude-symbols:_ZN28windows_gnu_corrupt_drective4main17h291ed884c1aada69E ' unrecognized"
6 );
7 println!("Warning: corrupt .drectve at end of def file");
8}
tests/run-make/windows-gnu-corrupt-drective/main.rs created+6
......@@ -0,0 +1,6 @@
1//@ only-windows-gnu
2//@ build-fail
3//@ compile-flags: -C linker={{src-base}}/linking/auxiliary/fake-linker.ps1
4#![deny(linker_info)]
5//~? ERROR Warning: .drectve
6fn main() {}
tests/run-make/windows-gnu-corrupt-drective/rmake.rs created+14
......@@ -0,0 +1,14 @@
1//@ only-windows-gnu
2
3use run_make_support::{bare_rustc, rustc};
4
5fn main() {
6 // bare_rustc so that this doesn't try to cross-compile our linker
7 bare_rustc().input("fake-linker.rs").output("fake-linker").run();
8 rustc()
9 .input("main.rs")
10 .linker("./fake-linker")
11 .arg("-Wlinker-messages")
12 .run()
13 .assert_stderr_contains("Warning: .drectve");
14}
tests/ui-fulldeps/session-diagnostic/diagnostic-derive-doc-comment-field.stderr-6
......@@ -35,12 +35,6 @@ help: the nightly-only, unstable trait `IntoDiagArg` is not implemented for `Not
3535LL | struct NotIntoDiagArg;
3636 | ^^^^^^^^^^^^^^^^^^^^^
3737 = help: normalized in stderr
38note: required by a bound in `Diag::<'a, G>::arg`
39 --> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC
40 ::: $COMPILER_DIR/rustc_errors/src/diagnostic.rs:LL:CC
41 |
42 = note: in this macro invocation
43 = note: this error originates in the macro `with_fn` (in Nightly builds, run with -Z macro-backtrace for more info)
4438
4539error: aborting due to 2 previous errors
4640
tests/ui/linking/macos-ignoring-duplicate.rs created+6
......@@ -0,0 +1,6 @@
1//@ only-apple
2//@ compile-flags: -C link-arg=-lc -C link-arg=-lc
3//@ build-fail
4#![deny(linker_info)]
5//~? ERROR ignoring duplicate libraries
6fn main() {}
tests/ui/linking/macos-ignoring-duplicate.stderr created+11
......@@ -0,0 +1,11 @@
1error: ld: warning: ignoring duplicate libraries: '-lc'
2
3 |
4note: the lint level is defined here
5 --> $DIR/macos-ignoring-duplicate.rs:4:9
6 |
7LL | #![deny(linker_info)]
8 | ^^^^^^^^^^^
9
10error: aborting due to 1 previous error
11
tests/ui/linking/macos-search-path.rs created+6
......@@ -0,0 +1,6 @@
1//@ only-apple
2//@ compile-flags: -C link-arg=-Wl,-L/no/such/file/or/directory
3//@ build-fail
4#![deny(linker_info)]
5//~? ERROR search path
6fn main() {}
tests/ui/linking/macos-search-path.stderr created+11
......@@ -0,0 +1,11 @@
1error: ld: warning: search path '/no/such/file/or/directory' not found
2
3 |
4note: the lint level is defined here
5 --> $DIR/macos-search-path.rs:4:9
6 |
7LL | #![deny(linker_info)]
8 | ^^^^^^^^^^^
9
10error: aborting due to 1 previous error
11
tests/ui/lint/linker-warning.stderr+1-1
......@@ -20,7 +20,7 @@ warning: unused attribute
2020LL | #![allow(linker_messages)]
2121 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute
2222 |
23 = note: the `linker_messages` lint can only be controlled at the root of a crate that needs to be linked
23 = note: the `linker_messages` and `linker_info` lints can only be controlled at the root of a crate that needs to be linked
2424
2525warning: 2 warnings emitted
2626
tests/ui/never_type/adjust_never.rs deleted-10
......@@ -1,10 +0,0 @@
1// Test that a variable of type ! can coerce to another type.
2
3//@ check-pass
4
5#![feature(never_type)]
6
7fn main() {
8 let x: ! = panic!();
9 let y: u32 = x;
10}
tests/ui/never_type/auto-traits.rs deleted-17
......@@ -1,17 +0,0 @@
1//@ check-pass
2
3#![feature(auto_traits)]
4#![feature(never_type)]
5
6fn main() {
7 enum Void {}
8
9 auto trait Auto {}
10 fn assert_auto<T: Auto>() {}
11 assert_auto::<Void>();
12 assert_auto::<!>();
13
14 fn assert_send<T: Send>() {}
15 assert_send::<Void>();
16 assert_send::<!>();
17}
tests/ui/never_type/basic/adjust_never.rs created+10
......@@ -0,0 +1,10 @@
1// Test that a variable of type ! can coerce to another type.
2
3//@ check-pass
4
5#![feature(never_type)]
6
7fn main() {
8 let x: ! = panic!();
9 let y: u32 = x;
10}
tests/ui/never_type/basic/auto-traits.rs created+17
......@@ -0,0 +1,17 @@
1//@ check-pass
2
3#![feature(auto_traits)]
4#![feature(never_type)]
5
6fn main() {
7 enum Void {}
8
9 auto trait Auto {}
10 fn assert_auto<T: Auto>() {}
11 assert_auto::<Void>();
12 assert_auto::<!>();
13
14 fn assert_send<T: Send>() {}
15 assert_send::<Void>();
16 assert_send::<!>();
17}
tests/ui/never_type/basic/call-fn-never-arg-wrong-type.rs created+11
......@@ -0,0 +1,11 @@
1// Test that we can't pass other types for !
2
3#![feature(never_type)]
4
5fn foo(x: !) -> ! {
6 x
7}
8
9fn main() {
10 foo("wow"); //~ ERROR mismatched types
11}
tests/ui/never_type/basic/call-fn-never-arg-wrong-type.stderr created+19
......@@ -0,0 +1,19 @@
1error[E0308]: mismatched types
2 --> $DIR/call-fn-never-arg-wrong-type.rs:10:9
3 |
4LL | foo("wow");
5 | --- ^^^^^ expected `!`, found `&str`
6 | |
7 | arguments to this function are incorrect
8 |
9 = note: expected type `!`
10 found reference `&'static str`
11note: function defined here
12 --> $DIR/call-fn-never-arg-wrong-type.rs:5:4
13 |
14LL | fn foo(x: !) -> ! {
15 | ^^^ ----
16
17error: aborting due to 1 previous error
18
19For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/basic/call-fn-never-arg.rs created+14
......@@ -0,0 +1,14 @@
1// Test that we can use a ! for an argument of type !
2//
3//@ check-pass
4
5#![feature(never_type)]
6#![expect(unreachable_code)]
7
8fn foo(x: !) -> ! {
9 x
10}
11
12fn main() {
13 foo(panic!("wowzers!"))
14}
tests/ui/never_type/basic/cast-never.rs created+10
......@@ -0,0 +1,10 @@
1// Test that we can explicitly cast ! to another type
2//
3//@ check-pass
4
5#![feature(never_type)]
6
7fn main() {
8 let x: ! = panic!();
9 let y: u32 = x as u32;
10}
tests/ui/never_type/basic/impl-for-never.rs created+29
......@@ -0,0 +1,29 @@
1// Test that we can call static methods on ! both directly and when it appears in a generic
2//
3//@ run-pass
4//@ check-run-results
5
6#![feature(never_type)]
7
8
9trait StringifyType {
10 fn stringify_type() -> &'static str;
11}
12
13impl StringifyType for ! {
14 fn stringify_type() -> &'static str {
15 "!"
16 }
17}
18
19fn maybe_stringify<T: StringifyType>(opt: Option<T>) -> &'static str {
20 match opt {
21 Some(_) => T::stringify_type(),
22 None => "none",
23 }
24}
25
26fn main() {
27 println!("! is {}", <!>::stringify_type());
28 println!("None is {}", maybe_stringify(None::<!>));
29}
tests/ui/never_type/basic/impl-for-never.run.stdout created+2
......@@ -0,0 +1,2 @@
1! is !
2None is none
tests/ui/never_type/basic/never-assign-wrong-type.rs created+7
......@@ -0,0 +1,7 @@
1// Test that we can't use another type in place of !
2
3#![feature(never_type)]
4
5fn main() {
6 let x: ! = "hello"; //~ ERROR mismatched types
7}
tests/ui/never_type/basic/never-assign-wrong-type.stderr created+14
......@@ -0,0 +1,14 @@
1error[E0308]: mismatched types
2 --> $DIR/never-assign-wrong-type.rs:6:16
3 |
4LL | let x: ! = "hello";
5 | - ^^^^^^^ expected `!`, found `&str`
6 | |
7 | expected due to this
8 |
9 = note: expected type `!`
10 found reference `&'static str`
11
12error: aborting due to 1 previous error
13
14For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/basic/never-associated-type.rs created+23
......@@ -0,0 +1,23 @@
1// Test that we can use ! as an associated type.
2//
3//@ check-pass
4
5#![feature(never_type)]
6
7trait Foo {
8 type Wow;
9
10 fn smeg(&self) -> Self::Wow;
11}
12
13struct Blah;
14impl Foo for Blah {
15 type Wow = !;
16 fn smeg(&self) -> ! {
17 panic!("kapow!");
18 }
19}
20
21fn main() {
22 Blah.smeg();
23}
tests/ui/never_type/basic/never-result.rs created+21
......@@ -0,0 +1,21 @@
1// Test that `!` can be coerced to multiple different types after getting it
2// from pattern matching.
3//
4//@ run-pass
5
6#![feature(never_type)]
7#![expect(unused_variables)]
8#![expect(unreachable_code)]
9
10fn main() {
11 let x: Result<u32, !> = Ok(123);
12 match x {
13 Ok(z) => (),
14 Err(y) => {
15 let q: u32 = y;
16 let w: i32 = y;
17 let e: String = y;
18 y
19 }
20 }
21}
tests/ui/never_type/basic/never-type-arg.rs created+17
......@@ -0,0 +1,17 @@
1// Test that we can use ! as an argument to a trait impl.
2//
3//@ check-pass
4
5#![feature(never_type)]
6
7struct Wub;
8
9impl PartialEq<!> for Wub {
10 fn eq(&self, other: &!) -> bool {
11 *other
12 }
13}
14
15fn main() {
16 let _ = Wub == panic!("oh no!");
17}
tests/ui/never_type/basic/never-type-in-nested-fn-decl.rs created+7
......@@ -0,0 +1,7 @@
1//@ build-pass
2
3trait X<const N: i32> {}
4
5fn hello<T: X<{ fn hello() -> ! { loop {} } 1 }>>() {}
6
7fn main() {}
tests/ui/never_type/basic/never-type-rvalues.rs created+40
......@@ -0,0 +1,40 @@
1// Check that the never type can be used in various positions.
2//
3//@ run-pass
4
5#![feature(never_type)]
6#![allow(dead_code)]
7#![allow(path_statements)]
8#![allow(unreachable_patterns)]
9
10fn never_direct(x: !) {
11 x;
12}
13
14fn never_ref_pat(ref x: !) {
15 *x;
16}
17
18fn never_ref(x: &!) {
19 let &y = x;
20 y;
21}
22
23fn never_pointer(x: *const !) {
24 unsafe {
25 *x;
26 }
27}
28
29fn never_slice(x: &[!]) {
30 x[0];
31}
32
33fn never_match(x: Result<(), !>) {
34 match x {
35 Ok(_) => {},
36 Err(_) => {},
37 }
38}
39
40pub fn main() { }
tests/ui/never_type/basic/never_coercions.rs created+12
......@@ -0,0 +1,12 @@
1//@ run-pass
2// Test that having something of type ! doesn't screw up type-checking and that it coerces to the
3// LUB type of the other match arms.
4
5fn main() {
6 let v: Vec<u32> = Vec::new();
7 match 0u32 {
8 0 => &v,
9 1 => return,
10 _ => &v[..],
11 };
12}
tests/ui/never_type/basic/never_transmute_never.rs created+23
......@@ -0,0 +1,23 @@
1//@ check-pass
2
3#![feature(never_type)]
4#![allow(dead_code)]
5#![expect(unreachable_code)]
6#![expect(unused_variables)]
7
8struct Foo;
9
10pub fn f(x: !) -> ! {
11 x
12}
13
14pub fn ub() {
15 // This is completely undefined behaviour,
16 // but we still want to make sure it compiles.
17 let x: ! = unsafe {
18 std::mem::transmute::<Foo, !>(Foo)
19 };
20 f(x)
21}
22
23fn main() {}
tests/ui/never_type/basic/return-never-coerce.rs created+18
......@@ -0,0 +1,18 @@
1// Test that ! coerces to other types.
2
3//@ run-fail
4//@ error-pattern:aah!
5//@ needs-subprocess
6
7fn call_another_fn<T, F: FnOnce() -> T>(f: F) -> T {
8 f()
9}
10
11fn wub() -> ! {
12 panic!("aah!");
13}
14
15fn main() {
16 let x: i32 = call_another_fn(wub);
17 let y: u32 = wub();
18}
tests/ui/never_type/call-fn-never-arg-wrong-type.rs deleted-11
......@@ -1,11 +0,0 @@
1// Test that we can't pass other types for !
2
3#![feature(never_type)]
4
5fn foo(x: !) -> ! {
6 x
7}
8
9fn main() {
10 foo("wow"); //~ ERROR mismatched types
11}
tests/ui/never_type/call-fn-never-arg-wrong-type.stderr deleted-19
......@@ -1,19 +0,0 @@
1error[E0308]: mismatched types
2 --> $DIR/call-fn-never-arg-wrong-type.rs:10:9
3 |
4LL | foo("wow");
5 | --- ^^^^^ expected `!`, found `&str`
6 | |
7 | arguments to this function are incorrect
8 |
9 = note: expected type `!`
10 found reference `&'static str`
11note: function defined here
12 --> $DIR/call-fn-never-arg-wrong-type.rs:5:4
13 |
14LL | fn foo(x: !) -> ! {
15 | ^^^ ----
16
17error: aborting due to 1 previous error
18
19For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/call-fn-never-arg.rs deleted-14
......@@ -1,14 +0,0 @@
1// Test that we can use a ! for an argument of type !
2//
3//@ check-pass
4
5#![feature(never_type)]
6#![expect(unreachable_code)]
7
8fn foo(x: !) -> ! {
9 x
10}
11
12fn main() {
13 foo(panic!("wowzers!"))
14}
tests/ui/never_type/cast-never.rs deleted-10
......@@ -1,10 +0,0 @@
1// Test that we can explicitly cast ! to another type
2//
3//@ check-pass
4
5#![feature(never_type)]
6
7fn main() {
8 let x: ! = panic!();
9 let y: u32 = x as u32;
10}
tests/ui/never_type/defaulted-never-note.e2021.stderr deleted-18
......@@ -1,18 +0,0 @@
1Future incompatibility report: Future breakage diagnostic:
2warning: this function depends on never type fallback being `()`
3 --> $DIR/defaulted-never-note.rs:38:1
4 |
5LL | fn main() {
6 | ^^^^^^^^^
7 |
8 = help: specify the types explicitly
9note: in edition 2024, the requirement `!: OnlyUnit` will fail
10 --> $DIR/defaulted-never-note.rs:40:19
11 |
12LL | requires_unit(x);
13 | ^
14help: use `()` annotations to avoid fallback changes
15 |
16LL | let x: () = return;
17 | ++++
18
tests/ui/never_type/defaulted-never-note.e2024.stderr deleted-62
......@@ -1,62 +0,0 @@
1error[E0277]: the trait bound `!: OnlyUnit` is not satisfied
2 --> $DIR/defaulted-never-note.rs:40:19
3 |
4LL | requires_unit(x);
5 | ------------- ^ the trait `OnlyUnit` is not implemented for `!`
6 | |
7 | required by a bound introduced by this call
8 |
9help: the trait `OnlyUnit` is implemented for `()`
10 --> $DIR/defaulted-never-note.rs:13:1
11 |
12LL | impl OnlyUnit for () {}
13 | ^^^^^^^^^^^^^^^^^^^^
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `requires_unit`
17 --> $DIR/defaulted-never-note.rs:16:26
18 |
19LL | fn requires_unit(_: impl OnlyUnit) {}
20 | ^^^^^^^^ required by this bound in `requires_unit`
21
22error[E0277]: the trait bound `!: OnlyU32` is not satisfied
23 --> $DIR/defaulted-never-note.rs:48:18
24 |
25LL | requires_u32(x);
26 | ------------ ^ the trait `OnlyU32` is not implemented for `!`
27 | |
28 | required by a bound introduced by this call
29 |
30help: the trait `OnlyU32` is implemented for `u32`
31 --> $DIR/defaulted-never-note.rs:23:1
32 |
33LL | impl OnlyU32 for u32 {}
34 | ^^^^^^^^^^^^^^^^^^^^
35note: required by a bound in `requires_u32`
36 --> $DIR/defaulted-never-note.rs:26:25
37 |
38LL | fn requires_u32(_: impl OnlyU32) {}
39 | ^^^^^^^ required by this bound in `requires_u32`
40
41error[E0277]: the trait bound `!: Nothing` is not satisfied
42 --> $DIR/defaulted-never-note.rs:54:22
43 |
44LL | requires_nothing(x);
45 | ---------------- ^ the trait `Nothing` is not implemented for `!`
46 | |
47 | required by a bound introduced by this call
48 |
49help: this trait has no implementations, consider adding one
50 --> $DIR/defaulted-never-note.rs:31:1
51 |
52LL | trait Nothing {}
53 | ^^^^^^^^^^^^^
54note: required by a bound in `requires_nothing`
55 --> $DIR/defaulted-never-note.rs:34:29
56 |
57LL | fn requires_nothing(_: impl Nothing) {}
58 | ^^^^^^^ required by this bound in `requires_nothing`
59
60error: aborting due to 3 previous errors
61
62For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/defaulted-never-note.rs deleted-58
......@@ -1,58 +0,0 @@
1// Test diagnostic for the case where a trait is not implemented for `!`. If it is implemented
2// for `()`, we want to add a note saying that this might be caused by a breaking change in the
3// compiler.
4//
5//@ revisions: e2021 e2024
6//@[e2021] edition: 2021
7//@[e2024] edition: 2024
8//@[e2021] run-pass
9#![expect(dependency_on_unit_never_type_fallback, unused)]
10
11trait OnlyUnit {}
12
13impl OnlyUnit for () {}
14//[e2024]~^ help: trait `OnlyUnit` is implemented for `()`
15
16fn requires_unit(_: impl OnlyUnit) {}
17//[e2024]~^ note: required by this bound in `requires_unit`
18//[e2024]~| note: required by a bound in `requires_unit`
19
20
21trait OnlyU32 {}
22
23impl OnlyU32 for u32 {}
24//[e2024]~^ help: the trait `OnlyU32` is implemented for `u32`
25
26fn requires_u32(_: impl OnlyU32) {}
27//[e2024]~^ note: required by this bound in `requires_u32`
28//[e2024]~| note: required by a bound in `requires_u32`
29
30
31trait Nothing {}
32//[e2024]~^ help: this trait has no implementations, consider adding one
33
34fn requires_nothing(_: impl Nothing) {}
35//[e2024]~^ note: required by this bound in `requires_nothing`
36//[e2024]~| note: required by a bound in `requires_nothing`
37
38fn main() {
39 let x = return;
40 requires_unit(x);
41 //[e2024]~^ error: the trait bound `!: OnlyUnit` is not satisfied
42 //[e2024]~| note: the trait `OnlyUnit` is not implemented for `!`
43 //[e2024]~| note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
44 //[e2024]~| note: required by a bound introduced by this call
45 //[e2024]~| help: you might have intended to use the type `()`
46
47 #[cfg(e2024)]
48 requires_u32(x);
49 //[e2024]~^ error: the trait bound `!: OnlyU32` is not satisfied
50 //[e2024]~| note: the trait `OnlyU32` is not implemented for `!`
51 //[e2024]~| note: required by a bound introduced by this call
52
53 #[cfg(e2024)]
54 requires_nothing(x);
55 //[e2024]~^ error: the trait bound `!: Nothing` is not satisfied
56 //[e2024]~| note: the trait `Nothing` is not implemented for `!`
57 //[e2024]~| note: required by a bound introduced by this call
58}
tests/ui/never_type/dependency-on-fallback-to-unit.rs deleted-26
......@@ -1,26 +0,0 @@
1fn main() {
2 def();
3 _ = question_mark();
4}
5
6fn def() {
7 //~^ error: this function depends on never type fallback being `()`
8 //~| 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!
9 match true {
10 false => <_>::default(),
11 true => return,
12 };
13}
14
15// <https://github.com/rust-lang/rust/issues/51125>
16// <https://github.com/rust-lang/rust/issues/39216>
17fn question_mark() -> Result<(), ()> {
18 //~^ error: this function depends on never type fallback being `()`
19 //~| 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!
20 deserialize()?;
21 Ok(())
22}
23
24fn deserialize<T: Default>() -> Result<T, ()> {
25 Ok(T::default())
26}
tests/ui/never_type/dependency-on-fallback-to-unit.stderr deleted-85
......@@ -1,85 +0,0 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/dependency-on-fallback-to-unit.rs:6:1
3 |
4LL | fn def() {
5 | ^^^^^^^^
6 |
7 = help: specify the types explicitly
8note: in edition 2024, the requirement `!: Default` will fail
9 --> $DIR/dependency-on-fallback-to-unit.rs:10:19
10 |
11LL | false => <_>::default(),
12 | ^
13 = 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!
14 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL - false => <_>::default(),
19LL + false => <()>::default(),
20 |
21
22error: this function depends on never type fallback being `()`
23 --> $DIR/dependency-on-fallback-to-unit.rs:17:1
24 |
25LL | fn question_mark() -> Result<(), ()> {
26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27 |
28 = help: specify the types explicitly
29note: in edition 2024, the requirement `!: Default` will fail
30 --> $DIR/dependency-on-fallback-to-unit.rs:20:5
31 |
32LL | deserialize()?;
33 | ^^^^^^^^^^^^^
34 = 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!
35 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
36help: use `()` annotations to avoid fallback changes
37 |
38LL | deserialize::<()>()?;
39 | ++++++
40
41error: aborting due to 2 previous errors
42
43Future incompatibility report: Future breakage diagnostic:
44error: this function depends on never type fallback being `()`
45 --> $DIR/dependency-on-fallback-to-unit.rs:6:1
46 |
47LL | fn def() {
48 | ^^^^^^^^
49 |
50 = help: specify the types explicitly
51note: in edition 2024, the requirement `!: Default` will fail
52 --> $DIR/dependency-on-fallback-to-unit.rs:10:19
53 |
54LL | false => <_>::default(),
55 | ^
56 = 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!
57 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
58 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
59help: use `()` annotations to avoid fallback changes
60 |
61LL - false => <_>::default(),
62LL + false => <()>::default(),
63 |
64
65Future breakage diagnostic:
66error: this function depends on never type fallback being `()`
67 --> $DIR/dependency-on-fallback-to-unit.rs:17:1
68 |
69LL | fn question_mark() -> Result<(), ()> {
70 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71 |
72 = help: specify the types explicitly
73note: in edition 2024, the requirement `!: Default` will fail
74 --> $DIR/dependency-on-fallback-to-unit.rs:20:5
75 |
76LL | deserialize()?;
77 | ^^^^^^^^^^^^^
78 = 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!
79 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
80 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
81help: use `()` annotations to avoid fallback changes
82 |
83LL | deserialize::<()>()?;
84 | ++++++
85
tests/ui/never_type/diverging-fallback-unconstrained-return.e2021.stderr deleted-43
......@@ -1,43 +0,0 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/diverging-fallback-unconstrained-return.rs:26:1
3 |
4LL | fn main() {
5 | ^^^^^^^^^
6 |
7 = help: specify the types explicitly
8note: in edition 2024, the requirement `!: UnitReturn` will fail
9 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
10 |
11LL | let _ = if true { unconstrained_return() } else { panic!() };
12 | ^^^^^^^^^^^^^^^^^^^^^^
13 = 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!
14 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL | let _: () = if true { unconstrained_return() } else { panic!() };
19 | ++++
20
21error: aborting due to 1 previous error
22
23Future incompatibility report: Future breakage diagnostic:
24error: this function depends on never type fallback being `()`
25 --> $DIR/diverging-fallback-unconstrained-return.rs:26:1
26 |
27LL | fn main() {
28 | ^^^^^^^^^
29 |
30 = help: specify the types explicitly
31note: in edition 2024, the requirement `!: UnitReturn` will fail
32 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
33 |
34LL | let _ = if true { unconstrained_return() } else { panic!() };
35 | ^^^^^^^^^^^^^^^^^^^^^^
36 = 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!
37 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
38 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
39help: use `()` annotations to avoid fallback changes
40 |
41LL | let _: () = if true { unconstrained_return() } else { panic!() };
42 | ++++
43
tests/ui/never_type/diverging-fallback-unconstrained-return.e2024.stderr deleted-24
......@@ -1,24 +0,0 @@
1error[E0277]: the trait bound `!: UnitReturn` is not satisfied
2 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
3 |
4LL | let _ = if true { unconstrained_return() } else { panic!() };
5 | ^^^^^^^^^^^^^^^^^^^^^^ the trait `UnitReturn` is not implemented for `!`
6 |
7help: the following other types implement trait `UnitReturn`
8 --> $DIR/diverging-fallback-unconstrained-return.rs:15:1
9 |
10LL | impl UnitReturn for i32 {}
11 | ^^^^^^^^^^^^^^^^^^^^^^^ `i32`
12LL | impl UnitReturn for () {}
13 | ^^^^^^^^^^^^^^^^^^^^^^ `()`
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `unconstrained_return`
17 --> $DIR/diverging-fallback-unconstrained-return.rs:18:28
18 |
19LL | fn unconstrained_return<T: UnitReturn>() -> T {
20 | ^^^^^^^^^^ required by this bound in `unconstrained_return`
21
22error: aborting due to 1 previous error
23
24For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/diverging-fallback-unconstrained-return.fallback.stderr deleted-24
......@@ -1,24 +0,0 @@
1error[E0277]: the trait bound `!: UnitReturn` is not satisfied
2 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
3 |
4LL | let _ = if true { unconstrained_return() } else { panic!() };
5 | ^^^^^^^^^^^^^^^^^^^^^^ the trait `UnitReturn` is not implemented for `!`
6 |
7help: the following other types implement trait `UnitReturn`
8 --> $DIR/diverging-fallback-unconstrained-return.rs:15:1
9 |
10LL | impl UnitReturn for i32 {}
11 | ^^^^^^^^^^^^^^^^^^^^^^^ `i32`
12LL | impl UnitReturn for () {}
13 | ^^^^^^^^^^^^^^^^^^^^^^ `()`
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `unconstrained_return`
17 --> $DIR/diverging-fallback-unconstrained-return.rs:18:28
18 |
19LL | fn unconstrained_return<T: UnitReturn>() -> T {
20 | ^^^^^^^^^^ required by this bound in `unconstrained_return`
21
22error: aborting due to 1 previous error
23
24For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/diverging-fallback-unconstrained-return.nofallback.stderr deleted-43
......@@ -1,43 +0,0 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/diverging-fallback-unconstrained-return.rs:26:1
3 |
4LL | fn main() {
5 | ^^^^^^^^^
6 |
7 = 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!
8 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
9 = help: specify the types explicitly
10note: in edition 2024, the requirement `!: UnitReturn` will fail
11 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
12 |
13LL | let _ = if true { unconstrained_return() } else { panic!() };
14 | ^^^^^^^^^^^^^^^^^^^^^^
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL | let _: () = if true { unconstrained_return() } else { panic!() };
19 | ++++
20
21error: aborting due to 1 previous error
22
23Future incompatibility report: Future breakage diagnostic:
24error: this function depends on never type fallback being `()`
25 --> $DIR/diverging-fallback-unconstrained-return.rs:26:1
26 |
27LL | fn main() {
28 | ^^^^^^^^^
29 |
30 = 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!
31 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
32 = help: specify the types explicitly
33note: in edition 2024, the requirement `!: UnitReturn` will fail
34 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
35 |
36LL | let _ = if true { unconstrained_return() } else { panic!() };
37 | ^^^^^^^^^^^^^^^^^^^^^^
38 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
39help: use `()` annotations to avoid fallback changes
40 |
41LL | let _: () = if true { unconstrained_return() } else { panic!() };
42 | ++++
43
tests/ui/never_type/diverging-fallback-unconstrained-return.rs deleted-38
......@@ -1,38 +0,0 @@
1// Variant of diverging-fallback-control-flow that tests
2// the specific case of a free function with an unconstrained
3// return type. This captures the pattern we saw in the wild
4// in the objc crate, where changing the fallback from `!` to `()`
5// resulted in unsoundness.
6//
7//@ revisions: e2021 e2024
8//@[e2024] edition: 2024
9
10#![expect(unit_bindings)]
11
12fn make_unit() {}
13
14trait UnitReturn {}
15impl UnitReturn for i32 {}
16impl UnitReturn for () {}
17
18fn unconstrained_return<T: UnitReturn>() -> T {
19 unsafe {
20 let make_unit_fn: fn() = make_unit;
21 let ffi: fn() -> T = std::mem::transmute(make_unit_fn);
22 ffi()
23 }
24}
25
26fn main() {
27 //[e2021]~^ error: this function depends on never type fallback being `()`
28 //[e2021]~| 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!
29
30 // In Ye Olde Days, the `T` parameter of `unconstrained_return`
31 // winds up "entangled" with the `!` type that results from
32 // `panic!`, and hence falls back to `()`. This is kind of unfortunate
33 // and unexpected. When we introduced the `!` type, the original
34 // idea was to change that fallback to `!`, but that would have resulted
35 // in this code no longer compiling (or worse, in some cases it injected
36 // unsound results).
37 let _ = if true { unconstrained_return() } else { panic!() }; //[e2024]~ error: the trait bound `!: UnitReturn` is not satisfied
38}
tests/ui/never_type/diverging-tuple-parts-39485.rs deleted-16
......@@ -1,16 +0,0 @@
1//@ edition:2015..2021
2// After #39485, this test used to pass, but that change was reverted
3// due to numerous inference failures like #39808, so it now fails
4// again. #39485 made it so that diverging types never propagate
5// upward; but we now do propagate such types upward in many more
6// cases.
7
8fn g() {
9 &panic!() //~ ERROR mismatched types
10}
11
12fn f() -> isize {
13 (return 1, return 2) //~ ERROR mismatched types
14}
15
16fn main() {}
tests/ui/never_type/diverging-tuple-parts-39485.stderr deleted-32
......@@ -1,32 +0,0 @@
1error[E0308]: mismatched types
2 --> $DIR/diverging-tuple-parts-39485.rs:9:5
3 |
4LL | &panic!()
5 | ^^^^^^^^^ expected `()`, found `&_`
6 |
7 = note: expected unit type `()`
8 found reference `&_`
9help: a return type might be missing here
10 |
11LL | fn g() -> _ {
12 | ++++
13help: consider removing the borrow
14 |
15LL - &panic!()
16LL + panic!()
17 |
18
19error[E0308]: mismatched types
20 --> $DIR/diverging-tuple-parts-39485.rs:13:5
21 |
22LL | fn f() -> isize {
23 | ----- expected `isize` because of return type
24LL | (return 1, return 2)
25 | ^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `(!, !)`
26 |
27 = note: expected type `isize`
28 found tuple `(!, !)`
29
30error: aborting due to 2 previous errors
31
32For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/dont-suggest-turbofish-from-expansion.rs deleted-18
......@@ -1,18 +0,0 @@
1fn create_ok_default<C>() -> Result<C, ()>
2where
3 C: Default,
4{
5 Ok(C::default())
6}
7
8fn main() -> Result<(), ()> {
9 //~^ ERROR this function depends on never type fallback being `()`
10 //~| WARN this was previously accepted by the compiler but is being phased out
11 let (returned_value, _) = (|| {
12 let created = create_ok_default()?;
13 Ok((created, ()))
14 })()?;
15
16 let _ = format_args!("{:?}", returned_value);
17 Ok(())
18}
tests/ui/never_type/dont-suggest-turbofish-from-expansion.stderr deleted-43
......@@ -1,43 +0,0 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/dont-suggest-turbofish-from-expansion.rs:8:1
3 |
4LL | fn main() -> Result<(), ()> {
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
7 = help: specify the types explicitly
8note: in edition 2024, the requirement `!: Default` will fail
9 --> $DIR/dont-suggest-turbofish-from-expansion.rs:12:23
10 |
11LL | let created = create_ok_default()?;
12 | ^^^^^^^^^^^^^^^^^^^
13 = 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!
14 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL | let created: () = create_ok_default()?;
19 | ++++
20
21error: aborting due to 1 previous error
22
23Future incompatibility report: Future breakage diagnostic:
24error: this function depends on never type fallback being `()`
25 --> $DIR/dont-suggest-turbofish-from-expansion.rs:8:1
26 |
27LL | fn main() -> Result<(), ()> {
28 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
29 |
30 = help: specify the types explicitly
31note: in edition 2024, the requirement `!: Default` will fail
32 --> $DIR/dont-suggest-turbofish-from-expansion.rs:12:23
33 |
34LL | let created = create_ok_default()?;
35 | ^^^^^^^^^^^^^^^^^^^
36 = 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!
37 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
38 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
39help: use `()` annotations to avoid fallback changes
40 |
41LL | let created: () = create_ok_default()?;
42 | ++++
43
tests/ui/never_type/eq-never-types.rs deleted-12
......@@ -1,12 +0,0 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/120600>
2//
3//@ edition: 2024
4//@ check-pass
5
6#![feature(never_type)]
7
8fn ice(a: !) {
9 a == a;
10}
11
12fn main() {}
tests/ui/never_type/expr-empty-ret.rs deleted-14
......@@ -1,14 +0,0 @@
1//@ run-pass
2
3#![allow(dead_code)]
4// Issue #521
5
6
7fn f() {
8 let _x = match true {
9 true => { 10 }
10 false => { return }
11 };
12}
13
14pub fn main() { }
tests/ui/never_type/fallback-closure-ret.e2021.stderr deleted-18
......@@ -1,18 +0,0 @@
1Future incompatibility report: Future breakage diagnostic:
2warning: this function depends on never type fallback being `()`
3 --> $DIR/fallback-closure-ret.rs:21:1
4 |
5LL | fn main() {
6 | ^^^^^^^^^
7 |
8 = help: specify the types explicitly
9note: in edition 2024, the requirement `!: Bar` will fail
10 --> $DIR/fallback-closure-ret.rs:22:5
11 |
12LL | foo(|| panic!());
13 | ^^^^^^^^^^^^^^^^
14help: use `()` annotations to avoid fallback changes
15 |
16LL | foo::<()>(|| panic!());
17 | ++++++
18
tests/ui/never_type/fallback-closure-ret.e2024.stderr deleted-24
......@@ -1,24 +0,0 @@
1error[E0277]: the trait bound `!: Bar` is not satisfied
2 --> $DIR/fallback-closure-ret.rs:22:5
3 |
4LL | foo(|| panic!());
5 | ^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `!`
6 |
7help: the following other types implement trait `Bar`
8 --> $DIR/fallback-closure-ret.rs:15:1
9 |
10LL | impl Bar for () {}
11 | ^^^^^^^^^^^^^^^ `()`
12LL | impl Bar for u32 {}
13 | ^^^^^^^^^^^^^^^^ `u32`
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `foo`
17 --> $DIR/fallback-closure-ret.rs:18:11
18 |
19LL | fn foo<R: Bar>(_: impl Fn() -> R) {}
20 | ^^^ required by this bound in `foo`
21
22error: aborting due to 1 previous error
23
24For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback-closure-ret.fallback.stderr deleted-24
......@@ -1,24 +0,0 @@
1error[E0277]: the trait bound `!: Bar` is not satisfied
2 --> $DIR/fallback-closure-ret.rs:18:5
3 |
4LL | foo(|| panic!());
5 | ^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `!`
6 |
7help: the following other types implement trait `Bar`
8 --> $DIR/fallback-closure-ret.rs:12:1
9 |
10LL | impl Bar for () {}
11 | ^^^^^^^^^^^^^^^ `()`
12LL | impl Bar for u32 {}
13 | ^^^^^^^^^^^^^^^^ `u32`
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `foo`
17 --> $DIR/fallback-closure-ret.rs:15:11
18 |
19LL | fn foo<R: Bar>(_: impl Fn() -> R) {}
20 | ^^^ required by this bound in `foo`
21
22error: aborting due to 1 previous error
23
24For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback-closure-ret.nofallback.stderr deleted-18
......@@ -1,18 +0,0 @@
1Future incompatibility report: Future breakage diagnostic:
2warning: this function depends on never type fallback being `()`
3 --> $DIR/fallback-closure-ret.rs:17:1
4 |
5LL | fn main() {
6 | ^^^^^^^^^
7 |
8 = help: specify the types explicitly
9note: in edition 2024, the requirement `!: Bar` will fail
10 --> $DIR/fallback-closure-ret.rs:18:5
11 |
12LL | foo(|| panic!());
13 | ^^^^^^^^^^^^^^^^
14help: use `()` annotations to avoid fallback changes
15 |
16LL | foo::<()>(|| panic!());
17 | ++++++
18
tests/ui/never_type/fallback-closure-ret.rs deleted-23
......@@ -1,23 +0,0 @@
1// Tests the pattern of returning `!` from a closure and then checking if the
2// return type iumplements a trait (not implemented for `!`).
3//
4// This test used to test that this pattern is not broken by context dependant
5// never type fallback. However, it got removed, so now this is an example of
6// expected breakage from the never type fallback change.
7//
8//@ revisions: e2021 e2024
9//@[e2021] edition: 2021
10//@[e2024] edition: 2024
11//
12//@[e2021] check-pass
13
14trait Bar {}
15impl Bar for () {}
16impl Bar for u32 {}
17
18fn foo<R: Bar>(_: impl Fn() -> R) {}
19
20#[cfg_attr(e2021, expect(dependency_on_unit_never_type_fallback))]
21fn main() {
22 foo(|| panic!()); //[e2024]~ error: the trait bound `!: Bar` is not satisfied
23}
tests/ui/never_type/fallback-closure-wrap.e2024.stderr deleted-15
......@@ -1,15 +0,0 @@
1error[E0271]: expected `{closure@fallback-closure-wrap.rs:16:40}` to return `()`, but it returns `!`
2 --> $DIR/fallback-closure-wrap.rs:17:9
3 |
4LL | let error = Closure::wrap(Box::new(move || {
5 | ------- this closure
6LL | panic!("Can't connect to server.");
7 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `!`
8 |
9 = note: expected unit type `()`
10 found type `!`
11 = note: required for the cast from `Box<{closure@$DIR/fallback-closure-wrap.rs:16:40: 16:47}>` to `Box<dyn FnMut()>`
12
13error: aborting due to 1 previous error
14
15For more information about this error, try `rustc --explain E0271`.
tests/ui/never_type/fallback-closure-wrap.fallback.stderr deleted-15
......@@ -1,15 +0,0 @@
1error[E0271]: expected `{closure@fallback-closure-wrap.rs:17:40}` to return `()`, but it returns `!`
2 --> $DIR/fallback-closure-wrap.rs:18:9
3 |
4LL | let error = Closure::wrap(Box::new(move || {
5 | ------- this closure
6LL | panic!("Can't connect to server.");
7 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `!`
8 |
9 = note: expected unit type `()`
10 found type `!`
11 = note: required for the cast from `Box<{closure@$DIR/fallback-closure-wrap.rs:17:40: 17:47}>` to `Box<dyn FnMut()>`
12
13error: aborting due to 1 previous error
14
15For more information about this error, try `rustc --explain E0271`.
tests/ui/never_type/fallback-closure-wrap.rs deleted-28
......@@ -1,28 +0,0 @@
1// This is a minified example from Crater breakage observed when attempting to
2// stabilize never type, nstoddard/webgl-gui @ 22f0169f.
3//
4// Crater did not find many cases of this occurring, but it is included for
5// awareness.
6//
7//@ revisions: e2021 e2024
8//@[e2021] edition: 2021
9//@[e2024] edition: 2024
10//
11//@[e2021] check-pass
12
13use std::marker::PhantomData;
14
15fn main() {
16 let error = Closure::wrap(Box::new(move || {
17 panic!("Can't connect to server.");
18 //[e2024]~^ ERROR to return `()`, but it returns `!`
19 }) as Box<dyn FnMut()>);
20}
21
22struct Closure<T: ?Sized>(PhantomData<T>);
23
24impl<T: ?Sized> Closure<T> {
25 fn wrap(data: Box<T>) -> Closure<T> {
26 todo!()
27 }
28}
tests/ui/never_type/fallback_change/defaulted-never-note.e2021.stderr created+18
......@@ -0,0 +1,18 @@
1Future incompatibility report: Future breakage diagnostic:
2warning: this function depends on never type fallback being `()`
3 --> $DIR/defaulted-never-note.rs:38:1
4 |
5LL | fn main() {
6 | ^^^^^^^^^
7 |
8 = help: specify the types explicitly
9note: in edition 2024, the requirement `!: OnlyUnit` will fail
10 --> $DIR/defaulted-never-note.rs:40:19
11 |
12LL | requires_unit(x);
13 | ^
14help: use `()` annotations to avoid fallback changes
15 |
16LL | let x: () = return;
17 | ++++
18
tests/ui/never_type/fallback_change/defaulted-never-note.e2024.stderr created+62
......@@ -0,0 +1,62 @@
1error[E0277]: the trait bound `!: OnlyUnit` is not satisfied
2 --> $DIR/defaulted-never-note.rs:40:19
3 |
4LL | requires_unit(x);
5 | ------------- ^ the trait `OnlyUnit` is not implemented for `!`
6 | |
7 | required by a bound introduced by this call
8 |
9help: the trait `OnlyUnit` is implemented for `()`
10 --> $DIR/defaulted-never-note.rs:13:1
11 |
12LL | impl OnlyUnit for () {}
13 | ^^^^^^^^^^^^^^^^^^^^
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `requires_unit`
17 --> $DIR/defaulted-never-note.rs:16:26
18 |
19LL | fn requires_unit(_: impl OnlyUnit) {}
20 | ^^^^^^^^ required by this bound in `requires_unit`
21
22error[E0277]: the trait bound `!: OnlyU32` is not satisfied
23 --> $DIR/defaulted-never-note.rs:48:18
24 |
25LL | requires_u32(x);
26 | ------------ ^ the trait `OnlyU32` is not implemented for `!`
27 | |
28 | required by a bound introduced by this call
29 |
30help: the trait `OnlyU32` is implemented for `u32`
31 --> $DIR/defaulted-never-note.rs:23:1
32 |
33LL | impl OnlyU32 for u32 {}
34 | ^^^^^^^^^^^^^^^^^^^^
35note: required by a bound in `requires_u32`
36 --> $DIR/defaulted-never-note.rs:26:25
37 |
38LL | fn requires_u32(_: impl OnlyU32) {}
39 | ^^^^^^^ required by this bound in `requires_u32`
40
41error[E0277]: the trait bound `!: Nothing` is not satisfied
42 --> $DIR/defaulted-never-note.rs:54:22
43 |
44LL | requires_nothing(x);
45 | ---------------- ^ the trait `Nothing` is not implemented for `!`
46 | |
47 | required by a bound introduced by this call
48 |
49help: this trait has no implementations, consider adding one
50 --> $DIR/defaulted-never-note.rs:31:1
51 |
52LL | trait Nothing {}
53 | ^^^^^^^^^^^^^
54note: required by a bound in `requires_nothing`
55 --> $DIR/defaulted-never-note.rs:34:29
56 |
57LL | fn requires_nothing(_: impl Nothing) {}
58 | ^^^^^^^ required by this bound in `requires_nothing`
59
60error: aborting due to 3 previous errors
61
62For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback_change/defaulted-never-note.rs created+58
......@@ -0,0 +1,58 @@
1// Test diagnostic for the case where a trait is not implemented for `!`. If it is implemented
2// for `()`, we want to add a note saying that this might be caused by a breaking change in the
3// compiler.
4//
5//@ revisions: e2021 e2024
6//@[e2021] edition: 2021
7//@[e2024] edition: 2024
8//@[e2021] run-pass
9#![expect(dependency_on_unit_never_type_fallback, unused)]
10
11trait OnlyUnit {}
12
13impl OnlyUnit for () {}
14//[e2024]~^ help: trait `OnlyUnit` is implemented for `()`
15
16fn requires_unit(_: impl OnlyUnit) {}
17//[e2024]~^ note: required by this bound in `requires_unit`
18//[e2024]~| note: required by a bound in `requires_unit`
19
20
21trait OnlyU32 {}
22
23impl OnlyU32 for u32 {}
24//[e2024]~^ help: the trait `OnlyU32` is implemented for `u32`
25
26fn requires_u32(_: impl OnlyU32) {}
27//[e2024]~^ note: required by this bound in `requires_u32`
28//[e2024]~| note: required by a bound in `requires_u32`
29
30
31trait Nothing {}
32//[e2024]~^ help: this trait has no implementations, consider adding one
33
34fn requires_nothing(_: impl Nothing) {}
35//[e2024]~^ note: required by this bound in `requires_nothing`
36//[e2024]~| note: required by a bound in `requires_nothing`
37
38fn main() {
39 let x = return;
40 requires_unit(x);
41 //[e2024]~^ error: the trait bound `!: OnlyUnit` is not satisfied
42 //[e2024]~| note: the trait `OnlyUnit` is not implemented for `!`
43 //[e2024]~| note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
44 //[e2024]~| note: required by a bound introduced by this call
45 //[e2024]~| help: you might have intended to use the type `()`
46
47 #[cfg(e2024)]
48 requires_u32(x);
49 //[e2024]~^ error: the trait bound `!: OnlyU32` is not satisfied
50 //[e2024]~| note: the trait `OnlyU32` is not implemented for `!`
51 //[e2024]~| note: required by a bound introduced by this call
52
53 #[cfg(e2024)]
54 requires_nothing(x);
55 //[e2024]~^ error: the trait bound `!: Nothing` is not satisfied
56 //[e2024]~| note: the trait `Nothing` is not implemented for `!`
57 //[e2024]~| note: required by a bound introduced by this call
58}
tests/ui/never_type/fallback_change/dependency-on-fallback-to-unit.rs created+26
......@@ -0,0 +1,26 @@
1fn main() {
2 def();
3 _ = question_mark();
4}
5
6fn def() {
7 //~^ error: this function depends on never type fallback being `()`
8 //~| 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!
9 match true {
10 false => <_>::default(),
11 true => return,
12 };
13}
14
15// <https://github.com/rust-lang/rust/issues/51125>
16// <https://github.com/rust-lang/rust/issues/39216>
17fn question_mark() -> Result<(), ()> {
18 //~^ error: this function depends on never type fallback being `()`
19 //~| 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!
20 deserialize()?;
21 Ok(())
22}
23
24fn deserialize<T: Default>() -> Result<T, ()> {
25 Ok(T::default())
26}
tests/ui/never_type/fallback_change/dependency-on-fallback-to-unit.stderr created+85
......@@ -0,0 +1,85 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/dependency-on-fallback-to-unit.rs:6:1
3 |
4LL | fn def() {
5 | ^^^^^^^^
6 |
7 = help: specify the types explicitly
8note: in edition 2024, the requirement `!: Default` will fail
9 --> $DIR/dependency-on-fallback-to-unit.rs:10:19
10 |
11LL | false => <_>::default(),
12 | ^
13 = 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!
14 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL - false => <_>::default(),
19LL + false => <()>::default(),
20 |
21
22error: this function depends on never type fallback being `()`
23 --> $DIR/dependency-on-fallback-to-unit.rs:17:1
24 |
25LL | fn question_mark() -> Result<(), ()> {
26 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27 |
28 = help: specify the types explicitly
29note: in edition 2024, the requirement `!: Default` will fail
30 --> $DIR/dependency-on-fallback-to-unit.rs:20:5
31 |
32LL | deserialize()?;
33 | ^^^^^^^^^^^^^
34 = 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!
35 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
36help: use `()` annotations to avoid fallback changes
37 |
38LL | deserialize::<()>()?;
39 | ++++++
40
41error: aborting due to 2 previous errors
42
43Future incompatibility report: Future breakage diagnostic:
44error: this function depends on never type fallback being `()`
45 --> $DIR/dependency-on-fallback-to-unit.rs:6:1
46 |
47LL | fn def() {
48 | ^^^^^^^^
49 |
50 = help: specify the types explicitly
51note: in edition 2024, the requirement `!: Default` will fail
52 --> $DIR/dependency-on-fallback-to-unit.rs:10:19
53 |
54LL | false => <_>::default(),
55 | ^
56 = 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!
57 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
58 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
59help: use `()` annotations to avoid fallback changes
60 |
61LL - false => <_>::default(),
62LL + false => <()>::default(),
63 |
64
65Future breakage diagnostic:
66error: this function depends on never type fallback being `()`
67 --> $DIR/dependency-on-fallback-to-unit.rs:17:1
68 |
69LL | fn question_mark() -> Result<(), ()> {
70 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71 |
72 = help: specify the types explicitly
73note: in edition 2024, the requirement `!: Default` will fail
74 --> $DIR/dependency-on-fallback-to-unit.rs:20:5
75 |
76LL | deserialize()?;
77 | ^^^^^^^^^^^^^
78 = 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!
79 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
80 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
81help: use `()` annotations to avoid fallback changes
82 |
83LL | deserialize::<()>()?;
84 | ++++++
85
tests/ui/never_type/fallback_change/diverging-fallback-unconstrained-return.e2021.stderr created+43
......@@ -0,0 +1,43 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/diverging-fallback-unconstrained-return.rs:26:1
3 |
4LL | fn main() {
5 | ^^^^^^^^^
6 |
7 = help: specify the types explicitly
8note: in edition 2024, the requirement `!: UnitReturn` will fail
9 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
10 |
11LL | let _ = if true { unconstrained_return() } else { panic!() };
12 | ^^^^^^^^^^^^^^^^^^^^^^
13 = 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!
14 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL | let _: () = if true { unconstrained_return() } else { panic!() };
19 | ++++
20
21error: aborting due to 1 previous error
22
23Future incompatibility report: Future breakage diagnostic:
24error: this function depends on never type fallback being `()`
25 --> $DIR/diverging-fallback-unconstrained-return.rs:26:1
26 |
27LL | fn main() {
28 | ^^^^^^^^^
29 |
30 = help: specify the types explicitly
31note: in edition 2024, the requirement `!: UnitReturn` will fail
32 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
33 |
34LL | let _ = if true { unconstrained_return() } else { panic!() };
35 | ^^^^^^^^^^^^^^^^^^^^^^
36 = 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!
37 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
38 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
39help: use `()` annotations to avoid fallback changes
40 |
41LL | let _: () = if true { unconstrained_return() } else { panic!() };
42 | ++++
43
tests/ui/never_type/fallback_change/diverging-fallback-unconstrained-return.e2024.stderr created+24
......@@ -0,0 +1,24 @@
1error[E0277]: the trait bound `!: UnitReturn` is not satisfied
2 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
3 |
4LL | let _ = if true { unconstrained_return() } else { panic!() };
5 | ^^^^^^^^^^^^^^^^^^^^^^ the trait `UnitReturn` is not implemented for `!`
6 |
7help: the following other types implement trait `UnitReturn`
8 --> $DIR/diverging-fallback-unconstrained-return.rs:15:1
9 |
10LL | impl UnitReturn for i32 {}
11 | ^^^^^^^^^^^^^^^^^^^^^^^ `i32`
12LL | impl UnitReturn for () {}
13 | ^^^^^^^^^^^^^^^^^^^^^^ `()`
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `unconstrained_return`
17 --> $DIR/diverging-fallback-unconstrained-return.rs:18:28
18 |
19LL | fn unconstrained_return<T: UnitReturn>() -> T {
20 | ^^^^^^^^^^ required by this bound in `unconstrained_return`
21
22error: aborting due to 1 previous error
23
24For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback_change/diverging-fallback-unconstrained-return.fallback.stderr created+24
......@@ -0,0 +1,24 @@
1error[E0277]: the trait bound `!: UnitReturn` is not satisfied
2 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
3 |
4LL | let _ = if true { unconstrained_return() } else { panic!() };
5 | ^^^^^^^^^^^^^^^^^^^^^^ the trait `UnitReturn` is not implemented for `!`
6 |
7help: the following other types implement trait `UnitReturn`
8 --> $DIR/diverging-fallback-unconstrained-return.rs:15:1
9 |
10LL | impl UnitReturn for i32 {}
11 | ^^^^^^^^^^^^^^^^^^^^^^^ `i32`
12LL | impl UnitReturn for () {}
13 | ^^^^^^^^^^^^^^^^^^^^^^ `()`
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `unconstrained_return`
17 --> $DIR/diverging-fallback-unconstrained-return.rs:18:28
18 |
19LL | fn unconstrained_return<T: UnitReturn>() -> T {
20 | ^^^^^^^^^^ required by this bound in `unconstrained_return`
21
22error: aborting due to 1 previous error
23
24For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback_change/diverging-fallback-unconstrained-return.nofallback.stderr created+43
......@@ -0,0 +1,43 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/diverging-fallback-unconstrained-return.rs:26:1
3 |
4LL | fn main() {
5 | ^^^^^^^^^
6 |
7 = 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!
8 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
9 = help: specify the types explicitly
10note: in edition 2024, the requirement `!: UnitReturn` will fail
11 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
12 |
13LL | let _ = if true { unconstrained_return() } else { panic!() };
14 | ^^^^^^^^^^^^^^^^^^^^^^
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL | let _: () = if true { unconstrained_return() } else { panic!() };
19 | ++++
20
21error: aborting due to 1 previous error
22
23Future incompatibility report: Future breakage diagnostic:
24error: this function depends on never type fallback being `()`
25 --> $DIR/diverging-fallback-unconstrained-return.rs:26:1
26 |
27LL | fn main() {
28 | ^^^^^^^^^
29 |
30 = 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!
31 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
32 = help: specify the types explicitly
33note: in edition 2024, the requirement `!: UnitReturn` will fail
34 --> $DIR/diverging-fallback-unconstrained-return.rs:37:23
35 |
36LL | let _ = if true { unconstrained_return() } else { panic!() };
37 | ^^^^^^^^^^^^^^^^^^^^^^
38 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
39help: use `()` annotations to avoid fallback changes
40 |
41LL | let _: () = if true { unconstrained_return() } else { panic!() };
42 | ++++
43
tests/ui/never_type/fallback_change/diverging-fallback-unconstrained-return.rs created+38
......@@ -0,0 +1,38 @@
1// Variant of diverging-fallback-control-flow that tests
2// the specific case of a free function with an unconstrained
3// return type. This captures the pattern we saw in the wild
4// in the objc crate, where changing the fallback from `!` to `()`
5// resulted in unsoundness.
6//
7//@ revisions: e2021 e2024
8//@[e2024] edition: 2024
9
10#![expect(unit_bindings)]
11
12fn make_unit() {}
13
14trait UnitReturn {}
15impl UnitReturn for i32 {}
16impl UnitReturn for () {}
17
18fn unconstrained_return<T: UnitReturn>() -> T {
19 unsafe {
20 let make_unit_fn: fn() = make_unit;
21 let ffi: fn() -> T = std::mem::transmute(make_unit_fn);
22 ffi()
23 }
24}
25
26fn main() {
27 //[e2021]~^ error: this function depends on never type fallback being `()`
28 //[e2021]~| 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!
29
30 // In Ye Olde Days, the `T` parameter of `unconstrained_return`
31 // winds up "entangled" with the `!` type that results from
32 // `panic!`, and hence falls back to `()`. This is kind of unfortunate
33 // and unexpected. When we introduced the `!` type, the original
34 // idea was to change that fallback to `!`, but that would have resulted
35 // in this code no longer compiling (or worse, in some cases it injected
36 // unsound results).
37 let _ = if true { unconstrained_return() } else { panic!() }; //[e2024]~ error: the trait bound `!: UnitReturn` is not satisfied
38}
tests/ui/never_type/fallback_change/dont-suggest-turbofish-from-expansion.rs created+18
......@@ -0,0 +1,18 @@
1fn create_ok_default<C>() -> Result<C, ()>
2where
3 C: Default,
4{
5 Ok(C::default())
6}
7
8fn main() -> Result<(), ()> {
9 //~^ ERROR this function depends on never type fallback being `()`
10 //~| WARN this was previously accepted by the compiler but is being phased out
11 let (returned_value, _) = (|| {
12 let created = create_ok_default()?;
13 Ok((created, ()))
14 })()?;
15
16 let _ = format_args!("{:?}", returned_value);
17 Ok(())
18}
tests/ui/never_type/fallback_change/dont-suggest-turbofish-from-expansion.stderr created+43
......@@ -0,0 +1,43 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/dont-suggest-turbofish-from-expansion.rs:8:1
3 |
4LL | fn main() -> Result<(), ()> {
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
7 = help: specify the types explicitly
8note: in edition 2024, the requirement `!: Default` will fail
9 --> $DIR/dont-suggest-turbofish-from-expansion.rs:12:23
10 |
11LL | let created = create_ok_default()?;
12 | ^^^^^^^^^^^^^^^^^^^
13 = 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!
14 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL | let created: () = create_ok_default()?;
19 | ++++
20
21error: aborting due to 1 previous error
22
23Future incompatibility report: Future breakage diagnostic:
24error: this function depends on never type fallback being `()`
25 --> $DIR/dont-suggest-turbofish-from-expansion.rs:8:1
26 |
27LL | fn main() -> Result<(), ()> {
28 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
29 |
30 = help: specify the types explicitly
31note: in edition 2024, the requirement `!: Default` will fail
32 --> $DIR/dont-suggest-turbofish-from-expansion.rs:12:23
33 |
34LL | let created = create_ok_default()?;
35 | ^^^^^^^^^^^^^^^^^^^
36 = 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!
37 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
38 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
39help: use `()` annotations to avoid fallback changes
40 |
41LL | let created: () = create_ok_default()?;
42 | ++++
43
tests/ui/never_type/fallback_change/fallback-closure-ret.e2021.stderr created+18
......@@ -0,0 +1,18 @@
1Future incompatibility report: Future breakage diagnostic:
2warning: this function depends on never type fallback being `()`
3 --> $DIR/fallback-closure-ret.rs:21:1
4 |
5LL | fn main() {
6 | ^^^^^^^^^
7 |
8 = help: specify the types explicitly
9note: in edition 2024, the requirement `!: Bar` will fail
10 --> $DIR/fallback-closure-ret.rs:22:5
11 |
12LL | foo(|| panic!());
13 | ^^^^^^^^^^^^^^^^
14help: use `()` annotations to avoid fallback changes
15 |
16LL | foo::<()>(|| panic!());
17 | ++++++
18
tests/ui/never_type/fallback_change/fallback-closure-ret.e2024.stderr created+24
......@@ -0,0 +1,24 @@
1error[E0277]: the trait bound `!: Bar` is not satisfied
2 --> $DIR/fallback-closure-ret.rs:22:5
3 |
4LL | foo(|| panic!());
5 | ^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `!`
6 |
7help: the following other types implement trait `Bar`
8 --> $DIR/fallback-closure-ret.rs:15:1
9 |
10LL | impl Bar for () {}
11 | ^^^^^^^^^^^^^^^ `()`
12LL | impl Bar for u32 {}
13 | ^^^^^^^^^^^^^^^^ `u32`
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `foo`
17 --> $DIR/fallback-closure-ret.rs:18:11
18 |
19LL | fn foo<R: Bar>(_: impl Fn() -> R) {}
20 | ^^^ required by this bound in `foo`
21
22error: aborting due to 1 previous error
23
24For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback_change/fallback-closure-ret.fallback.stderr created+24
......@@ -0,0 +1,24 @@
1error[E0277]: the trait bound `!: Bar` is not satisfied
2 --> $DIR/fallback-closure-ret.rs:18:5
3 |
4LL | foo(|| panic!());
5 | ^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `!`
6 |
7help: the following other types implement trait `Bar`
8 --> $DIR/fallback-closure-ret.rs:12:1
9 |
10LL | impl Bar for () {}
11 | ^^^^^^^^^^^^^^^ `()`
12LL | impl Bar for u32 {}
13 | ^^^^^^^^^^^^^^^^ `u32`
14 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
15 = help: you might have intended to use the type `()` here instead
16note: required by a bound in `foo`
17 --> $DIR/fallback-closure-ret.rs:15:11
18 |
19LL | fn foo<R: Bar>(_: impl Fn() -> R) {}
20 | ^^^ required by this bound in `foo`
21
22error: aborting due to 1 previous error
23
24For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback_change/fallback-closure-ret.nofallback.stderr created+18
......@@ -0,0 +1,18 @@
1Future incompatibility report: Future breakage diagnostic:
2warning: this function depends on never type fallback being `()`
3 --> $DIR/fallback-closure-ret.rs:17:1
4 |
5LL | fn main() {
6 | ^^^^^^^^^
7 |
8 = help: specify the types explicitly
9note: in edition 2024, the requirement `!: Bar` will fail
10 --> $DIR/fallback-closure-ret.rs:18:5
11 |
12LL | foo(|| panic!());
13 | ^^^^^^^^^^^^^^^^
14help: use `()` annotations to avoid fallback changes
15 |
16LL | foo::<()>(|| panic!());
17 | ++++++
18
tests/ui/never_type/fallback_change/fallback-closure-ret.rs created+23
......@@ -0,0 +1,23 @@
1// Tests the pattern of returning `!` from a closure and then checking if the
2// return type iumplements a trait (not implemented for `!`).
3//
4// This test used to test that this pattern is not broken by context dependant
5// never type fallback. However, it got removed, so now this is an example of
6// expected breakage from the never type fallback change.
7//
8//@ revisions: e2021 e2024
9//@[e2021] edition: 2021
10//@[e2024] edition: 2024
11//
12//@[e2021] check-pass
13
14trait Bar {}
15impl Bar for () {}
16impl Bar for u32 {}
17
18fn foo<R: Bar>(_: impl Fn() -> R) {}
19
20#[cfg_attr(e2021, expect(dependency_on_unit_never_type_fallback))]
21fn main() {
22 foo(|| panic!()); //[e2024]~ error: the trait bound `!: Bar` is not satisfied
23}
tests/ui/never_type/fallback_change/fallback-closure-wrap.e2024.stderr created+15
......@@ -0,0 +1,15 @@
1error[E0271]: expected `{closure@fallback-closure-wrap.rs:16:40}` to return `()`, but it returns `!`
2 --> $DIR/fallback-closure-wrap.rs:17:9
3 |
4LL | let error = Closure::wrap(Box::new(move || {
5 | ------- this closure
6LL | panic!("Can't connect to server.");
7 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `!`
8 |
9 = note: expected unit type `()`
10 found type `!`
11 = note: required for the cast from `Box<{closure@$DIR/fallback-closure-wrap.rs:16:40: 16:47}>` to `Box<dyn FnMut()>`
12
13error: aborting due to 1 previous error
14
15For more information about this error, try `rustc --explain E0271`.
tests/ui/never_type/fallback_change/fallback-closure-wrap.fallback.stderr created+15
......@@ -0,0 +1,15 @@
1error[E0271]: expected `{closure@fallback-closure-wrap.rs:17:40}` to return `()`, but it returns `!`
2 --> $DIR/fallback-closure-wrap.rs:18:9
3 |
4LL | let error = Closure::wrap(Box::new(move || {
5 | ------- this closure
6LL | panic!("Can't connect to server.");
7 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `!`
8 |
9 = note: expected unit type `()`
10 found type `!`
11 = note: required for the cast from `Box<{closure@$DIR/fallback-closure-wrap.rs:17:40: 17:47}>` to `Box<dyn FnMut()>`
12
13error: aborting due to 1 previous error
14
15For more information about this error, try `rustc --explain E0271`.
tests/ui/never_type/fallback_change/fallback-closure-wrap.rs created+28
......@@ -0,0 +1,28 @@
1// This is a minified example from Crater breakage observed when attempting to
2// stabilize never type, nstoddard/webgl-gui @ 22f0169f.
3//
4// Crater did not find many cases of this occurring, but it is included for
5// awareness.
6//
7//@ revisions: e2021 e2024
8//@[e2021] edition: 2021
9//@[e2024] edition: 2024
10//
11//@[e2021] check-pass
12
13use std::marker::PhantomData;
14
15fn main() {
16 let error = Closure::wrap(Box::new(move || {
17 panic!("Can't connect to server.");
18 //[e2024]~^ ERROR to return `()`, but it returns `!`
19 }) as Box<dyn FnMut()>);
20}
21
22struct Closure<T: ?Sized>(PhantomData<T>);
23
24impl<T: ?Sized> Closure<T> {
25 fn wrap(data: Box<T>) -> Closure<T> {
26 todo!()
27 }
28}
tests/ui/never_type/fallback_change/from_infer_breaking_with_unit_fallback.rs created+29
......@@ -0,0 +1,29 @@
1// issue: rust-lang/rust#66757
2//
3// This is a *minimization* of the issue.
4// Note that the original version with the `?` does not fail anymore even with fallback to unit,
5// see `tests/ui/never_type/fallback_change/question_mark_from_never.rs`.
6//
7//@ revisions: unit never
8//@[never] check-pass
9#![allow(internal_features)]
10#![feature(rustc_attrs, never_type)]
11#![cfg_attr(unit, rustc_never_type_options(fallback = "unit"))]
12#![cfg_attr(never, rustc_never_type_options(fallback = "never"))]
13
14struct E;
15
16impl From<!> for E {
17 fn from(_: !) -> E {
18 E
19 }
20}
21
22#[allow(unreachable_code)]
23fn foo(never: !) {
24 <E as From<!>>::from(never); // Ok
25 <E as From<_>>::from(never); // Should the inference fail?
26 //[unit]~^ error: the trait bound `E: From<()>` is not satisfied
27}
28
29fn main() {}
tests/ui/never_type/fallback_change/from_infer_breaking_with_unit_fallback.unit.stderr created+17
......@@ -0,0 +1,17 @@
1error[E0277]: the trait bound `E: From<()>` is not satisfied
2 --> $DIR/from_infer_breaking_with_unit_fallback.rs:25:6
3 |
4LL | <E as From<_>>::from(never); // Should the inference fail?
5 | ^ unsatisfied trait bound
6 |
7help: the trait `From<()>` is not implemented for `E`
8 but trait `From<!>` is implemented for it
9 --> $DIR/from_infer_breaking_with_unit_fallback.rs:16:1
10 |
11LL | impl From<!> for E {
12 | ^^^^^^^^^^^^^^^^^^
13 = help: for that trait implementation, expected `!`, found `()`
14
15error: aborting due to 1 previous error
16
17For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback_change/lint-breaking-2024-assign-underscore.fixed created+15
......@@ -0,0 +1,15 @@
1//@ run-rustfix
2#![allow(unused)]
3
4fn foo<T: Default>() -> Result<T, ()> {
5 Err(())
6}
7
8fn test() -> Result<(), ()> {
9 //~^ ERROR this function depends on never type fallback being `()`
10 //~| WARN this was previously accepted by the compiler but is being phased out
11 _ = foo::<()>()?;
12 Ok(())
13}
14
15fn main() {}
tests/ui/never_type/fallback_change/lint-breaking-2024-assign-underscore.rs created+15
......@@ -0,0 +1,15 @@
1//@ run-rustfix
2#![allow(unused)]
3
4fn foo<T: Default>() -> Result<T, ()> {
5 Err(())
6}
7
8fn test() -> Result<(), ()> {
9 //~^ ERROR this function depends on never type fallback being `()`
10 //~| WARN this was previously accepted by the compiler but is being phased out
11 _ = foo()?;
12 Ok(())
13}
14
15fn main() {}
tests/ui/never_type/fallback_change/lint-breaking-2024-assign-underscore.stderr created+43
......@@ -0,0 +1,43 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/lint-breaking-2024-assign-underscore.rs:8:1
3 |
4LL | fn test() -> Result<(), ()> {
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
7 = help: specify the types explicitly
8note: in edition 2024, the requirement `!: Default` will fail
9 --> $DIR/lint-breaking-2024-assign-underscore.rs:11:9
10 |
11LL | _ = foo()?;
12 | ^^^^^
13 = 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!
14 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL | _ = foo::<()>()?;
19 | ++++++
20
21error: aborting due to 1 previous error
22
23Future incompatibility report: Future breakage diagnostic:
24error: this function depends on never type fallback being `()`
25 --> $DIR/lint-breaking-2024-assign-underscore.rs:8:1
26 |
27LL | fn test() -> Result<(), ()> {
28 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
29 |
30 = help: specify the types explicitly
31note: in edition 2024, the requirement `!: Default` will fail
32 --> $DIR/lint-breaking-2024-assign-underscore.rs:11:9
33 |
34LL | _ = foo()?;
35 | ^^^^^
36 = 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!
37 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
38 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
39help: use `()` annotations to avoid fallback changes
40 |
41LL | _ = foo::<()>()?;
42 | ++++++
43
tests/ui/never_type/fallback_change/lint-never-type-fallback-flowing-into-unsafe.e2015.stderr created+287
......@@ -0,0 +1,287 @@
1error: never type fallback affects this call to an `unsafe` function
2 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
3 |
4LL | unsafe { mem::zeroed() }
5 | ^^^^^^^^^^^^^
6 |
7 = help: specify the type explicitly
8 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
9 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
10 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
11help: use `()` annotations to avoid fallback changes
12 |
13LL | unsafe { mem::zeroed::<()>() }
14 | ++++++
15
16error: never type fallback affects this call to an `unsafe` function
17 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13
18 |
19LL | core::mem::transmute(Zst)
20 | ^^^^^^^^^^^^^^^^^^^^^^^^^
21 |
22 = help: specify the type explicitly
23 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
24 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
25help: use `()` annotations to avoid fallback changes
26 |
27LL | core::mem::transmute::<_, ()>(Zst)
28 | +++++++++
29
30error: never type fallback affects this union access
31 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18
32 |
33LL | unsafe { Union { a: () }.b }
34 | ^^^^^^^^^^^^^^^^^
35 |
36 = help: specify the type explicitly
37 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
38 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
39
40error: never type fallback affects this raw pointer dereference
41 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18
42 |
43LL | unsafe { *ptr::from_ref(&()).cast() }
44 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
45 |
46 = help: specify the type explicitly
47 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
48 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
49help: use `()` annotations to avoid fallback changes
50 |
51LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
52 | ++++++
53
54error: never type fallback affects this call to an `unsafe` function
55 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18
56 |
57LL | unsafe { internally_create(x) }
58 | ^^^^^^^^^^^^^^^^^^^^
59 |
60 = help: specify the type explicitly
61 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
62 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
63help: use `()` annotations to avoid fallback changes
64 |
65LL | unsafe { internally_create::<()>(x) }
66 | ++++++
67
68error: never type fallback affects this call to an `unsafe` function
69 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18
70 |
71LL | unsafe { zeroed() }
72 | ^^^^^^^^
73 |
74 = help: specify the type explicitly
75 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
76 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
77help: use `()` annotations to avoid fallback changes
78 |
79LL | let zeroed = mem::zeroed::<()>;
80 | ++++++
81
82error: never type fallback affects this `unsafe` function
83 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22
84 |
85LL | let zeroed = mem::zeroed;
86 | ^^^^^^^^^^^
87 |
88 = help: specify the type explicitly
89 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
90 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
91help: use `()` annotations to avoid fallback changes
92 |
93LL | let zeroed = mem::zeroed::<()>;
94 | ++++++
95
96error: never type fallback affects this `unsafe` function
97 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17
98 |
99LL | let f = internally_create;
100 | ^^^^^^^^^^^^^^^^^
101 |
102 = help: specify the type explicitly
103 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
104 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
105help: use `()` annotations to avoid fallback changes
106 |
107LL | let f = internally_create::<()>;
108 | ++++++
109
110error: never type fallback affects this call to an `unsafe` method
111 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13
112 |
113LL | S(marker::PhantomData).create_out_of_thin_air()
114 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115 |
116 = help: specify the type explicitly
117 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
118 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
119
120error: never type fallback affects this call to an `unsafe` function
121 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19
122 |
123LL | match send_message::<_ /* ?0 */>() {
124 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125...
126LL | msg_send!();
127 | ----------- in this macro invocation
128 |
129 = help: specify the type explicitly
130 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
131 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
132 = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
133
134error: aborting due to 10 previous errors
135
136Future incompatibility report: Future breakage diagnostic:
137error: never type fallback affects this call to an `unsafe` function
138 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
139 |
140LL | unsafe { mem::zeroed() }
141 | ^^^^^^^^^^^^^
142 |
143 = help: specify the type explicitly
144 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
145 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
146 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
147help: use `()` annotations to avoid fallback changes
148 |
149LL | unsafe { mem::zeroed::<()>() }
150 | ++++++
151
152Future breakage diagnostic:
153error: never type fallback affects this call to an `unsafe` function
154 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13
155 |
156LL | core::mem::transmute(Zst)
157 | ^^^^^^^^^^^^^^^^^^^^^^^^^
158 |
159 = help: specify the type explicitly
160 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
161 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
162 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
163help: use `()` annotations to avoid fallback changes
164 |
165LL | core::mem::transmute::<_, ()>(Zst)
166 | +++++++++
167
168Future breakage diagnostic:
169error: never type fallback affects this union access
170 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18
171 |
172LL | unsafe { Union { a: () }.b }
173 | ^^^^^^^^^^^^^^^^^
174 |
175 = help: specify the type explicitly
176 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
177 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
178 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
179
180Future breakage diagnostic:
181error: never type fallback affects this raw pointer dereference
182 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18
183 |
184LL | unsafe { *ptr::from_ref(&()).cast() }
185 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
186 |
187 = help: specify the type explicitly
188 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
189 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
190 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
191help: use `()` annotations to avoid fallback changes
192 |
193LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
194 | ++++++
195
196Future breakage diagnostic:
197error: never type fallback affects this call to an `unsafe` function
198 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18
199 |
200LL | unsafe { internally_create(x) }
201 | ^^^^^^^^^^^^^^^^^^^^
202 |
203 = help: specify the type explicitly
204 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
205 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
206 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
207help: use `()` annotations to avoid fallback changes
208 |
209LL | unsafe { internally_create::<()>(x) }
210 | ++++++
211
212Future breakage diagnostic:
213error: never type fallback affects this call to an `unsafe` function
214 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18
215 |
216LL | unsafe { zeroed() }
217 | ^^^^^^^^
218 |
219 = help: specify the type explicitly
220 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
221 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
222 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
223help: use `()` annotations to avoid fallback changes
224 |
225LL | let zeroed = mem::zeroed::<()>;
226 | ++++++
227
228Future breakage diagnostic:
229error: never type fallback affects this `unsafe` function
230 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22
231 |
232LL | let zeroed = mem::zeroed;
233 | ^^^^^^^^^^^
234 |
235 = help: specify the type explicitly
236 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
237 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
238 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
239help: use `()` annotations to avoid fallback changes
240 |
241LL | let zeroed = mem::zeroed::<()>;
242 | ++++++
243
244Future breakage diagnostic:
245error: never type fallback affects this `unsafe` function
246 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17
247 |
248LL | let f = internally_create;
249 | ^^^^^^^^^^^^^^^^^
250 |
251 = help: specify the type explicitly
252 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
253 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
254 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
255help: use `()` annotations to avoid fallback changes
256 |
257LL | let f = internally_create::<()>;
258 | ++++++
259
260Future breakage diagnostic:
261error: never type fallback affects this call to an `unsafe` method
262 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13
263 |
264LL | S(marker::PhantomData).create_out_of_thin_air()
265 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
266 |
267 = help: specify the type explicitly
268 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
269 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
270 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
271
272Future breakage diagnostic:
273error: never type fallback affects this call to an `unsafe` function
274 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19
275 |
276LL | match send_message::<_ /* ?0 */>() {
277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
278...
279LL | msg_send!();
280 | ----------- in this macro invocation
281 |
282 = help: specify the type explicitly
283 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
284 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
285 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
286 = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
287
tests/ui/never_type/fallback_change/lint-never-type-fallback-flowing-into-unsafe.e2024.stderr created+296
......@@ -0,0 +1,296 @@
1error: never type fallback affects this call to an `unsafe` function
2 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
3 |
4LL | unsafe { mem::zeroed() }
5 | ^^^^^^^^^^^^^
6 |
7 = help: specify the type explicitly
8 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
9 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
10 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
11help: use `()` annotations to avoid fallback changes
12 |
13LL | unsafe { mem::zeroed::<()>() }
14 | ++++++
15
16error: never type fallback affects this call to an `unsafe` function
17 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13
18 |
19LL | core::mem::transmute(Zst)
20 | ^^^^^^^^^^^^^^^^^^^^^^^^^
21 |
22 = help: specify the type explicitly
23 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
24 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
25help: use `()` annotations to avoid fallback changes
26 |
27LL | core::mem::transmute::<_, ()>(Zst)
28 | +++++++++
29
30error: never type fallback affects this union access
31 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18
32 |
33LL | unsafe { Union { a: () }.b }
34 | ^^^^^^^^^^^^^^^^^
35 |
36 = help: specify the type explicitly
37 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
38 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
39
40error: never type fallback affects this raw pointer dereference
41 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18
42 |
43LL | unsafe { *ptr::from_ref(&()).cast() }
44 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
45 |
46 = help: specify the type explicitly
47 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
48 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
49help: use `()` annotations to avoid fallback changes
50 |
51LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
52 | ++++++
53
54error: never type fallback affects this call to an `unsafe` function
55 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18
56 |
57LL | unsafe { internally_create(x) }
58 | ^^^^^^^^^^^^^^^^^^^^
59 |
60 = help: specify the type explicitly
61 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
62 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
63help: use `()` annotations to avoid fallback changes
64 |
65LL | unsafe { internally_create::<()>(x) }
66 | ++++++
67
68error: never type fallback affects this call to an `unsafe` function
69 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18
70 |
71LL | unsafe { zeroed() }
72 | ^^^^^^^^
73 |
74 = help: specify the type explicitly
75 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
76 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
77help: use `()` annotations to avoid fallback changes
78 |
79LL | let zeroed = mem::zeroed::<()>;
80 | ++++++
81
82error: never type fallback affects this `unsafe` function
83 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22
84 |
85LL | let zeroed = mem::zeroed;
86 | ^^^^^^^^^^^
87 |
88 = help: specify the type explicitly
89 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
90 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
91help: use `()` annotations to avoid fallback changes
92 |
93LL | let zeroed = mem::zeroed::<()>;
94 | ++++++
95
96error: never type fallback affects this `unsafe` function
97 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17
98 |
99LL | let f = internally_create;
100 | ^^^^^^^^^^^^^^^^^
101 |
102 = help: specify the type explicitly
103 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
104 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
105help: use `()` annotations to avoid fallback changes
106 |
107LL | let f = internally_create::<()>;
108 | ++++++
109
110error: never type fallback affects this call to an `unsafe` method
111 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13
112 |
113LL | S(marker::PhantomData).create_out_of_thin_air()
114 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115 |
116 = help: specify the type explicitly
117 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
118 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
119
120error: never type fallback affects this call to an `unsafe` function
121 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19
122 |
123LL | match send_message::<_ /* ?0 */>() {
124 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125...
126LL | msg_send!();
127 | ----------- in this macro invocation
128 |
129 = help: specify the type explicitly
130 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
131 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
132 = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
133
134warning: the type `!` does not permit zero-initialization
135 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
136 |
137LL | unsafe { mem::zeroed() }
138 | ^^^^^^^^^^^^^ this code causes undefined behavior when executed
139 |
140 = note: the `!` type has no valid value
141 = note: `#[warn(invalid_value)]` on by default
142
143error: aborting due to 10 previous errors; 1 warning emitted
144
145Future incompatibility report: Future breakage diagnostic:
146error: never type fallback affects this call to an `unsafe` function
147 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
148 |
149LL | unsafe { mem::zeroed() }
150 | ^^^^^^^^^^^^^
151 |
152 = help: specify the type explicitly
153 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
154 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
155 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
156help: use `()` annotations to avoid fallback changes
157 |
158LL | unsafe { mem::zeroed::<()>() }
159 | ++++++
160
161Future breakage diagnostic:
162error: never type fallback affects this call to an `unsafe` function
163 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13
164 |
165LL | core::mem::transmute(Zst)
166 | ^^^^^^^^^^^^^^^^^^^^^^^^^
167 |
168 = help: specify the type explicitly
169 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
170 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
171 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
172help: use `()` annotations to avoid fallback changes
173 |
174LL | core::mem::transmute::<_, ()>(Zst)
175 | +++++++++
176
177Future breakage diagnostic:
178error: never type fallback affects this union access
179 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18
180 |
181LL | unsafe { Union { a: () }.b }
182 | ^^^^^^^^^^^^^^^^^
183 |
184 = help: specify the type explicitly
185 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
186 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
187 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
188
189Future breakage diagnostic:
190error: never type fallback affects this raw pointer dereference
191 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18
192 |
193LL | unsafe { *ptr::from_ref(&()).cast() }
194 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
195 |
196 = help: specify the type explicitly
197 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
198 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
199 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
200help: use `()` annotations to avoid fallback changes
201 |
202LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
203 | ++++++
204
205Future breakage diagnostic:
206error: never type fallback affects this call to an `unsafe` function
207 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18
208 |
209LL | unsafe { internally_create(x) }
210 | ^^^^^^^^^^^^^^^^^^^^
211 |
212 = help: specify the type explicitly
213 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
214 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
215 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
216help: use `()` annotations to avoid fallback changes
217 |
218LL | unsafe { internally_create::<()>(x) }
219 | ++++++
220
221Future breakage diagnostic:
222error: never type fallback affects this call to an `unsafe` function
223 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18
224 |
225LL | unsafe { zeroed() }
226 | ^^^^^^^^
227 |
228 = help: specify the type explicitly
229 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
230 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
231 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
232help: use `()` annotations to avoid fallback changes
233 |
234LL | let zeroed = mem::zeroed::<()>;
235 | ++++++
236
237Future breakage diagnostic:
238error: never type fallback affects this `unsafe` function
239 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22
240 |
241LL | let zeroed = mem::zeroed;
242 | ^^^^^^^^^^^
243 |
244 = help: specify the type explicitly
245 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
246 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
247 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
248help: use `()` annotations to avoid fallback changes
249 |
250LL | let zeroed = mem::zeroed::<()>;
251 | ++++++
252
253Future breakage diagnostic:
254error: never type fallback affects this `unsafe` function
255 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17
256 |
257LL | let f = internally_create;
258 | ^^^^^^^^^^^^^^^^^
259 |
260 = help: specify the type explicitly
261 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
262 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
263 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
264help: use `()` annotations to avoid fallback changes
265 |
266LL | let f = internally_create::<()>;
267 | ++++++
268
269Future breakage diagnostic:
270error: never type fallback affects this call to an `unsafe` method
271 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13
272 |
273LL | S(marker::PhantomData).create_out_of_thin_air()
274 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275 |
276 = help: specify the type explicitly
277 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
278 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
279 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
280
281Future breakage diagnostic:
282error: never type fallback affects this call to an `unsafe` function
283 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19
284 |
285LL | match send_message::<_ /* ?0 */>() {
286 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287...
288LL | msg_send!();
289 | ----------- in this macro invocation
290 |
291 = help: specify the type explicitly
292 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
293 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
294 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
295 = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
296
tests/ui/never_type/fallback_change/lint-never-type-fallback-flowing-into-unsafe.rs created+168
......@@ -0,0 +1,168 @@
1//@ revisions: e2015 e2024
2//@[e2024] edition:2024
3
4use std::{marker, mem, ptr};
5
6fn main() {}
7
8fn _zero() {
9 if false {
10 unsafe { mem::zeroed() }
11 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
12 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
13 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
14 //[e2024]~| warn: the type `!` does not permit zero-initialization
15 } else {
16 return;
17 };
18
19 // no ; -> type is inferred without fallback
20 if true { unsafe { mem::zeroed() } } else { return }
21}
22
23fn _trans() {
24 if false {
25 unsafe {
26 struct Zst;
27 core::mem::transmute(Zst)
28 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
29 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
30 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
31 }
32 } else {
33 return;
34 };
35}
36
37fn _union() {
38 if false {
39 union Union<T: Copy> {
40 a: (),
41 b: T,
42 }
43
44 unsafe { Union { a: () }.b }
45 //[e2015]~^ error: never type fallback affects this union access
46 //[e2024]~^^ error: never type fallback affects this union access
47 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
48 } else {
49 return;
50 };
51}
52
53fn _deref() {
54 if false {
55 unsafe { *ptr::from_ref(&()).cast() }
56 //[e2015]~^ error: never type fallback affects this raw pointer dereference
57 //[e2024]~^^ error: never type fallback affects this raw pointer dereference
58 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
59 } else {
60 return;
61 };
62}
63
64fn _only_generics() {
65 if false {
66 unsafe fn internally_create<T>(_: Option<T>) {
67 unsafe {
68 let _ = mem::zeroed::<T>();
69 }
70 }
71
72 // We need the option (and unwrap later) to call a function in a way,
73 // which makes it affected by the fallback, but without having it return anything
74 let x = None;
75
76 unsafe { internally_create(x) }
77 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
78 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
79 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
80
81 x.unwrap()
82 } else {
83 return;
84 };
85}
86
87fn _stored_function() {
88 if false {
89 let zeroed = mem::zeroed;
90 //[e2015]~^ error: never type fallback affects this `unsafe` function
91 //[e2024]~^^ error: never type fallback affects this `unsafe` function
92 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
93
94 unsafe { zeroed() }
95 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
96 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
97 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
98 } else {
99 return;
100 };
101}
102
103fn _only_generics_stored_function() {
104 if false {
105 unsafe fn internally_create<T>(_: Option<T>) {
106 unsafe {
107 let _ = mem::zeroed::<T>();
108 }
109 }
110
111 let x = None;
112 let f = internally_create;
113 //[e2015]~^ error: never type fallback affects this `unsafe` function
114 //[e2024]~^^ error: never type fallback affects this `unsafe` function
115 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
116
117 unsafe { f(x) }
118
119 x.unwrap()
120 } else {
121 return;
122 };
123}
124
125fn _method() {
126 struct S<T>(marker::PhantomData<T>);
127
128 impl<T> S<T> {
129 #[allow(unused)] // FIXME: the unused lint is probably incorrect here
130 unsafe fn create_out_of_thin_air(&self) -> T {
131 todo!()
132 }
133 }
134
135 if false {
136 unsafe {
137 S(marker::PhantomData).create_out_of_thin_air()
138 //[e2015]~^ error: never type fallback affects this call to an `unsafe` method
139 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` method
140 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
141 }
142 } else {
143 return;
144 };
145}
146
147// Minimization of the famous `objc` crate issue
148fn _objc() {
149 pub unsafe fn send_message<R>() -> Result<R, ()> {
150 Ok(unsafe { core::mem::zeroed() })
151 }
152
153 macro_rules! msg_send {
154 () => {
155 match send_message::<_ /* ?0 */>() {
156 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
157 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
158 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
159 Ok(x) => x,
160 Err(_) => loop {},
161 }
162 };
163 }
164
165 unsafe {
166 msg_send!();
167 }
168}
tests/ui/never_type/fallback_change/question_mark_from_never.rs created+46
......@@ -0,0 +1,46 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/66757>.
2//
3// See also: `tests/ui/never_type/fallback_change/from_infer_breaking_with_unit_fallback.rs`.
4//
5//@ revisions: unit never
6//@ check-pass
7#![allow(internal_features)]
8#![feature(rustc_attrs, never_type)]
9#![cfg_attr(unit, rustc_never_type_options(fallback = "unit"))]
10#![cfg_attr(never, rustc_never_type_options(fallback = "never"))]
11
12type Infallible = !;
13
14struct E;
15
16impl From<Infallible> for E {
17 fn from(_: Infallible) -> E {
18 E
19 }
20}
21
22fn u32_try_from(x: u32) -> Result<u32, Infallible> {
23 Ok(x)
24}
25
26fn _f() -> Result<(), E> {
27 // In an old attempt to make `Infallible = !` this caused a problem.
28 //
29 // Because at the time the code desugared to
30 //
31 // match u32::try_from(1u32) {
32 // Ok(x) => x, Err(e) => return Err(E::from(e))
33 // }
34 //
35 // With `Infallible = !`, `e: !` but with fallback to `()`, `e` in `E::from(e)` decayed to `()`
36 // causing an error.
37 //
38 // This does not happen with `Infallible = !`.
39 // And also does not happen with the newer `?` desugaring that does not pass `e` by value.
40 // (instead we only pass `Result<!, Error>` (where `Error = !` in this case) which does not get
41 // the implicit coercion and thus does not decay even with fallback to unit)
42 u32_try_from(1u32)?;
43 Ok(())
44}
45
46fn main() {}
tests/ui/never_type/fallback_change/try-block-never-type-fallback.e2021.stderr created+20
......@@ -0,0 +1,20 @@
1error[E0277]: the trait bound `!: From<()>` is not satisfied
2 --> $DIR/try-block-never-type-fallback.rs:20:9
3 |
4LL | bar(try { x? });
5 | --- ^^^^^^^^^^ the trait `From<()>` is not implemented for `!`
6 | |
7 | required by a bound introduced by this call
8 |
9 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
10 = help: you might have intended to use the type `()` here instead
11 = note: required for `()` to implement `Into<!>`
12note: required by a bound in `bar`
13 --> $DIR/try-block-never-type-fallback.rs:15:23
14 |
15LL | fn bar(_: Result<impl Into<!>, u32>) {
16 | ^^^^^^^ required by this bound in `bar`
17
18error: aborting due to 1 previous error
19
20For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/fallback_change/try-block-never-type-fallback.rs created+25
......@@ -0,0 +1,25 @@
1//@ revisions: e2021 e2024
2//@[e2021] edition: 2021
3//@[e2024] edition: 2024
4//@[e2024] check-pass
5
6// Issue #125364: Bad interaction between never_type, try_blocks, and From/Into
7//
8// In edition 2021, the never type in try blocks falls back to (),
9// causing a type error (since (): Into<!> does not hold).
10// In edition 2024, it falls back to !, allowing the code to compile correctly.
11
12#![feature(never_type)]
13#![feature(try_blocks)]
14
15fn bar(_: Result<impl Into<!>, u32>) {
16 unimplemented!()
17}
18
19fn foo(x: Result<!, u32>) {
20 bar(try { x? });
21 //[e2021]~^ ERROR the trait bound `!: From<()>` is not satisfied
22}
23
24fn main() {
25}
tests/ui/never_type/field-access-never-type-13847.rs deleted-5
......@@ -1,5 +0,0 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/13847
2
3fn main() {
4 return.is_failure //~ ERROR no field `is_failure` on type `!`
5}
tests/ui/never_type/field-access-never-type-13847.stderr deleted-9
......@@ -1,9 +0,0 @@
1error[E0609]: no field `is_failure` on type `!`
2 --> $DIR/field-access-never-type-13847.rs:4:12
3 |
4LL | return.is_failure
5 | ^^^^^^^^^^ unknown field
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0609`.
tests/ui/never_type/from_infer_breaking_with_unit_fallback.rs deleted-29
......@@ -1,29 +0,0 @@
1// issue: rust-lang/rust#66757
2//
3// This is a *minimization* of the issue.
4// Note that the original version with the `?` does not fail anymore even with fallback to unit,
5// see `tests/ui/never_type/question_mark_from_never.rs`.
6//
7//@ revisions: unit never
8//@[never] check-pass
9#![allow(internal_features)]
10#![feature(rustc_attrs, never_type)]
11#![cfg_attr(unit, rustc_never_type_options(fallback = "unit"))]
12#![cfg_attr(never, rustc_never_type_options(fallback = "never"))]
13
14struct E;
15
16impl From<!> for E {
17 fn from(_: !) -> E {
18 E
19 }
20}
21
22#[allow(unreachable_code)]
23fn foo(never: !) {
24 <E as From<!>>::from(never); // Ok
25 <E as From<_>>::from(never); // Should the inference fail?
26 //[unit]~^ error: the trait bound `E: From<()>` is not satisfied
27}
28
29fn main() {}
tests/ui/never_type/from_infer_breaking_with_unit_fallback.unit.stderr deleted-17
......@@ -1,17 +0,0 @@
1error[E0277]: the trait bound `E: From<()>` is not satisfied
2 --> $DIR/from_infer_breaking_with_unit_fallback.rs:25:6
3 |
4LL | <E as From<_>>::from(never); // Should the inference fail?
5 | ^ unsatisfied trait bound
6 |
7help: the trait `From<()>` is not implemented for `E`
8 but trait `From<!>` is implemented for it
9 --> $DIR/from_infer_breaking_with_unit_fallback.rs:16:1
10 |
11LL | impl From<!> for E {
12 | ^^^^^^^^^^^^^^^^^^
13 = help: for that trait implementation, expected `!`, found `()`
14
15error: aborting due to 1 previous error
16
17For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/impl-for-never.rs deleted-29
......@@ -1,29 +0,0 @@
1// Test that we can call static methods on ! both directly and when it appears in a generic
2//
3//@ run-pass
4//@ check-run-results
5
6#![feature(never_type)]
7
8
9trait StringifyType {
10 fn stringify_type() -> &'static str;
11}
12
13impl StringifyType for ! {
14 fn stringify_type() -> &'static str {
15 "!"
16 }
17}
18
19fn maybe_stringify<T: StringifyType>(opt: Option<T>) -> &'static str {
20 match opt {
21 Some(_) => T::stringify_type(),
22 None => "none",
23 }
24}
25
26fn main() {
27 println!("! is {}", <!>::stringify_type());
28 println!("None is {}", maybe_stringify(None::<!>));
29}
tests/ui/never_type/impl-for-never.run.stdout deleted-2
......@@ -1,2 +0,0 @@
1! is !
2None is none
tests/ui/never_type/issue-10176.rs deleted-9
......@@ -1,9 +0,0 @@
1fn f() -> isize { //~ NOTE expected `isize` because of return type
2 (return 1, return 2)
3//~^ ERROR mismatched types
4//~| NOTE expected type `isize`
5//~| NOTE found tuple `(!, !)`
6//~| NOTE expected `isize`, found `(!, !)`
7}
8
9fn main() {}
tests/ui/never_type/issue-10176.stderr deleted-14
......@@ -1,14 +0,0 @@
1error[E0308]: mismatched types
2 --> $DIR/issue-10176.rs:2:5
3 |
4LL | fn f() -> isize {
5 | ----- expected `isize` because of return type
6LL | (return 1, return 2)
7 | ^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `(!, !)`
8 |
9 = note: expected type `isize`
10 found tuple `(!, !)`
11
12error: aborting due to 1 previous error
13
14For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/issue-13352.rs deleted-9
......@@ -1,9 +0,0 @@
1fn foo(_: Box<dyn FnMut()>) {}
2
3fn main() {
4 foo(loop {
5 std::process::exit(0);
6 });
7 2_usize + (loop {});
8 //~^ ERROR E0277
9}
tests/ui/never_type/issue-13352.stderr deleted-28
......@@ -1,28 +0,0 @@
1error[E0277]: cannot add `()` to `usize`
2 --> $DIR/issue-13352.rs:7:13
3 |
4LL | 2_usize + (loop {});
5 | ^ no implementation for `usize + ()`
6 |
7 = help: the trait `Add<()>` is not implemented for `usize`
8help: the following other types implement trait `Add<Rhs>`
9 --> $SRC_DIR/core/src/ops/arith.rs:LL:COL
10 |
11 = note: `usize` implements `Add`
12 ::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
13 |
14 = note: in this macro invocation
15 --> $SRC_DIR/core/src/internal_macros.rs:LL:COL
16 |
17 = note: `&usize` implements `Add<usize>`
18 ::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
19 |
20 = note: `usize` implements `Add<&usize>`
21 ::: $SRC_DIR/core/src/internal_macros.rs:LL:COL
22 |
23 = note: `&usize` implements `Add`
24 = note: this error originates in the macro `add_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
25
26error: aborting due to 1 previous error
27
28For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/issue-2149.rs deleted-15
......@@ -1,15 +0,0 @@
1trait VecMonad<A> {
2 fn bind<B, F>(&self, f: F) where F: FnMut(A) -> Vec<B>;
3}
4
5impl<A> VecMonad<A> for Vec<A> {
6 fn bind<B, F>(&self, mut f: F) where F: FnMut(A) -> Vec<B> {
7 let mut r = panic!();
8 for elt in self { r = r + f(*elt); }
9 //~^ ERROR E0277
10 }
11}
12fn main() {
13 ["hi"].bind(|x| [x] );
14 //~^ ERROR no method named `bind` found
15}
tests/ui/never_type/issue-2149.stderr deleted-25
......@@ -1,25 +0,0 @@
1error[E0277]: cannot add `Vec<B>` to `()`
2 --> $DIR/issue-2149.rs:8:33
3 |
4LL | for elt in self { r = r + f(*elt); }
5 | ^ no implementation for `() + Vec<B>`
6 |
7 = help: the trait `Add<Vec<B>>` is not implemented for `()`
8
9error[E0599]: no method named `bind` found for array `[&str; 1]` in the current scope
10 --> $DIR/issue-2149.rs:13:12
11 |
12LL | ["hi"].bind(|x| [x] );
13 | ^^^^ method not found in `[&str; 1]`
14 |
15 = help: items from traits can only be used if the trait is implemented and in scope
16note: `VecMonad` defines an item `bind`, perhaps you need to implement it
17 --> $DIR/issue-2149.rs:1:1
18 |
19LL | trait VecMonad<A> {
20 | ^^^^^^^^^^^^^^^^^
21
22error: aborting due to 2 previous errors
23
24Some errors have detailed explanations: E0277, E0599.
25For more information about an error, try `rustc --explain E0277`.
tests/ui/never_type/issue-44402.rs deleted-34
......@@ -1,34 +0,0 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/44402>
2//
3// Previously inhabitedness check was handling cycles incorrectly causing this
4// to not compile.
5//
6//@ check-pass
7
8#![allow(dead_code)]
9#![feature(never_type)]
10#![feature(exhaustive_patterns)]
11
12struct Foo {
13 field1: !,
14 field2: Option<&'static Bar>,
15}
16
17struct Bar {
18 field1: &'static Foo
19}
20
21fn test_a() {
22 let x: Option<Foo> = None;
23 match x { None => () }
24}
25
26fn test_b() {
27 let x: Option<Bar> = None;
28 match x {
29 Some(_) => (),
30 None => ()
31 }
32}
33
34fn main() {}
tests/ui/never_type/issue-51506.rs deleted-43
......@@ -1,43 +0,0 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/51506>
2
3#![feature(never_type, specialization)]
4#![allow(incomplete_features)]
5
6use std::iter::{self, Empty};
7
8trait Trait {
9 type Out: Iterator<Item = u32>;
10
11 fn f(&self) -> Option<Self::Out>;
12}
13
14impl<T> Trait for T {
15 default type Out = !; //~ ERROR: `!` is not an iterator
16
17 default fn f(&self) -> Option<Self::Out> {
18 None
19 }
20}
21
22struct X;
23
24impl Trait for X {
25 type Out = Empty<u32>;
26
27 fn f(&self) -> Option<Self::Out> {
28 Some(iter::empty())
29 }
30}
31
32fn f<T: Trait>(a: T) {
33 if let Some(iter) = a.f() {
34 println!("Some");
35 for x in iter {
36 println!("x = {}", x);
37 }
38 }
39}
40
41pub fn main() {
42 f(10);
43}
tests/ui/never_type/issue-51506.stderr deleted-16
......@@ -1,16 +0,0 @@
1error[E0277]: `!` is not an iterator
2 --> $DIR/issue-51506.rs:15:24
3 |
4LL | default type Out = !;
5 | ^ `!` is not an iterator
6 |
7 = help: the trait `Iterator` is not implemented for `!`
8note: required by a bound in `Trait::Out`
9 --> $DIR/issue-51506.rs:9:15
10 |
11LL | type Out: Iterator<Item = u32>;
12 | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait::Out`
13
14error: aborting due to 1 previous error
15
16For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/issue-52443.rs deleted-12
......@@ -1,12 +0,0 @@
1fn main() {
2 [(); & { loop { continue } } ]; //~ ERROR mismatched types
3
4 [(); loop { break }]; //~ ERROR mismatched types
5
6 [(); {while true {break}; 0}];
7 //~^ WARN denote infinite loops with
8
9 [(); { for _ in 0usize.. {}; 0}];
10 //~^ ERROR `std::ops::RangeFrom<usize>: const Iterator` is not satisfied
11 //~| ERROR `std::ops::RangeFrom<usize>: const Iterator` is not satisfied
12}
tests/ui/never_type/issue-52443.stderr deleted-56
......@@ -1,56 +0,0 @@
1warning: denote infinite loops with `loop { ... }`
2 --> $DIR/issue-52443.rs:6:11
3 |
4LL | [(); {while true {break}; 0}];
5 | ^^^^^^^^^^ help: use `loop`
6 |
7 = note: `#[warn(while_true)]` on by default
8
9error[E0308]: mismatched types
10 --> $DIR/issue-52443.rs:2:10
11 |
12LL | [(); & { loop { continue } } ];
13 | ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
14 |
15 = note: expected type `usize`
16 found reference `&_`
17help: consider removing the borrow
18 |
19LL - [(); & { loop { continue } } ];
20LL + [(); { loop { continue } } ];
21 |
22
23error[E0308]: mismatched types
24 --> $DIR/issue-52443.rs:4:17
25 |
26LL | [(); loop { break }];
27 | ^^^^^ expected `usize`, found `()`
28 |
29help: give the `break` a value of the expected type
30 |
31LL | [(); loop { break 42 }];
32 | ++
33
34error[E0277]: the trait bound `std::ops::RangeFrom<usize>: const Iterator` is not satisfied
35 --> $DIR/issue-52443.rs:9:21
36 |
37LL | [(); { for _ in 0usize.. {}; 0}];
38 | ^^^^^^^^ required by a bound introduced by this call
39 |
40note: trait `Iterator` is implemented but not `const`
41 --> $SRC_DIR/core/src/iter/range.rs:LL:COL
42 = note: required for `std::ops::RangeFrom<usize>` to implement `const IntoIterator`
43
44error[E0277]: the trait bound `std::ops::RangeFrom<usize>: const Iterator` is not satisfied
45 --> $DIR/issue-52443.rs:9:21
46 |
47LL | [(); { for _ in 0usize.. {}; 0}];
48 | ^^^^^^^^
49 |
50note: trait `Iterator` is implemented but not `const`
51 --> $SRC_DIR/core/src/iter/range.rs:LL:COL
52
53error: aborting due to 4 previous errors; 1 warning emitted
54
55Some errors have detailed explanations: E0277, E0308.
56For more information about an error, try `rustc --explain E0277`.
tests/ui/never_type/issue-5500-1.rs deleted-16
......@@ -1,16 +0,0 @@
1//@ edition:2015..2021
2// MIR doesn't generate an error because the assignment isn't reachable. This
3// is OK because the test is here to check that the compiler doesn't ICE (cf.
4// #5500).
5
6//@ check-pass
7
8struct TrieMapIterator<'a> {
9 node: &'a usize
10}
11
12fn main() {
13 let a = 5;
14 let _iter = TrieMapIterator{node: &a};
15 _iter.node = &panic!()
16}
tests/ui/never_type/issue-96335.rs deleted-5
......@@ -1,5 +0,0 @@
1fn main() {
2 0.....{loop{}1};
3 //~^ ERROR unexpected token
4 //~| ERROR mismatched types
5}
tests/ui/never_type/issue-96335.stderr deleted-34
......@@ -1,34 +0,0 @@
1error: unexpected token: `...`
2 --> $DIR/issue-96335.rs:2:6
3 |
4LL | 0.....{loop{}1};
5 | ^^^
6 |
7help: use `..` for an exclusive range
8 |
9LL - 0.....{loop{}1};
10LL + 0....{loop{}1};
11 |
12help: or `..=` for an inclusive range
13 |
14LL - 0.....{loop{}1};
15LL + 0..=..{loop{}1};
16 |
17
18error[E0308]: mismatched types
19 --> $DIR/issue-96335.rs:2:9
20 |
21LL | 0.....{loop{}1};
22 | ----^^^^^^^^^^^
23 | | |
24 | | expected integer, found `RangeTo<{integer}>`
25 | arguments to this function are incorrect
26 |
27 = note: expected type `{integer}`
28 found struct `RangeTo<{integer}>`
29note: associated function defined here
30 --> $SRC_DIR/core/src/ops/range.rs:LL:COL
31
32error: aborting due to 2 previous errors
33
34For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/lint-breaking-2024-assign-underscore.fixed deleted-15
......@@ -1,15 +0,0 @@
1//@ run-rustfix
2#![allow(unused)]
3
4fn foo<T: Default>() -> Result<T, ()> {
5 Err(())
6}
7
8fn test() -> Result<(), ()> {
9 //~^ ERROR this function depends on never type fallback being `()`
10 //~| WARN this was previously accepted by the compiler but is being phased out
11 _ = foo::<()>()?;
12 Ok(())
13}
14
15fn main() {}
tests/ui/never_type/lint-breaking-2024-assign-underscore.rs deleted-15
......@@ -1,15 +0,0 @@
1//@ run-rustfix
2#![allow(unused)]
3
4fn foo<T: Default>() -> Result<T, ()> {
5 Err(())
6}
7
8fn test() -> Result<(), ()> {
9 //~^ ERROR this function depends on never type fallback being `()`
10 //~| WARN this was previously accepted by the compiler but is being phased out
11 _ = foo()?;
12 Ok(())
13}
14
15fn main() {}
tests/ui/never_type/lint-breaking-2024-assign-underscore.stderr deleted-43
......@@ -1,43 +0,0 @@
1error: this function depends on never type fallback being `()`
2 --> $DIR/lint-breaking-2024-assign-underscore.rs:8:1
3 |
4LL | fn test() -> Result<(), ()> {
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 |
7 = help: specify the types explicitly
8note: in edition 2024, the requirement `!: Default` will fail
9 --> $DIR/lint-breaking-2024-assign-underscore.rs:11:9
10 |
11LL | _ = foo()?;
12 | ^^^^^
13 = 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!
14 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
15 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
16help: use `()` annotations to avoid fallback changes
17 |
18LL | _ = foo::<()>()?;
19 | ++++++
20
21error: aborting due to 1 previous error
22
23Future incompatibility report: Future breakage diagnostic:
24error: this function depends on never type fallback being `()`
25 --> $DIR/lint-breaking-2024-assign-underscore.rs:8:1
26 |
27LL | fn test() -> Result<(), ()> {
28 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
29 |
30 = help: specify the types explicitly
31note: in edition 2024, the requirement `!: Default` will fail
32 --> $DIR/lint-breaking-2024-assign-underscore.rs:11:9
33 |
34LL | _ = foo()?;
35 | ^^^^^
36 = 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!
37 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
38 = note: `#[deny(dependency_on_unit_never_type_fallback)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
39help: use `()` annotations to avoid fallback changes
40 |
41LL | _ = foo::<()>()?;
42 | ++++++
43
tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2015.stderr deleted-287
......@@ -1,287 +0,0 @@
1error: never type fallback affects this call to an `unsafe` function
2 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
3 |
4LL | unsafe { mem::zeroed() }
5 | ^^^^^^^^^^^^^
6 |
7 = help: specify the type explicitly
8 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
9 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
10 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
11help: use `()` annotations to avoid fallback changes
12 |
13LL | unsafe { mem::zeroed::<()>() }
14 | ++++++
15
16error: never type fallback affects this call to an `unsafe` function
17 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13
18 |
19LL | core::mem::transmute(Zst)
20 | ^^^^^^^^^^^^^^^^^^^^^^^^^
21 |
22 = help: specify the type explicitly
23 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
24 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
25help: use `()` annotations to avoid fallback changes
26 |
27LL | core::mem::transmute::<_, ()>(Zst)
28 | +++++++++
29
30error: never type fallback affects this union access
31 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18
32 |
33LL | unsafe { Union { a: () }.b }
34 | ^^^^^^^^^^^^^^^^^
35 |
36 = help: specify the type explicitly
37 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
38 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
39
40error: never type fallback affects this raw pointer dereference
41 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18
42 |
43LL | unsafe { *ptr::from_ref(&()).cast() }
44 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
45 |
46 = help: specify the type explicitly
47 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
48 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
49help: use `()` annotations to avoid fallback changes
50 |
51LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
52 | ++++++
53
54error: never type fallback affects this call to an `unsafe` function
55 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18
56 |
57LL | unsafe { internally_create(x) }
58 | ^^^^^^^^^^^^^^^^^^^^
59 |
60 = help: specify the type explicitly
61 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
62 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
63help: use `()` annotations to avoid fallback changes
64 |
65LL | unsafe { internally_create::<()>(x) }
66 | ++++++
67
68error: never type fallback affects this call to an `unsafe` function
69 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18
70 |
71LL | unsafe { zeroed() }
72 | ^^^^^^^^
73 |
74 = help: specify the type explicitly
75 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
76 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
77help: use `()` annotations to avoid fallback changes
78 |
79LL | let zeroed = mem::zeroed::<()>;
80 | ++++++
81
82error: never type fallback affects this `unsafe` function
83 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22
84 |
85LL | let zeroed = mem::zeroed;
86 | ^^^^^^^^^^^
87 |
88 = help: specify the type explicitly
89 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
90 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
91help: use `()` annotations to avoid fallback changes
92 |
93LL | let zeroed = mem::zeroed::<()>;
94 | ++++++
95
96error: never type fallback affects this `unsafe` function
97 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17
98 |
99LL | let f = internally_create;
100 | ^^^^^^^^^^^^^^^^^
101 |
102 = help: specify the type explicitly
103 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
104 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
105help: use `()` annotations to avoid fallback changes
106 |
107LL | let f = internally_create::<()>;
108 | ++++++
109
110error: never type fallback affects this call to an `unsafe` method
111 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13
112 |
113LL | S(marker::PhantomData).create_out_of_thin_air()
114 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115 |
116 = help: specify the type explicitly
117 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
118 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
119
120error: never type fallback affects this call to an `unsafe` function
121 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19
122 |
123LL | match send_message::<_ /* ?0 */>() {
124 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125...
126LL | msg_send!();
127 | ----------- in this macro invocation
128 |
129 = help: specify the type explicitly
130 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
131 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
132 = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
133
134error: aborting due to 10 previous errors
135
136Future incompatibility report: Future breakage diagnostic:
137error: never type fallback affects this call to an `unsafe` function
138 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
139 |
140LL | unsafe { mem::zeroed() }
141 | ^^^^^^^^^^^^^
142 |
143 = help: specify the type explicitly
144 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
145 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
146 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
147help: use `()` annotations to avoid fallback changes
148 |
149LL | unsafe { mem::zeroed::<()>() }
150 | ++++++
151
152Future breakage diagnostic:
153error: never type fallback affects this call to an `unsafe` function
154 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13
155 |
156LL | core::mem::transmute(Zst)
157 | ^^^^^^^^^^^^^^^^^^^^^^^^^
158 |
159 = help: specify the type explicitly
160 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
161 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
162 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
163help: use `()` annotations to avoid fallback changes
164 |
165LL | core::mem::transmute::<_, ()>(Zst)
166 | +++++++++
167
168Future breakage diagnostic:
169error: never type fallback affects this union access
170 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18
171 |
172LL | unsafe { Union { a: () }.b }
173 | ^^^^^^^^^^^^^^^^^
174 |
175 = help: specify the type explicitly
176 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
177 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
178 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
179
180Future breakage diagnostic:
181error: never type fallback affects this raw pointer dereference
182 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18
183 |
184LL | unsafe { *ptr::from_ref(&()).cast() }
185 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
186 |
187 = help: specify the type explicitly
188 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
189 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
190 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
191help: use `()` annotations to avoid fallback changes
192 |
193LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
194 | ++++++
195
196Future breakage diagnostic:
197error: never type fallback affects this call to an `unsafe` function
198 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18
199 |
200LL | unsafe { internally_create(x) }
201 | ^^^^^^^^^^^^^^^^^^^^
202 |
203 = help: specify the type explicitly
204 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
205 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
206 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
207help: use `()` annotations to avoid fallback changes
208 |
209LL | unsafe { internally_create::<()>(x) }
210 | ++++++
211
212Future breakage diagnostic:
213error: never type fallback affects this call to an `unsafe` function
214 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18
215 |
216LL | unsafe { zeroed() }
217 | ^^^^^^^^
218 |
219 = help: specify the type explicitly
220 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
221 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
222 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
223help: use `()` annotations to avoid fallback changes
224 |
225LL | let zeroed = mem::zeroed::<()>;
226 | ++++++
227
228Future breakage diagnostic:
229error: never type fallback affects this `unsafe` function
230 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22
231 |
232LL | let zeroed = mem::zeroed;
233 | ^^^^^^^^^^^
234 |
235 = help: specify the type explicitly
236 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
237 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
238 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
239help: use `()` annotations to avoid fallback changes
240 |
241LL | let zeroed = mem::zeroed::<()>;
242 | ++++++
243
244Future breakage diagnostic:
245error: never type fallback affects this `unsafe` function
246 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17
247 |
248LL | let f = internally_create;
249 | ^^^^^^^^^^^^^^^^^
250 |
251 = help: specify the type explicitly
252 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
253 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
254 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
255help: use `()` annotations to avoid fallback changes
256 |
257LL | let f = internally_create::<()>;
258 | ++++++
259
260Future breakage diagnostic:
261error: never type fallback affects this call to an `unsafe` method
262 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13
263 |
264LL | S(marker::PhantomData).create_out_of_thin_air()
265 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
266 |
267 = help: specify the type explicitly
268 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
269 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
270 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
271
272Future breakage diagnostic:
273error: never type fallback affects this call to an `unsafe` function
274 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19
275 |
276LL | match send_message::<_ /* ?0 */>() {
277 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
278...
279LL | msg_send!();
280 | ----------- in this macro invocation
281 |
282 = help: specify the type explicitly
283 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
284 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
285 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
286 = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
287
tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2024.stderr deleted-296
......@@ -1,296 +0,0 @@
1error: never type fallback affects this call to an `unsafe` function
2 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
3 |
4LL | unsafe { mem::zeroed() }
5 | ^^^^^^^^^^^^^
6 |
7 = help: specify the type explicitly
8 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
9 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
10 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
11help: use `()` annotations to avoid fallback changes
12 |
13LL | unsafe { mem::zeroed::<()>() }
14 | ++++++
15
16error: never type fallback affects this call to an `unsafe` function
17 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13
18 |
19LL | core::mem::transmute(Zst)
20 | ^^^^^^^^^^^^^^^^^^^^^^^^^
21 |
22 = help: specify the type explicitly
23 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
24 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
25help: use `()` annotations to avoid fallback changes
26 |
27LL | core::mem::transmute::<_, ()>(Zst)
28 | +++++++++
29
30error: never type fallback affects this union access
31 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18
32 |
33LL | unsafe { Union { a: () }.b }
34 | ^^^^^^^^^^^^^^^^^
35 |
36 = help: specify the type explicitly
37 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
38 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
39
40error: never type fallback affects this raw pointer dereference
41 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18
42 |
43LL | unsafe { *ptr::from_ref(&()).cast() }
44 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
45 |
46 = help: specify the type explicitly
47 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
48 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
49help: use `()` annotations to avoid fallback changes
50 |
51LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
52 | ++++++
53
54error: never type fallback affects this call to an `unsafe` function
55 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18
56 |
57LL | unsafe { internally_create(x) }
58 | ^^^^^^^^^^^^^^^^^^^^
59 |
60 = help: specify the type explicitly
61 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
62 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
63help: use `()` annotations to avoid fallback changes
64 |
65LL | unsafe { internally_create::<()>(x) }
66 | ++++++
67
68error: never type fallback affects this call to an `unsafe` function
69 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18
70 |
71LL | unsafe { zeroed() }
72 | ^^^^^^^^
73 |
74 = help: specify the type explicitly
75 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
76 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
77help: use `()` annotations to avoid fallback changes
78 |
79LL | let zeroed = mem::zeroed::<()>;
80 | ++++++
81
82error: never type fallback affects this `unsafe` function
83 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22
84 |
85LL | let zeroed = mem::zeroed;
86 | ^^^^^^^^^^^
87 |
88 = help: specify the type explicitly
89 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
90 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
91help: use `()` annotations to avoid fallback changes
92 |
93LL | let zeroed = mem::zeroed::<()>;
94 | ++++++
95
96error: never type fallback affects this `unsafe` function
97 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17
98 |
99LL | let f = internally_create;
100 | ^^^^^^^^^^^^^^^^^
101 |
102 = help: specify the type explicitly
103 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
104 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
105help: use `()` annotations to avoid fallback changes
106 |
107LL | let f = internally_create::<()>;
108 | ++++++
109
110error: never type fallback affects this call to an `unsafe` method
111 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13
112 |
113LL | S(marker::PhantomData).create_out_of_thin_air()
114 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115 |
116 = help: specify the type explicitly
117 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
118 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
119
120error: never type fallback affects this call to an `unsafe` function
121 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19
122 |
123LL | match send_message::<_ /* ?0 */>() {
124 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125...
126LL | msg_send!();
127 | ----------- in this macro invocation
128 |
129 = help: specify the type explicitly
130 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
131 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
132 = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
133
134warning: the type `!` does not permit zero-initialization
135 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
136 |
137LL | unsafe { mem::zeroed() }
138 | ^^^^^^^^^^^^^ this code causes undefined behavior when executed
139 |
140 = note: the `!` type has no valid value
141 = note: `#[warn(invalid_value)]` on by default
142
143error: aborting due to 10 previous errors; 1 warning emitted
144
145Future incompatibility report: Future breakage diagnostic:
146error: never type fallback affects this call to an `unsafe` function
147 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18
148 |
149LL | unsafe { mem::zeroed() }
150 | ^^^^^^^^^^^^^
151 |
152 = help: specify the type explicitly
153 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
154 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
155 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
156help: use `()` annotations to avoid fallback changes
157 |
158LL | unsafe { mem::zeroed::<()>() }
159 | ++++++
160
161Future breakage diagnostic:
162error: never type fallback affects this call to an `unsafe` function
163 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13
164 |
165LL | core::mem::transmute(Zst)
166 | ^^^^^^^^^^^^^^^^^^^^^^^^^
167 |
168 = help: specify the type explicitly
169 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
170 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
171 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
172help: use `()` annotations to avoid fallback changes
173 |
174LL | core::mem::transmute::<_, ()>(Zst)
175 | +++++++++
176
177Future breakage diagnostic:
178error: never type fallback affects this union access
179 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18
180 |
181LL | unsafe { Union { a: () }.b }
182 | ^^^^^^^^^^^^^^^^^
183 |
184 = help: specify the type explicitly
185 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
186 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
187 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
188
189Future breakage diagnostic:
190error: never type fallback affects this raw pointer dereference
191 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18
192 |
193LL | unsafe { *ptr::from_ref(&()).cast() }
194 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
195 |
196 = help: specify the type explicitly
197 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
198 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
199 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
200help: use `()` annotations to avoid fallback changes
201 |
202LL | unsafe { *ptr::from_ref(&()).cast::<()>() }
203 | ++++++
204
205Future breakage diagnostic:
206error: never type fallback affects this call to an `unsafe` function
207 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18
208 |
209LL | unsafe { internally_create(x) }
210 | ^^^^^^^^^^^^^^^^^^^^
211 |
212 = help: specify the type explicitly
213 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
214 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
215 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
216help: use `()` annotations to avoid fallback changes
217 |
218LL | unsafe { internally_create::<()>(x) }
219 | ++++++
220
221Future breakage diagnostic:
222error: never type fallback affects this call to an `unsafe` function
223 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18
224 |
225LL | unsafe { zeroed() }
226 | ^^^^^^^^
227 |
228 = help: specify the type explicitly
229 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
230 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
231 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
232help: use `()` annotations to avoid fallback changes
233 |
234LL | let zeroed = mem::zeroed::<()>;
235 | ++++++
236
237Future breakage diagnostic:
238error: never type fallback affects this `unsafe` function
239 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22
240 |
241LL | let zeroed = mem::zeroed;
242 | ^^^^^^^^^^^
243 |
244 = help: specify the type explicitly
245 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
246 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
247 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
248help: use `()` annotations to avoid fallback changes
249 |
250LL | let zeroed = mem::zeroed::<()>;
251 | ++++++
252
253Future breakage diagnostic:
254error: never type fallback affects this `unsafe` function
255 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17
256 |
257LL | let f = internally_create;
258 | ^^^^^^^^^^^^^^^^^
259 |
260 = help: specify the type explicitly
261 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
262 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
263 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
264help: use `()` annotations to avoid fallback changes
265 |
266LL | let f = internally_create::<()>;
267 | ++++++
268
269Future breakage diagnostic:
270error: never type fallback affects this call to an `unsafe` method
271 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13
272 |
273LL | S(marker::PhantomData).create_out_of_thin_air()
274 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275 |
276 = help: specify the type explicitly
277 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
278 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
279 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
280
281Future breakage diagnostic:
282error: never type fallback affects this call to an `unsafe` function
283 --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19
284 |
285LL | match send_message::<_ /* ?0 */>() {
286 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287...
288LL | msg_send!();
289 | ----------- in this macro invocation
290 |
291 = help: specify the type explicitly
292 = warning: this changes meaning in Rust 2024 and in a future release in all editions!
293 = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/never-type-fallback.html>
294 = note: `#[deny(never_type_fallback_flowing_into_unsafe)]` (part of `#[deny(rust_2024_compatibility)]`) on by default
295 = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
296
tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.rs deleted-168
......@@ -1,168 +0,0 @@
1//@ revisions: e2015 e2024
2//@[e2024] edition:2024
3
4use std::{marker, mem, ptr};
5
6fn main() {}
7
8fn _zero() {
9 if false {
10 unsafe { mem::zeroed() }
11 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
12 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
13 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
14 //[e2024]~| warn: the type `!` does not permit zero-initialization
15 } else {
16 return;
17 };
18
19 // no ; -> type is inferred without fallback
20 if true { unsafe { mem::zeroed() } } else { return }
21}
22
23fn _trans() {
24 if false {
25 unsafe {
26 struct Zst;
27 core::mem::transmute(Zst)
28 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
29 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
30 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
31 }
32 } else {
33 return;
34 };
35}
36
37fn _union() {
38 if false {
39 union Union<T: Copy> {
40 a: (),
41 b: T,
42 }
43
44 unsafe { Union { a: () }.b }
45 //[e2015]~^ error: never type fallback affects this union access
46 //[e2024]~^^ error: never type fallback affects this union access
47 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
48 } else {
49 return;
50 };
51}
52
53fn _deref() {
54 if false {
55 unsafe { *ptr::from_ref(&()).cast() }
56 //[e2015]~^ error: never type fallback affects this raw pointer dereference
57 //[e2024]~^^ error: never type fallback affects this raw pointer dereference
58 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
59 } else {
60 return;
61 };
62}
63
64fn _only_generics() {
65 if false {
66 unsafe fn internally_create<T>(_: Option<T>) {
67 unsafe {
68 let _ = mem::zeroed::<T>();
69 }
70 }
71
72 // We need the option (and unwrap later) to call a function in a way,
73 // which makes it affected by the fallback, but without having it return anything
74 let x = None;
75
76 unsafe { internally_create(x) }
77 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
78 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
79 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
80
81 x.unwrap()
82 } else {
83 return;
84 };
85}
86
87fn _stored_function() {
88 if false {
89 let zeroed = mem::zeroed;
90 //[e2015]~^ error: never type fallback affects this `unsafe` function
91 //[e2024]~^^ error: never type fallback affects this `unsafe` function
92 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
93
94 unsafe { zeroed() }
95 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
96 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
97 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
98 } else {
99 return;
100 };
101}
102
103fn _only_generics_stored_function() {
104 if false {
105 unsafe fn internally_create<T>(_: Option<T>) {
106 unsafe {
107 let _ = mem::zeroed::<T>();
108 }
109 }
110
111 let x = None;
112 let f = internally_create;
113 //[e2015]~^ error: never type fallback affects this `unsafe` function
114 //[e2024]~^^ error: never type fallback affects this `unsafe` function
115 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
116
117 unsafe { f(x) }
118
119 x.unwrap()
120 } else {
121 return;
122 };
123}
124
125fn _method() {
126 struct S<T>(marker::PhantomData<T>);
127
128 impl<T> S<T> {
129 #[allow(unused)] // FIXME: the unused lint is probably incorrect here
130 unsafe fn create_out_of_thin_air(&self) -> T {
131 todo!()
132 }
133 }
134
135 if false {
136 unsafe {
137 S(marker::PhantomData).create_out_of_thin_air()
138 //[e2015]~^ error: never type fallback affects this call to an `unsafe` method
139 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` method
140 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
141 }
142 } else {
143 return;
144 };
145}
146
147// Minimization of the famous `objc` crate issue
148fn _objc() {
149 pub unsafe fn send_message<R>() -> Result<R, ()> {
150 Ok(unsafe { core::mem::zeroed() })
151 }
152
153 macro_rules! msg_send {
154 () => {
155 match send_message::<_ /* ?0 */>() {
156 //[e2015]~^ error: never type fallback affects this call to an `unsafe` function
157 //[e2024]~^^ error: never type fallback affects this call to an `unsafe` function
158 //~| warn: this changes meaning in Rust 2024 and in a future release in all editions!
159 Ok(x) => x,
160 Err(_) => loop {},
161 }
162 };
163 }
164
165 unsafe {
166 msg_send!();
167 }
168}
tests/ui/never_type/never-assign-dead-code.rs deleted-13
......@@ -1,13 +0,0 @@
1// Test that an assignment of type ! makes the rest of the block dead code.
2//
3//@ check-pass
4
5#![feature(never_type)]
6#![expect(dropping_copy_types)]
7#![warn(unused)]
8
9fn main() {
10 let x: ! = panic!("aah"); //~ WARN unused
11 drop(x); //~ WARN unreachable
12 //~^ WARN unreachable
13}
tests/ui/never_type/never-assign-dead-code.stderr deleted-33
......@@ -1,33 +0,0 @@
1warning: unreachable statement
2 --> $DIR/never-assign-dead-code.rs:11:5
3 |
4LL | let x: ! = panic!("aah");
5 | ------------- any code following this expression is unreachable
6LL | drop(x);
7 | ^^^^^^^^ unreachable statement
8 |
9note: the lint level is defined here
10 --> $DIR/never-assign-dead-code.rs:7:9
11 |
12LL | #![warn(unused)]
13 | ^^^^^^
14 = note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`
15
16warning: unreachable call
17 --> $DIR/never-assign-dead-code.rs:11:5
18 |
19LL | drop(x);
20 | ^^^^ - any code following this expression is unreachable
21 | |
22 | unreachable call
23
24warning: unused variable: `x`
25 --> $DIR/never-assign-dead-code.rs:10:9
26 |
27LL | let x: ! = panic!("aah");
28 | ^ help: if this is intentional, prefix it with an underscore: `_x`
29 |
30 = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
31
32warning: 3 warnings emitted
33
tests/ui/never_type/never-assign-wrong-type.rs deleted-7
......@@ -1,7 +0,0 @@
1// Test that we can't use another type in place of !
2
3#![feature(never_type)]
4
5fn main() {
6 let x: ! = "hello"; //~ ERROR mismatched types
7}
tests/ui/never_type/never-assign-wrong-type.stderr deleted-14
......@@ -1,14 +0,0 @@
1error[E0308]: mismatched types
2 --> $DIR/never-assign-wrong-type.rs:6:16
3 |
4LL | let x: ! = "hello";
5 | - ^^^^^^^ expected `!`, found `&str`
6 | |
7 | expected due to this
8 |
9 = note: expected type `!`
10 found reference `&'static str`
11
12error: aborting due to 1 previous error
13
14For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/never-associated-type.rs deleted-23
......@@ -1,23 +0,0 @@
1// Test that we can use ! as an associated type.
2//
3//@ check-pass
4
5#![feature(never_type)]
6
7trait Foo {
8 type Wow;
9
10 fn smeg(&self) -> Self::Wow;
11}
12
13struct Blah;
14impl Foo for Blah {
15 type Wow = !;
16 fn smeg(&self) -> ! {
17 panic!("kapow!");
18 }
19}
20
21fn main() {
22 Blah.smeg();
23}
tests/ui/never_type/never-deref.rs deleted-5
......@@ -1,5 +0,0 @@
1//! regression test for https://github.com/rust-lang/rust/issues/17373
2fn main() {
3 *return //~ ERROR type `!` cannot be dereferenced
4 ;
5}
tests/ui/never_type/never-deref.stderr deleted-9
......@@ -1,9 +0,0 @@
1error[E0614]: type `!` cannot be dereferenced
2 --> $DIR/never-deref.rs:3:5
3 |
4LL | *return
5 | ^^^^^^^ can't be dereferenced
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0614`.
tests/ui/never_type/never-in-range-pat.rs deleted-16
......@@ -1,16 +0,0 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/133947>.
2//
3// Make sure we don't ICE when there's `!` in a range pattern.
4//
5// This shouldn't be allowed anyways, but we only deny it during MIR
6// building, so make sure we handle it semi-gracefully during typeck.
7
8#![feature(never_type)]
9
10fn main() {
11 let x: !;
12 match 1 {
13 0..x => {}
14 //~^ ERROR only `char` and numeric types are allowed in range patterns
15 }
16}
tests/ui/never_type/never-in-range-pat.stderr deleted-11
......@@ -1,11 +0,0 @@
1error[E0029]: only `char` and numeric types are allowed in range patterns
2 --> $DIR/never-in-range-pat.rs:13:12
3 |
4LL | 0..x => {}
5 | - ^ this is of type `!` but it should be `char` or numeric
6 | |
7 | this is of type `{integer}`
8
9error: aborting due to 1 previous error
10
11For more information about this error, try `rustc --explain E0029`.
tests/ui/never_type/never-pattern-as-closure-param-141592.rs deleted-24
......@@ -1,24 +0,0 @@
1#![feature(never_patterns)]
2#![allow(incomplete_features)]
3
4enum Never {}
5
6fn example(x: Never) -> [i32; 1] {
7 let ! = x;
8 [1]
9}
10
11fn function_param_never(!: Never) -> [i32; 1] {
12 [1]
13}
14
15fn generic_never<T>(!: T) -> [i32; 1] //~ ERROR mismatched types
16where
17 T: Copy,
18{
19 [1]
20}
21
22fn main() {
23 let _ = "12".lines().map(|!| [1]); //~ ERROR mismatched types
24}
tests/ui/never_type/never-pattern-as-closure-param-141592.stderr deleted-18
......@@ -1,18 +0,0 @@
1error: mismatched types
2 --> $DIR/never-pattern-as-closure-param-141592.rs:15:21
3 |
4LL | fn generic_never<T>(!: T) -> [i32; 1]
5 | ^ a never pattern must be used on an uninhabited type
6 |
7 = note: the matched value is of type `T`
8
9error: mismatched types
10 --> $DIR/never-pattern-as-closure-param-141592.rs:23:31
11 |
12LL | let _ = "12".lines().map(|!| [1]);
13 | ^ a never pattern must be used on an uninhabited type
14 |
15 = note: the matched value is of type `str`
16
17error: aborting due to 2 previous errors
18
tests/ui/never_type/never-result.rs deleted-21
......@@ -1,21 +0,0 @@
1// Test that `!` can be coerced to multiple different types after getting it
2// from pattern matching.
3//
4//@ run-pass
5
6#![feature(never_type)]
7#![expect(unused_variables)]
8#![expect(unreachable_code)]
9
10fn main() {
11 let x: Result<u32, !> = Ok(123);
12 match x {
13 Ok(z) => (),
14 Err(y) => {
15 let q: u32 = y;
16 let w: i32 = y;
17 let e: String = y;
18 y
19 }
20 }
21}
tests/ui/never_type/never-type-arg.rs deleted-17
......@@ -1,17 +0,0 @@
1// Test that we can use ! as an argument to a trait impl.
2//
3//@ check-pass
4
5#![feature(never_type)]
6
7struct Wub;
8
9impl PartialEq<!> for Wub {
10 fn eq(&self, other: &!) -> bool {
11 *other
12 }
13}
14
15fn main() {
16 let _ = Wub == panic!("oh no!");
17}
tests/ui/never_type/never-type-fallback-option.rs deleted-22
......@@ -1,22 +0,0 @@
1//@ run-pass
2
3#![allow(warnings)]
4
5//! Tests type inference fallback to `!` (never type) in `Option` context.
6//!
7//! Regression test for issues:
8//! - https://github.com/rust-lang/rust/issues/39808
9//! - https://github.com/rust-lang/rust/issues/39984
10//!
11//! Here the type of `c` is `Option<?T>`, where `?T` is unconstrained.
12//! Because there is data-flow from the `{ return; }` block, which
13//! diverges and hence has type `!`, into `c`, we will default `?T` to
14//! `!`, and hence this code compiles rather than failing and requiring
15//! a type annotation.
16
17fn main() {
18 let c = Some({
19 return;
20 });
21 c.unwrap();
22}
tests/ui/never_type/never-type-in-nested-fn-decl.rs deleted-7
......@@ -1,7 +0,0 @@
1//@ build-pass
2
3trait X<const N: i32> {}
4
5fn hello<T: X<{ fn hello() -> ! { loop {} } 1 }>>() {}
6
7fn main() {}
tests/ui/never_type/never-type-method-call-15207.rs deleted-8
......@@ -1,8 +0,0 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/15207
2
3fn main() {
4 loop {
5 break.push(1) //~ ERROR no method named `push` found for type `!`
6 ;
7 }
8}
tests/ui/never_type/never-type-method-call-15207.stderr deleted-9
......@@ -1,9 +0,0 @@
1error[E0599]: no method named `push` found for type `!` in the current scope
2 --> $DIR/never-type-method-call-15207.rs:5:15
3 |
4LL | break.push(1)
5 | ^^^^ method not found in `!`
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0599`.
tests/ui/never_type/never-type-rvalues.rs deleted-40
......@@ -1,40 +0,0 @@
1// Check that the never type can be used in various positions.
2//
3//@ run-pass
4
5#![feature(never_type)]
6#![allow(dead_code)]
7#![allow(path_statements)]
8#![allow(unreachable_patterns)]
9
10fn never_direct(x: !) {
11 x;
12}
13
14fn never_ref_pat(ref x: !) {
15 *x;
16}
17
18fn never_ref(x: &!) {
19 let &y = x;
20 y;
21}
22
23fn never_pointer(x: *const !) {
24 unsafe {
25 *x;
26 }
27}
28
29fn never_slice(x: &[!]) {
30 x[0];
31}
32
33fn never_match(x: Result<(), !>) {
34 match x {
35 Ok(_) => {},
36 Err(_) => {},
37 }
38}
39
40pub fn main() { }
tests/ui/never_type/never_coercions.rs deleted-12
......@@ -1,12 +0,0 @@
1//@ run-pass
2// Test that having something of type ! doesn't screw up type-checking and that it coerces to the
3// LUB type of the other match arms.
4
5fn main() {
6 let v: Vec<u32> = Vec::new();
7 match 0u32 {
8 0 => &v,
9 1 => return,
10 _ => &v[..],
11 };
12}
tests/ui/never_type/never_pattern/never-pattern-as-closure-param-141592.rs created+24
......@@ -0,0 +1,24 @@
1#![feature(never_patterns)]
2#![allow(incomplete_features)]
3
4enum Never {}
5
6fn example(x: Never) -> [i32; 1] {
7 let ! = x;
8 [1]
9}
10
11fn function_param_never(!: Never) -> [i32; 1] {
12 [1]
13}
14
15fn generic_never<T>(!: T) -> [i32; 1] //~ ERROR mismatched types
16where
17 T: Copy,
18{
19 [1]
20}
21
22fn main() {
23 let _ = "12".lines().map(|!| [1]); //~ ERROR mismatched types
24}
tests/ui/never_type/never_pattern/never-pattern-as-closure-param-141592.stderr created+18
......@@ -0,0 +1,18 @@
1error: mismatched types
2 --> $DIR/never-pattern-as-closure-param-141592.rs:15:21
3 |
4LL | fn generic_never<T>(!: T) -> [i32; 1]
5 | ^ a never pattern must be used on an uninhabited type
6 |
7 = note: the matched value is of type `T`
8
9error: mismatched types
10 --> $DIR/never-pattern-as-closure-param-141592.rs:23:31
11 |
12LL | let _ = "12".lines().map(|!| [1]);
13 | ^ a never pattern must be used on an uninhabited type
14 |
15 = note: the matched value is of type `str`
16
17error: aborting due to 2 previous errors
18
tests/ui/never_type/never_pattern/unused_trait_in_never_pattern_body.rs created+12
......@@ -0,0 +1,12 @@
1fn a() {
2 match 0 {
3 ! => || { //~ ERROR `!` patterns are experimental
4 //~^ ERROR a never pattern is always unreachable
5 //~^^ ERROR mismatched types
6 use std::ops::Add;
7 0.add(1)
8 },
9 }
10}
11
12fn main() {}
tests/ui/never_type/never_pattern/unused_trait_in_never_pattern_body.stderr created+36
......@@ -0,0 +1,36 @@
1error[E0658]: `!` patterns are experimental
2 --> $DIR/unused_trait_in_never_pattern_body.rs:3:9
3 |
4LL | ! => || {
5 | ^
6 |
7 = note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
8 = help: add `#![feature(never_patterns)]` to the crate attributes to enable
9 = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10
11error: a never pattern is always unreachable
12 --> $DIR/unused_trait_in_never_pattern_body.rs:3:14
13 |
14LL | ! => || {
15 | ______________^
16LL | |
17LL | |
18LL | | use std::ops::Add;
19LL | | 0.add(1)
20LL | | },
21 | | ^
22 | | |
23 | |_________this will never be executed
24 | help: remove this expression
25
26error: mismatched types
27 --> $DIR/unused_trait_in_never_pattern_body.rs:3:9
28 |
29LL | ! => || {
30 | ^ a never pattern must be used on an uninhabited type
31 |
32 = note: the matched value is of type `i32`
33
34error: aborting due to 3 previous errors
35
36For more information about this error, try `rustc --explain E0658`.
tests/ui/never_type/never_transmute_never.rs deleted-23
......@@ -1,23 +0,0 @@
1//@ check-pass
2
3#![feature(never_type)]
4#![allow(dead_code)]
5#![expect(unreachable_code)]
6#![expect(unused_variables)]
7
8struct Foo;
9
10pub fn f(x: !) -> ! {
11 x
12}
13
14pub fn ub() {
15 // This is completely undefined behaviour,
16 // but we still want to make sure it compiles.
17 let x: ! = unsafe {
18 std::mem::transmute::<Foo, !>(Foo)
19 };
20 f(x)
21}
22
23fn main() {}
tests/ui/never_type/question_mark_from_never.rs deleted-46
......@@ -1,46 +0,0 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/66757>.
2//
3// See also: `tests/ui/never_type/from_infer_breaking_with_unit_fallback.rs`.
4//
5//@ revisions: unit never
6//@ check-pass
7#![allow(internal_features)]
8#![feature(rustc_attrs, never_type)]
9#![cfg_attr(unit, rustc_never_type_options(fallback = "unit"))]
10#![cfg_attr(never, rustc_never_type_options(fallback = "never"))]
11
12type Infallible = !;
13
14struct E;
15
16impl From<Infallible> for E {
17 fn from(_: Infallible) -> E {
18 E
19 }
20}
21
22fn u32_try_from(x: u32) -> Result<u32, Infallible> {
23 Ok(x)
24}
25
26fn _f() -> Result<(), E> {
27 // In an old attempt to make `Infallible = !` this caused a problem.
28 //
29 // Because at the time the code desugared to
30 //
31 // match u32::try_from(1u32) {
32 // Ok(x) => x, Err(e) => return Err(E::from(e))
33 // }
34 //
35 // With `Infallible = !`, `e: !` but with fallback to `()`, `e` in `E::from(e)` decayed to `()`
36 // causing an error.
37 //
38 // This does not happen with `Infallible = !`.
39 // And also does not happen with the newer `?` desugaring that does not pass `e` by value.
40 // (instead we only pass `Result<!, Error>` (where `Error = !` in this case) which does not get
41 // the implicit coercion and thus does not decay even with fallback to unit)
42 u32_try_from(1u32)?;
43 Ok(())
44}
45
46fn main() {}
tests/ui/never_type/regress/address-of-never.rs created+15
......@@ -0,0 +1,15 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/5500>,
2// check that you can take a reference to the never type.
3//
4//@ edition:2015..2021
5//@ check-pass
6
7struct TrieMapIterator<'a> {
8 node: &'a usize
9}
10
11fn main() {
12 let a = 5;
13 let _iter = TrieMapIterator{node: &a};
14 _iter.node = &panic!()
15}
tests/ui/never_type/regress/divergent-block-with-tail.rs created+20
......@@ -0,0 +1,20 @@
1// Rust briefly used to allow blocks with divergent statements to type check as `!`, even if they
2// had a tail expression. This led to a number of regressions (because type information no longer
3// flowed from the tail expression) and was quickly reverted.i
4//
5// See <https://github.com/rust-lang/rust/pull/39485>,
6// <https://github.com/rust-lang/rust/pull/40636>,
7// <https://github.com/rust-lang/rust/pull/39808>.
8//
9//@ edition:2015..2021
10
11fn g() {
12 &panic!() //~ ERROR mismatched types
13}
14
15// This used to ICE, see <https://github.com/rust-lang/rust/issues/10176>
16fn f() -> isize {
17 (return 1, return 2) //~ ERROR mismatched types
18}
19
20fn main() {}
tests/ui/never_type/regress/divergent-block-with-tail.stderr created+32
......@@ -0,0 +1,32 @@
1error[E0308]: mismatched types
2 --> $DIR/divergent-block-with-tail.rs:12:5
3 |
4LL | &panic!()
5 | ^^^^^^^^^ expected `()`, found `&_`
6 |
7 = note: expected unit type `()`
8 found reference `&_`
9help: a return type might be missing here
10 |
11LL | fn g() -> _ {
12 | ++++
13help: consider removing the borrow
14 |
15LL - &panic!()
16LL + panic!()
17 |
18
19error[E0308]: mismatched types
20 --> $DIR/divergent-block-with-tail.rs:17:5
21 |
22LL | fn f() -> isize {
23 | ----- expected `isize` because of return type
24LL | (return 1, return 2)
25 | ^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `(!, !)`
26 |
27 = note: expected type `isize`
28 found tuple `(!, !)`
29
30error: aborting due to 2 previous errors
31
32For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/regress/eq-never-types.rs created+12
......@@ -0,0 +1,12 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/120600>
2//
3//@ edition: 2024
4//@ check-pass
5
6#![feature(never_type)]
7
8fn ice(a: !) {
9 a == a;
10}
11
12fn main() {}
tests/ui/never_type/regress/field-access-never-type-13847.rs created+5
......@@ -0,0 +1,5 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/13847
2
3fn main() {
4 return.is_failure //~ ERROR no field `is_failure` on type `!`
5}
tests/ui/never_type/regress/field-access-never-type-13847.stderr created+9
......@@ -0,0 +1,9 @@
1error[E0609]: no field `is_failure` on type `!`
2 --> $DIR/field-access-never-type-13847.rs:4:12
3 |
4LL | return.is_failure
5 | ^^^^^^^^^^ unknown field
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0609`.
tests/ui/never_type/regress/loop-in-array-length.rs created+14
......@@ -0,0 +1,14 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/52443>
2
3fn main() {
4 [(); & { loop { continue } } ]; //~ ERROR mismatched types
5
6 [(); loop { break }]; //~ ERROR mismatched types
7
8 [(); {while true {break}; 0}];
9 //~^ WARN denote infinite loops with
10
11 [(); { for _ in 0usize.. {}; 0}];
12 //~^ ERROR `std::ops::RangeFrom<usize>: const Iterator` is not satisfied
13 //~| ERROR `std::ops::RangeFrom<usize>: const Iterator` is not satisfied
14}
tests/ui/never_type/regress/loop-in-array-length.stderr created+56
......@@ -0,0 +1,56 @@
1warning: denote infinite loops with `loop { ... }`
2 --> $DIR/loop-in-array-length.rs:8:11
3 |
4LL | [(); {while true {break}; 0}];
5 | ^^^^^^^^^^ help: use `loop`
6 |
7 = note: `#[warn(while_true)]` on by default
8
9error[E0308]: mismatched types
10 --> $DIR/loop-in-array-length.rs:4:10
11 |
12LL | [(); & { loop { continue } } ];
13 | ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_`
14 |
15 = note: expected type `usize`
16 found reference `&_`
17help: consider removing the borrow
18 |
19LL - [(); & { loop { continue } } ];
20LL + [(); { loop { continue } } ];
21 |
22
23error[E0308]: mismatched types
24 --> $DIR/loop-in-array-length.rs:6:17
25 |
26LL | [(); loop { break }];
27 | ^^^^^ expected `usize`, found `()`
28 |
29help: give the `break` a value of the expected type
30 |
31LL | [(); loop { break 42 }];
32 | ++
33
34error[E0277]: the trait bound `std::ops::RangeFrom<usize>: const Iterator` is not satisfied
35 --> $DIR/loop-in-array-length.rs:11:21
36 |
37LL | [(); { for _ in 0usize.. {}; 0}];
38 | ^^^^^^^^ required by a bound introduced by this call
39 |
40note: trait `Iterator` is implemented but not `const`
41 --> $SRC_DIR/core/src/iter/range.rs:LL:COL
42 = note: required for `std::ops::RangeFrom<usize>` to implement `const IntoIterator`
43
44error[E0277]: the trait bound `std::ops::RangeFrom<usize>: const Iterator` is not satisfied
45 --> $DIR/loop-in-array-length.rs:11:21
46 |
47LL | [(); { for _ in 0usize.. {}; 0}];
48 | ^^^^^^^^
49 |
50note: trait `Iterator` is implemented but not `const`
51 --> $SRC_DIR/core/src/iter/range.rs:LL:COL
52
53error: aborting due to 4 previous errors; 1 warning emitted
54
55Some errors have detailed explanations: E0277, E0308.
56For more information about an error, try `rustc --explain E0277`.
tests/ui/never_type/regress/malformed-range-to-never.rs created+7
......@@ -0,0 +1,7 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/96335>
2
3fn main() {
4 0.....{loop{}1};
5 //~^ ERROR unexpected token
6 //~| ERROR mismatched types
7}
tests/ui/never_type/regress/malformed-range-to-never.stderr created+34
......@@ -0,0 +1,34 @@
1error: unexpected token: `...`
2 --> $DIR/malformed-range-to-never.rs:4:6
3 |
4LL | 0.....{loop{}1};
5 | ^^^
6 |
7help: use `..` for an exclusive range
8 |
9LL - 0.....{loop{}1};
10LL + 0....{loop{}1};
11 |
12help: or `..=` for an inclusive range
13 |
14LL - 0.....{loop{}1};
15LL + 0..=..{loop{}1};
16 |
17
18error[E0308]: mismatched types
19 --> $DIR/malformed-range-to-never.rs:4:9
20 |
21LL | 0.....{loop{}1};
22 | ----^^^^^^^^^^^
23 | | |
24 | | expected integer, found `RangeTo<{integer}>`
25 | arguments to this function are incorrect
26 |
27 = note: expected type `{integer}`
28 found struct `RangeTo<{integer}>`
29note: associated function defined here
30 --> $SRC_DIR/core/src/ops/range.rs:LL:COL
31
32error: aborting due to 2 previous errors
33
34For more information about this error, try `rustc --explain E0308`.
tests/ui/never_type/regress/never-as-function-argument.rs created+13
......@@ -0,0 +1,13 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/13352>,
2// check that the never type can be used as a function argument.
3//
4//@run-pass
5
6fn foo(_: Box<dyn FnMut()>) {}
7
8fn main() {
9 #[expect(unreachable_code)]
10 foo(loop {
11 std::process::exit(0);
12 });
13}
tests/ui/never_type/regress/never-as-spec-default-associated-type.rs created+43
......@@ -0,0 +1,43 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/51506>
2
3#![feature(never_type, specialization)]
4#![allow(incomplete_features)]
5
6use std::iter::{self, Empty};
7
8trait Trait {
9 type Out: Iterator<Item = u32>;
10
11 fn f(&self) -> Option<Self::Out>;
12}
13
14impl<T> Trait for T {
15 default type Out = !; //~ ERROR: `!` is not an iterator
16
17 default fn f(&self) -> Option<Self::Out> {
18 None
19 }
20}
21
22struct X;
23
24impl Trait for X {
25 type Out = Empty<u32>;
26
27 fn f(&self) -> Option<Self::Out> {
28 Some(iter::empty())
29 }
30}
31
32fn f<T: Trait>(a: T) {
33 if let Some(iter) = a.f() {
34 println!("Some");
35 for x in iter {
36 println!("x = {}", x);
37 }
38 }
39}
40
41pub fn main() {
42 f(10);
43}
tests/ui/never_type/regress/never-as-spec-default-associated-type.stderr created+16
......@@ -0,0 +1,16 @@
1error[E0277]: `!` is not an iterator
2 --> $DIR/never-as-spec-default-associated-type.rs:15:24
3 |
4LL | default type Out = !;
5 | ^ `!` is not an iterator
6 |
7 = help: the trait `Iterator` is not implemented for `!`
8note: required by a bound in `Trait::Out`
9 --> $DIR/never-as-spec-default-associated-type.rs:9:15
10 |
11LL | type Out: Iterator<Item = u32>;
12 | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait::Out`
13
14error: aborting due to 1 previous error
15
16For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/regress/never-deref.rs created+5
......@@ -0,0 +1,5 @@
1//! regression test for https://github.com/rust-lang/rust/issues/17373
2fn main() {
3 *return //~ ERROR type `!` cannot be dereferenced
4 ;
5}
tests/ui/never_type/regress/never-deref.stderr created+9
......@@ -0,0 +1,9 @@
1error[E0614]: type `!` cannot be dereferenced
2 --> $DIR/never-deref.rs:3:5
3 |
4LL | *return
5 | ^^^^^^^ can't be dereferenced
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0614`.
tests/ui/never_type/regress/never-in-range-pat.rs created+16
......@@ -0,0 +1,16 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/133947>.
2//
3// Make sure we don't ICE when there's `!` in a range pattern.
4//
5// This shouldn't be allowed anyways, but we only deny it during MIR
6// building, so make sure we handle it semi-gracefully during typeck.
7
8#![feature(never_type)]
9
10fn main() {
11 let x: !;
12 match 1 {
13 0..x => {}
14 //~^ ERROR only `char` and numeric types are allowed in range patterns
15 }
16}
tests/ui/never_type/regress/never-in-range-pat.stderr created+11
......@@ -0,0 +1,11 @@
1error[E0029]: only `char` and numeric types are allowed in range patterns
2 --> $DIR/never-in-range-pat.rs:13:12
3 |
4LL | 0..x => {}
5 | - ^ this is of type `!` but it should be `char` or numeric
6 | |
7 | this is of type `{integer}`
8
9error: aborting due to 1 previous error
10
11For more information about this error, try `rustc --explain E0029`.
tests/ui/never_type/regress/never-type-fallback-option.rs created+22
......@@ -0,0 +1,22 @@
1//@ run-pass
2
3#![allow(warnings)]
4
5//! Tests type inference fallback to `!` (never type) in `Option` context.
6//!
7//! Regression test for issues:
8//! - https://github.com/rust-lang/rust/issues/39808
9//! - https://github.com/rust-lang/rust/issues/39984
10//!
11//! Here the type of `c` is `Option<?T>`, where `?T` is unconstrained.
12//! Because there is data-flow from the `{ return; }` block, which
13//! diverges and hence has type `!`, into `c`, we will default `?T` to
14//! `!`, and hence this code compiles rather than failing and requiring
15//! a type annotation.
16
17fn main() {
18 let c = Some({
19 return;
20 });
21 c.unwrap();
22}
tests/ui/never_type/regress/never-type-method-call-15207.rs created+8
......@@ -0,0 +1,8 @@
1//! Regression test for https://github.com/rust-lang/rust/issues/15207
2
3fn main() {
4 loop {
5 break.push(1) //~ ERROR no method named `push` found for type `!`
6 ;
7 }
8}
tests/ui/never_type/regress/never-type-method-call-15207.stderr created+9
......@@ -0,0 +1,9 @@
1error[E0599]: no method named `push` found for type `!` in the current scope
2 --> $DIR/never-type-method-call-15207.rs:5:15
3 |
4LL | break.push(1)
5 | ^^^^ method not found in `!`
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0599`.
tests/ui/never_type/regress/span-bug-issue-121445.rs created+17
......@@ -0,0 +1,17 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/121445>
2
3#![feature(never_type)]
4
5fn test2() {
6 let x: !;
7 let c2 = SingleVariant::Points(0)
8 | match x { //~ ERROR no implementation for `SingleVariant | ()`
9 _ => (),
10 };
11}
12
13enum SingleVariant {
14 Points(u32),
15}
16
17fn main() {}
tests/ui/never_type/regress/span-bug-issue-121445.stderr created+22
......@@ -0,0 +1,22 @@
1error[E0369]: no implementation for `SingleVariant | ()`
2 --> $DIR/span-bug-issue-121445.rs:8:9
3 |
4LL | let c2 = SingleVariant::Points(0)
5 | ------------------------ SingleVariant
6LL | | match x {
7 | _________^_-
8LL | | _ => (),
9LL | | };
10 | |_________- ()
11 |
12note: an implementation of `BitOr<()>` might be missing for `SingleVariant`
13 --> $DIR/span-bug-issue-121445.rs:13:1
14 |
15LL | enum SingleVariant {
16 | ^^^^^^^^^^^^^^^^^^ must implement `BitOr<()>`
17note: the trait `BitOr` must be implemented
18 --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
19
20error: aborting due to 1 previous error
21
22For more information about this error, try `rustc --explain E0369`.
tests/ui/never_type/regress/suggestion-ice-132517.rs created+4
......@@ -0,0 +1,4 @@
1fn main() {
2 x::<_>(|_| panic!())
3 //~^ ERROR cannot find function `x` in this scope
4}
tests/ui/never_type/regress/suggestion-ice-132517.stderr created+9
......@@ -0,0 +1,9 @@
1error[E0425]: cannot find function `x` in this scope
2 --> $DIR/suggestion-ice-132517.rs:2:5
3 |
4LL | x::<_>(|_| panic!())
5 | ^ not found in this scope
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0425`.
tests/ui/never_type/return-never-coerce.rs deleted-18
......@@ -1,18 +0,0 @@
1// Test that ! coerces to other types.
2
3//@ run-fail
4//@ error-pattern:aah!
5//@ needs-subprocess
6
7fn call_another_fn<T, F: FnOnce() -> T>(f: F) -> T {
8 f()
9}
10
11fn wub() -> ! {
12 panic!("aah!");
13}
14
15fn main() {
16 let x: i32 = call_another_fn(wub);
17 let y: u32 = wub();
18}
tests/ui/never_type/span-bug-issue-121445.rs deleted-17
......@@ -1,17 +0,0 @@
1// Regression test for <https://github.com/rust-lang/rust/issues/121445>
2
3#![feature(never_type)]
4
5fn test2() {
6 let x: !;
7 let c2 = SingleVariant::Points(0)
8 | match x { //~ ERROR no implementation for `SingleVariant | ()`
9 _ => (),
10 };
11}
12
13enum SingleVariant {
14 Points(u32),
15}
16
17fn main() {}
tests/ui/never_type/span-bug-issue-121445.stderr deleted-22
......@@ -1,22 +0,0 @@
1error[E0369]: no implementation for `SingleVariant | ()`
2 --> $DIR/span-bug-issue-121445.rs:8:9
3 |
4LL | let c2 = SingleVariant::Points(0)
5 | ------------------------ SingleVariant
6LL | | match x {
7 | _________^_-
8LL | | _ => (),
9LL | | };
10 | |_________- ()
11 |
12note: an implementation of `BitOr<()>` might be missing for `SingleVariant`
13 --> $DIR/span-bug-issue-121445.rs:13:1
14 |
15LL | enum SingleVariant {
16 | ^^^^^^^^^^^^^^^^^^ must implement `BitOr<()>`
17note: the trait `BitOr` must be implemented
18 --> $SRC_DIR/core/src/ops/bit.rs:LL:COL
19
20error: aborting due to 1 previous error
21
22For more information about this error, try `rustc --explain E0369`.
tests/ui/never_type/suggestion-ice-132517.rs deleted-4
......@@ -1,4 +0,0 @@
1fn main() {
2 x::<_>(|_| panic!())
3 //~^ ERROR cannot find function `x` in this scope
4}
tests/ui/never_type/suggestion-ice-132517.stderr deleted-9
......@@ -1,9 +0,0 @@
1error[E0425]: cannot find function `x` in this scope
2 --> $DIR/suggestion-ice-132517.rs:2:5
3 |
4LL | x::<_>(|_| panic!())
5 | ^ not found in this scope
6
7error: aborting due to 1 previous error
8
9For more information about this error, try `rustc --explain E0425`.
tests/ui/never_type/try-block-never-type-fallback.e2021.stderr deleted-20
......@@ -1,20 +0,0 @@
1error[E0277]: the trait bound `!: From<()>` is not satisfied
2 --> $DIR/try-block-never-type-fallback.rs:20:9
3 |
4LL | bar(try { x? });
5 | --- ^^^^^^^^^^ the trait `From<()>` is not implemented for `!`
6 | |
7 | required by a bound introduced by this call
8 |
9 = note: this error might have been caused by changes to Rust's type-inference algorithm (see issue #148922 <https://github.com/rust-lang/rust/issues/148922> for more information)
10 = help: you might have intended to use the type `()` here instead
11 = note: required for `()` to implement `Into<!>`
12note: required by a bound in `bar`
13 --> $DIR/try-block-never-type-fallback.rs:15:23
14 |
15LL | fn bar(_: Result<impl Into<!>, u32>) {
16 | ^^^^^^^ required by this bound in `bar`
17
18error: aborting due to 1 previous error
19
20For more information about this error, try `rustc --explain E0277`.
tests/ui/never_type/try-block-never-type-fallback.rs deleted-25
......@@ -1,25 +0,0 @@
1//@ revisions: e2021 e2024
2//@[e2021] edition: 2021
3//@[e2024] edition: 2024
4//@[e2024] check-pass
5
6// Issue #125364: Bad interaction between never_type, try_blocks, and From/Into
7//
8// In edition 2021, the never type in try blocks falls back to (),
9// causing a type error (since (): Into<!> does not hold).
10// In edition 2024, it falls back to !, allowing the code to compile correctly.
11
12#![feature(never_type)]
13#![feature(try_blocks)]
14
15fn bar(_: Result<impl Into<!>, u32>) {
16 unimplemented!()
17}
18
19fn foo(x: Result<!, u32>) {
20 bar(try { x? });
21 //[e2021]~^ ERROR the trait bound `!: From<()>` is not satisfied
22}
23
24fn main() {
25}
tests/ui/never_type/unused_trait_in_never_pattern_body.rs deleted-12
......@@ -1,12 +0,0 @@
1fn a() {
2 match 0 {
3 ! => || { //~ ERROR `!` patterns are experimental
4 //~^ ERROR a never pattern is always unreachable
5 //~^^ ERROR mismatched types
6 use std::ops::Add;
7 0.add(1)
8 },
9 }
10}
11
12fn main() {}
tests/ui/never_type/unused_trait_in_never_pattern_body.stderr deleted-36
......@@ -1,36 +0,0 @@
1error[E0658]: `!` patterns are experimental
2 --> $DIR/unused_trait_in_never_pattern_body.rs:3:9
3 |
4LL | ! => || {
5 | ^
6 |
7 = note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information
8 = help: add `#![feature(never_patterns)]` to the crate attributes to enable
9 = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10
11error: a never pattern is always unreachable
12 --> $DIR/unused_trait_in_never_pattern_body.rs:3:14
13 |
14LL | ! => || {
15 | ______________^
16LL | |
17LL | |
18LL | | use std::ops::Add;
19LL | | 0.add(1)
20LL | | },
21 | | ^
22 | | |
23 | |_________this will never be executed
24 | help: remove this expression
25
26error: mismatched types
27 --> $DIR/unused_trait_in_never_pattern_body.rs:3:9
28 |
29LL | ! => || {
30 | ^ a never pattern must be used on an uninhabited type
31 |
32 = note: the matched value is of type `i32`
33
34error: aborting due to 3 previous errors
35
36For more information about this error, try `rustc --explain E0658`.
tests/ui/parser/return-without-semicolon-in-match.rs created+14
......@@ -0,0 +1,14 @@
1// Tests that `return` without a semicolon parses correctly in a match arm.
2// See <https://github.com/rust-lang/rust/issues/521>
3//
4//@ check-pass
5
6fn _f() {
7 #[rustfmt::skip]
8 let _x = match true {
9 true => { 10 },
10 false => { return },
11 };
12}
13
14fn main() {}
tests/ui/process/nofile-limit.rs+3
......@@ -11,6 +11,9 @@
1111
1212#![feature(exit_status_error)]
1313#![feature(rustc_private)]
14// on aarch64, "Using 'getaddrinfo' in statically linked applications requires at runtime the shared
15// libraries from the glibc version used for linking"
16#![allow(linker_messages)]
1417extern crate libc;
1518
1619use std::os::unix::process::CommandExt;
tests/ui/reachable/never-assign-dead-code.rs created+13
......@@ -0,0 +1,13 @@
1// Test that an assignment of type ! makes the rest of the block dead code.
2//
3//@ check-pass
4
5#![feature(never_type)]
6#![expect(dropping_copy_types)]
7#![warn(unused)]
8
9fn main() {
10 let x: ! = panic!("aah"); //~ WARN unused
11 drop(x); //~ WARN unreachable
12 //~^ WARN unreachable
13}
tests/ui/reachable/never-assign-dead-code.stderr created+33
......@@ -0,0 +1,33 @@
1warning: unreachable statement
2 --> $DIR/never-assign-dead-code.rs:11:5
3 |
4LL | let x: ! = panic!("aah");
5 | ------------- any code following this expression is unreachable
6LL | drop(x);
7 | ^^^^^^^^ unreachable statement
8 |
9note: the lint level is defined here
10 --> $DIR/never-assign-dead-code.rs:7:9
11 |
12LL | #![warn(unused)]
13 | ^^^^^^
14 = note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`
15
16warning: unreachable call
17 --> $DIR/never-assign-dead-code.rs:11:5
18 |
19LL | drop(x);
20 | ^^^^ - any code following this expression is unreachable
21 | |
22 | unreachable call
23
24warning: unused variable: `x`
25 --> $DIR/never-assign-dead-code.rs:10:9
26 |
27LL | let x: ! = panic!("aah");
28 | ^ help: if this is intentional, prefix it with an underscore: `_x`
29 |
30 = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
31
32warning: 3 warnings emitted
33