about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-16 15:55:30 +0000
committerbors <bors@rust-lang.org>2022-11-16 15:55:30 +0000
commite69336efe035c274f2ee66922cd9cac6015956ea (patch)
tree75586b5b6990744696a789341a292c14f7ddcc78 /src/tools
parent63c748ee23ab7b6706655146f5b7c7f579811803 (diff)
parent972ad00094d8405b1188e5a40c1378f2eb073223 (diff)
downloadrust-e69336efe035c274f2ee66922cd9cac6015956ea.tar.gz
rust-e69336efe035c274f2ee66922cd9cac6015956ea.zip
Auto merge of #104492 - matthiaskrgr:rollup-3xyjynz, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #103750 (Fix some misleading target feature aliases)
 - #104137 (Issue error when -C link-self-contained option is used on unsupported platforms)
 - #104317 (cleanup and dedupe CTFE and Miri error reporting)
 - #104335 (Only do parser recovery on retried macro matching)
 - #104394 (various cleanups to try to reduce the use of spans inside method resolution)
 - #104459 (rustdoc: remove unused JS IIFE from main.js)
 - #104462 (rustdoc: remove pointless CSS `.rightside { padding-right: 2px }`)
 - #104466 (rustdoc: remove no-op CSS `#crate-search-div { display: inline-block }`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/clippy/tests/ui/indexing_slicing_index.stderr6
-rw-r--r--src/tools/miri/src/concurrency/thread.rs3
-rw-r--r--src/tools/miri/src/diagnostics.rs196
-rw-r--r--src/tools/miri/src/helpers.rs3
-rw-r--r--src/tools/miri/src/lib.rs1
-rw-r--r--src/tools/miri/tests/fail/erroneous_const.rs2
-rw-r--r--src/tools/miri/tests/fail/erroneous_const.stderr15
7 files changed, 109 insertions, 117 deletions
diff --git a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
index da5bc38b3b6..d8b6e3f1262 100644
--- a/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
+++ b/src/tools/clippy/tests/ui/indexing_slicing_index.stderr
@@ -4,11 +4,11 @@ error[E0080]: evaluation of `main::{constant#3}` failed
 LL |     const { &ARR[idx4()] }; // Ok, let rustc handle const contexts.
    |              ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
 
-error[E0080]: erroneous constant used
+note: erroneous constant used
   --> $DIR/indexing_slicing_index.rs:31:5
    |
 LL |     const { &ARR[idx4()] }; // Ok, let rustc handle const contexts.
-   |     ^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
+   |     ^^^^^^^^^^^^^^^^^^^^^^
 
 error: indexing may panic
   --> $DIR/indexing_slicing_index.rs:22:5
@@ -65,6 +65,6 @@ error[E0080]: evaluation of constant value failed
 LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
    |                        ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
 
-error: aborting due to 9 previous errors
+error: aborting due to 8 previous errors
 
 For more information about this error, try `rustc --explain E0080`.
diff --git a/src/tools/miri/src/concurrency/thread.rs b/src/tools/miri/src/concurrency/thread.rs
index ac5dcbf0f4f..8fbee9a3522 100644
--- a/src/tools/miri/src/concurrency/thread.rs
+++ b/src/tools/miri/src/concurrency/thread.rs
@@ -712,7 +712,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
             if tcx.is_foreign_item(def_id) {
                 throw_unsup_format!("foreign thread-local statics are not supported");
             }
-            let allocation = tcx.eval_static_initializer(def_id)?;
+            // We don't give a span -- statics don't need that, they cannot be generic or associated.
+            let allocation = this.ctfe_query(None, |tcx| tcx.eval_static_initializer(def_id))?;
             let mut allocation = allocation.inner().clone();
             // This allocation will be deallocated when the thread dies, so it is not in read-only memory.
             allocation.mutability = Mutability::Mut;
diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs
index 0cfa3812e40..7658cea10f9 100644
--- a/src/tools/miri/src/diagnostics.rs
+++ b/src/tools/miri/src/diagnostics.rs
@@ -146,7 +146,9 @@ fn prune_stacktrace<'tcx>(
     }
 }
 
