Skip to content

Commit b35ad72

Browse files
committed
Auto merge of rust-lang#133305 - cuviper:beta-next, r=cuviper
[beta] backports - Enforce that raw lifetimes must be valid raw identifiers rust-lang#132363 - Update cdb annotations for some debuginfo tests with cdb `10.0.26100.2161` rust-lang#133115 r? cuviper
2 parents 4ff8ff0 + 8435c75 commit b35ad72

File tree

8 files changed

+127
-44
lines changed

8 files changed

+127
-44
lines changed

Diff for: compiler/rustc_parse/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ parse_box_syntax_removed_suggestion = use `Box::new()` instead
7777
7878
parse_cannot_be_raw_ident = `{$ident}` cannot be a raw identifier
7979
80+
parse_cannot_be_raw_lifetime = `{$ident}` cannot be a raw lifetime
81+
8082
parse_catch_after_try = keyword `catch` cannot follow a `try` block
8183
.help = try using `match` on the result of the `try` block instead
8284

Diff for: compiler/rustc_parse/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,14 @@ pub(crate) struct CannotBeRawIdent {
20182018
pub ident: Symbol,
20192019
}
20202020

2021+
#[derive(Diagnostic)]
2022+
#[diag(parse_cannot_be_raw_lifetime)]
2023+
pub(crate) struct CannotBeRawLifetime {
2024+
#[primary_span]
2025+
pub span: Span,
2026+
pub ident: Symbol,
2027+
}
2028+
20212029
#[derive(Diagnostic)]
20222030
#[diag(parse_keyword_lifetime)]
20232031
pub(crate) struct KeywordLifetime {

Diff for: compiler/rustc_parse/src/lexer/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,21 @@ impl<'psess, 'src> StringReader<'psess, 'src> {
294294
let prefix_span = self.mk_sp(start, ident_start);
295295

296296
if prefix_span.at_least_rust_2021() {
297-
let lifetime_name_without_tick = self.str_from(ident_start);
297+
let span = self.mk_sp(start, self.pos);
298+
299+
let lifetime_name_without_tick = Symbol::intern(&self.str_from(ident_start));
300+
if !lifetime_name_without_tick.can_be_raw() {
301+
self.dcx().emit_err(errors::CannotBeRawLifetime { span, ident: lifetime_name_without_tick });
302+
}
303+
298304
// Put the `'` back onto the lifetime name.
299-
let mut lifetime_name = String::with_capacity(lifetime_name_without_tick.len() + 1);
305+
let mut lifetime_name = String::with_capacity(lifetime_name_without_tick.as_str().len() + 1);
300306
lifetime_name.push('\'');
301-
lifetime_name += lifetime_name_without_tick;
307+
lifetime_name += lifetime_name_without_tick.as_str();
302308
let sym = Symbol::intern(&lifetime_name);
303309

304310
// Make sure we mark this as a raw identifier.
305-
self.psess.raw_identifier_spans.push(self.mk_sp(start, self.pos));
311+
self.psess.raw_identifier_spans.push(span);
306312

307313
token::Lifetime(sym, IdentIsRaw::Yes)
308314
} else {

Diff for: tests/debuginfo/numeric-types.rs

+35-29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
//@ ignore-windows-gnu: #128981
44

5+
// Note: u128 visualization was not supported in 10.0.22621.3233 but was fixed in 10.0.26100.2161.
6+
7+
// FIXME(#133107): this is temporarily marked as `only-64bit` because of course 32-bit msvc has
8+
// a different integer width and thus underlying integer type display. Only marked as such to
9+
// unblock the tree.
10+
//@ only-64bit
11+
//@ min-cdb-version: 10.0.26100.2161
12+
513
// Tests the visualizations for `NonZero<T>`, `Wrapping<T>` and
614
// `Atomic{Bool,I8,I16,I32,I64,Isize,U8,U16,U32,U64,Usize}` located in `libcore.natvis`.
715

@@ -48,8 +56,8 @@
4856
// cdb-check:nz_u64 : 0x64 [Type: core::num::nonzero::NonZero<u64>]
4957
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<u64>]
5058

51-
// 128-bit integers don't seem to work in CDB
5259
// cdb-command: dx nz_u128
60+
// cdb-check:nz_u128 : 111 [Type: core::num::nonzero::NonZero<u128>]
5361
// cdb-check: [<Raw View>] [Type: core::num::nonzero::NonZero<u128>]
5462

5563
// cdb-command: dx nz_usize
@@ -58,101 +66,99 @@
5866

5967
// cdb-command: dx w_i8
6068
// cdb-check:w_i8 : 10 [Type: core::num::wrapping::Wrapping<i8>]
61-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<i8>]
69+
// cdb-check: [+0x000] __0 : 10 [Type: char]
6270

6371
// cdb-command: dx w_i16
6472
// cdb-check:w_i16 : 20 [Type: core::num::wrapping::Wrapping<i16>]
65-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<i16>]
73+
// cdb-check: [+0x000] __0 : 20 [Type: short]
6674

