Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4af6137
Don't check unsize goal in MIR validation when opaques remain
compiler-errors Sep 28, 2024
7b3f161
Add gate for precise capturing in traits
compiler-errors Sep 29, 2024
e4bf471
Add variances to RPITITs
compiler-errors Sep 29, 2024
f2659ef
Clarify implicit captures for RPITIT
compiler-errors Sep 29, 2024
960ba89
Don't fire refinement lint if there are errors
compiler-errors Sep 29, 2024
becf664
Match std RUSTFLAGS for host and target for `mir-opt` test
jieyouxu Oct 9, 2024
62b24ea
Compiler: Replace remaining occurrences of "object safe" with "dyn co…
fmease Oct 9, 2024
2e7a52b
Rename feature object_safe_for_dispatch to dyn_compatible_for_dispatch
fmease Oct 9, 2024
20cebae
UI tests: Rename "object safe" to "dyn compatible"
fmease Oct 9, 2024
a21a9fe
Auto merge of #13464 - y21:issue13458, r=flip1995
bors Oct 10, 2024
b12dc20
add config to explicitely test rustc with autodiff/enzyme disabled
ZuseZ4 Oct 10, 2024
1edff46
Avoid redundant additions to PATH when linking
madsmtm Oct 10, 2024
1696043
Rollup merge of #130989 - compiler-errors:unsize-opaque, r=estebank
matthiaskrgr Oct 10, 2024
5d515e6
Rollup merge of #131033 - compiler-errors:precise-capturing-in-traits…
matthiaskrgr Oct 10, 2024
07aab90
Rollup merge of #131442 - jieyouxu:mir-opt-rebuild, r=onur-ozkan
matthiaskrgr Oct 10, 2024
760650c
Rollup merge of #131470 - EnzymeAD:enzyme-testinfra2, r=jieyouxu
matthiaskrgr Oct 10, 2024
d5624a2
Rollup merge of #131475 - fmease:compiler-mv-obj-safe-dyn-compat-2, r…
matthiaskrgr Oct 10, 2024
04257c1
Rollup merge of #131492 - flip1995:clippy-master-backport, r=matthias…
matthiaskrgr Oct 10, 2024
adb659f
Rollup merge of #131493 - madsmtm:avoid-redundant-linker-path, r=jiey…
matthiaskrgr Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add gate for precise capturing in traits
  • Loading branch information
compiler-errors committed Oct 8, 2024
commit 7b3f1616d0966f8643a99efbecd01ad6833ab679
19 changes: 14 additions & 5 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,11 +1573,20 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// Feature gate for RPITIT + use<..>
match origin {
rustc_hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl: Some(_), .. } => {
if let Some(span) = bounds.iter().find_map(|bound| match *bound {
ast::GenericBound::Use(_, span) => Some(span),
_ => None,
}) {
self.tcx.dcx().emit_err(errors::NoPreciseCapturesOnRpitit { span });
if !self.tcx.features().precise_capturing_in_traits
&& let Some(span) = bounds.iter().find_map(|bound| match *bound {
ast::GenericBound::Use(_, span) => Some(span),
_ => None,
})
{
let mut diag =
self.tcx.dcx().create_err(errors::NoPreciseCapturesOnRpitit { span });
add_feature_diagnostics(
&mut diag,
self.tcx.sess,
sym::precise_capturing_in_traits,
);
diag.emit();
}
}
_ => {}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ declare_features! (
(incomplete, pin_ergonomics, "CURRENT_RUSTC_VERSION", Some(130494)),
/// Allows postfix match `expr.match { ... }`
(unstable, postfix_match, "1.79.0", Some(121618)),
/// Allows `use<..>` precise capturign on impl Trait in traits.
(unstable, precise_capturing_in_traits, "CURRENT_RUSTC_VERSION", Some(130044)),
/// Allows macro attributes on expressions, statements and non-inline modules.
(unstable, proc_macro_hygiene, "1.30.0", Some(54727)),
/// Makes `&` and `&mut` patterns eat only one layer of references in Rust 2024.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,7 @@ symbols! {
powif64,
pre_dash_lto: "pre-lto",
precise_capturing,
precise_capturing_in_traits,
precise_pointer_size_matching,
pref_align_of,
prefetch_read_data,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
trait Foo {
fn test() -> impl Sized + use<Self>;
//~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
--> $DIR/feature-gate-precise_capturing_in_traits.rs:2:31
|
LL | fn test() -> impl Sized + use<Self>;
| ^^^^^^^^^
|
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
= note: see issue #130044 <https://github.com/rust-lang/rust/issues/130044> for more information
= help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ LL | fn bar() -> impl Sized + use<>;
| ^^^^^
|
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
= note: see issue #130044 <https://github.com/rust-lang/rust/issues/130044> for more information
= help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `impl Trait` must mention all type parameters in scope in `use<...>`
--> $DIR/forgot-to-capture-type.rs:1:23
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/impl-trait/precise-capturing/redundant.rpitit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ LL | fn in_trait() -> impl Sized + use<'a, Self>;
| ^^^^^^^^^^^^^
|
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
= note: see issue #130044 <https://github.com/rust-lang/rust/issues/130044> for more information
= help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits
--> $DIR/redundant.rs:21:35
Expand All @@ -13,6 +16,9 @@ LL | fn in_trait() -> impl Sized + use<'a> {}
| ^^^^^^^
|
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
= note: see issue #130044 <https://github.com/rust-lang/rust/issues/130044> for more information
= help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>;
| ^^^^^^^^^
|
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
= note: see issue #130044 <https://github.com/rust-lang/rust/issues/130044> for more information
= help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: return type captures more lifetimes than trait definition
--> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/impl-trait/precise-capturing/rpitit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ LL | fn hello() -> impl PartialEq + use<Self>;
| ^^^^^^^^^
|
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
= note: see issue #130044 <https://github.com/rust-lang/rust/issues/130044> for more information
= help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list
--> $DIR/rpitit.rs:9:19
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/impl-trait/precise-capturing/self-capture.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ LL | fn bar<'a>() -> impl Sized + use<Self>;
| ^^^^^^^^^
|
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope
= note: see issue #130044 <https://github.com/rust-lang/rust/issues/130044> for more information
= help: add `#![feature(precise_capturing_in_traits)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 1 previous error