summaryrefslogtreecommitdiff
path: root/tests/ui
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-04-22 15:15:51 +0000
committerbors <bors@rust-lang.org>2023-04-22 15:15:51 +0000
commit4396ceca05585ad887976b985cfa8dd8e58cd512 (patch)
tree57ccce436c3230950a9a7dab80eb88cf55cde126 /tests/ui
parent39cf520299794e6c1b6b471db5d9935e0c6271ab (diff)
parent964600b38ed0aeec8d3869aa38d31b3e1553066a (diff)
downloadrust-4396ceca05585ad887976b985cfa8dd8e58cd512.tar.gz
Auto merge of #109753 - compiler-errors:replenish-region-constraints, r=aliemjay
Clone region var origins instead of taking them in borrowck Fixes an issue with the new solver where reporting a borrow-checker error ICEs because it calls `InferCtxt::evaluate_obligation`. This also removes a handful of unnecessary `tcx.infer_ctxt().build()` calls that are only there to mitigate this same exact issue, but with the old solver. Fixes compiler-errors/next-solver-hir-issues#12. ---- This implements `@aliemjay's` solution where we just don't *take* the region constraints, but clone them. This potentially makes it easier to write a bug about taking region constraints twice or never at all, but again, not many folks are touching this code.
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/traits/new-solver/borrowck-error.rs11
-rw-r--r--tests/ui/traits/new-solver/borrowck-error.stderr12
2 files changed, 23 insertions, 0 deletions
diff --git a/tests/ui/traits/new-solver/borrowck-error.rs b/tests/ui/traits/new-solver/borrowck-error.rs
new file mode 100644
index 00000000000..4787a2c7e11
--- /dev/null
+++ b/tests/ui/traits/new-solver/borrowck-error.rs
@@ -0,0 +1,11 @@
+// compile-flags: -Ztrait-solver=next
+
+use std::collections::HashMap;
+
+fn foo() -> &'static HashMap<i32, i32>
+{
+ &HashMap::new()
+ //~^ ERROR cannot return reference to temporary value
+}
+
+fn main() {}
diff --git a/tests/ui/traits/new-solver/borrowck-error.stderr b/tests/ui/traits/new-solver/borrowck-error.stderr
new file mode 100644
index 00000000000..a7d8201747a
--- /dev/null
+++ b/tests/ui/traits/new-solver/borrowck-error.stderr
@@ -0,0 +1,12 @@
+error[E0515]: cannot return reference to temporary value
+ --> $DIR/borrowck-error.rs:7:5
+ |
+LL | &HashMap::new()
+ | ^--------------
+ | ||
+ | |temporary value created here
+ | returns a reference to data owned by the current function
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0515`.