6775
// cdb-command: dx w_i32
6876
// cdb-check:w_i32 : 30 [Type: core::num::wrapping::Wrapping<i32>]
69-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<i32>]
77+
// cdb-check: [+0x000] __0 : 30 [Type: int]
7078

7179
// cdb-command: dx w_i64
7280
// cdb-check:w_i64 : 40 [Type: core::num::wrapping::Wrapping<i64>]
73-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<i64>]
81+
// cdb-check: [+0x000] __0 : 40 [Type: __int64]
7482

75-
// 128-bit integers don't seem to work in CDB
7683
// cdb-command: dx w_i128
77-
// cdb-check:w_i128 [Type: core::num::wrapping::Wrapping<i128>]
78-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<i128>]
84+
// cdb-check:w_i128 : 50 [Type: core::num::wrapping::Wrapping<i128>]
85+
// cdb-check: [+0x000] __0 : 50 [Type: i128]
7986

8087
// cdb-command: dx w_isize
8188
// cdb-check:w_isize : 60 [Type: core::num::wrapping::Wrapping<isize>]
82-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<isize>]
89+
// cdb-check: [+0x000] __0 : 60 [Type: __int64]
8390

8491
// cdb-command: dx w_u8
8592
// cdb-check:w_u8 : 0x46 [Type: core::num::wrapping::Wrapping<u8>]
86-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<u8>]
93+
// cdb-check: [+0x000] __0 : 0x46 [Type: unsigned char]
8794

8895
// cdb-command: dx w_u16
8996
// cdb-check:w_u16 : 0x50 [Type: core::num::wrapping::Wrapping<u16>]
90-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<u16>]
97+
// cdb-check: [+0x000] __0 : 0x50 [Type: unsigned short]
9198

9299
// cdb-command: dx w_u32
93100
// cdb-check:w_u32 : 0x5a [Type: core::num::wrapping::Wrapping<u32>]
94-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<u32>]
101+
// cdb-check: [+0x000] __0 : 0x5a [Type: unsigned int]
95102

96103
// cdb-command: dx w_u64
97104
// cdb-check:w_u64 : 0x64 [Type: core::num::wrapping::Wrapping<u64>]
98-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<u64>]
105+
// cdb-check: [+0x000] __0 : 0x64 [Type: unsigned __int64]
99106

100-
// 128-bit integers don't seem to work in CDB
101107
// cdb-command: dx w_u128
102-
// cdb-check:w_u128 [Type: core::num::wrapping::Wrapping<u128>]
103-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<u128>]
108+
// cdb-check:w_u128 : 110 [Type: core::num::wrapping::Wrapping<u128>]
109+
// cdb-check: [+0x000] __0 : 110 [Type: u128]
104110

105111
// cdb-command: dx w_usize
106112
// cdb-check:w_usize : 0x78 [Type: core::num::wrapping::Wrapping<usize>]
107-
// cdb-check: [<Raw View>] [Type: core::num::wrapping::Wrapping<usize>]
113+
// cdb-check: [+0x000] __0 : 0x78 [Type: unsigned __int64]
108114

109115
// cdb-command: dx a_bool_t
110116
// cdb-check:a_bool_t : true [Type: core::sync::atomic::AtomicBool]
111-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicBool]
117+
// cdb-check: [+0x000] v : 0x1 [Type: core::cell::UnsafeCell<u8>]
112118

113119
// cdb-command: dx a_bool_f
114120
// cdb-check:a_bool_f : false [Type: core::sync::atomic::AtomicBool]
115-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicBool]
121+
// cdb-check: [+0x000] v : 0x0 [Type: core::cell::UnsafeCell<u8>]
116122

117123
// cdb-command: dx a_i8
118124
// cdb-check:a_i8 : 2 [Type: core::sync::atomic::AtomicI8]
119-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicI8]
125+
// cdb-check: [+0x000] v : 2 [Type: core::cell::UnsafeCell<i8>]
120126

