Skip to content

Commit b44e14f

Browse files
committed
Auto merge of rust-lang#135273 - dianne:argument-patterns-are-not-boring, r=lqd
Remove special-casing for argument patterns in MIR typeck (attempt to fix perf regression of rust-lang#133858) See [my comment](rust-lang#133858 (comment)) on rust-lang#133858 for more information. This is just a guess as to what went wrong, and I haven't been able to get the profiler running locally, so I'll need a perf run to make sure this actually helps. There's one test's stderr that suffers a bit, but this was just papering over the issue anyway. Making region errors point to the correct constraints in the presence of invariance/contravariance is a broader problem; the current way it's handled is mostly based on guesswork, luck, and hoping it works out. Properly handling that (somehow) would improve the test's stderr without the hack that this PR reverts.
2 parents 67951d9 + 72945be commit b44e14f

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -892,19 +892,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
892892
Some(l) if !body.local_decls[l].is_user_variable() => {
893893
ConstraintCategory::Boring
894894
}
895-
Some(_)
896-
if let Some(body_id) = tcx
897-
.hir_node_by_def_id(body.source.def_id().expect_local())
898-
.body_id()
899-
&& let params = tcx.hir().body(body_id).params
900-
&& params
901-
.iter()
902-
.any(|param| param.span.contains(stmt.source_info.span)) =>
903-
{
904-
// Assignments generated from lowering argument patterns shouldn't be called
905-
// "assignments" in diagnostics and aren't interesting to blame for errors.
906-
ConstraintCategory::Boring
907-
}
908895
_ => ConstraintCategory::Assignment,
909896
};
910897
debug!(
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) {
2-
*v = x;
32
//~^ ERROR lifetime may not live long enough
3+
*v = x;
44
}
55

66
fn main() { }

tests/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-2.stderr

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
error: lifetime may not live long enough
2-
--> $DIR/ex3-both-anon-regions-2.rs:2:5
2+
--> $DIR/ex3-both-anon-regions-2.rs:1:14
33
|
44
LL | fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) {
5-
| - - let's call the lifetime of this reference `'1`
6-
| |
7-
| let's call the lifetime of this reference `'2`
8-
LL | *v = x;
9-
| ^^^^^^ assignment requires that `'1` must outlive `'2`
5+
| ^^^^^^^^^ - - let's call the lifetime of this reference `'1`
6+
| | |
7+
| | let's call the lifetime of this reference `'2`
8+
| assignment requires that `'1` must outlive `'2`
109
|
10+
= note: requirement occurs because of a mutable reference to `&u8`
11+
= note: mutable references are invariant over their type parameter
12+
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
1113
help: consider introducing a named lifetime parameter
1214
|
1315
LL | fn foo<'a>(&mut (ref mut v, w): &mut (&'a u8, &u8), x: &'a u8) {

0 commit comments

Comments
 (0)