Skip to content

Stop dirtying incremental with span access when computing region scope span #139459

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
22 changes: 4 additions & 18 deletions compiler/rustc_middle/src/ty/significant_drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,25 +143,11 @@ pub fn ty_dtor_span<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Span> {
| ty::UnsafeBinder(_) => None,

ty::Adt(adt_def, _) => {
let did = adt_def.did();
let try_local_did_span = |did: DefId| {
if let Some(local) = did.as_local() {
tcx.source_span(local)
} else {
tcx.def_span(did)
}
};
let dtor = if let Some(dtor) = tcx.adt_destructor(did) {
dtor.did
} else if let Some(dtor) = tcx.adt_async_destructor(did) {
return Some(tcx.source_span(dtor.impl_did));
if let Some(dtor) = tcx.adt_destructor(adt_def.did()) {
Some(tcx.def_span(tcx.parent(dtor.did)))
} else {
return Some(try_local_did_span(did));
};
let def_key = tcx.def_key(dtor);
let Some(parent_index) = def_key.parent else { return Some(try_local_did_span(dtor)) };
let parent_did = DefId { index: parent_index, krate: dtor.krate };
Some(try_local_did_span(parent_did))
Some(tcx.def_span(adt_def.did()))
}
}
ty::Coroutine(did, _)
| ty::CoroutineWitness(did, _)
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_mir_build/src/builder/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,11 +1135,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

if scope.region_scope == region_scope {
let region_scope_span = region_scope.span(self.tcx, self.region_scope_tree);
// Attribute scope exit drops to scope's closing brace.
let scope_end = self.tcx.sess.source_map().end_point(region_scope_span);

scope.drops.push(DropData {
source_info: SourceInfo { span: scope_end, scope: scope.source_scope },
source_info: SourceInfo {
span: region_scope_span.shrink_to_hi(),
scope: scope.source_scope,
},
local,
kind: drop_kind,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ LL | outlives::<'a>(c());
| argument requires that `c` is borrowed for `'a`
LL | outlives::<'a>(call_once(c));
LL | }
| - `c` dropped here while still borrowed
| - `c` dropped here while still borrowed

error[E0597]: `x` does not live long enough
--> $DIR/without-precise-captures-we-are-powerless.rs:26:13
Expand Down Expand Up @@ -72,7 +72,7 @@ LL | outlives::<'a>(c());
| argument requires that `c` is borrowed for `'a`
LL | outlives::<'a>(call_once(c));
LL | }
| - `c` dropped here while still borrowed
| - `c` dropped here while still borrowed

error[E0505]: cannot move out of `c` because it is borrowed
--> $DIR/without-precise-captures-we-are-powerless.rs:32:30
Expand Down Expand Up @@ -126,7 +126,7 @@ LL | outlives::<'a>(c());
| argument requires that `c` is borrowed for `'a`
LL | outlives::<'a>(call_once(c));
LL | }
| - `c` dropped here while still borrowed
| - `c` dropped here while still borrowed

error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/without-precise-captures-we-are-powerless.rs:44:5
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/async-await/feature-self-return-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | Foo::new(&bar).await
| ^^^^ borrowed value does not live long enough
LL |
LL | };
| - `bar` dropped here while still borrowed
| - `bar` dropped here while still borrowed

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ LL | || })()
| |_______|
| creates a temporary value which is freed while still in use
LL | }
| - temporary value is freed at the end of this statement
| - temporary value is freed at the end of this statement

error[E0506]: cannot assign to `*x` because it is borrowed
--> $DIR/issue-74072-lifetime-name-annotations.rs:27:9
Expand Down Expand Up @@ -106,7 +106,7 @@ LL | || })()
| |_______|
| creates a temporary value which is freed while still in use
LL | }
| - temporary value is freed at the end of this statement
| - temporary value is freed at the end of this statement

