Skip to content

Commit 90dd6bf

Browse files
committed
Auto merge of #140635 - Zalathar:rollup-3n5dyz3, r=Zalathar
Rollup of 3 pull requests Successful merges: - #140357 (bypass linker configuration and cross target check on `x check`) - #140580 (Don't name variables from external macros in borrow errors.) - #140630 (Async drop source info fix for proxy-drop-coroutine) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 62c5f58 + 74ba8b0 commit 90dd6bf

14 files changed

+124
-53
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,12 +2954,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
29542954
}
29552955
}
29562956

2957-
let name = if borrow_span.in_external_macro(self.infcx.tcx.sess.source_map()) {
2958-
// Don't name local variables in external macros.
2959-
"value".to_string()
2960-
} else {
2961-
format!("`{name}`")
2962-
};
2957+
let name = format!("`{name}`");
29632958

29642959
let mut err = self.path_does_not_live_long_enough(borrow_span, &name);
29652960

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
317317
opt: DescribePlaceOpt,
318318
) -> Option<String> {
319319
let local = place.local;
320+
if self.body.local_decls[local]
321+
.source_info
322+
.span
323+
.in_external_macro(self.infcx.tcx.sess.source_map())
324+
{
325+
return None;
326+
}
327+
320328
let mut autoderef_index = None;
321329
let mut buf = String::new();
322330
let mut ok = self.append_local_to_string(local, &mut buf);

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,13 +1929,17 @@ impl<'tcx> TyCtxt<'tcx> {
19291929
if arg_cor_ty.is_coroutine() {
19301930
let span = self.def_span(def_id);
19311931
let source_info = SourceInfo::outermost(span);
1932+
// Even minimal, empty coroutine has 3 states (RESERVED_VARIANTS),
1933+
// so variant_fields and variant_source_info should have 3 elements.
19321934
let variant_fields: IndexVec<VariantIdx, IndexVec<FieldIdx, CoroutineSavedLocal>> =
19331935
iter::repeat(IndexVec::new()).take(CoroutineArgs::RESERVED_VARIANTS).collect();
1936+
let variant_source_info: IndexVec<VariantIdx, SourceInfo> =
1937+
iter::repeat(source_info).take(CoroutineArgs::RESERVED_VARIANTS).collect();
19341938
let proxy_layout = CoroutineLayout {
19351939
field_tys: [].into(),
19361940
field_names: [].into(),
19371941
variant_fields,
1938-
variant_source_info: [source_info].into(),
1942+
variant_source_info,
19391943
storage_conflicts: BitMatrix::new(0, 0),
19401944
};
19411945
return Some(self.arena.alloc(proxy_layout));

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ impl Cargo {
112112
let mut cargo = builder.cargo(compiler, mode, source_type, target, cmd_kind);
113113

114114
match cmd_kind {
115-
// No need to configure the target linker for these command types,
116-
// as they don't invoke rustc at all.
117-
Kind::Clean | Kind::Suggest | Kind::Format | Kind::Setup => {}
115+
// No need to configure the target linker for these command types.
116+
Kind::Clean | Kind::Check | Kind::Suggest | Kind::Format | Kind::Setup => {}
118117
_ => {
119118
cargo.configure_linker(builder);
120119
}
@@ -205,6 +204,8 @@ impl Cargo {
205204
self
206205
}
207206

207+
// FIXME(onur-ozkan): Add coverage to make sure modifications to this function
208+
// doesn't cause cache invalidations (e.g., #130108).
208209
fn configure_linker(&mut self, builder: &Builder<'_>) -> &mut Cargo {
209210
let target = self.target;
210211
let compiler = self.compiler;

src/bootstrap/src/utils/cc_detect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub fn find(build: &Build) {
9696
let targets: HashSet<_> = match build.config.cmd {
9797
// We don't need to check cross targets for these commands.
9898
crate::Subcommand::Clean { .. }
99+
| crate::Subcommand::Check { .. }
99100
| crate::Subcommand::Suggest { .. }
100101
| crate::Subcommand::Format { .. }
101102
| crate::Subcommand::Setup { .. } => {

tests/ui/derives/deriving-with-repr-packed-move-errors.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use std::cmp::Ordering;
1111
#[repr(packed)]
1212
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
1313
struct StructA(String);
14-
//~^ ERROR: cannot move out of `self` which is behind a shared reference
15-
//~| ERROR: cannot move out of `self` which is behind a shared reference
16-
//~| ERROR: cannot move out of `other` which is behind a shared reference
17-
//~| ERROR: cannot move out of `self` which is behind a shared reference
18-
//~| ERROR: cannot move out of `other` which is behind a shared reference
19-
//~| ERROR: cannot move out of `self` which is behind a shared reference
20-
//~| ERROR: cannot move out of `other` which is behind a shared reference
21-
//~| ERROR: cannot move out of `self` which is behind a shared reference
22-
//~| ERROR: cannot move out of `self` which is behind a shared reference
14+
//~^ ERROR: cannot move out of a shared reference [E0507]
15+
//~| ERROR: cannot move out of a shared reference [E0507]
16+
//~| ERROR: cannot move out of a shared reference [E0507]
17+
//~| ERROR: cannot move out of a shared reference [E0507]
18+
//~| ERROR: cannot move out of a shared reference [E0507]
19+
//~| ERROR: cannot move out of a shared reference [E0507]
20+
//~| ERROR: cannot move out of a shared reference [E0507]
21+
//~| ERROR: cannot move out of a shared reference [E0507]
22+
//~| ERROR: cannot move out of a shared reference [E0507]
2323

2424

2525
// Unrelated impl: additinal diagnostic should NOT be emitted

tests/ui/derives/deriving-with-repr-packed-move-errors.stderr

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,125 @@
1-
error[E0507]: cannot move out of `self` which is behind a shared reference
1+
error[E0507]: cannot move out of a shared reference
22
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
33
|
44
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
55
| ----- in this derive macro expansion
66
LL | struct StructA(String);
7-
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
7+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
88
|
99
= note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
1010
help: consider cloning the value if the performance cost is acceptable
1111
|
1212
LL | struct StructA(String.clone());
1313
| ++++++++
1414

15-
error[E0507]: cannot move out of `self` which is behind a shared reference
15+
error[E0507]: cannot move out of a shared reference
1616
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
1717
|
1818
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
1919
| --------- in this derive macro expansion
2020
LL | struct StructA(String);
21-
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
21+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
2222
|
2323
= note: `#[derive(PartialEq)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
2424
help: consider cloning the value if the performance cost is acceptable
2525
|
2626
LL | struct StructA(String.clone());
2727
| ++++++++
2828

29-
error[E0507]: cannot move out of `other` which is behind a shared reference
29+
error[E0507]: cannot move out of a shared reference
3030
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
3131
|
3232
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
3333
| --------- in this derive macro expansion
3434
LL | struct StructA(String);
35-
| ^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait
35+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
3636
|
3737
= note: `#[derive(PartialEq)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
38+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3839
help: consider cloning the value if the performance cost is acceptable
3940
|
4041
LL | struct StructA(String.clone());
4142
| ++++++++
4243

43-
error[E0507]: cannot move out of `self` which is behind a shared reference
44+
error[E0507]: cannot move out of a shared reference
4445
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
4546
|
4647
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
4748
| ---------- in this derive macro expansion
4849
LL | struct StructA(String);
49-
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
50+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
5051
|
5152
= note: `#[derive(PartialOrd)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
5253
help: consider cloning the value if the performance cost is acceptable
5354
|
5455
LL | struct StructA(String.clone());
5556
| ++++++++
5657

57-
error[E0507]: cannot move out of `other` which is behind a shared reference
58+
error[E0507]: cannot move out of a shared reference
5859
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
5960
|
6061
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
6162
| ---------- in this derive macro expansion
6263
LL | struct StructA(String);
63-
| ^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait
64+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
6465
|
6566
= note: `#[derive(PartialOrd)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
67+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
6668
help: consider cloning the value if the performance cost is acceptable
6769
|
6870
LL | struct StructA(String.clone());
6971
| ++++++++
7072

71-
error[E0507]: cannot move out of `self` which is behind a shared reference
73+
error[E0507]: cannot move out of a shared reference
7274
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
7375
|
7476
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
7577
| --- in this derive macro expansion
7678
LL | struct StructA(String);
77-
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
79+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
7880
|
7981
= note: `#[derive(Ord)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
8082
help: consider cloning the value if the performance cost is acceptable
8183
|
8284
LL | struct StructA(String.clone());
8385
| ++++++++
8486

85-
error[E0507]: cannot move out of `other` which is behind a shared reference
87+
error[E0507]: cannot move out of a shared reference
8688
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
8789
|
8890
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
8991
| --- in this derive macro expansion
9092
LL | struct StructA(String);
91-
| ^^^^^^ move occurs because `other.0` has type `String`, which does not implement the `Copy` trait
93+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
9294
|
9395
= note: `#[derive(Ord)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
96+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
9497
help: consider cloning the value if the performance cost is acceptable
9598
|
9699
LL | struct StructA(String.clone());
97100
| ++++++++
98101

99-
error[E0507]: cannot move out of `self` which is behind a shared reference
102+
error[E0507]: cannot move out of a shared reference
100103
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
101104
|
102105
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
103106
| ---- in this derive macro expansion
104107
LL | struct StructA(String);
105-
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
108+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
106109
|
107110
= note: `#[derive(Hash)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
108111
help: consider cloning the value if the performance cost is acceptable
109112
|
110113
LL | struct StructA(String.clone());
111114
| ++++++++
112115

113-
error[E0507]: cannot move out of `self` which is behind a shared reference
116+
error[E0507]: cannot move out of a shared reference
114117
--> $DIR/deriving-with-repr-packed-move-errors.rs:13:16
115118
|
116119
LL | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
117120
| ----- in this derive macro expansion
118121
LL | struct StructA(String);
119-
| ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
122+
| ^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait
120123
|
121124
= note: `#[derive(Clone)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
122125
help: consider cloning the value if the performance cost is acceptable

tests/ui/derives/deriving-with-repr-packed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct Y(usize);
2020
#[derive(Debug, Default)]
2121
#[repr(packed)]
2222
struct X(Y);
23-
//~^ ERROR cannot move out of `self` which is behind a shared reference
23+
//~^ ERROR cannot move out of a shared reference [E0507]
2424

2525
#[derive(Debug)]
2626
#[repr(packed)]

tests/ui/derives/deriving-with-repr-packed.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0507]: cannot move out of `self` which is behind a shared reference
1+
error[E0507]: cannot move out of a shared reference
22
--> $DIR/deriving-with-repr-packed.rs:22:10
33
|
44
LL | #[derive(Debug, Default)]
55
| ----- in this derive macro expansion
66
LL | #[repr(packed)]
77
LL | struct X(Y);
8-
| ^ move occurs because `self.0` has type `Y`, which does not implement the `Copy` trait
8+
| ^ move occurs because value has type `Y`, which does not implement the `Copy` trait
99
|
1010
note: if `Y` implemented `Clone`, you could clone the value
1111
--> $DIR/deriving-with-repr-packed.rs:16:1
@@ -23,14 +23,14 @@ error[E0161]: cannot move a value of type `[u8]`
2323
LL | data: [u8],
2424
| ^^^^^^^^^^ the size of `[u8]` cannot be statically determined
2525

26-
error[E0507]: cannot move out of `self.data` which is behind a shared reference
26+
error[E0507]: cannot move out of a shared reference
2727
--> $DIR/deriving-with-repr-packed.rs:29:5
2828
|
2929
LL | #[derive(Debug)]
3030
| ----- in this derive macro expansion
3131
...
3232
LL | data: [u8],
33-
| ^^^^^^^^^^ move occurs because `self.data` has type `[u8]`, which does not implement the `Copy` trait
33+
| ^^^^^^^^^^ move occurs because value has type `[u8]`, which does not implement the `Copy` trait
3434
|
3535
= note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
3636

@@ -40,14 +40,14 @@ error[E0161]: cannot move a value of type `str`
4040
LL | data: str,
4141
| ^^^^^^^^^ the size of `str` cannot be statically determined
4242

43-
error[E0507]: cannot move out of `self.data` which is behind a shared reference
43+
error[E0507]: cannot move out of a shared reference
4444
--> $DIR/deriving-with-repr-packed.rs:38:5
4545
|
4646
LL | #[derive(Debug)]
4747
| ----- in this derive macro expansion
4848
...
4949
LL | data: str,
50-
| ^^^^^^^^^ move occurs because `self.data` has type `str`, which does not implement the `Copy` trait
50+
| ^^^^^^^^^ move occurs because value has type `str`, which does not implement the `Copy` trait
5151
|
5252
= note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
5353

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(super_let)]
2+
3+
#[macro_export]
4+
macro_rules! foo {
5+
() => {
6+
{
7+
super let args = 1;
8+
&args
9+
}
10+
};
11+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ aux-crate: ret_from_ext=return_from_external_macro.rs
2+
3+
#![feature(super_let)]
4+
extern crate ret_from_ext;
5+
6+
fn foo() -> impl Sized {
7+
drop(|| ret_from_ext::foo!());
8+
//~^ ERROR cannot return reference to local binding
9+
10+
ret_from_ext::foo!()
11+
//~^ ERROR temporary value dropped while borrowed
12+
}
13+
//~^ NOTE temporary value is freed at the end of this statement
14+
15+
fn main() {
16+
foo();
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0515]: cannot return reference to local binding
2+
--> $DIR/return_from_external_macro.rs:7:13
3+
|
4+
LL | drop(|| ret_from_ext::foo!());
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| returns a reference to data owned by the current function
8+
| local binding introduced here
9+
|
10+
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error[E0716]: temporary value dropped while borrowed
13+
--> $DIR/return_from_external_macro.rs:10:5
14+
|
15+
LL | ret_from_ext::foo!()
16+
| ^^^^^^^^^^^^^^^^^^^^
17+
| |
18+
| creates a temporary value which is freed while still in use
19+
| opaque type requires that borrow lasts for `'static`
20+
LL |
21+
LL | }
22+
| - temporary value is freed at the end of this statement
23+
|
24+
= note: this error originates in the macro `ret_from_ext::foo` (in Nightly builds, run with -Z macro-backtrace for more info)
25+
26+
error: aborting due to 2 previous errors
27+
28+
Some errors have detailed explanations: E0515, E0716.
29+
For more information about an error, try `rustc --explain E0515`.

tests/ui/pin-macro/lifetime_errors_on_promotion_misusage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use core::{
99

1010
fn function_call_stops_borrow_extension() {
1111
let phantom_pinned = identity(pin!(PhantomPinned));
12-
//~^ ERROR does not live long enough
12+
//~^ ERROR temporary value dropped while borrowed [E0716]
1313
stuff(phantom_pinned)
1414
}
1515

1616
fn promotion_only_works_for_the_innermost_block() {
1717
let phantom_pinned = {
1818
let phantom_pinned = pin!(PhantomPinned);
19-
//~^ ERROR does not live long enough
19+
//~^ ERROR temporary value dropped while borrowed [E0716]
2020
phantom_pinned
2121
};
2222
stuff(phantom_pinned)

0 commit comments

Comments
 (0)