| author | bors <bors@rust-lang.org> 2026-03-07 03:26:12 UTC |
| committer | bors <bors@rust-lang.org> 2026-03-07 03:26:12 UTC |
| log | ea5573a6c6e5e932f917ec4a8e6d8efdeb9f394d |
| tree | 9db4e1de400e41c0f5e07726678d8388dab99530 |
| parent | 80282b130679a654eaa22f028a908c51be53d436 |
| parent | f540b27f90f9f0d407f9b9b60165c8bd5e07cdb6 |
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; |
| 4 | 4 | |
| 5 | 5 | use rustc_abi::{FieldIdx, VariantIdx}; |
| 6 | 6 | use rustc_data_structures::fx::FxIndexMap; |
| 7 | use rustc_errors::formatting::DiagMessageAddArg; | |
| 7 | 8 | use rustc_errors::{Applicability, Diag, DiagMessage, EmissionGuarantee, MultiSpan, listify, msg}; |
| 8 | 9 | use rustc_hir::def::{CtorKind, Namespace}; |
| 9 | 10 | use rustc_hir::{ |
| ... | ... | @@ -1309,12 +1310,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { |
| 1309 | 1310 | && !spans.is_empty() |
| 1310 | 1311 | { |
| 1311 | 1312 | 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(); | |
| 1318 | 1316 | for sp in spans { |
| 1319 | 1317 | span.push_span_label(sp, msg.clone()); |
| 1320 | 1318 | } |
compiler/rustc_builtin_macros/src/errors.rs+14-14| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | use rustc_errors::codes::*; |
| 2 | use rustc_errors::formatting::DiagMessageAddArg; | |
| 2 | 3 | use rustc_errors::{ |
| 3 | 4 | Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans, |
| 4 | 5 | Subdiagnostic, msg, |
| ... | ... | @@ -763,15 +764,17 @@ pub(crate) struct FormatUnusedArg { |
| 763 | 764 | // form of diagnostic. |
| 764 | 765 | impl Subdiagnostic for FormatUnusedArg { |
| 765 | 766 | 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 | ); | |
| 775 | 778 | } |
| 776 | 779 | } |
| 777 | 780 | |
| ... | ... | @@ -946,17 +949,14 @@ pub(crate) struct AsmClobberNoReg { |
| 946 | 949 | |
| 947 | 950 | impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AsmClobberNoReg { |
| 948 | 951 | 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()); | |
| 952 | 952 | Diag::new( |
| 953 | 953 | dcx, |
| 954 | 954 | level, |
| 955 | 955 | msg!("asm with `clobber_abi` must specify explicit registers for outputs"), |
| 956 | 956 | ) |
| 957 | 957 | .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") | |
| 960 | 960 | } |
| 961 | 961 | } |
| 962 | 962 |
compiler/rustc_codegen_llvm/src/errors.rs+4-2| ... | ... | @@ -2,7 +2,9 @@ use std::ffi::CString; |
| 2 | 2 | use std::path::Path; |
| 3 | 3 | |
| 4 | 4 | use rustc_data_structures::small_c_str::SmallCStr; |
| 5 | use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, msg}; | |
| 5 | use rustc_errors::{ | |
| 6 | Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, format_diag_message, msg, | |
| 7 | }; | |
| 6 | 8 | use rustc_macros::Diagnostic; |
| 7 | 9 | use rustc_span::Span; |
| 8 | 10 | |
| ... | ... | @@ -24,7 +26,7 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> { |
| 24 | 26 | fn into_diag(self, dcx: DiagCtxtHandle<'_>, level: Level) -> Diag<'_, G> { |
| 25 | 27 | let diag: Diag<'_, G> = self.0.into_diag(dcx, level); |
| 26 | 28 | 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); | |
| 28 | 30 | Diag::new( |
| 29 | 31 | dcx, |
| 30 | 32 | level, |
compiler/rustc_codegen_ssa/src/back/link.rs+147-47| ... | ... | @@ -22,6 +22,7 @@ use rustc_errors::DiagCtxtHandle; |
| 22 | 22 | use rustc_fs_util::{TempDirBuilder, fix_windows_verbatim_for_gcc, try_canonicalize}; |
| 23 | 23 | use rustc_hir::attrs::NativeLibKind; |
| 24 | 24 | use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; |
| 25 | use rustc_lint_defs::builtin::LINKER_INFO; | |
| 25 | 26 | use rustc_macros::Diagnostic; |
| 26 | 27 | use rustc_metadata::fs::{METADATA_FILENAME, copy_to_stdout, emit_wrapper_file}; |
| 27 | 28 | use rustc_metadata::{ |
| ... | ... | @@ -60,7 +61,8 @@ use super::rpath::{self, RPathConfig}; |
| 60 | 61 | use super::{apple, versioned_llvm_target}; |
| 61 | 62 | use crate::base::needs_allocator_shim_for_linking; |
| 62 | 63 | use 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, | |
| 64 | 66 | }; |
| 65 | 67 | |
| 66 | 68 | pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) { |
| ... | ... | @@ -672,6 +674,147 @@ struct LinkerOutput { |
| 672 | 674 | inner: String, |
| 673 | 675 | } |
| 674 | 676 | |
| 677 | fn 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 | ||
| 685 | fn 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 | ||
| 690 | fn 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 | ||
| 697 | fn 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 | ||
| 675 | 818 | /// Create a dynamic library or executable. |
| 676 | 819 | /// |
| 677 | 820 | /// This will invoke the system linker/cc to create the resulting file. This links to all upstream |
| ... | ... | @@ -860,11 +1003,6 @@ fn link_natively( |
| 860 | 1003 | |
| 861 | 1004 | match prog { |
| 862 | 1005 | 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 | ||
| 868 | 1006 | if !prog.status.success() { |
| 869 | 1007 | let mut output = prog.stderr.clone(); |
| 870 | 1008 | output.extend_from_slice(&prog.stdout); |
| ... | ... | @@ -884,7 +1022,7 @@ fn link_natively( |
| 884 | 1022 | if let Some(code) = prog.status.code() { |
| 885 | 1023 | // All Microsoft `link.exe` linking ror codes are |
| 886 | 1024 | // 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) { | |
| 888 | 1026 | let is_vs_installed = find_msvc_tools::find_vs_version().is_ok(); |
| 889 | 1027 | let has_linker = |
| 890 | 1028 | find_msvc_tools::find_tool(sess.target.arch.desc(), "link.exe") |
| ... | ... | @@ -916,46 +1054,8 @@ fn link_natively( |
| 916 | 1054 | sess.dcx().abort_if_errors(); |
| 917 | 1055 | } |
| 918 | 1056 | |
| 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); | |
| 959 | 1059 | } |
| 960 | 1060 | Err(e) => { |
| 961 | 1061 | 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; |
| 24 | 24 | use rustc_hir::CRATE_HIR_ID; |
| 25 | 25 | use rustc_hir::attrs::{CfgEntry, NativeLibKind, WindowsSubsystemKind}; |
| 26 | 26 | use rustc_hir::def_id::CrateNum; |
| 27 | use rustc_lint_defs::builtin::LINKER_INFO; | |
| 27 | 28 | use rustc_macros::{Decodable, Encodable}; |
| 28 | 29 | use rustc_metadata::EncodedMetadata; |
| 29 | 30 | use rustc_middle::dep_graph::WorkProduct; |
| ... | ... | @@ -364,10 +365,14 @@ impl CompiledModules { |
| 364 | 365 | #[derive(Copy, Clone, Debug, Encodable, Decodable)] |
| 365 | 366 | pub struct CodegenLintLevels { |
| 366 | 367 | linker_messages: LevelAndSource, |
| 368 | linker_info: LevelAndSource, | |
| 367 | 369 | } |
| 368 | 370 | |
| 369 | 371 | impl CodegenLintLevels { |
| 370 | 372 | 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 | } | |
| 372 | 377 | } |
| 373 | 378 | } |
compiler/rustc_const_eval/src/check_consts/ops.rs+3-2| ... | ... | @@ -265,6 +265,7 @@ fn build_error_for_const_call<'tcx>( |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | CallKind::FnCall { fn_trait_id, self_ty } => { |
| 268 | let kind = ccx.const_kind(); | |
| 268 | 269 | let note = match self_ty.kind() { |
| 269 | 270 | FnDef(def_id, ..) => { |
| 270 | 271 | let span = tcx.def_span(*def_id); |
| ... | ... | @@ -274,8 +275,8 @@ fn build_error_for_const_call<'tcx>( |
| 274 | 275 | |
| 275 | 276 | Some(errors::NonConstClosureNote::FnDef { span }) |
| 276 | 277 | } |
| 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 }), | |
| 279 | 280 | _ => None, |
| 280 | 281 | }; |
| 281 | 282 |
compiler/rustc_const_eval/src/errors.rs+34-35| ... | ... | @@ -4,9 +4,10 @@ use std::fmt::Write; |
| 4 | 4 | use either::Either; |
| 5 | 5 | use rustc_abi::WrappingRange; |
| 6 | 6 | use rustc_errors::codes::*; |
| 7 | use rustc_errors::formatting::DiagMessageAddArg; | |
| 7 | 8 | use 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, | |
| 10 | 11 | }; |
| 11 | 12 | use rustc_hir::ConstContext; |
| 12 | 13 | use rustc_macros::{Diagnostic, Subdiagnostic}; |
| ... | ... | @@ -359,14 +360,11 @@ pub struct FrameNote { |
| 359 | 360 | |
| 360 | 361 | impl Subdiagnostic for FrameNote { |
| 361 | 362 | 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); | |
| 365 | 363 | let mut span: MultiSpan = self.span.into(); |
| 366 | 364 | if self.has_label && !self.span.is_dummy() { |
| 367 | 365 | span.push_span_label(self.span, msg!("the failure occurred here")); |
| 368 | 366 | } |
| 369 | let msg = diag.eagerly_format(msg!( | |
| 367 | let msg = msg!( | |
| 370 | 368 | r#"{$times -> |
| 371 | 369 | [0] inside {$where_ -> |
| 372 | 370 | [closure] closure |
| ... | ... | @@ -379,10 +377,11 @@ impl Subdiagnostic for FrameNote { |
| 379 | 377 | *[other] {""} |
| 380 | 378 | } ...] |
| 381 | 379 | }"# |
| 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(); | |
| 386 | 385 | diag.span_note(span, msg); |
| 387 | 386 | } |
| 388 | 387 | } |
| ... | ... | @@ -534,7 +533,7 @@ pub enum NonConstClosureNote { |
| 534 | 533 | *[other] {""} |
| 535 | 534 | }s"# |
| 536 | 535 | )] |
| 537 | FnPtr, | |
| 536 | FnPtr { kind: ConstContext }, | |
| 538 | 537 | #[note( |
| 539 | 538 | r#"closures need an RFC before allowed to be called in {$kind -> |
| 540 | 539 | [const] constant |
| ... | ... | @@ -543,7 +542,7 @@ pub enum NonConstClosureNote { |
| 543 | 542 | *[other] {""} |
| 544 | 543 | }s"# |
| 545 | 544 | )] |
| 546 | Closure, | |
| 545 | Closure { kind: ConstContext }, | |
| 547 | 546 | } |
| 548 | 547 | |
| 549 | 548 | #[derive(Subdiagnostic)] |
| ... | ... | @@ -624,7 +623,7 @@ pub trait ReportErrorExt { |
| 624 | 623 | let mut diag = dcx.struct_allow(DiagMessage::Str(String::new().into())); |
| 625 | 624 | let message = self.diagnostic_message(); |
| 626 | 625 | 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(); | |
| 628 | 627 | diag.cancel(); |
| 629 | 628 | s |
| 630 | 629 | }) |
| ... | ... | @@ -1086,12 +1085,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { |
| 1086 | 1085 | } |
| 1087 | 1086 | |
| 1088 | 1087 | 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()))]), | |
| 1092 | 1091 | ) |
| 1093 | 1092 | } else { |
| 1094 | err.dcx.eagerly_format_to_string(msg!("constructing invalid value"), [].into_iter()) | |
| 1093 | Cow::Borrowed("constructing invalid value") | |
| 1095 | 1094 | }; |
| 1096 | 1095 | |
| 1097 | 1096 | err.arg("front_matter", message); |
| ... | ... | @@ -1117,12 +1116,13 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { |
| 1117 | 1116 | msg!("in the range {$lo}..={$hi}") |
| 1118 | 1117 | }; |
| 1119 | 1118 | |
| 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 | ); | |
| 1126 | 1126 | err.arg("in_range", message); |
| 1127 | 1127 | } |
| 1128 | 1128 | |
| ... | ... | @@ -1132,19 +1132,18 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> { |
| 1132 | 1132 | } |
| 1133 | 1133 | PointerAsInt { expected } | Uninit { expected } => { |
| 1134 | 1134 | 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", | |
| 1146 | 1146 | }; |
| 1147 | let msg = err.dcx.eagerly_format_to_string(msg, [].into_iter()); | |
| 1148 | 1147 | err.arg("expected", msg); |
| 1149 | 1148 | } |
| 1150 | 1149 | InvalidEnumTag { value } |
compiler/rustc_const_eval/src/interpret/eval_context.rs+3-3| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | use either::{Left, Right}; |
| 2 | 2 | use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout}; |
| 3 | 3 | use rustc_data_structures::debug_assert_matches; |
| 4 | use rustc_errors::{DiagCtxtHandle, msg}; | |
| 4 | use rustc_errors::{DiagCtxtHandle, format_diag_message, msg}; | |
| 5 | 5 | use rustc_hir::def_id::DefId; |
| 6 | 6 | use rustc_hir::limit::Limit; |
| 7 | 7 | use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo}; |
| ... | ... | @@ -235,9 +235,9 @@ pub fn format_interp_error<'tcx>(dcx: DiagCtxtHandle<'_>, e: InterpErrorInfo<'tc |
| 235 | 235 | let mut diag = dcx.struct_allow(""); |
| 236 | 236 | let msg = e.diagnostic_message(); |
| 237 | 237 | 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(); | |
| 239 | 239 | diag.cancel(); |
| 240 | s | |
| 240 | msg | |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { |
compiler/rustc_errors/src/diagnostic.rs-28| ... | ... | @@ -236,9 +236,6 @@ pub struct DiagInner { |
| 236 | 236 | pub suggestions: Suggestions, |
| 237 | 237 | pub args: DiagArgMap, |
| 238 | 238 | |
| 239 | // This is used to store args and restore them after a subdiagnostic is rendered. | |
| 240 | pub reserved_args: DiagArgMap, | |
| 241 | ||
| 242 | 239 | /// This is not used for highlighting or rendering any error message. Rather, it can be used |
| 243 | 240 | /// as a sort key to sort a buffer of diagnostics. By default, it is the primary span of |
| 244 | 241 | /// `span` if there is one. Otherwise, it is `DUMMY_SP`. |
| ... | ... | @@ -269,7 +266,6 @@ impl DiagInner { |
| 269 | 266 | children: vec![], |
| 270 | 267 | suggestions: Suggestions::Enabled(vec![]), |
| 271 | 268 | args: Default::default(), |
| 272 | reserved_args: Default::default(), | |
| 273 | 269 | sort_span: DUMMY_SP, |
| 274 | 270 | is_lint: None, |
| 275 | 271 | long_ty_path: None, |
| ... | ... | @@ -334,14 +330,6 @@ impl DiagInner { |
| 334 | 330 | self.args.swap_remove(name); |
| 335 | 331 | } |
| 336 | 332 | |
| 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 | ||
| 345 | 333 | pub fn emitted_at_sub_diag(&self) -> Subdiag { |
| 346 | 334 | let track = format!("-Ztrack-diagnostics: created at {}", self.emitted_at); |
| 347 | 335 | Subdiag { |
| ... | ... | @@ -1144,16 +1132,6 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { |
| 1144 | 1132 | self |
| 1145 | 1133 | } |
| 1146 | 1134 | |
| 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 | ||
| 1157 | 1135 | with_fn! { with_span, |
| 1158 | 1136 | /// Add a span. |
| 1159 | 1137 | pub fn span(&mut self, sp: impl Into<MultiSpan>) -> &mut Self { |
| ... | ... | @@ -1341,12 +1319,6 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { |
| 1341 | 1319 | self.downgrade_to_delayed_bug(); |
| 1342 | 1320 | self.emit() |
| 1343 | 1321 | } |
| 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 | } | |
| 1350 | 1322 | } |
| 1351 | 1323 | |
| 1352 | 1324 | /// Destructor bomb: every `Diag` must be consumed (emitted, cancelled, etc.) |
compiler/rustc_errors/src/formatting.rs+66-24| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | use std::borrow::Cow; |
| 2 | 2 | |
| 3 | 3 | pub use rustc_error_messages::FluentArgs; |
| 4 | use rustc_error_messages::{DiagArgMap, langid, register_functions}; | |
| 4 | use rustc_error_messages::{DiagArgMap, DiagArgName, IntoDiagArg, langid, register_functions}; | |
| 5 | 5 | use tracing::{debug, trace}; |
| 6 | 6 | |
| 7 | 7 | use crate::fluent_bundle::FluentResource; |
| ... | ... | @@ -33,30 +33,72 @@ pub fn format_diag_messages( |
| 33 | 33 | |
| 34 | 34 | /// Convert a `DiagMessage` to a string |
| 35 | 35 | pub fn format_diag_message<'a>(message: &'a DiagMessage, args: &DiagArgMap) -> Cow<'a, str> { |
| 36 | trace!(?message, ?args); | |
| 37 | ||
| 38 | 36 | match message { |
| 39 | 37 | 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 | ||
| 42 | fn 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 | ||
| 64 | pub trait DiagMessageAddArg { | |
| 65 | fn arg(self, name: impl Into<DiagArgName>, arg: impl IntoDiagArg) -> EagerDiagMessageBuilder; | |
| 66 | } | |
| 67 | ||
| 68 | pub struct EagerDiagMessageBuilder { | |
| 69 | fluent_str: Cow<'static, str>, | |
| 70 | args: DiagArgMap, | |
| 71 | } | |
| 72 | ||
| 73 | impl 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 | ||
| 91 | impl 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 | ||
| 100 | impl EagerDiagMessageBuilder { | |
| 101 | pub fn format(self) -> DiagMessage { | |
| 102 | DiagMessage::Str(format_fluent_str(&self.fluent_str, &self.args)) | |
| 61 | 103 | } |
| 62 | 104 | } |
compiler/rustc_errors/src/lib.rs+9-57| ... | ... | @@ -66,7 +66,8 @@ use rustc_span::{DUMMY_SP, Span}; |
| 66 | 66 | use tracing::debug; |
| 67 | 67 | |
| 68 | 68 | use crate::emitter::TimingEvent; |
| 69 | use crate::formatting::format_diag_message; | |
| 69 | use crate::formatting::DiagMessageAddArg; | |
| 70 | pub use crate::formatting::format_diag_message; | |
| 70 | 71 | use crate::timings::TimingRecord; |
| 71 | 72 | |
| 72 | 73 | pub mod annotate_snippet_emitter_writer; |
| ... | ... | @@ -482,26 +483,6 @@ impl DiagCtxt { |
| 482 | 483 | self.inner.borrow_mut().emitter = emitter; |
| 483 | 484 | } |
| 484 | 485 | |
| 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 | ||
| 505 | 486 | // This is here to not allow mutation of flags; |
| 506 | 487 | // as of this writing it's used in Session::consider_optimizing and |
| 507 | 488 | // in tests in rustc_interface. |
| ... | ... | @@ -1417,33 +1398,6 @@ impl DiagCtxtInner { |
| 1417 | 1398 | self.has_errors().or_else(|| self.delayed_bugs.get(0).map(|(_, guar)| guar).copied()) |
| 1418 | 1399 | } |
| 1419 | 1400 | |
| 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 | ||
| 1447 | 1401 | fn flush_delayed(&mut self) { |
| 1448 | 1402 | // Stashed diagnostics must be emitted before delayed bugs are flushed. |
| 1449 | 1403 | // Otherwise, we might ICE prematurely when errors would have |
| ... | ... | @@ -1493,7 +1447,7 @@ impl DiagCtxtInner { |
| 1493 | 1447 | ); |
| 1494 | 1448 | } |
| 1495 | 1449 | |
| 1496 | let mut bug = if decorate { bug.decorate(self) } else { bug.inner }; | |
| 1450 | let mut bug = if decorate { bug.decorate() } else { bug.inner }; | |
| 1497 | 1451 | |
| 1498 | 1452 | // "Undelay" the delayed bugs into plain bugs. |
| 1499 | 1453 | if bug.level != DelayedBug { |
| ... | ... | @@ -1503,11 +1457,9 @@ impl DiagCtxtInner { |
| 1503 | 1457 | // We are at the `DiagInner`/`DiagCtxtInner` level rather than |
| 1504 | 1458 | // the usual `Diag`/`DiagCtxt` level, so we must augment `bug` |
| 1505 | 1459 | // in a lower-level fashion. |
| 1506 | bug.arg("level", bug.level); | |
| 1507 | 1460 | let msg = msg!( |
| 1508 | 1461 | "`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(); | |
| 1511 | 1463 | bug.sub(Note, msg, bug.span.primary_span().unwrap().into()); |
| 1512 | 1464 | } |
| 1513 | 1465 | bug.level = Bug; |
| ... | ... | @@ -1542,7 +1494,7 @@ impl DelayedDiagInner { |
| 1542 | 1494 | DelayedDiagInner { inner: diagnostic, note: backtrace } |
| 1543 | 1495 | } |
| 1544 | 1496 | |
| 1545 | fn decorate(self, dcx: &DiagCtxtInner) -> DiagInner { | |
| 1497 | fn decorate(self) -> DiagInner { | |
| 1546 | 1498 | // We are at the `DiagInner`/`DiagCtxtInner` level rather than the |
| 1547 | 1499 | // usual `Diag`/`DiagCtxt` level, so we must construct `diag` in a |
| 1548 | 1500 | // lower-level fashion. |
| ... | ... | @@ -1555,10 +1507,10 @@ impl DelayedDiagInner { |
| 1555 | 1507 | // Avoid the needless newline when no backtrace has been captured, |
| 1556 | 1508 | // the display impl should just be a single line. |
| 1557 | 1509 | _ => 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(); | |
| 1562 | 1514 | diag.sub(Note, msg, diag.span.primary_span().unwrap_or(DUMMY_SP).into()); |
| 1563 | 1515 | diag |
| 1564 | 1516 | } |
compiler/rustc_hir_typeck/src/errors.rs+7-3| ... | ... | @@ -987,13 +987,17 @@ impl rustc_errors::Subdiagnostic for CastUnknownPointerSub { |
| 987 | 987 | fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) { |
| 988 | 988 | match self { |
| 989 | 989 | CastUnknownPointerSub::To(span) => { |
| 990 | let msg = diag.eagerly_format(msg!("needs more type information")); | |
| 990 | let msg = msg!("needs more type information"); | |
| 991 | 991 | 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 | ); | |
| 993 | 995 | diag.note(msg); |
| 994 | 996 | } |
| 995 | 997 | 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 | ); | |
| 997 | 1001 | diag.span_label(span, msg); |
| 998 | 1002 | } |
| 999 | 1003 | } |
compiler/rustc_lint/src/builtin.rs+1-1| ... | ... | @@ -2242,10 +2242,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements { |
| 2242 | 2242 | EXPLICIT_OUTLIVES_REQUIREMENTS, |
| 2243 | 2243 | lint_spans.clone(), |
| 2244 | 2244 | BuiltinExplicitOutlives { |
| 2245 | count: bound_count, | |
| 2246 | 2245 | suggestion: BuiltinExplicitOutlivesSuggestion { |
| 2247 | 2246 | spans: lint_spans, |
| 2248 | 2247 | applicability, |
| 2248 | count: bound_count, | |
| 2249 | 2249 | }, |
| 2250 | 2250 | }, |
| 2251 | 2251 | ); |
compiler/rustc_lint/src/if_let_rescope.rs+2-3| ... | ... | @@ -354,9 +354,8 @@ impl Subdiagnostic for IfLetRescopeRewrite { |
| 354 | 354 | .chain(repeat_n('}', closing_brackets.count)) |
| 355 | 355 | .collect(), |
| 356 | 356 | )); |
| 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"); | |
| 360 | 359 | diag.multipart_suggestion_with_style( |
| 361 | 360 | msg, |
| 362 | 361 | suggestions, |
compiler/rustc_lint/src/lints.rs+5-4| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | use std::num::NonZero; |
| 4 | 4 | |
| 5 | 5 | use rustc_errors::codes::*; |
| 6 | use rustc_errors::formatting::DiagMessageAddArg; | |
| 6 | 7 | use rustc_errors::{ |
| 7 | 8 | Applicability, Diag, DiagArgValue, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic, |
| 8 | 9 | ElidedLifetimeInPathSubdiag, EmissionGuarantee, Level, MultiSpan, Subdiagnostic, |
| ... | ... | @@ -492,7 +493,6 @@ pub(crate) struct BuiltinKeywordIdents { |
| 492 | 493 | #[derive(Diagnostic)] |
| 493 | 494 | #[diag("outlives requirements can be inferred")] |
| 494 | 495 | pub(crate) struct BuiltinExplicitOutlives { |
| 495 | pub count: usize, | |
| 496 | 496 | #[subdiagnostic] |
| 497 | 497 | pub suggestion: BuiltinExplicitOutlivesSuggestion, |
| 498 | 498 | } |
| ... | ... | @@ -509,6 +509,7 @@ pub(crate) struct BuiltinExplicitOutlivesSuggestion { |
| 509 | 509 | pub spans: Vec<Span>, |
| 510 | 510 | #[applicability] |
| 511 | 511 | pub applicability: Applicability, |
| 512 | pub count: usize, | |
| 512 | 513 | } |
| 513 | 514 | |
| 514 | 515 | #[derive(Diagnostic)] |
| ... | ... | @@ -3628,9 +3629,9 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion { |
| 3628 | 3629 | } |
| 3629 | 3630 | |
| 3630 | 3631 | 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(); | |
| 3634 | 3635 | diag.multipart_suggestion_with_style( |
| 3635 | 3636 | msg, |
| 3636 | 3637 | suggestions, |
compiler/rustc_lint_defs/src/builtin.rs+35| ... | ... | @@ -61,6 +61,7 @@ declare_lint_pass! { |
| 61 | 61 | LARGE_ASSIGNMENTS, |
| 62 | 62 | LATE_BOUND_LIFETIME_ARGUMENTS, |
| 63 | 63 | LEGACY_DERIVE_HELPERS, |
| 64 | LINKER_INFO, | |
| 64 | 65 | LINKER_MESSAGES, |
| 65 | 66 | LONG_RUNNING_CONST_EVAL, |
| 66 | 67 | LOSSY_PROVENANCE_CASTS, |
| ... | ... | @@ -4062,6 +4063,40 @@ declare_lint! { |
| 4062 | 4063 | "warnings emitted at runtime by the target-specific linker program" |
| 4063 | 4064 | } |
| 4064 | 4065 | |
| 4066 | declare_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 | ||
| 4065 | 4100 | declare_lint! { |
| 4066 | 4101 | /// The `named_arguments_used_positionally` lint detects cases where named arguments are only |
| 4067 | 4102 | /// 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 |
| 64 | 64 | |
| 65 | 65 | fn variable_references<'a>(msg: &fluent_syntax::ast::Message<&'a str>) -> Vec<&'a str> { |
| 66 | 66 | let mut refs = vec![]; |
| 67 | ||
| 67 | 68 | if let Some(Pattern { elements }) = &msg.value { |
| 68 | 69 | 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); | |
| 75 | 71 | } |
| 76 | 72 | } |
| 77 | 73 | for attr in &msg.attributes { |
| 78 | 74 | 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); | |
| 84 | 97 | } |
| 85 | 98 | } |
| 86 | 99 | } |
| 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 | ||
| 87 | 107 | refs |
| 88 | 108 | } |
| 89 | 109 |
compiler/rustc_macros/src/diagnostics/subdiagnostic.rs+18-20| ... | ... | @@ -227,9 +227,9 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { |
| 227 | 227 | let ident = format_ident!("{}", ident); // strip `r#` prefix, if present |
| 228 | 228 | |
| 229 | 229 | 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) | |
| 233 | 233 | ); |
| 234 | 234 | } |
| 235 | 235 | } |
| ... | ... | @@ -529,14 +529,25 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { |
| 529 | 529 | } |
| 530 | 530 | }; |
| 531 | 531 | |
| 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 | }; | |
| 533 | 543 | |
| 544 | let span_field = self.span_field.value_ref(); | |
| 534 | 545 | let diag = &self.parent.diag; |
| 535 | 546 | let mut calls = TokenStream::new(); |
| 536 | 547 | for (kind, messages) in kind_messages { |
| 537 | 548 | let message = format_ident!("__message"); |
| 538 | 549 | 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); }); | |
| 540 | 551 | |
| 541 | 552 | let name = format_ident!("{}{}", if span_field.is_some() { "span_" } else { "" }, kind); |
| 542 | 553 | let call = match kind { |
| ... | ... | @@ -600,19 +611,6 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { |
| 600 | 611 | |
| 601 | 612 | calls.extend(call); |
| 602 | 613 | } |
| 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(); | |
| 616 | 614 | |
| 617 | 615 | let formatting_init = &self.formatting_init; |
| 618 | 616 | |
| ... | ... | @@ -626,10 +624,10 @@ impl<'parent, 'a> SubdiagnosticDeriveVariantBuilder<'parent, 'a> { |
| 626 | 624 | #init |
| 627 | 625 | #formatting_init |
| 628 | 626 | #attr_args |
| 629 | #store_args | |
| 627 | // #store_args | |
| 630 | 628 | #plain_args |
| 631 | 629 | #calls |
| 632 | #restore_args | |
| 630 | // #restore_args | |
| 633 | 631 | }) |
| 634 | 632 | } |
| 635 | 633 | } |
compiler/rustc_mir_transform/src/lint_tail_expr_drop_order.rs+22-22| ... | ... | @@ -5,6 +5,7 @@ use std::rc::Rc; |
| 5 | 5 | use itertools::Itertools as _; |
| 6 | 6 | use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; |
| 7 | 7 | use rustc_data_structures::unord::{UnordMap, UnordSet}; |
| 8 | use rustc_errors::formatting::DiagMessageAddArg; | |
| 8 | 9 | use rustc_errors::{Subdiagnostic, msg}; |
| 9 | 10 | use rustc_hir::CRATE_HIR_ID; |
| 10 | 11 | use rustc_hir::def_id::LocalDefId; |
| ... | ... | @@ -524,31 +525,30 @@ struct LocalLabel<'a> { |
| 524 | 525 | /// A custom `Subdiagnostic` implementation so that the notes are delivered in a specific order |
| 525 | 526 | impl Subdiagnostic for LocalLabel<'_> { |
| 526 | 527 | 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 | ); | |
| 541 | 540 | for dtor in self.destructors { |
| 542 | 541 | dtor.add_to_diag(diag); |
| 543 | 542 | } |
| 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()); | |
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | 554 |
compiler/rustc_parse/src/errors.rs+1| ... | ... | @@ -1179,6 +1179,7 @@ pub(crate) enum MatchArmBodyWithoutBracesSugg { |
| 1179 | 1179 | left: Span, |
| 1180 | 1180 | #[suggestion_part(code = " }}")] |
| 1181 | 1181 | right: Span, |
| 1182 | num_statements: usize, | |
| 1182 | 1183 | }, |
| 1183 | 1184 | #[suggestion( |
| 1184 | 1185 | "replace `;` with `,` to end a `match` arm expression", |
compiler/rustc_parse/src/parser/expr.rs+1| ... | ... | @@ -3207,6 +3207,7 @@ impl<'a> Parser<'a> { |
| 3207 | 3207 | errors::MatchArmBodyWithoutBracesSugg::AddBraces { |
| 3208 | 3208 | left: span.shrink_to_lo(), |
| 3209 | 3209 | right: span.shrink_to_hi(), |
| 3210 | num_statements: stmts.len(), | |
| 3210 | 3211 | } |
| 3211 | 3212 | } else { |
| 3212 | 3213 | errors::MatchArmBodyWithoutBracesSugg::UseComma { semicolon: semi_sp } |
compiler/rustc_passes/src/check_attr.rs+3-1| ... | ... | @@ -1598,7 +1598,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { |
| 1598 | 1598 | sym::expect, |
| 1599 | 1599 | ]) && let Some(meta) = attr.meta_item_list() |
| 1600 | 1600 | && 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 | }) | |
| 1602 | 1604 | }) |
| 1603 | 1605 | { |
| 1604 | 1606 | if hir_id != CRATE_HIR_ID { |
compiler/rustc_passes/src/errors.rs+1-1| ... | ... | @@ -301,7 +301,7 @@ pub(crate) enum UnusedNote { |
| 301 | 301 | #[note("`default_method_body_is_const` has been replaced with `const` on traits")] |
| 302 | 302 | DefaultMethodBodyConst, |
| 303 | 303 | #[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" | |
| 305 | 305 | )] |
| 306 | 306 | LinkerMessagesBinaryCrateOnly, |
| 307 | 307 | } |
compiler/rustc_resolve/src/diagnostics.rs+2| ... | ... | @@ -1,3 +1,4 @@ |
| 1 | // ignore-tidy-filelength | |
| 1 | 2 | use std::ops::ControlFlow; |
| 2 | 3 | |
| 3 | 4 | use itertools::Itertools as _; |
| ... | ... | @@ -579,6 +580,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { |
| 579 | 580 | errs::GenericParamsFromOuterItemInnerItem { |
| 580 | 581 | span: *span, |
| 581 | 582 | descr: kind.descr().to_string(), |
| 583 | is_self, | |
| 582 | 584 | } |
| 583 | 585 | }), |
| 584 | 586 | }; |
compiler/rustc_resolve/src/errors.rs+5-5| ... | ... | @@ -1,4 +1,5 @@ |
| 1 | 1 | use rustc_errors::codes::*; |
| 2 | use rustc_errors::formatting::DiagMessageAddArg; | |
| 2 | 3 | use rustc_errors::{ |
| 3 | 4 | Applicability, Diag, DiagCtxtHandle, DiagMessage, Diagnostic, ElidedLifetimeInPathSubdiag, |
| 4 | 5 | EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg, |
| ... | ... | @@ -51,6 +52,7 @@ pub(crate) struct GenericParamsFromOuterItemInnerItem { |
| 51 | 52 | #[primary_span] |
| 52 | 53 | pub(crate) span: Span, |
| 53 | 54 | pub(crate) descr: String, |
| 55 | pub(crate) is_self: bool, | |
| 54 | 56 | } |
| 55 | 57 | |
| 56 | 58 | #[derive(Subdiagnostic)] |
| ... | ... | @@ -1364,12 +1366,10 @@ impl Subdiagnostic for FoundItemConfigureOut { |
| 1364 | 1366 | let mut multispan: MultiSpan = self.span.into(); |
| 1365 | 1367 | match self.item_was { |
| 1366 | 1368 | ItemWas::BehindFeature { feature, span } => { |
| 1367 | let key = "feature".into(); | |
| 1368 | 1369 | 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(); | |
| 1373 | 1373 | multispan.push_span_label(span, msg); |
| 1374 | 1374 | } |
| 1375 | 1375 | ItemWas::CfgOut { span } => { |
compiler/rustc_session/src/errors.rs+1-1| ... | ... | @@ -539,5 +539,5 @@ pub(crate) struct UnexpectedBuiltinCfg { |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | #[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")] | |
| 543 | 543 | pub(crate) struct ThinLtoNotSupportedByBackend; |
compiler/rustc_session/src/session.rs+2-2| ... | ... | @@ -620,9 +620,9 @@ impl Session { |
| 620 | 620 | config::LtoCli::Thin => { |
| 621 | 621 | // The user explicitly asked for ThinLTO |
| 622 | 622 | if !self.thin_lto_supported { |
| 623 | // Backend doesn't support ThinLTO, disable LTO. | |
| 623 | // Backend doesn't support ThinLTO, fallback to fat LTO. | |
| 624 | 624 | self.dcx().emit_warn(errors::ThinLtoNotSupportedByBackend); |
| 625 | return config::Lto::No; | |
| 625 | return config::Lto::Fat; | |
| 626 | 626 | } |
| 627 | 627 | return config::Lto::Thin; |
| 628 | 628 | } |
compiler/rustc_span/src/symbol.rs+1| ... | ... | @@ -1152,6 +1152,7 @@ symbols! { |
| 1152 | 1152 | link_section, |
| 1153 | 1153 | linkage, |
| 1154 | 1154 | linker, |
| 1155 | linker_info, | |
| 1155 | 1156 | linker_messages, |
| 1156 | 1157 | linkonce, |
| 1157 | 1158 | linkonce_odr, |
compiler/rustc_trait_selection/src/errors.rs+28-65| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; |
| 2 | 2 | use rustc_errors::codes::*; |
| 3 | use rustc_errors::formatting::DiagMessageAddArg; | |
| 3 | 4 | use rustc_errors::{ |
| 4 | 5 | Applicability, Diag, DiagCtxtHandle, DiagMessage, DiagStyledString, Diagnostic, |
| 5 | 6 | EmissionGuarantee, IntoDiagArg, Level, MultiSpan, Subdiagnostic, msg, |
| ... | ... | @@ -450,28 +451,23 @@ impl Subdiagnostic for RegionOriginNote<'_> { |
| 450 | 451 | requirement, |
| 451 | 452 | expected_found: Some((expected, found)), |
| 452 | 453 | } => { |
| 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!( | |
| 460 | 455 | "...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(); | |
| 475 | 471 | label_or_note(diag, span, msg); |
| 476 | 472 | |
| 477 | 473 | diag.note_expected_found("", expected, "", found); |
| ... | ... | @@ -480,9 +476,7 @@ impl Subdiagnostic for RegionOriginNote<'_> { |
| 480 | 476 | // FIXME: this really should be handled at some earlier stage. Our |
| 481 | 477 | // handling of region checking when type errors are present is |
| 482 | 478 | // *terrible*. |
| 483 | diag.store_args(); | |
| 484 | diag.arg("requirement", requirement); | |
| 485 | let msg = diag.eagerly_format(msg!( | |
| 479 | let msg = msg!( | |
| 486 | 480 | "...so that {$requirement -> |
| 487 | 481 | [method_compat] method type is compatible with trait |
| 488 | 482 | [type_compat] associated type is compatible with trait |
| ... | ... | @@ -496,8 +490,9 @@ impl Subdiagnostic for RegionOriginNote<'_> { |
| 496 | 490 | [method_correct_type] method receiver has the correct type |
| 497 | 491 | *[other] types are compatible |
| 498 | 492 | }" |
| 499 | )); | |
| 500 | diag.restore_args(); | |
| 493 | ) | |
| 494 | .arg("requirement", requirement) | |
| 495 | .format(); | |
| 501 | 496 | label_or_note(diag, span, msg); |
| 502 | 497 | } |
| 503 | 498 | }; |
| ... | ... | @@ -1174,7 +1169,9 @@ impl Subdiagnostic for ConsiderBorrowingParamHelp { |
| 1174 | 1169 | type_param_span |
| 1175 | 1170 | .push_span_label(span, msg!("consider borrowing this type parameter in the trait")); |
| 1176 | 1171 | } |
| 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 | ); | |
| 1178 | 1175 | diag.span_help(type_param_span, msg); |
| 1179 | 1176 | } |
| 1180 | 1177 | } |
| ... | ... | @@ -1218,9 +1215,9 @@ impl Subdiagnostic for DynTraitConstraintSuggestion { |
| 1218 | 1215 | self.ident.span, |
| 1219 | 1216 | msg!("calling this method introduces the `impl`'s `'static` requirement"), |
| 1220 | 1217 | ); |
| 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"); | |
| 1222 | 1219 | 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"); | |
| 1224 | 1221 | diag.span_suggestion_verbose( |
| 1225 | 1222 | self.span.shrink_to_hi(), |
| 1226 | 1223 | msg, |
| ... | ... | @@ -1230,38 +1227,6 @@ impl Subdiagnostic for DynTraitConstraintSuggestion { |
| 1230 | 1227 | } |
| 1231 | 1228 | } |
| 1232 | 1229 | |
| 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)] | |
| 1241 | pub 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 | ||
| 1265 | 1230 | pub struct ReqIntroducedLocations { |
| 1266 | 1231 | pub span: MultiSpan, |
| 1267 | 1232 | pub spans: Vec<Span>, |
| ... | ... | @@ -1283,8 +1248,7 @@ impl Subdiagnostic for ReqIntroducedLocations { |
| 1283 | 1248 | ); |
| 1284 | 1249 | } |
| 1285 | 1250 | 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"); | |
| 1288 | 1252 | diag.span_note(self.span, msg); |
| 1289 | 1253 | } |
| 1290 | 1254 | } |
| ... | ... | @@ -1724,8 +1688,7 @@ pub struct SuggestTuplePatternMany { |
| 1724 | 1688 | impl Subdiagnostic for SuggestTuplePatternMany { |
| 1725 | 1689 | fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) { |
| 1726 | 1690 | 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}`"); | |
| 1729 | 1692 | diag.multipart_suggestions( |
| 1730 | 1693 | message, |
| 1731 | 1694 | self.compatible_variants.into_iter().map(|variant| { |
compiler/rustc_trait_selection/src/errors/note_and_explain.rs+10-9| ... | ... | @@ -1,3 +1,4 @@ |
| 1 | use rustc_errors::formatting::DiagMessageAddArg; | |
| 1 | 2 | use rustc_errors::{Diag, EmissionGuarantee, IntoDiagArg, Subdiagnostic, msg}; |
| 2 | 3 | use rustc_hir::def_id::LocalDefId; |
| 3 | 4 | use rustc_middle::bug; |
| ... | ... | @@ -163,13 +164,7 @@ impl RegionExplanation<'_> { |
| 163 | 164 | |
| 164 | 165 | impl Subdiagnostic for RegionExplanation<'_> { |
| 165 | 166 | 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!( | |
| 173 | 168 | "{$pref_kind -> |
| 174 | 169 | *[should_not_happen] [{$pref_kind}] |
| 175 | 170 | [ref_valid_for] ...the reference is valid for |
| ... | ... | @@ -202,8 +197,14 @@ impl Subdiagnostic for RegionExplanation<'_> { |
| 202 | 197 | [continues] ... |
| 203 | 198 | [req_by_binding] {\" \"}as required by this binding |
| 204 | 199 | }" |
| 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(); | |
| 207 | 208 | if let Some(span) = self.desc.span { |
| 208 | 209 | diag.span_note(span, msg); |
| 209 | 210 | } 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 |
| 32 | 32 | |
| 33 | 33 | ENV TARGETS=arm-linux-androideabi |
| 34 | 34 | |
| 35 | ENV RUST_CONFIGURE_ARGS --android-ndk=/android/ndk/ | |
| 35 | ENV RUST_CONFIGURE_ARGS="--android-ndk=/android/ndk/" | |
| 36 | 36 | |
| 37 | ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target $TARGETS | |
| 37 | ENV SCRIPT="python3 ../x.py --stage 2 test --host= --target $TARGETS" | |
| 38 | 38 | |
| 39 | 39 | COPY scripts/sccache.sh /scripts/ |
| 40 | 40 | RUN sh /scripts/sccache.sh |
src/ci/docker/host-x86_64/armhf-gnu/Dockerfile+2-2| ... | ... | @@ -82,7 +82,7 @@ RUN sh /scripts/sccache.sh |
| 82 | 82 | |
| 83 | 83 | COPY static/gitconfig /etc/gitconfig |
| 84 | 84 | |
| 85 | ENV RUST_CONFIGURE_ARGS --qemu-armhf-rootfs=/tmp/rootfs | |
| 86 | ENV SCRIPT python3 ../x.py --stage 2 test --host='' --target arm-unknown-linux-gnueabihf | |
| 85 | ENV RUST_CONFIGURE_ARGS="--qemu-armhf-rootfs=/tmp/rootfs" | |
| 86 | ENV SCRIPT="python3 ../x.py --stage 2 test --host= --target arm-unknown-linux-gnueabihf" | |
| 87 | 87 | |
| 88 | 88 | ENV 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 \ |
| 27 | 27 | |
| 28 | 28 | ENV HOSTS=arm-unknown-linux-gnueabi |
| 29 | 29 | |
| 30 | ENV RUST_CONFIGURE_ARGS \ | |
| 31 | --enable-full-tools \ | |
| 30 | ENV RUST_CONFIGURE_ARGS="--enable-full-tools \ | |
| 32 | 31 | --disable-docs \ |
| 33 | 32 | --enable-sanitizers \ |
| 34 | --enable-profiler | |
| 35 | ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS | |
| 33 | --enable-profiler" | |
| 34 | ENV 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 |
| 18 | 18 | |
| 19 | 19 | ENV HOSTS=aarch64-unknown-linux-musl |
| 20 | 20 | |
| 21 | ENV RUST_CONFIGURE_ARGS \ | |
| 22 | --enable-full-tools \ | |
| 21 | ENV RUST_CONFIGURE_ARGS="--enable-full-tools \ | |
| 23 | 22 | --disable-docs \ |
| 24 | 23 | --musl-root-aarch64=/usr/local/aarch64-linux-musl \ |
| 25 | 24 | --enable-sanitizers \ |
| 26 | 25 | --enable-profiler \ |
| 27 | --set target.aarch64-unknown-linux-musl.crt-static=false | |
| 28 | ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS | |
| 26 | --set target.aarch64-unknown-linux-musl.crt-static=false" | |
| 27 | ENV 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 \ |
| 25 | 25 | |
| 26 | 26 | ENV HOSTS=arm-unknown-linux-gnueabihf |
| 27 | 27 | |
| 28 | ENV RUST_CONFIGURE_ARGS --enable-full-tools --enable-profiler --disable-docs | |
| 29 | ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS | |
| 28 | ENV RUST_CONFIGURE_ARGS="--enable-full-tools --enable-profiler --disable-docs" | |
| 29 | ENV 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 \ |
| 25 | 25 | |
| 26 | 26 | ENV HOSTS=armv7-unknown-linux-gnueabihf |
| 27 | 27 | |
| 28 | ENV RUST_CONFIGURE_ARGS --enable-full-tools --enable-profiler --disable-docs | |
| 29 | ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS | |
| 28 | ENV RUST_CONFIGURE_ARGS="--enable-full-tools --enable-profiler --disable-docs" | |
| 29 | ENV 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 \ |
| 40 | 40 | AR_armv7_unknown_linux_ohos=/opt/ohos-sdk/native/llvm/bin/llvm-ar \ |
| 41 | 41 | CXX_armv7_unknown_linux_ohos=/usr/local/bin/armv7-unknown-linux-ohos-clang++.sh |
| 42 | 42 | |
| 43 | ENV RUST_CONFIGURE_ARGS \ | |
| 44 | --enable-profiler \ | |
| 43 | ENV RUST_CONFIGURE_ARGS="--enable-profiler \ | |
| 45 | 44 | --disable-docs \ |
| 46 | 45 | --tools=cargo,clippy,rustdocs,rustfmt,rust-analyzer,rust-analyzer-proc-macro-srv,analysis,src,wasm-component-ld \ |
| 47 | 46 | --enable-extended \ |
| 48 | --enable-sanitizers | |
| 47 | --enable-sanitizers" | |
| 49 | 48 | |
| 50 | ENV SCRIPT python3 ../x.py dist --host=$TARGETS --target $TARGETS | |
| 49 | ENV SCRIPT="python3 ../x.py dist --host=$TARGETS --target $TARGETS" | |
| 51 | 50 | |
| 52 | 51 | COPY scripts/sccache.sh /scripts/ |
| 53 | 52 | RUN sh /scripts/sccache.sh |
src/tools/tidy/src/issues.txt-8| ... | ... | @@ -1726,14 +1726,6 @@ ui/moves/issue-46099-move-in-macro.rs |
| 1726 | 1726 | ui/moves/issue-72649-uninit-in-loop.rs |
| 1727 | 1727 | ui/moves/issue-75904-move-closure-loop.rs |
| 1728 | 1728 | ui/moves/issue-99470-move-out-of-some.rs |
| 1729 | ui/never_type/issue-10176.rs | |
| 1730 | ui/never_type/issue-13352.rs | |
| 1731 | ui/never_type/issue-2149.rs | |
| 1732 | ui/never_type/issue-44402.rs | |
| 1733 | ui/never_type/issue-51506.rs | |
| 1734 | ui/never_type/issue-52443.rs | |
| 1735 | ui/never_type/issue-5500-1.rs | |
| 1736 | ui/never_type/issue-96335.rs | |
| 1737 | 1729 | ui/nll/closure-requirements/issue-58127-mutliple-requirements.rs |
| 1738 | 1730 | ui/nll/issue-112604-closure-output-normalize.rs |
| 1739 | 1731 | ui/nll/issue-16223.rs |
tests/run-make/linker-warning/fake-linker.sh deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | #!/bin/sh | |
| 2 | ||
| 3 | code=0 | |
| 4 | while ! [ $# = 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 | |
| 15 | done | |
| 16 | ||
| 17 | exit $code |
tests/run-make/macos-deployment-target-warning/foo.c created+1| ... | ... | @@ -0,0 +1 @@ |
| 1 | void foo() {} |
tests/run-make/macos-deployment-target-warning/main.rs created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | #![warn(linker_info, linker_messages)] | |
| 2 | unsafe extern "C" { | |
| 3 | safe fn foo(); | |
| 4 | } | |
| 5 | ||
| 6 | fn 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 | ||
| 4 | use run_make_support::external_deps::c_cxx_compiler::cc; | |
| 5 | use run_make_support::external_deps::llvm::llvm_ar; | |
| 6 | use run_make_support::{bare_rustc, diff}; | |
| 7 | ||
| 8 | fn 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 @@ |
| 1 | warning: 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 | | | |
| 4 | note: the lint level is defined here | |
| 5 | --> main.rs:1:9 | |
| 6 | | | |
| 7 | 1 | #![warn(linker_info, linker_messages)] | |
| 8 | | ^^^^^^^^^^^ | |
| 9 | ||
| 10 | warning: 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 | ||
| 3 | fn 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 | |
| 6 | fn main() {} |
tests/run-make/windows-gnu-corrupt-drective/rmake.rs created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | //@ only-windows-gnu | |
| 2 | ||
| 3 | use run_make_support::{bare_rustc, rustc}; | |
| 4 | ||
| 5 | fn 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 |
| 35 | 35 | LL | struct NotIntoDiagArg; |
| 36 | 36 | | ^^^^^^^^^^^^^^^^^^^^^ |
| 37 | 37 | = help: normalized in stderr |
| 38 | note: 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) | |
| 44 | 38 | |
| 45 | 39 | error: aborting due to 2 previous errors |
| 46 | 40 |
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 | |
| 6 | fn main() {} |
tests/ui/linking/macos-ignoring-duplicate.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error: ld: warning: ignoring duplicate libraries: '-lc' | |
| 2 | ||
| 3 | | | |
| 4 | note: the lint level is defined here | |
| 5 | --> $DIR/macos-ignoring-duplicate.rs:4:9 | |
| 6 | | | |
| 7 | LL | #![deny(linker_info)] | |
| 8 | | ^^^^^^^^^^^ | |
| 9 | ||
| 10 | error: 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 | |
| 6 | fn main() {} |
tests/ui/linking/macos-search-path.stderr created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | error: ld: warning: search path '/no/such/file/or/directory' not found | |
| 2 | ||
| 3 | | | |
| 4 | note: the lint level is defined here | |
| 5 | --> $DIR/macos-search-path.rs:4:9 | |
| 6 | | | |
| 7 | LL | #![deny(linker_info)] | |
| 8 | | ^^^^^^^^^^^ | |
| 9 | ||
| 10 | error: aborting due to 1 previous error | |
| 11 |
tests/ui/lint/linker-warning.stderr+1-1| ... | ... | @@ -20,7 +20,7 @@ warning: unused attribute |
| 20 | 20 | LL | #![allow(linker_messages)] |
| 21 | 21 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute |
| 22 | 22 | | |
| 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 | |
| 24 | 24 | |
| 25 | 25 | warning: 2 warnings emitted |
| 26 | 26 |
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 | ||
| 7 | fn 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 | ||
| 6 | fn 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 | ||
| 7 | fn 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 | ||
| 6 | fn 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 | ||
| 5 | fn foo(x: !) -> ! { | |
| 6 | x | |
| 7 | } | |
| 8 | ||
| 9 | fn 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 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/call-fn-never-arg-wrong-type.rs:10:9 | |
| 3 | | | |
| 4 | LL | foo("wow"); | |
| 5 | | --- ^^^^^ expected `!`, found `&str` | |
| 6 | | | | |
| 7 | | arguments to this function are incorrect | |
| 8 | | | |
| 9 | = note: expected type `!` | |
| 10 | found reference `&'static str` | |
| 11 | note: function defined here | |
| 12 | --> $DIR/call-fn-never-arg-wrong-type.rs:5:4 | |
| 13 | | | |
| 14 | LL | fn foo(x: !) -> ! { | |
| 15 | | ^^^ ---- | |
| 16 | ||
| 17 | error: aborting due to 1 previous error | |
| 18 | ||
| 19 | For 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 | ||
| 8 | fn foo(x: !) -> ! { | |
| 9 | x | |
| 10 | } | |
| 11 | ||
| 12 | fn 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 | ||
| 7 | fn 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 | ||
| 9 | trait StringifyType { | |
| 10 | fn stringify_type() -> &'static str; | |
| 11 | } | |
| 12 | ||
| 13 | impl StringifyType for ! { | |
| 14 | fn stringify_type() -> &'static str { | |
| 15 | "!" | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | fn maybe_stringify<T: StringifyType>(opt: Option<T>) -> &'static str { | |
| 20 | match opt { | |
| 21 | Some(_) => T::stringify_type(), | |
| 22 | None => "none", | |
| 23 | } | |
| 24 | } | |
| 25 | ||
| 26 | fn 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 ! | |
| 2 | None 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 | ||
| 5 | fn 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 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/never-assign-wrong-type.rs:6:16 | |
| 3 | | | |
| 4 | LL | let x: ! = "hello"; | |
| 5 | | - ^^^^^^^ expected `!`, found `&str` | |
| 6 | | | | |
| 7 | | expected due to this | |
| 8 | | | |
| 9 | = note: expected type `!` | |
| 10 | found reference `&'static str` | |
| 11 | ||
| 12 | error: aborting due to 1 previous error | |
| 13 | ||
| 14 | For 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 | ||
| 7 | trait Foo { | |
| 8 | type Wow; | |
| 9 | ||
| 10 | fn smeg(&self) -> Self::Wow; | |
| 11 | } | |
| 12 | ||
| 13 | struct Blah; | |
| 14 | impl Foo for Blah { | |
| 15 | type Wow = !; | |
| 16 | fn smeg(&self) -> ! { | |
| 17 | panic!("kapow!"); | |
| 18 | } | |
| 19 | } | |
| 20 | ||
| 21 | fn 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 | ||
| 10 | fn 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 | ||
| 7 | struct Wub; | |
| 8 | ||
| 9 | impl PartialEq<!> for Wub { | |
| 10 | fn eq(&self, other: &!) -> bool { | |
| 11 | *other | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | fn 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 | ||
| 3 | trait X<const N: i32> {} | |
| 4 | ||
| 5 | fn hello<T: X<{ fn hello() -> ! { loop {} } 1 }>>() {} | |
| 6 | ||
| 7 | fn 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 | ||
| 10 | fn never_direct(x: !) { | |
| 11 | x; | |
| 12 | } | |
| 13 | ||
| 14 | fn never_ref_pat(ref x: !) { | |
| 15 | *x; | |
| 16 | } | |
| 17 | ||
| 18 | fn never_ref(x: &!) { | |
| 19 | let &y = x; | |
| 20 | y; | |
| 21 | } | |
| 22 | ||
| 23 | fn never_pointer(x: *const !) { | |
| 24 | unsafe { | |
| 25 | *x; | |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 29 | fn never_slice(x: &[!]) { | |
| 30 | x[0]; | |
| 31 | } | |
| 32 | ||
| 33 | fn never_match(x: Result<(), !>) { | |
| 34 | match x { | |
| 35 | Ok(_) => {}, | |
| 36 | Err(_) => {}, | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | pub 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 | ||
| 5 | fn 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 | ||
| 8 | struct Foo; | |
| 9 | ||
| 10 | pub fn f(x: !) -> ! { | |
| 11 | x | |
| 12 | } | |
| 13 | ||
| 14 | pub 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 | ||
| 23 | fn 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 | ||
| 7 | fn call_another_fn<T, F: FnOnce() -> T>(f: F) -> T { | |
| 8 | f() | |
| 9 | } | |
| 10 | ||
| 11 | fn wub() -> ! { | |
| 12 | panic!("aah!"); | |
| 13 | } | |
| 14 | ||
| 15 | fn 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 | ||
| 5 | fn foo(x: !) -> ! { | |
| 6 | x | |
| 7 | } | |
| 8 | ||
| 9 | fn 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 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/call-fn-never-arg-wrong-type.rs:10:9 | |
| 3 | | | |
| 4 | LL | foo("wow"); | |
| 5 | | --- ^^^^^ expected `!`, found `&str` | |
| 6 | | | | |
| 7 | | arguments to this function are incorrect | |
| 8 | | | |
| 9 | = note: expected type `!` | |
| 10 | found reference `&'static str` | |
| 11 | note: function defined here | |
| 12 | --> $DIR/call-fn-never-arg-wrong-type.rs:5:4 | |
| 13 | | | |
| 14 | LL | fn foo(x: !) -> ! { | |
| 15 | | ^^^ ---- | |
| 16 | ||
| 17 | error: aborting due to 1 previous error | |
| 18 | ||
| 19 | For 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 | ||
| 8 | fn foo(x: !) -> ! { | |
| 9 | x | |
| 10 | } | |
| 11 | ||
| 12 | fn 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 | ||
| 7 | fn 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 @@ |
| 1 | Future incompatibility report: Future breakage diagnostic: | |
| 2 | warning: this function depends on never type fallback being `()` | |
| 3 | --> $DIR/defaulted-never-note.rs:38:1 | |
| 4 | | | |
| 5 | LL | fn main() { | |
| 6 | | ^^^^^^^^^ | |
| 7 | | | |
| 8 | = help: specify the types explicitly | |
| 9 | note: in edition 2024, the requirement `!: OnlyUnit` will fail | |
| 10 | --> $DIR/defaulted-never-note.rs:40:19 | |
| 11 | | | |
| 12 | LL | requires_unit(x); | |
| 13 | | ^ | |
| 14 | help: use `()` annotations to avoid fallback changes | |
| 15 | | | |
| 16 | LL | let x: () = return; | |
| 17 | | ++++ | |
| 18 |
tests/ui/never_type/defaulted-never-note.e2024.stderr deleted-62| ... | ... | @@ -1,62 +0,0 @@ |
| 1 | error[E0277]: the trait bound `!: OnlyUnit` is not satisfied | |
| 2 | --> $DIR/defaulted-never-note.rs:40:19 | |
| 3 | | | |
| 4 | LL | requires_unit(x); | |
| 5 | | ------------- ^ the trait `OnlyUnit` is not implemented for `!` | |
| 6 | | | | |
| 7 | | required by a bound introduced by this call | |
| 8 | | | |
| 9 | help: the trait `OnlyUnit` is implemented for `()` | |
| 10 | --> $DIR/defaulted-never-note.rs:13:1 | |
| 11 | | | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `requires_unit` | |
| 17 | --> $DIR/defaulted-never-note.rs:16:26 | |
| 18 | | | |
| 19 | LL | fn requires_unit(_: impl OnlyUnit) {} | |
| 20 | | ^^^^^^^^ required by this bound in `requires_unit` | |
| 21 | ||
| 22 | error[E0277]: the trait bound `!: OnlyU32` is not satisfied | |
| 23 | --> $DIR/defaulted-never-note.rs:48:18 | |
| 24 | | | |
| 25 | LL | requires_u32(x); | |
| 26 | | ------------ ^ the trait `OnlyU32` is not implemented for `!` | |
| 27 | | | | |
| 28 | | required by a bound introduced by this call | |
| 29 | | | |
| 30 | help: the trait `OnlyU32` is implemented for `u32` | |
| 31 | --> $DIR/defaulted-never-note.rs:23:1 | |
| 32 | | | |
| 33 | LL | impl OnlyU32 for u32 {} | |
| 34 | | ^^^^^^^^^^^^^^^^^^^^ | |
| 35 | note: required by a bound in `requires_u32` | |
| 36 | --> $DIR/defaulted-never-note.rs:26:25 | |
| 37 | | | |
| 38 | LL | fn requires_u32(_: impl OnlyU32) {} | |
| 39 | | ^^^^^^^ required by this bound in `requires_u32` | |
| 40 | ||
| 41 | error[E0277]: the trait bound `!: Nothing` is not satisfied | |
| 42 | --> $DIR/defaulted-never-note.rs:54:22 | |
| 43 | | | |
| 44 | LL | requires_nothing(x); | |
| 45 | | ---------------- ^ the trait `Nothing` is not implemented for `!` | |
| 46 | | | | |
| 47 | | required by a bound introduced by this call | |
| 48 | | | |
| 49 | help: this trait has no implementations, consider adding one | |
| 50 | --> $DIR/defaulted-never-note.rs:31:1 | |
| 51 | | | |
| 52 | LL | trait Nothing {} | |
| 53 | | ^^^^^^^^^^^^^ | |
| 54 | note: required by a bound in `requires_nothing` | |
| 55 | --> $DIR/defaulted-never-note.rs:34:29 | |
| 56 | | | |
| 57 | LL | fn requires_nothing(_: impl Nothing) {} | |
| 58 | | ^^^^^^^ required by this bound in `requires_nothing` | |
| 59 | ||
| 60 | error: aborting due to 3 previous errors | |
| 61 | ||
| 62 | For 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 | ||
| 11 | trait OnlyUnit {} | |
| 12 | ||
| 13 | impl OnlyUnit for () {} | |
| 14 | //[e2024]~^ help: trait `OnlyUnit` is implemented for `()` | |
| 15 | ||
| 16 | fn 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 | ||
| 21 | trait OnlyU32 {} | |
| 22 | ||
| 23 | impl OnlyU32 for u32 {} | |
| 24 | //[e2024]~^ help: the trait `OnlyU32` is implemented for `u32` | |
| 25 | ||
| 26 | fn 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 | ||
| 31 | trait Nothing {} | |
| 32 | //[e2024]~^ help: this trait has no implementations, consider adding one | |
| 33 | ||
| 34 | fn 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 | ||
| 38 | fn 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 @@ |
| 1 | fn main() { | |
| 2 | def(); | |
| 3 | _ = question_mark(); | |
| 4 | } | |
| 5 | ||
| 6 | fn 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> | |
| 17 | fn 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 | ||
| 24 | fn 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 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/dependency-on-fallback-to-unit.rs:6:1 | |
| 3 | | | |
| 4 | LL | fn def() { | |
| 5 | | ^^^^^^^^ | |
| 6 | | | |
| 7 | = help: specify the types explicitly | |
| 8 | note: in edition 2024, the requirement `!: Default` will fail | |
| 9 | --> $DIR/dependency-on-fallback-to-unit.rs:10:19 | |
| 10 | | | |
| 11 | LL | 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL - false => <_>::default(), | |
| 19 | LL + false => <()>::default(), | |
| 20 | | | |
| 21 | ||
| 22 | error: this function depends on never type fallback being `()` | |
| 23 | --> $DIR/dependency-on-fallback-to-unit.rs:17:1 | |
| 24 | | | |
| 25 | LL | fn question_mark() -> Result<(), ()> { | |
| 26 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 27 | | | |
| 28 | = help: specify the types explicitly | |
| 29 | note: in edition 2024, the requirement `!: Default` will fail | |
| 30 | --> $DIR/dependency-on-fallback-to-unit.rs:20:5 | |
| 31 | | | |
| 32 | LL | 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> | |
| 36 | help: use `()` annotations to avoid fallback changes | |
| 37 | | | |
| 38 | LL | deserialize::<()>()?; | |
| 39 | | ++++++ | |
| 40 | ||
| 41 | error: aborting due to 2 previous errors | |
| 42 | ||
| 43 | Future incompatibility report: Future breakage diagnostic: | |
| 44 | error: this function depends on never type fallback being `()` | |
| 45 | --> $DIR/dependency-on-fallback-to-unit.rs:6:1 | |
| 46 | | | |
| 47 | LL | fn def() { | |
| 48 | | ^^^^^^^^ | |
| 49 | | | |
| 50 | = help: specify the types explicitly | |
| 51 | note: in edition 2024, the requirement `!: Default` will fail | |
| 52 | --> $DIR/dependency-on-fallback-to-unit.rs:10:19 | |
| 53 | | | |
| 54 | LL | 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 | |
| 59 | help: use `()` annotations to avoid fallback changes | |
| 60 | | | |
| 61 | LL - false => <_>::default(), | |
| 62 | LL + false => <()>::default(), | |
| 63 | | | |
| 64 | ||
| 65 | Future breakage diagnostic: | |
| 66 | error: this function depends on never type fallback being `()` | |
| 67 | --> $DIR/dependency-on-fallback-to-unit.rs:17:1 | |
| 68 | | | |
| 69 | LL | fn question_mark() -> Result<(), ()> { | |
| 70 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 71 | | | |
| 72 | = help: specify the types explicitly | |
| 73 | note: in edition 2024, the requirement `!: Default` will fail | |
| 74 | --> $DIR/dependency-on-fallback-to-unit.rs:20:5 | |
| 75 | | | |
| 76 | LL | 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 | |
| 81 | help: use `()` annotations to avoid fallback changes | |
| 82 | | | |
| 83 | LL | deserialize::<()>()?; | |
| 84 | | ++++++ | |
| 85 |
tests/ui/never_type/diverging-fallback-unconstrained-return.e2021.stderr deleted-43| ... | ... | @@ -1,43 +0,0 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/diverging-fallback-unconstrained-return.rs:26:1 | |
| 3 | | | |
| 4 | LL | fn main() { | |
| 5 | | ^^^^^^^^^ | |
| 6 | | | |
| 7 | = help: specify the types explicitly | |
| 8 | note: in edition 2024, the requirement `!: UnitReturn` will fail | |
| 9 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 10 | | | |
| 11 | LL | 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL | let _: () = if true { unconstrained_return() } else { panic!() }; | |
| 19 | | ++++ | |
| 20 | ||
| 21 | error: aborting due to 1 previous error | |
| 22 | ||
| 23 | Future incompatibility report: Future breakage diagnostic: | |
| 24 | error: this function depends on never type fallback being `()` | |
| 25 | --> $DIR/diverging-fallback-unconstrained-return.rs:26:1 | |
| 26 | | | |
| 27 | LL | fn main() { | |
| 28 | | ^^^^^^^^^ | |
| 29 | | | |
| 30 | = help: specify the types explicitly | |
| 31 | note: in edition 2024, the requirement `!: UnitReturn` will fail | |
| 32 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 33 | | | |
| 34 | LL | 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 | |
| 39 | help: use `()` annotations to avoid fallback changes | |
| 40 | | | |
| 41 | LL | 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 @@ |
| 1 | error[E0277]: the trait bound `!: UnitReturn` is not satisfied | |
| 2 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 3 | | | |
| 4 | LL | let _ = if true { unconstrained_return() } else { panic!() }; | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^ the trait `UnitReturn` is not implemented for `!` | |
| 6 | | | |
| 7 | help: the following other types implement trait `UnitReturn` | |
| 8 | --> $DIR/diverging-fallback-unconstrained-return.rs:15:1 | |
| 9 | | | |
| 10 | LL | impl UnitReturn for i32 {} | |
| 11 | | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `unconstrained_return` | |
| 17 | --> $DIR/diverging-fallback-unconstrained-return.rs:18:28 | |
| 18 | | | |
| 19 | LL | fn unconstrained_return<T: UnitReturn>() -> T { | |
| 20 | | ^^^^^^^^^^ required by this bound in `unconstrained_return` | |
| 21 | ||
| 22 | error: aborting due to 1 previous error | |
| 23 | ||
| 24 | For 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 @@ |
| 1 | error[E0277]: the trait bound `!: UnitReturn` is not satisfied | |
| 2 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 3 | | | |
| 4 | LL | let _ = if true { unconstrained_return() } else { panic!() }; | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^ the trait `UnitReturn` is not implemented for `!` | |
| 6 | | | |
| 7 | help: the following other types implement trait `UnitReturn` | |
| 8 | --> $DIR/diverging-fallback-unconstrained-return.rs:15:1 | |
| 9 | | | |
| 10 | LL | impl UnitReturn for i32 {} | |
| 11 | | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `unconstrained_return` | |
| 17 | --> $DIR/diverging-fallback-unconstrained-return.rs:18:28 | |
| 18 | | | |
| 19 | LL | fn unconstrained_return<T: UnitReturn>() -> T { | |
| 20 | | ^^^^^^^^^^ required by this bound in `unconstrained_return` | |
| 21 | ||
| 22 | error: aborting due to 1 previous error | |
| 23 | ||
| 24 | For 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 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/diverging-fallback-unconstrained-return.rs:26:1 | |
| 3 | | | |
| 4 | LL | 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 | |
| 10 | note: in edition 2024, the requirement `!: UnitReturn` will fail | |
| 11 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 12 | | | |
| 13 | LL | 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL | let _: () = if true { unconstrained_return() } else { panic!() }; | |
| 19 | | ++++ | |
| 20 | ||
| 21 | error: aborting due to 1 previous error | |
| 22 | ||
| 23 | Future incompatibility report: Future breakage diagnostic: | |
| 24 | error: this function depends on never type fallback being `()` | |
| 25 | --> $DIR/diverging-fallback-unconstrained-return.rs:26:1 | |
| 26 | | | |
| 27 | LL | 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 | |
| 33 | note: in edition 2024, the requirement `!: UnitReturn` will fail | |
| 34 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 35 | | | |
| 36 | LL | 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 | |
| 39 | help: use `()` annotations to avoid fallback changes | |
| 40 | | | |
| 41 | LL | 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 | ||
| 12 | fn make_unit() {} | |
| 13 | ||
| 14 | trait UnitReturn {} | |
| 15 | impl UnitReturn for i32 {} | |
| 16 | impl UnitReturn for () {} | |
| 17 | ||
| 18 | fn 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 | ||
| 26 | fn 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 | ||
| 8 | fn g() { | |
| 9 | &panic!() //~ ERROR mismatched types | |
| 10 | } | |
| 11 | ||
| 12 | fn f() -> isize { | |
| 13 | (return 1, return 2) //~ ERROR mismatched types | |
| 14 | } | |
| 15 | ||
| 16 | fn main() {} |
tests/ui/never_type/diverging-tuple-parts-39485.stderr deleted-32| ... | ... | @@ -1,32 +0,0 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/diverging-tuple-parts-39485.rs:9:5 | |
| 3 | | | |
| 4 | LL | &panic!() | |
| 5 | | ^^^^^^^^^ expected `()`, found `&_` | |
| 6 | | | |
| 7 | = note: expected unit type `()` | |
| 8 | found reference `&_` | |
| 9 | help: a return type might be missing here | |
| 10 | | | |
| 11 | LL | fn g() -> _ { | |
| 12 | | ++++ | |
| 13 | help: consider removing the borrow | |
| 14 | | | |
| 15 | LL - &panic!() | |
| 16 | LL + panic!() | |
| 17 | | | |
| 18 | ||
| 19 | error[E0308]: mismatched types | |
| 20 | --> $DIR/diverging-tuple-parts-39485.rs:13:5 | |
| 21 | | | |
| 22 | LL | fn f() -> isize { | |
| 23 | | ----- expected `isize` because of return type | |
| 24 | LL | (return 1, return 2) | |
| 25 | | ^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `(!, !)` | |
| 26 | | | |
| 27 | = note: expected type `isize` | |
| 28 | found tuple `(!, !)` | |
| 29 | ||
| 30 | error: aborting due to 2 previous errors | |
| 31 | ||
| 32 | For 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 @@ |
| 1 | fn create_ok_default<C>() -> Result<C, ()> | |
| 2 | where | |
| 3 | C: Default, | |
| 4 | { | |
| 5 | Ok(C::default()) | |
| 6 | } | |
| 7 | ||
| 8 | fn 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 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/dont-suggest-turbofish-from-expansion.rs:8:1 | |
| 3 | | | |
| 4 | LL | fn main() -> Result<(), ()> { | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 6 | | | |
| 7 | = help: specify the types explicitly | |
| 8 | note: in edition 2024, the requirement `!: Default` will fail | |
| 9 | --> $DIR/dont-suggest-turbofish-from-expansion.rs:12:23 | |
| 10 | | | |
| 11 | LL | 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL | let created: () = create_ok_default()?; | |
| 19 | | ++++ | |
| 20 | ||
| 21 | error: aborting due to 1 previous error | |
| 22 | ||
| 23 | Future incompatibility report: Future breakage diagnostic: | |
| 24 | error: this function depends on never type fallback being `()` | |
| 25 | --> $DIR/dont-suggest-turbofish-from-expansion.rs:8:1 | |
| 26 | | | |
| 27 | LL | fn main() -> Result<(), ()> { | |
| 28 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 29 | | | |
| 30 | = help: specify the types explicitly | |
| 31 | note: in edition 2024, the requirement `!: Default` will fail | |
| 32 | --> $DIR/dont-suggest-turbofish-from-expansion.rs:12:23 | |
| 33 | | | |
| 34 | LL | 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 | |
| 39 | help: use `()` annotations to avoid fallback changes | |
| 40 | | | |
| 41 | LL | 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 | ||
| 8 | fn ice(a: !) { | |
| 9 | a == a; | |
| 10 | } | |
| 11 | ||
| 12 | fn 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 | ||
| 7 | fn f() { | |
| 8 | let _x = match true { | |
| 9 | true => { 10 } | |
| 10 | false => { return } | |
| 11 | }; | |
| 12 | } | |
| 13 | ||
| 14 | pub fn main() { } |
tests/ui/never_type/fallback-closure-ret.e2021.stderr deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | Future incompatibility report: Future breakage diagnostic: | |
| 2 | warning: this function depends on never type fallback being `()` | |
| 3 | --> $DIR/fallback-closure-ret.rs:21:1 | |
| 4 | | | |
| 5 | LL | fn main() { | |
| 6 | | ^^^^^^^^^ | |
| 7 | | | |
| 8 | = help: specify the types explicitly | |
| 9 | note: in edition 2024, the requirement `!: Bar` will fail | |
| 10 | --> $DIR/fallback-closure-ret.rs:22:5 | |
| 11 | | | |
| 12 | LL | foo(|| panic!()); | |
| 13 | | ^^^^^^^^^^^^^^^^ | |
| 14 | help: use `()` annotations to avoid fallback changes | |
| 15 | | | |
| 16 | LL | foo::<()>(|| panic!()); | |
| 17 | | ++++++ | |
| 18 |
tests/ui/never_type/fallback-closure-ret.e2024.stderr deleted-24| ... | ... | @@ -1,24 +0,0 @@ |
| 1 | error[E0277]: the trait bound `!: Bar` is not satisfied | |
| 2 | --> $DIR/fallback-closure-ret.rs:22:5 | |
| 3 | | | |
| 4 | LL | foo(|| panic!()); | |
| 5 | | ^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `!` | |
| 6 | | | |
| 7 | help: the following other types implement trait `Bar` | |
| 8 | --> $DIR/fallback-closure-ret.rs:15:1 | |
| 9 | | | |
| 10 | LL | impl Bar for () {} | |
| 11 | | ^^^^^^^^^^^^^^^ `()` | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `foo` | |
| 17 | --> $DIR/fallback-closure-ret.rs:18:11 | |
| 18 | | | |
| 19 | LL | fn foo<R: Bar>(_: impl Fn() -> R) {} | |
| 20 | | ^^^ required by this bound in `foo` | |
| 21 | ||
| 22 | error: aborting due to 1 previous error | |
| 23 | ||
| 24 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/never_type/fallback-closure-ret.fallback.stderr deleted-24| ... | ... | @@ -1,24 +0,0 @@ |
| 1 | error[E0277]: the trait bound `!: Bar` is not satisfied | |
| 2 | --> $DIR/fallback-closure-ret.rs:18:5 | |
| 3 | | | |
| 4 | LL | foo(|| panic!()); | |
| 5 | | ^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `!` | |
| 6 | | | |
| 7 | help: the following other types implement trait `Bar` | |
| 8 | --> $DIR/fallback-closure-ret.rs:12:1 | |
| 9 | | | |
| 10 | LL | impl Bar for () {} | |
| 11 | | ^^^^^^^^^^^^^^^ `()` | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `foo` | |
| 17 | --> $DIR/fallback-closure-ret.rs:15:11 | |
| 18 | | | |
| 19 | LL | fn foo<R: Bar>(_: impl Fn() -> R) {} | |
| 20 | | ^^^ required by this bound in `foo` | |
| 21 | ||
| 22 | error: aborting due to 1 previous error | |
| 23 | ||
| 24 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/never_type/fallback-closure-ret.nofallback.stderr deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | Future incompatibility report: Future breakage diagnostic: | |
| 2 | warning: this function depends on never type fallback being `()` | |
| 3 | --> $DIR/fallback-closure-ret.rs:17:1 | |
| 4 | | | |
| 5 | LL | fn main() { | |
| 6 | | ^^^^^^^^^ | |
| 7 | | | |
| 8 | = help: specify the types explicitly | |
| 9 | note: in edition 2024, the requirement `!: Bar` will fail | |
| 10 | --> $DIR/fallback-closure-ret.rs:18:5 | |
| 11 | | | |
| 12 | LL | foo(|| panic!()); | |
| 13 | | ^^^^^^^^^^^^^^^^ | |
| 14 | help: use `()` annotations to avoid fallback changes | |
| 15 | | | |
| 16 | LL | 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 | ||
| 14 | trait Bar {} | |
| 15 | impl Bar for () {} | |
| 16 | impl Bar for u32 {} | |
| 17 | ||
| 18 | fn foo<R: Bar>(_: impl Fn() -> R) {} | |
| 19 | ||
| 20 | #[cfg_attr(e2021, expect(dependency_on_unit_never_type_fallback))] | |
| 21 | fn 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 @@ |
| 1 | error[E0271]: expected `{closure@fallback-closure-wrap.rs:16:40}` to return `()`, but it returns `!` | |
| 2 | --> $DIR/fallback-closure-wrap.rs:17:9 | |
| 3 | | | |
| 4 | LL | let error = Closure::wrap(Box::new(move || { | |
| 5 | | ------- this closure | |
| 6 | LL | 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 | ||
| 13 | error: aborting due to 1 previous error | |
| 14 | ||
| 15 | For more information about this error, try `rustc --explain E0271`. |
tests/ui/never_type/fallback-closure-wrap.fallback.stderr deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | error[E0271]: expected `{closure@fallback-closure-wrap.rs:17:40}` to return `()`, but it returns `!` | |
| 2 | --> $DIR/fallback-closure-wrap.rs:18:9 | |
| 3 | | | |
| 4 | LL | let error = Closure::wrap(Box::new(move || { | |
| 5 | | ------- this closure | |
| 6 | LL | 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 | ||
| 13 | error: aborting due to 1 previous error | |
| 14 | ||
| 15 | For 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 | ||
| 13 | use std::marker::PhantomData; | |
| 14 | ||
| 15 | fn 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 | ||
| 22 | struct Closure<T: ?Sized>(PhantomData<T>); | |
| 23 | ||
| 24 | impl<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 @@ |
| 1 | Future incompatibility report: Future breakage diagnostic: | |
| 2 | warning: this function depends on never type fallback being `()` | |
| 3 | --> $DIR/defaulted-never-note.rs:38:1 | |
| 4 | | | |
| 5 | LL | fn main() { | |
| 6 | | ^^^^^^^^^ | |
| 7 | | | |
| 8 | = help: specify the types explicitly | |
| 9 | note: in edition 2024, the requirement `!: OnlyUnit` will fail | |
| 10 | --> $DIR/defaulted-never-note.rs:40:19 | |
| 11 | | | |
| 12 | LL | requires_unit(x); | |
| 13 | | ^ | |
| 14 | help: use `()` annotations to avoid fallback changes | |
| 15 | | | |
| 16 | LL | let x: () = return; | |
| 17 | | ++++ | |
| 18 |
tests/ui/never_type/fallback_change/defaulted-never-note.e2024.stderr created+62| ... | ... | @@ -0,0 +1,62 @@ |
| 1 | error[E0277]: the trait bound `!: OnlyUnit` is not satisfied | |
| 2 | --> $DIR/defaulted-never-note.rs:40:19 | |
| 3 | | | |
| 4 | LL | requires_unit(x); | |
| 5 | | ------------- ^ the trait `OnlyUnit` is not implemented for `!` | |
| 6 | | | | |
| 7 | | required by a bound introduced by this call | |
| 8 | | | |
| 9 | help: the trait `OnlyUnit` is implemented for `()` | |
| 10 | --> $DIR/defaulted-never-note.rs:13:1 | |
| 11 | | | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `requires_unit` | |
| 17 | --> $DIR/defaulted-never-note.rs:16:26 | |
| 18 | | | |
| 19 | LL | fn requires_unit(_: impl OnlyUnit) {} | |
| 20 | | ^^^^^^^^ required by this bound in `requires_unit` | |
| 21 | ||
| 22 | error[E0277]: the trait bound `!: OnlyU32` is not satisfied | |
| 23 | --> $DIR/defaulted-never-note.rs:48:18 | |
| 24 | | | |
| 25 | LL | requires_u32(x); | |
| 26 | | ------------ ^ the trait `OnlyU32` is not implemented for `!` | |
| 27 | | | | |
| 28 | | required by a bound introduced by this call | |
| 29 | | | |
| 30 | help: the trait `OnlyU32` is implemented for `u32` | |
| 31 | --> $DIR/defaulted-never-note.rs:23:1 | |
| 32 | | | |
| 33 | LL | impl OnlyU32 for u32 {} | |
| 34 | | ^^^^^^^^^^^^^^^^^^^^ | |
| 35 | note: required by a bound in `requires_u32` | |
| 36 | --> $DIR/defaulted-never-note.rs:26:25 | |
| 37 | | | |
| 38 | LL | fn requires_u32(_: impl OnlyU32) {} | |
| 39 | | ^^^^^^^ required by this bound in `requires_u32` | |
| 40 | ||
| 41 | error[E0277]: the trait bound `!: Nothing` is not satisfied | |
| 42 | --> $DIR/defaulted-never-note.rs:54:22 | |
| 43 | | | |
| 44 | LL | requires_nothing(x); | |
| 45 | | ---------------- ^ the trait `Nothing` is not implemented for `!` | |
| 46 | | | | |
| 47 | | required by a bound introduced by this call | |
| 48 | | | |
| 49 | help: this trait has no implementations, consider adding one | |
| 50 | --> $DIR/defaulted-never-note.rs:31:1 | |
| 51 | | | |
| 52 | LL | trait Nothing {} | |
| 53 | | ^^^^^^^^^^^^^ | |
| 54 | note: required by a bound in `requires_nothing` | |
| 55 | --> $DIR/defaulted-never-note.rs:34:29 | |
| 56 | | | |
| 57 | LL | fn requires_nothing(_: impl Nothing) {} | |
| 58 | | ^^^^^^^ required by this bound in `requires_nothing` | |
| 59 | ||
| 60 | error: aborting due to 3 previous errors | |
| 61 | ||
| 62 | For 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 | ||
| 11 | trait OnlyUnit {} | |
| 12 | ||
| 13 | impl OnlyUnit for () {} | |
| 14 | //[e2024]~^ help: trait `OnlyUnit` is implemented for `()` | |
| 15 | ||
| 16 | fn 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 | ||
| 21 | trait OnlyU32 {} | |
| 22 | ||
| 23 | impl OnlyU32 for u32 {} | |
| 24 | //[e2024]~^ help: the trait `OnlyU32` is implemented for `u32` | |
| 25 | ||
| 26 | fn 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 | ||
| 31 | trait Nothing {} | |
| 32 | //[e2024]~^ help: this trait has no implementations, consider adding one | |
| 33 | ||
| 34 | fn 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 | ||
| 38 | fn 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 @@ |
| 1 | fn main() { | |
| 2 | def(); | |
| 3 | _ = question_mark(); | |
| 4 | } | |
| 5 | ||
| 6 | fn 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> | |
| 17 | fn 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 | ||
| 24 | fn 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 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/dependency-on-fallback-to-unit.rs:6:1 | |
| 3 | | | |
| 4 | LL | fn def() { | |
| 5 | | ^^^^^^^^ | |
| 6 | | | |
| 7 | = help: specify the types explicitly | |
| 8 | note: in edition 2024, the requirement `!: Default` will fail | |
| 9 | --> $DIR/dependency-on-fallback-to-unit.rs:10:19 | |
| 10 | | | |
| 11 | LL | 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL - false => <_>::default(), | |
| 19 | LL + false => <()>::default(), | |
| 20 | | | |
| 21 | ||
| 22 | error: this function depends on never type fallback being `()` | |
| 23 | --> $DIR/dependency-on-fallback-to-unit.rs:17:1 | |
| 24 | | | |
| 25 | LL | fn question_mark() -> Result<(), ()> { | |
| 26 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 27 | | | |
| 28 | = help: specify the types explicitly | |
| 29 | note: in edition 2024, the requirement `!: Default` will fail | |
| 30 | --> $DIR/dependency-on-fallback-to-unit.rs:20:5 | |
| 31 | | | |
| 32 | LL | 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> | |
| 36 | help: use `()` annotations to avoid fallback changes | |
| 37 | | | |
| 38 | LL | deserialize::<()>()?; | |
| 39 | | ++++++ | |
| 40 | ||
| 41 | error: aborting due to 2 previous errors | |
| 42 | ||
| 43 | Future incompatibility report: Future breakage diagnostic: | |
| 44 | error: this function depends on never type fallback being `()` | |
| 45 | --> $DIR/dependency-on-fallback-to-unit.rs:6:1 | |
| 46 | | | |
| 47 | LL | fn def() { | |
| 48 | | ^^^^^^^^ | |
| 49 | | | |
| 50 | = help: specify the types explicitly | |
| 51 | note: in edition 2024, the requirement `!: Default` will fail | |
| 52 | --> $DIR/dependency-on-fallback-to-unit.rs:10:19 | |
| 53 | | | |
| 54 | LL | 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 | |
| 59 | help: use `()` annotations to avoid fallback changes | |
| 60 | | | |
| 61 | LL - false => <_>::default(), | |
| 62 | LL + false => <()>::default(), | |
| 63 | | | |
| 64 | ||
| 65 | Future breakage diagnostic: | |
| 66 | error: this function depends on never type fallback being `()` | |
| 67 | --> $DIR/dependency-on-fallback-to-unit.rs:17:1 | |
| 68 | | | |
| 69 | LL | fn question_mark() -> Result<(), ()> { | |
| 70 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 71 | | | |
| 72 | = help: specify the types explicitly | |
| 73 | note: in edition 2024, the requirement `!: Default` will fail | |
| 74 | --> $DIR/dependency-on-fallback-to-unit.rs:20:5 | |
| 75 | | | |
| 76 | LL | 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 | |
| 81 | help: use `()` annotations to avoid fallback changes | |
| 82 | | | |
| 83 | LL | deserialize::<()>()?; | |
| 84 | | ++++++ | |
| 85 |
tests/ui/never_type/fallback_change/diverging-fallback-unconstrained-return.e2021.stderr created+43| ... | ... | @@ -0,0 +1,43 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/diverging-fallback-unconstrained-return.rs:26:1 | |
| 3 | | | |
| 4 | LL | fn main() { | |
| 5 | | ^^^^^^^^^ | |
| 6 | | | |
| 7 | = help: specify the types explicitly | |
| 8 | note: in edition 2024, the requirement `!: UnitReturn` will fail | |
| 9 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 10 | | | |
| 11 | LL | 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL | let _: () = if true { unconstrained_return() } else { panic!() }; | |
| 19 | | ++++ | |
| 20 | ||
| 21 | error: aborting due to 1 previous error | |
| 22 | ||
| 23 | Future incompatibility report: Future breakage diagnostic: | |
| 24 | error: this function depends on never type fallback being `()` | |
| 25 | --> $DIR/diverging-fallback-unconstrained-return.rs:26:1 | |
| 26 | | | |
| 27 | LL | fn main() { | |
| 28 | | ^^^^^^^^^ | |
| 29 | | | |
| 30 | = help: specify the types explicitly | |
| 31 | note: in edition 2024, the requirement `!: UnitReturn` will fail | |
| 32 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 33 | | | |
| 34 | LL | 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 | |
| 39 | help: use `()` annotations to avoid fallback changes | |
| 40 | | | |
| 41 | LL | 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 @@ |
| 1 | error[E0277]: the trait bound `!: UnitReturn` is not satisfied | |
| 2 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 3 | | | |
| 4 | LL | let _ = if true { unconstrained_return() } else { panic!() }; | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^ the trait `UnitReturn` is not implemented for `!` | |
| 6 | | | |
| 7 | help: the following other types implement trait `UnitReturn` | |
| 8 | --> $DIR/diverging-fallback-unconstrained-return.rs:15:1 | |
| 9 | | | |
| 10 | LL | impl UnitReturn for i32 {} | |
| 11 | | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `unconstrained_return` | |
| 17 | --> $DIR/diverging-fallback-unconstrained-return.rs:18:28 | |
| 18 | | | |
| 19 | LL | fn unconstrained_return<T: UnitReturn>() -> T { | |
| 20 | | ^^^^^^^^^^ required by this bound in `unconstrained_return` | |
| 21 | ||
| 22 | error: aborting due to 1 previous error | |
| 23 | ||
| 24 | For 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 @@ |
| 1 | error[E0277]: the trait bound `!: UnitReturn` is not satisfied | |
| 2 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 3 | | | |
| 4 | LL | let _ = if true { unconstrained_return() } else { panic!() }; | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^ the trait `UnitReturn` is not implemented for `!` | |
| 6 | | | |
| 7 | help: the following other types implement trait `UnitReturn` | |
| 8 | --> $DIR/diverging-fallback-unconstrained-return.rs:15:1 | |
| 9 | | | |
| 10 | LL | impl UnitReturn for i32 {} | |
| 11 | | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `unconstrained_return` | |
| 17 | --> $DIR/diverging-fallback-unconstrained-return.rs:18:28 | |
| 18 | | | |
| 19 | LL | fn unconstrained_return<T: UnitReturn>() -> T { | |
| 20 | | ^^^^^^^^^^ required by this bound in `unconstrained_return` | |
| 21 | ||
| 22 | error: aborting due to 1 previous error | |
| 23 | ||
| 24 | For 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 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/diverging-fallback-unconstrained-return.rs:26:1 | |
| 3 | | | |
| 4 | LL | 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 | |
| 10 | note: in edition 2024, the requirement `!: UnitReturn` will fail | |
| 11 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 12 | | | |
| 13 | LL | 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL | let _: () = if true { unconstrained_return() } else { panic!() }; | |
| 19 | | ++++ | |
| 20 | ||
| 21 | error: aborting due to 1 previous error | |
| 22 | ||
| 23 | Future incompatibility report: Future breakage diagnostic: | |
| 24 | error: this function depends on never type fallback being `()` | |
| 25 | --> $DIR/diverging-fallback-unconstrained-return.rs:26:1 | |
| 26 | | | |
| 27 | LL | 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 | |
| 33 | note: in edition 2024, the requirement `!: UnitReturn` will fail | |
| 34 | --> $DIR/diverging-fallback-unconstrained-return.rs:37:23 | |
| 35 | | | |
| 36 | LL | 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 | |
| 39 | help: use `()` annotations to avoid fallback changes | |
| 40 | | | |
| 41 | LL | 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 | ||
| 12 | fn make_unit() {} | |
| 13 | ||
| 14 | trait UnitReturn {} | |
| 15 | impl UnitReturn for i32 {} | |
| 16 | impl UnitReturn for () {} | |
| 17 | ||
| 18 | fn 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 | ||
| 26 | fn 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 @@ |
| 1 | fn create_ok_default<C>() -> Result<C, ()> | |
| 2 | where | |
| 3 | C: Default, | |
| 4 | { | |
| 5 | Ok(C::default()) | |
| 6 | } | |
| 7 | ||
| 8 | fn 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 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/dont-suggest-turbofish-from-expansion.rs:8:1 | |
| 3 | | | |
| 4 | LL | fn main() -> Result<(), ()> { | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 6 | | | |
| 7 | = help: specify the types explicitly | |
| 8 | note: in edition 2024, the requirement `!: Default` will fail | |
| 9 | --> $DIR/dont-suggest-turbofish-from-expansion.rs:12:23 | |
| 10 | | | |
| 11 | LL | 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL | let created: () = create_ok_default()?; | |
| 19 | | ++++ | |
| 20 | ||
| 21 | error: aborting due to 1 previous error | |
| 22 | ||
| 23 | Future incompatibility report: Future breakage diagnostic: | |
| 24 | error: this function depends on never type fallback being `()` | |
| 25 | --> $DIR/dont-suggest-turbofish-from-expansion.rs:8:1 | |
| 26 | | | |
| 27 | LL | fn main() -> Result<(), ()> { | |
| 28 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 29 | | | |
| 30 | = help: specify the types explicitly | |
| 31 | note: in edition 2024, the requirement `!: Default` will fail | |
| 32 | --> $DIR/dont-suggest-turbofish-from-expansion.rs:12:23 | |
| 33 | | | |
| 34 | LL | 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 | |
| 39 | help: use `()` annotations to avoid fallback changes | |
| 40 | | | |
| 41 | LL | let created: () = create_ok_default()?; | |
| 42 | | ++++ | |
| 43 |
tests/ui/never_type/fallback_change/fallback-closure-ret.e2021.stderr created+18| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | Future incompatibility report: Future breakage diagnostic: | |
| 2 | warning: this function depends on never type fallback being `()` | |
| 3 | --> $DIR/fallback-closure-ret.rs:21:1 | |
| 4 | | | |
| 5 | LL | fn main() { | |
| 6 | | ^^^^^^^^^ | |
| 7 | | | |
| 8 | = help: specify the types explicitly | |
| 9 | note: in edition 2024, the requirement `!: Bar` will fail | |
| 10 | --> $DIR/fallback-closure-ret.rs:22:5 | |
| 11 | | | |
| 12 | LL | foo(|| panic!()); | |
| 13 | | ^^^^^^^^^^^^^^^^ | |
| 14 | help: use `()` annotations to avoid fallback changes | |
| 15 | | | |
| 16 | LL | foo::<()>(|| panic!()); | |
| 17 | | ++++++ | |
| 18 |
tests/ui/never_type/fallback_change/fallback-closure-ret.e2024.stderr created+24| ... | ... | @@ -0,0 +1,24 @@ |
| 1 | error[E0277]: the trait bound `!: Bar` is not satisfied | |
| 2 | --> $DIR/fallback-closure-ret.rs:22:5 | |
| 3 | | | |
| 4 | LL | foo(|| panic!()); | |
| 5 | | ^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `!` | |
| 6 | | | |
| 7 | help: the following other types implement trait `Bar` | |
| 8 | --> $DIR/fallback-closure-ret.rs:15:1 | |
| 9 | | | |
| 10 | LL | impl Bar for () {} | |
| 11 | | ^^^^^^^^^^^^^^^ `()` | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `foo` | |
| 17 | --> $DIR/fallback-closure-ret.rs:18:11 | |
| 18 | | | |
| 19 | LL | fn foo<R: Bar>(_: impl Fn() -> R) {} | |
| 20 | | ^^^ required by this bound in `foo` | |
| 21 | ||
| 22 | error: aborting due to 1 previous error | |
| 23 | ||
| 24 | For 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 @@ |
| 1 | error[E0277]: the trait bound `!: Bar` is not satisfied | |
| 2 | --> $DIR/fallback-closure-ret.rs:18:5 | |
| 3 | | | |
| 4 | LL | foo(|| panic!()); | |
| 5 | | ^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `!` | |
| 6 | | | |
| 7 | help: the following other types implement trait `Bar` | |
| 8 | --> $DIR/fallback-closure-ret.rs:12:1 | |
| 9 | | | |
| 10 | LL | impl Bar for () {} | |
| 11 | | ^^^^^^^^^^^^^^^ `()` | |
| 12 | LL | 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 | |
| 16 | note: required by a bound in `foo` | |
| 17 | --> $DIR/fallback-closure-ret.rs:15:11 | |
| 18 | | | |
| 19 | LL | fn foo<R: Bar>(_: impl Fn() -> R) {} | |
| 20 | | ^^^ required by this bound in `foo` | |
| 21 | ||
| 22 | error: aborting due to 1 previous error | |
| 23 | ||
| 24 | For 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 @@ |
| 1 | Future incompatibility report: Future breakage diagnostic: | |
| 2 | warning: this function depends on never type fallback being `()` | |
| 3 | --> $DIR/fallback-closure-ret.rs:17:1 | |
| 4 | | | |
| 5 | LL | fn main() { | |
| 6 | | ^^^^^^^^^ | |
| 7 | | | |
| 8 | = help: specify the types explicitly | |
| 9 | note: in edition 2024, the requirement `!: Bar` will fail | |
| 10 | --> $DIR/fallback-closure-ret.rs:18:5 | |
| 11 | | | |
| 12 | LL | foo(|| panic!()); | |
| 13 | | ^^^^^^^^^^^^^^^^ | |
| 14 | help: use `()` annotations to avoid fallback changes | |
| 15 | | | |
| 16 | LL | 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 | ||
| 14 | trait Bar {} | |
| 15 | impl Bar for () {} | |
| 16 | impl Bar for u32 {} | |
| 17 | ||
| 18 | fn foo<R: Bar>(_: impl Fn() -> R) {} | |
| 19 | ||
| 20 | #[cfg_attr(e2021, expect(dependency_on_unit_never_type_fallback))] | |
| 21 | fn 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 @@ |
| 1 | error[E0271]: expected `{closure@fallback-closure-wrap.rs:16:40}` to return `()`, but it returns `!` | |
| 2 | --> $DIR/fallback-closure-wrap.rs:17:9 | |
| 3 | | | |
| 4 | LL | let error = Closure::wrap(Box::new(move || { | |
| 5 | | ------- this closure | |
| 6 | LL | 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 | ||
| 13 | error: aborting due to 1 previous error | |
| 14 | ||
| 15 | For 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 @@ |
| 1 | error[E0271]: expected `{closure@fallback-closure-wrap.rs:17:40}` to return `()`, but it returns `!` | |
| 2 | --> $DIR/fallback-closure-wrap.rs:18:9 | |
| 3 | | | |
| 4 | LL | let error = Closure::wrap(Box::new(move || { | |
| 5 | | ------- this closure | |
| 6 | LL | 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 | ||
| 13 | error: aborting due to 1 previous error | |
| 14 | ||
| 15 | For 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 | ||
| 13 | use std::marker::PhantomData; | |
| 14 | ||
| 15 | fn 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 | ||
| 22 | struct Closure<T: ?Sized>(PhantomData<T>); | |
| 23 | ||
| 24 | impl<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 | ||
| 14 | struct E; | |
| 15 | ||
| 16 | impl From<!> for E { | |
| 17 | fn from(_: !) -> E { | |
| 18 | E | |
| 19 | } | |
| 20 | } | |
| 21 | ||
| 22 | #[allow(unreachable_code)] | |
| 23 | fn 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 | ||
| 29 | fn main() {} |
tests/ui/never_type/fallback_change/from_infer_breaking_with_unit_fallback.unit.stderr created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | error[E0277]: the trait bound `E: From<()>` is not satisfied | |
| 2 | --> $DIR/from_infer_breaking_with_unit_fallback.rs:25:6 | |
| 3 | | | |
| 4 | LL | <E as From<_>>::from(never); // Should the inference fail? | |
| 5 | | ^ unsatisfied trait bound | |
| 6 | | | |
| 7 | help: 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 | | | |
| 11 | LL | impl From<!> for E { | |
| 12 | | ^^^^^^^^^^^^^^^^^^ | |
| 13 | = help: for that trait implementation, expected `!`, found `()` | |
| 14 | ||
| 15 | error: aborting due to 1 previous error | |
| 16 | ||
| 17 | For 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 | ||
| 4 | fn foo<T: Default>() -> Result<T, ()> { | |
| 5 | Err(()) | |
| 6 | } | |
| 7 | ||
| 8 | fn 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 | ||
| 15 | fn 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 | ||
| 4 | fn foo<T: Default>() -> Result<T, ()> { | |
| 5 | Err(()) | |
| 6 | } | |
| 7 | ||
| 8 | fn 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 | ||
| 15 | fn main() {} |
tests/ui/never_type/fallback_change/lint-breaking-2024-assign-underscore.stderr created+43| ... | ... | @@ -0,0 +1,43 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/lint-breaking-2024-assign-underscore.rs:8:1 | |
| 3 | | | |
| 4 | LL | fn test() -> Result<(), ()> { | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 6 | | | |
| 7 | = help: specify the types explicitly | |
| 8 | note: in edition 2024, the requirement `!: Default` will fail | |
| 9 | --> $DIR/lint-breaking-2024-assign-underscore.rs:11:9 | |
| 10 | | | |
| 11 | LL | _ = 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL | _ = foo::<()>()?; | |
| 19 | | ++++++ | |
| 20 | ||
| 21 | error: aborting due to 1 previous error | |
| 22 | ||
| 23 | Future incompatibility report: Future breakage diagnostic: | |
| 24 | error: this function depends on never type fallback being `()` | |
| 25 | --> $DIR/lint-breaking-2024-assign-underscore.rs:8:1 | |
| 26 | | | |
| 27 | LL | fn test() -> Result<(), ()> { | |
| 28 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 29 | | | |
| 30 | = help: specify the types explicitly | |
| 31 | note: in edition 2024, the requirement `!: Default` will fail | |
| 32 | --> $DIR/lint-breaking-2024-assign-underscore.rs:11:9 | |
| 33 | | | |
| 34 | LL | _ = 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 | |
| 39 | help: use `()` annotations to avoid fallback changes | |
| 40 | | | |
| 41 | LL | _ = foo::<()>()?; | |
| 42 | | ++++++ | |
| 43 |
tests/ui/never_type/fallback_change/lint-never-type-fallback-flowing-into-unsafe.e2015.stderr created+287| ... | ... | @@ -0,0 +1,287 @@ |
| 1 | error: never type fallback affects this call to an `unsafe` function | |
| 2 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 3 | | | |
| 4 | LL | 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 | |
| 11 | help: use `()` annotations to avoid fallback changes | |
| 12 | | | |
| 13 | LL | unsafe { mem::zeroed::<()>() } | |
| 14 | | ++++++ | |
| 15 | ||
| 16 | error: never type fallback affects this call to an `unsafe` function | |
| 17 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13 | |
| 18 | | | |
| 19 | LL | 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> | |
| 25 | help: use `()` annotations to avoid fallback changes | |
| 26 | | | |
| 27 | LL | core::mem::transmute::<_, ()>(Zst) | |
| 28 | | +++++++++ | |
| 29 | ||
| 30 | error: never type fallback affects this union access | |
| 31 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18 | |
| 32 | | | |
| 33 | LL | 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 | ||
| 40 | error: never type fallback affects this raw pointer dereference | |
| 41 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18 | |
| 42 | | | |
| 43 | LL | 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> | |
| 49 | help: use `()` annotations to avoid fallback changes | |
| 50 | | | |
| 51 | LL | unsafe { *ptr::from_ref(&()).cast::<()>() } | |
| 52 | | ++++++ | |
| 53 | ||
| 54 | error: never type fallback affects this call to an `unsafe` function | |
| 55 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18 | |
| 56 | | | |
| 57 | LL | 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> | |
| 63 | help: use `()` annotations to avoid fallback changes | |
| 64 | | | |
| 65 | LL | unsafe { internally_create::<()>(x) } | |
| 66 | | ++++++ | |
| 67 | ||
| 68 | error: never type fallback affects this call to an `unsafe` function | |
| 69 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18 | |
| 70 | | | |
| 71 | LL | 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> | |
| 77 | help: use `()` annotations to avoid fallback changes | |
| 78 | | | |
| 79 | LL | let zeroed = mem::zeroed::<()>; | |
| 80 | | ++++++ | |
| 81 | ||
| 82 | error: never type fallback affects this `unsafe` function | |
| 83 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22 | |
| 84 | | | |
| 85 | LL | 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> | |
| 91 | help: use `()` annotations to avoid fallback changes | |
| 92 | | | |
| 93 | LL | let zeroed = mem::zeroed::<()>; | |
| 94 | | ++++++ | |
| 95 | ||
| 96 | error: never type fallback affects this `unsafe` function | |
| 97 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17 | |
| 98 | | | |
| 99 | LL | 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> | |
| 105 | help: use `()` annotations to avoid fallback changes | |
| 106 | | | |
| 107 | LL | let f = internally_create::<()>; | |
| 108 | | ++++++ | |
| 109 | ||
| 110 | error: never type fallback affects this call to an `unsafe` method | |
| 111 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13 | |
| 112 | | | |
| 113 | LL | 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 | ||
| 120 | error: never type fallback affects this call to an `unsafe` function | |
| 121 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19 | |
| 122 | | | |
| 123 | LL | match send_message::<_ /* ?0 */>() { | |
| 124 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 125 | ... | |
| 126 | LL | 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 | ||
| 134 | error: aborting due to 10 previous errors | |
| 135 | ||
| 136 | Future incompatibility report: Future breakage diagnostic: | |
| 137 | error: never type fallback affects this call to an `unsafe` function | |
| 138 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 139 | | | |
| 140 | LL | 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 | |
| 147 | help: use `()` annotations to avoid fallback changes | |
| 148 | | | |
| 149 | LL | unsafe { mem::zeroed::<()>() } | |
| 150 | | ++++++ | |
| 151 | ||
| 152 | Future breakage diagnostic: | |
| 153 | error: never type fallback affects this call to an `unsafe` function | |
| 154 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13 | |
| 155 | | | |
| 156 | LL | 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 | |
| 163 | help: use `()` annotations to avoid fallback changes | |
| 164 | | | |
| 165 | LL | core::mem::transmute::<_, ()>(Zst) | |
| 166 | | +++++++++ | |
| 167 | ||
| 168 | Future breakage diagnostic: | |
| 169 | error: never type fallback affects this union access | |
| 170 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18 | |
| 171 | | | |
| 172 | LL | 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 | ||
| 180 | Future breakage diagnostic: | |
| 181 | error: never type fallback affects this raw pointer dereference | |
| 182 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18 | |
| 183 | | | |
| 184 | LL | 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 | |
| 191 | help: use `()` annotations to avoid fallback changes | |
| 192 | | | |
| 193 | LL | unsafe { *ptr::from_ref(&()).cast::<()>() } | |
| 194 | | ++++++ | |
| 195 | ||
| 196 | Future breakage diagnostic: | |
| 197 | error: never type fallback affects this call to an `unsafe` function | |
| 198 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18 | |
| 199 | | | |
| 200 | LL | 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 | |
| 207 | help: use `()` annotations to avoid fallback changes | |
| 208 | | | |
| 209 | LL | unsafe { internally_create::<()>(x) } | |
| 210 | | ++++++ | |
| 211 | ||
| 212 | Future breakage diagnostic: | |
| 213 | error: never type fallback affects this call to an `unsafe` function | |
| 214 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18 | |
| 215 | | | |
| 216 | LL | 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 | |
| 223 | help: use `()` annotations to avoid fallback changes | |
| 224 | | | |
| 225 | LL | let zeroed = mem::zeroed::<()>; | |
| 226 | | ++++++ | |
| 227 | ||
| 228 | Future breakage diagnostic: | |
| 229 | error: never type fallback affects this `unsafe` function | |
| 230 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22 | |
| 231 | | | |
| 232 | LL | 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 | |
| 239 | help: use `()` annotations to avoid fallback changes | |
| 240 | | | |
| 241 | LL | let zeroed = mem::zeroed::<()>; | |
| 242 | | ++++++ | |
| 243 | ||
| 244 | Future breakage diagnostic: | |
| 245 | error: never type fallback affects this `unsafe` function | |
| 246 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17 | |
| 247 | | | |
| 248 | LL | 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 | |
| 255 | help: use `()` annotations to avoid fallback changes | |
| 256 | | | |
| 257 | LL | let f = internally_create::<()>; | |
| 258 | | ++++++ | |
| 259 | ||
| 260 | Future breakage diagnostic: | |
| 261 | error: never type fallback affects this call to an `unsafe` method | |
| 262 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13 | |
| 263 | | | |
| 264 | LL | 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 | ||
| 272 | Future breakage diagnostic: | |
| 273 | error: never type fallback affects this call to an `unsafe` function | |
| 274 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19 | |
| 275 | | | |
| 276 | LL | match send_message::<_ /* ?0 */>() { | |
| 277 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 278 | ... | |
| 279 | LL | 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 @@ |
| 1 | error: never type fallback affects this call to an `unsafe` function | |
| 2 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 3 | | | |
| 4 | LL | 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 | |
| 11 | help: use `()` annotations to avoid fallback changes | |
| 12 | | | |
| 13 | LL | unsafe { mem::zeroed::<()>() } | |
| 14 | | ++++++ | |
| 15 | ||
| 16 | error: never type fallback affects this call to an `unsafe` function | |
| 17 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13 | |
| 18 | | | |
| 19 | LL | 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> | |
| 25 | help: use `()` annotations to avoid fallback changes | |
| 26 | | | |
| 27 | LL | core::mem::transmute::<_, ()>(Zst) | |
| 28 | | +++++++++ | |
| 29 | ||
| 30 | error: never type fallback affects this union access | |
| 31 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18 | |
| 32 | | | |
| 33 | LL | 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 | ||
| 40 | error: never type fallback affects this raw pointer dereference | |
| 41 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18 | |
| 42 | | | |
| 43 | LL | 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> | |
| 49 | help: use `()` annotations to avoid fallback changes | |
| 50 | | | |
| 51 | LL | unsafe { *ptr::from_ref(&()).cast::<()>() } | |
| 52 | | ++++++ | |
| 53 | ||
| 54 | error: never type fallback affects this call to an `unsafe` function | |
| 55 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18 | |
| 56 | | | |
| 57 | LL | 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> | |
| 63 | help: use `()` annotations to avoid fallback changes | |
| 64 | | | |
| 65 | LL | unsafe { internally_create::<()>(x) } | |
| 66 | | ++++++ | |
| 67 | ||
| 68 | error: never type fallback affects this call to an `unsafe` function | |
| 69 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18 | |
| 70 | | | |
| 71 | LL | 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> | |
| 77 | help: use `()` annotations to avoid fallback changes | |
| 78 | | | |
| 79 | LL | let zeroed = mem::zeroed::<()>; | |
| 80 | | ++++++ | |
| 81 | ||
| 82 | error: never type fallback affects this `unsafe` function | |
| 83 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22 | |
| 84 | | | |
| 85 | LL | 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> | |
| 91 | help: use `()` annotations to avoid fallback changes | |
| 92 | | | |
| 93 | LL | let zeroed = mem::zeroed::<()>; | |
| 94 | | ++++++ | |
| 95 | ||
| 96 | error: never type fallback affects this `unsafe` function | |
| 97 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17 | |
| 98 | | | |
| 99 | LL | 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> | |
| 105 | help: use `()` annotations to avoid fallback changes | |
| 106 | | | |
| 107 | LL | let f = internally_create::<()>; | |
| 108 | | ++++++ | |
| 109 | ||
| 110 | error: never type fallback affects this call to an `unsafe` method | |
| 111 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13 | |
| 112 | | | |
| 113 | LL | 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 | ||
| 120 | error: never type fallback affects this call to an `unsafe` function | |
| 121 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19 | |
| 122 | | | |
| 123 | LL | match send_message::<_ /* ?0 */>() { | |
| 124 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 125 | ... | |
| 126 | LL | 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 | ||
| 134 | warning: the type `!` does not permit zero-initialization | |
| 135 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 136 | | | |
| 137 | LL | 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 | ||
| 143 | error: aborting due to 10 previous errors; 1 warning emitted | |
| 144 | ||
| 145 | Future incompatibility report: Future breakage diagnostic: | |
| 146 | error: never type fallback affects this call to an `unsafe` function | |
| 147 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 148 | | | |
| 149 | LL | 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 | |
| 156 | help: use `()` annotations to avoid fallback changes | |
| 157 | | | |
| 158 | LL | unsafe { mem::zeroed::<()>() } | |
| 159 | | ++++++ | |
| 160 | ||
| 161 | Future breakage diagnostic: | |
| 162 | error: never type fallback affects this call to an `unsafe` function | |
| 163 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13 | |
| 164 | | | |
| 165 | LL | 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 | |
| 172 | help: use `()` annotations to avoid fallback changes | |
| 173 | | | |
| 174 | LL | core::mem::transmute::<_, ()>(Zst) | |
| 175 | | +++++++++ | |
| 176 | ||
| 177 | Future breakage diagnostic: | |
| 178 | error: never type fallback affects this union access | |
| 179 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18 | |
| 180 | | | |
| 181 | LL | 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 | ||
| 189 | Future breakage diagnostic: | |
| 190 | error: never type fallback affects this raw pointer dereference | |
| 191 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18 | |
| 192 | | | |
| 193 | LL | 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 | |
| 200 | help: use `()` annotations to avoid fallback changes | |
| 201 | | | |
| 202 | LL | unsafe { *ptr::from_ref(&()).cast::<()>() } | |
| 203 | | ++++++ | |
| 204 | ||
| 205 | Future breakage diagnostic: | |
| 206 | error: never type fallback affects this call to an `unsafe` function | |
| 207 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18 | |
| 208 | | | |
| 209 | LL | 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 | |
| 216 | help: use `()` annotations to avoid fallback changes | |
| 217 | | | |
| 218 | LL | unsafe { internally_create::<()>(x) } | |
| 219 | | ++++++ | |
| 220 | ||
| 221 | Future breakage diagnostic: | |
| 222 | error: never type fallback affects this call to an `unsafe` function | |
| 223 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18 | |
| 224 | | | |
| 225 | LL | 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 | |
| 232 | help: use `()` annotations to avoid fallback changes | |
| 233 | | | |
| 234 | LL | let zeroed = mem::zeroed::<()>; | |
| 235 | | ++++++ | |
| 236 | ||
| 237 | Future breakage diagnostic: | |
| 238 | error: never type fallback affects this `unsafe` function | |
| 239 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22 | |
| 240 | | | |
| 241 | LL | 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 | |
| 248 | help: use `()` annotations to avoid fallback changes | |
| 249 | | | |
| 250 | LL | let zeroed = mem::zeroed::<()>; | |
| 251 | | ++++++ | |
| 252 | ||
| 253 | Future breakage diagnostic: | |
| 254 | error: never type fallback affects this `unsafe` function | |
| 255 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17 | |
| 256 | | | |
| 257 | LL | 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 | |
| 264 | help: use `()` annotations to avoid fallback changes | |
| 265 | | | |
| 266 | LL | let f = internally_create::<()>; | |
| 267 | | ++++++ | |
| 268 | ||
| 269 | Future breakage diagnostic: | |
| 270 | error: never type fallback affects this call to an `unsafe` method | |
| 271 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13 | |
| 272 | | | |
| 273 | LL | 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 | ||
| 281 | Future breakage diagnostic: | |
| 282 | error: never type fallback affects this call to an `unsafe` function | |
| 283 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19 | |
| 284 | | | |
| 285 | LL | match send_message::<_ /* ?0 */>() { | |
| 286 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 287 | ... | |
| 288 | LL | 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 | ||
| 4 | use std::{marker, mem, ptr}; | |
| 5 | ||
| 6 | fn main() {} | |
| 7 | ||
| 8 | fn _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 | ||
| 23 | fn _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 | ||
| 37 | fn _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 | ||
| 53 | fn _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 | ||
| 64 | fn _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 | ||
| 87 | fn _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 | ||
| 103 | fn _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 | ||
| 125 | fn _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 | |
| 148 | fn _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 | ||
| 12 | type Infallible = !; | |
| 13 | ||
| 14 | struct E; | |
| 15 | ||
| 16 | impl From<Infallible> for E { | |
| 17 | fn from(_: Infallible) -> E { | |
| 18 | E | |
| 19 | } | |
| 20 | } | |
| 21 | ||
| 22 | fn u32_try_from(x: u32) -> Result<u32, Infallible> { | |
| 23 | Ok(x) | |
| 24 | } | |
| 25 | ||
| 26 | fn _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 | ||
| 46 | fn main() {} |
tests/ui/never_type/fallback_change/try-block-never-type-fallback.e2021.stderr created+20| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | error[E0277]: the trait bound `!: From<()>` is not satisfied | |
| 2 | --> $DIR/try-block-never-type-fallback.rs:20:9 | |
| 3 | | | |
| 4 | LL | 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<!>` | |
| 12 | note: required by a bound in `bar` | |
| 13 | --> $DIR/try-block-never-type-fallback.rs:15:23 | |
| 14 | | | |
| 15 | LL | fn bar(_: Result<impl Into<!>, u32>) { | |
| 16 | | ^^^^^^^ required by this bound in `bar` | |
| 17 | ||
| 18 | error: aborting due to 1 previous error | |
| 19 | ||
| 20 | For 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 | ||
| 15 | fn bar(_: Result<impl Into<!>, u32>) { | |
| 16 | unimplemented!() | |
| 17 | } | |
| 18 | ||
| 19 | fn foo(x: Result<!, u32>) { | |
| 20 | bar(try { x? }); | |
| 21 | //[e2021]~^ ERROR the trait bound `!: From<()>` is not satisfied | |
| 22 | } | |
| 23 | ||
| 24 | fn 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 | ||
| 3 | fn 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 @@ |
| 1 | error[E0609]: no field `is_failure` on type `!` | |
| 2 | --> $DIR/field-access-never-type-13847.rs:4:12 | |
| 3 | | | |
| 4 | LL | return.is_failure | |
| 5 | | ^^^^^^^^^^ unknown field | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 | ||
| 14 | struct E; | |
| 15 | ||
| 16 | impl From<!> for E { | |
| 17 | fn from(_: !) -> E { | |
| 18 | E | |
| 19 | } | |
| 20 | } | |
| 21 | ||
| 22 | #[allow(unreachable_code)] | |
| 23 | fn 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 | ||
| 29 | fn main() {} |
tests/ui/never_type/from_infer_breaking_with_unit_fallback.unit.stderr deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | error[E0277]: the trait bound `E: From<()>` is not satisfied | |
| 2 | --> $DIR/from_infer_breaking_with_unit_fallback.rs:25:6 | |
| 3 | | | |
| 4 | LL | <E as From<_>>::from(never); // Should the inference fail? | |
| 5 | | ^ unsatisfied trait bound | |
| 6 | | | |
| 7 | help: 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 | | | |
| 11 | LL | impl From<!> for E { | |
| 12 | | ^^^^^^^^^^^^^^^^^^ | |
| 13 | = help: for that trait implementation, expected `!`, found `()` | |
| 14 | ||
| 15 | error: aborting due to 1 previous error | |
| 16 | ||
| 17 | For 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 | ||
| 9 | trait StringifyType { | |
| 10 | fn stringify_type() -> &'static str; | |
| 11 | } | |
| 12 | ||
| 13 | impl StringifyType for ! { | |
| 14 | fn stringify_type() -> &'static str { | |
| 15 | "!" | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | fn maybe_stringify<T: StringifyType>(opt: Option<T>) -> &'static str { | |
| 20 | match opt { | |
| 21 | Some(_) => T::stringify_type(), | |
| 22 | None => "none", | |
| 23 | } | |
| 24 | } | |
| 25 | ||
| 26 | fn 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 ! | |
| 2 | None is none |
tests/ui/never_type/issue-10176.rs deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | fn 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 | ||
| 9 | fn main() {} |
tests/ui/never_type/issue-10176.stderr deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/issue-10176.rs:2:5 | |
| 3 | | | |
| 4 | LL | fn f() -> isize { | |
| 5 | | ----- expected `isize` because of return type | |
| 6 | LL | (return 1, return 2) | |
| 7 | | ^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `(!, !)` | |
| 8 | | | |
| 9 | = note: expected type `isize` | |
| 10 | found tuple `(!, !)` | |
| 11 | ||
| 12 | error: aborting due to 1 previous error | |
| 13 | ||
| 14 | For more information about this error, try `rustc --explain E0308`. |
tests/ui/never_type/issue-13352.rs deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | fn foo(_: Box<dyn FnMut()>) {} | |
| 2 | ||
| 3 | fn 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 @@ |
| 1 | error[E0277]: cannot add `()` to `usize` | |
| 2 | --> $DIR/issue-13352.rs:7:13 | |
| 3 | | | |
| 4 | LL | 2_usize + (loop {}); | |
| 5 | | ^ no implementation for `usize + ()` | |
| 6 | | | |
| 7 | = help: the trait `Add<()>` is not implemented for `usize` | |
| 8 | help: 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 | ||
| 26 | error: aborting due to 1 previous error | |
| 27 | ||
| 28 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/never_type/issue-2149.rs deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | trait VecMonad<A> { | |
| 2 | fn bind<B, F>(&self, f: F) where F: FnMut(A) -> Vec<B>; | |
| 3 | } | |
| 4 | ||
| 5 | impl<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 | } | |
| 12 | fn 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 @@ |
| 1 | error[E0277]: cannot add `Vec<B>` to `()` | |
| 2 | --> $DIR/issue-2149.rs:8:33 | |
| 3 | | | |
| 4 | LL | 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 | ||
| 9 | error[E0599]: no method named `bind` found for array `[&str; 1]` in the current scope | |
| 10 | --> $DIR/issue-2149.rs:13:12 | |
| 11 | | | |
| 12 | LL | ["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 | |
| 16 | note: `VecMonad` defines an item `bind`, perhaps you need to implement it | |
| 17 | --> $DIR/issue-2149.rs:1:1 | |
| 18 | | | |
| 19 | LL | trait VecMonad<A> { | |
| 20 | | ^^^^^^^^^^^^^^^^^ | |
| 21 | ||
| 22 | error: aborting due to 2 previous errors | |
| 23 | ||
| 24 | Some errors have detailed explanations: E0277, E0599. | |
| 25 | For 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 | ||
| 12 | struct Foo { | |
| 13 | field1: !, | |
| 14 | field2: Option<&'static Bar>, | |
| 15 | } | |
| 16 | ||
| 17 | struct Bar { | |
| 18 | field1: &'static Foo | |
| 19 | } | |
| 20 | ||
| 21 | fn test_a() { | |
| 22 | let x: Option<Foo> = None; | |
| 23 | match x { None => () } | |
| 24 | } | |
| 25 | ||
| 26 | fn test_b() { | |
| 27 | let x: Option<Bar> = None; | |
| 28 | match x { | |
| 29 | Some(_) => (), | |
| 30 | None => () | |
| 31 | } | |
| 32 | } | |
| 33 | ||
| 34 | fn 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 | ||
| 6 | use std::iter::{self, Empty}; | |
| 7 | ||
| 8 | trait Trait { | |
| 9 | type Out: Iterator<Item = u32>; | |
| 10 | ||
| 11 | fn f(&self) -> Option<Self::Out>; | |
| 12 | } | |
| 13 | ||
| 14 | impl<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 | ||
| 22 | struct X; | |
| 23 | ||
| 24 | impl Trait for X { | |
| 25 | type Out = Empty<u32>; | |
| 26 | ||
| 27 | fn f(&self) -> Option<Self::Out> { | |
| 28 | Some(iter::empty()) | |
| 29 | } | |
| 30 | } | |
| 31 | ||
| 32 | fn 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 | ||
| 41 | pub fn main() { | |
| 42 | f(10); | |
| 43 | } |
tests/ui/never_type/issue-51506.stderr deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | error[E0277]: `!` is not an iterator | |
| 2 | --> $DIR/issue-51506.rs:15:24 | |
| 3 | | | |
| 4 | LL | default type Out = !; | |
| 5 | | ^ `!` is not an iterator | |
| 6 | | | |
| 7 | = help: the trait `Iterator` is not implemented for `!` | |
| 8 | note: required by a bound in `Trait::Out` | |
| 9 | --> $DIR/issue-51506.rs:9:15 | |
| 10 | | | |
| 11 | LL | type Out: Iterator<Item = u32>; | |
| 12 | | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait::Out` | |
| 13 | ||
| 14 | error: aborting due to 1 previous error | |
| 15 | ||
| 16 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/never_type/issue-52443.rs deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | fn 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 @@ |
| 1 | warning: denote infinite loops with `loop { ... }` | |
| 2 | --> $DIR/issue-52443.rs:6:11 | |
| 3 | | | |
| 4 | LL | [(); {while true {break}; 0}]; | |
| 5 | | ^^^^^^^^^^ help: use `loop` | |
| 6 | | | |
| 7 | = note: `#[warn(while_true)]` on by default | |
| 8 | ||
| 9 | error[E0308]: mismatched types | |
| 10 | --> $DIR/issue-52443.rs:2:10 | |
| 11 | | | |
| 12 | LL | [(); & { loop { continue } } ]; | |
| 13 | | ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_` | |
| 14 | | | |
| 15 | = note: expected type `usize` | |
| 16 | found reference `&_` | |
| 17 | help: consider removing the borrow | |
| 18 | | | |
| 19 | LL - [(); & { loop { continue } } ]; | |
| 20 | LL + [(); { loop { continue } } ]; | |
| 21 | | | |
| 22 | ||
| 23 | error[E0308]: mismatched types | |
| 24 | --> $DIR/issue-52443.rs:4:17 | |
| 25 | | | |
| 26 | LL | [(); loop { break }]; | |
| 27 | | ^^^^^ expected `usize`, found `()` | |
| 28 | | | |
| 29 | help: give the `break` a value of the expected type | |
| 30 | | | |
| 31 | LL | [(); loop { break 42 }]; | |
| 32 | | ++ | |
| 33 | ||
| 34 | error[E0277]: the trait bound `std::ops::RangeFrom<usize>: const Iterator` is not satisfied | |
| 35 | --> $DIR/issue-52443.rs:9:21 | |
| 36 | | | |
| 37 | LL | [(); { for _ in 0usize.. {}; 0}]; | |
| 38 | | ^^^^^^^^ required by a bound introduced by this call | |
| 39 | | | |
| 40 | note: 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 | ||
| 44 | error[E0277]: the trait bound `std::ops::RangeFrom<usize>: const Iterator` is not satisfied | |
| 45 | --> $DIR/issue-52443.rs:9:21 | |
| 46 | | | |
| 47 | LL | [(); { for _ in 0usize.. {}; 0}]; | |
| 48 | | ^^^^^^^^ | |
| 49 | | | |
| 50 | note: trait `Iterator` is implemented but not `const` | |
| 51 | --> $SRC_DIR/core/src/iter/range.rs:LL:COL | |
| 52 | ||
| 53 | error: aborting due to 4 previous errors; 1 warning emitted | |
| 54 | ||
| 55 | Some errors have detailed explanations: E0277, E0308. | |
| 56 | For 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 | ||
| 8 | struct TrieMapIterator<'a> { | |
| 9 | node: &'a usize | |
| 10 | } | |
| 11 | ||
| 12 | fn 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 @@ |
| 1 | fn 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 @@ |
| 1 | error: unexpected token: `...` | |
| 2 | --> $DIR/issue-96335.rs:2:6 | |
| 3 | | | |
| 4 | LL | 0.....{loop{}1}; | |
| 5 | | ^^^ | |
| 6 | | | |
| 7 | help: use `..` for an exclusive range | |
| 8 | | | |
| 9 | LL - 0.....{loop{}1}; | |
| 10 | LL + 0....{loop{}1}; | |
| 11 | | | |
| 12 | help: or `..=` for an inclusive range | |
| 13 | | | |
| 14 | LL - 0.....{loop{}1}; | |
| 15 | LL + 0..=..{loop{}1}; | |
| 16 | | | |
| 17 | ||
| 18 | error[E0308]: mismatched types | |
| 19 | --> $DIR/issue-96335.rs:2:9 | |
| 20 | | | |
| 21 | LL | 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}>` | |
| 29 | note: associated function defined here | |
| 30 | --> $SRC_DIR/core/src/ops/range.rs:LL:COL | |
| 31 | ||
| 32 | error: aborting due to 2 previous errors | |
| 33 | ||
| 34 | For 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 | ||
| 4 | fn foo<T: Default>() -> Result<T, ()> { | |
| 5 | Err(()) | |
| 6 | } | |
| 7 | ||
| 8 | fn 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 | ||
| 15 | fn main() {} |
tests/ui/never_type/lint-breaking-2024-assign-underscore.rs deleted-15| ... | ... | @@ -1,15 +0,0 @@ |
| 1 | //@ run-rustfix | |
| 2 | #![allow(unused)] | |
| 3 | ||
| 4 | fn foo<T: Default>() -> Result<T, ()> { | |
| 5 | Err(()) | |
| 6 | } | |
| 7 | ||
| 8 | fn 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 | ||
| 15 | fn main() {} |
tests/ui/never_type/lint-breaking-2024-assign-underscore.stderr deleted-43| ... | ... | @@ -1,43 +0,0 @@ |
| 1 | error: this function depends on never type fallback being `()` | |
| 2 | --> $DIR/lint-breaking-2024-assign-underscore.rs:8:1 | |
| 3 | | | |
| 4 | LL | fn test() -> Result<(), ()> { | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 6 | | | |
| 7 | = help: specify the types explicitly | |
| 8 | note: in edition 2024, the requirement `!: Default` will fail | |
| 9 | --> $DIR/lint-breaking-2024-assign-underscore.rs:11:9 | |
| 10 | | | |
| 11 | LL | _ = 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 | |
| 16 | help: use `()` annotations to avoid fallback changes | |
| 17 | | | |
| 18 | LL | _ = foo::<()>()?; | |
| 19 | | ++++++ | |
| 20 | ||
| 21 | error: aborting due to 1 previous error | |
| 22 | ||
| 23 | Future incompatibility report: Future breakage diagnostic: | |
| 24 | error: this function depends on never type fallback being `()` | |
| 25 | --> $DIR/lint-breaking-2024-assign-underscore.rs:8:1 | |
| 26 | | | |
| 27 | LL | fn test() -> Result<(), ()> { | |
| 28 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 29 | | | |
| 30 | = help: specify the types explicitly | |
| 31 | note: in edition 2024, the requirement `!: Default` will fail | |
| 32 | --> $DIR/lint-breaking-2024-assign-underscore.rs:11:9 | |
| 33 | | | |
| 34 | LL | _ = 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 | |
| 39 | help: use `()` annotations to avoid fallback changes | |
| 40 | | | |
| 41 | LL | _ = foo::<()>()?; | |
| 42 | | ++++++ | |
| 43 |
tests/ui/never_type/lint-never-type-fallback-flowing-into-unsafe.e2015.stderr deleted-287| ... | ... | @@ -1,287 +0,0 @@ |
| 1 | error: never type fallback affects this call to an `unsafe` function | |
| 2 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 3 | | | |
| 4 | LL | 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 | |
| 11 | help: use `()` annotations to avoid fallback changes | |
| 12 | | | |
| 13 | LL | unsafe { mem::zeroed::<()>() } | |
| 14 | | ++++++ | |
| 15 | ||
| 16 | error: never type fallback affects this call to an `unsafe` function | |
| 17 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13 | |
| 18 | | | |
| 19 | LL | 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> | |
| 25 | help: use `()` annotations to avoid fallback changes | |
| 26 | | | |
| 27 | LL | core::mem::transmute::<_, ()>(Zst) | |
| 28 | | +++++++++ | |
| 29 | ||
| 30 | error: never type fallback affects this union access | |
| 31 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18 | |
| 32 | | | |
| 33 | LL | 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 | ||
| 40 | error: never type fallback affects this raw pointer dereference | |
| 41 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18 | |
| 42 | | | |
| 43 | LL | 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> | |
| 49 | help: use `()` annotations to avoid fallback changes | |
| 50 | | | |
| 51 | LL | unsafe { *ptr::from_ref(&()).cast::<()>() } | |
| 52 | | ++++++ | |
| 53 | ||
| 54 | error: never type fallback affects this call to an `unsafe` function | |
| 55 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18 | |
| 56 | | | |
| 57 | LL | 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> | |
| 63 | help: use `()` annotations to avoid fallback changes | |
| 64 | | | |
| 65 | LL | unsafe { internally_create::<()>(x) } | |
| 66 | | ++++++ | |
| 67 | ||
| 68 | error: never type fallback affects this call to an `unsafe` function | |
| 69 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18 | |
| 70 | | | |
| 71 | LL | 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> | |
| 77 | help: use `()` annotations to avoid fallback changes | |
| 78 | | | |
| 79 | LL | let zeroed = mem::zeroed::<()>; | |
| 80 | | ++++++ | |
| 81 | ||
| 82 | error: never type fallback affects this `unsafe` function | |
| 83 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22 | |
| 84 | | | |
| 85 | LL | 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> | |
| 91 | help: use `()` annotations to avoid fallback changes | |
| 92 | | | |
| 93 | LL | let zeroed = mem::zeroed::<()>; | |
| 94 | | ++++++ | |
| 95 | ||
| 96 | error: never type fallback affects this `unsafe` function | |
| 97 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17 | |
| 98 | | | |
| 99 | LL | 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> | |
| 105 | help: use `()` annotations to avoid fallback changes | |
| 106 | | | |
| 107 | LL | let f = internally_create::<()>; | |
| 108 | | ++++++ | |
| 109 | ||
| 110 | error: never type fallback affects this call to an `unsafe` method | |
| 111 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13 | |
| 112 | | | |
| 113 | LL | 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 | ||
| 120 | error: never type fallback affects this call to an `unsafe` function | |
| 121 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19 | |
| 122 | | | |
| 123 | LL | match send_message::<_ /* ?0 */>() { | |
| 124 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 125 | ... | |
| 126 | LL | 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 | ||
| 134 | error: aborting due to 10 previous errors | |
| 135 | ||
| 136 | Future incompatibility report: Future breakage diagnostic: | |
| 137 | error: never type fallback affects this call to an `unsafe` function | |
| 138 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 139 | | | |
| 140 | LL | 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 | |
| 147 | help: use `()` annotations to avoid fallback changes | |
| 148 | | | |
| 149 | LL | unsafe { mem::zeroed::<()>() } | |
| 150 | | ++++++ | |
| 151 | ||
| 152 | Future breakage diagnostic: | |
| 153 | error: never type fallback affects this call to an `unsafe` function | |
| 154 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13 | |
| 155 | | | |
| 156 | LL | 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 | |
| 163 | help: use `()` annotations to avoid fallback changes | |
| 164 | | | |
| 165 | LL | core::mem::transmute::<_, ()>(Zst) | |
| 166 | | +++++++++ | |
| 167 | ||
| 168 | Future breakage diagnostic: | |
| 169 | error: never type fallback affects this union access | |
| 170 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18 | |
| 171 | | | |
| 172 | LL | 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 | ||
| 180 | Future breakage diagnostic: | |
| 181 | error: never type fallback affects this raw pointer dereference | |
| 182 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18 | |
| 183 | | | |
| 184 | LL | 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 | |
| 191 | help: use `()` annotations to avoid fallback changes | |
| 192 | | | |
| 193 | LL | unsafe { *ptr::from_ref(&()).cast::<()>() } | |
| 194 | | ++++++ | |
| 195 | ||
| 196 | Future breakage diagnostic: | |
| 197 | error: never type fallback affects this call to an `unsafe` function | |
| 198 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18 | |
| 199 | | | |
| 200 | LL | 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 | |
| 207 | help: use `()` annotations to avoid fallback changes | |
| 208 | | | |
| 209 | LL | unsafe { internally_create::<()>(x) } | |
| 210 | | ++++++ | |
| 211 | ||
| 212 | Future breakage diagnostic: | |
| 213 | error: never type fallback affects this call to an `unsafe` function | |
| 214 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18 | |
| 215 | | | |
| 216 | LL | 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 | |
| 223 | help: use `()` annotations to avoid fallback changes | |
| 224 | | | |
| 225 | LL | let zeroed = mem::zeroed::<()>; | |
| 226 | | ++++++ | |
| 227 | ||
| 228 | Future breakage diagnostic: | |
| 229 | error: never type fallback affects this `unsafe` function | |
| 230 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22 | |
| 231 | | | |
| 232 | LL | 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 | |
| 239 | help: use `()` annotations to avoid fallback changes | |
| 240 | | | |
| 241 | LL | let zeroed = mem::zeroed::<()>; | |
| 242 | | ++++++ | |
| 243 | ||
| 244 | Future breakage diagnostic: | |
| 245 | error: never type fallback affects this `unsafe` function | |
| 246 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17 | |
| 247 | | | |
| 248 | LL | 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 | |
| 255 | help: use `()` annotations to avoid fallback changes | |
| 256 | | | |
| 257 | LL | let f = internally_create::<()>; | |
| 258 | | ++++++ | |
| 259 | ||
| 260 | Future breakage diagnostic: | |
| 261 | error: never type fallback affects this call to an `unsafe` method | |
| 262 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13 | |
| 263 | | | |
| 264 | LL | 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 | ||
| 272 | Future breakage diagnostic: | |
| 273 | error: never type fallback affects this call to an `unsafe` function | |
| 274 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19 | |
| 275 | | | |
| 276 | LL | match send_message::<_ /* ?0 */>() { | |
| 277 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 278 | ... | |
| 279 | LL | 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 @@ |
| 1 | error: never type fallback affects this call to an `unsafe` function | |
| 2 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 3 | | | |
| 4 | LL | 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 | |
| 11 | help: use `()` annotations to avoid fallback changes | |
| 12 | | | |
| 13 | LL | unsafe { mem::zeroed::<()>() } | |
| 14 | | ++++++ | |
| 15 | ||
| 16 | error: never type fallback affects this call to an `unsafe` function | |
| 17 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13 | |
| 18 | | | |
| 19 | LL | 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> | |
| 25 | help: use `()` annotations to avoid fallback changes | |
| 26 | | | |
| 27 | LL | core::mem::transmute::<_, ()>(Zst) | |
| 28 | | +++++++++ | |
| 29 | ||
| 30 | error: never type fallback affects this union access | |
| 31 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18 | |
| 32 | | | |
| 33 | LL | 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 | ||
| 40 | error: never type fallback affects this raw pointer dereference | |
| 41 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18 | |
| 42 | | | |
| 43 | LL | 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> | |
| 49 | help: use `()` annotations to avoid fallback changes | |
| 50 | | | |
| 51 | LL | unsafe { *ptr::from_ref(&()).cast::<()>() } | |
| 52 | | ++++++ | |
| 53 | ||
| 54 | error: never type fallback affects this call to an `unsafe` function | |
| 55 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18 | |
| 56 | | | |
| 57 | LL | 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> | |
| 63 | help: use `()` annotations to avoid fallback changes | |
| 64 | | | |
| 65 | LL | unsafe { internally_create::<()>(x) } | |
| 66 | | ++++++ | |
| 67 | ||
| 68 | error: never type fallback affects this call to an `unsafe` function | |
| 69 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18 | |
| 70 | | | |
| 71 | LL | 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> | |
| 77 | help: use `()` annotations to avoid fallback changes | |
| 78 | | | |
| 79 | LL | let zeroed = mem::zeroed::<()>; | |
| 80 | | ++++++ | |
| 81 | ||
| 82 | error: never type fallback affects this `unsafe` function | |
| 83 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22 | |
| 84 | | | |
| 85 | LL | 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> | |
| 91 | help: use `()` annotations to avoid fallback changes | |
| 92 | | | |
| 93 | LL | let zeroed = mem::zeroed::<()>; | |
| 94 | | ++++++ | |
| 95 | ||
| 96 | error: never type fallback affects this `unsafe` function | |
| 97 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17 | |
| 98 | | | |
| 99 | LL | 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> | |
| 105 | help: use `()` annotations to avoid fallback changes | |
| 106 | | | |
| 107 | LL | let f = internally_create::<()>; | |
| 108 | | ++++++ | |
| 109 | ||
| 110 | error: never type fallback affects this call to an `unsafe` method | |
| 111 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13 | |
| 112 | | | |
| 113 | LL | 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 | ||
| 120 | error: never type fallback affects this call to an `unsafe` function | |
| 121 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19 | |
| 122 | | | |
| 123 | LL | match send_message::<_ /* ?0 */>() { | |
| 124 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 125 | ... | |
| 126 | LL | 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 | ||
| 134 | warning: the type `!` does not permit zero-initialization | |
| 135 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 136 | | | |
| 137 | LL | 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 | ||
| 143 | error: aborting due to 10 previous errors; 1 warning emitted | |
| 144 | ||
| 145 | Future incompatibility report: Future breakage diagnostic: | |
| 146 | error: never type fallback affects this call to an `unsafe` function | |
| 147 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:10:18 | |
| 148 | | | |
| 149 | LL | 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 | |
| 156 | help: use `()` annotations to avoid fallback changes | |
| 157 | | | |
| 158 | LL | unsafe { mem::zeroed::<()>() } | |
| 159 | | ++++++ | |
| 160 | ||
| 161 | Future breakage diagnostic: | |
| 162 | error: never type fallback affects this call to an `unsafe` function | |
| 163 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:27:13 | |
| 164 | | | |
| 165 | LL | 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 | |
| 172 | help: use `()` annotations to avoid fallback changes | |
| 173 | | | |
| 174 | LL | core::mem::transmute::<_, ()>(Zst) | |
| 175 | | +++++++++ | |
| 176 | ||
| 177 | Future breakage diagnostic: | |
| 178 | error: never type fallback affects this union access | |
| 179 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:44:18 | |
| 180 | | | |
| 181 | LL | 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 | ||
| 189 | Future breakage diagnostic: | |
| 190 | error: never type fallback affects this raw pointer dereference | |
| 191 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:55:18 | |
| 192 | | | |
| 193 | LL | 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 | |
| 200 | help: use `()` annotations to avoid fallback changes | |
| 201 | | | |
| 202 | LL | unsafe { *ptr::from_ref(&()).cast::<()>() } | |
| 203 | | ++++++ | |
| 204 | ||
| 205 | Future breakage diagnostic: | |
| 206 | error: never type fallback affects this call to an `unsafe` function | |
| 207 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:76:18 | |
| 208 | | | |
| 209 | LL | 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 | |
| 216 | help: use `()` annotations to avoid fallback changes | |
| 217 | | | |
| 218 | LL | unsafe { internally_create::<()>(x) } | |
| 219 | | ++++++ | |
| 220 | ||
| 221 | Future breakage diagnostic: | |
| 222 | error: never type fallback affects this call to an `unsafe` function | |
| 223 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:94:18 | |
| 224 | | | |
| 225 | LL | 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 | |
| 232 | help: use `()` annotations to avoid fallback changes | |
| 233 | | | |
| 234 | LL | let zeroed = mem::zeroed::<()>; | |
| 235 | | ++++++ | |
| 236 | ||
| 237 | Future breakage diagnostic: | |
| 238 | error: never type fallback affects this `unsafe` function | |
| 239 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:89:22 | |
| 240 | | | |
| 241 | LL | 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 | |
| 248 | help: use `()` annotations to avoid fallback changes | |
| 249 | | | |
| 250 | LL | let zeroed = mem::zeroed::<()>; | |
| 251 | | ++++++ | |
| 252 | ||
| 253 | Future breakage diagnostic: | |
| 254 | error: never type fallback affects this `unsafe` function | |
| 255 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:112:17 | |
| 256 | | | |
| 257 | LL | 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 | |
| 264 | help: use `()` annotations to avoid fallback changes | |
| 265 | | | |
| 266 | LL | let f = internally_create::<()>; | |
| 267 | | ++++++ | |
| 268 | ||
| 269 | Future breakage diagnostic: | |
| 270 | error: never type fallback affects this call to an `unsafe` method | |
| 271 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:137:13 | |
| 272 | | | |
| 273 | LL | 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 | ||
| 281 | Future breakage diagnostic: | |
| 282 | error: never type fallback affects this call to an `unsafe` function | |
| 283 | --> $DIR/lint-never-type-fallback-flowing-into-unsafe.rs:155:19 | |
| 284 | | | |
| 285 | LL | match send_message::<_ /* ?0 */>() { | |
| 286 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 287 | ... | |
| 288 | LL | 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 | ||
| 4 | use std::{marker, mem, ptr}; | |
| 5 | ||
| 6 | fn main() {} | |
| 7 | ||
| 8 | fn _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 | ||
| 23 | fn _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 | ||
| 37 | fn _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 | ||
| 53 | fn _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 | ||
| 64 | fn _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 | ||
| 87 | fn _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 | ||
| 103 | fn _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 | ||
| 125 | fn _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 | |
| 148 | fn _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 | ||
| 9 | fn 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 @@ |
| 1 | warning: unreachable statement | |
| 2 | --> $DIR/never-assign-dead-code.rs:11:5 | |
| 3 | | | |
| 4 | LL | let x: ! = panic!("aah"); | |
| 5 | | ------------- any code following this expression is unreachable | |
| 6 | LL | drop(x); | |
| 7 | | ^^^^^^^^ unreachable statement | |
| 8 | | | |
| 9 | note: the lint level is defined here | |
| 10 | --> $DIR/never-assign-dead-code.rs:7:9 | |
| 11 | | | |
| 12 | LL | #![warn(unused)] | |
| 13 | | ^^^^^^ | |
| 14 | = note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]` | |
| 15 | ||
| 16 | warning: unreachable call | |
| 17 | --> $DIR/never-assign-dead-code.rs:11:5 | |
| 18 | | | |
| 19 | LL | drop(x); | |
| 20 | | ^^^^ - any code following this expression is unreachable | |
| 21 | | | | |
| 22 | | unreachable call | |
| 23 | ||
| 24 | warning: unused variable: `x` | |
| 25 | --> $DIR/never-assign-dead-code.rs:10:9 | |
| 26 | | | |
| 27 | LL | 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 | ||
| 32 | warning: 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 | ||
| 5 | fn main() { | |
| 6 | let x: ! = "hello"; //~ ERROR mismatched types | |
| 7 | } |
tests/ui/never_type/never-assign-wrong-type.stderr deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/never-assign-wrong-type.rs:6:16 | |
| 3 | | | |
| 4 | LL | let x: ! = "hello"; | |
| 5 | | - ^^^^^^^ expected `!`, found `&str` | |
| 6 | | | | |
| 7 | | expected due to this | |
| 8 | | | |
| 9 | = note: expected type `!` | |
| 10 | found reference `&'static str` | |
| 11 | ||
| 12 | error: aborting due to 1 previous error | |
| 13 | ||
| 14 | For 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 | ||
| 7 | trait Foo { | |
| 8 | type Wow; | |
| 9 | ||
| 10 | fn smeg(&self) -> Self::Wow; | |
| 11 | } | |
| 12 | ||
| 13 | struct Blah; | |
| 14 | impl Foo for Blah { | |
| 15 | type Wow = !; | |
| 16 | fn smeg(&self) -> ! { | |
| 17 | panic!("kapow!"); | |
| 18 | } | |
| 19 | } | |
| 20 | ||
| 21 | fn 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 | |
| 2 | fn main() { | |
| 3 | *return //~ ERROR type `!` cannot be dereferenced | |
| 4 | ; | |
| 5 | } |
tests/ui/never_type/never-deref.stderr deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | error[E0614]: type `!` cannot be dereferenced | |
| 2 | --> $DIR/never-deref.rs:3:5 | |
| 3 | | | |
| 4 | LL | *return | |
| 5 | | ^^^^^^^ can't be dereferenced | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 | ||
| 10 | fn 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 @@ |
| 1 | error[E0029]: only `char` and numeric types are allowed in range patterns | |
| 2 | --> $DIR/never-in-range-pat.rs:13:12 | |
| 3 | | | |
| 4 | LL | 0..x => {} | |
| 5 | | - ^ this is of type `!` but it should be `char` or numeric | |
| 6 | | | | |
| 7 | | this is of type `{integer}` | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For 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 | ||
| 4 | enum Never {} | |
| 5 | ||
| 6 | fn example(x: Never) -> [i32; 1] { | |
| 7 | let ! = x; | |
| 8 | [1] | |
| 9 | } | |
| 10 | ||
| 11 | fn function_param_never(!: Never) -> [i32; 1] { | |
| 12 | [1] | |
| 13 | } | |
| 14 | ||
| 15 | fn generic_never<T>(!: T) -> [i32; 1] //~ ERROR mismatched types | |
| 16 | where | |
| 17 | T: Copy, | |
| 18 | { | |
| 19 | [1] | |
| 20 | } | |
| 21 | ||
| 22 | fn 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 @@ |
| 1 | error: mismatched types | |
| 2 | --> $DIR/never-pattern-as-closure-param-141592.rs:15:21 | |
| 3 | | | |
| 4 | LL | 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 | ||
| 9 | error: mismatched types | |
| 10 | --> $DIR/never-pattern-as-closure-param-141592.rs:23:31 | |
| 11 | | | |
| 12 | LL | 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 | ||
| 17 | error: 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 | ||
| 10 | fn 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 | ||
| 7 | struct Wub; | |
| 8 | ||
| 9 | impl PartialEq<!> for Wub { | |
| 10 | fn eq(&self, other: &!) -> bool { | |
| 11 | *other | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | fn 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 | ||
| 17 | fn 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 | ||
| 3 | trait X<const N: i32> {} | |
| 4 | ||
| 5 | fn hello<T: X<{ fn hello() -> ! { loop {} } 1 }>>() {} | |
| 6 | ||
| 7 | fn 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 | ||
| 3 | fn 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 @@ |
| 1 | error[E0599]: no method named `push` found for type `!` in the current scope | |
| 2 | --> $DIR/never-type-method-call-15207.rs:5:15 | |
| 3 | | | |
| 4 | LL | break.push(1) | |
| 5 | | ^^^^ method not found in `!` | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 | ||
| 10 | fn never_direct(x: !) { | |
| 11 | x; | |
| 12 | } | |
| 13 | ||
| 14 | fn never_ref_pat(ref x: !) { | |
| 15 | *x; | |
| 16 | } | |
| 17 | ||
| 18 | fn never_ref(x: &!) { | |
| 19 | let &y = x; | |
| 20 | y; | |
| 21 | } | |
| 22 | ||
| 23 | fn never_pointer(x: *const !) { | |
| 24 | unsafe { | |
| 25 | *x; | |
| 26 | } | |
| 27 | } | |
| 28 | ||
| 29 | fn never_slice(x: &[!]) { | |
| 30 | x[0]; | |
| 31 | } | |
| 32 | ||
| 33 | fn never_match(x: Result<(), !>) { | |
| 34 | match x { | |
| 35 | Ok(_) => {}, | |
| 36 | Err(_) => {}, | |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | pub 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 | ||
| 5 | fn 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 | ||
| 4 | enum Never {} | |
| 5 | ||
| 6 | fn example(x: Never) -> [i32; 1] { | |
| 7 | let ! = x; | |
| 8 | [1] | |
| 9 | } | |
| 10 | ||
| 11 | fn function_param_never(!: Never) -> [i32; 1] { | |
| 12 | [1] | |
| 13 | } | |
| 14 | ||
| 15 | fn generic_never<T>(!: T) -> [i32; 1] //~ ERROR mismatched types | |
| 16 | where | |
| 17 | T: Copy, | |
| 18 | { | |
| 19 | [1] | |
| 20 | } | |
| 21 | ||
| 22 | fn 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 @@ |
| 1 | error: mismatched types | |
| 2 | --> $DIR/never-pattern-as-closure-param-141592.rs:15:21 | |
| 3 | | | |
| 4 | LL | 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 | ||
| 9 | error: mismatched types | |
| 10 | --> $DIR/never-pattern-as-closure-param-141592.rs:23:31 | |
| 11 | | | |
| 12 | LL | 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 | ||
| 17 | error: 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 @@ |
| 1 | fn 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 | ||
| 12 | fn main() {} |
tests/ui/never_type/never_pattern/unused_trait_in_never_pattern_body.stderr created+36| ... | ... | @@ -0,0 +1,36 @@ |
| 1 | error[E0658]: `!` patterns are experimental | |
| 2 | --> $DIR/unused_trait_in_never_pattern_body.rs:3:9 | |
| 3 | | | |
| 4 | LL | ! => || { | |
| 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 | ||
| 11 | error: a never pattern is always unreachable | |
| 12 | --> $DIR/unused_trait_in_never_pattern_body.rs:3:14 | |
| 13 | | | |
| 14 | LL | ! => || { | |
| 15 | | ______________^ | |
| 16 | LL | | | |
| 17 | LL | | | |
| 18 | LL | | use std::ops::Add; | |
| 19 | LL | | 0.add(1) | |
| 20 | LL | | }, | |
| 21 | | | ^ | |
| 22 | | | | | |
| 23 | | |_________this will never be executed | |
| 24 | | help: remove this expression | |
| 25 | ||
| 26 | error: mismatched types | |
| 27 | --> $DIR/unused_trait_in_never_pattern_body.rs:3:9 | |
| 28 | | | |
| 29 | LL | ! => || { | |
| 30 | | ^ a never pattern must be used on an uninhabited type | |
| 31 | | | |
| 32 | = note: the matched value is of type `i32` | |
| 33 | ||
| 34 | error: aborting due to 3 previous errors | |
| 35 | ||
| 36 | For 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 | ||
| 8 | struct Foo; | |
| 9 | ||
| 10 | pub fn f(x: !) -> ! { | |
| 11 | x | |
| 12 | } | |
| 13 | ||
| 14 | pub 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 | ||
| 23 | fn 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 | ||
| 12 | type Infallible = !; | |
| 13 | ||
| 14 | struct E; | |
| 15 | ||
| 16 | impl From<Infallible> for E { | |
| 17 | fn from(_: Infallible) -> E { | |
| 18 | E | |
| 19 | } | |
| 20 | } | |
| 21 | ||
| 22 | fn u32_try_from(x: u32) -> Result<u32, Infallible> { | |
| 23 | Ok(x) | |
| 24 | } | |
| 25 | ||
| 26 | fn _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 | ||
| 46 | fn 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 | ||
| 7 | struct TrieMapIterator<'a> { | |
| 8 | node: &'a usize | |
| 9 | } | |
| 10 | ||
| 11 | fn 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 | ||
| 11 | fn g() { | |
| 12 | &panic!() //~ ERROR mismatched types | |
| 13 | } | |
| 14 | ||
| 15 | // This used to ICE, see <https://github.com/rust-lang/rust/issues/10176> | |
| 16 | fn f() -> isize { | |
| 17 | (return 1, return 2) //~ ERROR mismatched types | |
| 18 | } | |
| 19 | ||
| 20 | fn main() {} |
tests/ui/never_type/regress/divergent-block-with-tail.stderr created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | error[E0308]: mismatched types | |
| 2 | --> $DIR/divergent-block-with-tail.rs:12:5 | |
| 3 | | | |
| 4 | LL | &panic!() | |
| 5 | | ^^^^^^^^^ expected `()`, found `&_` | |
| 6 | | | |
| 7 | = note: expected unit type `()` | |
| 8 | found reference `&_` | |
| 9 | help: a return type might be missing here | |
| 10 | | | |
| 11 | LL | fn g() -> _ { | |
| 12 | | ++++ | |
| 13 | help: consider removing the borrow | |
| 14 | | | |
| 15 | LL - &panic!() | |
| 16 | LL + panic!() | |
| 17 | | | |
| 18 | ||
| 19 | error[E0308]: mismatched types | |
| 20 | --> $DIR/divergent-block-with-tail.rs:17:5 | |
| 21 | | | |
| 22 | LL | fn f() -> isize { | |
| 23 | | ----- expected `isize` because of return type | |
| 24 | LL | (return 1, return 2) | |
| 25 | | ^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `(!, !)` | |
| 26 | | | |
| 27 | = note: expected type `isize` | |
| 28 | found tuple `(!, !)` | |
| 29 | ||
| 30 | error: aborting due to 2 previous errors | |
| 31 | ||
| 32 | For 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 | ||
| 8 | fn ice(a: !) { | |
| 9 | a == a; | |
| 10 | } | |
| 11 | ||
| 12 | fn 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 | ||
| 3 | fn 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 @@ |
| 1 | error[E0609]: no field `is_failure` on type `!` | |
| 2 | --> $DIR/field-access-never-type-13847.rs:4:12 | |
| 3 | | | |
| 4 | LL | return.is_failure | |
| 5 | | ^^^^^^^^^^ unknown field | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 | ||
| 3 | fn 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 @@ |
| 1 | warning: denote infinite loops with `loop { ... }` | |
| 2 | --> $DIR/loop-in-array-length.rs:8:11 | |
| 3 | | | |
| 4 | LL | [(); {while true {break}; 0}]; | |
| 5 | | ^^^^^^^^^^ help: use `loop` | |
| 6 | | | |
| 7 | = note: `#[warn(while_true)]` on by default | |
| 8 | ||
| 9 | error[E0308]: mismatched types | |
| 10 | --> $DIR/loop-in-array-length.rs:4:10 | |
| 11 | | | |
| 12 | LL | [(); & { loop { continue } } ]; | |
| 13 | | ^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&_` | |
| 14 | | | |
| 15 | = note: expected type `usize` | |
| 16 | found reference `&_` | |
| 17 | help: consider removing the borrow | |
| 18 | | | |
| 19 | LL - [(); & { loop { continue } } ]; | |
| 20 | LL + [(); { loop { continue } } ]; | |
| 21 | | | |
| 22 | ||
| 23 | error[E0308]: mismatched types | |
| 24 | --> $DIR/loop-in-array-length.rs:6:17 | |
| 25 | | | |
| 26 | LL | [(); loop { break }]; | |
| 27 | | ^^^^^ expected `usize`, found `()` | |
| 28 | | | |
| 29 | help: give the `break` a value of the expected type | |
| 30 | | | |
| 31 | LL | [(); loop { break 42 }]; | |
| 32 | | ++ | |
| 33 | ||
| 34 | error[E0277]: the trait bound `std::ops::RangeFrom<usize>: const Iterator` is not satisfied | |
| 35 | --> $DIR/loop-in-array-length.rs:11:21 | |
| 36 | | | |
| 37 | LL | [(); { for _ in 0usize.. {}; 0}]; | |
| 38 | | ^^^^^^^^ required by a bound introduced by this call | |
| 39 | | | |
| 40 | note: 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 | ||
| 44 | error[E0277]: the trait bound `std::ops::RangeFrom<usize>: const Iterator` is not satisfied | |
| 45 | --> $DIR/loop-in-array-length.rs:11:21 | |
| 46 | | | |
| 47 | LL | [(); { for _ in 0usize.. {}; 0}]; | |
| 48 | | ^^^^^^^^ | |
| 49 | | | |
| 50 | note: trait `Iterator` is implemented but not `const` | |
| 51 | --> $SRC_DIR/core/src/iter/range.rs:LL:COL | |
| 52 | ||
| 53 | error: aborting due to 4 previous errors; 1 warning emitted | |
| 54 | ||
| 55 | Some errors have detailed explanations: E0277, E0308. | |
| 56 | For 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 | ||
| 3 | fn 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 @@ |
| 1 | error: unexpected token: `...` | |
| 2 | --> $DIR/malformed-range-to-never.rs:4:6 | |
| 3 | | | |
| 4 | LL | 0.....{loop{}1}; | |
| 5 | | ^^^ | |
| 6 | | | |
| 7 | help: use `..` for an exclusive range | |
| 8 | | | |
| 9 | LL - 0.....{loop{}1}; | |
| 10 | LL + 0....{loop{}1}; | |
| 11 | | | |
| 12 | help: or `..=` for an inclusive range | |
| 13 | | | |
| 14 | LL - 0.....{loop{}1}; | |
| 15 | LL + 0..=..{loop{}1}; | |
| 16 | | | |
| 17 | ||
| 18 | error[E0308]: mismatched types | |
| 19 | --> $DIR/malformed-range-to-never.rs:4:9 | |
| 20 | | | |
| 21 | LL | 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}>` | |
| 29 | note: associated function defined here | |
| 30 | --> $SRC_DIR/core/src/ops/range.rs:LL:COL | |
| 31 | ||
| 32 | error: aborting due to 2 previous errors | |
| 33 | ||
| 34 | For 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 | ||
| 6 | fn foo(_: Box<dyn FnMut()>) {} | |
| 7 | ||
| 8 | fn 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 | ||
| 6 | use std::iter::{self, Empty}; | |
| 7 | ||
| 8 | trait Trait { | |
| 9 | type Out: Iterator<Item = u32>; | |
| 10 | ||
| 11 | fn f(&self) -> Option<Self::Out>; | |
| 12 | } | |
| 13 | ||
| 14 | impl<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 | ||
| 22 | struct X; | |
| 23 | ||
| 24 | impl Trait for X { | |
| 25 | type Out = Empty<u32>; | |
| 26 | ||
| 27 | fn f(&self) -> Option<Self::Out> { | |
| 28 | Some(iter::empty()) | |
| 29 | } | |
| 30 | } | |
| 31 | ||
| 32 | fn 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 | ||
| 41 | pub fn main() { | |
| 42 | f(10); | |
| 43 | } |
tests/ui/never_type/regress/never-as-spec-default-associated-type.stderr created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | error[E0277]: `!` is not an iterator | |
| 2 | --> $DIR/never-as-spec-default-associated-type.rs:15:24 | |
| 3 | | | |
| 4 | LL | default type Out = !; | |
| 5 | | ^ `!` is not an iterator | |
| 6 | | | |
| 7 | = help: the trait `Iterator` is not implemented for `!` | |
| 8 | note: required by a bound in `Trait::Out` | |
| 9 | --> $DIR/never-as-spec-default-associated-type.rs:9:15 | |
| 10 | | | |
| 11 | LL | type Out: Iterator<Item = u32>; | |
| 12 | | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `Trait::Out` | |
| 13 | ||
| 14 | error: aborting due to 1 previous error | |
| 15 | ||
| 16 | For 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 | |
| 2 | fn main() { | |
| 3 | *return //~ ERROR type `!` cannot be dereferenced | |
| 4 | ; | |
| 5 | } |
tests/ui/never_type/regress/never-deref.stderr created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | error[E0614]: type `!` cannot be dereferenced | |
| 2 | --> $DIR/never-deref.rs:3:5 | |
| 3 | | | |
| 4 | LL | *return | |
| 5 | | ^^^^^^^ can't be dereferenced | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 | ||
| 10 | fn 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 @@ |
| 1 | error[E0029]: only `char` and numeric types are allowed in range patterns | |
| 2 | --> $DIR/never-in-range-pat.rs:13:12 | |
| 3 | | | |
| 4 | LL | 0..x => {} | |
| 5 | | - ^ this is of type `!` but it should be `char` or numeric | |
| 6 | | | | |
| 7 | | this is of type `{integer}` | |
| 8 | ||
| 9 | error: aborting due to 1 previous error | |
| 10 | ||
| 11 | For 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 | ||
| 17 | fn 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 | ||
| 3 | fn 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 @@ |
| 1 | error[E0599]: no method named `push` found for type `!` in the current scope | |
| 2 | --> $DIR/never-type-method-call-15207.rs:5:15 | |
| 3 | | | |
| 4 | LL | break.push(1) | |
| 5 | | ^^^^ method not found in `!` | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 | ||
| 5 | fn test2() { | |
| 6 | let x: !; | |
| 7 | let c2 = SingleVariant::Points(0) | |
| 8 | | match x { //~ ERROR no implementation for `SingleVariant | ()` | |
| 9 | _ => (), | |
| 10 | }; | |
| 11 | } | |
| 12 | ||
| 13 | enum SingleVariant { | |
| 14 | Points(u32), | |
| 15 | } | |
| 16 | ||
| 17 | fn main() {} |
tests/ui/never_type/regress/span-bug-issue-121445.stderr created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | error[E0369]: no implementation for `SingleVariant | ()` | |
| 2 | --> $DIR/span-bug-issue-121445.rs:8:9 | |
| 3 | | | |
| 4 | LL | let c2 = SingleVariant::Points(0) | |
| 5 | | ------------------------ SingleVariant | |
| 6 | LL | | match x { | |
| 7 | | _________^_- | |
| 8 | LL | | _ => (), | |
| 9 | LL | | }; | |
| 10 | | |_________- () | |
| 11 | | | |
| 12 | note: an implementation of `BitOr<()>` might be missing for `SingleVariant` | |
| 13 | --> $DIR/span-bug-issue-121445.rs:13:1 | |
| 14 | | | |
| 15 | LL | enum SingleVariant { | |
| 16 | | ^^^^^^^^^^^^^^^^^^ must implement `BitOr<()>` | |
| 17 | note: the trait `BitOr` must be implemented | |
| 18 | --> $SRC_DIR/core/src/ops/bit.rs:LL:COL | |
| 19 | ||
| 20 | error: aborting due to 1 previous error | |
| 21 | ||
| 22 | For more information about this error, try `rustc --explain E0369`. |
tests/ui/never_type/regress/suggestion-ice-132517.rs created+4| ... | ... | @@ -0,0 +1,4 @@ |
| 1 | fn 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 @@ |
| 1 | error[E0425]: cannot find function `x` in this scope | |
| 2 | --> $DIR/suggestion-ice-132517.rs:2:5 | |
| 3 | | | |
| 4 | LL | x::<_>(|_| panic!()) | |
| 5 | | ^ not found in this scope | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 | ||
| 7 | fn call_another_fn<T, F: FnOnce() -> T>(f: F) -> T { | |
| 8 | f() | |
| 9 | } | |
| 10 | ||
| 11 | fn wub() -> ! { | |
| 12 | panic!("aah!"); | |
| 13 | } | |
| 14 | ||
| 15 | fn 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 | ||
| 5 | fn test2() { | |
| 6 | let x: !; | |
| 7 | let c2 = SingleVariant::Points(0) | |
| 8 | | match x { //~ ERROR no implementation for `SingleVariant | ()` | |
| 9 | _ => (), | |
| 10 | }; | |
| 11 | } | |
| 12 | ||
| 13 | enum SingleVariant { | |
| 14 | Points(u32), | |
| 15 | } | |
| 16 | ||
| 17 | fn main() {} |
tests/ui/never_type/span-bug-issue-121445.stderr deleted-22| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | error[E0369]: no implementation for `SingleVariant | ()` | |
| 2 | --> $DIR/span-bug-issue-121445.rs:8:9 | |
| 3 | | | |
| 4 | LL | let c2 = SingleVariant::Points(0) | |
| 5 | | ------------------------ SingleVariant | |
| 6 | LL | | match x { | |
| 7 | | _________^_- | |
| 8 | LL | | _ => (), | |
| 9 | LL | | }; | |
| 10 | | |_________- () | |
| 11 | | | |
| 12 | note: an implementation of `BitOr<()>` might be missing for `SingleVariant` | |
| 13 | --> $DIR/span-bug-issue-121445.rs:13:1 | |
| 14 | | | |
| 15 | LL | enum SingleVariant { | |
| 16 | | ^^^^^^^^^^^^^^^^^^ must implement `BitOr<()>` | |
| 17 | note: the trait `BitOr` must be implemented | |
| 18 | --> $SRC_DIR/core/src/ops/bit.rs:LL:COL | |
| 19 | ||
| 20 | error: aborting due to 1 previous error | |
| 21 | ||
| 22 | For more information about this error, try `rustc --explain E0369`. |
tests/ui/never_type/suggestion-ice-132517.rs deleted-4| ... | ... | @@ -1,4 +0,0 @@ |
| 1 | fn 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 @@ |
| 1 | error[E0425]: cannot find function `x` in this scope | |
| 2 | --> $DIR/suggestion-ice-132517.rs:2:5 | |
| 3 | | | |
| 4 | LL | x::<_>(|_| panic!()) | |
| 5 | | ^ not found in this scope | |
| 6 | ||
| 7 | error: aborting due to 1 previous error | |
| 8 | ||
| 9 | For 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 @@ |
| 1 | error[E0277]: the trait bound `!: From<()>` is not satisfied | |
| 2 | --> $DIR/try-block-never-type-fallback.rs:20:9 | |
| 3 | | | |
| 4 | LL | 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<!>` | |
| 12 | note: required by a bound in `bar` | |
| 13 | --> $DIR/try-block-never-type-fallback.rs:15:23 | |
| 14 | | | |
| 15 | LL | fn bar(_: Result<impl Into<!>, u32>) { | |
| 16 | | ^^^^^^^ required by this bound in `bar` | |
| 17 | ||
| 18 | error: aborting due to 1 previous error | |
| 19 | ||
| 20 | For 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 | ||
| 15 | fn bar(_: Result<impl Into<!>, u32>) { | |
| 16 | unimplemented!() | |
| 17 | } | |
| 18 | ||
| 19 | fn foo(x: Result<!, u32>) { | |
| 20 | bar(try { x? }); | |
| 21 | //[e2021]~^ ERROR the trait bound `!: From<()>` is not satisfied | |
| 22 | } | |
| 23 | ||
| 24 | fn main() { | |
| 25 | } |
tests/ui/never_type/unused_trait_in_never_pattern_body.rs deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | fn 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 | ||
| 12 | fn main() {} |
tests/ui/never_type/unused_trait_in_never_pattern_body.stderr deleted-36| ... | ... | @@ -1,36 +0,0 @@ |
| 1 | error[E0658]: `!` patterns are experimental | |
| 2 | --> $DIR/unused_trait_in_never_pattern_body.rs:3:9 | |
| 3 | | | |
| 4 | LL | ! => || { | |
| 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 | ||
| 11 | error: a never pattern is always unreachable | |
| 12 | --> $DIR/unused_trait_in_never_pattern_body.rs:3:14 | |
| 13 | | | |
| 14 | LL | ! => || { | |
| 15 | | ______________^ | |
| 16 | LL | | | |
| 17 | LL | | | |
| 18 | LL | | use std::ops::Add; | |
| 19 | LL | | 0.add(1) | |
| 20 | LL | | }, | |
| 21 | | | ^ | |
| 22 | | | | | |
| 23 | | |_________this will never be executed | |
| 24 | | help: remove this expression | |
| 25 | ||
| 26 | error: mismatched types | |
| 27 | --> $DIR/unused_trait_in_never_pattern_body.rs:3:9 | |
| 28 | | | |
| 29 | LL | ! => || { | |
| 30 | | ^ a never pattern must be used on an uninhabited type | |
| 31 | | | |
| 32 | = note: the matched value is of type `i32` | |
| 33 | ||
| 34 | error: aborting due to 3 previous errors | |
| 35 | ||
| 36 | For 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 | ||
| 6 | fn _f() { | |
| 7 | #[rustfmt::skip] | |
| 8 | let _x = match true { | |
| 9 | true => { 10 }, | |
| 10 | false => { return }, | |
| 11 | }; | |
| 12 | } | |
| 13 | ||
| 14 | fn main() {} |
tests/ui/process/nofile-limit.rs+3| ... | ... | @@ -11,6 +11,9 @@ |
| 11 | 11 | |
| 12 | 12 | #![feature(exit_status_error)] |
| 13 | 13 | #![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)] | |
| 14 | 17 | extern crate libc; |
| 15 | 18 | |
| 16 | 19 | use 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 | ||
| 9 | fn 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 @@ |
| 1 | warning: unreachable statement | |
| 2 | --> $DIR/never-assign-dead-code.rs:11:5 | |
| 3 | | | |
| 4 | LL | let x: ! = panic!("aah"); | |
| 5 | | ------------- any code following this expression is unreachable | |
| 6 | LL | drop(x); | |
| 7 | | ^^^^^^^^ unreachable statement | |
| 8 | | | |
| 9 | note: the lint level is defined here | |
| 10 | --> $DIR/never-assign-dead-code.rs:7:9 | |
| 11 | | | |
| 12 | LL | #![warn(unused)] | |
| 13 | | ^^^^^^ | |
| 14 | = note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]` | |
| 15 | ||
| 16 | warning: unreachable call | |
| 17 | --> $DIR/never-assign-dead-code.rs:11:5 | |
| 18 | | | |
| 19 | LL | drop(x); | |
| 20 | | ^^^^ - any code following this expression is unreachable | |
| 21 | | | | |
| 22 | | unreachable call | |
| 23 | ||
| 24 | warning: unused variable: `x` | |
| 25 | --> $DIR/never-assign-dead-code.rs:10:9 | |
| 26 | | | |
| 27 | LL | 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 | ||
| 32 | warning: 3 warnings emitted | |
| 33 |