121127
// cdb-command: dx a_i16
122128
// cdb-check:a_i16 : 4 [Type: core::sync::atomic::AtomicI16]
123-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicI16]
129+
// cdb-check: [+0x000] v : 4 [Type: core::cell::UnsafeCell<i16>]
124130

125131
// cdb-command: dx a_i32
126132
// cdb-check:a_i32 : 8 [Type: core::sync::atomic::AtomicI32]
127-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicI32]
133+
// cdb-check: [+0x000] v : 8 [Type: core::cell::UnsafeCell<i32>]
128134

129135
// cdb-command: dx a_i64
130136
// cdb-check:a_i64 : 16 [Type: core::sync::atomic::AtomicI64]
131-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicI64]
137+
// cdb-check: [+0x000] v : 16 [Type: core::cell::UnsafeCell<i64>]
132138

133139
// cdb-command: dx a_isize
134140
// cdb-check:a_isize : 32 [Type: core::sync::atomic::AtomicIsize]
135-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicIsize]
141+
// cdb-check: [+0x000] v : 32 [Type: core::cell::UnsafeCell<isize>]
136142

137143
// cdb-command: dx a_u8
138144
// cdb-check:a_u8 : 0x40 [Type: core::sync::atomic::AtomicU8]
139-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicU8]
145+
// cdb-check: [+0x000] v : 0x40 [Type: core::cell::UnsafeCell<u8>]
140146

141147
// cdb-command: dx a_u16
142148
// cdb-check:a_u16 : 0x80 [Type: core::sync::atomic::AtomicU16]
143-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicU16]
149+
// cdb-check: [+0x000] v : 0x80 [Type: core::cell::UnsafeCell<u16>]
144150

145151
// cdb-command: dx a_u32
146152
// cdb-check:a_u32 : 0x100 [Type: core::sync::atomic::AtomicU32]
147-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicU32]
153+
// cdb-check: [+0x000] v : 0x100 [Type: core::cell::UnsafeCell<u32>]
148154

149155
// cdb-command: dx a_u64
150156
// cdb-check:a_u64 : 0x200 [Type: core::sync::atomic::AtomicU64]
151-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicU64]
157+
// cdb-check: [+0x000] v : 0x200 [Type: core::cell::UnsafeCell<u64>]
152158

153159
// cdb-command: dx a_usize
154160
// cdb-check:a_usize : 0x400 [Type: core::sync::atomic::AtomicUsize]
155-
// cdb-check: [<Raw View>] [Type: core::sync::atomic::AtomicUsize]
161+
// cdb-check: [+0x000] v : 0x400 [Type: core::cell::UnsafeCell<usize>]
156162

157163

158164
// === GDB TESTS ===================================================================================

Diff for: tests/debuginfo/range-types.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Testing the display of range types in cdb.
22

3-
// cdb-only
4-
//@ min-cdb-version: 10.0.18317.1001
3+
//@ only-cdb
4+
5+
// FIXME(jieyouxu): triple check in CI if the directive actually works
6+
//@ min-cdb-version: 10.0.26100.2161
7+
58
//@ compile-flags:-g
69

710
// === CDB TESTS ==================================================================================
@@ -10,23 +13,26 @@
1013

1114
// cdb-command: dx r1,d
1215
// cdb-check:r1,d : (3..5) [Type: core::ops::range::Range<i32>]
13-
// cdb-check: [<Raw View>] [Type: core::ops::range::Range<i32>]
16+
// cdb-check: [+0x000] start : 3 [Type: int]
17+
// cdb-check: [+0x004] end : 5 [Type: int]
1418

1519
// cdb-command: dx r2,d
1620
// cdb-check:r2,d : (2..) [Type: core::ops::range::RangeFrom<i32>]
17-
// cdb-check: [<Raw View>] [Type: core::ops::range::RangeFrom<i32>]
21+
// cdb-check: [+0x000] start : 2 [Type: int]
1822

1923
// cdb-command: dx r3,d
2024
// cdb-check:r3,d : (1..=4) [Type: core::ops::range::RangeInclusive<i32>]
21-
// cdb-check: [<Raw View>] [Type: core::ops::range::RangeInclusive<i32>]
25+
// cdb-check: [+0x000] start : 1 [Type: int]
26+
// cdb-check: [+0x004] end : 4 [Type: int]
27+
// cdb-check: [+0x008] exhausted : false [Type: bool]
2228