error[E0506]: cannot assign to `*x` because it is borrowed
--> $DIR/issue-74072-lifetime-name-annotations.rs:35:9
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/alias-liveness/escaping-bounds-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/escaping-bounds-2.rs:10:31
|
LL | let func = get_func::<T>(&String::new());
| ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
LL | drop(func);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | test(&vec![])
| | creates a temporary value which is freed while still in use
| argument requires that borrow lasts for `'static`
LL | }
| - temporary value is freed at the end of this statement
| - temporary value is freed at the end of this statement
|
= note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | foo.g();
| ^^^ second mutable borrow occurs here
LL |
LL | }
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
|
help: consider using the `matches!` macro
|
Expand All @@ -32,7 +32,7 @@ LL | foo.g();
| ^^^ second mutable borrow occurs here
LL |
LL | }
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
|
help: consider using the `matches!` macro
|
Expand All @@ -52,7 +52,7 @@ LL | foo.g();
| ^^^ second mutable borrow occurs here
LL |
LL | }
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`

error[E0499]: cannot borrow `foo` as mutable more than once at a time
--> $DIR/already-borrowed-as-mutable-if-let-133941.rs:37:9
Expand All @@ -66,13 +66,13 @@ LL | foo.g();
| ^^^ second mutable borrow occurs here
LL |
LL | }
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`

error[E0499]: cannot borrow `foo` as mutable more than once at a time
--> $DIR/already-borrowed-as-mutable-if-let-133941.rs:40:45
|
LL | while let Some(_x) = {let _x = foo.f(); foo.g(); None::<()>} {
| --- ^^^ - first borrow might be used here, when `_x` is dropped and runs the destructor for type `Option<Bar<'_>>`
| --- ^^^ - first borrow might be used here, when `_x` is dropped and runs the destructor for type `Option<Bar<'_>>`
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
Expand All @@ -81,7 +81,7 @@ error[E0499]: cannot borrow `foo` as mutable more than once at a time
--> $DIR/already-borrowed-as-mutable-if-let-133941.rs:43:42
|
LL | if let Some(_x) = {let _x = foo.f(); foo.g(); None::<()>} {
| --- ^^^ - first borrow might be used here, when `_x` is dropped and runs the destructor for type `Option<Bar<'_>>`
| --- ^^^ - first borrow might be used here, when `_x` is dropped and runs the destructor for type `Option<Bar<'_>>`
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/borrowck-borrowed-uniq-rvalue-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/borrowck-borrowed-uniq-rvalue-2.rs:20:20
|
LL | let x = defer(&vec!["Goodbye", "world!"]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| ^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
LL | x.x[0];
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/borrowck-borrowed-uniq-rvalue.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/borrowck-borrowed-uniq-rvalue.rs:8:28
|
LL | buggy_map.insert(42, &*Box::new(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/borrowck-fn-in-const-c.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0713]: borrow may still be in use when destructor runs
LL | return &local.inner;
| ^^^^^^^^^^^^ returning this value requires that `local.inner` is borrowed for `'static`
LL | }
| - here, drop of `local` needs exclusive access to `local.inner`, because the type `DropString` implements the `Drop` trait
| - here, drop of `local` needs exclusive access to `local.inner`, because the type `DropString` implements the `Drop` trait

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/fn-item-check-trait-ref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/fn-item-check-trait-ref.rs:13:7
|
LL | (&String::new()).assert_static();
| --^^^^^^^^^^^^^------------------ temporary value is freed at the end of this statement
| --^^^^^^^^^^^^^----------------- - temporary value is freed at the end of this statement
| | |
| | creates a temporary value which is freed while still in use
| argument requires that borrow lasts for `'static`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/fn-item-check-type-params.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/fn-item-check-type-params.rs:48:11
|
LL | want(&String::new(), extend_lt);
| ------^^^^^^^^^^^^^------------- temporary value is freed at the end of this statement
| ------^^^^^^^^^^^^^------------ - temporary value is freed at the end of this statement
| | |
| | creates a temporary value which is freed while still in use
| argument requires that borrow lasts for `'static`
Expand All @@ -32,7 +32,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/fn-item-check-type-params.rs:54:26
|
LL | let val = extend_lt(&String::from("blah blah blah"));
| -----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- temporary value is freed at the end of this statement
| -----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- - temporary value is freed at the end of this statement
| | |
| | creates a temporary value which is freed while still in use
| argument requires that borrow lasts for `'static`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LL | force_send(async_load(&not_static));
| argument requires that `not_static` is borrowed for `'1`
...
LL | }
| - `not_static` dropped here while still borrowed
| - `not_static` dropped here while still borrowed
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/implementation-not-general-enough-ice-133252.rs:16:18
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/issue-114374-invalid-help-fmt-args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/issue-114374-invalid-help-fmt-args.rs:5:13
|
LL | let x = format_args!("a {} {} {}.", 1, format_args!("b{}!", 2), 3);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand All @@ -16,7 +16,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/issue-114374-invalid-help-fmt-args.rs:10:15
|
LL | let foo = format_args!("{}", "hi");
| ^^^^^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement
| ^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
LL |
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-11493.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/issue-11493.rs:6:35
|
LL | let y = x.as_ref().unwrap_or(&id(5));
| ^^^^^ - temporary value is freed at the end of this statement
| ^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
LL | let _ = &y;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-17545.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | / bar.call((
LL | | &id(()),
| | ^^^^^^ creates a temporary value which is freed while still in use
LL | | ));
| | -- temporary value is freed at the end of this statement
| | - - temporary value is freed at the end of this statement
| |______|
| argument requires that borrow lasts for `'a`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-36082.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0716]: temporary value dropped while borrowed
--> $DIR/issue-36082.rs:9:19
|
LL | let val: &_ = x.borrow().0;
| ^^^^^^^^^^ - temporary value is freed at the end of this statement
| ^^^^^^^^^^ - temporary value is freed at the end of this statement
| |
| creates a temporary value which is freed while still in use
...
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-47646.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | println!("{:?}", heap);
| ^^^^ immutable borrow occurs here
...
LL | };
| - ... and the mutable borrow might be used here, when that temporary is dropped and runs the destructor for type `(Option<PeekMut<'_, i32>>, ())`
| - ... and the mutable borrow might be used here, when that temporary is dropped and runs the destructor for type `(Option<PeekMut<'_, i32>>, ())`
|
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-82462.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LL | v.push(*x);
| ^^^^^^^^^^ mutable borrow occurs here
LL | break;
LL | }
| - ... and the immutable borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DroppingSlice`
| - ... and the immutable borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DroppingSlice`
|
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-85581.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ LL | Some(_) => { heap.pop(); },
| ^^^^ second mutable borrow occurs here
...
LL | }
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<PeekMut<'_, i32>>`
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<PeekMut<'_, i32>>`