-/// Emit a custom diagnostic without going through the miri-engine machinery
+/// Emit a custom diagnostic without going through the miri-engine machinery.
+///
+/// Returns `Some` if this was regular program termination with a given exit code, `None` otherwise.
 pub fn report_error<'tcx, 'mir>(
     ecx: &InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>,
     e: InterpErrorInfo<'tcx>,
@@ -155,106 +157,102 @@ pub fn report_error<'tcx, 'mir>(
 
     let mut msg = vec![];
 
-    let (title, helps) = match &e.kind() {
-        MachineStop(info) => {
-            let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
-            use TerminationInfo::*;
-            let title = match info {
-                Exit(code) => return Some(*code),
-                Abort(_) => Some("abnormal termination"),
-                UnsupportedInIsolation(_) | Int2PtrWithStrictProvenance =>
-                    Some("unsupported operation"),
-                StackedBorrowsUb { .. } => Some("Undefined Behavior"),
-                Deadlock => Some("deadlock"),
-                MultipleSymbolDefinitions { .. } | SymbolShimClashing { .. } => None,
-            };
-            #[rustfmt::skip]
-            let helps = match info {
-                UnsupportedInIsolation(_) =>
-                    vec![
-                        (None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")),
-                        (None, format!("or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning")),
-                    ],
-                StackedBorrowsUb { help, history, .. } => {
-                    let url = "https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md";
-                    msg.extend(help.clone());
-                    let mut helps = vec![
-                        (None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental")),
-                        (None, format!("see {url} for further information")),
-                    ];
-                    if let Some(TagHistory {created, invalidated, protected}) = history.clone() {
-                        helps.push((Some(created.1), created.0));
-                        if let Some((msg, span)) = invalidated {
-                            helps.push((Some(span), msg));
-                        }
-                        if let Some((protector_msg, protector_span)) = protected {
-                            helps.push((Some(protector_span), protector_msg));
-                        }
+    let (title, helps) = if let MachineStop(info) = e.kind() {
+        let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
+        use TerminationInfo::*;
+        let title = match info {
+            Exit(code) => return Some(*code),
+            Abort(_) => Some("abnormal termination"),
+            UnsupportedInIsolation(_) | Int2PtrWithStrictProvenance =>
+                Some("unsupported operation"),
+            StackedBorrowsUb { .. } => Some("Undefined Behavior"),
+            Deadlock => Some("deadlock"),
+            MultipleSymbolDefinitions { .. } | SymbolShimClashing { .. } => None,
+        };
+        #[rustfmt::skip]
+        let helps = match info {
+            UnsupportedInIsolation(_) =>
+                vec![
+                    (None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")),
+                    (None, format!("or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning")),
+                ],
+            StackedBorrowsUb { help, history, .. } => {
+                let url = "https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md";
+                msg.extend(help.clone());
+                let mut helps = vec![
+                    (None, format!("this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental")),
+                    (None, format!("see {url} for further information")),
+                ];
+                if let Some(TagHistory {created, invalidated, protected}) = history.clone() {
+                    helps.push((Some(created.1), created.0));
+                    if let Some((msg, span)) = invalidated {
+                        helps.push((Some(span), msg));
+                    }
+                    if let Some((protector_msg, protector_span)) = protected {
+                        helps.push((Some(protector_span), protector_msg));
                     }
-                    helps
                 }
-                MultipleSymbolDefinitions { first, first_crate, second, second_crate, .. } =>
-                    vec![
-                        (Some(*first), format!("it's first defined here, in crate `{first_crate}`")),
-                        (Some(*second), format!("then it's defined here again, in crate `{second_crate}`")),
-                    ],
-                SymbolShimClashing { link_name, span } =>
-                    vec![(Some(*span), format!("the `{link_name}` symbol is defined here"))],
-                Int2PtrWithStrictProvenance =>
-                    vec![(None, format!("use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead"))],
-                _ => vec![],
-            };
-            (title, helps)
-        }
-        _ => {
-            #[rustfmt::skip]
-            let title = match e.kind() {
-                Unsupported(_) =>
-                    "unsupported operation",
-                UndefinedBehavior(_) =>
-                    "Undefined Behavior",
-                ResourceExhaustion(_) =>
-                    "resource exhaustion",
-                InvalidProgram(
-                    InvalidProgramInfo::AlreadyReported(_) |
-                    InvalidProgramInfo::Layout(..) |
-                    InvalidProgramInfo::ReferencedConstant
-                ) =>
-                    "post-monomorphization error",
-                kind =>
-                    bug!("This error should be impossible in Miri: {kind:?}"),
-            };
-            #[rustfmt::skip]
-            let helps = match e.kind() {
-                Unsupported(
-                    UnsupportedOpInfo::ThreadLocalStatic(_) |
-                    UnsupportedOpInfo::ReadExternStatic(_) |
-                    UnsupportedOpInfo::PartialPointerOverwrite(_) |
-                    UnsupportedOpInfo::PartialPointerCopy(_) |
-                    UnsupportedOpInfo::ReadPointerAsBytes
-                ) =>
-                    panic!("Error should never be raised by Miri: {kind:?}", kind = e.kind()),
-                Unsupported(
-                    UnsupportedOpInfo::Unsupported(_)
-                ) =>
-                    vec![(None, format!("this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support"))],
-                UndefinedBehavior(UndefinedBehaviorInfo::AlignmentCheckFailed { .. })
-                    if ecx.machine.check_alignment == AlignmentCheck::Symbolic
-                =>
-                    vec![
-                        (None, format!("this usually indicates that your program performed an invalid operation and caused Undefined Behavior")),
-                        (None, format!("but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives")),
-                    ],
-                UndefinedBehavior(_) =>
-                    vec![
-                        (None, format!("this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior")),
-                        (None, format!("see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information")),
-                    ],
-                InvalidProgram(_) | ResourceExhaustion(_) | MachineStop(_) =>
-                    vec![],
-            };
-            (Some(title), helps)
-        }
+                helps
+            }
+            MultipleSymbolDefinitions { first, first_crate, second, second_crate, .. } =>
+                vec![
+                    (Some(*first), format!("it's first defined here, in crate `{first_crate}`")),
+                    (Some(*second), format!("then it's defined here again, in crate `{second_crate}`")),
+                ],
+            SymbolShimClashing { link_name, span } =>
+                vec![(Some(*span), format!("the `{link_name}` symbol is defined here"))],
+            Int2PtrWithStrictProvenance =>
+                vec![(None, format!("use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead"))],
+            _ => vec![],
+        };
+        (title, helps)
+    } else {
+        #[rustfmt::skip]
+        let title = match e.kind() {
+            UndefinedBehavior(_) =>
+                "Undefined Behavior",
+            ResourceExhaustion(_) =>
+                "resource exhaustion",
+            Unsupported(
+                // We list only the ones that can actually happen.
+                UnsupportedOpInfo::Unsupported(_)
+            ) =>
+                "unsupported operation",
+            InvalidProgram(
+                // We list only the ones that can actually happen.
+                InvalidProgramInfo::AlreadyReported(_) |
+                InvalidProgramInfo::Layout(..)
+            ) =>
+                "post-monomorphization error",
+            kind =>
+                bug!("This error should be impossible in Miri: {kind:?}"),
+        };
+        #[rustfmt::skip]
+        let helps = match e.kind() {
+            Unsupported(_) =>
+                vec![(None, format!("this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support"))],
+            UndefinedBehavior(UndefinedBehaviorInfo::AlignmentCheckFailed { .. })
+                if ecx.machine.check_alignment == AlignmentCheck::Symbolic
+            =>
+                vec![
+                    (None, format!("this usually indicates that your program performed an invalid operation and caused Undefined Behavior")),
+                    (None, format!("but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives")),
+                ],
+            UndefinedBehavior(_) =>
+                vec![
+                    (None, format!("this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior")),
+                    (None, format!("see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information")),
+                ],
+            InvalidProgram(
+                InvalidProgramInfo::AlreadyReported(rustc_errors::ErrorGuaranteed { .. })
+            ) => {
+                // This got already reported. No point in reporting it again.
+                return None;
+            }
+            _ =>
+                vec![],
+        };
+        (Some(title), helps)
     };
 
     let stacktrace = ecx.generate_stacktrace();
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs
index f98727186c4..1fdf3e52a8b 100644
--- a/src/tools/miri/src/helpers.rs
+++ b/src/tools/miri/src/helpers.rs
@@ -117,7 +117,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
         let this = self.eval_context_ref();
         let instance = this.resolve_path(path);
         let cid = GlobalId { instance, promoted: None };
-        let const_val = this.eval_to_allocation(cid)?;
+        // We don't give a span -- this isn't actually used directly by the program anyway.
+        let const_val = this.eval_global(cid, None)?;
         this.read_scalar(&const_val.into())
     }
 
diff --git a/src/tools/miri/src/lib.rs b/src/tools/miri/src/lib.rs
index 8028ce75354..66df0d737c0 100644
--- a/src/tools/miri/src/lib.rs
+++ b/src/tools/miri/src/lib.rs
@@ -46,6 +46,7 @@ extern crate rustc_ast;
 extern crate rustc_middle;
 extern crate rustc_const_eval;
 extern crate rustc_data_structures;
+extern crate rustc_errors;
 extern crate rustc_hir;
 extern crate rustc_index;
 extern crate rustc_session;
diff --git a/src/tools/miri/tests/fail/erroneous_const.rs b/src/tools/miri/tests/fail/erroneous_const.rs
index d14998ccba2..d37837c7193 100644
--- a/src/tools/miri/tests/fail/erroneous_const.rs
+++ b/src/tools/miri/tests/fail/erroneous_const.rs
@@ -11,7 +11,7 @@ impl<T> PrintName<T> {
 
 fn no_codegen<T>() {
     if false {
-        let _ = PrintName::<T>::VOID; //~ERROR: post-monomorphization error
+        let _ = PrintName::<T>::VOID; //~NOTE: constant
     }
 }
 fn main() {
diff --git a/src/tools/miri/tests/fail/erroneous_const.stderr b/src/tools/miri/tests/fail/erroneous_const.stderr
index 8138d69f403..c32ebf67a11 100644
--- a/src/tools/miri/tests/fail/erroneous_const.stderr
+++ b/src/tools/miri/tests/fail/erroneous_const.stderr
@@ -6,21 +6,12 @@ LL |     const VOID: ! = panic!();
    |
    = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: post-monomorphization error: referenced constant has errors
+note: erroneous constant used
   --> $DIR/erroneous_const.rs:LL:CC
    |
 LL |         let _ = PrintName::<T>::VOID;
-   |                 ^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
-   |
-   = note: inside `no_codegen::<i32>` at $DIR/erroneous_const.rs:LL:CC
-note: inside `main` at $DIR/erroneous_const.rs:LL:CC
-  --> $DIR/erroneous_const.rs:LL:CC
-   |
-LL |     no_codegen::<i32>();
-   |     ^^^^^^^^^^^^^^^^^^^
-
-note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
+   |                 ^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
 For more information about this error, try `rustc --explain E0080`.