This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit f132bcf
committed
Auto merge of rust-lang#94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis
Lazy type-alias-impl-trait take two
### user visible change 1: RPIT inference from recursive call sites
Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned.
```rust
fn bar(b: bool) -> impl std::fmt::Debug {
if b {
return 42
}
let x: u32 = bar(false); // this errors on stable
99
}
```
The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type.
### user visible change 2: divergence between RPIT and TAIT in return statements
Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So
```rust
#![feature(type_alias_impl_trait)]
type Foo = impl std::fmt::Debug;
fn foo(b: bool) -> Foo {
if b {
return vec![42];
}
std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator
}
fn bar(b: bool) -> impl std::fmt::Debug {
if b {
return vec![42]
}
std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended)
}
```
But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same:
```rust
type Foo = impl std::fmt::Debug;
fn foo(b: bool) -> Foo {
if b {
return vec![];
}
let mut x = foo(false);
x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator
vec![]
}
fn bar(b: bool) -> impl std::fmt::Debug {
if b {
return vec![];
}
let mut x = bar(false);
x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator
vec![]
}
```
### user visible change 3: TAIT does not merge types across branches
In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile.
```rust
type Foo = impl std::fmt::Debug;
fn foo(b: bool) -> Foo {
if b {
vec![42_i32]
} else {
std::iter::empty().collect()
//~^ ERROR `Foo` cannot be built from an iterator over elements of type `_`
}
}
```
It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this).
### PR formalities
previous attempt: rust-lang#92007
This PR also includes rust-lang#92306 and rust-lang#93783, as they were reverted along with rust-lang#92007 in rust-lang#93893
fixes rust-lang#93411
fixes rust-lang#88236
fixes rust-lang#89312
fixes rust-lang#87340
fixes rust-lang#86800
fixes rust-lang#86719
fixes rust-lang#84073
fixes rust-lang#83919
fixes rust-lang#82139
fixes rust-lang#77987
fixes rust-lang#74282
fixes rust-lang#67830
fixes rust-lang#62742
fixes rust-lang#54895File tree
419 files changed
+5204
-2486
lines changed- compiler
- rustc_borrowck/src
- diagnostics
- region_infer
- type_check
- rustc_const_eval/src/transform
- check_consts
- rustc_data_structures/src
- rustc_infer/src/infer
- canonical
- nll_relate
- opaque_types
- outlives
- rustc_middle/src
- infer
- mir
- ty
- print
- rustc_mir_build/src/build
- rustc_query_system/src/dep_graph
- rustc_trait_selection/src
- traits
- error_reporting
- query/type_op
- select
- rustc_traits/src/chalk
- rustc_type_ir/src
- rustc_typeck/src
- check
- fn_ctxt
- method
- collect
- src
- bootstrap/bin
- test
- incremental/hashes
- ui
- associated-type-bounds
- associated-types
- async-await
- multiple-lifetimes
- chalkify/bugs
- closures/2229_closure_analysis/diagnostics/borrowck
- const-generics/defaults
- entry-point
- feature-gates
- generator
- generic-associated-types
- bugs
- impl-trait
- issues
- multiple-lifetimes
- lazy-type-alias-impl-trait
- lifetimes
- lint
- never_type
- nll
- relate_tys
- ty-outlives
- parser
- polymorphization
- resolve
- save-analysis
- self
- suggestions
- traits
- alias
- type-alias-impl-trait
- tools/tidy/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
419 files changed
+5204
-2486
lines changedLines changed: 91 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| 10 | + | |
| 11 | + | |
8 | 12 | | |
9 | 13 | | |
10 | 14 | | |
| |||
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
79 | 92 | | |
80 | 93 | | |
81 | 94 | | |
| |||
116 | 129 | | |
117 | 130 | | |
118 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
119 | 138 | | |
120 | 139 | | |
121 | 140 | | |
| |||
130 | 149 | | |
131 | 150 | | |
132 | 151 | | |
133 | | - | |
| 152 | + | |
134 | 153 | | |
135 | 154 | | |
136 | 155 | | |
| |||
175 | 194 | | |
176 | 195 | | |
177 | 196 | | |
178 | | - | |
| 197 | + | |
179 | 198 | | |
180 | 199 | | |
181 | 200 | | |
| |||
208 | 227 | | |
209 | 228 | | |
210 | 229 | | |
211 | | - | |
| 230 | + | |
212 | 231 | | |
213 | 232 | | |
214 | 233 | | |
215 | 234 | | |
216 | | - | |
| 235 | + | |
217 | 236 | | |
218 | 237 | | |
219 | 238 | | |
220 | | - | |
| 239 | + | |
221 | 240 | | |
222 | 241 | | |
223 | 242 | | |
| |||
255 | 274 | | |
256 | 275 | | |
257 | 276 | | |
258 | | - | |
| 277 | + | |
259 | 278 | | |
260 | 279 | | |
261 | 280 | | |
262 | 281 | | |
263 | | - | |
| 282 | + | |
264 | 283 | | |
265 | 284 | | |
266 | 285 | | |
267 | | - | |
| 286 | + | |
268 | 287 | | |
269 | 288 | | |
270 | 289 | | |
| |||
316 | 335 | | |
317 | 336 | | |
318 | 337 | | |
319 | | - | |
| 338 | + | |
320 | 339 | | |
321 | 340 | | |
322 | 341 | | |
323 | 342 | | |
324 | | - | |
| 343 | + | |
325 | 344 | | |
326 | 345 | | |
327 | 346 | | |
328 | | - | |
| 347 | + | |
329 | 348 | | |
330 | 349 | | |
331 | 350 | | |
| |||
339 | 358 | | |
340 | 359 | | |
341 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
342 | 398 | | |
343 | 399 | | |
344 | 400 | | |
345 | 401 | | |
346 | 402 | | |
347 | 403 | | |
348 | 404 | | |
349 | | - | |
350 | | - | |
351 | 405 | | |
352 | 406 | | |
353 | 407 | | |
354 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
355 | 419 | | |
356 | | - | |
357 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
358 | 429 | | |
359 | 430 | | |
360 | 431 | | |
361 | 432 | | |
362 | 433 | | |
363 | 434 | | |
364 | 435 | | |
365 | | - | |
| 436 | + | |
366 | 437 | | |
367 | 438 | | |
368 | 439 | | |
369 | | - | |
370 | | - | |
| 440 | + | |
371 | 441 | | |
372 | 442 | | |
373 | 443 | | |
374 | 444 | | |
375 | 445 | | |
376 | 446 | | |
377 | 447 | | |
378 | | - | |
| 448 | + | |
379 | 449 | | |
380 | 450 | | |
381 | 451 | | |
| |||
392 | 462 | | |
393 | 463 | | |
394 | 464 | | |
395 | | - | |
396 | | - | |
| 465 | + | |
| 466 | + | |
397 | 467 | | |
398 | 468 | | |
399 | 469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| 129 | + | |
128 | 130 | | |
129 | | - | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | 134 | | |
| |||
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
144 | | - | |
| 146 | + | |
145 | 147 | | |
146 | 148 | | |
147 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
| 375 | + | |
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
267 | 268 | | |
268 | 269 | | |
269 | 270 | | |
270 | | - | |
| 271 | + | |
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
| |||
292 | 293 | | |
293 | 294 | | |
294 | 295 | | |
| 296 | + | |
295 | 297 | | |
296 | 298 | | |
297 | 299 | | |
| |||
0 commit comments