about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-12-16 08:26:32 +0000
committerbors <bors@rust-lang.org>2024-12-16 08:26:32 +0000
commiteedc229049b937a007a79ee6fc2801bfc484240e (patch)
tree5613145d6c4d180aac1e37d68d7ba701e36bd694 /compiler
parentf2b91ccbc27cb06369aa2dd934ff219e156408a8 (diff)
parent0a779720f43aaaa33c67f8b97a9dbb6e1b4fccb8 (diff)
downloadrust-eedc229049b937a007a79ee6fc2801bfc484240e.tar.gz
rust-eedc229049b937a007a79ee6fc2801bfc484240e.zip
Auto merge of #134374 - matthiaskrgr:rollup-2tbbrxq, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #134314 (Make sure to use normalized ty for unevaluated const in default struct value)
 - #134342 (crashes: more tests)
 - #134357 (Fix `trimmed_def_paths` ICE in the function ptr comparison lint)
 - #134369 (Update spelling of "referring")
 - #134372 (Disable `tests/ui/associated-consts/issue-93775.rs` on windows msvc)

Failed merges:

 - #134365 (Rename `rustc_mir_build::build` to `builder`)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_lint/messages.ftl2
-rw-r--r--compiler/rustc_lint/src/lints.rs54
-rw-r--r--compiler/rustc_lint/src/types.rs39
-rw-r--r--compiler/rustc_lint/src/unqualified_local_imports.rs2
-rw-r--r--compiler/rustc_mir_build/src/build/expr/into.rs16
5 files changed, 72 insertions, 41 deletions
diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl
index 48d6d6bbf67..2ecd5051f9e 100644
--- a/compiler/rustc_lint/messages.ftl
+++ b/compiler/rustc_lint/messages.ftl
@@ -813,7 +813,7 @@ lint_unexpected_cfg_doc_cargo = see <https://doc.rust-lang.org/nightly/rustc/che
 lint_unexpected_cfg_doc_rustc = see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
 
 lint_unexpected_cfg_from_external_macro_origin = using a cfg inside a {$macro_kind} will use the cfgs from the destination crate and not the ones from the defining crate
-lint_unexpected_cfg_from_external_macro_refer = try refering to `{$macro_name}` crate for guidance on how handle this unexpected cfg
+lint_unexpected_cfg_from_external_macro_refer = try referring to `{$macro_name}` crate for guidance on how handle this unexpected cfg
 lint_unexpected_cfg_name = unexpected `cfg` condition name: `{$name}`
 lint_unexpected_cfg_name_expected_names = expected names are: {$possibilities}{$and_more ->
         [0] {""}
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 4977b3971bd..df89fe6f701 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -1816,14 +1816,14 @@ pub(crate) enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
 }
 
 #[derive(LintDiagnostic)]
-pub(crate) enum UnpredictableFunctionPointerComparisons<'a> {
+pub(crate) enum UnpredictableFunctionPointerComparisons<'a, 'tcx> {
     #[diag(lint_unpredictable_fn_pointer_comparisons)]
     #[note(lint_note_duplicated_fn)]
     #[note(lint_note_deduplicated_fn)]
     #[note(lint_note_visit_fn_addr_eq)]
     Suggestion {
         #[subdiagnostic]
-        sugg: UnpredictableFunctionPointerComparisonsSuggestion<'a>,
+        sugg: UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx>,
     },
     #[diag(lint_unpredictable_fn_pointer_comparisons)]
     #[note(lint_note_duplicated_fn)]
@@ -1833,22 +1833,40 @@ pub(crate) enum UnpredictableFunctionPointerComparisons<'a> {
 }
 
 #[derive(Subdiagnostic)]
-#[multipart_suggestion(
-    lint_fn_addr_eq_suggestion,
-    style = "verbose",
-    applicability = "maybe-incorrect"
-)]
-pub(crate) struct UnpredictableFunctionPointerComparisonsSuggestion<'a> {
-    pub ne: &'a str,
-    pub cast_right: String,
-    pub deref_left: &'a str,
-    pub deref_right: &'a str,
-    #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
-    pub left: Span,
-    #[suggestion_part(code = ", {deref_right}")]
-    pub middle: Span,
-    #[suggestion_part(code = "{cast_right})")]
-    pub right: Span,
+pub(crate) enum UnpredictableFunctionPointerComparisonsSuggestion<'a, 'tcx> {
+    #[multipart_suggestion(
+        lint_fn_addr_eq_suggestion,
+        style = "verbose",
+        applicability = "maybe-incorrect"
+    )]
+    FnAddrEq {
+        ne: &'a str,
+        deref_left: &'a str,
+        deref_right: &'a str,
+        #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
+        left: Span,
+        #[suggestion_part(code = ", {deref_right}")]
+        middle: Span,
+        #[suggestion_part(code = ")")]
+        right: Span,
+    },
+    #[multipart_suggestion(
+        lint_fn_addr_eq_suggestion,
+        style = "verbose",
+        applicability = "maybe-incorrect"
+    )]
+    FnAddrEqWithCast {
+        ne: &'a str,
+        deref_left: &'a str,
+        deref_right: &'a str,
+        fn_sig: rustc_middle::ty::PolyFnSig<'tcx>,
+        #[suggestion_part(code = "{ne}std::ptr::fn_addr_eq({deref_left}")]
+        left: Span,
+        #[suggestion_part(code = ", {deref_right}")]
+        middle: Span,
+        #[suggestion_part(code = " as {fn_sig})")]
+        right: Span,
+    },
 }
 
 pub(crate) struct ImproperCTypes<'a> {
diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs
index 33650be056d..33d31d27c73 100644
--- a/compiler/rustc_lint/src/types.rs
+++ b/compiler/rustc_lint/src/types.rs
@@ -483,29 +483,36 @@ fn lint_fn_pointer<'tcx>(
     let middle = l_span.shrink_to_hi().until(r_span.shrink_to_lo());
     let right = r_span.shrink_to_hi().until(e.span.shrink_to_hi());
 
-    // We only check for a right cast as `FnDef` == `FnPtr` is not possible,
-    // only `FnPtr == FnDef` is possible.
-    let cast_right = if !r_ty.is_fn_ptr() {
-        let fn_sig = r_ty.fn_sig(cx.tcx);
-        format!(" as {fn_sig}")
-    } else {
-        String::new()
-    };
+    let sugg =
+        // We only check for a right cast as `FnDef` == `FnPtr` is not possible,
+        // only `FnPtr == FnDef` is possible.
+        if !r_ty.is_fn_ptr() {
+            let fn_sig = r_ty.fn_sig(cx.tcx);
 
-    cx.emit_span_lint(
-        UNPREDICTABLE_FUNCTION_POINTER_COMPARISONS,
-        e.span,
-        UnpredictableFunctionPointerComparisons::Suggestion {
-            sugg: UnpredictableFunctionPointerComparisonsSuggestion {
+            UnpredictableFunctionPointerComparisonsSuggestion::FnAddrEqWithCast {
                 ne,
+                fn_sig,
                 deref_left,
                 deref_right,
                 left,
                 middle,
                 right,
-                cast_right,
-            },
-        },
+            }
+        } else {
+            UnpredictableFunctionPointerComparisonsSuggestion::FnAddrEq {
+                ne,
+                deref_left,
+                deref_right,
+                left,
+                middle,
+                right,
+            }
+        };
+
+    cx.emit_span_lint(
+        UNPREDICTABLE_FUNCTION_POINTER_COMPARISONS,
+        e.span,
+        UnpredictableFunctionPointerComparisons::Suggestion { sugg },
     );
 }
 
diff --git a/compiler/rustc_lint/src/unqualified_local_imports.rs b/compiler/rustc_lint/src/unqualified_local_imports.rs
index bea01a33bd6..d4b39d91a71 100644
--- a/compiler/rustc_lint/src/unqualified_local_imports.rs
+++ b/compiler/rustc_lint/src/unqualified_local_imports.rs
@@ -31,7 +31,7 @@ declare_lint! {
     ///
     /// This lint is meant to be used with the (unstable) rustfmt setting `group_imports = "StdExternalCrate"`.
     /// That setting makes rustfmt group `self::`, `super::`, and `crate::` imports separately from those
-    /// refering to other crates. However, rustfmt cannot know whether `use c::S;` refers to a local module `c`
+    /// referring to other crates. However, rustfmt cannot know whether `use c::S;` refers to a local module `c`
     /// or an external crate `c`, so it always gets categorized as an import from another crate.
     /// To ensure consistent grouping of imports from the local crate, all local imports must
     /// start with `self::`, `super::`, or `crate::`. This lint can be used to enforce that style.
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs
index a3d5376dcd4..0ac1ae56d59 100644
--- a/compiler/rustc_mir_build/src/build/expr/into.rs
+++ b/compiler/rustc_mir_build/src/build/expr/into.rs
@@ -367,14 +367,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                             .collect()
                     }
                     AdtExprBase::DefaultFields(field_types) => {
-                        itertools::zip_eq(field_names, &**field_types)
-                            .map(|(n, ty)| match fields_map.get(&n) {
+                        itertools::zip_eq(field_names, field_types)
+                            .map(|(n, &ty)| match fields_map.get(&n) {
                                 Some(v) => v.clone(),
                                 None => match variant.fields[n].value {
                                     Some(def) => {
-                                        let value = Const::from_unevaluated(this.tcx, def)
-                                            .instantiate(this.tcx, args);
-                                        this.literal_operand(expr_span, value)
+                                        let value = Const::Unevaluated(
+                                            UnevaluatedConst::new(def, args),
+                                            ty,
+                                        );
+                                        Operand::Constant(Box::new(ConstOperand {
+                                            span: expr_span,
+                                            user_ty: None,
+                                            const_: value,
+                                        }))
                                     }
                                     None => {
                                         let name = variant.fields[n].name;