Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #121294

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});

// We're done if we found errors, but we already emitted them.
if let Some(reported) = reported {
assert!(errors.is_empty());
if let Some(reported) = reported
&& errors.is_empty()
{
return reported;
}
assert!(!errors.is_empty());
Expand Down
30 changes: 17 additions & 13 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ impl Level {
}

/// Converts a lower-case string to a level. This will never construct the expect
/// level as that would require a [`LintExpectationId`]
pub fn from_str(x: &str) -> Option<Level> {
/// level as that would require a [`LintExpectationId`].
pub fn from_str(x: &str) -> Option<Self> {
match x {
"allow" => Some(Level::Allow),
"warn" => Some(Level::Warn),
Expand All @@ -238,17 +238,21 @@ impl Level {
}
}

/// Converts a symbol to a level.
pub fn from_attr(attr: &Attribute) -> Option<Level> {
match attr.name_or_empty() {
sym::allow => Some(Level::Allow),
sym::expect => Some(Level::Expect(LintExpectationId::Unstable {
attr_id: attr.id,
lint_index: None,
})),
sym::warn => Some(Level::Warn),
sym::deny => Some(Level::Deny),
sym::forbid => Some(Level::Forbid),
/// Converts an `Attribute` to a level.
pub fn from_attr(attr: &Attribute) -> Option<Self> {
Self::from_symbol(attr.name_or_empty(), Some(attr.id))
}

/// Converts a `Symbol` to a level.
pub fn from_symbol(s: Symbol, id: Option<AttrId>) -> Option<Self> {
match (s, id) {
(sym::allow, _) => Some(Level::Allow),
(sym::expect, Some(attr_id)) => {
Some(Level::Expect(LintExpectationId::Unstable { attr_id, lint_index: None }))
}
(sym::warn, _) => Some(Level::Warn),
(sym::deny, _) => Some(Level::Deny),
(sym::forbid, _) => Some(Level::Forbid),
_ => None,
}
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_resolve/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ resolve_consider_declaring_with_pub =
resolve_consider_marking_as_pub =
consider marking `{$ident}` as `pub` in the imported module

resolve_consider_move_macro_position =
consider moving the definition of `{$ident}` before this call


resolve_const_not_member_of_trait =
const `{$const_}` is not a member of trait `{$trait_}`
.label = not a member of trait `{$trait_}`
Expand Down Expand Up @@ -186,6 +190,9 @@ resolve_lowercase_self =
attempt to use a non-constant value in a constant
.suggestion = try using `Self`

resolve_macro_defined_later =
a macro with the same name exists, but it appears later at here

resolve_macro_expected_found =
expected {$expected}, found {$found} `{$macro_path}`

Expand Down
23 changes: 22 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use rustc_span::{BytePos, Span, SyntaxContext};
use thin_vec::{thin_vec, ThinVec};

use crate::errors::{AddedMacroUse, ChangeImportBinding, ChangeImportBindingSuggestion};
use crate::errors::{ConsiderAddingADerive, ExplicitUnsafeTraits, MaybeMissingMacroRulesName};
use crate::errors::{
ConsiderAddingADerive, ExplicitUnsafeTraits, MacroDefinedLater, MacroSuggMovePosition,
MaybeMissingMacroRulesName,
};
use crate::imports::{Import, ImportKind};
use crate::late::{PatternSource, Rib};
use crate::{errors as errs, BindingKey};
Expand Down Expand Up @@ -1442,6 +1445,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
return;
}

let unused_macro = self.unused_macros.iter().find_map(|(def_id, (_, unused_ident))| {
if unused_ident.name == ident.name {
Some((def_id.clone(), unused_ident.clone()))
} else {
None
}
});

if let Some((def_id, unused_ident)) = unused_macro {
let scope = self.local_macro_def_scopes[&def_id];
let parent_nearest = parent_scope.module.nearest_parent_mod();
if Some(parent_nearest) == scope.opt_def_id() {
err.subdiagnostic(MacroDefinedLater { span: unused_ident.span });
err.subdiagnostic(MacroSuggMovePosition { span: ident.span, ident });
return;
}
}

if self.macro_names.contains(&ident.normalize_to_macros_2_0()) {
err.subdiagnostic(self.dcx(), AddedMacroUse);
return;
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_resolve/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,21 @@ pub(crate) struct ExplicitUnsafeTraits {
pub(crate) ident: Ident,
}

#[derive(Subdiagnostic)]
#[note(resolve_macro_defined_later)]
pub(crate) struct MacroDefinedLater {
#[primary_span]
pub(crate) span: Span,
}

#[derive(Subdiagnostic)]
#[label(resolve_consider_move_macro_position)]
pub(crate) struct MacroSuggMovePosition {
#[primary_span]
pub(crate) span: Span,
pub(crate) ident: Ident,
}

#[derive(Subdiagnostic)]
#[note(resolve_missing_macro_rules_name)]
pub(crate) struct MaybeMissingMacroRulesName {
Expand Down
14 changes: 14 additions & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::num::FpCategory;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `RADIX` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_radix"]
pub const RADIX: u32 = f32::RADIX;

/// Number of significant digits in base 2.
Expand All @@ -52,6 +53,7 @@ pub const RADIX: u32 = f32::RADIX;
since = "TBD",
note = "replaced by the `MANTISSA_DIGITS` associated constant on `f32`"
)]
#[rustc_diagnostic_item = "f32_legacy_const_mantissa_dig"]
pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;

/// Approximate number of significant digits in base 10.
Expand All @@ -69,6 +71,7 @@ pub const MANTISSA_DIGITS: u32 = f32::MANTISSA_DIGITS;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `DIGITS` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_digits"]
pub const DIGITS: u32 = f32::DIGITS;

/// [Machine epsilon] value for `f32`.
Expand All @@ -90,6 +93,7 @@ pub const DIGITS: u32 = f32::DIGITS;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `EPSILON` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_epsilon"]
pub const EPSILON: f32 = f32::EPSILON;

/// Smallest finite `f32` value.
Expand All @@ -107,6 +111,7 @@ pub const EPSILON: f32 = f32::EPSILON;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_min"]
pub const MIN: f32 = f32::MIN;

/// Smallest positive normal `f32` value.
Expand All @@ -124,6 +129,7 @@ pub const MIN: f32 = f32::MIN;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN_POSITIVE` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_min_positive"]
pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;

/// Largest finite `f32` value.
Expand All @@ -141,6 +147,7 @@ pub const MIN_POSITIVE: f32 = f32::MIN_POSITIVE;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MAX` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_max"]
pub const MAX: f32 = f32::MAX;

/// One greater than the minimum possible normal power of 2 exponent.
Expand All @@ -158,6 +165,7 @@ pub const MAX: f32 = f32::MAX;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN_EXP` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_min_exp"]
pub const MIN_EXP: i32 = f32::MIN_EXP;

/// Maximum possible power of 2 exponent.
Expand All @@ -175,6 +183,7 @@ pub const MIN_EXP: i32 = f32::MIN_EXP;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MAX_EXP` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_max_exp"]
pub const MAX_EXP: i32 = f32::MAX_EXP;

/// Minimum possible normal power of 10 exponent.
Expand All @@ -192,6 +201,7 @@ pub const MAX_EXP: i32 = f32::MAX_EXP;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN_10_EXP` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_min_10_exp"]
pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;

/// Maximum possible power of 10 exponent.
Expand All @@ -209,6 +219,7 @@ pub const MIN_10_EXP: i32 = f32::MIN_10_EXP;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MAX_10_EXP` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_max_10_exp"]
pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;

/// Not a Number (NaN).
Expand All @@ -226,6 +237,7 @@ pub const MAX_10_EXP: i32 = f32::MAX_10_EXP;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `NAN` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_nan"]
pub const NAN: f32 = f32::NAN;

/// Infinity (∞).
Expand All @@ -243,6 +255,7 @@ pub const NAN: f32 = f32::NAN;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `INFINITY` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_infinity"]
pub const INFINITY: f32 = f32::INFINITY;

/// Negative infinity (−∞).
Expand All @@ -260,6 +273,7 @@ pub const INFINITY: f32 = f32::INFINITY;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `NEG_INFINITY` associated constant on `f32`")]
#[rustc_diagnostic_item = "f32_legacy_const_neg_infinity"]
pub const NEG_INFINITY: f32 = f32::NEG_INFINITY;

/// Basic mathematical constants.
Expand Down
14 changes: 14 additions & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::num::FpCategory;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `RADIX` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_radix"]
pub const RADIX: u32 = f64::RADIX;

/// Number of significant digits in base 2.
Expand All @@ -52,6 +53,7 @@ pub const RADIX: u32 = f64::RADIX;
since = "TBD",
note = "replaced by the `MANTISSA_DIGITS` associated constant on `f64`"
)]
#[rustc_diagnostic_item = "f64_legacy_const_mantissa_dig"]
pub const MANTISSA_DIGITS: u32 = f64::MANTISSA_DIGITS;

/// Approximate number of significant digits in base 10.
Expand All @@ -69,6 +71,7 @@ pub const MANTISSA_DIGITS: u32 = f64::MANTISSA_DIGITS;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `DIGITS` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_digits"]
pub const DIGITS: u32 = f64::DIGITS;

/// [Machine epsilon] value for `f64`.
Expand All @@ -90,6 +93,7 @@ pub const DIGITS: u32 = f64::DIGITS;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `EPSILON` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_epsilon"]
pub const EPSILON: f64 = f64::EPSILON;

/// Smallest finite `f64` value.
Expand All @@ -107,6 +111,7 @@ pub const EPSILON: f64 = f64::EPSILON;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_min"]
pub const MIN: f64 = f64::MIN;

/// Smallest positive normal `f64` value.
Expand All @@ -124,6 +129,7 @@ pub const MIN: f64 = f64::MIN;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN_POSITIVE` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_min_positive"]
pub const MIN_POSITIVE: f64 = f64::MIN_POSITIVE;

/// Largest finite `f64` value.
Expand All @@ -141,6 +147,7 @@ pub const MIN_POSITIVE: f64 = f64::MIN_POSITIVE;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MAX` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_max"]
pub const MAX: f64 = f64::MAX;

/// One greater than the minimum possible normal power of 2 exponent.
Expand All @@ -158,6 +165,7 @@ pub const MAX: f64 = f64::MAX;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN_EXP` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_min_exp"]
pub const MIN_EXP: i32 = f64::MIN_EXP;

/// Maximum possible power of 2 exponent.
Expand All @@ -175,6 +183,7 @@ pub const MIN_EXP: i32 = f64::MIN_EXP;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MAX_EXP` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_max_exp"]
pub const MAX_EXP: i32 = f64::MAX_EXP;

/// Minimum possible normal power of 10 exponent.
Expand All @@ -192,6 +201,7 @@ pub const MAX_EXP: i32 = f64::MAX_EXP;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN_10_EXP` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_min_10_exp"]
pub const MIN_10_EXP: i32 = f64::MIN_10_EXP;

/// Maximum possible power of 10 exponent.
Expand All @@ -209,6 +219,7 @@ pub const MIN_10_EXP: i32 = f64::MIN_10_EXP;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `MAX_10_EXP` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_max_10_exp"]
pub const MAX_10_EXP: i32 = f64::MAX_10_EXP;

/// Not a Number (NaN).
Expand All @@ -226,6 +237,7 @@ pub const MAX_10_EXP: i32 = f64::MAX_10_EXP;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `NAN` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_nan"]
pub const NAN: f64 = f64::NAN;

/// Infinity (∞).
Expand All @@ -243,6 +255,7 @@ pub const NAN: f64 = f64::NAN;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `INFINITY` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_infinity"]
pub const INFINITY: f64 = f64::INFINITY;

/// Negative infinity (−∞).
Expand All @@ -260,6 +273,7 @@ pub const INFINITY: f64 = f64::INFINITY;
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[deprecated(since = "TBD", note = "replaced by the `NEG_INFINITY` associated constant on `f64`")]
#[rustc_diagnostic_item = "f64_legacy_const_neg_infinity"]
pub const NEG_INFINITY: f64 = f64::NEG_INFINITY;

/// Basic mathematical constants.
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3507,6 +3507,7 @@ macro_rules! int_impl {
#[rustc_promotable]
#[rustc_const_stable(feature = "const_min_value", since = "1.32.0")]
#[deprecated(since = "TBD", note = "replaced by the `MIN` associated constant on this type")]
#[rustc_diagnostic_item = concat!(stringify!($SelfT), "_legacy_fn_min_value")]
pub const fn min_value() -> Self {
Self::MIN
}
Expand All @@ -3520,6 +3521,7 @@ macro_rules! int_impl {
#[rustc_promotable]
#[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
#[deprecated(since = "TBD", note = "replaced by the `MAX` associated constant on this type")]
#[rustc_diagnostic_item = concat!(stringify!($SelfT), "_legacy_fn_max_value")]
pub const fn max_value() -> Self {
Self::MAX
}
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/num/shells/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ macro_rules! int_module {
///
#[$attr]
#[deprecated(since = "TBD", note = "replaced by the `MIN` associated constant on this type")]
#[rustc_diagnostic_item = concat!(stringify!($T), "_legacy_const_min")]
pub const MIN: $T = $T::MIN;

#[doc = concat!(
Expand All @@ -39,6 +40,7 @@ macro_rules! int_module {
///
#[$attr]
#[deprecated(since = "TBD", note = "replaced by the `MAX` associated constant on this type")]
#[rustc_diagnostic_item = concat!(stringify!($T), "_legacy_const_max")]
pub const MAX: $T = $T::MAX;
)
}
Loading
Loading