diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index 8c0228101133a..6ea72de92ce8c 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -145,6 +145,8 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { }, ); } else { + // Report the method call's return type before adjustments required by its parent. + let unadjusted_expr_ty = cx.typeck_results().expr_ty(expr); match name { // If `type_of(x) == T` and `x.borrow()` is used to get `&T`, // then that should be allowed @@ -152,12 +154,12 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { sym::noop_method_clone => cx.emit_span_lint( SUSPICIOUS_DOUBLE_REF_OP, span, - SuspiciousDoubleRefCloneDiag { ty: expr_ty }, + SuspiciousDoubleRefCloneDiag { ty: unadjusted_expr_ty }, ), sym::noop_method_deref => cx.emit_span_lint( SUSPICIOUS_DOUBLE_REF_OP, span, - SuspiciousDoubleRefDerefDiag { ty: expr_ty }, + SuspiciousDoubleRefDerefDiag { ty: unadjusted_expr_ty }, ), _ => return, } diff --git a/compiler/rustc_mir_build/src/diagnostics.rs b/compiler/rustc_mir_build/src/diagnostics.rs index fea6e85ed9641..b9dbbb169fb8c 100644 --- a/compiler/rustc_mir_build/src/diagnostics.rs +++ b/compiler/rustc_mir_build/src/diagnostics.rs @@ -5,7 +5,7 @@ use rustc_errors::{ }; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_middle::ty::{self, Ty}; -use rustc_pattern_analysis::errors::Uncovered; +use rustc_pattern_analysis::diagnostics::Uncovered; use rustc_pattern_analysis::rustc::RustcPatCtxt; use rustc_span::{Ident, Span, Symbol}; diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 274a9d874790e..7a38d9293724d 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -13,7 +13,7 @@ use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::*; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt}; -use rustc_pattern_analysis::errors::Uncovered; +use rustc_pattern_analysis::diagnostics::Uncovered; use rustc_pattern_analysis::rustc::{ Constructor, DeconstructedPat, MatchArm, RedundancyExplanation, RevealedTy, RustcPatCtxt as PatCtxt, Usefulness, UsefulnessReport, WitnessPat, diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs index f8a0cfaecf8e9..d60f826c0ac2b 100644 --- a/compiler/rustc_passes/src/abi_test.rs +++ b/compiler/rustc_passes/src/abi_test.rs @@ -9,7 +9,7 @@ use rustc_span::Span; use rustc_target::callconv::FnAbi; use super::layout_test::ensure_wf; -use crate::errors::{AbiInvalidAttribute, AbiNe, AbiOf, UnrecognizedArgument}; +use crate::diagnostics::{AbiInvalidAttribute, AbiNe, AbiOf, UnrecognizedArgument}; pub fn test_abi(tcx: TyCtxt<'_>) { if !tcx.features().rustc_attrs() { diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ec94e33e92c69..cb2e1494b9cc0 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -48,7 +48,7 @@ use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs}; use rustc_trait_selection::traits::ObligationCtxt; -use crate::errors; +use crate::diagnostics; #[derive(Diagnostic)] #[diag("`#[diagnostic::on_const]` can only be applied to non-const trait implementations")] @@ -444,21 +444,25 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match item { Some(item) if matches!(item.kind, ty::AssocKind::Fn { .. }) => { if !item.defaultness(self.tcx).has_value() { - self.tcx.dcx().emit_err(errors::FunctionNotHaveDefaultImplementation { - span: self.tcx.def_span(item.def_id), - note_span: attr_span, - }); + self.tcx.dcx().emit_err( + diagnostics::FunctionNotHaveDefaultImplementation { + span: self.tcx.def_span(item.def_id), + note_span: attr_span, + }, + ); } } Some(item) => { - self.dcx().emit_err(errors::MustImplementNotFunction { + self.dcx().emit_err(diagnostics::MustImplementNotFunction { span: self.tcx.def_span(item.def_id), - span_note: errors::MustImplementNotFunctionSpanNote { span: attr_span }, - note: errors::MustImplementNotFunctionNote {}, + span_note: diagnostics::MustImplementNotFunctionSpanNote { + span: attr_span, + }, + note: diagnostics::MustImplementNotFunctionNote {}, }); } None => { - self.dcx().emit_err(errors::FunctionNotFoundInTrait { span: ident.span }); + self.dcx().emit_err(diagnostics::FunctionNotFoundInTrait { span: ident.span }); } } } @@ -468,9 +472,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { for ident in &*list { if let Some(dup) = set.insert(ident.name, ident.span) { - self.tcx - .dcx() - .emit_err(errors::FunctionNamesDuplicated { spans: vec![dup, ident.span] }); + self.tcx.dcx().emit_err(diagnostics::FunctionNamesDuplicated { + spans: vec![dup, ident.span], + }); } } } @@ -480,7 +484,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { Target::Fn | Target::Static => {} _ => { - self.dcx().emit_err(errors::EiiImplTarget { span: *span }); + self.dcx().emit_err(diagnostics::EiiImplTarget { span: *span }); } } @@ -488,10 +492,10 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && find_attr!(self.tcx, *eii_macro, EiiDeclaration(EiiDecl { impl_unsafe, .. }) if *impl_unsafe) && !impl_marked_unsafe { - self.dcx().emit_err(errors::EiiImplRequiresUnsafe { + self.dcx().emit_err(diagnostics::EiiImplRequiresUnsafe { span: *span, name: self.tcx.item_name(*eii_macro), - suggestion: errors::EiiImplRequiresUnsafeSuggestion { + suggestion: diagnostics::EiiImplRequiresUnsafeSuggestion { left: inner_span.shrink_to_lo(), right: inner_span.shrink_to_hi(), }, @@ -524,7 +528,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, hir_id, span, - errors::UnknownFormatParameterForOnUnimplementedAttr { + diagnostics::UnknownFormatParameterForOnUnimplementedAttr { argument_name, trait_name: *trait_name, help: !directive.is_rustc_attr, @@ -596,7 +600,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, hir_id, span, - errors::OnMoveMalformedFormatLiterals { name: argument_name }, + diagnostics::OnMoveMalformedFormatLiterals { name: argument_name }, ) } }); @@ -626,7 +630,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { MALFORMED_DIAGNOSTIC_ATTRIBUTES, hir_id, generics.span, - errors::OnTypeErrorNotExactlyOneGeneric { count: generic_count }, + diagnostics::OnTypeErrorNotExactlyOneGeneric { count: generic_count }, ); } @@ -648,7 +652,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, hir_id, span, - errors::OnTypeErrorMalformedFormatLiterals { name: argument_name }, + diagnostics::OnTypeErrorMalformedFormatLiterals { name: argument_name }, ) } }); @@ -674,7 +678,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr_span, - errors::InlineIgnoredForExported, + diagnostics::InlineIgnoredForExported, ); } } @@ -741,7 +745,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { { let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); - self.dcx().emit_err(errors::LangItemWithTrackCaller { + self.dcx().emit_err(diagnostics::LangItemWithTrackCaller { attr_span, name: item.name(), sig_span: sig.span, @@ -756,7 +760,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { EiiImplResolution::Known(decl) => decl.name.name, EiiImplResolution::Error(_eg) => continue, }; - self.dcx().emit_err(errors::EiiWithTrackCaller { + self.dcx().emit_err(diagnostics::EiiWithTrackCaller { attr_span, name, sig_span: sig.span, @@ -785,7 +789,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && !fields.is_empty() && fields.iter().any(|f| f.default.is_some()) { - self.dcx().emit_err(errors::NonExhaustiveWithDefaultFieldValues { + self.dcx().emit_err(diagnostics::NonExhaustiveWithDefaultFieldValues { attr_span, defn_span: span, }); @@ -815,7 +819,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { { let sig = self.tcx.hir_node(hir_id).fn_sig().unwrap(); - self.dcx().emit_err(errors::LangItemWithTargetFeature { + self.dcx().emit_err(diagnostics::LangItemWithTargetFeature { attr_span, name: lang_item.name(), sig_span: sig.span, @@ -883,11 +887,11 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | Target::MacroCall | Target::Delegation { .. } => None, } { - self.tcx.dcx().emit_err(errors::DocAliasBadLocation { span, location }); + self.tcx.dcx().emit_err(diagnostics::DocAliasBadLocation { span, location }); return; } if self.tcx.hir_opt_name(hir_id) == Some(alias) { - self.tcx.dcx().emit_err(errors::DocAliasNotAnAlias { span, attr_str: alias }); + self.tcx.dcx().emit_err(diagnostics::DocAliasNotAnAlias { span, attr_str: alias }); return; } } @@ -910,18 +914,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> { false }; if !is_valid { - self.dcx().emit_err(errors::DocFakeVariadicNotValid { span }); + self.dcx().emit_err(diagnostics::DocFakeVariadicNotValid { span }); } } _ => { - self.dcx().emit_err(errors::DocKeywordOnlyImpl { span }); + self.dcx().emit_err(diagnostics::DocKeywordOnlyImpl { span }); } } } fn check_doc_search_unbox(&self, span: Span, hir_id: HirId) { let hir::Node::Item(item) = self.tcx.hir_node(hir_id) else { - self.dcx().emit_err(errors::DocSearchUnboxInvalid { span }); + self.dcx().emit_err(diagnostics::DocSearchUnboxInvalid { span }); return; }; match item.kind { @@ -934,7 +938,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { }) => {} ItemKind::TyAlias(_, generics, _) if generics.params.len() != 0 => {} _ => { - self.dcx().emit_err(errors::DocSearchUnboxInvalid { span }); + self.dcx().emit_err(diagnostics::DocSearchUnboxInvalid { span }); } } } @@ -961,7 +965,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { *span2, msg!("{\".\"}..conflicts with this attribute"), ); - self.dcx().emit_err(errors::DocInlineConflict { spans }); + self.dcx().emit_err(diagnostics::DocInlineConflict { spans }); return; } } @@ -976,7 +980,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { INVALID_DOC_ATTRIBUTES, hir_id, span, - errors::DocInlineOnlyUse { + diagnostics::DocInlineOnlyUse { attr_span: span, item_span: self.tcx.hir_span(hir_id), }, @@ -991,7 +995,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { INVALID_DOC_ATTRIBUTES, hir_id, span, - errors::DocMaskedOnlyExternCrate { + diagnostics::DocMaskedOnlyExternCrate { attr_span: span, item_span: self.tcx.hir_span(hir_id), }, @@ -1004,7 +1008,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { INVALID_DOC_ATTRIBUTES, hir_id, span, - errors::DocMaskedNotExternCrateSelf { + diagnostics::DocMaskedNotExternCrateSelf { attr_span: span, item_span: self.tcx.hir_span(hir_id), }, @@ -1020,12 +1024,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match item_kind { Some(ItemKind::Mod(_, module)) => { if !module.item_ids.is_empty() { - self.dcx().emit_err(errors::DocKeywordAttributeEmptyMod { span, attr_name }); + self.dcx() + .emit_err(diagnostics::DocKeywordAttributeEmptyMod { span, attr_name }); return; } } _ => { - self.dcx().emit_err(errors::DocKeywordAttributeNotMod { span, attr_name }); + self.dcx().emit_err(diagnostics::DocKeywordAttributeNotMod { span, attr_name }); return; } } @@ -1107,7 +1112,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { fn check_ffi_pure(&self, attr_span: Span, attrs: &[Attribute]) { if find_attr!(attrs, FfiConst) { // `#[ffi_const]` functions cannot be `#[ffi_pure]` - self.dcx().emit_err(errors::BothFfiConstAndPure { attr_span }); + self.dcx().emit_err(diagnostics::BothFfiConstAndPure { attr_span }); } } @@ -1129,7 +1134,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { return; } - self.dcx().emit_err(errors::InvalidMayDangle { attr_span }); + self.dcx().emit_err(diagnostics::InvalidMayDangle { attr_span }); } /// Checks if `#[link]` is applied to an item other than a foreign module. @@ -1145,7 +1150,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { return; } - self.tcx.emit_node_span_lint(UNUSED_ATTRIBUTES, hir_id, attr_span, errors::Link); + self.tcx.emit_node_span_lint(UNUSED_ATTRIBUTES, hir_id, attr_span, diagnostics::Link); } /// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument. @@ -1168,7 +1173,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match param.kind { hir::GenericParamKind::Const { .. } => {} _ => { - self.dcx().emit_err(errors::RustcLegacyConstGenericsOnly { + self.dcx().emit_err(diagnostics::RustcLegacyConstGenericsOnly { attr_span, param_span: param.span, }); @@ -1178,7 +1183,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } if index_list.len() != generics.params.len() { - self.dcx().emit_err(errors::RustcLegacyConstGenericsIndex { + self.dcx().emit_err(diagnostics::RustcLegacyConstGenericsIndex { attr_span, generics_span: generics.span, }); @@ -1188,7 +1193,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let arg_count = decl.inputs.len() + generics.params.len(); for (index, span) in index_list { if *index >= arg_count { - self.dcx().emit_err(errors::RustcLegacyConstGenericsIndexExceed { + self.dcx().emit_err(diagnostics::RustcLegacyConstGenericsIndexExceed { span: *span, arg_count, }); @@ -1249,7 +1254,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // Error on repr(transparent, ). if is_transparent && reprs.len() > 1 { let hint_spans = hint_spans.clone().collect(); - self.dcx().emit_err(errors::TransparentIncompatible { + self.dcx().emit_err(diagnostics::TransparentIncompatible { hint_spans, target: target.to_string(), }); @@ -1260,14 +1265,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && let Some(&pass_indirectly_span) = find_attr!(attrs, RustcPassIndirectlyInNonRusticAbis(span) => span) { - self.dcx().emit_err(errors::TransparentIncompatible { + self.dcx().emit_err(diagnostics::TransparentIncompatible { hint_spans: vec![span, pass_indirectly_span], target: target.to_string(), }); } if is_explicit_rust && (int_reprs > 0 || is_c || is_simd) { let hint_spans = hint_spans.clone().collect(); - self.dcx().emit_err(errors::ReprConflicting { hint_spans }); + self.dcx().emit_err(diagnostics::ReprConflicting { hint_spans }); } // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8) if (int_reprs > 1) @@ -1282,7 +1287,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { CONFLICTING_REPR_HINTS, hir_id, hint_spans.collect::>(), - errors::ReprConflictingLint, + diagnostics::ReprConflictingLint, ); } } @@ -1306,7 +1311,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { return; } } - self.tcx.dcx().emit_err(errors::MacroOnlyAttribute { attr_span, span }); + self.tcx.dcx().emit_err(diagnostics::MacroOnlyAttribute { attr_span, span }); } _ => {} } @@ -1324,7 +1329,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { Target::Fn | Target::Method(_) => { if !self.tcx.is_const_fn(hir_id.expect_owner().to_def_id()) { - self.tcx.dcx().emit_err(errors::RustcAllowConstFnUnstable { attr_span, span }); + self.tcx + .dcx() + .emit_err(diagnostics::RustcAllowConstFnUnstable { attr_span, span }); } } _ => {} @@ -1341,7 +1348,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr_span, - errors::DeprecatedAnnotationHasNoEffect { span: attr_span }, + diagnostics::DeprecatedAnnotationHasNoEffect { span: attr_span }, ); } _ => {} @@ -1362,7 +1369,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr_span, - errors::MacroExport::OnDeclMacro, + diagnostics::MacroExport::OnDeclMacro, ); } } @@ -1374,7 +1381,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { if attr.has_any_name(&[sym::allow, sym::expect, sym::warn, sym::deny, sym::forbid]) && attr.meta_item_list().is_some_and(|list| list.is_empty()) { - errors::UnusedNote::EmptyList { name: attr.name().unwrap() } + diagnostics::UnusedNote::EmptyList { name: attr.name().unwrap() } } else if attr.has_any_name(&[ sym::allow, sym::warn, @@ -1387,7 +1394,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && let MetaItemKind::NameValue(_) = &item.kind && item.path == sym::reason { - errors::UnusedNote::NoLints { name: attr.name().unwrap() } + diagnostics::UnusedNote::NoLints { name: attr.name().unwrap() } } else if attr.has_any_name(&[ sym::allow, sym::warn, @@ -1416,8 +1423,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr_span, - errors::OuterCrateLevelAttr { - suggestion: errors::OuterCrateLevelAttrSuggestion { + diagnostics::OuterCrateLevelAttr { + suggestion: diagnostics::OuterCrateLevelAttrSuggestion { bang_position, }, }, @@ -1427,7 +1434,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr.span(), - errors::InnerCrateLevelAttr, + diagnostics::InnerCrateLevelAttr, ), }; return; @@ -1438,7 +1445,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { .iter() .all(|kind| matches!(kind, CrateType::Rlib | CrateType::StaticLib)); if never_needs_link { - errors::UnusedNote::LinkerMessagesBinaryCrateOnly + diagnostics::UnusedNote::LinkerMessagesBinaryCrateOnly } else { return; } @@ -1451,9 +1458,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { }) && !self.tcx.crate_types().contains(&CrateType::Executable) { - errors::UnusedNote::NoEffectDeadCodePubInBinary + diagnostics::UnusedNote::NoEffectDeadCodePubInBinary } else if attr.has_name(sym::default_method_body_is_const) { - errors::UnusedNote::DefaultMethodBodyConst + diagnostics::UnusedNote::DefaultMethodBodyConst } else { return; }; @@ -1462,7 +1469,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { UNUSED_ATTRIBUTES, hir_id, attr.span(), - errors::Unused { attr_span: attr.span(), note }, + diagnostics::Unused { attr_span: attr.span(), note }, ); } @@ -1516,7 +1523,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { ); if let Err(terr) = ocx.eq(&cause, param_env, expected_sig, sig) { - let mut diag = tcx.dcx().create_err(errors::ProcMacroBadSig { span, kind }); + let mut diag = tcx.dcx().create_err(diagnostics::ProcMacroBadSig { span, kind }); let hir_sig = tcx.hir_fn_sig_by_hir_id(hir_id); if let Some(hir_sig) = hir_sig { @@ -1577,7 +1584,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { if !find_attr!(attrs, Repr { reprs, .. } => reprs.iter().any(|(r, _)| r == &ReprAttr::ReprTransparent)) .unwrap_or(false) { - self.dcx().emit_err(errors::RustcPubTransparent { span, attr_span }); + self.dcx().emit_err(diagnostics::RustcPubTransparent { span, attr_span }); } } @@ -1601,7 +1608,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Inline(InlineAttr::Force { attr_span, .. }, _) => *attr_span ) && is_coro { - self.dcx().emit_err(errors::RustcForceInlineCoro { attr_span, span: parent_span }); + self.dcx() + .emit_err(diagnostics::RustcForceInlineCoro { attr_span, span: parent_span }); } } } @@ -1627,7 +1635,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { lint::builtin::UNUSED_ATTRIBUTES, hir_id, no_mangle_span, - errors::MixedExportNameAndNoMangle { + diagnostics::MixedExportNameAndNoMangle { no_mangle_span, export_name_span, no_mangle_attr, @@ -1644,7 +1652,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { find_attr!(attrs, Inline(inline_attr, span) => (inline_attr, *span)) && inline_attr != &InlineAttr::Never { - self.dcx().emit_err(errors::BothOptimizeNoneAndInline { optimize_span, inline_span }); + self.dcx() + .emit_err(diagnostics::BothOptimizeNoneAndInline { optimize_span, inline_span }); } } @@ -1656,7 +1665,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } if !matches!(self.tcx.hir_expect_expr(hir_id).kind, hir::ExprKind::Loop(..)) { - self.dcx().emit_err(errors::LoopMatchAttr { attr_span, node_span }); + self.dcx().emit_err(diagnostics::LoopMatchAttr { attr_span, node_span }); }; } @@ -1668,7 +1677,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } if !matches!(self.tcx.hir_expect_expr(hir_id).kind, hir::ExprKind::Break(..)) { - self.dcx().emit_err(errors::ConstContinueAttr { attr_span, node_span }); + self.dcx().emit_err(diagnostics::ConstContinueAttr { attr_span, node_span }); }; } } @@ -1800,7 +1809,7 @@ fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>) if let Some(attr_span) = find_attr!(attrs, Inline(i, span) if !matches!(i, InlineAttr::Force{..}) => *span) { - tcx.dcx().emit_err(errors::NonExportedMacroInvalidAttrs { attr_span }); + tcx.dcx().emit_err(diagnostics::NonExportedMacroInvalidAttrs { attr_span }); } } diff --git a/compiler/rustc_passes/src/check_export.rs b/compiler/rustc_passes/src/check_export.rs index fa3042277b409..cd724078e72c9 100644 --- a/compiler/rustc_passes/src/check_export.rs +++ b/compiler/rustc_passes/src/check_export.rs @@ -17,7 +17,7 @@ use rustc_middle::ty::{ use rustc_session::config::CrateType; use rustc_span::Span; -use crate::errors::UnexportableItem; +use crate::diagnostics::UnexportableItem; struct ExportableItemCollector<'tcx> { tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 59a347c9042bf..e5c1a7ecbdfec 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -26,7 +26,7 @@ use rustc_session::lint::builtin::{DEAD_CODE, DEAD_CODE_PUB_IN_BINARY}; use rustc_session::lint::{self, Lint, StableLintExpectationId}; use rustc_span::{Symbol, kw}; -use crate::errors::{ +use crate::diagnostics::{ ChangeFields, DeadCodePubInBinaryNote, IgnoredDerivedImpls, MultipleDeadCodes, ParentInfo, UselessAssignment, }; @@ -1233,7 +1233,7 @@ impl<'tcx> DeadVisitor<'tcx> { && let Some(variant) = maybe_enum.variants().iter().find(|i| i.name == dead_item.name) { - Some(crate::errors::EnumVariantSameName { + Some(crate::diagnostics::EnumVariantSameName { dead_descr: tcx.def_descr(dead_item.def_id.to_def_id()), dead_name: dead_item.name, variant_span: tcx.def_span(variant.def_id), diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs index 1f27384d4e7ca..2f14884a248b9 100644 --- a/compiler/rustc_passes/src/debugger_visualizer.rs +++ b/compiler/rustc_passes/src/debugger_visualizer.rs @@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::sym; -use crate::errors::DebugVisualizerUnreadable; +use crate::diagnostics::DebugVisualizerUnreadable; impl DebuggerVisualizerCollector<'_> { fn check_for_debugger_visualizer(&mut self, attrs: &[ast::Attribute]) { diff --git a/compiler/rustc_passes/src/delegation.rs b/compiler/rustc_passes/src/delegation.rs index c4407f7b09498..825f1ebecb423 100644 --- a/compiler/rustc_passes/src/delegation.rs +++ b/compiler/rustc_passes/src/delegation.rs @@ -1,7 +1,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_middle::ty::TyCtxt; -use crate::errors::GlobOrListDelegationUnusedTargetExpr; +use crate::diagnostics::GlobOrListDelegationUnusedTargetExpr; pub fn check_glob_and_list_delegations_target_expr(tcx: TyCtxt<'_>) { let mut delegations_by_group_id = FxIndexMap::default(); diff --git a/compiler/rustc_passes/src/diagnostic_items.rs b/compiler/rustc_passes/src/diagnostic_items.rs index be7ae5b97f55c..49e46a05e5ccd 100644 --- a/compiler/rustc_passes/src/diagnostic_items.rs +++ b/compiler/rustc_passes/src/diagnostic_items.rs @@ -16,7 +16,7 @@ use rustc_middle::ty::TyCtxt; use rustc_span::Symbol; use rustc_span::def_id::{DefId, LOCAL_CRATE}; -use crate::errors::DuplicateDiagnosticItemInCrate; +use crate::diagnostics::DuplicateDiagnosticItemInCrate; fn observe_item<'tcx>(tcx: TyCtxt<'tcx>, diagnostic_items: &mut DiagnosticItems, owner: OwnerId) { let attrs = tcx.hir_attrs(owner.into()); diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/diagnostics.rs similarity index 100% rename from compiler/rustc_passes/src/errors.rs rename to compiler/rustc_passes/src/diagnostics.rs diff --git a/compiler/rustc_passes/src/eii.rs b/compiler/rustc_passes/src/eii.rs index 6aceae29e40a4..c9cfd1e050313 100644 --- a/compiler/rustc_passes/src/eii.rs +++ b/compiler/rustc_passes/src/eii.rs @@ -9,7 +9,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; -use crate::errors::{DuplicateEiiImpls, EiiWithoutImpl}; +use crate::diagnostics::{DuplicateEiiImpls, EiiWithoutImpl}; #[derive(Clone, Copy, Debug)] enum CheckingMode { diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 9fc9df7604c51..80cfe10ca7176 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::config::{CrateType, EntryFnType, sigpipe}; use rustc_span::{RemapPathScopeComponents, Span}; -use crate::errors::{ExternMain, MultipleRustcMain, NoMainErr}; +use crate::diagnostics::{ExternMain, MultipleRustcMain, NoMainErr}; struct EntryContext<'tcx> { tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index c274ca48df622..6180d6f8c4c27 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -18,7 +18,7 @@ use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_session::cstore::ExternCrate; use rustc_span::{Span, Symbol, sym}; -use crate::errors::{ +use crate::diagnostics::{ DuplicateLangItem, IncorrectCrateType, IncorrectTarget, LangItemOnIncorrectTarget, }; use crate::weak_lang_items; diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index b51934cab90c4..ea26d4043b25f 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -13,9 +13,9 @@ pub mod dead; mod debugger_visualizer; pub mod delegation; mod diagnostic_items; +mod diagnostics; mod eii; pub mod entry; -mod errors; pub mod hir_id_validator; pub mod input_stats; mod lang_items; diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs index 1f92643815fd9..ceaad91d25982 100644 --- a/compiler/rustc_passes/src/lib_features.rs +++ b/compiler/rustc_passes/src/lib_features.rs @@ -13,7 +13,7 @@ use rustc_middle::query::{LocalCrate, Providers}; use rustc_middle::ty::TyCtxt; use rustc_span::{Span, Symbol, sym}; -use crate::errors::{FeaturePreviouslyDeclared, FeatureStableTwice}; +use crate::diagnostics::{FeaturePreviouslyDeclared, FeatureStableTwice}; struct LibFeatureCollector<'tcx> { tcx: TyCtxt<'tcx>, diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index e2c32e0bbf266..05ea8ee6fe97f 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -28,7 +28,7 @@ use rustc_session::lint::builtin::{DEPRECATED, INEFFECTIVE_UNSTABLE_TRAIT_IMPL}; use rustc_span::{Span, Symbol, sym}; use tracing::instrument; -use crate::errors; +use crate::diagnostics; #[derive(PartialEq)] enum AnnotationKind { @@ -337,7 +337,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && depr.map_or(false, |d| d.attr.is_since_rustc_version()) && let Some(span) = find_attr_span!(Deprecated) { - self.tcx.dcx().emit_err(errors::DeprecatedAttribute { span }); + self.tcx.dcx().emit_err(diagnostics::DeprecatedAttribute { span }); } if let Some(stab) = stab { @@ -348,7 +348,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { { if let Some(span) = find_attr_span!(Stability) { let item_sp = self.tcx.def_span(def_id); - self.tcx.dcx().emit_err(errors::UselessStability { span, item_sp }); + self.tcx.dcx().emit_err(diagnostics::UselessStability { span, item_sp }); } } @@ -364,13 +364,13 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { StableSince::Current => { self.tcx .dcx() - .emit_err(errors::CannotStabilizeDeprecated { span, item_sp }); + .emit_err(diagnostics::CannotStabilizeDeprecated { span, item_sp }); } StableSince::Version(stab_since) => { if dep_since < stab_since { self.tcx .dcx() - .emit_err(errors::CannotStabilizeDeprecated { span, item_sp }); + .emit_err(diagnostics::CannotStabilizeDeprecated { span, item_sp }); } } StableSince::Err(_) => { @@ -389,7 +389,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && const_stab.is_some() && find_attr_span!(RustcConstStability).is_some() { - self.tcx.dcx().emit_err(errors::MissingConstErr { fn_sig_span: fn_sig.span }); + self.tcx.dcx().emit_err(diagnostics::MissingConstErr { fn_sig_span: fn_sig.span }); } // If this is marked const *stable*, it must also be regular-stable. @@ -399,9 +399,10 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && !stab.is_some_and(|s| s.is_stable()) && let Some(const_span) = find_attr_span!(RustcConstStability) { - self.tcx - .dcx() - .emit_err(errors::ConstStableNotStable { fn_sig_span: fn_sig.span, const_span }); + self.tcx.dcx().emit_err(diagnostics::ConstStableNotStable { + fn_sig_span: fn_sig.span, + const_span, + }); } if let Some(stab) = &const_stab @@ -409,7 +410,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && stab.const_stable_indirect && let Some(span) = find_attr_span!(RustcConstStability) { - self.tcx.dcx().emit_err(errors::RustcConstStableIndirectPairing { span }); + self.tcx.dcx().emit_err(diagnostics::RustcConstStableIndirectPairing { span }); } } @@ -423,7 +424,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { { let descr = self.tcx.def_descr(def_id.to_def_id()); let span = self.tcx.def_span(def_id); - self.tcx.dcx().emit_err(errors::MissingStabilityAttr { span, descr }); + self.tcx.dcx().emit_err(diagnostics::MissingStabilityAttr { span, descr }); } } @@ -439,7 +440,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { { let span = self.tcx.def_span(def_id); let descr = self.tcx.def_descr(def_id.to_def_id()); - self.tcx.dcx().emit_err(errors::MissingConstStabAttr { span, descr }); + self.tcx.dcx().emit_err(diagnostics::MissingConstStabAttr { span, descr }); } } } @@ -646,7 +647,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { INEFFECTIVE_UNSTABLE_TRAIT_IMPL, item.hir_id(), span, - errors::IneffectiveUnstableImpl, + diagnostics::IneffectiveUnstableImpl, ); } } @@ -660,9 +661,9 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { // `#![feature(const_trait_impl)]` is unstable, so any impl declared stable // needs to have an error emitted. // Note: Remove this error once `const_trait_impl` is stabilized - self.tcx - .dcx() - .emit_err(errors::TraitImplConstStable { span: item.span }); + self.tcx.dcx().emit_err(diagnostics::TraitImplConstStable { + span: item.span, + }); true } Some(_) => false, @@ -676,21 +677,23 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { let trait_span = self.tcx.def_ident_span(trait_id).unwrap(); let impl_stability = if stable_or_implied_stable { - errors::ImplConstStability::Stable { span: item.span } + diagnostics::ImplConstStability::Stable { span: item.span } } else { - errors::ImplConstStability::Unstable { span: item.span } + diagnostics::ImplConstStability::Unstable { span: item.span } }; let trait_stability = if const_stab.is_const_stable() { - errors::TraitConstStability::Stable { span: trait_span } + diagnostics::TraitConstStability::Stable { span: trait_span } } else { - errors::TraitConstStability::Unstable { span: trait_span } + diagnostics::TraitConstStability::Unstable { span: trait_span } }; - self.tcx.dcx().emit_err(errors::TraitImplConstStabilityMismatch { - span: item.span, - impl_stability, - trait_stability, - }); + self.tcx.dcx().emit_err( + diagnostics::TraitImplConstStabilityMismatch { + span: item.span, + impl_stability, + trait_stability, + }, + ); } } } @@ -1044,7 +1047,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { if let FeatureStability::Unstable { old_name: Some(alias) } = stability && let Some(span) = remaining_lib_features.swap_remove(&alias) { - tcx.dcx().emit_err(errors::RenamedFeature { span, feature, alias }); + tcx.dcx().emit_err(diagnostics::RenamedFeature { span, feature, alias }); } if remaining_lib_features.is_empty() && remaining_implications.is_empty() { @@ -1118,7 +1121,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { if let Some(removed) = unstable_removed_features.iter().find(|removed| removed.feature == feature) { - tcx.dcx().emit_err(errors::FeatureRemoved { + tcx.dcx().emit_err(diagnostics::FeatureRemoved { span, feature, reason: removed.reason, @@ -1126,10 +1129,11 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { since: removed.since.to_string(), }); } else { - let suggestion = feature - .find_similar(&valid_feature_names) - .map(|(actual_name, _)| errors::MisspelledFeature { span, actual_name }); - tcx.dcx().emit_err(errors::UnknownFeature { span, feature, suggestion }); + let suggestion = + feature.find_similar(&valid_feature_names).map(|(actual_name, _)| { + diagnostics::MisspelledFeature { span, actual_name } + }); + tcx.dcx().emit_err(diagnostics::UnknownFeature { span, feature, suggestion }); } } } @@ -1142,7 +1146,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { .get(&feature) .expect("feature that implied another does not exist") .1; - tcx.dcx().emit_err(errors::ImpliedFeatureNotExist { span, feature, implied_by }); + tcx.dcx().emit_err(diagnostics::ImpliedFeatureNotExist { span, feature, implied_by }); } // FIXME(#44232): the `used_features` table no longer exists, so we @@ -1160,7 +1164,7 @@ fn unnecessary_partially_stable_feature_lint( lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, - errors::UnnecessaryPartialStableFeature { + diagnostics::UnnecessaryPartialStableFeature { span, line: tcx.sess.source_map().span_extend_to_line(span), feature, @@ -1183,7 +1187,7 @@ fn unnecessary_stable_feature_lint( lint::builtin::STABLE_FEATURES, hir::CRATE_HIR_ID, span, - errors::UnnecessaryStableFeature { feature, since }, + diagnostics::UnnecessaryStableFeature { feature, since }, ); } @@ -1192,6 +1196,6 @@ fn duplicate_feature_lint(tcx: TyCtxt<'_>, span: Span, feature: Symbol) { lint::builtin::DUPLICATE_FEATURES, hir::CRATE_HIR_ID, span, - errors::DuplicateFeature { feature }, + diagnostics::DuplicateFeature { feature }, ); } diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 2d5eee183aec4..b42b27ec74184 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -9,7 +9,7 @@ use rustc_middle::middle::lang_items::required; use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; -use crate::errors::{ +use crate::diagnostics::{ MissingLangItem, MissingPanicHandler, PanicUnwindWithoutStd, UnknownExternLangItem, }; use crate::lang_items::extract_ast; diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/diagnostics.rs similarity index 100% rename from compiler/rustc_pattern_analysis/src/errors.rs rename to compiler/rustc_pattern_analysis/src/diagnostics.rs diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index e1883e7df815e..9e405c801867e 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -9,7 +9,7 @@ pub(crate) mod checks; pub mod constructor; #[cfg(feature = "rustc")] -pub mod errors; +pub mod diagnostics; #[cfg(feature = "rustc")] pub(crate) mod lints; pub mod pat; diff --git a/compiler/rustc_pattern_analysis/src/lints.rs b/compiler/rustc_pattern_analysis/src/lints.rs index d258733dc095a..d22738ec0b980 100644 --- a/compiler/rustc_pattern_analysis/src/lints.rs +++ b/compiler/rustc_pattern_analysis/src/lints.rs @@ -4,7 +4,9 @@ use tracing::instrument; use crate::MatchArm; use crate::constructor::Constructor; -use crate::errors::{NonExhaustiveOmittedPattern, NonExhaustiveOmittedPatternLintOnArm, Uncovered}; +use crate::diagnostics::{ + NonExhaustiveOmittedPattern, NonExhaustiveOmittedPatternLintOnArm, Uncovered, +}; use crate::pat_column::PatternColumn; use crate::rustc::{RevealedTy, RustcPatCtxt, WitnessPat}; diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index b5491de7905bc..88ec44beec753 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -25,7 +25,7 @@ use crate::lints::lint_nonexhaustive_missing_variants; use crate::pat_column::PatternColumn; use crate::rustc::print::EnumInfo; use crate::usefulness::{PlaceValidity, compute_match_usefulness}; -use crate::{PatCx, PrivateUninhabitedField, errors}; +use crate::{PatCx, PrivateUninhabitedField, diagnostics}; mod print; @@ -949,14 +949,14 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { let overlaps: Vec<_> = overlaps_with .iter() .map(|pat| pat.data().span) - .map(|span| errors::Overlap { range: overlap_as_pat.to_string(), span }) + .map(|span| diagnostics::Overlap { range: overlap_as_pat.to_string(), span }) .collect(); let pat_span = pat.data().span; self.tcx.emit_node_span_lint( lint::builtin::OVERLAPPING_RANGE_ENDPOINTS, self.match_lint_level, pat_span, - errors::OverlappingRangeEndpoints { overlap: overlaps, range: pat_span }, + diagnostics::OverlappingRangeEndpoints { overlap: overlaps, range: pat_span }, ); } @@ -992,7 +992,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { lint::builtin::NON_CONTIGUOUS_RANGE_ENDPOINTS, self.match_lint_level, thir_pat.span, - errors::ExclusiveRangeMissingMax { + diagnostics::ExclusiveRangeMissingMax { // Point at this range. first_range: thir_pat.span, // That's the gap that isn't covered. @@ -1006,7 +1006,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { lint::builtin::NON_CONTIGUOUS_RANGE_ENDPOINTS, self.match_lint_level, thir_pat.span, - errors::ExclusiveRangeMissingGap { + diagnostics::ExclusiveRangeMissingGap { // Point at this range. first_range: thir_pat.span, // That's the gap that isn't covered. @@ -1017,7 +1017,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { // mistake. gap_with: gapped_with .iter() - .map(|pat| errors::GappedRange { + .map(|pat| diagnostics::GappedRange { span: pat.data().span, gap: gap_as_pat.to_string(), first_range: range.to_string(), @@ -1039,7 +1039,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { ) -> Self::Error { let deref_pattern_label = deref_pat.data().span; let normal_constructor_label = normal_pat.data().span; - self.tcx.dcx().emit_err(errors::MixedDerefPatternConstructors { + self.tcx.dcx().emit_err(diagnostics::MixedDerefPatternConstructors { spans: vec![deref_pattern_label, normal_constructor_label], smart_pointer_ty: deref_pat.ty().inner(), deref_pattern_label, diff --git a/library/core/src/intrinsics/mod.rs b/library/core/src/intrinsics/mod.rs index c96c2344a8cb4..a714bfa098c1d 100644 --- a/library/core/src/intrinsics/mod.rs +++ b/library/core/src/intrinsics/mod.rs @@ -1621,6 +1621,7 @@ pub unsafe fn float_to_int_unchecked(v /// Float addition that allows optimizations based on algebraic rules. /// /// Stabilized as [`f16::algebraic_add`], [`f32::algebraic_add`], [`f64::algebraic_add`] and [`f128::algebraic_add`]. +#[rustc_intrinsic_const_stable_indirect] #[rustc_nounwind] #[rustc_intrinsic] pub const fn fadd_algebraic(a: T, b: T) -> T; @@ -1628,6 +1629,7 @@ pub const fn fadd_algebraic(a: T, b: T) -> T; /// Float subtraction that allows optimizations based on algebraic rules. /// /// Stabilized as [`f16::algebraic_sub`], [`f32::algebraic_sub`], [`f64::algebraic_sub`] and [`f128::algebraic_sub`]. +#[rustc_intrinsic_const_stable_indirect] #[rustc_nounwind] #[rustc_intrinsic] pub const fn fsub_algebraic(a: T, b: T) -> T; @@ -1635,6 +1637,7 @@ pub const fn fsub_algebraic(a: T, b: T) -> T; /// Float multiplication that allows optimizations based on algebraic rules. /// /// Stabilized as [`f16::algebraic_mul`], [`f32::algebraic_mul`], [`f64::algebraic_mul`] and [`f128::algebraic_mul`]. +#[rustc_intrinsic_const_stable_indirect] #[rustc_nounwind] #[rustc_intrinsic] pub const fn fmul_algebraic(a: T, b: T) -> T; @@ -1642,6 +1645,7 @@ pub const fn fmul_algebraic(a: T, b: T) -> T; /// Float division that allows optimizations based on algebraic rules. /// /// Stabilized as [`f16::algebraic_div`], [`f32::algebraic_div`], [`f64::algebraic_div`] and [`f128::algebraic_div`]. +#[rustc_intrinsic_const_stable_indirect] #[rustc_nounwind] #[rustc_intrinsic] pub const fn fdiv_algebraic(a: T, b: T) -> T; @@ -1649,6 +1653,7 @@ pub const fn fdiv_algebraic(a: T, b: T) -> T; /// Float remainder that allows optimizations based on algebraic rules. /// /// Stabilized as [`f16::algebraic_rem`], [`f32::algebraic_rem`], [`f64::algebraic_rem`] and [`f128::algebraic_rem`]. +#[rustc_intrinsic_const_stable_indirect] #[rustc_nounwind] #[rustc_intrinsic] pub const fn frem_algebraic(a: T, b: T) -> T; @@ -2054,7 +2059,8 @@ pub const fn rotate_right(x: T, shift: u32) -> unsafe { unchecked_funnel_shr(x, x, shift % (mem::size_of::() as u32 * 8)) } } -/// Returns (a + b) mod 2N, where N is the width of T in bits. +/// Wrapping (modular) addition. Computes `a + b`, +/// wrapping around at the boundary of the type. /// /// Note that, unlike most intrinsics, this is safe to call; /// it does not require an `unsafe` block. @@ -2068,7 +2074,8 @@ pub const fn rotate_right(x: T, shift: u32) -> #[rustc_nounwind] #[rustc_intrinsic] pub const fn wrapping_add(a: T, b: T) -> T; -/// Returns (a - b) mod 2N, where N is the width of T in bits. +/// Wrapping (modular) subtraction. Computes `a - b`, +/// wrapping around at the boundary of the type. /// /// Note that, unlike most intrinsics, this is safe to call; /// it does not require an `unsafe` block. @@ -2082,7 +2089,8 @@ pub const fn wrapping_add(a: T, b: T) -> T; #[rustc_nounwind] #[rustc_intrinsic] pub const fn wrapping_sub(a: T, b: T) -> T; -/// Returns (a * b) mod 2N, where N is the width of T in bits. +/// Wrapping (modular) multiplication. Computes `a * +/// b`, wrapping around at the boundary of the type. /// /// Note that, unlike most intrinsics, this is safe to call; /// it does not require an `unsafe` block. diff --git a/library/core/src/num/f128.rs b/library/core/src/num/f128.rs index cd1987aa959dd..4875835695e69 100644 --- a/library/core/src/num/f128.rs +++ b/library/core/src/num/f128.rs @@ -1552,8 +1552,8 @@ impl f128 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f128", issue = "116909")] + #[rustc_const_unstable(feature = "f128", issue = "116909")] #[inline] pub const fn algebraic_add(self, rhs: f128) -> f128 { intrinsics::fadd_algebraic(self, rhs) @@ -1563,8 +1563,8 @@ impl f128 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f128", issue = "116909")] + #[rustc_const_unstable(feature = "f128", issue = "116909")] #[inline] pub const fn algebraic_sub(self, rhs: f128) -> f128 { intrinsics::fsub_algebraic(self, rhs) @@ -1574,8 +1574,8 @@ impl f128 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f128", issue = "116909")] + #[rustc_const_unstable(feature = "f128", issue = "116909")] #[inline] pub const fn algebraic_mul(self, rhs: f128) -> f128 { intrinsics::fmul_algebraic(self, rhs) @@ -1585,8 +1585,8 @@ impl f128 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f128", issue = "116909")] + #[rustc_const_unstable(feature = "f128", issue = "116909")] #[inline] pub const fn algebraic_div(self, rhs: f128) -> f128 { intrinsics::fdiv_algebraic(self, rhs) @@ -1596,8 +1596,8 @@ impl f128 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f128", issue = "116909")] + #[rustc_const_unstable(feature = "f128", issue = "116909")] #[inline] pub const fn algebraic_rem(self, rhs: f128) -> f128 { intrinsics::frem_algebraic(self, rhs) diff --git a/library/core/src/num/f16.rs b/library/core/src/num/f16.rs index ef8eb3c0b57a0..186945db9ae92 100644 --- a/library/core/src/num/f16.rs +++ b/library/core/src/num/f16.rs @@ -1538,8 +1538,8 @@ impl f16 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f16", issue = "116909")] + #[rustc_const_unstable(feature = "f16", issue = "116909")] #[inline] pub const fn algebraic_add(self, rhs: f16) -> f16 { intrinsics::fadd_algebraic(self, rhs) @@ -1549,8 +1549,8 @@ impl f16 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f16", issue = "116909")] + #[rustc_const_unstable(feature = "f16", issue = "116909")] #[inline] pub const fn algebraic_sub(self, rhs: f16) -> f16 { intrinsics::fsub_algebraic(self, rhs) @@ -1560,8 +1560,8 @@ impl f16 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f16", issue = "116909")] + #[rustc_const_unstable(feature = "f16", issue = "116909")] #[inline] pub const fn algebraic_mul(self, rhs: f16) -> f16 { intrinsics::fmul_algebraic(self, rhs) @@ -1571,8 +1571,8 @@ impl f16 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f16", issue = "116909")] + #[rustc_const_unstable(feature = "f16", issue = "116909")] #[inline] pub const fn algebraic_div(self, rhs: f16) -> f16 { intrinsics::fdiv_algebraic(self, rhs) @@ -1582,8 +1582,8 @@ impl f16 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[unstable(feature = "f16", issue = "116909")] + #[rustc_const_unstable(feature = "f16", issue = "116909")] #[inline] pub const fn algebraic_rem(self, rhs: f16) -> f16 { intrinsics::frem_algebraic(self, rhs) diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 2a7506f198589..92ecabc581839 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -1694,8 +1694,8 @@ impl f32 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_add(self, rhs: f32) -> f32 { intrinsics::fadd_algebraic(self, rhs) @@ -1705,8 +1705,8 @@ impl f32 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_sub(self, rhs: f32) -> f32 { intrinsics::fsub_algebraic(self, rhs) @@ -1716,8 +1716,8 @@ impl f32 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_mul(self, rhs: f32) -> f32 { intrinsics::fmul_algebraic(self, rhs) @@ -1727,8 +1727,8 @@ impl f32 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_div(self, rhs: f32) -> f32 { intrinsics::fdiv_algebraic(self, rhs) @@ -1738,8 +1738,8 @@ impl f32 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_rem(self, rhs: f32) -> f32 { intrinsics::frem_algebraic(self, rhs) diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 8b77a3b7b0bde..6470658d3ea35 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -1674,8 +1674,8 @@ impl f64 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_add(self, rhs: f64) -> f64 { intrinsics::fadd_algebraic(self, rhs) @@ -1685,8 +1685,8 @@ impl f64 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_sub(self, rhs: f64) -> f64 { intrinsics::fsub_algebraic(self, rhs) @@ -1696,8 +1696,8 @@ impl f64 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_mul(self, rhs: f64) -> f64 { intrinsics::fmul_algebraic(self, rhs) @@ -1707,8 +1707,8 @@ impl f64 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_div(self, rhs: f64) -> f64 { intrinsics::fdiv_algebraic(self, rhs) @@ -1718,8 +1718,8 @@ impl f64 { /// /// See [algebraic operators](primitive@f32#algebraic-operators) for more info. #[must_use = "method returns a new number and does not mutate the original value"] - #[unstable(feature = "float_algebraic", issue = "136469")] - #[rustc_const_unstable(feature = "float_algebraic", issue = "136469")] + #[stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "float_algebraic", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn algebraic_rem(self, rhs: f64) -> f64 { intrinsics::frem_algebraic(self, rhs) diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 7362bb77b1684..5863fd57e71e6 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -1374,8 +1374,6 @@ macro_rules! nonzero_integer { /// # Examples /// /// ``` - /// #![feature(nonzero_from_str_radix)] - /// /// # use std::num::NonZero; /// # /// # fn main() { test().unwrap(); } @@ -1388,13 +1386,12 @@ macro_rules! nonzero_integer { /// Trailing space returns error: /// /// ``` - /// #![feature(nonzero_from_str_radix)] - /// /// # use std::num::NonZero; /// # #[doc = concat!("assert!(NonZero::<", stringify!($Int), ">::from_str_radix(\"1 \", 10).is_err());")] /// ``` - #[unstable(feature = "nonzero_from_str_radix", issue = "152193")] + #[stable(feature = "nonzero_from_str_radix", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "nonzero_from_str_radix", since = "CURRENT_RUSTC_VERSION")] #[inline] pub const fn from_str_radix(src: &str, radix: u32) -> Result { Self::from_ascii_radix(src.as_bytes(), radix) diff --git a/library/core/src/primitive_docs.rs b/library/core/src/primitive_docs.rs index 9efcabcf3f194..c6fbe52ee887b 100644 --- a/library/core/src/primitive_docs.rs +++ b/library/core/src/primitive_docs.rs @@ -1341,7 +1341,6 @@ mod prim_f16 {} /// For example: /// /// ``` -/// # #![feature(float_algebraic)] /// # #![allow(unused_assignments)] /// # let mut x: f32 = 0.0; /// # let a: f32 = 1.0; @@ -1360,7 +1359,7 @@ mod prim_f16 {} /// # let b: f32 = 2.0; /// # let c: f32 = 3.0; /// # let d: f32 = 4.0; -/// x = a + b + c + d; // As written +/// x = ((a + b) + c) + d; // As written /// x = (a + c) + (b + d); // Reordered to shorten critical path and enable vectorization /// ``` #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index 1799da9d4abc2..ec2201aa7b9da 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -53,7 +53,6 @@ #![feature(extern_types)] #![feature(f16)] #![feature(f128)] -#![feature(float_algebraic)] #![feature(float_exact_integer_constants)] #![feature(float_gamma)] #![feature(float_minimum_maximum)] @@ -91,7 +90,6 @@ #![feature(never_type)] #![feature(next_index)] #![feature(non_exhaustive_omitted_patterns_lint)] -#![feature(nonzero_from_str_radix)] #![feature(num_internals)] #![feature(numfmt)] #![feature(one_sided_range)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index ee7f108bc4e3d..503707a18dcaa 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -340,7 +340,6 @@ #![feature(exact_size_is_empty)] #![feature(exclusive_wrapper)] #![feature(extend_one)] -#![feature(float_algebraic)] #![feature(float_gamma)] #![feature(float_minimum_maximum)] #![feature(fmt_internals)] diff --git a/tests/codegen-llvm/float/algebraic.rs b/tests/codegen-llvm/float/algebraic.rs index 818a4bcdfe3f1..ca351db710c47 100644 --- a/tests/codegen-llvm/float/algebraic.rs +++ b/tests/codegen-llvm/float/algebraic.rs @@ -6,7 +6,6 @@ #![crate_type = "lib"] #![feature(f16)] #![feature(f128)] -#![feature(float_algebraic)] // CHECK-LABEL: @f16_algebraic_add #[no_mangle] diff --git a/tests/ui/lint/suspicious-double-ref-op.rs b/tests/ui/lint/suspicious-double-ref-op.rs index 5aeb81dbd65aa..eac6325a28fcf 100644 --- a/tests/ui/lint/suspicious-double-ref-op.rs +++ b/tests/ui/lint/suspicious-double-ref-op.rs @@ -1,6 +1,7 @@ #![deny(suspicious_double_ref_op, noop_method_call)] use std::borrow::Borrow; +use std::io::Write; use std::ops::Deref; struct PlainType(T); @@ -27,6 +28,15 @@ fn rust_clippy_issue_9272() { println!("{str}") } +// https://github.com/rust-lang/rust/issues/146227 +fn method_receiver_adjustment(file: &std::fs::File, double_ref: &&std::fs::File) { + let _ = file.clone().write(&[]); + //~^ ERROR using `.clone()` on a double reference, which returns `&File` + + let _ = double_ref.deref().write(&[]); + //~^ ERROR using `.deref()` on a double reference, which returns `&File` +} + fn main() { let clone_type_ref = &&CloneType(1u32); let clone_type_ref_clone: &CloneType = clone_type_ref.clone(); diff --git a/tests/ui/lint/suspicious-double-ref-op.stderr b/tests/ui/lint/suspicious-double-ref-op.stderr index c956843c50780..0ebd796a62bee 100644 --- a/tests/ui/lint/suspicious-double-ref-op.stderr +++ b/tests/ui/lint/suspicious-double-ref-op.stderr @@ -1,5 +1,5 @@ error: using `.clone()` on a double reference, which returns `&Vec` instead of cloning the inner type - --> $DIR/suspicious-double-ref-op.rs:14:23 + --> $DIR/suspicious-double-ref-op.rs:15:23 | LL | let z: &Vec<_> = y.clone(); | ^^^^^^^^ @@ -10,23 +10,35 @@ note: the lint level is defined here LL | #![deny(suspicious_double_ref_op, noop_method_call)] | ^^^^^^^^^^^^^^^^^^^^^^^^ +error: using `.clone()` on a double reference, which returns `&File` instead of cloning the inner type + --> $DIR/suspicious-double-ref-op.rs:33:17 + | +LL | let _ = file.clone().write(&[]); + | ^^^^^^^^ + +error: using `.deref()` on a double reference, which returns `&File` instead of dereferencing the inner type + --> $DIR/suspicious-double-ref-op.rs:36:23 + | +LL | let _ = double_ref.deref().write(&[]); + | ^^^^^^^^ + error: using `.clone()` on a double reference, which returns `&CloneType` instead of cloning the inner type - --> $DIR/suspicious-double-ref-op.rs:32:63 + --> $DIR/suspicious-double-ref-op.rs:42:63 | LL | let clone_type_ref_clone: &CloneType = clone_type_ref.clone(); | ^^^^^^^^ error: using `.deref()` on a double reference, which returns `&PlainType` instead of dereferencing the inner type - --> $DIR/suspicious-double-ref-op.rs:36:63 + --> $DIR/suspicious-double-ref-op.rs:46:63 | LL | let non_deref_type_deref: &PlainType = non_deref_type.deref(); | ^^^^^^^^ error: using `.clone()` on a double reference, which returns `&str` instead of cloning the inner type - --> $DIR/suspicious-double-ref-op.rs:40:44 + --> $DIR/suspicious-double-ref-op.rs:50:44 | LL | let _v: Vec<&str> = xs.iter().map(|x| x.clone()).collect(); // could use `*x` instead | ^^^^^^^^ -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors diff --git a/triagebot.toml b/triagebot.toml index d50d74210c1ee..c8fb0b24b265e 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1530,6 +1530,7 @@ libs = [ "@LawnGnome", "@clarfonthey", "@aapoalas", + "@Darksonn", ] infra-ci = [ "@Mark-Simulacrum",