error: aborting due to 1 previous error

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/borrowck/let_underscore_temporary.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | &a
| ^^ borrowed value does not live long enough
LL |
LL | };
| - `a` dropped here while still borrowed
| - `a` dropped here while still borrowed

error[E0597]: `a` does not live long enough
--> $DIR/let_underscore_temporary.rs:26:9
Expand All @@ -18,7 +18,7 @@ LL | &a
| ^^ borrowed value does not live long enough
LL |
LL | };
| - `a` dropped here while still borrowed
| - `a` dropped here while still borrowed

error[E0597]: `a` does not live long enough
--> $DIR/let_underscore_temporary.rs:39:9
Expand All @@ -29,7 +29,7 @@ LL | &a
| ^^ borrowed value does not live long enough
LL |
LL | };
| - `a` dropped here while still borrowed
| - `a` dropped here while still borrowed

error[E0597]: `a` does not live long enough
--> $DIR/let_underscore_temporary.rs:54:9
Expand All @@ -40,7 +40,7 @@ LL | &a
| ^^ borrowed value does not live long enough
LL |
LL | };
| - `a` dropped here while still borrowed
| - `a` dropped here while still borrowed

error[E0597]: `a` does not live long enough
--> $DIR/let_underscore_temporary.rs:71:9
Expand All @@ -51,7 +51,7 @@ LL | &a
| ^^ borrowed value does not live long enough
LL |
LL | } {
| - `a` dropped here while still borrowed
| - `a` dropped here while still borrowed

error[E0597]: `a` does not live long enough
--> $DIR/let_underscore_temporary.rs:92:9
Expand All @@ -62,7 +62,7 @@ LL | &a
| ^^ borrowed value does not live long enough
LL |
LL | } {
| - `a` dropped here while still borrowed
| - `a` dropped here while still borrowed

error: aborting due to 6 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/btreemap/btreemap_dropck.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]);
LL | drop(s);
| ^ move out of `s` occurs here
LL | }
| - borrow might be used here, when `_map` is dropped and runs the `Drop` code for type `BTreeMap`
| - borrow might be used here, when `_map` is dropped and runs the `Drop` code for type `BTreeMap`
|
help: consider cloning the value if the performance cost is acceptable
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/c-variadic/variadic-ffi-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ LL | ap0 = &mut ap1;
| assignment requires that `ap1` is borrowed for `'3`
...
LL | }
| - `ap1` dropped here while still borrowed
| - `ap1` dropped here while still borrowed

error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:35:5
Expand Down
Loading
Loading