mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Taint borrowck results without running any borrowck if the MIR body was already tainted
This commit is contained in:
parent
1fcd04ed49
commit
e5461de392
@ -111,14 +111,16 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
|
||||
let (input_body, promoted) = tcx.mir_promoted(def);
|
||||
debug!("run query mir_borrowck: {}", tcx.def_path_str(def));
|
||||
|
||||
if input_body.borrow().should_skip() {
|
||||
debug!("Skipping borrowck because of injected body");
|
||||
let input_body: &Body<'_> = &input_body.borrow();
|
||||
|
||||
if input_body.should_skip() || input_body.tainted_by_errors.is_some() {
|
||||
debug!("Skipping borrowck because of injected body or tainted body");
|
||||
// Let's make up a borrowck result! Fun times!
|
||||
let result = BorrowCheckResult {
|
||||
concrete_opaque_types: FxIndexMap::default(),
|
||||
closure_requirements: None,
|
||||
used_mut_upvars: SmallVec::new(),
|
||||
tainted_by_errors: None,
|
||||
tainted_by_errors: input_body.tainted_by_errors,
|
||||
};
|
||||
return tcx.arena.alloc(result);
|
||||
}
|
||||
@ -127,7 +129,6 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
|
||||
|
||||
let infcx =
|
||||
tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)).build();
|
||||
let input_body: &Body<'_> = &input_body.borrow();
|
||||
let promoted: &IndexSlice<_, _> = &promoted.borrow();
|
||||
let opt_closure_req = do_mir_borrowck(&infcx, input_body, promoted, None).0;
|
||||
debug!("mir_borrowck done");
|
||||
|
@ -6,26 +6,6 @@ LL | let _: &'static _ = &id(&Panic);
|
||||
| |
|
||||
| the destructor for this type cannot be evaluated in constants
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call.rs:11:26
|
||||
|
|
||||
LL | let _: &'static _ = &id(&Panic);
|
||||
| ---------- ^^^^^^^^^^ creates a temporary value which is freed while still in use
|
||||
| |
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
...
|
||||
LL | };
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call.rs:11:30
|
||||
|
|
||||
LL | let _: &'static _ = &id(&Panic);
|
||||
| ---------- ^^^^^ - temporary value is freed at the end of this statement
|
||||
| | |
|
||||
| | creates a temporary value which is freed while still in use
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call.rs:17:26
|
||||
|
|
||||
@ -68,7 +48,7 @@ LL | let _: &'static _ = &&(Panic, 0).1;
|
||||
LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0493, E0716.
|
||||
For more information about an error, try `rustc --explain E0493`.
|
||||
|
@ -2,13 +2,14 @@ pub const fn id<T>(x: T) -> T { x }
|
||||
pub const C: () = {
|
||||
let _: &'static _ = &String::new();
|
||||
//~^ ERROR: destructor of `String` cannot be evaluated at compile-time
|
||||
//~| ERROR: temporary value dropped while borrowed
|
||||
};
|
||||
|
||||
pub const _: () = {
|
||||
let _: &'static _ = &id(&String::new());
|
||||
//~^ ERROR: destructor of `String` cannot be evaluated at compile-time
|
||||
//~| ERROR: temporary value dropped while borrowed
|
||||
//~| ERROR: temporary value dropped while borrowed
|
||||
};
|
||||
|
||||
pub const _: () = {
|
||||
let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
|
||||
//~^ ERROR: temporary value dropped while borrowed
|
||||
};
|
||||
|
@ -1,53 +1,22 @@
|
||||
error[E0493]: destructor of `String` cannot be evaluated at compile-time
|
||||
--> $DIR/promoted_const_call3.rs:7:30
|
||||
--> $DIR/promoted_const_call3.rs:3:26
|
||||
|
|
||||
LL | let _: &'static _ = &String::new();
|
||||
| ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
|
||||
LL |
|
||||
LL | };
|
||||
| - value is dropped here
|
||||
|
||||
error[E0493]: destructor of `String` cannot be evaluated at compile-time
|
||||
--> $DIR/promoted_const_call3.rs:8:30
|
||||
|
|
||||
LL | let _: &'static _ = &id(&String::new());
|
||||
| ^^^^^^^^^^^^^ - value is dropped here
|
||||
| |
|
||||
| the destructor for this type cannot be evaluated in constants
|
||||
|
||||
error[E0493]: destructor of `String` cannot be evaluated at compile-time
|
||||
--> $DIR/promoted_const_call3.rs:3:26
|
||||
|
|
||||
LL | let _: &'static _ = &String::new();
|
||||
| ^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
|
||||
...
|
||||
LL | };
|
||||
| - value is dropped here
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call3.rs:3:26
|
||||
|
|
||||
LL | let _: &'static _ = &String::new();
|
||||
| ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
|
||||
| |
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
...
|
||||
LL | };
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call3.rs:7:26
|
||||
|
|
||||
LL | let _: &'static _ = &id(&String::new());
|
||||
| ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
|
||||
| |
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
...
|
||||
LL | };
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call3.rs:7:30
|
||||
|
|
||||
LL | let _: &'static _ = &id(&String::new());
|
||||
| ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
|
||||
| | |
|
||||
| | creates a temporary value which is freed while still in use
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call3.rs:12:26
|
||||
--> $DIR/promoted_const_call3.rs:13:26
|
||||
|
|
||||
LL | let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
|
||||
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
|
||||
@ -58,7 +27,7 @@ LL | };
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call3.rs:17:26
|
||||
--> $DIR/promoted_const_call3.rs:18:26
|
||||
|
|
||||
LL | let _: &'static _ = &String::new();
|
||||
| ---------- ^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
|
||||
@ -69,7 +38,7 @@ LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call3.rs:20:26
|
||||
--> $DIR/promoted_const_call3.rs:21:26
|
||||
|
|
||||
LL | let _: &'static _ = &id(&String::new());
|
||||
| ---------- ^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
|
||||
@ -80,7 +49,7 @@ LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call3.rs:20:30
|
||||
--> $DIR/promoted_const_call3.rs:21:30
|
||||
|
|
||||
LL | let _: &'static _ = &id(&String::new());
|
||||
| ---------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
|
||||
@ -89,7 +58,7 @@ LL | let _: &'static _ = &id(&String::new());
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call3.rs:24:26
|
||||
--> $DIR/promoted_const_call3.rs:25:26
|
||||
|
|
||||
LL | let _: &'static _ = &std::mem::ManuallyDrop::new(String::new());
|
||||
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
|
||||
@ -99,7 +68,7 @@ LL |
|
||||
LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0493, E0716.
|
||||
For more information about an error, try `rustc --explain E0493`.
|
||||
|
@ -25,9 +25,9 @@ pub const fn new_manually_drop<T>(t: T) -> std::mem::ManuallyDrop<T> {
|
||||
const C: () = {
|
||||
let _: &'static _ = &id(&new_string());
|
||||
//~^ ERROR destructor of `String` cannot be evaluated at compile-time
|
||||
//~| ERROR: temporary value dropped while borrowed
|
||||
//~| ERROR: temporary value dropped while borrowed
|
||||
};
|
||||
|
||||
const _: () = {
|
||||
let _: &'static _ = &new_manually_drop(new_string());
|
||||
//~^ ERROR: temporary value dropped while borrowed
|
||||
};
|
||||
|
@ -6,26 +6,6 @@ LL | let _: &'static _ = &id(&new_string());
|
||||
| |
|
||||
| the destructor for this type cannot be evaluated in constants
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call5.rs:26:26
|
||||
|
|
||||
LL | let _: &'static _ = &id(&new_string());
|
||||
| ---------- ^^^^^^^^^^^^^^^^^ creates a temporary value which is freed while still in use
|
||||
| |
|
||||
| type annotation requires that borrow lasts for `'static`
|
||||
...
|
||||
LL | };
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call5.rs:26:30
|
||||
|
|
||||
LL | let _: &'static _ = &id(&new_string());
|
||||
| ----^^^^^^^^^^^^-- 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`
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/promoted_const_call5.rs:31:26
|
||||
|
|
||||
@ -68,7 +48,7 @@ LL |
|
||||
LL | }
|
||||
| - temporary value is freed at the end of this statement
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0493, E0716.
|
||||
For more information about an error, try `rustc --explain E0493`.
|
||||
|
@ -6,7 +6,6 @@ static A: () = {
|
||||
//~^ ERROR destructor of
|
||||
a[0] = String::new();
|
||||
//~^ ERROR destructor of
|
||||
//~| ERROR binding `a` isn't initialized
|
||||
};
|
||||
|
||||
struct B<T>([T; 1]);
|
||||
@ -17,7 +16,6 @@ impl<T> B<T> {
|
||||
//~^ ERROR destructor of
|
||||
self.0[0] = other;
|
||||
//~^ ERROR destructor of
|
||||
//~| ERROR use of moved value
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -16,22 +16,8 @@ LL | let a: [String; 1];
|
||||
LL | };
|
||||
| - value is dropped here
|
||||
|
||||
error[E0381]: used binding `a` isn't initialized
|
||||
--> $DIR/drop-elaboration-after-borrowck-error.rs:7:5
|
||||
|
|
||||
LL | let a: [String; 1];
|
||||
| - binding declared here but left uninitialized
|
||||
LL |
|
||||
LL | a[0] = String::new();
|
||||
| ^^^^ `a` used here but it isn't initialized
|
||||
|
|
||||
help: consider assigning a value
|
||||
|
|
||||
LL | let a: [String; 1] = todo!();
|
||||
| +++++++++
|
||||
|
||||
error[E0493]: destructor of `T` cannot be evaluated at compile-time
|
||||
--> $DIR/drop-elaboration-after-borrowck-error.rs:18:9
|
||||
--> $DIR/drop-elaboration-after-borrowck-error.rs:17:9
|
||||
|
|
||||
LL | self.0[0] = other;
|
||||
| ^^^^^^^^^
|
||||
@ -40,7 +26,7 @@ LL | self.0[0] = other;
|
||||
| value is dropped here
|
||||
|
||||
error[E0493]: destructor of `B<T>` cannot be evaluated at compile-time
|
||||
--> $DIR/drop-elaboration-after-borrowck-error.rs:16:13
|
||||
--> $DIR/drop-elaboration-after-borrowck-error.rs:15:13
|
||||
|
|
||||
LL | let _this = self;
|
||||
| ^^^^^ the destructor for this type cannot be evaluated in constant functions
|
||||
@ -48,18 +34,6 @@ LL | let _this = self;
|
||||
LL | }
|
||||
| - value is dropped here
|
||||
|
||||
error[E0382]: use of moved value: `self.0`
|
||||
--> $DIR/drop-elaboration-after-borrowck-error.rs:18:9
|
||||
|
|
||||
LL | pub const fn f(mut self, other: T) -> Self {
|
||||
| -------- move occurs because `self` has type `B<T>`, which does not implement the `Copy` trait
|
||||
LL | let _this = self;
|
||||
| ---- value moved here
|
||||
LL |
|
||||
LL | self.0[0] = other;
|
||||
| ^^^^^^^^^ value used here after move
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0381, E0382, E0493.
|
||||
For more information about an error, try `rustc --explain E0381`.
|
||||
For more information about this error, try `rustc --explain E0493`.
|
||||
|
@ -6,11 +6,9 @@ impl Drop for WithDtor {
|
||||
|
||||
static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
|
||||
//~^ ERROR destructor of
|
||||
//~| ERROR temporary value dropped while borrowed
|
||||
|
||||
const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
|
||||
//~^ ERROR destructor of
|
||||
//~| ERROR temporary value dropped while borrowed
|
||||
|
||||
static EARLY_DROP_S: i32 = (WithDtor, 0).1;
|
||||
//~^ ERROR destructor of
|
||||
|
@ -6,36 +6,16 @@ LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
|
||||
| |
|
||||
| the destructor for this type cannot be evaluated in statics
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/static-drop-scope.rs:7:60
|
||||
|
|
||||
LL | static PROMOTION_FAIL_S: Option<&'static WithDtor> = Some(&WithDtor);
|
||||
| ------^^^^^^^^-
|
||||
| | | |
|
||||
| | | temporary value is freed at the end of this statement
|
||||
| | creates a temporary value which is freed while still in use
|
||||
| using this value as a static requires that borrow lasts for `'static`
|
||||
|
||||
error[E0493]: destructor of `WithDtor` cannot be evaluated at compile-time
|
||||
--> $DIR/static-drop-scope.rs:11:59
|
||||
--> $DIR/static-drop-scope.rs:10:59
|
||||
|
|
||||
LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
|
||||
| ^^^^^^^^- value is dropped here
|
||||
| |
|
||||
| the destructor for this type cannot be evaluated in constants
|
||||
|
||||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/static-drop-scope.rs:11:59
|
||||
|
|
||||
LL | const PROMOTION_FAIL_C: Option<&'static WithDtor> = Some(&WithDtor);
|
||||
| ------^^^^^^^^-
|
||||
| | | |
|
||||
| | | temporary value is freed at the end of this statement
|
||||
| | creates a temporary value which is freed while still in use
|
||||
| using this value as a constant requires that borrow lasts for `'static`
|
||||
|
||||
error[E0493]: destructor of `(WithDtor, i32)` cannot be evaluated at compile-time
|
||||
--> $DIR/static-drop-scope.rs:15:28
|
||||
--> $DIR/static-drop-scope.rs:13:28
|
||||
|
|
||||
LL | static EARLY_DROP_S: i32 = (WithDtor, 0).1;
|
||||
| ^^^^^^^^^^^^^ - value is dropped here
|
||||
@ -43,7 +23,7 @@ LL | static EARLY_DROP_S: i32 = (WithDtor, 0).1;
|
||||
| the destructor for this type cannot be evaluated in statics
|
||||
|
||||
error[E0493]: destructor of `(WithDtor, i32)` cannot be evaluated at compile-time
|
||||
--> $DIR/static-drop-scope.rs:18:27
|
||||
--> $DIR/static-drop-scope.rs:16:27
|
||||
|
|
||||
LL | const EARLY_DROP_C: i32 = (WithDtor, 0).1;
|
||||
| ^^^^^^^^^^^^^ - value is dropped here
|
||||
@ -51,7 +31,7 @@ LL | const EARLY_DROP_C: i32 = (WithDtor, 0).1;
|
||||
| the destructor for this type cannot be evaluated in constants
|
||||
|
||||
error[E0493]: destructor of `T` cannot be evaluated at compile-time
|
||||
--> $DIR/static-drop-scope.rs:21:24
|
||||
--> $DIR/static-drop-scope.rs:19:24
|
||||
|
|
||||
LL | const fn const_drop<T>(_: T) {}
|
||||
| ^ - value is dropped here
|
||||
@ -59,7 +39,7 @@ LL | const fn const_drop<T>(_: T) {}
|
||||
| the destructor for this type cannot be evaluated in constant functions
|
||||
|
||||
error[E0493]: destructor of `(T, ())` cannot be evaluated at compile-time
|
||||
--> $DIR/static-drop-scope.rs:25:5
|
||||
--> $DIR/static-drop-scope.rs:23:5
|
||||
|
|
||||
LL | (x, ()).1
|
||||
| ^^^^^^^ the destructor for this type cannot be evaluated in constant functions
|
||||
@ -68,7 +48,7 @@ LL | }
|
||||
| - value is dropped here
|
||||
|
||||
error[E0493]: destructor of `(Option<WithDtor>, i32)` cannot be evaluated at compile-time
|
||||
--> $DIR/static-drop-scope.rs:29:34
|
||||
--> $DIR/static-drop-scope.rs:27:34
|
||||
|
|
||||
LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
|
||||
| ^^^^^^^^^^^^^^^^^^^ - value is dropped here
|
||||
@ -76,14 +56,13 @@ LL | const EARLY_DROP_C_OPTION: i32 = (Some(WithDtor), 0).1;
|
||||
| the destructor for this type cannot be evaluated in constants
|
||||
|
||||
error[E0493]: destructor of `(Option<WithDtor>, i32)` cannot be evaluated at compile-time
|
||||
--> $DIR/static-drop-scope.rs:34:43
|
||||
--> $DIR/static-drop-scope.rs:32:43
|
||||
|
|
||||
LL | const EARLY_DROP_C_OPTION_CONSTANT: i32 = (HELPER, 0).1;
|
||||
| ^^^^^^^^^^^ - value is dropped here
|
||||
| |
|
||||
| the destructor for this type cannot be evaluated in constants
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0493, E0716.
|
||||
For more information about an error, try `rustc --explain E0493`.
|
||||
For more information about this error, try `rustc --explain E0493`.
|
||||
|
Loading…
Reference in New Issue
Block a user