diff --git a/CHANGELOG.md b/CHANGELOG.md index eec143420d..d43b9627c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -86,6 +86,8 @@ - Load a compiled module's interface into its first dependent without decoding it again, and keep the syntax tree nodes the built-in frontend pass leaves unchanged instead of copying them. https://github.com/jfrolich/rescript-rust/pull/89 https://github.com/jfrolich/rescript-rust/pull/85 +- Print the path of a value or type for a deprecation warning only when the item is deprecated, instead of on every use. https://github.com/jfrolich/rescript-rust/pull/98 + - Compute the item digests and item references of a compiled module's interface once, when it is published, instead of decoding the stored interface again for each. https://github.com/jfrolich/rescript-rust/pull/87 - Type-check faster: lower argument levels directly, settle the checks before binding a type variable in one walk, and skip the inclusion check of a unit against its own inferred signature. https://github.com/jfrolich/rescript-rust/pull/84 diff --git a/compiler-rust/src/types/typecore.rs b/compiler-rust/src/types/typecore.rs index a183e2ccdd..c8a4d71eae 100644 --- a/compiler-rust/src/types/typecore.rs +++ b/compiler-rust/src/types/typecore.rs @@ -7667,6 +7667,20 @@ fn deprecated_warning_from_attrs( .map(|(reason, can_be_automigrated)| deprecated_warning(name, reason, can_be_automigrated))) } +/// `deprecated_warning_from_attrs` for an item named by its path. The name is +/// printed only for a deprecated item: this runs on every use of a value or +/// type, and almost none of them is deprecated. +fn deprecated_warning_for_path( + path: &Path, + attrs: &[crate::types::decl::Attribute], +) -> Result, crate::types::DeclLoc> { + Ok( + deprecated_attr_payload(attrs)?.map(|(reason, can_be_automigrated)| { + deprecated_warning(path.name().as_str(), reason, can_be_automigrated) + }), + ) +} + /// `Builtin_attributes.deprecated_of_attrs` (builtin_attributes.ml:59-62): /// `string_of_opt_payload` of the first `deprecated` attribute, the record /// form reading as `""`; `Err` where it raises. @@ -7835,14 +7849,14 @@ fn deprecated_warning_for_value( path: &Path, desc: &ValueDescription, ) -> Result, crate::types::DeclLoc> { - deprecated_warning_from_attrs(path.name().as_str(), &desc.val_attributes) + deprecated_warning_for_path(path, &desc.val_attributes) } fn deprecated_warning_for_type( path: &Path, decl: &crate::types::decl::TypeDeclaration, ) -> Result, crate::types::DeclLoc> { - deprecated_warning_from_attrs(path.name().as_str(), &decl.type_attributes) + deprecated_warning_for_path(path, &decl.type_attributes) } /// Type check an expression against an expected type.