2329
// cdb-command: dx r4,d
2430
// cdb-check:r4,d : (..10) [Type: core::ops::range::RangeTo<i32>]
25-
// cdb-check: [<Raw View>] [Type: core::ops::range::RangeTo<i32>]
31+
// cdb-check: [+0x000] end : 10 [Type: int]
2632

2733
// cdb-command: dx r5,d
2834
// cdb-check:r5,d : (..=3) [Type: core::ops::range::RangeToInclusive<i32>]
29-
// cdb-check: [<Raw View>] [Type: core::ops::range::RangeToInclusive<i32>]
35+
// cdb-check: [+0x000] end : 3 [Type: int]
3036

3137
// cdb-command: dx r6,d
3238
// cdb-check:r6,d [Type: core::ops::range::RangeFull]

Diff for: tests/debuginfo/unit-type.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//@ compile-flags:-g
22

3+
// FIXME(jieyouxu): triple check if this works in CI
4+
//@ min-cdb-version: 10.0.26100.2161
5+
36
// === GDB TESTS ===================================================================================
47

58
// gdb-command: run
@@ -26,18 +29,18 @@
2629
// cdb-check: Breakpoint 0 hit
2730

2831
// cdb-command: dx _ref
29-
// cdb-check: _ref : 0x[...] : () [Type: tuple$<> *]
32+
// cdb-check: _ref : 0x[...] [Type: tuple$<> *]
3033

3134
// cdb-command: dx _ptr
32-
// cdb-check: _ptr : 0x[...] : () [Type: tuple$<> *]
35+
// cdb-check: _ptr : 0x[...] [Type: tuple$<> *]
3336

3437
// cdb-command: dx _local
35-
// cdb-check: _local : () [Type: tuple$<>]
38+
// cdb-check: _local [Type: tuple$<>]
3639

3740
// cdb-command: dx _field,d
3841
// cdb-check: _field,d [Type: unit_type::_TypeContainingUnitField]
3942
// cdb-check: [+0x[...]] _a : 123 [Type: unsigned int]
40-
// cdb-check: [+0x[...]] _unit : () [Type: tuple$<>]
43+
// cdb-check: [+0x[...]] _unit [Type: tuple$<>]
4144
// cdb-check: [+0x[...]] _b : 456 [Type: unsigned __int64]
4245

4346
// Check that we can cast "void pointers" to their actual type in the debugger

Diff for: tests/ui/lifetimes/raw/raw-lt-invalid-raw-id.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ edition: 2021
2+
3+
// Reject raw lifetimes with identifier parts that wouldn't be valid raw identifiers.
4+
5+
macro_rules! w {
6+
($tt:tt) => {};
7+
}
8+
9+
w!('r#_);
10+
//~^ ERROR `_` cannot be a raw lifetime
11+
w!('r#self);
12+
//~^ ERROR `self` cannot be a raw lifetime
13+
w!('r#super);
14+
//~^ ERROR `super` cannot be a raw lifetime
15+
w!('r#Self);
16+
//~^ ERROR `Self` cannot be a raw lifetime
17+
w!('r#crate);
18+
//~^ ERROR `crate` cannot be a raw lifetime
19+
20+
fn main() {}

Diff for: tests/ui/lifetimes/raw/raw-lt-invalid-raw-id.stderr

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: `_` cannot be a raw lifetime
2+
--> $DIR/raw-lt-invalid-raw-id.rs:9:4
3+
|
4+
LL | w!('r#_);
5+
| ^^^^
6+
7+
error: `self` cannot be a raw lifetime
8+
--> $DIR/raw-lt-invalid-raw-id.rs:11:4
9+
|
10+
LL | w!('r#self);
11+
| ^^^^^^^
12+
13+
error: `super` cannot be a raw lifetime
14+
--> $DIR/raw-lt-invalid-raw-id.rs:13:4
15+
|
16+
LL | w!('r#super);
17+
| ^^^^^^^^
18+
19+
error: `Self` cannot be a raw lifetime
20+
--> $DIR/raw-lt-invalid-raw-id.rs:15:4
21+
|
22+
LL | w!('r#Self);
23+
| ^^^^^^^
24+
25+
error: `crate` cannot be a raw lifetime
26+
--> $DIR/raw-lt-invalid-raw-id.rs:17:4
27+
|
28+
LL | w!('r#crate);
29+
| ^^^^^^^^
30+
31+
error: aborting due to 5 previous errors
32+

0 commit comments

Comments
 (0)