-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #116891 - aliemjay:opaque-region-infer-rework-2, r=comp…
…iler-errors,oli-obk rework opaque type region inference User-facing changes are documented in [this comment](#116891 (comment)). The design document is in [this comment](#116891 (comment)). --- \- Fix Ice in check_unique; ICE -> Error; fixes #122782. \- Ignore uncaptured lifetime args; ICE -> Pass; fixes #111906, fixes #110623, fixes #109059, fixes #122307 \- Except equal parameters from the uniqueness check; Pass -> Error; fixes #113916. \- Check RPITs for invalid args; Pass -> Error; fixes #111935; ICE -> Error; fixes #110726. \- Rework opaque types region inference; Pass -> Error; fixes #113971, fixes #112841. \- Reject external lifetimes as invalid args; Pass -> Error; fixes #105498. r? `@ghost`
- Loading branch information
Showing
40 changed files
with
879 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
379 changes: 210 additions & 169 deletions
379
compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/ui/impl-trait/defining-use-captured-non-universal-region.infer.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0792]: expected generic lifetime parameter, found `'_` | ||
--> $DIR/defining-use-captured-non-universal-region.rs:13:18 | ||
| | ||
LL | fn foo<'a>() -> impl Sized + 'a { | ||
| -- this generic parameter must be used with a generic lifetime parameter | ||
... | ||
LL | let i: i32 = foo::<'_>(); | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0792`. |
22 changes: 22 additions & 0 deletions
22
tests/ui/impl-trait/defining-use-captured-non-universal-region.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// This was an ICE. See #110726. | ||
|
||
//@ revisions: statik infer fixed | ||
//@ [fixed] check-pass | ||
#![allow(unconditional_recursion)] | ||
|
||
fn foo<'a>() -> impl Sized + 'a { | ||
#[cfg(statik)] | ||
let i: i32 = foo::<'static>(); | ||
//[statik]~^ ERROR expected generic lifetime parameter, found `'static` | ||
|
||
#[cfg(infer)] | ||
let i: i32 = foo::<'_>(); | ||
//[infer]~^ ERROR expected generic lifetime parameter, found `'_` | ||
|
||
#[cfg(fixed)] | ||
let i: i32 = foo::<'a>(); | ||
|
||
i | ||
} | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
tests/ui/impl-trait/defining-use-captured-non-universal-region.statik.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0792]: expected generic lifetime parameter, found `'static` | ||
--> $DIR/defining-use-captured-non-universal-region.rs:9:18 | ||
| | ||
LL | fn foo<'a>() -> impl Sized + 'a { | ||
| -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type | ||
LL | #[cfg(statik)] | ||
LL | let i: i32 = foo::<'static>(); | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0792`. |
74 changes: 74 additions & 0 deletions
74
tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// issue: #110623 | ||
//@ check-pass | ||
|
||
use std::{collections::BTreeMap, num::ParseIntError, str::FromStr}; | ||
|
||
enum FileSystem { | ||
File(usize), | ||
Directory(BTreeMap<String, FileSystem>), | ||
} | ||
|
||
impl FromStr for FileSystem { | ||
type Err = ParseIntError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
if s.starts_with("dir") { | ||
Ok(Self::new_dir()) | ||
} else { | ||
Ok(Self::File(s.split_whitespace().next().unwrap().parse()?)) | ||
} | ||
} | ||
} | ||
|
||
impl FileSystem { | ||
fn new_dir() -> FileSystem { | ||
FileSystem::Directory(BTreeMap::new()) | ||
} | ||
|
||
fn insert(&mut self, name: String, other: FileSystem) -> Option<FileSystem> { | ||
match self { | ||
FileSystem::File(_) => panic!("can only insert into directory!"), | ||
FileSystem::Directory(tree) => tree.insert(name, other), | ||
} | ||
} | ||
|
||
// Recursively build a tree from commands. This uses (abuses?) | ||
// the fact that `cd /` only appears at the start and that | ||
// subsequent `cd`s can only move ONE level to use the recursion | ||
// stack as the filesystem stack | ||
fn build<'a>( | ||
&mut self, | ||
mut commands: impl Iterator<Item = &'a str> + 'a, | ||
) -> Option<impl Iterator<Item = &'a str> + 'a> { | ||
let cmd = commands.next()?; | ||
let mut elements = cmd.lines(); | ||
match elements.next().map(str::trim) { | ||
Some("cd /") | None => self.build(commands), | ||
Some("cd ..") => { | ||
// return to higher scope | ||
Some(commands) | ||
} | ||
Some("ls") => { | ||
for item in elements { | ||
let name = item.split_whitespace().last().unwrap(); | ||
let prior = self.insert(name.to_string(), item.parse().unwrap()); | ||
debug_assert!(prior.is_none()); | ||
} | ||
// continue on | ||
self.build(commands) | ||
} | ||
Some(other_cd) => { | ||
let name = other_cd | ||
.trim() | ||
.strip_prefix("cd ") | ||
.expect("expected a cd command"); | ||
let mut directory = FileSystem::new_dir(); | ||
let further_commands = directory.build(commands); | ||
self.insert(name.to_string(), directory); | ||
self.build(further_commands?) // THIS LINE FAILS TO COMPILE | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
13 changes: 13 additions & 0 deletions
13
tests/ui/impl-trait/defining-use-uncaptured-non-universal-region-3.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ check-pass | ||
|
||
#![feature(adt_const_params)] | ||
#![allow(incomplete_features)] | ||
|
||
trait Bar<const FOO: &'static str> {} | ||
impl Bar<"asdf"> for () {} | ||
|
||
fn foo<const FOO: &'static str>() -> impl Bar<"asdf"> { | ||
() | ||
} | ||
|
||
fn main() {} |
16 changes: 16 additions & 0 deletions
16
tests/ui/impl-trait/defining-use-uncaptured-non-universal-region.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// issue: #111906 | ||
//@ check-pass | ||
|
||
#![allow(unconditional_recursion)] | ||
|
||
fn foo<'a: 'a>() -> impl Sized { | ||
let _: () = foo::<'a>(); | ||
loop {} | ||
} | ||
|
||
fn bar<'a: 'a>() -> impl Sized + 'a { | ||
let _: *mut &'a () = bar::<'a>(); | ||
loop {} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,11 @@ | ||
error: concrete type differs from previous defining opaque type use | ||
--> $DIR/impl-fn-predefined-lifetimes.rs:7:9 | ||
| | ||
LL | |x| x | ||
| ^ expected `impl Debug + '_`, got `&u8` | ||
| | ||
note: previous use here | ||
--> $DIR/impl-fn-predefined-lifetimes.rs:7:5 | ||
| | ||
LL | |x| x | ||
| ^^^^^ | ||
|
||
error[E0720]: cannot resolve opaque type | ||
--> $DIR/impl-fn-predefined-lifetimes.rs:4:35 | ||
error[E0792]: expected generic lifetime parameter, found `'_` | ||
--> $DIR/impl-fn-predefined-lifetimes.rs:5:9 | ||
| | ||
LL | fn a<'a>() -> impl Fn(&'a u8) -> (impl Debug + '_) { | ||
| ^^^^^^^^^^^^^^^ cannot resolve opaque type | ||
| -- this generic parameter must be used with a generic lifetime parameter | ||
LL | |x| x | ||
| ^ | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0720`. | ||
For more information about this error, try `rustc --explain E0792`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.