diff options
88 files changed, 2174 insertions, 1403 deletions
diff --git a/Cargo.lock b/Cargo.lock index e2b7b58c372..99cb71cd0ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3809,6 +3809,7 @@ dependencies = [ "rustc_abi", "rustc_ast", "rustc_attr_data_structures", + "rustc_attr_parsing", "rustc_data_structures", "rustc_errors", "rustc_fluent_macro", diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index f48a571b86a..e98d6c50ee7 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -70,44 +70,32 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { } } - pub(super) fn lower_node(&mut self, def_id: LocalDefId) -> hir::MaybeOwner<'hir> { + pub(super) fn lower_node(&mut self, def_id: LocalDefId) { let owner = self.owners.ensure_contains_elem(def_id, || hir::MaybeOwner::Phantom); if let hir::MaybeOwner::Phantom = owner { let node = self.ast_index[def_id]; match node { AstOwner::NonOwner => {} - AstOwner::Crate(c) => self.lower_crate(c), - AstOwner::Item(item) => self.lower_item(item), - AstOwner::AssocItem(item, ctxt) => self.lower_assoc_item(item, ctxt), - AstOwner::ForeignItem(item) => self.lower_foreign_item(item), + AstOwner::Crate(c) => { + debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID); + self.with_lctx(CRATE_NODE_ID, |lctx| { + let module = lctx.lower_mod(&c.items, &c.spans); + // FIXME(jdonszelman): is dummy span ever a problem here? + lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, DUMMY_SP); + hir::OwnerNode::Crate(module) + }) + } + AstOwner::Item(item) => { + self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item))) + } + AstOwner::AssocItem(item, ctxt) => { + self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt)) + } + AstOwner::ForeignItem(item) => self.with_lctx(item.id, |lctx| { + hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item)) + }), } } - - self.owners[def_id] - } - - #[instrument(level = "debug", skip(self, c))] - fn lower_crate(&mut self, c: &Crate) { - debug_assert_eq!(self.resolver.node_id_to_def_id[&CRATE_NODE_ID], CRATE_DEF_ID); - self.with_lctx(CRATE_NODE_ID, |lctx| { - let module = lctx.lower_mod(&c.items, &c.spans); - // FIXME(jdonszelman): is dummy span ever a problem here? - lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs, DUMMY_SP); - hir::OwnerNode::Crate(module) - }) - } - - #[instrument(level = "debug", skip(self))] - fn lower_item(&mut self, item: &Item) { - self.with_lctx(item.id, |lctx| hir::OwnerNode::Item(lctx.lower_item(item))) - } - - fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) { - self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt)) - } - - fn lower_foreign_item(&mut self, item: &ForeignItem) { - self.with_lctx(item.id, |lctx| hir::OwnerNode::ForeignItem(lctx.lower_foreign_item(item))) } } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 19095f2e01e..422e79ca82f 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -444,14 +444,14 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> hir::Crate<'_> { tcx.definitions_untracked().def_index_count(), ); + let mut lowerer = item::ItemLowerer { + tcx, + resolver: &mut resolver, + ast_index: &ast_index, + owners: &mut owners, + }; for def_id in ast_index.indices() { - item::ItemLowerer { - tcx, - resolver: &mut resolver, - ast_index: &ast_index, - owners: &mut owners, - } - .lower_node(def_id); + lowerer.lower_node(def_id); } drop(ast_index); diff --git a/compiler/rustc_attr_parsing/src/attributes/util.rs b/compiler/rustc_attr_parsing/src/attributes/util.rs index 05a9029c59a..503d2f1fae1 100644 --- a/compiler/rustc_attr_parsing/src/attributes/util.rs +++ b/compiler/rustc_attr_parsing/src/attributes/util.rs @@ -26,3 +26,33 @@ pub fn is_builtin_attr(attr: &impl AttributeExt) -> bool { pub fn find_crate_name(attrs: &[impl AttributeExt]) -> Option<Symbol> { first_attr_value_str_by_name(attrs, sym::crate_name) } + +pub fn is_doc_alias_attrs_contain_symbol<'tcx, T: AttributeExt + 'tcx>( + attrs: impl Iterator<Item = &'tcx T>, + symbol: Symbol, +) -> bool { + let doc_attrs = attrs.filter(|attr| attr.has_name(sym::doc)); + for attr in doc_attrs { + let Some(values) = attr.meta_item_list() else { + continue; + }; + let alias_values = values.iter().filter(|v| v.has_name(sym::alias)); + for v in alias_values { + if let Some(nested) = v.meta_item_list() { + // #[doc(alias("foo", "bar"))] + let mut iter = nested.iter().filter_map(|item| item.lit()).map(|item| item.symbol); + if iter.any(|s| s == symbol) { + return true; + } + } else if let Some(meta) = v.meta_item() + && let Some(lit) = meta.name_value_literal() + { + // #[doc(alias = "foo")] + if lit.symbol == symbol { + return true; + } + } + } + } + false +} diff --git a/compiler/rustc_attr_parsing/src/lib.rs b/compiler/rustc_attr_parsing/src/lib.rs index da683ad58c1..63bccf52018 100644 --- a/compiler/rustc_attr_parsing/src/lib.rs +++ b/compiler/rustc_attr_parsing/src/lib.rs @@ -90,7 +90,9 @@ pub mod parser; mod session_diagnostics; pub use attributes::cfg::*; -pub use attributes::util::{find_crate_name, is_builtin_attr, parse_version}; +pub use attributes::util::{ + find_crate_name, is_builtin_attr, is_doc_alias_attrs_contain_symbol, parse_version, +}; pub use context::{AttributeParser, OmitDoc}; rustc_fluent_macro::fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index a1386b4e1be..d13e17a481a 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -147,6 +147,12 @@ pub trait Machine<'tcx>: Sized { /// already been checked before. const ALL_CONSTS_ARE_PRECHECKED: bool = true; + /// Determines whether rustc_const_eval functions that make use of the [Machine] should make + /// tracing calls (to the `tracing` library). By default this is `false`, meaning the tracing + /// calls will supposedly be optimized out. This flag is set to `true` inside Miri, to allow + /// tracing the interpretation steps, among other things. + const TRACING_ENABLED: bool = false; + /// Whether memory accesses should be alignment-checked. fn enforce_alignment(ecx: &InterpCx<'tcx, Self>) -> bool; diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index ba579e25f03..847905e8343 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -45,3 +45,22 @@ pub(crate) fn create_static_alloc<'tcx>( assert!(ecx.memory.alloc_map.insert(alloc_id, (MemoryKind::Stack, alloc)).is_none()); interp_ok(ecx.ptr_to_mplace(Pointer::from(alloc_id).into(), layout)) } + +/// This struct is needed to enforce `#[must_use]` on [tracing::span::EnteredSpan] +/// while wrapping them in an `Option`. +#[must_use] +pub enum MaybeEnteredSpan { + Some(tracing::span::EnteredSpan), + None, +} + +#[macro_export] +macro_rules! enter_trace_span { + ($machine:ident, $($tt:tt)*) => { + if $machine::TRACING_ENABLED { + $crate::interpret::tracing_utils::MaybeEnteredSpan::Some(tracing::info_span!($($tt)*).entered()) + } else { + $crate::interpret::tracing_utils::MaybeEnteredSpan::None + } + } +} diff --git a/compiler/rustc_hir_typeck/Cargo.toml b/compiler/rustc_hir_typeck/Cargo.toml index 40fb2d6a106..c963f0ddefd 100644 --- a/compiler/rustc_hir_typeck/Cargo.toml +++ b/compiler/rustc_hir_typeck/Cargo.toml @@ -9,6 +9,7 @@ itertools = "0.12" rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } rustc_attr_data_structures = { path = "../rustc_attr_data_structures" } +rustc_attr_parsing = { path = "../rustc_attr_parsing" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_fluent_macro = { path = "../rustc_fluent_macro" } diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index d1bc54ed73e..8182851a015 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -84,7 +84,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.annotate_expected_due_to_let_ty(err, expr, error); self.annotate_loop_expected_due_to_inference(err, expr, error); - if self.annotate_mut_binding_to_immutable_binding(err, expr, error) { + if self.annotate_mut_binding_to_immutable_binding(err, expr, expr_ty, expected, error) { return; } @@ -799,17 +799,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Detect the following case /// /// ```text - /// fn change_object(mut a: &Ty) { + /// fn change_object(mut b: &Ty) { /// let a = Ty::new(); /// b = a; /// } /// ``` /// - /// where the user likely meant to modify the value behind there reference, use `a` as an out + /// where the user likely meant to modify the value behind there reference, use `b` as an out /// parameter, instead of mutating the local binding. When encountering this we suggest: /// /// ```text - /// fn change_object(a: &'_ mut Ty) { + /// fn change_object(b: &'_ mut Ty) { /// let a = Ty::new(); /// *b = a; /// } @@ -818,13 +818,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, err: &mut Diag<'_>, expr: &hir::Expr<'_>, + expr_ty: Ty<'tcx>, + expected: Ty<'tcx>, error: Option<TypeError<'tcx>>, ) -> bool { - if let Some(TypeError::Sorts(ExpectedFound { expected, found })) = error + if let Some(TypeError::Sorts(ExpectedFound { .. })) = error && let ty::Ref(_, inner, hir::Mutability::Not) = expected.kind() // The difference between the expected and found values is one level of borrowing. - && self.can_eq(self.param_env, *inner, found) + && self.can_eq(self.param_env, *inner, expr_ty) // We have an `ident = expr;` assignment. && let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Assign(lhs, rhs, _), .. }) = diff --git a/compiler/rustc_hir_typeck/src/gather_locals.rs b/compiler/rustc_hir_typeck/src/gather_locals.rs index 956671fc66e..7d99b0e7869 100644 --- a/compiler/rustc_hir_typeck/src/gather_locals.rs +++ b/compiler/rustc_hir_typeck/src/gather_locals.rs @@ -218,7 +218,12 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> { ); } let old_outermost_fn_param_pat = self.outermost_fn_param_pat.take(); - intravisit::walk_pat(self, p); + if let PatKind::Guard(subpat, _) = p.kind { + // We'll visit the guard when checking it. Don't gather its locals twice. + self.visit_pat(subpat); + } else { + intravisit::walk_pat(self, p); + } self.outermost_fn_param_pat = old_outermost_fn_param_pat; } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index bda051f1560..6090c0f9aee 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -2,6 +2,7 @@ use std::cell::{Cell, RefCell}; use std::cmp::max; use std::ops::Deref; +use rustc_attr_parsing::is_doc_alias_attrs_contain_symbol; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sso::SsoHashSet; use rustc_errors::Applicability; @@ -2333,10 +2334,13 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }; let hir_id = self.fcx.tcx.local_def_id_to_hir_id(local_def_id); let attrs = self.fcx.tcx.hir_attrs(hir_id); + + if is_doc_alias_attrs_contain_symbol(attrs.into_iter(), method.name) { + return true; + } + for attr in attrs { - if attr.has_name(sym::doc) { - // do nothing - } else if attr.has_name(sym::rustc_confusables) { + if attr.has_name(sym::rustc_confusables) { let Some(confusables) = attr.meta_item_list() else { continue; }; @@ -2348,33 +2352,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { return true; } } - continue; - } else { - continue; - }; - let Some(values) = attr.meta_item_list() else { - continue; - }; - for v in values { - if !v.has_name(sym::alias) { - continue; - } - if let Some(nested) = v.meta_item_list() { - // #[doc(alias("foo", "bar"))] - for n in nested { - if let Some(lit) = n.lit() - && method.name == lit.symbol - { - return true; - } - } - } else if let Some(meta) = v.meta_item() - && let Some(lit) = meta.name_value_literal() - && method.name == lit.symbol - { - // #[doc(alias = "foo")] - return true; - } } } false diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 9be041f75d7..b2497cb0de1 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -9,17 +9,21 @@ //! which creates a new `TypeckResults` which doesn't contain any inference variables. use std::mem; +use std::ops::ControlFlow; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::unord::ExtendUnord; -use rustc_errors::ErrorGuaranteed; +use rustc_errors::{E0720, ErrorGuaranteed}; +use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, InferKind, Visitor}; use rustc_hir::{self as hir, AmbigArg, HirId}; use rustc_infer::traits::solve::Goal; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion}; use rustc_middle::ty::{ - self, DefiningScopeKind, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, - TypeVisitableExt, fold_regions, + self, DefiningScopeKind, OpaqueHiddenType, Ty, TyCtxt, TypeFoldable, TypeFolder, + TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, + fold_regions, }; use rustc_span::{Span, sym}; use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded; @@ -595,6 +599,35 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { entry.span = prev.span.substitute_dummy(hidden_type.span); } } + + let recursive_opaques: Vec<_> = self + .typeck_results + .concrete_opaque_types + .iter() + .filter(|&(&def_id, hidden_ty)| { + hidden_ty + .ty + .visit_with(&mut HasRecursiveOpaque { + def_id, + seen: Default::default(), + opaques: &self.typeck_results.concrete_opaque_types, + tcx, + }) + .is_break() + }) + .map(|(def_id, hidden_ty)| (*def_id, hidden_ty.span)) + .collect(); + for (def_id, span) in recursive_opaques { + let guar = self + .fcx + .dcx() + .struct_span_err(span, "cannot resolve opaque type") + .with_code(E0720) + .emit(); + self.typeck_results + .concrete_opaque_types + .insert(def_id, OpaqueHiddenType { span, ty: Ty::new_error(tcx, guar) }); + } } fn visit_field_id(&mut self, hir_id: HirId) { @@ -959,3 +992,34 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerlyNormalizeConsts<'tcx> { self.tcx.try_normalize_erasing_regions(self.typing_env, ct).unwrap_or(ct) } } + +struct HasRecursiveOpaque<'a, 'tcx> { + def_id: LocalDefId, + seen: FxHashSet<LocalDefId>, + opaques: &'a FxIndexMap<LocalDefId, ty::OpaqueHiddenType<'tcx>>, + tcx: TyCtxt<'tcx>, +} + +impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> { + type Result = ControlFlow<()>; + + fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { + if let ty::Alias(ty::Opaque, alias_ty) = *t.kind() + && let Some(def_id) = alias_ty.def_id.as_local() + { + if self.def_id == def_id { + return ControlFlow::Break(()); + } + + if self.seen.insert(def_id) + && let Some(hidden_ty) = self.opaques.get(&def_id) + { + ty::EarlyBinder::bind(hidden_ty.ty) + .instantiate(self.tcx, alias_ty.args) + .visit_with(self)?; + } + } + + t.super_visit_with(self) + } +} diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl index cac8f34b0fa..bccffe39243 100644 --- a/compiler/rustc_metadata/messages.ftl +++ b/compiler/rustc_metadata/messages.ftl @@ -2,7 +2,7 @@ metadata_as_needed_compatibility = linking modifier `as-needed` is only compatible with `dylib` and `framework` linking kinds metadata_async_drop_types_in_dependency = - found async drop types in dependecy `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}` + found async drop types in dependency `{$extern_crate}`, but async_drop feature is disabled for `{$local_crate}` .help = if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used metadata_bad_panic_strategy = diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index a89d01dcbbe..d9f1888bfd9 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -1,6 +1,5 @@ use std::fmt; use std::iter::once; -use std::ops::ControlFlow; use rustc_abi::{FIRST_VARIANT, FieldIdx, Integer, VariantIdx}; use rustc_arena::DroplessArena; @@ -12,8 +11,7 @@ use rustc_middle::mir::{self, Const}; use rustc_middle::thir::{self, Pat, PatKind, PatRange, PatRangeBoundary}; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{ - self, FieldDef, OpaqueTypeKey, ScalarInt, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, - TypeVisitableExt, TypeVisitor, VariantDef, + self, FieldDef, OpaqueTypeKey, ScalarInt, Ty, TyCtxt, TypeVisitableExt, VariantDef, }; use rustc_middle::{bug, span_bug}; use rustc_session::lint; @@ -137,22 +135,11 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { /// Returns the hidden type corresponding to this key if the body under analysis is allowed to /// know it. fn reveal_opaque_key(&self, key: OpaqueTypeKey<'tcx>) -> Option<Ty<'tcx>> { - if let Some(hidden_ty) = self.typeck_results.concrete_opaque_types.get(&key.def_id) { - let ty = ty::EarlyBinder::bind(hidden_ty.ty).instantiate(self.tcx, key.args); - if ty.visit_with(&mut RecursiveOpaque { def_id: key.def_id.into() }).is_continue() { - Some(ty) - } else { - // HACK: We skip revealing opaque types which recursively expand - // to themselves. This is because we may infer hidden types like - // `Opaque<T> = Opaque<Opaque<T>>` or `Opaque<T> = Opaque<(T,)>` - // in hir typeck. - None - } - } else { - None - } + self.typeck_results + .concrete_opaque_types + .get(&key.def_id) + .map(|x| ty::EarlyBinder::bind(x.ty).instantiate(self.tcx, key.args)) } - // This can take a non-revealed `Ty` because it reveals opaques itself. pub fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool { !ty.inhabited_predicate(self.tcx).apply_revealing_opaque( @@ -1177,20 +1164,3 @@ fn detect_mixed_deref_pat_ctors<'p, 'tcx>( } Ok(()) } - -struct RecursiveOpaque { - def_id: DefId, -} -impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for RecursiveOpaque { - type Result = ControlFlow<()>; - - fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { - if let ty::Alias(ty::Opaque, alias_ty) = t.kind() { - if alias_ty.def_id == self.def_id { - return ControlFlow::Break(()); - } - } - - if t.has_opaque_types() { t.super_visit_with(self) } else { ControlFlow::Continue(()) } - } -} diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index b538be34f31..6768907adde 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -11,6 +11,7 @@ use rustc_ast::{ Item, ItemKind, MethodCall, NodeId, Path, PathSegment, Ty, TyKind, }; use rustc_ast_pretty::pprust::where_bound_predicate_to_string; +use rustc_attr_parsing::is_doc_alias_attrs_contain_symbol; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_errors::codes::*; use rustc_errors::{ @@ -39,7 +40,7 @@ use crate::late::{ }; use crate::ty::fast_reject::SimplifiedType; use crate::{ - Module, ModuleKind, ModuleOrUniformRoot, PathResult, PathSource, Segment, errors, + Module, ModuleKind, ModuleOrUniformRoot, PathResult, PathSource, Resolver, Segment, errors, path_names_to_string, }; @@ -477,6 +478,19 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { return (err, Vec::new()); } + if let Some((did, item)) = self.lookup_doc_alias_name(path, source.namespace()) { + let item_name = item.name; + let suggestion_name = self.r.tcx.item_name(did); + err.span_suggestion( + item.span, + format!("`{suggestion_name}` has a name defined in the doc alias attribute as `{item_name}`"), + suggestion_name, + Applicability::MaybeIncorrect + ); + + return (err, Vec::new()); + }; + let (found, suggested_candidates, mut candidates) = self.try_lookup_name_relaxed( &mut err, source, @@ -852,6 +866,65 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { (false, suggested_candidates, candidates) } + fn lookup_doc_alias_name(&mut self, path: &[Segment], ns: Namespace) -> Option<(DefId, Ident)> { + let find_doc_alias_name = |r: &mut Resolver<'ra, '_>, m: Module<'ra>, item_name: Symbol| { + for resolution in r.resolutions(m).borrow().values() { + let Some(did) = + resolution.borrow().binding.and_then(|binding| binding.res().opt_def_id()) + else { + continue; + }; + if did.is_local() { + // We don't record the doc alias name in the local crate + // because the people who write doc alias are usually not + // confused by them. + continue; + } + if is_doc_alias_attrs_contain_symbol(r.tcx.get_attrs(did, sym::doc), item_name) { + return Some(did); + } + } + None + }; + + if path.len() == 1 { + for rib in self.ribs[ns].iter().rev() { + let item = path[0].ident; + if let RibKind::Module(module) = rib.kind + && let Some(did) = find_doc_alias_name(self.r, module, item.name) + { + return Some((did, item)); + } + } + } else { + // Finds to the last resolved module item in the path + // and searches doc aliases within that module. + // + // Example: For the path `a::b::last_resolved::not_exist::c::d`, + // we will try to find any item has doc aliases named `not_exist` + // in `last_resolved` module. + // + // - Use `skip(1)` because the final segment must remain unresolved. + for (idx, seg) in path.iter().enumerate().rev().skip(1) { + let Some(id) = seg.id else { + continue; + }; + let Some(res) = self.r.partial_res_map.get(&id) else { + continue; + }; + if let Res::Def(DefKind::Mod, module) = res.expect_full_res() + && let Some(module) = self.r.get_module(module) + && let item = path[idx + 1].ident + && let Some(did) = find_doc_alias_name(self.r, module, item.name) + { + return Some((did, item)); + } + break; + } + } + None + } + fn suggest_trait_and_bounds( &mut self, err: &mut Diag<'_>, diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index eae3213ead0..1b5d04e6025 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -193,7 +193,7 @@ impl<I: Interner> fmt::Debug for RegionKind<I> { ReVar(vid) => write!(f, "{vid:?}"), - RePlaceholder(placeholder) => write!(f, "{placeholder:?}"), + RePlaceholder(placeholder) => write!(f, "'{placeholder:?}"), // Use `'{erased}` as the output instead of `'erased` so that its more obviously distinct from // a `ReEarlyParam` named `'erased`. Technically that would print as `'erased/#IDX` so this is diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index 24c5d4c92f7..8766fd904b0 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -234,7 +234,7 @@ impl str { #[stable(feature = "str_box_extras", since = "1.20.0")] #[must_use = "`self` will be dropped if the result is not used"] #[inline] - pub fn into_boxed_bytes(self: Box<str>) -> Box<[u8]> { + pub fn into_boxed_bytes(self: Box<Self>) -> Box<[u8]> { self.into() } @@ -501,7 +501,7 @@ impl str { #[rustc_allow_incoherent_impl] #[must_use = "`self` will be dropped if the result is not used"] #[inline] - pub fn into_string(self: Box<str>) -> String { + pub fn into_string(self: Box<Self>) -> String { let slice = Box::<[u8]>::from(self); unsafe { String::from_utf8_unchecked(slice.into_vec()) } } diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 9525bdb6762..43bf414d6be 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -12,7 +12,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::convert::FloatToInt; -use crate::num::{FpCategory, libm}; +use crate::num::FpCategory; use crate::panic::const_assert; use crate::{cfg_match, intrinsics, mem}; @@ -1557,413 +1557,441 @@ impl f32 { } } -/// Experimental version of `floor` in `core`. See [`f32::floor`] for details. +/// Experimental implementations of floating point functions in `core`. /// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let f = 3.7_f32; -/// let g = 3.0_f32; -/// let h = -3.7_f32; -/// -/// assert_eq!(f32::floor(f), 3.0); -/// assert_eq!(f32::floor(g), 3.0); -/// assert_eq!(f32::floor(h), -4.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::floor`]: ../../std/primitive.f32.html#method.floor -#[inline] +/// _The standalone functions in this module are for testing only. +/// They will be stabilized as inherent methods._ #[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn floor(x: f32) -> f32 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::floorf32(x) } -} +pub mod math { + use crate::intrinsics; + use crate::num::libm; -/// Experimental version of `ceil` in `core`. See [`f32::ceil`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let f = 3.01_f32; -/// let g = 4.0_f32; -/// -/// assert_eq!(f32::ceil(f), 4.0); -/// assert_eq!(f32::ceil(g), 4.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::ceil`]: ../../std/primitive.f32.html#method.ceil -#[inline] -#[doc(alias = "ceiling")] -#[must_use = "method returns a new number and does not mutate the original value"] -#[unstable(feature = "core_float_math", issue = "137578")] -pub fn ceil(x: f32) -> f32 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::ceilf32(x) } -} + /// Experimental version of `floor` in `core`. See [`f32::floor`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let f = 3.7_f32; + /// let g = 3.0_f32; + /// let h = -3.7_f32; + /// + /// assert_eq!(f32::math::floor(f), 3.0); + /// assert_eq!(f32::math::floor(g), 3.0); + /// assert_eq!(f32::math::floor(h), -4.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::floor`]: ../../../std/primitive.f32.html#method.floor + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn floor(x: f32) -> f32 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::floorf32(x) } + } -/// Experimental version of `round` in `core`. See [`f32::round`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let f = 3.3_f32; -/// let g = -3.3_f32; -/// let h = -3.7_f32; -/// let i = 3.5_f32; -/// let j = 4.5_f32; -/// -/// assert_eq!(f32::round(f), 3.0); -/// assert_eq!(f32::round(g), -3.0); -/// assert_eq!(f32::round(h), -4.0); -/// assert_eq!(f32::round(i), 4.0); -/// assert_eq!(f32::round(j), 5.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::round`]: ../../std/primitive.f32.html#method.round -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn round(x: f32) -> f32 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::roundf32(x) } -} + /// Experimental version of `ceil` in `core`. See [`f32::ceil`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let f = 3.01_f32; + /// let g = 4.0_f32; + /// + /// assert_eq!(f32::math::ceil(f), 4.0); + /// assert_eq!(f32::math::ceil(g), 4.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::ceil`]: ../../../std/primitive.f32.html#method.ceil + #[inline] + #[doc(alias = "ceiling")] + #[must_use = "method returns a new number and does not mutate the original value"] + #[unstable(feature = "core_float_math", issue = "137578")] + pub fn ceil(x: f32) -> f32 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::ceilf32(x) } + } -/// Experimental version of `round_ties_even` in `core`. See [`f32::round_ties_even`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let f = 3.3_f32; -/// let g = -3.3_f32; -/// let h = 3.5_f32; -/// let i = 4.5_f32; -/// -/// assert_eq!(f32::round_ties_even(f), 3.0); -/// assert_eq!(f32::round_ties_even(g), -3.0); -/// assert_eq!(f32::round_ties_even(h), 4.0); -/// assert_eq!(f32::round_ties_even(i), 4.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::round_ties_even`]: ../../std/primitive.f32.html#method.round_ties_even -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn round_ties_even(x: f32) -> f32 { - intrinsics::round_ties_even_f32(x) -} + /// Experimental version of `round` in `core`. See [`f32::round`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let f = 3.3_f32; + /// let g = -3.3_f32; + /// let h = -3.7_f32; + /// let i = 3.5_f32; + /// let j = 4.5_f32; + /// + /// assert_eq!(f32::math::round(f), 3.0); + /// assert_eq!(f32::math::round(g), -3.0); + /// assert_eq!(f32::math::round(h), -4.0); + /// assert_eq!(f32::math::round(i), 4.0); + /// assert_eq!(f32::math::round(j), 5.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::round`]: ../../../std/primitive.f32.html#method.round + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn round(x: f32) -> f32 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::roundf32(x) } + } -/// Experimental version of `trunc` in `core`. See [`f32::trunc`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let f = 3.7_f32; -/// let g = 3.0_f32; -/// let h = -3.7_f32; -/// -/// assert_eq!(f32::trunc(f), 3.0); -/// assert_eq!(f32::trunc(g), 3.0); -/// assert_eq!(f32::trunc(h), -3.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::trunc`]: ../../std/primitive.f32.html#method.trunc -#[inline] -#[doc(alias = "truncate")] -#[must_use = "method returns a new number and does not mutate the original value"] -#[unstable(feature = "core_float_math", issue = "137578")] -pub fn trunc(x: f32) -> f32 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::truncf32(x) } -} + /// Experimental version of `round_ties_even` in `core`. See [`f32::round_ties_even`] for + /// details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let f = 3.3_f32; + /// let g = -3.3_f32; + /// let h = 3.5_f32; + /// let i = 4.5_f32; + /// + /// assert_eq!(f32::math::round_ties_even(f), 3.0); + /// assert_eq!(f32::math::round_ties_even(g), -3.0); + /// assert_eq!(f32::math::round_ties_even(h), 4.0); + /// assert_eq!(f32::math::round_ties_even(i), 4.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::round_ties_even`]: ../../../std/primitive.f32.html#method.round_ties_even + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn round_ties_even(x: f32) -> f32 { + intrinsics::round_ties_even_f32(x) + } -/// Experimental version of `fract` in `core`. See [`f32::fract`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let x = 3.6_f32; -/// let y = -3.6_f32; -/// let abs_difference_x = (f32::fract(x) - 0.6).abs(); -/// let abs_difference_y = (f32::fract(y) - (-0.6)).abs(); -/// -/// assert!(abs_difference_x <= f32::EPSILON); -/// assert!(abs_difference_y <= f32::EPSILON); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::fract`]: ../../std/primitive.f32.html#method.fract -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn fract(x: f32) -> f32 { - x - trunc(x) -} + /// Experimental version of `trunc` in `core`. See [`f32::trunc`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let f = 3.7_f32; + /// let g = 3.0_f32; + /// let h = -3.7_f32; + /// + /// assert_eq!(f32::math::trunc(f), 3.0); + /// assert_eq!(f32::math::trunc(g), 3.0); + /// assert_eq!(f32::math::trunc(h), -3.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::trunc`]: ../../../std/primitive.f32.html#method.trunc + #[inline] + #[doc(alias = "truncate")] + #[must_use = "method returns a new number and does not mutate the original value"] + #[unstable(feature = "core_float_math", issue = "137578")] + pub fn trunc(x: f32) -> f32 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::truncf32(x) } + } -/// Experimental version of `mul_add` in `core`. See [`f32::mul_add`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// # // FIXME(#140515): mingw has an incorrect fma https://sourceforge.net/p/mingw-w64/bugs/848/ -/// # #[cfg(all(target_os = "windows", target_env = "gnu", not(target_abi = "llvm")))] { -/// use core::f32; -/// -/// let m = 10.0_f32; -/// let x = 4.0_f32; -/// let b = 60.0_f32; -/// -/// assert_eq!(f32::mul_add(m, x, b), 100.0); -/// assert_eq!(m * x + b, 100.0); -/// -/// let one_plus_eps = 1.0_f32 + f32::EPSILON; -/// let one_minus_eps = 1.0_f32 - f32::EPSILON; -/// let minus_one = -1.0_f32; -/// -/// // The exact result (1 + eps) * (1 - eps) = 1 - eps * eps. -/// assert_eq!(f32::mul_add(one_plus_eps, one_minus_eps, minus_one), -f32::EPSILON * f32::EPSILON); -/// // Different rounding with the non-fused multiply and add. -/// assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0); -/// # } -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::mul_add`]: ../../std/primitive.f32.html#method.mul_add -#[inline] -#[doc(alias = "fmaf", alias = "fusedMultiplyAdd")] -#[must_use = "method returns a new number and does not mutate the original value"] -#[unstable(feature = "core_float_math", issue = "137578")] -pub fn mul_add(x: f32, y: f32, z: f32) -> f32 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::fmaf32(x, y, z) } -} + /// Experimental version of `fract` in `core`. See [`f32::fract`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let x = 3.6_f32; + /// let y = -3.6_f32; + /// let abs_difference_x = (f32::math::fract(x) - 0.6).abs(); + /// let abs_difference_y = (f32::math::fract(y) - (-0.6)).abs(); + /// + /// assert!(abs_difference_x <= f32::EPSILON); + /// assert!(abs_difference_y <= f32::EPSILON); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::fract`]: ../../../std/primitive.f32.html#method.fract + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn fract(x: f32) -> f32 { + x - trunc(x) + } -/// Experimental version of `div_euclid` in `core`. See [`f32::div_euclid`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let a: f32 = 7.0; -/// let b = 4.0; -/// assert_eq!(f32::div_euclid(a, b), 1.0); // 7.0 > 4.0 * 1.0 -/// assert_eq!(f32::div_euclid(-a, b), -2.0); // -7.0 >= 4.0 * -2.0 -/// assert_eq!(f32::div_euclid(a, -b), -1.0); // 7.0 >= -4.0 * -1.0 -/// assert_eq!(f32::div_euclid(-a, -b), 2.0); // -7.0 >= -4.0 * 2.0 -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::div_euclid`]: ../../std/primitive.f32.html#method.div_euclid -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn div_euclid(x: f32, rhs: f32) -> f32 { - let q = trunc(x / rhs); - if x % rhs < 0.0 { - return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }; + /// Experimental version of `mul_add` in `core`. See [`f32::mul_add`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// # // FIXME(#140515): mingw has an incorrect fma + /// # // https://sourceforge.net/p/mingw-w64/bugs/848/ + /// # #[cfg(all(target_os = "windows", target_env = "gnu", not(target_abi = "llvm")))] { + /// use core::f32; + /// + /// let m = 10.0_f32; + /// let x = 4.0_f32; + /// let b = 60.0_f32; + /// + /// assert_eq!(f32::math::mul_add(m, x, b), 100.0); + /// assert_eq!(m * x + b, 100.0); + /// + /// let one_plus_eps = 1.0_f32 + f32::EPSILON; + /// let one_minus_eps = 1.0_f32 - f32::EPSILON; + /// let minus_one = -1.0_f32; + /// + /// // The exact result (1 + eps) * (1 - eps) = 1 - eps * eps. + /// assert_eq!( + /// f32::math::mul_add(one_plus_eps, one_minus_eps, minus_one), + /// -f32::EPSILON * f32::EPSILON + /// ); + /// // Different rounding with the non-fused multiply and add. + /// assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0); + /// # } + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::mul_add`]: ../../../std/primitive.f32.html#method.mul_add + #[inline] + #[doc(alias = "fmaf", alias = "fusedMultiplyAdd")] + #[must_use = "method returns a new number and does not mutate the original value"] + #[unstable(feature = "core_float_math", issue = "137578")] + pub fn mul_add(x: f32, y: f32, z: f32) -> f32 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::fmaf32(x, y, z) } } - q -} -/// Experimental version of `rem_euclid` in `core`. See [`f32::rem_euclid`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let a: f32 = 7.0; -/// let b = 4.0; -/// assert_eq!(f32::rem_euclid(a, b), 3.0); -/// assert_eq!(f32::rem_euclid(-a, b), 1.0); -/// assert_eq!(f32::rem_euclid(a, -b), 3.0); -/// assert_eq!(f32::rem_euclid(-a, -b), 1.0); -/// // limitation due to round-off error -/// assert!(f32::rem_euclid(-f32::EPSILON, 3.0) != 0.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::rem_euclid`]: ../../std/primitive.f32.html#method.rem_euclid -#[inline] -#[doc(alias = "modulo", alias = "mod")] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn rem_euclid(x: f32, rhs: f32) -> f32 { - let r = x % rhs; - if r < 0.0 { r + rhs.abs() } else { r } -} + /// Experimental version of `div_euclid` in `core`. See [`f32::div_euclid`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let a: f32 = 7.0; + /// let b = 4.0; + /// assert_eq!(f32::math::div_euclid(a, b), 1.0); // 7.0 > 4.0 * 1.0 + /// assert_eq!(f32::math::div_euclid(-a, b), -2.0); // -7.0 >= 4.0 * -2.0 + /// assert_eq!(f32::math::div_euclid(a, -b), -1.0); // 7.0 >= -4.0 * -1.0 + /// assert_eq!(f32::math::div_euclid(-a, -b), 2.0); // -7.0 >= -4.0 * 2.0 + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::div_euclid`]: ../../../std/primitive.f32.html#method.div_euclid + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn div_euclid(x: f32, rhs: f32) -> f32 { + let q = trunc(x / rhs); + if x % rhs < 0.0 { + return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }; + } + q + } -/// Experimental version of `powi` in `core`. See [`f32::powi`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let x = 2.0_f32; -/// let abs_difference = (f32::powi(x, 2) - (x * x)).abs(); -/// assert!(abs_difference <= f32::EPSILON); -/// -/// assert_eq!(f32::powi(f32::NAN, 0), 1.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::powi`]: ../../std/primitive.f32.html#method.powi -#[inline] -#[must_use = "method returns a new number and does not mutate the original value"] -#[unstable(feature = "core_float_math", issue = "137578")] -pub fn powi(x: f32, n: i32) -> f32 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::powif32(x, n) } -} + /// Experimental version of `rem_euclid` in `core`. See [`f32::rem_euclid`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let a: f32 = 7.0; + /// let b = 4.0; + /// assert_eq!(f32::math::rem_euclid(a, b), 3.0); + /// assert_eq!(f32::math::rem_euclid(-a, b), 1.0); + /// assert_eq!(f32::math::rem_euclid(a, -b), 3.0); + /// assert_eq!(f32::math::rem_euclid(-a, -b), 1.0); + /// // limitation due to round-off error + /// assert!(f32::math::rem_euclid(-f32::EPSILON, 3.0) != 0.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::rem_euclid`]: ../../../std/primitive.f32.html#method.rem_euclid + #[inline] + #[doc(alias = "modulo", alias = "mod")] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn rem_euclid(x: f32, rhs: f32) -> f32 { + let r = x % rhs; + if r < 0.0 { r + rhs.abs() } else { r } + } -/// Experimental version of `sqrt` in `core`. See [`f32::sqrt`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let positive = 4.0_f32; -/// let negative = -4.0_f32; -/// let negative_zero = -0.0_f32; -/// -/// assert_eq!(f32::sqrt(positive), 2.0); -/// assert!(f32::sqrt(negative).is_nan()); -/// assert_eq!(f32::sqrt(negative_zero), negative_zero); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::sqrt`]: ../../std/primitive.f32.html#method.sqrt -#[inline] -#[doc(alias = "squareRoot")] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn sqrt(x: f32) -> f32 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::sqrtf32(x) } -} + /// Experimental version of `powi` in `core`. See [`f32::powi`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let x = 2.0_f32; + /// let abs_difference = (f32::math::powi(x, 2) - (x * x)).abs(); + /// assert!(abs_difference <= f32::EPSILON); + /// + /// assert_eq!(f32::math::powi(f32::NAN, 0), 1.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::powi`]: ../../../std/primitive.f32.html#method.powi + #[inline] + #[must_use = "method returns a new number and does not mutate the original value"] + #[unstable(feature = "core_float_math", issue = "137578")] + pub fn powi(x: f32, n: i32) -> f32 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::powif32(x, n) } + } -/// Experimental version of `abs_sub` in `core`. See [`f32::abs_sub`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let x = 3.0f32; -/// let y = -3.0f32; -/// -/// let abs_difference_x = (f32::abs_sub(x, 1.0) - 2.0).abs(); -/// let abs_difference_y = (f32::abs_sub(y, 1.0) - 0.0).abs(); -/// -/// assert!(abs_difference_x <= f32::EPSILON); -/// assert!(abs_difference_y <= f32::EPSILON); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::abs_sub`]: ../../std/primitive.f32.html#method.abs_sub -#[inline] -#[stable(feature = "rust1", since = "1.0.0")] -#[deprecated( - since = "1.10.0", - note = "you probably meant `(self - other).abs()`: \ + /// Experimental version of `sqrt` in `core`. See [`f32::sqrt`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let positive = 4.0_f32; + /// let negative = -4.0_f32; + /// let negative_zero = -0.0_f32; + /// + /// assert_eq!(f32::math::sqrt(positive), 2.0); + /// assert!(f32::math::sqrt(negative).is_nan()); + /// assert_eq!(f32::math::sqrt(negative_zero), negative_zero); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::sqrt`]: ../../../std/primitive.f32.html#method.sqrt + #[inline] + #[doc(alias = "squareRoot")] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn sqrt(x: f32) -> f32 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::sqrtf32(x) } + } + + /// Experimental version of `abs_sub` in `core`. See [`f32::abs_sub`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let x = 3.0f32; + /// let y = -3.0f32; + /// + /// let abs_difference_x = (f32::math::abs_sub(x, 1.0) - 2.0).abs(); + /// let abs_difference_y = (f32::math::abs_sub(y, 1.0) - 0.0).abs(); + /// + /// assert!(abs_difference_x <= f32::EPSILON); + /// assert!(abs_difference_y <= f32::EPSILON); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::abs_sub`]: ../../../std/primitive.f32.html#method.abs_sub + #[inline] + #[stable(feature = "rust1", since = "1.0.0")] + #[deprecated( + since = "1.10.0", + note = "you probably meant `(self - other).abs()`: \ this operation is `(self - other).max(0.0)` \ except that `abs_sub` also propagates NaNs (also \ known as `fdimf` in C). If you truly need the positive \ difference, consider using that expression or the C function \ `fdimf`, depending on how you wish to handle NaN (please consider \ filing an issue describing your use-case too)." -)] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn abs_sub(x: f32, other: f32) -> f32 { - libm::fdimf(x, other) -} + )] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn abs_sub(x: f32, other: f32) -> f32 { + libm::fdimf(x, other) + } -/// Experimental version of `cbrt` in `core`. See [`f32::cbrt`] for details. -/// -/// # Unspecified precision -/// -/// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and -/// can even differ within the same execution from one invocation to the next. -/// This function currently corresponds to the `cbrtf` from libc on Unix -/// and Windows. Note that this might change in the future. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f32; -/// -/// let x = 8.0f32; -/// -/// // x^(1/3) - 2 == 0 -/// let abs_difference = (f32::cbrt(x) - 2.0).abs(); -/// -/// assert!(abs_difference <= f32::EPSILON); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f32::cbrt`]: ../../std/primitive.f32.html#method.cbrt -#[inline] -#[must_use = "method returns a new number and does not mutate the original value"] -#[unstable(feature = "core_float_math", issue = "137578")] -pub fn cbrt(x: f32) -> f32 { - libm::cbrtf(x) + /// Experimental version of `cbrt` in `core`. See [`f32::cbrt`] for details. + /// + /// # Unspecified precision + /// + /// The precision of this function is non-deterministic. This means it varies by platform, Rust version, and + /// can even differ within the same execution from one invocation to the next. + /// This function currently corresponds to the `cbrtf` from libc on Unix + /// and Windows. Note that this might change in the future. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f32; + /// + /// let x = 8.0f32; + /// + /// // x^(1/3) - 2 == 0 + /// let abs_difference = (f32::math::cbrt(x) - 2.0).abs(); + /// + /// assert!(abs_difference <= f32::EPSILON); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f32::cbrt`]: ../../../std/primitive.f32.html#method.cbrt + #[inline] + #[must_use = "method returns a new number and does not mutate the original value"] + #[unstable(feature = "core_float_math", issue = "137578")] + pub fn cbrt(x: f32) -> f32 { + libm::cbrtf(x) + } } diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 76c4e5d1a6f..8fbf2cffbaf 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -12,7 +12,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::convert::FloatToInt; -use crate::num::{FpCategory, libm}; +use crate::num::FpCategory; use crate::panic::const_assert; use crate::{intrinsics, mem}; @@ -1556,406 +1556,434 @@ impl f64 { } } -/// Experimental version of `floor` in `core`. See [`f64::floor`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let f = 3.7_f64; -/// let g = 3.0_f64; -/// let h = -3.7_f64; -/// -/// assert_eq!(f64::floor(f), 3.0); -/// assert_eq!(f64::floor(g), 3.0); -/// assert_eq!(f64::floor(h), -4.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::floor`]: ../../std/primitive.f64.html#method.floor -#[inline] #[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn floor(x: f64) -> f64 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::floorf64(x) } -} - -/// Experimental version of `ceil` in `core`. See [`f64::ceil`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let f = 3.01_f64; -/// let g = 4.0_f64; -/// -/// assert_eq!(f64::ceil(f), 4.0); -/// assert_eq!(f64::ceil(g), 4.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ +/// Experimental implementations of floating point functions in `core`. /// -/// [`f64::ceil`]: ../../std/primitive.f64.html#method.ceil -#[inline] -#[doc(alias = "ceiling")] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn ceil(x: f64) -> f64 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::ceilf64(x) } -} +/// _The standalone functions in this module are for testing only. +/// They will be stabilized as inherent methods._ +pub mod math { + use crate::intrinsics; + use crate::num::libm; -/// Experimental version of `round` in `core`. See [`f64::round`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let f = 3.3_f64; -/// let g = -3.3_f64; -/// let h = -3.7_f64; -/// let i = 3.5_f64; -/// let j = 4.5_f64; -/// -/// assert_eq!(f64::round(f), 3.0); -/// assert_eq!(f64::round(g), -3.0); -/// assert_eq!(f64::round(h), -4.0); -/// assert_eq!(f64::round(i), 4.0); -/// assert_eq!(f64::round(j), 5.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::round`]: ../../std/primitive.f64.html#method.round -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn round(x: f64) -> f64 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::roundf64(x) } -} + /// Experimental version of `floor` in `core`. See [`f64::floor`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let f = 3.7_f64; + /// let g = 3.0_f64; + /// let h = -3.7_f64; + /// + /// assert_eq!(f64::math::floor(f), 3.0); + /// assert_eq!(f64::math::floor(g), 3.0); + /// assert_eq!(f64::math::floor(h), -4.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::floor`]: ../../../std/primitive.f64.html#method.floor + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn floor(x: f64) -> f64 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::floorf64(x) } + } -/// Experimental version of `round_ties_even` in `core`. See [`f64::round_ties_even`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let f = 3.3_f64; -/// let g = -3.3_f64; -/// let h = 3.5_f64; -/// let i = 4.5_f64; -/// -/// assert_eq!(f64::round_ties_even(f), 3.0); -/// assert_eq!(f64::round_ties_even(g), -3.0); -/// assert_eq!(f64::round_ties_even(h), 4.0); -/// assert_eq!(f64::round_ties_even(i), 4.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::round_ties_even`]: ../../std/primitive.f64.html#method.round_ties_even -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn round_ties_even(x: f64) -> f64 { - intrinsics::round_ties_even_f64(x) -} + /// Experimental version of `ceil` in `core`. See [`f64::ceil`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let f = 3.01_f64; + /// let g = 4.0_f64; + /// + /// assert_eq!(f64::math::ceil(f), 4.0); + /// assert_eq!(f64::math::ceil(g), 4.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::ceil`]: ../../../std/primitive.f64.html#method.ceil + #[inline] + #[doc(alias = "ceiling")] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn ceil(x: f64) -> f64 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::ceilf64(x) } + } -/// Experimental version of `trunc` in `core`. See [`f64::trunc`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let f = 3.7_f64; -/// let g = 3.0_f64; -/// let h = -3.7_f64; -/// -/// assert_eq!(f64::trunc(f), 3.0); -/// assert_eq!(f64::trunc(g), 3.0); -/// assert_eq!(f64::trunc(h), -3.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::trunc`]: ../../std/primitive.f64.html#method.trunc -#[inline] -#[doc(alias = "truncate")] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn trunc(x: f64) -> f64 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::truncf64(x) } -} + /// Experimental version of `round` in `core`. See [`f64::round`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let f = 3.3_f64; + /// let g = -3.3_f64; + /// let h = -3.7_f64; + /// let i = 3.5_f64; + /// let j = 4.5_f64; + /// + /// assert_eq!(f64::math::round(f), 3.0); + /// assert_eq!(f64::math::round(g), -3.0); + /// assert_eq!(f64::math::round(h), -4.0); + /// assert_eq!(f64::math::round(i), 4.0); + /// assert_eq!(f64::math::round(j), 5.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::round`]: ../../../std/primitive.f64.html#method.round + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn round(x: f64) -> f64 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::roundf64(x) } + } -/// Experimental version of `fract` in `core`. See [`f64::fract`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let x = 3.6_f64; -/// let y = -3.6_f64; -/// let abs_difference_x = (f64::fract(x) - 0.6).abs(); -/// let abs_difference_y = (f64::fract(y) - (-0.6)).abs(); -/// -/// assert!(abs_difference_x < 1e-10); -/// assert!(abs_difference_y < 1e-10); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::fract`]: ../../std/primitive.f64.html#method.fract -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn fract(x: f64) -> f64 { - x - trunc(x) -} + /// Experimental version of `round_ties_even` in `core`. See [`f64::round_ties_even`] for + /// details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let f = 3.3_f64; + /// let g = -3.3_f64; + /// let h = 3.5_f64; + /// let i = 4.5_f64; + /// + /// assert_eq!(f64::math::round_ties_even(f), 3.0); + /// assert_eq!(f64::math::round_ties_even(g), -3.0); + /// assert_eq!(f64::math::round_ties_even(h), 4.0); + /// assert_eq!(f64::math::round_ties_even(i), 4.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::round_ties_even`]: ../../../std/primitive.f64.html#method.round_ties_even + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn round_ties_even(x: f64) -> f64 { + intrinsics::round_ties_even_f64(x) + } -/// Experimental version of `mul_add` in `core`. See [`f64::mul_add`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// # // FIXME(#140515): mingw has an incorrect fma https://sourceforge.net/p/mingw-w64/bugs/848/ -/// # #[cfg(all(target_os = "windows", target_env = "gnu", not(target_abi = "llvm")))] { -/// use core::f64; -/// -/// let m = 10.0_f64; -/// let x = 4.0_f64; -/// let b = 60.0_f64; -/// -/// assert_eq!(f64::mul_add(m, x, b), 100.0); -/// assert_eq!(m * x + b, 100.0); -/// -/// let one_plus_eps = 1.0_f64 + f64::EPSILON; -/// let one_minus_eps = 1.0_f64 - f64::EPSILON; -/// let minus_one = -1.0_f64; -/// -/// // The exact result (1 + eps) * (1 - eps) = 1 - eps * eps. -/// assert_eq!(f64::mul_add(one_plus_eps, one_minus_eps, minus_one), -f64::EPSILON * f64::EPSILON); -/// // Different rounding with the non-fused multiply and add. -/// assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0); -/// # } -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::mul_add`]: ../../std/primitive.f64.html#method.mul_add -#[inline] -#[doc(alias = "fma", alias = "fusedMultiplyAdd")] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn mul_add(x: f64, a: f64, b: f64) -> f64 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::fmaf64(x, a, b) } -} + /// Experimental version of `trunc` in `core`. See [`f64::trunc`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let f = 3.7_f64; + /// let g = 3.0_f64; + /// let h = -3.7_f64; + /// + /// assert_eq!(f64::math::trunc(f), 3.0); + /// assert_eq!(f64::math::trunc(g), 3.0); + /// assert_eq!(f64::math::trunc(h), -3.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::trunc`]: ../../../std/primitive.f64.html#method.trunc + #[inline] + #[doc(alias = "truncate")] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn trunc(x: f64) -> f64 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::truncf64(x) } + } -/// Experimental version of `div_euclid` in `core`. See [`f64::div_euclid`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let a: f64 = 7.0; -/// let b = 4.0; -/// assert_eq!(f64::div_euclid(a, b), 1.0); // 7.0 > 4.0 * 1.0 -/// assert_eq!(f64::div_euclid(-a, b), -2.0); // -7.0 >= 4.0 * -2.0 -/// assert_eq!(f64::div_euclid(a, -b), -1.0); // 7.0 >= -4.0 * -1.0 -/// assert_eq!(f64::div_euclid(-a, -b), 2.0); // -7.0 >= -4.0 * 2.0 -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::div_euclid`]: ../../std/primitive.f64.html#method.div_euclid -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn div_euclid(x: f64, rhs: f64) -> f64 { - let q = trunc(x / rhs); - if x % rhs < 0.0 { - return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }; + /// Experimental version of `fract` in `core`. See [`f64::fract`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let x = 3.6_f64; + /// let y = -3.6_f64; + /// let abs_difference_x = (f64::math::fract(x) - 0.6).abs(); + /// let abs_difference_y = (f64::math::fract(y) - (-0.6)).abs(); + /// + /// assert!(abs_difference_x < 1e-10); + /// assert!(abs_difference_y < 1e-10); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::fract`]: ../../../std/primitive.f64.html#method.fract + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn fract(x: f64) -> f64 { + x - trunc(x) } - q -} -/// Experimental version of `rem_euclid` in `core`. See [`f64::rem_euclid`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let a: f64 = 7.0; -/// let b = 4.0; -/// assert_eq!(f64::rem_euclid(a, b), 3.0); -/// assert_eq!(f64::rem_euclid(-a, b), 1.0); -/// assert_eq!(f64::rem_euclid(a, -b), 3.0); -/// assert_eq!(f64::rem_euclid(-a, -b), 1.0); -/// // limitation due to round-off error -/// assert!(f64::rem_euclid(-f64::EPSILON, 3.0) != 0.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::rem_euclid`]: ../../std/primitive.f64.html#method.rem_euclid -#[inline] -#[doc(alias = "modulo", alias = "mod")] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn rem_euclid(x: f64, rhs: f64) -> f64 { - let r = x % rhs; - if r < 0.0 { r + rhs.abs() } else { r } -} + /// Experimental version of `mul_add` in `core`. See [`f64::mul_add`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// # // FIXME(#140515): mingw has an incorrect fma + /// # // https://sourceforge.net/p/mingw-w64/bugs/848/ + /// # #[cfg(all(target_os = "windows", target_env = "gnu", not(target_abi = "llvm")))] { + /// use core::f64; + /// + /// let m = 10.0_f64; + /// let x = 4.0_f64; + /// let b = 60.0_f64; + /// + /// assert_eq!(f64::math::mul_add(m, x, b), 100.0); + /// assert_eq!(m * x + b, 100.0); + /// + /// let one_plus_eps = 1.0_f64 + f64::EPSILON; + /// let one_minus_eps = 1.0_f64 - f64::EPSILON; + /// let minus_one = -1.0_f64; + /// + /// // The exact result (1 + eps) * (1 - eps) = 1 - eps * eps. + /// assert_eq!( + /// f64::math::mul_add(one_plus_eps, one_minus_eps, minus_one), + /// -f64::EPSILON * f64::EPSILON + /// ); + /// // Different rounding with the non-fused multiply and add. + /// assert_eq!(one_plus_eps * one_minus_eps + minus_one, 0.0); + /// # } + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::mul_add`]: ../../../std/primitive.f64.html#method.mul_add + #[inline] + #[doc(alias = "fma", alias = "fusedMultiplyAdd")] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn mul_add(x: f64, a: f64, b: f64) -> f64 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::fmaf64(x, a, b) } + } -/// Experimental version of `powi` in `core`. See [`f64::powi`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let x = 2.0_f64; -/// let abs_difference = (f64::powi(x, 2) - (x * x)).abs(); -/// assert!(abs_difference <= f64::EPSILON); -/// -/// assert_eq!(f64::powi(f64::NAN, 0), 1.0); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::powi`]: ../../std/primitive.f64.html#method.powi -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn powi(x: f64, n: i32) -> f64 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::powif64(x, n) } -} + /// Experimental version of `div_euclid` in `core`. See [`f64::div_euclid`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let a: f64 = 7.0; + /// let b = 4.0; + /// assert_eq!(f64::math::div_euclid(a, b), 1.0); // 7.0 > 4.0 * 1.0 + /// assert_eq!(f64::math::div_euclid(-a, b), -2.0); // -7.0 >= 4.0 * -2.0 + /// assert_eq!(f64::math::div_euclid(a, -b), -1.0); // 7.0 >= -4.0 * -1.0 + /// assert_eq!(f64::math::div_euclid(-a, -b), 2.0); // -7.0 >= -4.0 * 2.0 + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::div_euclid`]: ../../../std/primitive.f64.html#method.div_euclid + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn div_euclid(x: f64, rhs: f64) -> f64 { + let q = trunc(x / rhs); + if x % rhs < 0.0 { + return if rhs > 0.0 { q - 1.0 } else { q + 1.0 }; + } + q + } -/// Experimental version of `sqrt` in `core`. See [`f64::sqrt`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let positive = 4.0_f64; -/// let negative = -4.0_f64; -/// let negative_zero = -0.0_f64; -/// -/// assert_eq!(f64::sqrt(positive), 2.0); -/// assert!(f64::sqrt(negative).is_nan()); -/// assert_eq!(f64::sqrt(negative_zero), negative_zero); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::sqrt`]: ../../std/primitive.f64.html#method.sqrt -#[inline] -#[doc(alias = "squareRoot")] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn sqrt(x: f64) -> f64 { - // SAFETY: intrinsic with no preconditions - unsafe { intrinsics::sqrtf64(x) } -} + /// Experimental version of `rem_euclid` in `core`. See [`f64::rem_euclid`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let a: f64 = 7.0; + /// let b = 4.0; + /// assert_eq!(f64::math::rem_euclid(a, b), 3.0); + /// assert_eq!(f64::math::rem_euclid(-a, b), 1.0); + /// assert_eq!(f64::math::rem_euclid(a, -b), 3.0); + /// assert_eq!(f64::math::rem_euclid(-a, -b), 1.0); + /// // limitation due to round-off error + /// assert!(f64::math::rem_euclid(-f64::EPSILON, 3.0) != 0.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::rem_euclid`]: ../../../std/primitive.f64.html#method.rem_euclid + #[inline] + #[doc(alias = "modulo", alias = "mod")] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn rem_euclid(x: f64, rhs: f64) -> f64 { + let r = x % rhs; + if r < 0.0 { r + rhs.abs() } else { r } + } -/// Experimental version of `abs_sub` in `core`. See [`f64::abs_sub`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let x = 3.0_f64; -/// let y = -3.0_f64; -/// -/// let abs_difference_x = (f64::abs_sub(x, 1.0) - 2.0).abs(); -/// let abs_difference_y = (f64::abs_sub(y, 1.0) - 0.0).abs(); -/// -/// assert!(abs_difference_x < 1e-10); -/// assert!(abs_difference_y < 1e-10); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::abs_sub`]: ../../std/primitive.f64.html#method.abs_sub -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[deprecated( - since = "1.10.0", - note = "you probably meant `(self - other).abs()`: \ + /// Experimental version of `powi` in `core`. See [`f64::powi`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let x = 2.0_f64; + /// let abs_difference = (f64::math::powi(x, 2) - (x * x)).abs(); + /// assert!(abs_difference <= f64::EPSILON); + /// + /// assert_eq!(f64::math::powi(f64::NAN, 0), 1.0); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::powi`]: ../../../std/primitive.f64.html#method.powi + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn powi(x: f64, n: i32) -> f64 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::powif64(x, n) } + } + + /// Experimental version of `sqrt` in `core`. See [`f64::sqrt`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let positive = 4.0_f64; + /// let negative = -4.0_f64; + /// let negative_zero = -0.0_f64; + /// + /// assert_eq!(f64::math::sqrt(positive), 2.0); + /// assert!(f64::math::sqrt(negative).is_nan()); + /// assert_eq!(f64::math::sqrt(negative_zero), negative_zero); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::sqrt`]: ../../../std/primitive.f64.html#method.sqrt + #[inline] + #[doc(alias = "squareRoot")] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn sqrt(x: f64) -> f64 { + // SAFETY: intrinsic with no preconditions + unsafe { intrinsics::sqrtf64(x) } + } + + /// Experimental version of `abs_sub` in `core`. See [`f64::abs_sub`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let x = 3.0_f64; + /// let y = -3.0_f64; + /// + /// let abs_difference_x = (f64::math::abs_sub(x, 1.0) - 2.0).abs(); + /// let abs_difference_y = (f64::math::abs_sub(y, 1.0) - 0.0).abs(); + /// + /// assert!(abs_difference_x < 1e-10); + /// assert!(abs_difference_y < 1e-10); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::abs_sub`]: ../../../std/primitive.f64.html#method.abs_sub + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[deprecated( + since = "1.10.0", + note = "you probably meant `(self - other).abs()`: \ this operation is `(self - other).max(0.0)` \ except that `abs_sub` also propagates NaNs (also \ known as `fdim` in C). If you truly need the positive \ difference, consider using that expression or the C function \ `fdim`, depending on how you wish to handle NaN (please consider \ filing an issue describing your use-case too)." -)] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn abs_sub(x: f64, other: f64) -> f64 { - libm::fdim(x, other) -} + )] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn abs_sub(x: f64, other: f64) -> f64 { + libm::fdim(x, other) + } -/// Experimental version of `cbrt` in `core`. See [`f64::cbrt`] for details. -/// -/// # Examples -/// -/// ``` -/// #![feature(core_float_math)] -/// -/// use core::f64; -/// -/// let x = 8.0_f64; -/// -/// // x^(1/3) - 2 == 0 -/// let abs_difference = (f64::cbrt(x) - 2.0).abs(); -/// -/// assert!(abs_difference < 1e-10); -/// ``` -/// -/// _This standalone function is for testing only. It will be stabilized as an inherent method._ -/// -/// [`f64::cbrt`]: ../../std/primitive.f64.html#method.cbrt -#[inline] -#[unstable(feature = "core_float_math", issue = "137578")] -#[must_use = "method returns a new number and does not mutate the original value"] -pub fn cbrt(x: f64) -> f64 { - libm::cbrt(x) + /// Experimental version of `cbrt` in `core`. See [`f64::cbrt`] for details. + /// + /// # Examples + /// + /// ``` + /// #![feature(core_float_math)] + /// + /// use core::f64; + /// + /// let x = 8.0_f64; + /// + /// // x^(1/3) - 2 == 0 + /// let abs_difference = (f64::math::cbrt(x) - 2.0).abs(); + /// + /// assert!(abs_difference < 1e-10); + /// ``` + /// + /// _This standalone function is for testing only. + /// It will be stabilized as an inherent method._ + /// + /// [`f64::cbrt`]: ../../../std/primitive.f64.html#method.cbrt + #[inline] + #[unstable(feature = "core_float_math", issue = "137578")] + #[must_use = "method returns a new number and does not mutate the original value"] + pub fn cbrt(x: f64) -> f64 { + libm::cbrt(x) + } } diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 257424b355f..aad073cc8cd 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1419,7 +1419,7 @@ impl<Ptr: DerefMut> Pin<Ptr> { #[stable(feature = "pin_deref_mut", since = "1.84.0")] #[must_use = "`self` will be dropped if the result is not used"] #[inline(always)] - pub fn as_deref_mut(self: Pin<&mut Pin<Ptr>>) -> Pin<&mut Ptr::Target> { + pub fn as_deref_mut(self: Pin<&mut Self>) -> Pin<&mut Ptr::Target> { // SAFETY: What we're asserting here is that going from // // Pin<&mut Pin<Ptr>> diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 35089b4853d..f6109cafe86 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -66,6 +66,34 @@ impl<T: ?Sized> *const T { self as _ } + /// Try to cast to a pointer of another type by checking aligment. + /// + /// If the pointer is properly aligned to the target type, it will be + /// cast to the target type. Otherwise, `None` is returned. + /// + /// # Examples + /// + /// ```rust + /// #![feature(pointer_try_cast_aligned)] + /// + /// let aligned: *const u8 = 0x1000 as _; + /// + /// // i32 has at most 4-byte alignment, so this will succeed + /// assert!(aligned.try_cast_aligned::<i32>().is_some()); + /// + /// let unaligned: *const u8 = 0x1001 as _; + /// + /// // i32 has at least 2-byte alignment, so this will fail + /// assert!(unaligned.try_cast_aligned::<i32>().is_none()); + /// ``` + #[unstable(feature = "pointer_try_cast_aligned", issue = "141221")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub fn try_cast_aligned<U>(self) -> Option<*const U> { + if self.is_aligned_to(align_of::<U>()) { Some(self.cast()) } else { None } + } + /// Uses the address value in a new pointer of another type. /// /// This operation will ignore the address part of its `meta` operand and discard existing diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 9cf251742d4..2662a4fdc31 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -48,6 +48,34 @@ impl<T: ?Sized> *mut T { self as _ } + /// Try to cast to a pointer of another type by checking aligment. + /// + /// If the pointer is properly aligned to the target type, it will be + /// cast to the target type. Otherwise, `None` is returned. + /// + /// # Examples + /// + /// ```rust + /// #![feature(pointer_try_cast_aligned)] + /// + /// let aligned: *mut u8 = 0x1000 as _; + /// + /// // i32 has at most 4-byte alignment, so this will succeed + /// assert!(aligned.try_cast_aligned::<i32>().is_some()); + /// + /// let unaligned: *mut u8 = 0x1001 as _; + /// + /// // i32 has at least 2-byte alignment, so this will fail + /// assert!(unaligned.try_cast_aligned::<i32>().is_none()); + /// ``` + #[unstable(feature = "pointer_try_cast_aligned", issue = "141221")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub fn try_cast_aligned<U>(self) -> Option<*mut U> { + if self.is_aligned_to(align_of::<U>()) { Some(self.cast()) } else { None } + } + /// Uses the address value in a new pointer of another type. /// /// This operation will ignore the address part of its `meta` operand and discard existing diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 8b31328de04..bb344c6a0d3 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -490,6 +490,35 @@ impl<T: ?Sized> NonNull<T> { unsafe { NonNull { pointer: self.as_ptr() as *mut U } } } + /// Try to cast to a pointer of another type by checking aligment. + /// + /// If the pointer is properly aligned to the target type, it will be + /// cast to the target type. Otherwise, `None` is returned. + /// + /// # Examples + /// + /// ```rust + /// #![feature(pointer_try_cast_aligned)] + /// use std::ptr::NonNull; + /// + /// let aligned: NonNull<u8> = NonNull::new(0x1000 as _).unwrap(); + /// + /// // i32 has at most 4-byte alignment, so this will succeed + /// assert!(aligned.try_cast_aligned::<i32>().is_some()); + /// + /// let unaligned: NonNull<u8> = NonNull::new(0x1001 as _).unwrap(); + /// + /// // i32 has at least 2-byte alignment, so this will fail + /// assert!(unaligned.try_cast_aligned::<i32>().is_none()); + /// ``` + #[unstable(feature = "pointer_try_cast_aligned", issue = "141221")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub fn try_cast_aligned<U>(self) -> Option<NonNull<U>> { + if self.is_aligned_to(align_of::<U>()) { Some(self.cast()) } else { None } + } + /// Adds an offset to a pointer. /// /// `count` is in units of T; e.g., a `count` of 3 represents a pointer diff --git a/library/coretests/tests/floats/f32.rs b/library/coretests/tests/floats/f32.rs index 9b551643bae..36f1937bedf 100644 --- a/library/coretests/tests/floats/f32.rs +++ b/library/coretests/tests/floats/f32.rs @@ -215,88 +215,88 @@ fn test_classify() { #[test] fn test_floor() { - assert_approx_eq!(f32::floor(1.0f32), 1.0f32); - assert_approx_eq!(f32::floor(1.3f32), 1.0f32); - assert_approx_eq!(f32::floor(1.5f32), 1.0f32); - assert_approx_eq!(f32::floor(1.7f32), 1.0f32); - assert_approx_eq!(f32::floor(0.0f32), 0.0f32); - assert_approx_eq!(f32::floor(-0.0f32), -0.0f32); - assert_approx_eq!(f32::floor(-1.0f32), -1.0f32); - assert_approx_eq!(f32::floor(-1.3f32), -2.0f32); - assert_approx_eq!(f32::floor(-1.5f32), -2.0f32); - assert_approx_eq!(f32::floor(-1.7f32), -2.0f32); + assert_approx_eq!(f32::math::floor(1.0f32), 1.0f32); + assert_approx_eq!(f32::math::floor(1.3f32), 1.0f32); + assert_approx_eq!(f32::math::floor(1.5f32), 1.0f32); + assert_approx_eq!(f32::math::floor(1.7f32), 1.0f32); + assert_approx_eq!(f32::math::floor(0.0f32), 0.0f32); + assert_approx_eq!(f32::math::floor(-0.0f32), -0.0f32); + assert_approx_eq!(f32::math::floor(-1.0f32), -1.0f32); + assert_approx_eq!(f32::math::floor(-1.3f32), -2.0f32); + assert_approx_eq!(f32::math::floor(-1.5f32), -2.0f32); + assert_approx_eq!(f32::math::floor(-1.7f32), -2.0f32); } #[test] fn test_ceil() { - assert_approx_eq!(f32::ceil(1.0f32), 1.0f32); - assert_approx_eq!(f32::ceil(1.3f32), 2.0f32); - assert_approx_eq!(f32::ceil(1.5f32), 2.0f32); - assert_approx_eq!(f32::ceil(1.7f32), 2.0f32); - assert_approx_eq!(f32::ceil(0.0f32), 0.0f32); - assert_approx_eq!(f32::ceil(-0.0f32), -0.0f32); - assert_approx_eq!(f32::ceil(-1.0f32), -1.0f32); - assert_approx_eq!(f32::ceil(-1.3f32), -1.0f32); - assert_approx_eq!(f32::ceil(-1.5f32), -1.0f32); - assert_approx_eq!(f32::ceil(-1.7f32), -1.0f32); + assert_approx_eq!(f32::math::ceil(1.0f32), 1.0f32); + assert_approx_eq!(f32::math::ceil(1.3f32), 2.0f32); + assert_approx_eq!(f32::math::ceil(1.5f32), 2.0f32); + assert_approx_eq!(f32::math::ceil(1.7f32), 2.0f32); + assert_approx_eq!(f32::math::ceil(0.0f32), 0.0f32); + assert_approx_eq!(f32::math::ceil(-0.0f32), -0.0f32); + assert_approx_eq!(f32::math::ceil(-1.0f32), -1.0f32); + assert_approx_eq!(f32::math::ceil(-1.3f32), -1.0f32); + assert_approx_eq!(f32::math::ceil(-1.5f32), -1.0f32); + assert_approx_eq!(f32::math::ceil(-1.7f32), -1.0f32); } #[test] fn test_round() { - assert_approx_eq!(f32::round(2.5f32), 3.0f32); - assert_approx_eq!(f32::round(1.0f32), 1.0f32); - assert_approx_eq!(f32::round(1.3f32), 1.0f32); - assert_approx_eq!(f32::round(1.5f32), 2.0f32); - assert_approx_eq!(f32::round(1.7f32), 2.0f32); - assert_approx_eq!(f32::round(0.0f32), 0.0f32); - assert_approx_eq!(f32::round(-0.0f32), -0.0f32); - assert_approx_eq!(f32::round(-1.0f32), -1.0f32); - assert_approx_eq!(f32::round(-1.3f32), -1.0f32); - assert_approx_eq!(f32::round(-1.5f32), -2.0f32); - assert_approx_eq!(f32::round(-1.7f32), -2.0f32); + assert_approx_eq!(f32::math::round(2.5f32), 3.0f32); + assert_approx_eq!(f32::math::round(1.0f32), 1.0f32); + assert_approx_eq!(f32::math::round(1.3f32), 1.0f32); + assert_approx_eq!(f32::math::round(1.5f32), 2.0f32); + assert_approx_eq!(f32::math::round(1.7f32), 2.0f32); + assert_approx_eq!(f32::math::round(0.0f32), 0.0f32); + assert_approx_eq!(f32::math::round(-0.0f32), -0.0f32); + assert_approx_eq!(f32::math::round(-1.0f32), -1.0f32); + assert_approx_eq!(f32::math::round(-1.3f32), -1.0f32); + assert_approx_eq!(f32::math::round(-1.5f32), -2.0f32); + assert_approx_eq!(f32::math::round(-1.7f32), -2.0f32); } #[test] fn test_round_ties_even() { - assert_approx_eq!(f32::round_ties_even(2.5f32), 2.0f32); - assert_approx_eq!(f32::round_ties_even(1.0f32), 1.0f32); - assert_approx_eq!(f32::round_ties_even(1.3f32), 1.0f32); - assert_approx_eq!(f32::round_ties_even(1.5f32), 2.0f32); - assert_approx_eq!(f32::round_ties_even(1.7f32), 2.0f32); - assert_approx_eq!(f32::round_ties_even(0.0f32), 0.0f32); - assert_approx_eq!(f32::round_ties_even(-0.0f32), -0.0f32); - assert_approx_eq!(f32::round_ties_even(-1.0f32), -1.0f32); - assert_approx_eq!(f32::round_ties_even(-1.3f32), -1.0f32); - assert_approx_eq!(f32::round_ties_even(-1.5f32), -2.0f32); - assert_approx_eq!(f32::round_ties_even(-1.7f32), -2.0f32); + assert_approx_eq!(f32::math::round_ties_even(2.5f32), 2.0f32); + assert_approx_eq!(f32::math::round_ties_even(1.0f32), 1.0f32); + assert_approx_eq!(f32::math::round_ties_even(1.3f32), 1.0f32); + assert_approx_eq!(f32::math::round_ties_even(1.5f32), 2.0f32); + assert_approx_eq!(f32::math::round_ties_even(1.7f32), 2.0f32); + assert_approx_eq!(f32::math::round_ties_even(0.0f32), 0.0f32); + assert_approx_eq!(f32::math::round_ties_even(-0.0f32), -0.0f32); + assert_approx_eq!(f32::math::round_ties_even(-1.0f32), -1.0f32); + assert_approx_eq!(f32::math::round_ties_even(-1.3f32), -1.0f32); + assert_approx_eq!(f32::math::round_ties_even(-1.5f32), -2.0f32); + assert_approx_eq!(f32::math::round_ties_even(-1.7f32), -2.0f32); } #[test] fn test_trunc() { - assert_approx_eq!(f32::trunc(1.0f32), 1.0f32); - assert_approx_eq!(f32::trunc(1.3f32), 1.0f32); - assert_approx_eq!(f32::trunc(1.5f32), 1.0f32); - assert_approx_eq!(f32::trunc(1.7f32), 1.0f32); - assert_approx_eq!(f32::trunc(0.0f32), 0.0f32); - assert_approx_eq!(f32::trunc(-0.0f32), -0.0f32); - assert_approx_eq!(f32::trunc(-1.0f32), -1.0f32); - assert_approx_eq!(f32::trunc(-1.3f32), -1.0f32); - assert_approx_eq!(f32::trunc(-1.5f32), -1.0f32); - assert_approx_eq!(f32::trunc(-1.7f32), -1.0f32); + assert_approx_eq!(f32::math::trunc(1.0f32), 1.0f32); + assert_approx_eq!(f32::math::trunc(1.3f32), 1.0f32); + assert_approx_eq!(f32::math::trunc(1.5f32), 1.0f32); + assert_approx_eq!(f32::math::trunc(1.7f32), 1.0f32); + assert_approx_eq!(f32::math::trunc(0.0f32), 0.0f32); + assert_approx_eq!(f32::math::trunc(-0.0f32), -0.0f32); + assert_approx_eq!(f32::math::trunc(-1.0f32), -1.0f32); + assert_approx_eq!(f32::math::trunc(-1.3f32), -1.0f32); + assert_approx_eq!(f32::math::trunc(-1.5f32), -1.0f32); + assert_approx_eq!(f32::math::trunc(-1.7f32), -1.0f32); } #[test] fn test_fract() { - assert_approx_eq!(f32::fract(1.0f32), 0.0f32); - assert_approx_eq!(f32::fract(1.3f32), 0.3f32); - assert_approx_eq!(f32::fract(1.5f32), 0.5f32); - assert_approx_eq!(f32::fract(1.7f32), 0.7f32); - assert_approx_eq!(f32::fract(0.0f32), 0.0f32); - assert_approx_eq!(f32::fract(-0.0f32), -0.0f32); - assert_approx_eq!(f32::fract(-1.0f32), -0.0f32); - assert_approx_eq!(f32::fract(-1.3f32), -0.3f32); - assert_approx_eq!(f32::fract(-1.5f32), -0.5f32); - assert_approx_eq!(f32::fract(-1.7f32), -0.7f32); + assert_approx_eq!(f32::math::fract(1.0f32), 0.0f32); + assert_approx_eq!(f32::math::fract(1.3f32), 0.3f32); + assert_approx_eq!(f32::math::fract(1.5f32), 0.5f32); + assert_approx_eq!(f32::math::fract(1.7f32), 0.7f32); + assert_approx_eq!(f32::math::fract(0.0f32), 0.0f32); + assert_approx_eq!(f32::math::fract(-0.0f32), -0.0f32); + assert_approx_eq!(f32::math::fract(-1.0f32), -0.0f32); + assert_approx_eq!(f32::math::fract(-1.3f32), -0.3f32); + assert_approx_eq!(f32::math::fract(-1.5f32), -0.5f32); + assert_approx_eq!(f32::math::fract(-1.7f32), -0.7f32); } #[test] @@ -417,15 +417,15 @@ fn test_mul_add() { let nan: f32 = f32::NAN; let inf: f32 = f32::INFINITY; let neg_inf: f32 = f32::NEG_INFINITY; - assert_approx_eq!(f32::mul_add(12.3f32, 4.5, 6.7), 62.05); - assert_approx_eq!(f32::mul_add(-12.3f32, -4.5, -6.7), 48.65); - assert_approx_eq!(f32::mul_add(0.0f32, 8.9, 1.2), 1.2); - assert_approx_eq!(f32::mul_add(3.4f32, -0.0, 5.6), 5.6); - assert!(f32::mul_add(nan, 7.8, 9.0).is_nan()); - assert_eq!(f32::mul_add(inf, 7.8, 9.0), inf); - assert_eq!(f32::mul_add(neg_inf, 7.8, 9.0), neg_inf); - assert_eq!(f32::mul_add(8.9f32, inf, 3.2), inf); - assert_eq!(f32::mul_add(-3.2f32, 2.4, neg_inf), neg_inf); + assert_approx_eq!(f32::math::mul_add(12.3f32, 4.5, 6.7), 62.05); + assert_approx_eq!(f32::math::mul_add(-12.3f32, -4.5, -6.7), 48.65); + assert_approx_eq!(f32::math::mul_add(0.0f32, 8.9, 1.2), 1.2); + assert_approx_eq!(f32::math::mul_add(3.4f32, -0.0, 5.6), 5.6); + assert!(f32::math::mul_add(nan, 7.8, 9.0).is_nan()); + assert_eq!(f32::math::mul_add(inf, 7.8, 9.0), inf); + assert_eq!(f32::math::mul_add(neg_inf, 7.8, 9.0), neg_inf); + assert_eq!(f32::math::mul_add(8.9f32, inf, 3.2), inf); + assert_eq!(f32::math::mul_add(-3.2f32, 2.4, neg_inf), neg_inf); } #[test] diff --git a/library/coretests/tests/floats/f64.rs b/library/coretests/tests/floats/f64.rs index 988108371d7..97051998353 100644 --- a/library/coretests/tests/floats/f64.rs +++ b/library/coretests/tests/floats/f64.rs @@ -1,5 +1,6 @@ -use std::f64::consts; -use std::num::FpCategory as Fp; +use core::f64; +use core::f64::consts; +use core::num::FpCategory as Fp; /// Smallest number const TINY_BITS: u64 = 0x1; @@ -201,88 +202,88 @@ fn test_classify() { #[test] fn test_floor() { - assert_approx_eq!(f64::floor(1.0f64), 1.0f64); - assert_approx_eq!(f64::floor(1.3f64), 1.0f64); - assert_approx_eq!(f64::floor(1.5f64), 1.0f64); - assert_approx_eq!(f64::floor(1.7f64), 1.0f64); - assert_approx_eq!(f64::floor(0.0f64), 0.0f64); - assert_approx_eq!(f64::floor(-0.0f64), -0.0f64); - assert_approx_eq!(f64::floor(-1.0f64), -1.0f64); - assert_approx_eq!(f64::floor(-1.3f64), -2.0f64); - assert_approx_eq!(f64::floor(-1.5f64), -2.0f64); - assert_approx_eq!(f64::floor(-1.7f64), -2.0f64); + assert_approx_eq!(f64::math::floor(1.0f64), 1.0f64); + assert_approx_eq!(f64::math::floor(1.3f64), 1.0f64); + assert_approx_eq!(f64::math::floor(1.5f64), 1.0f64); + assert_approx_eq!(f64::math::floor(1.7f64), 1.0f64); + assert_approx_eq!(f64::math::floor(0.0f64), 0.0f64); + assert_approx_eq!(f64::math::floor(-0.0f64), -0.0f64); + assert_approx_eq!(f64::math::floor(-1.0f64), -1.0f64); + assert_approx_eq!(f64::math::floor(-1.3f64), -2.0f64); + assert_approx_eq!(f64::math::floor(-1.5f64), -2.0f64); + assert_approx_eq!(f64::math::floor(-1.7f64), -2.0f64); } #[test] fn test_ceil() { - assert_approx_eq!(f64::ceil(1.0f64), 1.0f64); - assert_approx_eq!(f64::ceil(1.3f64), 2.0f64); - assert_approx_eq!(f64::ceil(1.5f64), 2.0f64); - assert_approx_eq!(f64::ceil(1.7f64), 2.0f64); - assert_approx_eq!(f64::ceil(0.0f64), 0.0f64); - assert_approx_eq!(f64::ceil(-0.0f64), -0.0f64); - assert_approx_eq!(f64::ceil(-1.0f64), -1.0f64); - assert_approx_eq!(f64::ceil(-1.3f64), -1.0f64); - assert_approx_eq!(f64::ceil(-1.5f64), -1.0f64); - assert_approx_eq!(f64::ceil(-1.7f64), -1.0f64); + assert_approx_eq!(f64::math::ceil(1.0f64), 1.0f64); + assert_approx_eq!(f64::math::ceil(1.3f64), 2.0f64); + assert_approx_eq!(f64::math::ceil(1.5f64), 2.0f64); + assert_approx_eq!(f64::math::ceil(1.7f64), 2.0f64); + assert_approx_eq!(f64::math::ceil(0.0f64), 0.0f64); + assert_approx_eq!(f64::math::ceil(-0.0f64), -0.0f64); + assert_approx_eq!(f64::math::ceil(-1.0f64), -1.0f64); + assert_approx_eq!(f64::math::ceil(-1.3f64), -1.0f64); + assert_approx_eq!(f64::math::ceil(-1.5f64), -1.0f64); + assert_approx_eq!(f64::math::ceil(-1.7f64), -1.0f64); } #[test] fn test_round() { - assert_approx_eq!(f64::round(2.5f64), 3.0f64); - assert_approx_eq!(f64::round(1.0f64), 1.0f64); - assert_approx_eq!(f64::round(1.3f64), 1.0f64); - assert_approx_eq!(f64::round(1.5f64), 2.0f64); - assert_approx_eq!(f64::round(1.7f64), 2.0f64); - assert_approx_eq!(f64::round(0.0f64), 0.0f64); - assert_approx_eq!(f64::round(-0.0f64), -0.0f64); - assert_approx_eq!(f64::round(-1.0f64), -1.0f64); - assert_approx_eq!(f64::round(-1.3f64), -1.0f64); - assert_approx_eq!(f64::round(-1.5f64), -2.0f64); - assert_approx_eq!(f64::round(-1.7f64), -2.0f64); + assert_approx_eq!(f64::math::round(2.5f64), 3.0f64); + assert_approx_eq!(f64::math::round(1.0f64), 1.0f64); + assert_approx_eq!(f64::math::round(1.3f64), 1.0f64); + assert_approx_eq!(f64::math::round(1.5f64), 2.0f64); + assert_approx_eq!(f64::math::round(1.7f64), 2.0f64); + assert_approx_eq!(f64::math::round(0.0f64), 0.0f64); + assert_approx_eq!(f64::math::round(-0.0f64), -0.0f64); + assert_approx_eq!(f64::math::round(-1.0f64), -1.0f64); + assert_approx_eq!(f64::math::round(-1.3f64), -1.0f64); + assert_approx_eq!(f64::math::round(-1.5f64), -2.0f64); + assert_approx_eq!(f64::math::round(-1.7f64), -2.0f64); } #[test] fn test_round_ties_even() { - assert_approx_eq!(f64::round_ties_even(2.5f64), 2.0f64); - assert_approx_eq!(f64::round_ties_even(1.0f64), 1.0f64); - assert_approx_eq!(f64::round_ties_even(1.3f64), 1.0f64); - assert_approx_eq!(f64::round_ties_even(1.5f64), 2.0f64); - assert_approx_eq!(f64::round_ties_even(1.7f64), 2.0f64); - assert_approx_eq!(f64::round_ties_even(0.0f64), 0.0f64); - assert_approx_eq!(f64::round_ties_even(-0.0f64), -0.0f64); - assert_approx_eq!(f64::round_ties_even(-1.0f64), -1.0f64); - assert_approx_eq!(f64::round_ties_even(-1.3f64), -1.0f64); - assert_approx_eq!(f64::round_ties_even(-1.5f64), -2.0f64); - assert_approx_eq!(f64::round_ties_even(-1.7f64), -2.0f64); + assert_approx_eq!(f64::math::round_ties_even(2.5f64), 2.0f64); + assert_approx_eq!(f64::math::round_ties_even(1.0f64), 1.0f64); + assert_approx_eq!(f64::math::round_ties_even(1.3f64), 1.0f64); + assert_approx_eq!(f64::math::round_ties_even(1.5f64), 2.0f64); + assert_approx_eq!(f64::math::round_ties_even(1.7f64), 2.0f64); + assert_approx_eq!(f64::math::round_ties_even(0.0f64), 0.0f64); + assert_approx_eq!(f64::math::round_ties_even(-0.0f64), -0.0f64); + assert_approx_eq!(f64::math::round_ties_even(-1.0f64), -1.0f64); + assert_approx_eq!(f64::math::round_ties_even(-1.3f64), -1.0f64); + assert_approx_eq!(f64::math::round_ties_even(-1.5f64), -2.0f64); + assert_approx_eq!(f64::math::round_ties_even(-1.7f64), -2.0f64); } #[test] fn test_trunc() { - assert_approx_eq!(f64::trunc(1.0f64), 1.0f64); - assert_approx_eq!(f64::trunc(1.3f64), 1.0f64); - assert_approx_eq!(f64::trunc(1.5f64), 1.0f64); - assert_approx_eq!(f64::trunc(1.7f64), 1.0f64); - assert_approx_eq!(f64::trunc(0.0f64), 0.0f64); - assert_approx_eq!(f64::trunc(-0.0f64), -0.0f64); - assert_approx_eq!(f64::trunc(-1.0f64), -1.0f64); - assert_approx_eq!(f64::trunc(-1.3f64), -1.0f64); - assert_approx_eq!(f64::trunc(-1.5f64), -1.0f64); - assert_approx_eq!(f64::trunc(-1.7f64), -1.0f64); + assert_approx_eq!(f64::math::trunc(1.0f64), 1.0f64); + assert_approx_eq!(f64::math::trunc(1.3f64), 1.0f64); + assert_approx_eq!(f64::math::trunc(1.5f64), 1.0f64); + assert_approx_eq!(f64::math::trunc(1.7f64), 1.0f64); + assert_approx_eq!(f64::math::trunc(0.0f64), 0.0f64); + assert_approx_eq!(f64::math::trunc(-0.0f64), -0.0f64); + assert_approx_eq!(f64::math::trunc(-1.0f64), -1.0f64); + assert_approx_eq!(f64::math::trunc(-1.3f64), -1.0f64); + assert_approx_eq!(f64::math::trunc(-1.5f64), -1.0f64); + assert_approx_eq!(f64::math::trunc(-1.7f64), -1.0f64); } #[test] fn test_fract() { - assert_approx_eq!(f64::fract(1.0f64), 0.0f64); - assert_approx_eq!(f64::fract(1.3f64), 0.3f64); - assert_approx_eq!(f64::fract(1.5f64), 0.5f64); - assert_approx_eq!(f64::fract(1.7f64), 0.7f64); - assert_approx_eq!(f64::fract(0.0f64), 0.0f64); - assert_approx_eq!(f64::fract(-0.0f64), -0.0f64); - assert_approx_eq!(f64::fract(-1.0f64), -0.0f64); - assert_approx_eq!(f64::fract(-1.3f64), -0.3f64); - assert_approx_eq!(f64::fract(-1.5f64), -0.5f64); - assert_approx_eq!(f64::fract(-1.7f64), -0.7f64); + assert_approx_eq!(f64::math::fract(1.0f64), 0.0f64); + assert_approx_eq!(f64::math::fract(1.3f64), 0.3f64); + assert_approx_eq!(f64::math::fract(1.5f64), 0.5f64); + assert_approx_eq!(f64::math::fract(1.7f64), 0.7f64); + assert_approx_eq!(f64::math::fract(0.0f64), 0.0f64); + assert_approx_eq!(f64::math::fract(-0.0f64), -0.0f64); + assert_approx_eq!(f64::math::fract(-1.0f64), -0.0f64); + assert_approx_eq!(f64::math::fract(-1.3f64), -0.3f64); + assert_approx_eq!(f64::math::fract(-1.5f64), -0.5f64); + assert_approx_eq!(f64::math::fract(-1.7f64), -0.7f64); } #[test] diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs index 94140d01d8b..5210e75ec45 100644 --- a/library/std/src/f32.rs +++ b/library/std/src/f32.rs @@ -46,7 +46,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn floor(self) -> f32 { - core::f32::floor(self) + core::f32::math::floor(self) } /// Returns the smallest integer greater than or equal to `self`. @@ -68,7 +68,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ceil(self) -> f32 { - core::f32::ceil(self) + core::f32::math::ceil(self) } /// Returns the nearest integer to `self`. If a value is half-way between two @@ -96,7 +96,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn round(self) -> f32 { - core::f32::round(self) + core::f32::math::round(self) } /// Returns the nearest integer to a number. Rounds half-way cases to the number @@ -122,7 +122,7 @@ impl f32 { #[stable(feature = "round_ties_even", since = "1.77.0")] #[inline] pub fn round_ties_even(self) -> f32 { - core::f32::round_ties_even(self) + core::f32::math::round_ties_even(self) } /// Returns the integer part of `self`. @@ -147,7 +147,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn trunc(self) -> f32 { - core::f32::trunc(self) + core::f32::math::trunc(self) } /// Returns the fractional part of `self`. @@ -170,7 +170,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn fract(self) -> f32 { - core::f32::fract(self) + core::f32::math::fract(self) } /// Fused multiply-add. Computes `(self * a) + b` with only one rounding @@ -212,7 +212,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn mul_add(self, a: f32, b: f32) -> f32 { - core::f32::mul_add(self, a, b) + core::f32::math::mul_add(self, a, b) } /// Calculates Euclidean division, the matching method for `rem_euclid`. @@ -242,7 +242,7 @@ impl f32 { #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] pub fn div_euclid(self, rhs: f32) -> f32 { - core::f32::div_euclid(self, rhs) + core::f32::math::div_euclid(self, rhs) } /// Calculates the least nonnegative remainder of `self (mod rhs)`. @@ -279,7 +279,7 @@ impl f32 { #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] pub fn rem_euclid(self, rhs: f32) -> f32 { - core::f32::rem_euclid(self, rhs) + core::f32::math::rem_euclid(self, rhs) } /// Raises a number to an integer power. @@ -307,7 +307,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn powi(self, n: i32) -> f32 { - core::f32::powi(self, n) + core::f32::math::powi(self, n) } /// Raises a number to a floating point power. @@ -362,7 +362,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sqrt(self) -> f32 { - core::f32::sqrt(self) + core::f32::math::sqrt(self) } /// Returns `e^(self)`, (the exponential function). @@ -595,7 +595,7 @@ impl f32 { )] pub fn abs_sub(self, other: f32) -> f32 { #[allow(deprecated)] - core::f32::abs_sub(self, other) + core::f32::math::abs_sub(self, other) } /// Returns the cube root of a number. @@ -622,7 +622,7 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cbrt(self) -> f32 { - core::f32::cbrt(self) + core::f32::math::cbrt(self) } /// Compute the distance between the origin and a point (`x`, `y`) on the diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs index 051061ae605..f837800d663 100644 --- a/library/std/src/f64.rs +++ b/library/std/src/f64.rs @@ -46,7 +46,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn floor(self) -> f64 { - core::f64::floor(self) + core::f64::math::floor(self) } /// Returns the smallest integer greater than or equal to `self`. @@ -68,7 +68,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn ceil(self) -> f64 { - core::f64::ceil(self) + core::f64::math::ceil(self) } /// Returns the nearest integer to `self`. If a value is half-way between two @@ -96,7 +96,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn round(self) -> f64 { - core::f64::round(self) + core::f64::math::round(self) } /// Returns the nearest integer to a number. Rounds half-way cases to the number @@ -122,7 +122,7 @@ impl f64 { #[stable(feature = "round_ties_even", since = "1.77.0")] #[inline] pub fn round_ties_even(self) -> f64 { - core::f64::round_ties_even(self) + core::f64::math::round_ties_even(self) } /// Returns the integer part of `self`. @@ -147,7 +147,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn trunc(self) -> f64 { - core::f64::trunc(self) + core::f64::math::trunc(self) } /// Returns the fractional part of `self`. @@ -170,7 +170,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn fract(self) -> f64 { - core::f64::fract(self) + core::f64::math::fract(self) } /// Fused multiply-add. Computes `(self * a) + b` with only one rounding @@ -212,7 +212,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn mul_add(self, a: f64, b: f64) -> f64 { - core::f64::mul_add(self, a, b) + core::f64::math::mul_add(self, a, b) } /// Calculates Euclidean division, the matching method for `rem_euclid`. @@ -242,7 +242,7 @@ impl f64 { #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] pub fn div_euclid(self, rhs: f64) -> f64 { - core::f64::div_euclid(self, rhs) + core::f64::math::div_euclid(self, rhs) } /// Calculates the least nonnegative remainder of `self (mod rhs)`. @@ -279,7 +279,7 @@ impl f64 { #[inline] #[stable(feature = "euclidean_division", since = "1.38.0")] pub fn rem_euclid(self, rhs: f64) -> f64 { - core::f64::rem_euclid(self, rhs) + core::f64::math::rem_euclid(self, rhs) } /// Raises a number to an integer power. @@ -307,7 +307,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn powi(self, n: i32) -> f64 { - core::f64::powi(self, n) + core::f64::math::powi(self, n) } /// Raises a number to a floating point power. @@ -362,7 +362,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn sqrt(self) -> f64 { - core::f64::sqrt(self) + core::f64::math::sqrt(self) } /// Returns `e^(self)`, (the exponential function). @@ -595,7 +595,7 @@ impl f64 { )] pub fn abs_sub(self, other: f64) -> f64 { #[allow(deprecated)] - core::f64::abs_sub(self, other) + core::f64::math::abs_sub(self, other) } /// Returns the cube root of a number. @@ -622,7 +622,7 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn cbrt(self) -> f64 { - core::f64::cbrt(self) + core::f64::math::cbrt(self) } /// Compute the distance between the origin and a point (`x`, `y`) on the diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 72bdf03ee61..ead48775127 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -1040,7 +1040,7 @@ impl OsStr { /// Converts a <code>[Box]<[OsStr]></code> into an [`OsString`] without copying or allocating. #[stable(feature = "into_boxed_os_str", since = "1.20.0")] #[must_use = "`self` will be dropped if the result is not used"] - pub fn into_os_string(self: Box<OsStr>) -> OsString { + pub fn into_os_string(self: Box<Self>) -> OsString { let boxed = unsafe { Box::from_raw(Box::into_raw(self) as *mut Slice) }; OsString { inner: Buf::from_box(boxed) } } diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 1a4a7aa7448..7959c633858 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -3163,7 +3163,7 @@ impl Path { /// allocating. #[stable(feature = "into_boxed_path", since = "1.20.0")] #[must_use = "`self` will be dropped if the result is not used"] - pub fn into_path_buf(self: Box<Path>) -> PathBuf { + pub fn into_path_buf(self: Box<Self>) -> PathBuf { let rw = Box::into_raw(self) as *mut OsStr; let inner = unsafe { Box::from_raw(rw) }; PathBuf { inner: OsString::from(inner) } diff --git a/src/ci/docker/host-x86_64/dist-arm-linux-gnueabi/Dockerfile b/src/ci/docker/host-x86_64/dist-arm-linux-gnueabi/Dockerfile new file mode 100644 index 00000000000..996dacd7124 --- /dev/null +++ b/src/ci/docker/host-x86_64/dist-arm-linux-gnueabi/Dockerfile @@ -0,0 +1,35 @@ +FROM ghcr.io/rust-lang/ubuntu:22.04 + +COPY scripts/cross-apt-packages.sh /scripts/ +RUN sh /scripts/cross-apt-packages.sh + +COPY scripts/crosstool-ng.sh /scripts/ +RUN sh /scripts/crosstool-ng.sh + +WORKDIR /build + +COPY scripts/rustbuild-setup.sh /scripts/ +RUN sh /scripts/rustbuild-setup.sh +WORKDIR /tmp + +COPY scripts/crosstool-ng-build.sh /scripts/ +COPY host-x86_64/dist-arm-linux-gnueabi/arm-linux-gnueabi.defconfig /tmp/crosstool.defconfig +RUN /scripts/crosstool-ng-build.sh + +COPY scripts/sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +ENV PATH=$PATH:/x-tools/arm-unknown-linux-gnueabi/bin + +ENV CC_arm_unknown_linux_gnueabi=arm-unknown-linux-gnueabi-gcc \ + AR_arm_unknown_linux_gnueabi=arm-unknown-linux-gnueabi-ar \ + CXX_arm_unknown_linux_gnueabi=arm-unknown-linux-gnueabi-g++ + +ENV HOSTS=arm-unknown-linux-gnueabi + +ENV RUST_CONFIGURE_ARGS \ + --enable-full-tools \ + --disable-docs \ + --enable-sanitizers \ + --enable-profiler +ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS diff --git a/src/ci/docker/host-x86_64/dist-arm-linux/arm-linux-gnueabi.defconfig b/src/ci/docker/host-x86_64/dist-arm-linux-gnueabi/arm-linux-gnueabi.defconfig index e7afdbe9d4d..e7afdbe9d4d 100644 --- a/src/ci/docker/host-x86_64/dist-arm-linux/arm-linux-gnueabi.defconfig +++ b/src/ci/docker/host-x86_64/dist-arm-linux-gnueabi/arm-linux-gnueabi.defconfig diff --git a/src/ci/docker/host-x86_64/dist-arm-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-arm-linux-musl/Dockerfile index 3795859f308..6e055cd2bd5 100644 --- a/src/ci/docker/host-x86_64/dist-arm-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-arm-linux-musl/Dockerfile @@ -19,19 +19,13 @@ RUN sh /scripts/rustbuild-setup.sh WORKDIR /tmp COPY scripts/crosstool-ng-build.sh /scripts/ -COPY host-x86_64/dist-arm-linux/arm-linux-gnueabi.defconfig /tmp/crosstool.defconfig +COPY host-x86_64/dist-arm-linux-musl/arm-linux-musl.defconfig /tmp/crosstool.defconfig RUN /scripts/crosstool-ng-build.sh COPY scripts/sccache.sh /scripts/ RUN sh /scripts/sccache.sh -ENV PATH=$PATH:/x-tools/arm-unknown-linux-gnueabi/bin - -ENV CC_arm_unknown_linux_gnueabi=arm-unknown-linux-gnueabi-gcc \ - AR_arm_unknown_linux_gnueabi=arm-unknown-linux-gnueabi-ar \ - CXX_arm_unknown_linux_gnueabi=arm-unknown-linux-gnueabi-g++ - -ENV HOSTS=arm-unknown-linux-gnueabi,aarch64-unknown-linux-musl +ENV HOSTS=aarch64-unknown-linux-musl ENV RUST_CONFIGURE_ARGS \ --enable-full-tools \ diff --git a/src/ci/docker/host-x86_64/dist-arm-linux-musl/arm-linux-musl.defconfig b/src/ci/docker/host-x86_64/dist-arm-linux-musl/arm-linux-musl.defconfig new file mode 100644 index 00000000000..e7afdbe9d4d --- /dev/null +++ b/src/ci/docker/host-x86_64/dist-arm-linux-musl/arm-linux-musl.defconfig @@ -0,0 +1,13 @@ +CT_CONFIG_VERSION="4" +CT_PREFIX_DIR="/x-tools/${CT_TARGET}" +CT_USE_MIRROR=y +CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc" +CT_ARCH_ARM=y +CT_ARCH_ARCH="armv6" +CT_ARCH_FLOAT_SW=y +CT_KERNEL_LINUX=y +CT_LINUX_V_3_2=y +CT_BINUTILS_V_2_32=y +CT_GLIBC_V_2_17=y +CT_GCC_V_8=y +CT_CC_LANG_CXX=y diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/Dockerfile b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/Dockerfile new file mode 100644 index 00000000000..d2f1b9400ad --- /dev/null +++ b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/Dockerfile @@ -0,0 +1,41 @@ +FROM ubuntu:22.04 + +COPY scripts/cross-apt-packages.sh /scripts/ +RUN sh /scripts/cross-apt-packages.sh + +COPY scripts/crosstool-ng.sh /scripts/ +RUN sh /scripts/crosstool-ng.sh + +COPY scripts/rustbuild-setup.sh /scripts/ +RUN sh /scripts/rustbuild-setup.sh + +WORKDIR /tmp + +COPY scripts/crosstool-ng-build.sh /scripts/ +COPY host-x86_64/dist-powerpc64le-linux-gnu/powerpc64le-unknown-linux-gnu.defconfig /tmp/crosstool.defconfig +RUN /scripts/crosstool-ng-build.sh + +WORKDIR /build + +RUN apt-get install -y --no-install-recommends rpm2cpio cpio +COPY scripts/shared.sh scripts/build-powerpc64le-toolchain.sh /build/ +RUN ./build-powerpc64le-toolchain.sh + +COPY scripts/sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +ENV \ + AR_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-ar \ + CC_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-gcc \ + CXX_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-g++ + +ENV HOSTS=powerpc64le-unknown-linux-gnu + +ENV RUST_CONFIGURE_ARGS \ + --enable-extended \ + --enable-full-tools \ + --enable-profiler \ + --enable-sanitizers \ + --disable-docs + +ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/powerpc64le-unknown-linux-gnu.defconfig b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/powerpc64le-unknown-linux-gnu.defconfig new file mode 100644 index 00000000000..363e5850894 --- /dev/null +++ b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/powerpc64le-unknown-linux-gnu.defconfig @@ -0,0 +1,14 @@ +CT_CONFIG_VERSION="4" +CT_EXPERIMENTAL=y +CT_PREFIX_DIR="/x-tools/${CT_TARGET}" +CT_USE_MIRROR=y +CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc" +CT_ARCH_POWERPC=y +CT_ARCH_LE=y +CT_ARCH_64=y +# CT_DEMULTILIB is not set +CT_ARCH_ARCH="powerpc64le" +CT_KERNEL_LINUX=y +CT_LINUX_V_4_19=y +CT_CC_LANG_CXX=y +CT_GETTEXT_NEEDED=y diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-musl/Dockerfile index cb20f43cff7..f045b2a5f65 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-musl/Dockerfile @@ -12,13 +12,13 @@ RUN sh /scripts/rustbuild-setup.sh WORKDIR /tmp COPY scripts/crosstool-ng-build.sh /scripts/ -COPY host-x86_64/dist-powerpc64le-linux/powerpc64le-unknown-linux-musl.defconfig /tmp/crosstool.defconfig +COPY host-x86_64/dist-powerpc64le-linux-musl/powerpc64le-unknown-linux-musl.defconfig /tmp/crosstool.defconfig RUN /scripts/crosstool-ng-build.sh WORKDIR /build RUN apt-get install -y --no-install-recommends rpm2cpio cpio -COPY scripts/shared.sh host-x86_64/dist-powerpc64le-linux/build-powerpc64le-toolchain.sh /build/ +COPY scripts/shared.sh scripts/build-powerpc64le-toolchain.sh /build/ RUN ./build-powerpc64le-toolchain.sh COPY scripts/sccache.sh /scripts/ @@ -27,14 +27,11 @@ RUN sh /scripts/sccache.sh ENV PATH=$PATH:/x-tools/powerpc64le-unknown-linux-musl/bin ENV \ - AR_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-ar \ - CC_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-gcc \ - CXX_powerpc64le_unknown_linux_gnu=powerpc64le-linux-gnu-g++ \ AR_powerpc64le_unknown_linux_musl=powerpc64le-unknown-linux-musl-ar \ CC_powerpc64le_unknown_linux_musl=powerpc64le-unknown-linux-musl-gcc \ CXX_powerpc64le_unknown_linux_musl=powerpc64le-unknown-linux-musl-g++ -ENV HOSTS=powerpc64le-unknown-linux-gnu,powerpc64le-unknown-linux-musl +ENV HOSTS=powerpc64le-unknown-linux-musl ENV RUST_CONFIGURE_ARGS \ --enable-extended \ diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/powerpc64le-unknown-linux-musl.defconfig b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-musl/powerpc64le-unknown-linux-musl.defconfig index c6cde30b2a4..c6cde30b2a4 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/powerpc64le-unknown-linux-musl.defconfig +++ b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-musl/powerpc64le-unknown-linux-musl.defconfig diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/build-powerpc64le-toolchain.sh b/src/ci/docker/scripts/build-powerpc64le-toolchain.sh index 56ea28b6ca5..56ea28b6ca5 100755 --- a/src/ci/docker/host-x86_64/dist-powerpc64le-linux/build-powerpc64le-toolchain.sh +++ b/src/ci/docker/scripts/build-powerpc64le-toolchain.sh diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 42ad5acbdac..005007bbccd 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -10,11 +10,6 @@ runners: free_disk: true <<: *base-job - # Large runner used mainly for its bigger disk capacity - - &job-linux-4c-largedisk - os: ubuntu-24.04-4core-16gb - <<: *base-job - - &job-linux-8c os: ubuntu-24.04-8core-32gb <<: *base-job @@ -167,8 +162,11 @@ auto: - name: dist-android <<: *job-linux-4c - - name: dist-arm-linux - <<: *job-linux-8c-codebuild + - name: dist-arm-linux-gnueabi + <<: *job-linux-4c + + - name: dist-arm-linux-musl + <<: *job-linux-4c - name: dist-armhf-linux <<: *job-linux-4c @@ -203,8 +201,11 @@ auto: - name: dist-powerpc64-linux <<: *job-linux-4c - - name: dist-powerpc64le-linux - <<: *job-linux-4c-largedisk + - name: dist-powerpc64le-linux-gnu + <<: *job-linux-4c + + - name: dist-powerpc64le-linux-musl + <<: *job-linux-4c - name: dist-riscv64-linux <<: *job-linux-4c diff --git a/src/ci/scripts/install-clang.sh b/src/ci/scripts/install-clang.sh index 5522095e304..a9528e92915 100755 --- a/src/ci/scripts/install-clang.sh +++ b/src/ci/scripts/install-clang.sh @@ -10,8 +10,8 @@ IFS=$'\n\t' source "$(cd "$(dirname "$0")" && pwd)/../shared.sh" # Update both macOS's and Windows's tarballs when bumping the version here. -# Try to keep this in sync with src/ci/docker/host-x86_64/dist-x86_64-linux/build-clang.sh -LLVM_VERSION="18.1.4" +# Try to keep this in sync with src/ci/docker/scripts/build-clang.sh +LLVM_VERSION="20.1.3" if isMacOS; then # FIXME: This is the latest pre-built version of LLVM that's available for diff --git a/src/doc/rustc-dev-guide/rust-version b/src/doc/rustc-dev-guide/rust-version index 5e4266f61da..0d889a5d5b9 100644 --- a/src/doc/rustc-dev-guide/rust-version +++ b/src/doc/rustc-dev-guide/rust-version @@ -1 +1 @@ -414482f6a0d4e7290f614300581a0b55442552a3 +e42bbfe1f7c26f8760a99c4b1f27d33aba1040bb diff --git a/src/doc/rustc-dev-guide/src/SUMMARY.md b/src/doc/rustc-dev-guide/src/SUMMARY.md index 31119496e75..a7b76233d19 100644 --- a/src/doc/rustc-dev-guide/src/SUMMARY.md +++ b/src/doc/rustc-dev-guide/src/SUMMARY.md @@ -134,9 +134,9 @@ - [Command-line arguments](./cli.md) - [rustc_driver and rustc_interface](./rustc-driver/intro.md) + - [Remarks on perma-unstable features](./rustc-driver/remarks-on-perma-unstable-features.md) - [Example: Type checking](./rustc-driver/interacting-with-the-ast.md) - [Example: Getting diagnostics](./rustc-driver/getting-diagnostics.md) - - [Remarks on perma-unstable features](./rustc-driver/remarks-on-perma-unstable-features.md) - [Errors and lints](diagnostics.md) - [Diagnostic and subdiagnostic structs](./diagnostics/diagnostic-structs.md) - [Translation](./diagnostics/translation.md) diff --git a/src/doc/rustc-dev-guide/src/backend/libs-and-metadata.md b/src/doc/rustc-dev-guide/src/backend/libs-and-metadata.md index 513df1650c3..eeb2af5e6bc 100644 --- a/src/doc/rustc-dev-guide/src/backend/libs-and-metadata.md +++ b/src/doc/rustc-dev-guide/src/backend/libs-and-metadata.md @@ -28,8 +28,8 @@ format is specific to `rustc`, and may change over time. This file contains: [`-C embed-bitcode=no`][embed-bitcode] CLI option to improve compile times and reduce disk space if LTO is not needed. * `rustc` [metadata], in a file named `lib.rmeta`. -* A symbol table, which is generally a list of symbols with offsets to the - object file that contain that symbol. This is pretty standard for archive +* A symbol table, which is essentially a list of symbols with offsets to the + object files that contain that symbol. This is pretty standard for archive files. [archive file]: https://en.wikipedia.org/wiki/Ar_(Unix) @@ -46,12 +46,11 @@ A `dylib` is a platform-specific shared library. It includes the `rustc` ### rmeta -An `rmeta` file is custom binary format that contains the [metadata] for the -crate. This file can be used for fast "checks" of a project by skipping all -code generation (as is done with `cargo check`), collecting enough information -for documentation (as is done with `cargo doc`), or for -[pipelining](#pipelining). This file is created if the -[`--emit=metadata`][emit] CLI option is used. +An `rmeta` file is a custom binary format that contains the [metadata] for the +crate. This file can be used for fast "checks" of a project by skipping all code +generation (as is done with `cargo check`), collecting enough information for +documentation (as is done with `cargo doc`), or for [pipelining](#pipelining). +This file is created if the [`--emit=metadata`][emit] CLI option is used. `rmeta` files do not support linking, since they do not contain compiled object files. @@ -60,8 +59,8 @@ object files. ## Metadata -The metadata contains a wide swath of different elements. This guide will not -go into detail of every field it contains. You are encouraged to browse the +The metadata contains a wide swath of different elements. This guide will not go +into detail about every field it contains. You are encouraged to browse the [`CrateRoot`] definition to get a sense of the different elements it contains. Everything about metadata encoding and decoding is in the [`rustc_metadata`] package. @@ -122,9 +121,9 @@ much more. By default, all Rust symbols are mangled and incorporate the stable crate id. This allows multiple versions of the same crate to be included together. Cargo -automatically generates `-C metadata` hashes based on a variety of factors, -like the package version, source, and the target kind (a lib and test can have -the same crate name, so they need to be disambiguated). +automatically generates `-C metadata` hashes based on a variety of factors, like +the package version, source, and target kind (a lib and test can have the same +crate name, so they need to be disambiguated). [`StableCrateId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/def_id/struct.StableCrateId.html [`StableCrateId::new`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/def_id/struct.StableCrateId.html#method.new @@ -154,7 +153,7 @@ will also look at the [sysroot] to find dependencies. As crates are loaded, they are kept in the [`CStore`] with the crate metadata wrapped in the [`CrateMetadata`] struct. After resolution and expansion, the -`CStore` will make its way into the [`GlobalCtxt`] for the rest of +`CStore` will make its way into the [`GlobalCtxt`] for the rest of the compilation. [name resolution]: ../name-resolution.md diff --git a/src/doc/rustc-dev-guide/src/cli.md b/src/doc/rustc-dev-guide/src/cli.md index 408ae207004..4c77007ea44 100644 --- a/src/doc/rustc-dev-guide/src/cli.md +++ b/src/doc/rustc-dev-guide/src/cli.md @@ -28,6 +28,6 @@ adding a new command-line argument. unstable-options` flag. [cli-docs]: https://doc.rust-lang.org/rustc/command-line-arguments.html -[forge guide for new options]: https://forge.rust-lang.org/compiler/new_option.html +[forge guide for new options]: https://forge.rust-lang.org/compiler/proposals-and-stabilization.html#compiler-flags [unstable book]: https://doc.rust-lang.org/nightly/unstable-book/ [`parse_bool`]: https://github.com/rust-lang/rust/blob/e5335592e78354e33d798d20c04bcd677c1df62d/src/librustc_session/options.rs#L307-L313 diff --git a/src/doc/rustc-dev-guide/src/getting-started.md b/src/doc/rustc-dev-guide/src/getting-started.md index 8bf14bef2a0..0e5b32a06f8 100644 --- a/src/doc/rustc-dev-guide/src/getting-started.md +++ b/src/doc/rustc-dev-guide/src/getting-started.md @@ -89,7 +89,7 @@ filtering the search to areas you're interested in. For example: Not all important or beginner work has issue labels. See below for how to find work that isn't labelled. -[help-wanted-search]: https://github.com/issues?q=is%3Aopen+is%3Aissue+org%3Arust-lang+no%3Aassignee+label%3AE-easy%2C%22good+first+issue%22%2Cgood-first-issue%2CE-medium%2CEasy%2CE-help-wanted%2CE-mentor+-label%3AS-blocked+ +[help-wanted-search]: https://github.com/issues?q=is%3Aopen+is%3Aissue+org%3Arust-lang+no%3Aassignee+label%3AE-easy%2C%22good+first+issue%22%2Cgood-first-issue%2CE-medium%2CEasy%2CE-help-wanted%2CE-mentor+-label%3AS-blocked+-linked:pr+ [Triage]: ./contributing.md#issue-triage ### Recurring work diff --git a/src/doc/rustc-dev-guide/src/rustc-driver/intro.md b/src/doc/rustc-dev-guide/src/rustc-driver/intro.md index 40500e6bc7a..a3684397b29 100644 --- a/src/doc/rustc-dev-guide/src/rustc-driver/intro.md +++ b/src/doc/rustc-dev-guide/src/rustc-driver/intro.md @@ -7,8 +7,8 @@ It acts as the glue for running the various phases of the compiler in the correc using the interface defined in the [`rustc_interface`] crate. Where possible, using [`rustc_driver`] rather than [`rustc_interface`] is recommended. The main entry point of [`rustc_driver`] is [`rustc_driver::run_compiler`][rd_rc]. -This builder accepts the same command-line args as rustc as well as an implementation of [`Callbacks`][cb] and a couple of other optional options. -[`Callbacks`][cb] is a `trait` that allows for custom compiler configuration, +This builder accepts the same command-line args as rustc as well as an implementation of [`Callbacks`] and a couple of other optional options. +[`Callbacks`] is a `trait` that allows for custom compiler configuration, as well as allowing custom code to run after different phases of the compilation. ## `rustc_interface` @@ -33,14 +33,8 @@ specifically [`rustc_driver_impl::run_compiler`][rdi_rc] [`Compiler`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Compiler.html [`rustc_driver`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/ [`rustc_interface`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/index.html -[`Session`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_session/struct.Session.html -[`SourceMap`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/source_map/struct.SourceMap.html -[`TyCtxt`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html -[Appendix A]: appendix/stupid-stats.html -[cb]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html +[`Callbacks`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html [example]: https://github.com/rust-lang/rustc-dev-guide/blob/master/examples/rustc-interface-example.rs [i_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/fn.run_compiler.html [rd_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/fn.run_compiler.html [rdi_rc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver_impl/fn.run_compiler.html -[stupid-stats]: https://github.com/nrc/stupid-stats -[`nightly-rustc`]: https://doc.rust-lang.org/nightly/nightly-rustc/ diff --git a/src/doc/rustc/theme/pagetoc.css b/src/doc/rustc/theme/pagetoc.css index 58ca1f8b26f..fa709194f37 100644 --- a/src/doc/rustc/theme/pagetoc.css +++ b/src/doc/rustc/theme/pagetoc.css @@ -49,7 +49,7 @@ } #pagetoc a { border-left: 1px solid var(--sidebar-bg); - color: var(--sidebar-fg) !important; + color: var(--fg); display: block; padding-bottom: 5px; padding-top: 5px; diff --git a/src/doc/unstable-book/src/language-features/explicit-extern-abis.md b/src/doc/unstable-book/src/language-features/explicit-extern-abis.md index ba622466ba7..7728f6725b1 100644 --- a/src/doc/unstable-book/src/language-features/explicit-extern-abis.md +++ b/src/doc/unstable-book/src/language-features/explicit-extern-abis.md @@ -1,6 +1,6 @@ # `explicit_extern_abis` -The tracking issue for this feature is: #134986 +The tracking issue for this feature is: [#134986] ------ @@ -21,3 +21,5 @@ extern "C" fn function2() {} // compiles extern "aapcs" fn function3() {} // compiles ``` + +[#134986]: https://github.com/rust-lang/rust/issues/134986 diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 44b3be23914..3b5f9b5a458 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Display}; +use std::fmt::Display; use std::path::PathBuf; use askama::Template; @@ -71,23 +71,6 @@ struct PageLayout<'a> { pub(crate) use crate::html::render::sidebar::filters; -/// Implements [`Display`] for a function that accepts a mutable reference to a [`String`], and (optionally) writes to it. -/// -/// The wrapped function will receive an empty string, and can modify it, -/// and the `Display` implementation will write the contents of the string after the function has finished. -pub(crate) struct BufDisplay<F>(pub F); - -impl<F> Display for BufDisplay<F> -where - F: Fn(&mut String), -{ - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut buf = String::new(); - self.0(&mut buf); - f.write_str(&buf) - } -} - pub(crate) fn render<T: Display, S: Display>( layout: &Layout, page: &Page<'_>, diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index f22935df96c..1f7201b8ca8 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -28,11 +28,10 @@ use crate::formats::cache::Cache; use crate::formats::item_type::ItemType; use crate::html::escape::Escape; use crate::html::format::join_with_double_colon; -use crate::html::layout::{self, BufDisplay}; use crate::html::markdown::{self, ErrorCodes, IdMap, plain_text_summary}; use crate::html::render::write_shared::write_shared; use crate::html::url_parts_builder::UrlPartsBuilder; -use crate::html::{sources, static_files}; +use crate::html::{layout, sources, static_files}; use crate::scrape_examples::AllCallLocations; use crate::{DOC_RUST_LANG_ORG_VERSION, try_err}; @@ -250,9 +249,7 @@ impl<'tcx> Context<'tcx> { layout::render( &self.shared.layout, &page, - BufDisplay(|buf: &mut String| { - print_sidebar(self, it, buf); - }), + fmt::from_fn(|f| print_sidebar(self, it, f)), content, &self.shared.style_files, ) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 3492df99955..06cb9269cc8 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -538,7 +538,7 @@ fn document( } fmt::from_fn(move |f| { - document_item_info(cx, item, parent).render_into(f).unwrap(); + document_item_info(cx, item, parent).render_into(f)?; if parent.is_none() { write!(f, "{}", document_full_collapsible(item, cx, heading_offset)) } else { @@ -582,7 +582,7 @@ fn document_short( show_def_docs: bool, ) -> impl fmt::Display { fmt::from_fn(move |f| { - document_item_info(cx, item, Some(parent)).render_into(f).unwrap(); + document_item_info(cx, item, Some(parent)).render_into(f)?; if !show_def_docs { return Ok(()); } @@ -661,7 +661,7 @@ fn document_full_inner( }; if let clean::ItemKind::FunctionItem(..) | clean::ItemKind::MethodItem(..) = kind { - render_call_locations(f, cx, item); + render_call_locations(f, cx, item)?; } Ok(()) }) @@ -2584,11 +2584,15 @@ const MAX_FULL_EXAMPLES: usize = 5; const NUM_VISIBLE_LINES: usize = 10; /// Generates the HTML for example call locations generated via the --scrape-examples flag. -fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean::Item) { +fn render_call_locations<W: fmt::Write>( + mut w: W, + cx: &Context<'_>, + item: &clean::Item, +) -> fmt::Result { let tcx = cx.tcx(); let def_id = item.item_id.expect_def_id(); let key = tcx.def_path_hash(def_id); - let Some(call_locations) = cx.shared.call_locations.get(&key) else { return }; + let Some(call_locations) = cx.shared.call_locations.get(&key) else { return Ok(()) }; // Generate a unique ID so users can link to this section for a given method let id = cx.derive_id("scraped-examples"); @@ -2602,8 +2606,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean </h5>", root_path = cx.root_path(), id = id - ) - .unwrap(); + )?; // Create a URL to a particular location in a reverse-dependency's source file let link_to_loc = |call_data: &CallData, loc: &CallLocation| -> (String, String) { @@ -2705,7 +2708,8 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean title: init_title, locations: locations_encoded, }), - ); + ) + .unwrap(); true }; @@ -2761,8 +2765,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean <div class=\"hide-more\">Hide additional examples</div>\ <div class=\"more-scraped-examples\">\ <div class=\"toggle-line\"><div class=\"toggle-line-inner\"></div></div>" - ) - .unwrap(); + )?; // Only generate inline code for MAX_FULL_EXAMPLES number of examples. Otherwise we could // make the page arbitrarily huge! @@ -2774,9 +2777,8 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean if it.peek().is_some() { w.write_str( r#"<div class="example-links">Additional examples can be found in:<br><ul>"#, - ) - .unwrap(); - it.for_each(|(_, call_data)| { + )?; + it.try_for_each(|(_, call_data)| { let (url, _) = link_to_loc(call_data, &call_data.locations[0]); write!( w, @@ -2784,13 +2786,12 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &Context<'_>, item: &clean url = url, name = call_data.display_name ) - .unwrap(); - }); - w.write_str("</ul></div>").unwrap(); + })?; + w.write_str("</ul></div>")?; } - w.write_str("</div></details>").unwrap(); + w.write_str("</div></details>")?; } - w.write_str("</div>").unwrap(); + w.write_str("</div>") } diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index cd0c9775f5c..a9029972d96 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -1,5 +1,6 @@ use std::borrow::Cow; use std::cmp::Ordering; +use std::fmt; use askama::Template; use rustc_data_structures::fx::FxHashSet; @@ -135,7 +136,11 @@ pub(crate) mod filters { } } -pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut String) { +pub(super) fn print_sidebar( + cx: &Context<'_>, + it: &clean::Item, + mut buffer: impl fmt::Write, +) -> fmt::Result { let mut ids = IdMap::new(); let mut blocks: Vec<LinkBlock<'_>> = docblock_toc(cx, it, &mut ids).into_iter().collect(); let deref_id_map = cx.deref_id_map.borrow(); @@ -195,7 +200,8 @@ pub(super) fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Str blocks, path, }; - sidebar.render_into(buffer).unwrap(); + sidebar.render_into(&mut buffer)?; + Ok(()) } fn get_struct_fields_name<'a>(fields: &'a [clean::Item]) -> Vec<Link<'a>> { diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 095795c711d..1fa6b5a60f3 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -11,9 +11,8 @@ use rustc_session::Session; use rustc_span::{FileName, FileNameDisplayPreference, RealFileName, sym}; use tracing::info; -use super::highlight; -use super::layout::{self, BufDisplay}; use super::render::Context; +use super::{highlight, layout}; use crate::clean; use crate::clean::utils::has_doc_flag; use crate::docfs::PathError; @@ -243,16 +242,16 @@ impl SourceCollector<'_, '_> { &shared.layout, &page, "", - BufDisplay(|buf: &mut String| { + fmt::from_fn(|f| { print_src( - buf, + f, contents, file_span, self.cx, &root_path, &highlight::DecorationInfo::default(), &source_context, - ); + ) }), &shared.style_files, ); @@ -331,7 +330,7 @@ pub(crate) fn print_src( root_path: &str, decoration_info: &highlight::DecorationInfo, source_context: &SourceContext<'_>, -) { +) -> fmt::Result { let mut lines = s.lines().count(); let line_info = if let SourceContext::Embedded(info) = source_context { highlight::LineInfo::new_scraped(lines as u32, info.offset as u32) @@ -367,12 +366,10 @@ pub(crate) fn print_src( }, max_nb_digits, } - .render_into(&mut writer) - .unwrap(), + .render_into(&mut writer), SourceContext::Embedded(info) => { - ScrapedSource { info, code_html: code, max_nb_digits } - .render_into(&mut writer) - .unwrap(); + ScrapedSource { info, code_html: code, max_nb_digits }.render_into(&mut writer) } - }; + }?; + Ok(()) } diff --git a/tests/crashes/140823.rs b/tests/crashes/140823.rs deleted file mode 100644 index ca2d683beed..00000000000 --- a/tests/crashes/140823.rs +++ /dev/null @@ -1,9 +0,0 @@ -//@ known-bug: #140823 - -struct Container<T> { - data: T, -} - -fn ice(callback: Box<dyn Fn(Container<&u8>)>) { - let fails: Box<dyn Fn(&Container<&u8>)> = callback; -} diff --git a/tests/ui/async-await/async-drop/dependency-dropped.rs b/tests/ui/async-await/async-drop/dependency-dropped.rs index c8670be4e8b..d7f415e19aa 100644 --- a/tests/ui/async-await/async-drop/dependency-dropped.rs +++ b/tests/ui/async-await/async-drop/dependency-dropped.rs @@ -5,7 +5,7 @@ //@ edition:2021 #![cfg_attr(with_feature, feature(async_drop))] -//[without_feature]~^ WARN found async drop types in dependecy `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped` +//[without_feature]~^ WARN found async drop types in dependency `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped` #![allow(incomplete_features)] diff --git a/tests/ui/async-await/async-drop/dependency-dropped.without_feature.stderr b/tests/ui/async-await/async-drop/dependency-dropped.without_feature.stderr index 56e49568e10..96a4572055c 100644 --- a/tests/ui/async-await/async-drop/dependency-dropped.without_feature.stderr +++ b/tests/ui/async-await/async-drop/dependency-dropped.without_feature.stderr @@ -1,4 +1,4 @@ -warning: found async drop types in dependecy `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped` +warning: found async drop types in dependency `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped` --> $DIR/dependency-dropped.rs:7:1 | LL | #![cfg_attr(with_feature, feature(async_drop))] diff --git a/tests/ui/attributes/auxiliary/use-doc-alias-name-extern.rs b/tests/ui/attributes/auxiliary/use-doc-alias-name-extern.rs new file mode 100644 index 00000000000..4c06d0fdfe3 --- /dev/null +++ b/tests/ui/attributes/auxiliary/use-doc-alias-name-extern.rs @@ -0,0 +1,24 @@ +#[doc(alias="DocAliasS1")] +pub struct S1; + +#[doc(alias="DocAliasS2")] +#[doc(alias("DocAliasS3", "DocAliasS4"))] +pub struct S2; + +#[doc(alias("doc_alias_f1", "doc_alias_f2"))] +pub fn f() {} + +pub mod m { + #[doc(alias="DocAliasS5")] + pub struct S5; + + pub mod n { + #[doc(alias("DocAliasX"))] + pub mod x { + pub mod y { + #[doc(alias="DocAliasS6")] + pub struct S6; + } + } + } +} diff --git a/tests/ui/attributes/use-doc-alias-name.rs b/tests/ui/attributes/use-doc-alias-name.rs new file mode 100644 index 00000000000..1fc9199b6e3 --- /dev/null +++ b/tests/ui/attributes/use-doc-alias-name.rs @@ -0,0 +1,67 @@ +//@ aux-build: use-doc-alias-name-extern.rs + +// issue#124273 + +extern crate use_doc_alias_name_extern; + +use use_doc_alias_name_extern::*; + +#[doc(alias="LocalDocAliasS")] +struct S; + +fn main() { + LocalDocAliasS; // don't show help in local crate + //~^ ERROR: cannot find value `LocalDocAliasS` in this scope + + DocAliasS1; + //~^ ERROR: cannot find value `DocAliasS1` in this scope + //~| HELP: `S1` has a name defined in the doc alias attribute as `DocAliasS1` + + DocAliasS2; + //~^ ERROR: cannot find value `DocAliasS2` in this scope + //~| HELP: `S2` has a name defined in the doc alias attribute as `DocAliasS2` + + DocAliasS3; + //~^ ERROR: cannot find value `DocAliasS3` in this scope + //~| HELP: `S2` has a name defined in the doc alias attribute as `DocAliasS3` + + DocAliasS4; + //~^ ERROR: cannot find value `DocAliasS4` in this scope + //~| HELP: `S2` has a name defined in the doc alias attribute as `DocAliasS4` + + doc_alias_f1(); + //~^ ERROR: cannot find function `doc_alias_f1` in this scope + //~| HELP: `f` has a name defined in the doc alias attribute as `doc_alias_f1` + + doc_alias_f2(); + //~^ ERROR: cannot find function `doc_alias_f2` in this scope + //~| HELP: `f` has a name defined in the doc alias attribute as `doc_alias_f2` + + m::DocAliasS5; + //~^ ERROR: cannot find value `DocAliasS5` in module `m` + //~| HELP: `S5` has a name defined in the doc alias attribute as `DocAliasS5` + + not_exist_module::DocAliasS1; + //~^ ERROR: use of unresolved module or unlinked crate `not_exist_module` + //~| HELP: you might be missing a crate named `not_exist_module` + + use_doc_alias_name_extern::DocAliasS1; + //~^ ERROR: cannot find value `DocAliasS1` in crate `use_doc_alias_name_extern + //~| HELP: `S1` has a name defined in the doc alias attribute as `DocAliasS1` + + m::n::DocAliasX::y::S6; + //~^ ERROR: could not find `DocAliasX` in `n` + //~| HELP: `x` has a name defined in the doc alias attribute as `DocAliasX` + + m::n::x::y::DocAliasS6; + //~^ ERROR: cannot find value `DocAliasS6` in module `m::n::x::y` + //~| HELP: `S6` has a name defined in the doc alias attribute as `DocAliasS6` +} + +trait T { + fn f() { + DocAliasS1; + //~^ ERROR: cannot find value `DocAliasS1` in this scope + //~| HELP: `S1` has a name defined in the doc alias attribute as `DocAliasS1` + } +} diff --git a/tests/ui/attributes/use-doc-alias-name.stderr b/tests/ui/attributes/use-doc-alias-name.stderr new file mode 100644 index 00000000000..07f4865e415 --- /dev/null +++ b/tests/ui/attributes/use-doc-alias-name.stderr @@ -0,0 +1,150 @@ +error[E0433]: failed to resolve: could not find `DocAliasX` in `n` + --> $DIR/use-doc-alias-name.rs:52:11 + | +LL | m::n::DocAliasX::y::S6; + | ^^^^^^^^^ could not find `DocAliasX` in `n` + | +help: `x` has a name defined in the doc alias attribute as `DocAliasX` + | +LL - m::n::DocAliasX::y::S6; +LL + m::n::x::y::S6; + | + +error[E0425]: cannot find value `LocalDocAliasS` in this scope + --> $DIR/use-doc-alias-name.rs:13:5 + | +LL | LocalDocAliasS; // don't show help in local crate + | ^^^^^^^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `DocAliasS1` in this scope + --> $DIR/use-doc-alias-name.rs:16:5 + | +LL | DocAliasS1; + | ^^^^^^^^^^ + | +help: `S1` has a name defined in the doc alias attribute as `DocAliasS1` + | +LL - DocAliasS1; +LL + S1; + | + +error[E0425]: cannot find value `DocAliasS2` in this scope + --> $DIR/use-doc-alias-name.rs:20:5 + | +LL | DocAliasS2; + | ^^^^^^^^^^ + | +help: `S2` has a name defined in the doc alias attribute as `DocAliasS2` + | +LL - DocAliasS2; +LL + S2; + | + +error[E0425]: cannot find value `DocAliasS3` in this scope + --> $DIR/use-doc-alias-name.rs:24:5 + | +LL | DocAliasS3; + | ^^^^^^^^^^ + | +help: `S2` has a name defined in the doc alias attribute as `DocAliasS3` + | +LL - DocAliasS3; +LL + S2; + | + +error[E0425]: cannot find value `DocAliasS4` in this scope + --> $DIR/use-doc-alias-name.rs:28:5 + | +LL | DocAliasS4; + | ^^^^^^^^^^ + | +help: `S2` has a name defined in the doc alias attribute as `DocAliasS4` + | +LL - DocAliasS4; +LL + S2; + | + +error[E0425]: cannot find value `DocAliasS5` in module `m` + --> $DIR/use-doc-alias-name.rs:40:8 + | +LL | m::DocAliasS5; + | ^^^^^^^^^^ + | +help: `S5` has a name defined in the doc alias attribute as `DocAliasS5` + | +LL - m::DocAliasS5; +LL + m::S5; + | + +error[E0425]: cannot find value `DocAliasS1` in crate `use_doc_alias_name_extern` + --> $DIR/use-doc-alias-name.rs:48:32 + | +LL | use_doc_alias_name_extern::DocAliasS1; + | ^^^^^^^^^^ + | +help: `S1` has a name defined in the doc alias attribute as `DocAliasS1` + | +LL - use_doc_alias_name_extern::DocAliasS1; +LL + use_doc_alias_name_extern::S1; + | + +error[E0425]: cannot find value `DocAliasS6` in module `m::n::x::y` + --> $DIR/use-doc-alias-name.rs:56:17 + | +LL | m::n::x::y::DocAliasS6; + | ^^^^^^^^^^ + | +help: `S6` has a name defined in the doc alias attribute as `DocAliasS6` + | +LL - m::n::x::y::DocAliasS6; +LL + m::n::x::y::S6; + | + +error[E0425]: cannot find value `DocAliasS1` in this scope + --> $DIR/use-doc-alias-name.rs:63:9 + | +LL | DocAliasS1; + | ^^^^^^^^^^ + | +help: `S1` has a name defined in the doc alias attribute as `DocAliasS1` + | +LL - DocAliasS1; +LL + S1; + | + +error[E0425]: cannot find function `doc_alias_f1` in this scope + --> $DIR/use-doc-alias-name.rs:32:5 + | +LL | doc_alias_f1(); + | ^^^^^^^^^^^^ + | +help: `f` has a name defined in the doc alias attribute as `doc_alias_f1` + | +LL - doc_alias_f1(); +LL + f(); + | + +error[E0425]: cannot find function `doc_alias_f2` in this scope + --> $DIR/use-doc-alias-name.rs:36:5 + | +LL | doc_alias_f2(); + | ^^^^^^^^^^^^ + | +help: `f` has a name defined in the doc alias attribute as `doc_alias_f2` + | +LL - doc_alias_f2(); +LL + f(); + | + +error[E0433]: failed to resolve: use of unresolved module or unlinked crate `not_exist_module` + --> $DIR/use-doc-alias-name.rs:44:5 + | +LL | not_exist_module::DocAliasS1; + | ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `not_exist_module` + | + = help: you might be missing a crate named `not_exist_module` + +error: aborting due to 13 previous errors + +Some errors have detailed explanations: E0425, E0433. +For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/drop/drop-order-comparisons.e2021.fixed b/tests/ui/drop/drop-order-comparisons.e2021.fixed index 71158cb8062..6c8d2d3fa9c 100644 --- a/tests/ui/drop/drop-order-comparisons.e2021.fixed +++ b/tests/ui/drop/drop-order-comparisons.e2021.fixed @@ -24,6 +24,7 @@ //@ [e2024] edition: 2024 //@ run-pass +#![feature(if_let_guard)] #![cfg_attr(e2021, feature(let_chains))] #![cfg_attr(e2021, warn(rust_2024_compatibility))] @@ -344,6 +345,25 @@ fn t_if_let_chains_then() { e.assert(9); } +#[rustfmt::skip] +fn t_guard_if_let_chains_then() { + let e = Events::new(); + _ = match () { + () if e.ok(1).is_ok() + && let true = e.ok(9).is_ok() + && let Ok(_v) = e.ok(8) + && let Ok(_) = e.ok(7) + && let Ok(_) = e.ok(6).as_ref() + && e.ok(2).is_ok() + && let Ok(_v) = e.ok(5) + && let Ok(_) = e.ok(4).as_ref() => { + e.mark(3); + } + _ => {} + }; + e.assert(9); +} + #[cfg(e2021)] #[rustfmt::skip] fn t_if_let_nested_else() { @@ -484,6 +504,25 @@ fn t_if_let_chains_then_else() { e.assert(9); } +#[rustfmt::skip] +fn t_guard_if_let_chains_then_else() { + let e = Events::new(); + _ = match () { + () if e.ok(1).is_ok() + && let true = e.ok(8).is_ok() + && let Ok(_v) = e.ok(7) + && let Ok(_) = e.ok(6) + && let Ok(_) = e.ok(5).as_ref() + && e.ok(2).is_ok() + && let Ok(_v) = e.ok(4) + && let Ok(_) = e.err(3) => {} + _ => { + e.mark(9); + } + }; + e.assert(9); +} + fn main() { t_bindings(); t_tuples(); @@ -502,10 +541,12 @@ fn main() { t_if_let_nested_then(); t_let_else_chained_then(); t_if_let_chains_then(); + t_guard_if_let_chains_then(); t_if_let_nested_else(); t_if_let_nested_then_else(); t_let_else_chained_then_else(); t_if_let_chains_then_else(); + t_guard_if_let_chains_then_else(); } // # Test scaffolding diff --git a/tests/ui/drop/drop-order-comparisons.e2021.stderr b/tests/ui/drop/drop-order-comparisons.e2021.stderr index 0717a8c1b9b..8b93376cc0d 100644 --- a/tests/ui/drop/drop-order-comparisons.e2021.stderr +++ b/tests/ui/drop/drop-order-comparisons.e2021.stderr @@ -1,5 +1,5 @@ warning: relative drop order changing in Rust 2024 - --> $DIR/drop-order-comparisons.rs:76:9 + --> $DIR/drop-order-comparisons.rs:77:9 | LL | _ = ({ | _________- @@ -29,35 +29,35 @@ LL | | }, e.mark(3), e.ok(4)); = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html> note: `#3` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: `#1` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: `_v` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: `#2` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages note: the lint level is defined here - --> $DIR/drop-order-comparisons.rs:28:25 + --> $DIR/drop-order-comparisons.rs:29:25 | LL | #![cfg_attr(e2021, warn(rust_2024_compatibility))] | ^^^^^^^^^^^^^^^^^^^^^^^ = note: `#[warn(tail_expr_drop_order)]` implied by `#[warn(rust_2024_compatibility)]` warning: relative drop order changing in Rust 2024 - --> $DIR/drop-order-comparisons.rs:100:45 + --> $DIR/drop-order-comparisons.rs:101:45 | LL | _ = ({ | _________- @@ -77,19 +77,19 @@ LL | | }, e.mark(1), e.ok(4)); = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html> note: `#2` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: `#1` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages warning: relative drop order changing in Rust 2024 - --> $DIR/drop-order-comparisons.rs:100:19 + --> $DIR/drop-order-comparisons.rs:101:19 | LL | _ = ({ | _________- @@ -109,19 +109,19 @@ LL | | }, e.mark(1), e.ok(4)); = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html> note: `#2` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: `#1` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages warning: relative drop order changing in Rust 2024 - --> $DIR/drop-order-comparisons.rs:221:24 + --> $DIR/drop-order-comparisons.rs:222:24 | LL | _ = ({ | _________- @@ -141,19 +141,19 @@ LL | | }, e.mark(2), e.ok(3)); = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html> note: `#2` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: `#1` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages warning: relative drop order changing in Rust 2024 - --> $DIR/drop-order-comparisons.rs:247:24 + --> $DIR/drop-order-comparisons.rs:248:24 | LL | _ = ({ | _________- @@ -173,19 +173,19 @@ LL | | }, e.mark(2), e.ok(3)); = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-tail-expr-scope.html> note: `#2` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: `#1` invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: most of the time, changing drop order is harmless; inspect the `impl Drop`s for side effects like releasing locks or sending messages warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:123:13 + --> $DIR/drop-order-comparisons.rs:124:13 | LL | _ = (if let Ok(_) = e.ok(4).as_ref() { | ^^^^^^^^^^^^-------^^^^^^^^^ @@ -195,12 +195,12 @@ LL | _ = (if let Ok(_) = e.ok(4).as_ref() { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:127:5 + --> $DIR/drop-order-comparisons.rs:128:5 | LL | }, e.mark(2), e.ok(3)); | ^ @@ -215,7 +215,7 @@ LL ~ } _ => {}}, e.mark(2), e.ok(3)); | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:145:13 + --> $DIR/drop-order-comparisons.rs:146:13 | LL | _ = (if let Ok(_) = e.err(4).as_ref() {} else { | ^^^^^^^^^^^^--------^^^^^^^^^ @@ -225,12 +225,12 @@ LL | _ = (if let Ok(_) = e.err(4).as_ref() {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:145:44 + --> $DIR/drop-order-comparisons.rs:146:44 | LL | _ = (if let Ok(_) = e.err(4).as_ref() {} else { | ^ @@ -244,7 +244,7 @@ LL ~ }}, e.mark(2), e.ok(3)); | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:247:12 + --> $DIR/drop-order-comparisons.rs:248:12 | LL | if let Ok(_) = e.err(4).as_ref() {} else { | ^^^^^^^^^^^^--------^^^^^^^^^ @@ -254,12 +254,12 @@ LL | if let Ok(_) = e.err(4).as_ref() {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:247:43 + --> $DIR/drop-order-comparisons.rs:248:43 | LL | if let Ok(_) = e.err(4).as_ref() {} else { | ^ @@ -273,7 +273,7 @@ LL ~ }} | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:352:12 + --> $DIR/drop-order-comparisons.rs:372:12 | LL | if let true = e.err(9).is_ok() {} else { | ^^^^^^^^^^^--------^^^^^^^^ @@ -283,12 +283,12 @@ LL | if let true = e.err(9).is_ok() {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:352:41 + --> $DIR/drop-order-comparisons.rs:372:41 | LL | if let true = e.err(9).is_ok() {} else { | ^ @@ -302,7 +302,7 @@ LL ~ }}}}}}}}}; | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:355:12 + --> $DIR/drop-order-comparisons.rs:375:12 | LL | if let Ok(_v) = e.err(8) {} else { | ^^^^^^^^^^^^^-------- @@ -312,12 +312,12 @@ LL | if let Ok(_v) = e.err(8) {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:355:35 + --> $DIR/drop-order-comparisons.rs:375:35 | LL | if let Ok(_v) = e.err(8) {} else { | ^ @@ -331,7 +331,7 @@ LL ~ }}}}}}}}}; | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:358:12 + --> $DIR/drop-order-comparisons.rs:378:12 | LL | if let Ok(_) = e.err(7) {} else { | ^^^^^^^^^^^^-------- @@ -341,12 +341,12 @@ LL | if let Ok(_) = e.err(7) {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:358:34 + --> $DIR/drop-order-comparisons.rs:378:34 | LL | if let Ok(_) = e.err(7) {} else { | ^ @@ -360,7 +360,7 @@ LL ~ }}}}}}}}}; | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:361:12 + --> $DIR/drop-order-comparisons.rs:381:12 | LL | if let Ok(_) = e.err(6).as_ref() {} else { | ^^^^^^^^^^^^--------^^^^^^^^^ @@ -370,12 +370,12 @@ LL | if let Ok(_) = e.err(6).as_ref() {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:361:43 + --> $DIR/drop-order-comparisons.rs:381:43 | LL | if let Ok(_) = e.err(6).as_ref() {} else { | ^ @@ -389,7 +389,7 @@ LL ~ }}}}}}}}}; | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:365:12 + --> $DIR/drop-order-comparisons.rs:385:12 | LL | if let Ok(_v) = e.err(5) {} else { | ^^^^^^^^^^^^^-------- @@ -399,12 +399,12 @@ LL | if let Ok(_v) = e.err(5) {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:365:35 + --> $DIR/drop-order-comparisons.rs:385:35 | LL | if let Ok(_v) = e.err(5) {} else { | ^ @@ -418,7 +418,7 @@ LL ~ }}}}}}}}}; | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:368:12 + --> $DIR/drop-order-comparisons.rs:388:12 | LL | if let Ok(_) = e.err(4) {} else { | ^^^^^^^^^^^^-------- @@ -428,12 +428,12 @@ LL | if let Ok(_) = e.err(4) {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:368:34 + --> $DIR/drop-order-comparisons.rs:388:34 | LL | if let Ok(_) = e.err(4) {} else { | ^ @@ -447,7 +447,7 @@ LL ~ }}}}}}}}}; | warning: `if let` assigns a shorter lifetime since Edition 2024 - --> $DIR/drop-order-comparisons.rs:404:12 + --> $DIR/drop-order-comparisons.rs:424:12 | LL | if let Ok(_) = e.err(4).as_ref() {} else { | ^^^^^^^^^^^^--------^^^^^^^^^ @@ -457,12 +457,12 @@ LL | if let Ok(_) = e.err(4).as_ref() {} else { = warning: this changes meaning in Rust 2024 = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/temporary-if-let-scope.html> note: value invokes this custom destructor - --> $DIR/drop-order-comparisons.rs:571:1 + --> $DIR/drop-order-comparisons.rs:612:1 | LL | impl<'b> Drop for LogDrop<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: the value is now dropped here in Edition 2024 - --> $DIR/drop-order-comparisons.rs:404:43 + --> $DIR/drop-order-comparisons.rs:424:43 | LL | if let Ok(_) = e.err(4).as_ref() {} else { | ^ diff --git a/tests/ui/drop/drop-order-comparisons.rs b/tests/ui/drop/drop-order-comparisons.rs index 0492b3a4db7..9a10a08a3ff 100644 --- a/tests/ui/drop/drop-order-comparisons.rs +++ b/tests/ui/drop/drop-order-comparisons.rs @@ -24,6 +24,7 @@ //@ [e2024] edition: 2024 //@ run-pass +#![feature(if_let_guard)] #![cfg_attr(e2021, feature(let_chains))] #![cfg_attr(e2021, warn(rust_2024_compatibility))] @@ -344,6 +345,25 @@ fn t_if_let_chains_then() { e.assert(9); } +#[rustfmt::skip] +fn t_guard_if_let_chains_then() { + let e = Events::new(); + _ = match () { + () if e.ok(1).is_ok() + && let true = e.ok(9).is_ok() + && let Ok(_v) = e.ok(8) + && let Ok(_) = e.ok(7) + && let Ok(_) = e.ok(6).as_ref() + && e.ok(2).is_ok() + && let Ok(_v) = e.ok(5) + && let Ok(_) = e.ok(4).as_ref() => { + e.mark(3); + } + _ => {} + }; + e.assert(9); +} + #[cfg(e2021)] #[rustfmt::skip] fn t_if_let_nested_else() { @@ -484,6 +504,25 @@ fn t_if_let_chains_then_else() { e.assert(9); } +#[rustfmt::skip] +fn t_guard_if_let_chains_then_else() { + let e = Events::new(); + _ = match () { + () if e.ok(1).is_ok() + && let true = e.ok(8).is_ok() + && let Ok(_v) = e.ok(7) + && let Ok(_) = e.ok(6) + && let Ok(_) = e.ok(5).as_ref() + && e.ok(2).is_ok() + && let Ok(_v) = e.ok(4) + && let Ok(_) = e.err(3) => {} + _ => { + e.mark(9); + } + }; + e.assert(9); +} + fn main() { t_bindings(); t_tuples(); @@ -502,10 +541,12 @@ fn main() { t_if_let_nested_then(); t_let_else_chained_then(); t_if_let_chains_then(); + t_guard_if_let_chains_then(); t_if_let_nested_else(); t_if_let_nested_then_else(); t_let_else_chained_then_else(); t_if_let_chains_then_else(); + t_guard_if_let_chains_then_else(); } // # Test scaffolding diff --git a/tests/ui/fn/coerce-suggestion-infer-region.rs b/tests/ui/fn/coerce-suggestion-infer-region.rs new file mode 100644 index 00000000000..7edb828c973 --- /dev/null +++ b/tests/ui/fn/coerce-suggestion-infer-region.rs @@ -0,0 +1,26 @@ +//! Functions with a mismatch between the expected and found type where the difference is a +//! reference may trigger analysis for additional help. In this test the expected type will be +//! &'a Container<&'a u8> and the found type will be Container<&'?0 u8>. +//! +//! This test exercises a scenario where the found type being analyzed contains an inference region +//! variable ('?0). This cannot be used in comparisons because the variable no longer exists by the +//! time the later analysis is performed. +//! +//! This is a regression test of #140823 + +trait MyFn<P> {} + +struct Container<T> { + data: T, +} + +struct Desugared { + callback: Box<dyn for<'a> MyFn<&'a Container<&'a u8>>>, +} + +fn test(callback: Box<dyn for<'a> MyFn<Container<&'a u8>>>) -> Desugared { + Desugared { callback } + //~^ ERROR mismatched types +} + +fn main() {} diff --git a/tests/ui/fn/coerce-suggestion-infer-region.stderr b/tests/ui/fn/coerce-suggestion-infer-region.stderr new file mode 100644 index 00000000000..9dd0fcf76ce --- /dev/null +++ b/tests/ui/fn/coerce-suggestion-infer-region.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/coerce-suggestion-infer-region.rs:22:17 + | +LL | Desugared { callback } + | ^^^^^^^^ expected `Box<dyn MyFn<&Container<&u8>>>`, found `Box<dyn MyFn<Container<&u8>>>` + | + = note: expected struct `Box<(dyn for<'a> MyFn<&'a Container<&'a u8>> + 'static)>` + found struct `Box<(dyn for<'a> MyFn<Container<&'a u8>> + 'static)>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/impl-trait/issues/issue-100075-2.stderr b/tests/ui/impl-trait/issues/issue-100075-2.stderr index b3b69677507..554c3ea3433 100644 --- a/tests/ui/impl-trait/issues/issue-100075-2.stderr +++ b/tests/ui/impl-trait/issues/issue-100075-2.stderr @@ -1,3 +1,9 @@ +error[E0720]: cannot resolve opaque type + --> $DIR/issue-100075-2.rs:1:23 + | +LL | fn opaque<T>(t: T) -> impl Sized { + | ^^^^^^^^^^ + warning: function cannot return without recursing --> $DIR/issue-100075-2.rs:1:1 | @@ -10,15 +16,6 @@ LL | opaque(Some(t)) = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -error[E0720]: cannot resolve opaque type - --> $DIR/issue-100075-2.rs:1:23 - | -LL | fn opaque<T>(t: T) -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -... -LL | opaque(Some(t)) - | --------------- returning here with type `impl Sized` - error: aborting due to 1 previous error; 1 warning emitted For more information about this error, try `rustc --explain E0720`. diff --git a/tests/ui/impl-trait/issues/issue-100075.stderr b/tests/ui/impl-trait/issues/issue-100075.stderr index 75963489236..bca2874b2b4 100644 --- a/tests/ui/impl-trait/issues/issue-100075.stderr +++ b/tests/ui/impl-trait/issues/issue-100075.stderr @@ -2,10 +2,7 @@ error[E0720]: cannot resolve opaque type --> $DIR/issue-100075.rs:13:37 | LL | fn _g<T>(t: &'static T) -> &'static impl Marker { - | ^^^^^^^^^^^ recursive opaque type -... -LL | return _g(t); - | ----- returning here with type `&impl Marker` + | ^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/issues/issue-103599.rs b/tests/ui/impl-trait/issues/issue-103599.rs index 62741a7454c..e674ce3cbdf 100644 --- a/tests/ui/impl-trait/issues/issue-103599.rs +++ b/tests/ui/impl-trait/issues/issue-103599.rs @@ -1,9 +1,8 @@ -//@ check-pass - trait T {} fn wrap(x: impl T) -> impl T { - //~^ WARN function cannot return without recursing + //~^ ERROR cannot resolve opaque type + //~| WARN function cannot return without recursing wrap(wrap(x)) } diff --git a/tests/ui/impl-trait/issues/issue-103599.stderr b/tests/ui/impl-trait/issues/issue-103599.stderr index 82038c1dceb..9878b12044f 100644 --- a/tests/ui/impl-trait/issues/issue-103599.stderr +++ b/tests/ui/impl-trait/issues/issue-103599.stderr @@ -1,14 +1,21 @@ +error[E0720]: cannot resolve opaque type + --> $DIR/issue-103599.rs:3:23 + | +LL | fn wrap(x: impl T) -> impl T { + | ^^^^^^ + warning: function cannot return without recursing - --> $DIR/issue-103599.rs:5:1 + --> $DIR/issue-103599.rs:3:1 | LL | fn wrap(x: impl T) -> impl T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing -LL | +... LL | wrap(wrap(x)) | ------- recursive call site | = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -warning: 1 warning emitted +error: aborting due to 1 previous error; 1 warning emitted +For more information about this error, try `rustc --explain E0720`. diff --git a/tests/ui/impl-trait/issues/issue-87450.rs b/tests/ui/impl-trait/issues/issue-87450.rs index 983ef7cfbe0..5a7759af111 100644 --- a/tests/ui/impl-trait/issues/issue-87450.rs +++ b/tests/ui/impl-trait/issues/issue-87450.rs @@ -3,8 +3,8 @@ fn bar() -> impl Fn() { } fn foo() -> impl Fn() { - //~^ WARNING 5:1: 5:22: function cannot return without recursing [unconditional_recursion] - //~| ERROR 5:13: 5:22: cannot resolve opaque type [E0720] + //~^ WARN function cannot return without recursing + //~| ERROR cannot resolve opaque type wrap(wrap(wrap(wrap(wrap(wrap(wrap(foo()))))))) } diff --git a/tests/ui/impl-trait/issues/issue-87450.stderr b/tests/ui/impl-trait/issues/issue-87450.stderr index 9567e09651d..f0f8b5859c0 100644 --- a/tests/ui/impl-trait/issues/issue-87450.stderr +++ b/tests/ui/impl-trait/issues/issue-87450.stderr @@ -1,3 +1,9 @@ +error[E0720]: cannot resolve opaque type + --> $DIR/issue-87450.rs:5:13 + | +LL | fn foo() -> impl Fn() { + | ^^^^^^^^^ + warning: function cannot return without recursing --> $DIR/issue-87450.rs:5:1 | @@ -10,18 +16,6 @@ LL | wrap(wrap(wrap(wrap(wrap(wrap(wrap(foo()))))))) = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -error[E0720]: cannot resolve opaque type - --> $DIR/issue-87450.rs:5:13 - | -LL | fn foo() -> impl Fn() { - | ^^^^^^^^^ recursive opaque type -... -LL | wrap(wrap(wrap(wrap(wrap(wrap(wrap(foo()))))))) - | ----------------------------------------------- returning here with type `impl Fn()` -... -LL | fn wrap(f: impl Fn()) -> impl Fn() { - | --------- returning this opaque type `impl Fn()` - error: aborting due to 1 previous error; 1 warning emitted For more information about this error, try `rustc --explain E0720`. diff --git a/tests/ui/impl-trait/recursive-impl-trait-type-indirect.stderr b/tests/ui/impl-trait/recursive-impl-trait-type-indirect.stderr index 2d2731e4368..af84375c747 100644 --- a/tests/ui/impl-trait/recursive-impl-trait-type-indirect.stderr +++ b/tests/ui/impl-trait/recursive-impl-trait-type-indirect.stderr @@ -2,112 +2,67 @@ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:6:22 | LL | fn option(i: i32) -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -LL | -LL | if i < 0 { None } else { Some((option(i - 1), i)) } - | ---- ------------------------ returning here with type `Option<(impl Sized, i32)>` - | | - | returning here with type `Option<(impl Sized, i32)>` + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:11:15 | LL | fn tuple() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -LL | -LL | (tuple(),) - | ---------- returning here with type `(impl Sized,)` + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:16:15 | LL | fn array() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -LL | -LL | [array()] - | --------- returning here with type `[impl Sized; 1]` + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:21:13 | LL | fn ptr() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -LL | -LL | &ptr() as *const _ - | ------------------ returning here with type `*const impl Sized` + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:26:16 | LL | fn fn_ptr() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -LL | -LL | fn_ptr as fn() -> _ - | ------------------- returning here with type `fn() -> impl Sized` + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:31:25 | -LL | fn closure_capture() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -... -LL | / move || { -LL | | x; - | | - closure captures itself here -LL | | } - | |_____- returning here with type `{closure@$DIR/recursive-impl-trait-type-indirect.rs:34:5: 34:12}` +LL | fn closure_capture() -> impl Sized { + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:39:29 | -LL | fn closure_ref_capture() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -... -LL | / move || { -LL | | &x; - | | - closure captures itself here -LL | | } - | |_____- returning here with type `{closure@$DIR/recursive-impl-trait-type-indirect.rs:42:5: 42:12}` +LL | fn closure_ref_capture() -> impl Sized { + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:47:21 | LL | fn closure_sig() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -LL | -LL | || closure_sig() - | ---------------- returning here with type `{closure@$DIR/recursive-impl-trait-type-indirect.rs:49:5: 49:7}` + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:52:23 | LL | fn coroutine_sig() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -LL | -LL | || coroutine_sig() - | ------------------ returning here with type `{closure@$DIR/recursive-impl-trait-type-indirect.rs:54:5: 54:7}` + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:57:27 | -LL | fn coroutine_capture() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -... -LL | / move || { -LL | | yield; -LL | | x; - | | - coroutine captures itself here -LL | | } - | |_____- returning here with type `{coroutine@$DIR/recursive-impl-trait-type-indirect.rs:62:5: 62:12}` +LL | fn coroutine_capture() -> impl Sized { + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:68:35 | LL | fn substs_change<T: 'static>() -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -LL | -LL | (substs_change::<&T>(),) - | ------------------------ returning here with type `(impl Sized,)` + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-impl-trait-type-indirect.rs:78:26 diff --git a/tests/ui/impl-trait/recursive-in-exhaustiveness.current.stderr b/tests/ui/impl-trait/recursive-in-exhaustiveness.current.stderr index 42dbc7c9160..080c3284641 100644 --- a/tests/ui/impl-trait/recursive-in-exhaustiveness.current.stderr +++ b/tests/ui/impl-trait/recursive-in-exhaustiveness.current.stderr @@ -1,56 +1,21 @@ -warning: function cannot return without recursing - --> $DIR/recursive-in-exhaustiveness.rs:17:1 +error[E0720]: cannot resolve opaque type + --> $DIR/recursive-in-exhaustiveness.rs:17:22 | LL | fn build<T>(x: T) -> impl Sized { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing -LL | -LL | let (x,) = (build(x),); - | -------- recursive call site - | - = help: a `loop` may express intention better if this is on purpose - = note: `#[warn(unconditional_recursion)]` on by default - -warning: function cannot return without recursing - --> $DIR/recursive-in-exhaustiveness.rs:27:1 - | -LL | fn build2<T>(x: T) -> impl Sized { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing -... -LL | let (x,) = (build2(x),); - | --------- recursive call site - | - = help: a `loop` may express intention better if this is on purpose + | ^^^^^^^^^^ error[E0720]: cannot resolve opaque type --> $DIR/recursive-in-exhaustiveness.rs:27:23 | LL | fn build2<T>(x: T) -> impl Sized { - | ^^^^^^^^^^ recursive opaque type -... -LL | (build2(x),) - | ------------ returning here with type `(impl Sized,)` + | ^^^^^^^^^^ -warning: function cannot return without recursing - --> $DIR/recursive-in-exhaustiveness.rs:40:1 - | -LL | fn build3<T>(x: T) -> impl Sized { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing -LL | -LL | let (x,) = (build3((x,)),); - | ------------ recursive call site - | - = help: a `loop` may express intention better if this is on purpose - -error[E0792]: expected generic type parameter, found `(T,)` - --> $DIR/recursive-in-exhaustiveness.rs:49:5 +error[E0720]: cannot resolve opaque type + --> $DIR/recursive-in-exhaustiveness.rs:39:23 | LL | fn build3<T>(x: T) -> impl Sized { - | - this generic parameter must be used with a generic type parameter -... -LL | build3(x) - | ^^^^^^^^^ + | ^^^^^^^^^^ -error: aborting due to 2 previous errors; 3 warnings emitted +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0720, E0792. -For more information about an error, try `rustc --explain E0720`. +For more information about this error, try `rustc --explain E0720`. diff --git a/tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr b/tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr index 4c3d5aa8fb8..a3609b93cb3 100644 --- a/tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr +++ b/tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr @@ -5,19 +5,19 @@ LL | let (x,) = (build(x),); | ^^^^^^^^ cannot satisfy `impl Sized == _` error[E0271]: type mismatch resolving `build2<(_,)>::{opaque#0} normalizes-to _` - --> $DIR/recursive-in-exhaustiveness.rs:31:6 + --> $DIR/recursive-in-exhaustiveness.rs:30:6 | LL | (build2(x),) | ^^^^^^^^^ types differ error[E0271]: type mismatch resolving `build2<(_,)>::{opaque#0} normalizes-to _` - --> $DIR/recursive-in-exhaustiveness.rs:31:5 + --> $DIR/recursive-in-exhaustiveness.rs:30:5 | LL | (build2(x),) | ^^^^^^^^^^^^ types differ error[E0277]: the size for values of type `(impl Sized,)` cannot be known at compilation time - --> $DIR/recursive-in-exhaustiveness.rs:31:5 + --> $DIR/recursive-in-exhaustiveness.rs:30:5 | LL | (build2(x),) | ^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -26,13 +26,13 @@ LL | (build2(x),) = note: tuples must have a statically known size to be initialized error[E0271]: type mismatch resolving `build3<(T,)>::{opaque#0} normalizes-to _` - --> $DIR/recursive-in-exhaustiveness.rs:42:17 + --> $DIR/recursive-in-exhaustiveness.rs:41:17 | LL | let (x,) = (build3((x,)),); | ^^^^^^^^^^^^ types differ error[E0277]: the size for values of type `(impl Sized,)` cannot be known at compilation time - --> $DIR/recursive-in-exhaustiveness.rs:42:16 + --> $DIR/recursive-in-exhaustiveness.rs:41:16 | LL | let (x,) = (build3((x,)),); | ^^^^^^^^^^^^^^^ doesn't have a size known at compile-time @@ -41,7 +41,7 @@ LL | let (x,) = (build3((x,)),); = note: tuples must have a statically known size to be initialized error[E0308]: mismatched types - --> $DIR/recursive-in-exhaustiveness.rs:42:16 + --> $DIR/recursive-in-exhaustiveness.rs:41:16 | LL | fn build3<T>(x: T) -> impl Sized { | ---------- the found opaque type @@ -53,7 +53,7 @@ LL | let (x,) = (build3((x,)),); found tuple `(impl Sized,)` error[E0271]: type mismatch resolving `build3<(T,)>::{opaque#0} normalizes-to _` - --> $DIR/recursive-in-exhaustiveness.rs:42:17 + --> $DIR/recursive-in-exhaustiveness.rs:41:17 | LL | let (x,) = (build3((x,)),); | ^^^^^^^^^^^^ types differ @@ -61,13 +61,13 @@ LL | let (x,) = (build3((x,)),); = note: the return type of a function must have a statically known size error[E0271]: type mismatch resolving `build3<(T,)>::{opaque#0} normalizes-to _` - --> $DIR/recursive-in-exhaustiveness.rs:42:16 + --> $DIR/recursive-in-exhaustiveness.rs:41:16 | LL | let (x,) = (build3((x,)),); | ^^^^^^^^^^^^^^^ types differ error[E0271]: type mismatch resolving `build3<(T,)>::{opaque#0} normalizes-to _` - --> $DIR/recursive-in-exhaustiveness.rs:42:17 + --> $DIR/recursive-in-exhaustiveness.rs:41:17 | LL | let (x,) = (build3((x,)),); | ^^^^^^^^^^^^ types differ diff --git a/tests/ui/impl-trait/recursive-in-exhaustiveness.rs b/tests/ui/impl-trait/recursive-in-exhaustiveness.rs index 58944533686..fa8fa0e8174 100644 --- a/tests/ui/impl-trait/recursive-in-exhaustiveness.rs +++ b/tests/ui/impl-trait/recursive-in-exhaustiveness.rs @@ -15,7 +15,7 @@ // We unfortunately accept this today, and due to how opaque type relating is implemented // in the NLL type relation, this defines `Opaque<T> = T`. fn build<T>(x: T) -> impl Sized { - //[current]~^ WARN function cannot return without recursing + //[current]~^ ERROR cannot resolve opaque type let (x,) = (build(x),); //[next]~^ ERROR type annotations needed build(x) @@ -26,7 +26,6 @@ fn build<T>(x: T) -> impl Sized { // Not allowed today. Detected as recursive. fn build2<T>(x: T) -> impl Sized { //[current]~^ ERROR cannot resolve opaque type - //[current]~| WARN function cannot return without recursing let (x,) = (build2(x),); (build2(x),) //[next]~^ ERROR type mismatch resolving @@ -38,7 +37,7 @@ fn build2<T>(x: T) -> impl Sized { // // Not allowed today. Detected as not defining. fn build3<T>(x: T) -> impl Sized { - //[current]~^ WARN function cannot return without recursing + //[current]~^ ERROR cannot resolve opaque type let (x,) = (build3((x,)),); //[next]~^ ERROR type mismatch resolving //[next]~| ERROR type mismatch resolving @@ -47,7 +46,6 @@ fn build3<T>(x: T) -> impl Sized { //[next]~| ERROR the size for values of type //[next]~| ERROR mismatched types build3(x) - //[current]~^ ERROR expected generic type parameter, found `(T,)` } fn main() {} diff --git a/tests/ui/mir/mir_match_guard_let_chains_drop_order.rs b/tests/ui/mir/mir_match_guard_let_chains_drop_order.rs new file mode 100644 index 00000000000..e98d57d1154 --- /dev/null +++ b/tests/ui/mir/mir_match_guard_let_chains_drop_order.rs @@ -0,0 +1,110 @@ +//@ run-pass +//@ needs-unwind +//@ revisions: edition2021 edition2024 +//@ [edition2021] edition: 2021 +//@ [edition2024] edition: 2024 + +// See `mir_drop_order.rs` for more information + +#![feature(if_let_guard)] +#![allow(irrefutable_let_patterns)] + +use std::cell::RefCell; +use std::panic; + +pub struct DropLogger<'a, T> { + extra: T, + id: usize, + log: &'a panic::AssertUnwindSafe<RefCell<Vec<usize>>>, +} + +impl<'a, T> Drop for DropLogger<'a, T> { + fn drop(&mut self) { + self.log.0.borrow_mut().push(self.id); + } +} + +struct InjectedFailure; + +#[allow(unreachable_code)] +fn main() { + let log = panic::AssertUnwindSafe(RefCell::new(vec![])); + let d = |id, extra| DropLogger { extra, id: id, log: &log }; + let get = || -> Vec<_> { + let mut m = log.0.borrow_mut(); + let n = m.drain(..); + n.collect() + }; + + { + let _x = ( + d( + 0, + d( + 1, + match () { () if let Some(_) = d(2, Some(true)).extra + && let DropLogger { .. } = d(3, None) => { + None + } + _ => { + Some(true) + } + } + ) + .extra, + ), + d(4, None), + &d(5, None), + d(6, None), + match () { + () if let DropLogger { .. } = d(7, None) + && let DropLogger { .. } = d(8, None) => { + d(9, None) + } + _ => { + // 10 is not constructed + d(10, None) + } + }, + ); + assert_eq!(get(), vec![3, 2, 8, 7, 1]); + } + assert_eq!(get(), vec![0, 4, 6, 9, 5]); + + let _ = std::panic::catch_unwind(|| { + ( + d( + 11, + d( + 12, + match () { + () if let Some(_) = d(13, Some(true)).extra + && let DropLogger { .. } = d(14, None) => { + None + } + _ => { + Some(true) + } + } + ) + .extra, + ), + d(15, None), + &d(16, None), + d(17, None), + match () { + () if let DropLogger { .. } = d(18, None) + && let DropLogger { .. } = d(19, None) + => { + d(20, None) + } + _ => { + // 10 is not constructed + d(21, None) + } + }, + panic::panic_any(InjectedFailure), + ); + }); + assert_eq!(get(), vec![14, 13, 19, 18, 20, 17, 15, 11, 16, 12]); +} diff --git a/tests/ui/pattern/rfc-3637-guard-patterns/only-gather-locals-once.rs b/tests/ui/pattern/rfc-3637-guard-patterns/only-gather-locals-once.rs new file mode 100644 index 00000000000..7bb39ca7bb9 --- /dev/null +++ b/tests/ui/pattern/rfc-3637-guard-patterns/only-gather-locals-once.rs @@ -0,0 +1,15 @@ +//@ check-pass +//! Test that `GatherLocalsVisitor` only visits expressions in guard patterns when checking the +//! expressions, and not a second time when visiting the pattern. If locals are declared inside the +//! the guard expression, it would ICE if visited twice ("evaluated expression more than once"). + +#![feature(guard_patterns)] +#![expect(incomplete_features)] + +fn main() { + match (0,) { + // FIXME(guard_patterns): liveness lints don't work yet; this will ICE without the `_`. + (_ if { let _x = false; _x },) => {} + _ => {} + } +} diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/temporary-early-drop.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/temporary-early-drop.rs new file mode 100644 index 00000000000..9edbc3243c7 --- /dev/null +++ b/tests/ui/rfcs/rfc-2294-if-let-guard/temporary-early-drop.rs @@ -0,0 +1,29 @@ +// issue-103476 +//@ revisions: edition2021 edition2024 +//@ [edition2021] edition: 2021 +//@ [edition2024] edition: 2024 +//@ check-pass + +#![feature(if_let_guard)] +#![allow(irrefutable_let_patterns)] + +struct Pd; + +impl Pd { + fn it(&self) -> It { + todo!() + } +} + +pub struct It<'a>(Box<dyn Tr<'a>>); + +trait Tr<'a> {} + +fn f(m: Option<Pd>) { + match () { + () if let Some(n) = m && let it = n.it() => {} + _ => {} + } +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.rs b/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.rs index ef6871bec7c..0aaee5d1764 100644 --- a/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.rs +++ b/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.rs @@ -1,10 +1,10 @@ #![feature(type_alias_impl_trait)] type T = impl Copy; -//~^ ERROR cannot resolve opaque type #[define_opaque(T)] fn foo() -> T { + //~^ ERROR cannot resolve opaque type None::<&'static T> } diff --git a/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.stderr b/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.stderr index d820df472f9..426a6c29fff 100644 --- a/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.stderr +++ b/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.stderr @@ -1,8 +1,8 @@ error[E0720]: cannot resolve opaque type - --> $DIR/infinite-cycle-involving-weak.rs:3:10 + --> $DIR/infinite-cycle-involving-weak.rs:6:13 | -LL | type T = impl Copy; - | ^^^^^^^^^ cannot resolve opaque type +LL | fn foo() -> T { + | ^ error: aborting due to 1 previous error diff --git a/tests/crashes/139817.rs b/tests/ui/type-alias-impl-trait/match-upvar-discriminant-of-opaque.rs index d439ed4cacb..f4e2cb0c037 100644 --- a/tests/crashes/139817.rs +++ b/tests/ui/type-alias-impl-trait/match-upvar-discriminant-of-opaque.rs @@ -1,8 +1,12 @@ -//@ known-bug: #139817 +#![feature(type_alias_impl_trait)] + fn enum_upvar() { type T = impl Copy; let foo: T = Some((42, std::marker::PhantomData::<T>)); let x = move || match foo { None => (), + //~^ ERROR cannot resolve opaque type }; } + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/match-upvar-discriminant-of-opaque.stderr b/tests/ui/type-alias-impl-trait/match-upvar-discriminant-of-opaque.stderr new file mode 100644 index 00000000000..2bfce2d63a8 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/match-upvar-discriminant-of-opaque.stderr @@ -0,0 +1,9 @@ +error[E0720]: cannot resolve opaque type + --> $DIR/match-upvar-discriminant-of-opaque.rs:7:9 + | +LL | None => (), + | ^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0720`. diff --git a/tests/ui/type-alias-impl-trait/recursive-fn-tait.rs b/tests/ui/type-alias-impl-trait/recursive-fn-tait.rs index 94597adfed0..fe354cc6545 100644 --- a/tests/ui/type-alias-impl-trait/recursive-fn-tait.rs +++ b/tests/ui/type-alias-impl-trait/recursive-fn-tait.rs @@ -13,7 +13,7 @@ pub fn add( n: Diff, m: Diff, ) -> Diff { - //~^ ERROR concrete type differs + //~^ ERROR cannot resolve opaque type move |x: usize| m(n(x)) } diff --git a/tests/ui/type-alias-impl-trait/recursive-fn-tait.stderr b/tests/ui/type-alias-impl-trait/recursive-fn-tait.stderr index 59ff9917612..847f1cc6c2e 100644 --- a/tests/ui/type-alias-impl-trait/recursive-fn-tait.stderr +++ b/tests/ui/type-alias-impl-trait/recursive-fn-tait.stderr @@ -1,14 +1,9 @@ -error: concrete type differs from previous defining opaque type use +error[E0720]: cannot resolve opaque type --> $DIR/recursive-fn-tait.rs:15:6 | LL | ) -> Diff { - | ^^^^ expected `{closure@$DIR/recursive-fn-tait.rs:8:5: 8:16}`, got `{closure@$DIR/recursive-fn-tait.rs:17:5: 17:20}` - | -note: previous use here - --> $DIR/recursive-fn-tait.rs:7:18 - | -LL | pub fn lift() -> Diff { - | ^^^^ + | ^^^^ error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0720`. diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.rs b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.rs index 858f2a2feb6..7803b3b78db 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.rs +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.rs @@ -13,7 +13,7 @@ fn transform<S>() -> impl std::fmt::Display { } #[define_opaque(Op)] fn bad() -> Op { - //~^ ERROR concrete type differs from previous defining opaque type use + //~^ ERROR cannot resolve opaque type transform::<Op>() } diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.stderr b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.stderr index e527b5bc7f8..837df7f5d43 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.stderr +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.stderr @@ -1,14 +1,9 @@ -error: concrete type differs from previous defining opaque type use +error[E0720]: cannot resolve opaque type --> $DIR/recursive-tait-conflicting-defn-2.rs:15:13 | LL | fn bad() -> Op { - | ^^ expected `&&str`, got `impl std::fmt::Display` - | -note: previous use here - --> $DIR/recursive-tait-conflicting-defn-2.rs:7:13 - | -LL | fn foo() -> Op { | ^^ error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0720`. diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs index 90581a98a34..d66ceda5234 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs @@ -23,7 +23,7 @@ pub fn test() -> TestImpl { #[define_opaque(TestImpl)] fn make_option2() -> Option<TestImpl> { - //~^ ERROR concrete type differs from previous defining opaque type use + //~^ ERROR cannot resolve opaque type let inner = make_option().unwrap(); Some(B { inner }) } diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr index 256f13b6221..c7a3381d615 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr @@ -1,14 +1,9 @@ -error: concrete type differs from previous defining opaque type use +error[E0720]: cannot resolve opaque type --> $DIR/recursive-tait-conflicting-defn.rs:25:22 | LL | fn make_option2() -> Option<TestImpl> { - | ^^^^^^^^^^^^^^^^ expected `A`, got `B<TestImpl>` - | -note: previous use here - --> $DIR/recursive-tait-conflicting-defn.rs:20:18 - | -LL | pub fn test() -> TestImpl { - | ^^^^^^^^ + | ^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error +For more information about this error, try `rustc --explain E0720`. diff --git a/triagebot.toml b/triagebot.toml index e62e49b90fb..fd7a861bc92 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -887,6 +887,7 @@ message = "Some changes occurred in HTML/CSS/JS." cc = [ "@GuillaumeGomez", "@jsha", + "@lolbinarycat", ] [mentions."tests/rustdoc-gui/"] |
