From dfee48cd7297a36facf8e9fa6452fe6c84c9c8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Fri, 23 Oct 2026 15:16:17 +0200 Subject: [PATCH 01/10] Extend support of lint `explicit_outlives_requirements` to checked type aliases --- compiler/rustc_lint/src/builtin.rs | 330 +++++++++--------- .../lint-explicit-outlives-requirements.fixed | 14 + .../lint-explicit-outlives-requirements.rs | 14 + ...lint-explicit-outlives-requirements.stderr | 20 ++ .../edition-lint-infer-outlives-macro.fixed | 8 +- .../edition-lint-infer-outlives-macro.stderr | 16 +- ...ition-lint-infer-outlives-multispan.stderr | 8 +- .../edition-lint-infer-outlives.fixed | 16 +- .../edition-lint-infer-outlives.stderr | 32 +- 9 files changed, 252 insertions(+), 206 deletions(-) create mode 100644 tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.fixed create mode 100644 tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.rs create mode 100644 tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.stderr diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 2b1e0a24294d2..94d8d82729f08 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1976,204 +1976,202 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements { use rustc_middle::middle::resolve_bound_vars::ResolvedArg; let def_id = item.owner_id.def_id; - if let hir::ItemKind::Struct(_, generics, _) - | hir::ItemKind::Enum(_, generics, _) - | hir::ItemKind::Union(_, generics, _) = item.kind - { - let inferred_outlives = cx.tcx.inferred_outlives_of(def_id); - if inferred_outlives.is_empty() { - return; + + let generics = match item.kind { + hir::ItemKind::Struct(_, generics, _) + | hir::ItemKind::Enum(_, generics, _) + | hir::ItemKind::Union(_, generics, _) => generics, + hir::ItemKind::TyAlias(_, generics, _) if cx.tcx.type_alias_is_checked(def_id) => { + generics } + _ => return, + }; + + let inferred_outlives = cx.tcx.inferred_outlives_of(def_id); + if inferred_outlives.is_empty() { + return; + } - let ty_generics = cx.tcx.generics_of(def_id); - let num_where_predicates = generics - .predicates - .iter() - .filter(|predicate| predicate.kind.in_where_clause()) - .count(); - - let mut bound_count = 0; - let mut lint_spans = Vec::new(); - let mut where_lint_spans = Vec::new(); - let mut dropped_where_predicate_count = 0; - for (i, where_predicate) in generics.predicates.iter().enumerate() { - let (relevant_lifetimes, bounds, predicate_span, in_where_clause) = - match where_predicate.kind { - hir::WherePredicateKind::RegionPredicate(predicate) => { - if let Some(ResolvedArg::EarlyBound(region_def_id)) = - cx.tcx.named_bound_var(predicate.lifetime.hir_id) - { + let ty_generics = cx.tcx.generics_of(def_id); + let num_where_predicates = + generics.predicates.iter().filter(|predicate| predicate.kind.in_where_clause()).count(); + + let mut bound_count = 0; + let mut lint_spans = Vec::new(); + let mut where_lint_spans = Vec::new(); + let mut dropped_where_predicate_count = 0; + for (i, where_predicate) in generics.predicates.iter().enumerate() { + let (relevant_lifetimes, bounds, predicate_span, in_where_clause) = + match where_predicate.kind { + hir::WherePredicateKind::RegionPredicate(predicate) => { + if let Some(ResolvedArg::EarlyBound(region_def_id)) = + cx.tcx.named_bound_var(predicate.lifetime.hir_id) + { + ( + Self::lifetimes_outliving_lifetime( + cx.tcx, + // don't warn if the inferred span actually came from the predicate we're looking at + // this happens if the type is recursively defined + inferred_outlives + .iter() + .filter(|(_, span)| !where_predicate.span.contains(*span)), + item.owner_id.def_id, + region_def_id, + ), + &predicate.bounds, + where_predicate.span, + predicate.in_where_clause, + ) + } else { + continue; + } + } + hir::WherePredicateKind::BoundPredicate(predicate) => { + // FIXME we can also infer bounds on associated types, + // and should check for them here. + match predicate.bounded_ty.kind { + hir::TyKind::Path(hir::QPath::Resolved(None, path)) => { + let Res::Def(DefKind::TyParam, def_id) = path.res else { + continue; + }; + let index = ty_generics.param_def_id_to_index[&def_id]; + // Removing a `T: 'r` outlives bound can silently change + // the object lifetime default for `Struct<'r, dyn Trait>` + // (RFC 599): the explicit bound sets the default to `'r`, + // so removing it may change it to `'static` (or cause an + // ambiguity error if there is no unique default). Only + // suppress the lint for non-higher-ranked predicates when + // T is not `Sized` (i.e. can hold trait object types). + // Higher-ranked predicates (`for<'x> T: 'r`) are excluded + // from RFC 599 object lifetime defaulting and are always + // safe to remove. + if predicate.bound_generic_params.is_empty() { + let ty_param = &ty_generics.own_params[index as usize]; + let param_ty = + Ty::new_param(cx.tcx, ty_param.index, ty_param.name); + if !param_ty.is_sized(cx.tcx, cx.typing_env()) { + continue; + } + } ( - Self::lifetimes_outliving_lifetime( - cx.tcx, + Self::lifetimes_outliving_type( // don't warn if the inferred span actually came from the predicate we're looking at // this happens if the type is recursively defined inferred_outlives.iter().filter(|(_, span)| { !where_predicate.span.contains(*span) }), - item.owner_id.def_id, - region_def_id, + index, ), &predicate.bounds, where_predicate.span, - predicate.in_where_clause, + predicate.origin == PredicateOrigin::WhereClause, ) - } else { - continue; } - } - hir::WherePredicateKind::BoundPredicate(predicate) => { - // FIXME we can also infer bounds on associated types, - // and should check for them here. - match predicate.bounded_ty.kind { - hir::TyKind::Path(hir::QPath::Resolved(None, path)) => { - let Res::Def(DefKind::TyParam, def_id) = path.res else { - continue; - }; - let index = ty_generics.param_def_id_to_index[&def_id]; - // Removing a `T: 'r` outlives bound can silently change - // the object lifetime default for `Struct<'r, dyn Trait>` - // (RFC 599): the explicit bound sets the default to `'r`, - // so removing it may change it to `'static` (or cause an - // ambiguity error if there is no unique default). Only - // suppress the lint for non-higher-ranked predicates when - // T is not `Sized` (i.e. can hold trait object types). - // Higher-ranked predicates (`for<'x> T: 'r`) are excluded - // from RFC 599 object lifetime defaulting and are always - // safe to remove. - if predicate.bound_generic_params.is_empty() { - let ty_param = &ty_generics.own_params[index as usize]; - let param_ty = - Ty::new_param(cx.tcx, ty_param.index, ty_param.name); - if !param_ty.is_sized(cx.tcx, cx.typing_env()) { - continue; - } - } - ( - Self::lifetimes_outliving_type( - // don't warn if the inferred span actually came from the predicate we're looking at - // this happens if the type is recursively defined - inferred_outlives.iter().filter(|(_, span)| { - !where_predicate.span.contains(*span) - }), - index, - ), - &predicate.bounds, - where_predicate.span, - predicate.origin == PredicateOrigin::WhereClause, - ) - } - _ => { - continue; - } + _ => { + continue; } } - }; - if relevant_lifetimes.is_empty() { - continue; - } + } + }; + if relevant_lifetimes.is_empty() { + continue; + } - let bound_spans = self.collect_outlives_bound_spans( - cx.tcx, - bounds, - &relevant_lifetimes, - predicate_span, - item.owner_id.to_def_id(), - ); - bound_count += bound_spans.len(); + let bound_spans = self.collect_outlives_bound_spans( + cx.tcx, + bounds, + &relevant_lifetimes, + predicate_span, + item.owner_id.to_def_id(), + ); + bound_count += bound_spans.len(); - let drop_predicate = bound_spans.len() == bounds.len(); - if drop_predicate && in_where_clause { - dropped_where_predicate_count += 1; - } + let drop_predicate = bound_spans.len() == bounds.len(); + if drop_predicate && in_where_clause { + dropped_where_predicate_count += 1; + } - if drop_predicate { - if !in_where_clause { - lint_spans.push(predicate_span); - } else if predicate_span.from_expansion() { - // Don't try to extend the span if it comes from a macro expansion. + if drop_predicate { + if !in_where_clause { + lint_spans.push(predicate_span); + } else if predicate_span.from_expansion() { + // Don't try to extend the span if it comes from a macro expansion. + where_lint_spans.push(predicate_span); + } else if i + 1 < num_where_predicates { + // If all the bounds on a predicate were inferable and there are + // further predicates, we want to eat the trailing comma. + let next_predicate_span = generics.predicates[i + 1].span; + if next_predicate_span.from_expansion() { where_lint_spans.push(predicate_span); - } else if i + 1 < num_where_predicates { - // If all the bounds on a predicate were inferable and there are - // further predicates, we want to eat the trailing comma. - let next_predicate_span = generics.predicates[i + 1].span; - if next_predicate_span.from_expansion() { - where_lint_spans.push(predicate_span); - } else { - where_lint_spans - .push(predicate_span.to(next_predicate_span.shrink_to_lo())); - } } else { - // Eat the optional trailing comma after the last predicate. - let where_span = generics.where_clause_span; - if where_span.from_expansion() { - where_lint_spans.push(predicate_span); - } else { - where_lint_spans.push(predicate_span.to(where_span.shrink_to_hi())); - } + where_lint_spans + .push(predicate_span.to(next_predicate_span.shrink_to_lo())); } } else { - where_lint_spans.extend(self.consolidate_outlives_bound_spans( - predicate_span.shrink_to_lo(), - bounds, - bound_spans, - )); + // Eat the optional trailing comma after the last predicate. + let where_span = generics.where_clause_span; + if where_span.from_expansion() { + where_lint_spans.push(predicate_span); + } else { + where_lint_spans.push(predicate_span.to(where_span.shrink_to_hi())); + } } + } else { + where_lint_spans.extend(self.consolidate_outlives_bound_spans( + predicate_span.shrink_to_lo(), + bounds, + bound_spans, + )); } + } - // If all predicates in where clause are inferable, drop the entire clause - // (including the `where`) - if generics.has_where_clause_predicates - && dropped_where_predicate_count == num_where_predicates - { - let where_span = generics.where_clause_span; - // Extend the where clause back to the closing `>` of the - // generics, except for tuple struct, which have the `where` - // after the fields of the struct. - let full_where_span = - if let hir::ItemKind::Struct(_, _, hir::VariantData::Tuple(..)) = item.kind { - where_span - } else { - generics.span.shrink_to_hi().to(where_span) - }; - - // Due to macro expansions, the `full_where_span` might not actually contain all - // predicates. - if where_lint_spans.iter().all(|&sp| full_where_span.contains(sp)) { - lint_spans.push(full_where_span); - } else { - lint_spans.extend(where_lint_spans); - } + // If all predicates in the where clause are inferable, drop the entire clause + // (including the `where`) + if generics.has_where_clause_predicates + && dropped_where_predicate_count == num_where_predicates + { + let where_span = generics.where_clause_span; + let full_where_span = cx + .sess() + .source_map() + .span_extend_prev_while(where_span, char::is_whitespace) + .unwrap_or(where_span); + + // Due to macro expansions, the `full_where_span` might not actually contain all + // predicates. + if where_lint_spans.iter().all(|&sp| full_where_span.contains(sp)) { + lint_spans.push(full_where_span); } else { lint_spans.extend(where_lint_spans); } + } else { + lint_spans.extend(where_lint_spans); + } - if !lint_spans.is_empty() { - // Do not automatically delete outlives requirements from macros. - let applicability = if lint_spans.iter().all(|sp| sp.can_be_used_for_suggestions()) - { - Applicability::MachineApplicable - } else { - Applicability::MaybeIncorrect - }; + if !lint_spans.is_empty() { + // Do not automatically delete outlives requirements from macros. + let applicability = if lint_spans.iter().all(|sp| sp.can_be_used_for_suggestions()) { + Applicability::MachineApplicable + } else { + Applicability::MaybeIncorrect + }; - // Due to macros, there might be several predicates with the same span - // and we only want to suggest removing them once. - lint_spans.sort_unstable_by_key(|span| span.lo_hi()); - lint_spans.dedup_by_key(|span| span.lo_hi()); + // Due to macros, there might be several predicates with the same span + // and we only want to suggest removing them once. + lint_spans.sort_unstable_by_key(|span| span.lo_hi()); + lint_spans.dedup_by_key(|span| span.lo_hi()); - cx.emit_span_lint( - EXPLICIT_OUTLIVES_REQUIREMENTS, - lint_spans.clone(), - BuiltinExplicitOutlives { - suggestion: BuiltinExplicitOutlivesSuggestion { - spans: lint_spans, - applicability, - count: bound_count, - }, + cx.emit_span_lint( + EXPLICIT_OUTLIVES_REQUIREMENTS, + lint_spans.clone(), + BuiltinExplicitOutlives { + suggestion: BuiltinExplicitOutlivesSuggestion { + spans: lint_spans, + applicability, + count: bound_count, }, - ); - } + }, + ); } } } diff --git a/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.fixed b/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.fixed new file mode 100644 index 0000000000000..8afe48b5ee3c3 --- /dev/null +++ b/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.fixed @@ -0,0 +1,14 @@ +// Test that lint `explicit_outlives_requirements` can also trigger on CTAs. + +//@ check-pass +//@ run-rustfix + +#![feature(checked_type_aliases)] +#![warn(explicit_outlives_requirements)] +#![allow(dead_code)] + +type A0<'a, T> = &'a T; //~ WARN [explicit_outlives_requirements] + +type A1<'a, T> = &'a T; //~ WARN [explicit_outlives_requirements] + +fn main() {} diff --git a/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.rs b/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.rs new file mode 100644 index 0000000000000..a12c31e8726d8 --- /dev/null +++ b/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.rs @@ -0,0 +1,14 @@ +// Test that lint `explicit_outlives_requirements` can also trigger on CTAs. + +//@ check-pass +//@ run-rustfix + +#![feature(checked_type_aliases)] +#![warn(explicit_outlives_requirements)] +#![allow(dead_code)] + +type A0<'a, T: 'a> = &'a T; //~ WARN [explicit_outlives_requirements] + +type A1<'a, T> = &'a T where T: 'a; //~ WARN [explicit_outlives_requirements] + +fn main() {} diff --git a/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.stderr b/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.stderr new file mode 100644 index 0000000000000..dabd9cf613afa --- /dev/null +++ b/tests/ui/checked-type-aliases/lint-explicit-outlives-requirements.stderr @@ -0,0 +1,20 @@ +warning: outlives requirements can be inferred + --> $DIR/lint-explicit-outlives-requirements.rs:10:14 + | +LL | type A0<'a, T: 'a> = &'a T; + | ^^^^ help: remove this bound + | +note: the lint level is defined here + --> $DIR/lint-explicit-outlives-requirements.rs:7:9 + | +LL | #![warn(explicit_outlives_requirements)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: outlives requirements can be inferred + --> $DIR/lint-explicit-outlives-requirements.rs:12:23 + | +LL | type A1<'a, T> = &'a T where T: 'a; + | ^^^^^^^^^^^^ help: remove this bound + +warning: 2 warnings emitted + diff --git a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.fixed b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.fixed index 435857224ac31..1ed17ed4061e9 100644 --- a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.fixed +++ b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.fixed @@ -40,7 +40,7 @@ mod everything_inside { ('b: 'a) => { struct Foo<'a, 'b>(&'a &'b ()); //~^ ERROR: outlives requirements can be inferred - struct Bar<'a, 'b>(&'a &'b ()) ; + struct Bar<'a, 'b>(&'a &'b ()); //~^ ERROR: outlives requirements can be inferred struct Baz<'a, 'b>(&'a &'b ()) where (): Sized, ; //~^ ERROR: outlives requirements can be inferred @@ -54,7 +54,7 @@ mod inner_lifetime_outside_colon_inside { ($b:lifetime: 'a) => { struct Foo<'a, $b>(&'a &$b ()); //~^ ERROR: outlives requirements can be inferred - struct Bar<'a, $b>(&'a &$b ()) ; + struct Bar<'a, $b>(&'a &$b ()); //~^ ERROR: outlives requirements can be inferred struct Baz<'a, $b>(&'a &$b ()) where (): Sized, ; //~^ ERROR: outlives requirements can be inferred @@ -114,7 +114,7 @@ mod everything_outside_with_tt_outer { // FIXME: replacement span is corrupted due to a collision in metavar span table. // struct Foo<$a, $b $colon $a>(&$a &$b ()); // ^ ERROR: outlives requirements can be inferred - struct Bar<$a, $b>(&$a &$b ()) ; + struct Bar<$a, $b>(&$a &$b ()); //~^ ERROR: outlives requirements can be inferred struct Baz<$a, $b>(&$a &$b ()) where (): Sized, ; //~^ ERROR: outlives requirements can be inferred @@ -129,7 +129,7 @@ mod everything_outside_with_tt_both { // FIXME: replacement span is corrupted due to a collision in metavar span table. // struct Foo<$a, $b $colon $a>(&$a &$b ()); // ^ ERROR: outlives requirements can be inferred - struct Bar<$a, $b>(&$a &$b ()) ; + struct Bar<$a, $b>(&$a &$b ()); //~^ ERROR: outlives requirements can be inferred struct Baz<$a, $b>(&$a &$b ()) where (): Sized, ; //~^ ERROR: outlives requirements can be inferred diff --git a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.stderr b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.stderr index cda31ed346f28..55f462098b24f 100644 --- a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.stderr +++ b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-macro.stderr @@ -28,12 +28,12 @@ LL | m!('b: 'a); | ---------- in this macro invocation error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-macro.rs:43:44 + --> $DIR/edition-lint-infer-outlives-macro.rs:43:43 | LL | macro_rules! m { ... LL | struct Bar<'a, 'b>(&'a &'b ()) where 'b: 'a; - | ^^^^^^^^^^^^ help: remove this bound + | ^^^^^^^^^^^^^ help: remove this bound ... LL | m!('b: 'a); | ---------- in this macro invocation @@ -61,12 +61,12 @@ LL | m!('b: 'a); | ---------- in this macro invocation error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-macro.rs:57:44 + --> $DIR/edition-lint-infer-outlives-macro.rs:57:43 | LL | macro_rules! m { ... LL | struct Bar<'a, $b>(&'a &$b ()) where $b: 'a; - | ^^^^^^^^^^^^ help: remove this bound + | ^^^^^^^^^^^^^ help: remove this bound ... LL | m!('b: 'a); | ---------- in this macro invocation @@ -83,12 +83,12 @@ LL | m!('b: 'a); | ---------- in this macro invocation error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-macro.rs:117:44 + --> $DIR/edition-lint-infer-outlives-macro.rs:117:43 | LL | macro_rules! m { ... LL | struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a; - | ^^^^^^^^^^^^^^^^^^ help: remove this bound + | ^^^^^^^^^^^^^^^^^^^ help: remove this bound ... LL | m!('b: 'a); | ---------- in this macro invocation @@ -105,12 +105,12 @@ LL | m!('b: 'a); | ---------- in this macro invocation error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-macro.rs:132:44 + --> $DIR/edition-lint-infer-outlives-macro.rs:132:43 | LL | macro_rules! m { ... LL | struct Bar<$a, $b>(&$a &$b ()) where $b $colon $a; - | ^^^^^^^^^^^^^^^^^^ help: remove this bound + | ^^^^^^^^^^^^^^^^^^^ help: remove this bound ... LL | m!('b: 'a); | ---------- in this macro invocation diff --git a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-multispan.stderr b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-multispan.stderr index b2d4c3d035890..cfe01a6693426 100644 --- a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-multispan.stderr +++ b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives-multispan.stderr @@ -271,12 +271,12 @@ error: outlives requirements can be inferred --> $DIR/edition-lint-infer-outlives-multispan.rs:130:46 | LL | struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: 'b; - | ^^^^ ^^^^^^^^^^^ + | ^^^^ ^^^^^^^^^^^^ | help: remove these bounds | LL - struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U>(&'a T, &'b U) where U: 'b; -LL + struct TeeOutlivesAyYooWhereBee<'a, 'b, T, U>(&'a T, &'b U) ; +LL + struct TeeOutlivesAyYooWhereBee<'a, 'b, T, U>(&'a T, &'b U); | error: outlives requirements can be inferred @@ -831,12 +831,12 @@ LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15); | --------------------------------------------------------- in this macro invocation error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives-multispan.rs:374:64 + --> $DIR/edition-lint-infer-outlives-multispan.rs:374:63 | LL | macro_rules! m { ... LL | struct FullWhere<'a, $($name,)+>(&'a ($($name,)+)) where $($name: 'a,)+; - | ^^^^^^^^^^^^^^^^^^ help: remove these bounds + | ^^^^^^^^^^^^^^^^^^^ help: remove these bounds ... LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15); | --------------------------------------------------------- in this macro invocation diff --git a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.fixed b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.fixed index fbf31764b6878..03a2699c4f027 100644 --- a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.fixed +++ b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.fixed @@ -253,7 +253,7 @@ mod tuple_structs { struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug>(&'a &'b T); //~^ ERROR outlives requirements can be inferred - struct TeeWhereOutlivesAy<'a, T>(&'a T) ; + struct TeeWhereOutlivesAy<'a, T>(&'a T); //~^ ERROR outlives requirements can be inferred struct TeeWhereOutlivesAyIsDebug<'a, T>(&'a T) where T: Debug; @@ -262,7 +262,7 @@ mod tuple_structs { struct TeeWhereIsDebugOutlivesAy<'a, T>(&'a T) where T: Debug; //~^ ERROR outlives requirements can be inferred - struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T) ; + struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T); //~^ ERROR outlives requirements can be inferred struct TeeWhereOutlivesAyBeeIsDebug<'a, 'b, T>(&'a &'b T) where T: Debug; @@ -295,7 +295,7 @@ mod tuple_structs { struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T, U: Debug>(&'a &'b T, U); //~^ ERROR outlives requirements can be inferred - struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U) ; + struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U); //~^ ERROR outlives requirements can be inferred struct TeeYooWhereOutlivesAyIsDebug<'a, T, U>(T, &'a U) where U: Debug; @@ -307,7 +307,7 @@ mod tuple_structs { struct TeeOutlivesAyYooWhereIsDebug<'a, T, U>(&'a T, U) where U: Debug; //~^ ERROR outlives requirements can be inferred - struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) ; + struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U); //~^ ERROR outlives requirements can be inferred struct TeeYooWhereOutlivesAyBeeIsDebug<'a, 'b, T, U>(T, &'a &'b U) where U: Debug; @@ -328,19 +328,19 @@ mod tuple_structs { struct BeeOutlivesAy<'a, 'b>(&'a &'b ()); //~^ ERROR outlives requirements can be inferred - struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ()) ; + struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ()); //~^ ERROR outlives requirements can be inferred struct BeeOutlivesAyTee<'a, 'b, T>(&'a &'b T); //~^ ERROR outlives requirements can be inferred - struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T) ; + struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T); //~^ ERROR outlives requirements can be inferred - struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T) ; + struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T); //~^ ERROR outlives requirements can be inferred - struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T) ; + struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T); //~^ ERROR outlives requirements can be inferred struct BeeOutlivesAyTeeDebug<'a, 'b, T: Debug>(&'a &'b T); diff --git a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.stderr b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.stderr index 472900b52d470..6911f46497c42 100644 --- a/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.stderr +++ b/tests/ui/rust-2018/edition-lint-inter-outlives/edition-lint-infer-outlives.stderr @@ -283,10 +283,10 @@ LL | struct TeeIsDebugOutlivesAyBee<'a, 'b, T: Debug + 'a + 'b>(&'a &'b T); | ^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:256:45 + --> $DIR/edition-lint-infer-outlives.rs:256:44 | LL | struct TeeWhereOutlivesAy<'a, T>(&'a T) where T: 'a; - | ^^^^^^^^^^^ help: remove this bound + | ^^^^^^^^^^^^ help: remove this bound error: outlives requirements can be inferred --> $DIR/edition-lint-infer-outlives.rs:259:61 @@ -301,10 +301,10 @@ LL | struct TeeWhereIsDebugOutlivesAy<'a, T>(&'a T) where T: Debug + 'a; | ^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:265:56 + --> $DIR/edition-lint-infer-outlives.rs:265:55 | LL | struct TeeWhereOutlivesAyBee<'a, 'b, T>(&'a &'b T) where T: 'a + 'b; - | ^^^^^^^^^^^^^^^^ help: remove these bounds + | ^^^^^^^^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred --> $DIR/edition-lint-infer-outlives.rs:268:72 @@ -367,10 +367,10 @@ LL | struct TeeOutlivesAyBeeYooIsDebug<'a, 'b, T: 'a + 'b, U: Debug>(&'a &'b | ^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:298:54 + --> $DIR/edition-lint-infer-outlives.rs:298:53 | LL | struct TeeYooWhereOutlivesAy<'a, T, U>(T, &'a U) where U: 'a; - | ^^^^^^^^^^^ help: remove this bound + | ^^^^^^^^^^^^ help: remove this bound error: outlives requirements can be inferred --> $DIR/edition-lint-infer-outlives.rs:301:70 @@ -391,10 +391,10 @@ LL | struct TeeOutlivesAyYooWhereIsDebug<'a, T: 'a, U>(&'a T, U) where U: De | ^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:310:65 + --> $DIR/edition-lint-infer-outlives.rs:310:64 | LL | struct TeeYooWhereOutlivesAyBee<'a, 'b, T, U>(T, &'a &'b U) where U: 'a + 'b; - | ^^^^^^^^^^^^^^^^ help: remove these bounds + | ^^^^^^^^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred --> $DIR/edition-lint-infer-outlives.rs:313:81 @@ -433,10 +433,10 @@ LL | struct BeeOutlivesAy<'a, 'b: 'a>(&'a &'b ()); | ^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:331:51 + --> $DIR/edition-lint-infer-outlives.rs:331:50 | LL | struct BeeWhereOutlivesAy<'a, 'b>(&'a &'b ()) where 'b: 'a; - | ^^^^^^^^^^^^ help: remove this bound + | ^^^^^^^^^^^^^ help: remove this bound error: outlives requirements can be inferred --> $DIR/edition-lint-infer-outlives.rs:334:35 @@ -445,22 +445,22 @@ LL | struct BeeOutlivesAyTee<'a, 'b: 'a, T>(&'a &'b T); | ^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:337:56 + --> $DIR/edition-lint-infer-outlives.rs:337:55 | LL | struct BeeWhereOutlivesAyTee<'a, 'b, T>(&'a &'b T) where 'b: 'a; - | ^^^^^^^^^^^^ help: remove this bound + | ^^^^^^^^^^^^^ help: remove this bound error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:340:64 + --> $DIR/edition-lint-infer-outlives.rs:340:63 | LL | struct BeeWhereOutlivesAyTeeWhereBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'b; - | ^^^^^^^^^^^^^^^^^^^ help: remove these bounds + | ^^^^^^^^^^^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred - --> $DIR/edition-lint-infer-outlives.rs:343:66 + --> $DIR/edition-lint-infer-outlives.rs:343:65 | LL | struct BeeWhereOutlivesAyTeeWhereAyBee<'a, 'b, T>(&'a &'b T) where 'b: 'a, T: 'a + 'b; - | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds + | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove these bounds error: outlives requirements can be inferred --> $DIR/edition-lint-infer-outlives.rs:346:40 From 4f3fddad610fbcf70ead799d8fdb28645b00ef83 Mon Sep 17 00:00:00 2001 From: Bas Schoenmaeckers Date: Tue, 3 Nov 2026 14:48:57 +0100 Subject: [PATCH 02/10] Implement `FnAddr` --- compiler/rustc_attr_ir/src/lang_items.rs | 4 ++- .../rustc_const_eval/src/interpret/call.rs | 2 +- compiler/rustc_middle/src/mir/visit.rs | 2 +- compiler/rustc_middle/src/mono.rs | 2 +- .../src/ty/context/impl_interner.rs | 1 + compiler/rustc_middle/src/ty/instance.rs | 8 ++--- compiler/rustc_middle/src/ty/print/mod.rs | 2 +- compiler/rustc_mir_transform/src/inline.rs | 2 +- .../rustc_mir_transform/src/inline/cycle.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 8 ++--- compiler/rustc_monomorphize/src/collector.rs | 2 +- .../rustc_monomorphize/src/partitioning.rs | 4 +-- .../src/solve/assembly/mod.rs | 3 ++ .../cfi/typeid/itanium_cxx_abi/transform.rs | 4 +-- compiler/rustc_span/src/symbol.rs | 4 ++- .../src/traits/select/candidate_assembly.rs | 3 ++ .../src/traits/select/confirmation.rs | 1 + compiler/rustc_ty_utils/src/instance.rs | 30 ++++++++++++------- compiler/rustc_type_ir/src/lang_items.rs | 1 + library/core/src/ops/function.rs | 20 +++++++++---- library/core/src/ops/mod.rs | 2 +- tests/ui/fn/fn-ptr-trait-run.rs | 2 +- 22 files changed, 70 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_attr_ir/src/lang_items.rs b/compiler/rustc_attr_ir/src/lang_items.rs index d715a6d3af8c5..a75359d6ef4f5 100644 --- a/compiler/rustc_attr_ir/src/lang_items.rs +++ b/compiler/rustc_attr_ir/src/lang_items.rs @@ -186,7 +186,9 @@ language_item_table! { UnsafeUnpin, sym::unsafe_unpin, unsafe_unpin_trait, Target::Trait, GenericRequirement::Exact(0); FnPtrTrait, sym::fn_ptr_trait, fn_ptr_trait, Target::Trait, GenericRequirement::Exact(0); - FnPtrAsPtr, sym::fn_ptr_as_ptr, fn_ptr_as_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + FnAddrTrait, sym::fn_addr_trait, fn_addr_trait, Target::Trait, GenericRequirement::Exact(0); + FnAddrAsPtr, sym::fn_addr_as_ptr, fn_addr_as_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + FnAddrAddrFn, sym::fn_addr_addr_fn, fn_addr_addr_fn, Target::Method(MethodKind::Trait { body: true }), GenericRequirement::None; FnPtrFromPtr, sym::fn_ptr_from_ptr, fn_ptr_from_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; Code, sym::code, code, Target::ForeignTy, GenericRequirement::None; diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index bd3b17b9717b9..5984448fcabdb 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -842,7 +842,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { | ty::InstanceKind::Shim(ty::ShimKind::FnPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(..)) | ty::InstanceKind::Shim(ty::ShimKind::Clone(..)) - | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(..)) + | ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(..)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(..)) diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 2fc07d1c43cd3..20e9f70691b5a 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -362,7 +362,7 @@ macro_rules! make_mir_visitor { ty::InstanceKind::Shim(ty::ShimKind::FnPtr(_def_id, ty)) | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id, Some(ty))) | ty::InstanceKind::Shim(ty::ShimKind::Clone(_def_id, ty)) - | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(_def_id, ty)) + | ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr(_def_id, ty)) | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(_def_id, ty)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(_def_id, ty)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(_def_id, ty)) => { diff --git a/compiler/rustc_middle/src/mono.rs b/compiler/rustc_middle/src/mono.rs index afefe410d3043..21569b4d62180 100644 --- a/compiler/rustc_middle/src/mono.rs +++ b/compiler/rustc_middle/src/mono.rs @@ -548,7 +548,7 @@ impl<'tcx> CodegenUnit<'tcx> { | InstanceKind::Shim(ShimKind::DropGlue(..)) | InstanceKind::Shim(ShimKind::Clone(..)) | InstanceKind::Shim(ShimKind::ThreadLocal(..)) - | InstanceKind::Shim(ShimKind::FnPtrAsPtr(..)) + | InstanceKind::Shim(ShimKind::FnAddrAsPtr(..)) | InstanceKind::Shim(ShimKind::FnPtrFromPtr(..)) | InstanceKind::Shim(ShimKind::AsyncDropGlue(..)) | InstanceKind::Shim(ShimKind::FutureDropPoll(..)) diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index eb81ea291759b..af5423dcf3865 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -833,6 +833,7 @@ bidirectional_lang_item_map! { Drop, Field, Fn, + FnAddrTrait, FnMut, FnOnce, FnPtrTrait, diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index a90de4c3baba6..ceb1d2a55823e 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -182,7 +182,7 @@ pub enum ShimKind<'tcx> { /// Automatically generated for all potentially higher-ranked `fn(I) -> R` types. /// /// The `DefId` is for `FnPtr::as_ptr`, the `Ty` is the type `T`. - FnPtrAsPtr(DefId, Ty<'tcx>), + FnAddrAsPtr(DefId, Ty<'tcx>), /// Compiler-generated `::from_ptr` implementation. /// @@ -351,7 +351,7 @@ impl<'tcx> ShimKind<'tcx> { } | ShimKind::DropGlue(def_id, _) | ShimKind::Clone(def_id, _) - | ShimKind::FnPtrAsPtr(def_id, _) + | ShimKind::FnAddrAsPtr(def_id, _) | ShimKind::FnPtrFromPtr(def_id, _) | ShimKind::FutureDropPoll(def_id, _, _) | ShimKind::AsyncDropGlue(def_id, _) @@ -374,7 +374,7 @@ impl<'tcx> ShimKind<'tcx> { | ShimKind::ConstructCoroutineInClosure { .. } | ShimKind::DropGlue(..) | ShimKind::Clone(..) - | ShimKind::FnPtrAsPtr(..) + | ShimKind::FnAddrAsPtr(..) | ShimKind::FnPtrFromPtr(..) => None, } } @@ -395,7 +395,7 @@ impl<'tcx> ShimKind<'tcx> { ShimKind::Clone(..) | ShimKind::ThreadLocal(..) | ShimKind::FnPtr(..) - | ShimKind::FnPtrAsPtr(..) + | ShimKind::FnAddrAsPtr(..) | ShimKind::FnPtrFromPtr(..) | ShimKind::DropGlue(_, Some(_)) | ShimKind::FutureDropPoll(..) diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index afb0bc1705f91..7c62c5a5c4f17 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -400,7 +400,7 @@ impl<'tcx, P: Printer<'tcx> + std::fmt::Write> Print

for ty::ShimKind<'tcx> { ty::ShimKind::DropGlue(_, None) => cx.write_str("shim(None)"), ty::ShimKind::DropGlue(_, Some(ty)) => cx.write_str(&format!("shim(Some({ty}))")), ty::ShimKind::Clone(_, ty) => cx.write_str(&format!("shim({ty})")), - ty::ShimKind::FnPtrAsPtr(_, ty) => cx.write_str(&format!("shim({ty})")), + ty::ShimKind::FnAddrAsPtr(_, ty) => cx.write_str(&format!("shim({ty})")), ty::ShimKind::FnPtrFromPtr(_, ty) => cx.write_str(&format!("shim({ty})")), ty::ShimKind::FutureDropPoll(_, proxy_ty, impl_ty) => { cx.write_str(&format!("dropshim({proxy_ty}-{impl_ty})")) diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 501d2c38df170..2ab02a7220782 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -763,7 +763,7 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>( | InstanceKind::Shim(ShimKind::DropGlue(..)) | InstanceKind::Shim(ShimKind::Clone(..)) | InstanceKind::Shim(ShimKind::ThreadLocal(..)) - | InstanceKind::Shim(ShimKind::FnPtrAsPtr(..)) + | InstanceKind::Shim(ShimKind::FnAddrAsPtr(..)) | InstanceKind::Shim(ShimKind::FnPtrFromPtr(..)) => return Ok(()), } diff --git a/compiler/rustc_mir_transform/src/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs index ed3fcb1bbc679..77ddecabc291f 100644 --- a/compiler/rustc_mir_transform/src/inline/cycle.rs +++ b/compiler/rustc_mir_transform/src/inline/cycle.rs @@ -36,7 +36,7 @@ fn should_recurse<'tcx>(tcx: TyCtxt<'tcx>, callee: ty::Instance<'tcx>) -> bool { | InstanceKind::Shim(ShimKind::Clone(..)) => {} // This shim does not call any other functions, thus there can be no recursion. - InstanceKind::Shim(ShimKind::FnPtrAsPtr(..) | ShimKind::FnPtrFromPtr(..)) => return false, + InstanceKind::Shim(ShimKind::FnAddrAsPtr(..) | ShimKind::FnPtrFromPtr(..)) => return false, // FIXME: A not fully instantiated drop shim can cause ICEs if one attempts to // have its MIR built. Likely oli-obk just screwed up the `ParamEnv`s, so this diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 170a13ac173ea..bf3b512b27d21 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -126,7 +126,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, shim: ty::ShimKind<'tcx>) -> Body<'tcx> { } ty::ShimKind::ThreadLocal(..) => build_thread_local_shim(tcx, shim), ty::ShimKind::Clone(def_id, ty) => build_clone_shim(tcx, def_id, ty), - ty::ShimKind::FnPtrAsPtr(def_id, ty) => build_fn_ptr_as_ptr_shim(tcx, def_id, ty), + ty::ShimKind::FnAddrAsPtr(def_id, ty) => build_fn_addr_as_ptr_shim(tcx, def_id, ty), ty::ShimKind::FnPtrFromPtr(def_id, ty) => build_fn_ptr_from_ptr_shim(tcx, def_id, ty), ty::ShimKind::FutureDropPoll(def_id, proxy_ty, impl_ty) => { let mut body = @@ -1095,7 +1095,7 @@ pub(super) fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> { /// } /// } /// ``` -fn build_fn_ptr_as_ptr_shim<'tcx>( +fn build_fn_addr_as_ptr_shim<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>, @@ -1116,7 +1116,7 @@ fn build_fn_ptr_as_ptr_shim<'tcx>( let Some(sig) = tcx.fn_sig(def_id).instantiate(tcx, &[self_ty.into()]).skip_norm_wip().no_bound_vars() else { - span_bug!(span, "FnPtr::as_ptr with bound vars for `{self_ty}`"); + span_bug!(span, "FnAddr::as_ptr with bound vars for `{self_ty}`"); }; let mut locals = local_decls_for_sig(&sig, span); @@ -1146,7 +1146,7 @@ fn build_fn_ptr_as_ptr_shim<'tcx>( Some(Terminator { source_info, kind: TerminatorKind::Return }), false, ); - let source = MirSource::from_shim(ty::ShimKind::FnPtrAsPtr(def_id, self_ty)); + let source = MirSource::from_shim(ty::ShimKind::FnAddrAsPtr(def_id, self_ty)); new_body(source, IndexVec::from_elem_n(start_block, 1), locals, sig.inputs().len(), span) } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index f4bdb1e785205..9833b6fafdaf8 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1065,7 +1065,7 @@ fn visit_instance_use<'tcx>( | ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure { .. }) | ty::InstanceKind::Shim(ty::ShimKind::FnPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::Clone(..)) - | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(..)) + | ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(..)) => { output.push(create_fn_mono_item(tcx, instance, source)); } diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 16df895b0f728..a6bcfbd94a35d 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -654,7 +654,7 @@ fn characteristic_def_id_of_mono_item<'tcx>( | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(..)) | ty::InstanceKind::Shim(ty::ShimKind::Clone(..)) | ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(..)) - | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(..)) + | ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(..)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(..)) @@ -841,7 +841,7 @@ fn mono_item_visibility<'tcx>( | InstanceKind::Shim(ShimKind::ConstructCoroutineInClosure { .. }) | InstanceKind::Shim(ShimKind::DropGlue(..)) | InstanceKind::Shim(ShimKind::Clone(..)) - | InstanceKind::Shim(ShimKind::FnPtrAsPtr(..)) + | InstanceKind::Shim(ShimKind::FnAddrAsPtr(..)) | InstanceKind::Shim(ShimKind::FnPtrFromPtr(..)) => return Visibility::Hidden, }; diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index a06b0625654c2..99cc4ec9f64d3 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -677,6 +677,9 @@ where Some(SolverTraitLangItem::FnPtrTrait) => { G::consider_builtin_fn_ptr_trait_candidate(self, goal) } + Some(SolverTraitLangItem::FnAddrTrait) => { + G::consider_builtin_fn_ptr_trait_candidate(self, goal) + } Some(SolverTraitLangItem::AsyncFnKindHelper) => { G::consider_builtin_async_fn_kind_helper_candidate(self, goal) } diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs index e0c8dbd6a3d16..0d47a89b2a002 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs @@ -657,11 +657,11 @@ pub(crate) fn transform_instance<'tcx>( // (i.e., type ids are encoded for them as is). ty::InstanceKind::Shim(ty::ShimKind::Clone(..)) => instance, - // FnPtrAsPtrShims and FnPtrFromPtrShims (i.e., compiler-generated `::as_ptr` + // FnAddrAsPtrShims and FnPtrFromPtrShims (i.e., compiler-generated `::as_ptr` // and `::from_ptr` implementations): the FnPtr trait is not dyn compatible, so // they can not be called through a vtable and are not transformed (i.e., type ids are // encoded for them as is). - ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(..) | ty::ShimKind::FnPtrFromPtr(..)) => { + ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr(..) | ty::ShimKind::FnPtrFromPtr(..)) => { instance } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6f078fef4892b..13023bcecadac 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1012,6 +1012,9 @@ symbols! { fmul_algebraic, fmul_fast, fmuladd, + fn_addr_addr_fn, + fn_addr_as_ptr, + fn_addr_trait, fn_align, fn_body, fn_delegation, @@ -1019,7 +1022,6 @@ symbols! { fn_mut, fn_once, fn_once_output, - fn_ptr_as_ptr, fn_ptr_from_ptr, fn_ptr_trait, fn_static, diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 8a770bea8468b..218b998cd233a 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -126,6 +126,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Some(LangItem::FnPtrTrait) => { self.assemble_candidates_for_fn_ptr_trait(obligation, &mut candidates); } + Some(LangItem::FnAddrTrait) => { + self.assemble_candidates_for_fn_ptr_trait(obligation, &mut candidates); + } Some(LangItem::BikeshedGuaranteedNoDrop) => { self.assemble_candidates_for_bikeshed_guaranteed_no_drop_trait( obligation, diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 88bb711844cb1..1d0696d745373 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -261,6 +261,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | LangItem::DiscriminantKind | LangItem::Field | LangItem::FnPtrTrait + | LangItem::FnAddrTrait | LangItem::PointeeTrait | LangItem::Tuple | LangItem::Unpin, diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 9640f9add604c..ad5749a44387f 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -301,24 +301,34 @@ fn resolve_associated_item<'tcx>( if !matches!(self_ty.kind(), ty::FnPtr(..)) { return Ok(None); } - if tcx.is_lang_item(trait_item_id, LangItem::FnPtrAsPtr) { - Some(Instance { - def: ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr( + match tcx.as_lang_item(trait_item_id) { + Some(LangItem::FnPtrFromPtr) => Some(Instance { + def: ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr( trait_item_id, self_ty, )), args: rcvr_args, - }) - } else if tcx.is_lang_item(trait_item_id, LangItem::FnPtrFromPtr) { - Some(Instance { - def: ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr( + }), + _ => bug!("Unknown item for FnPtr: {:?}", trait_item_id), + } + } else if tcx.is_lang_item(trait_ref.def_id, LangItem::FnAddrTrait) { + let self_ty = trait_ref.self_ty(); + if !matches!(self_ty.kind(), ty::FnPtr(..)) { + return Ok(None); + } + match tcx.as_lang_item(trait_item_id) { + Some(LangItem::FnAddrAsPtr) => Some(Instance { + def: ty::InstanceKind::Shim(ty::ShimKind::FnAddrAsPtr( trait_item_id, self_ty, )), args: rcvr_args, - }) - } else { - Some(Instance { def: ty::InstanceKind::Item(trait_item_id), args: rcvr_args }) + }), + Some(LangItem::FnAddrAddrFn) => Some(Instance { + def: ty::InstanceKind::Item(trait_item_id), + args: rcvr_args, + }), + _ => bug!("Unknown item for FnAddr: {:?}", trait_item_id), } } else if let Some(target_kind) = tcx.fn_trait_kind_from_def_id(trait_ref.def_id) { // FIXME: This doesn't check for malformed libcore that defines, e.g., diff --git a/compiler/rustc_type_ir/src/lang_items.rs b/compiler/rustc_type_ir/src/lang_items.rs index 246d6241ec8ba..59afbe0619737 100644 --- a/compiler/rustc_type_ir/src/lang_items.rs +++ b/compiler/rustc_type_ir/src/lang_items.rs @@ -43,6 +43,7 @@ pub enum SolverTraitLangItem { Drop, Field, Fn, + FnAddrTrait, FnMut, FnOnce, FnPtrTrait, diff --git a/library/core/src/ops/function.rs b/library/core/src/ops/function.rs index 276b75c53cc38..d5dea51d3efda 100644 --- a/library/core/src/ops/function.rs +++ b/library/core/src/ops/function.rs @@ -325,30 +325,38 @@ unsafe extern "C" { pub type Code; } -/// A common trait implemented by all function pointers. +/// A common trait implemented by all function pointers and function definition types #[unstable(feature = "fn_static", issue = "148768")] -#[lang = "fn_ptr_trait"] -#[fundamental] +#[lang = "fn_addr_trait"] #[rustc_deny_explicit_impl] #[rustc_dyn_incompatible_trait] -pub trait FnPtr: Copy { +pub unsafe trait FnAddr: Copy { /// Returns the address of the function pointer. #[unstable(feature = "fn_static", issue = "148768")] + #[lang = "fn_addr_addr_fn"] fn addr(self) -> usize { self.as_ptr().addr().get() } /// Returns the function pointer as a [`NonNull`]. #[unstable(feature = "fn_static", issue = "148768")] - #[lang = "fn_ptr_as_ptr"] + #[lang = "fn_addr_as_ptr"] fn as_ptr(self) -> NonNull; +} +/// A common trait implemented by all function pointers. +#[unstable(feature = "fn_static", issue = "148768")] +#[lang = "fn_ptr_trait"] +#[fundamental] +#[rustc_deny_explicit_impl] +#[rustc_dyn_incompatible_trait] +pub unsafe trait FnPtr: FnAddr { /// Constructs a function pointer from a `NonNull` pointer. /// /// # Safety /// /// The function pointer must have been obtained - /// from an [`FnPtr::as_ptr`] call from a function + /// from an [`FnAddr::as_ptr`] call from a function /// pointer type that is ABI compatible. #[unstable(feature = "fn_static", issue = "148768")] #[lang = "fn_ptr_from_ptr"] diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 9b5915a901aaa..5443c1ed4147a 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -177,7 +177,7 @@ pub use self::deref::{Deref, DerefMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::drop::Drop; #[unstable(feature = "fn_static", issue = "148768")] -pub use self::function::{Code, FnPtr}; +pub use self::function::{Code, FnAddr, FnPtr}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::function::{Fn, FnMut, FnOnce}; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/tests/ui/fn/fn-ptr-trait-run.rs b/tests/ui/fn/fn-ptr-trait-run.rs index 529deb9be1e0a..d3b2e8f269073 100644 --- a/tests/ui/fn/fn-ptr-trait-run.rs +++ b/tests/ui/fn/fn-ptr-trait-run.rs @@ -1,7 +1,7 @@ #![feature(fn_static)] //@ run-pass -use std::ops::FnPtr; +use std::ops::{FnPtr, FnAddr}; fn bar(a: u64) -> u64 { a From 49918a65401e6a0c314cc6f70bd32a11d11feda6 Mon Sep 17 00:00:00 2001 From: Bas Schoenmaeckers Date: Fri, 6 Nov 2026 16:05:14 +0100 Subject: [PATCH 03/10] Implement `FnAddr` for function definitions --- compiler/rustc_mir_transform/src/shim.rs | 38 +++++++++++++++++-- .../src/solve/assembly/mod.rs | 12 +++++- .../src/solve/effect_goals.rs | 7 ++++ .../src/solve/normalizes_to.rs | 7 ++++ .../src/solve/trait_goals.rs | 27 +++++++++++++ .../src/traits/select/candidate_assembly.rs | 17 +++++++++ compiler/rustc_ty_utils/src/instance.rs | 2 +- tests/ui/fn/fn-ptr-trait-run.rs | 1 + 8 files changed, 106 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index bf3b512b27d21..f5dbc89e10e4e 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -1100,7 +1100,11 @@ fn build_fn_addr_as_ptr_shim<'tcx>( def_id: DefId, self_ty: Ty<'tcx>, ) -> Body<'tcx> { - assert_matches!(self_ty.kind(), ty::FnPtr(..), "expected fn ptr, found {self_ty}"); + assert_matches!( + self_ty.kind(), + ty::FnPtr(..) | ty::FnDef(..), + "expected fn ptr or function def, found {self_ty}" + ); let span = tcx.def_span(def_id); let nonnull_did = tcx.require_lang_item(LangItem::NonNull, span); @@ -1126,8 +1130,36 @@ fn build_fn_addr_as_ptr_shim<'tcx>( // FIXME: use `expose_provenance` once we figure out whether function pointers have meaningful // provenance. let raw_unit_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit); - let cast_to_raw_rvalue = - Rvalue::Cast(CastKind::FnPtrToPtr, Operand::Move(Place::from(Local::arg(0))), raw_unit_ptr); + + let fn_ptr_operand = match self_ty.kind() { + ty::FnDef(..) => { + let fn_sig = self_ty.fn_sig(tcx); + let fn_ptr_ty = Ty::new_fn_ptr(tcx, fn_sig); + let fn_ptr = + Place::from(locals.push(LocalDecl::with_source_info(fn_ptr_ty, source_info))); + + statements.push(Statement::new( + source_info, + StatementKind::Assign(Box::new(( + fn_ptr, + Rvalue::Cast( + CastKind::PointerCoercion( + ty::adjustment::PointerCoercion::ReifyFnPointer(fn_sig.safety()), + CoercionSource::Implicit, + ), + Operand::Move(Place::from(Local::arg(0))), + fn_ptr_ty, + ), + ))), + )); + + Operand::Move(fn_ptr) + } + _ => Operand::Move(Place::from(Local::arg(0))), + }; + + let cast_to_raw_rvalue = Rvalue::Cast(CastKind::FnPtrToPtr, fn_ptr_operand, raw_unit_ptr); + let raw_ptr = locals.push(LocalDecl::with_source_info(raw_unit_ptr, source_info)).into(); statements.push(Statement::new( source_info, diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 99cc4ec9f64d3..203abcb61a7b0 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -311,6 +311,12 @@ where goal: Goal, ) -> Result, NoSolutionOrRerunNonErased>; + /// A type is a `FnStatic` if it is of `FnDef` type. + fn consider_builtin_fn_static_trait_candidate( + ecx: &mut EvalCtxt<'_, D>, + goal: Goal, + ) -> Result, NoSolutionOrRerunNonErased>; + /// A callable type (a closure, fn def, or fn ptr) is known to implement the `Fn` /// family of traits where `A` is given by the signature of the type. fn consider_builtin_fn_trait_candidates( @@ -678,7 +684,11 @@ where G::consider_builtin_fn_ptr_trait_candidate(self, goal) } Some(SolverTraitLangItem::FnAddrTrait) => { - G::consider_builtin_fn_ptr_trait_candidate(self, goal) + if matches!(goal.predicate.self_ty().kind(), ty::FnDef(..)) { + G::consider_builtin_fn_static_trait_candidate(self, goal) + } else { + G::consider_builtin_fn_ptr_trait_candidate(self, goal) + } } Some(SolverTraitLangItem::AsyncFnKindHelper) => { G::consider_builtin_async_fn_kind_helper_candidate(self, goal) diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs index 44832635b8908..a20c17ce6933f 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -293,6 +293,13 @@ where unimplemented!("Fn* are not yet const") } + fn consider_builtin_fn_static_trait_candidate( + _ecx: &mut EvalCtxt<'_, D>, + _goal: Goal, + ) -> Result, NoSolutionOrRerunNonErased> { + unimplemented!("Fn* are not yet const") + } + #[instrument(level = "trace", skip_all, ret)] fn consider_builtin_fn_trait_candidates( ecx: &mut EvalCtxt<'_, D>, diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs index 873c44b402315..da6f57f044d5a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs @@ -531,6 +531,13 @@ where panic!("`FnPtr` does not have an associated type: {:?}", goal); } + fn consider_builtin_fn_static_trait_candidate( + _ecx: &mut EvalCtxt<'_, D>, + goal: Goal, + ) -> Result, NoSolutionOrRerunNonErased> { + panic!("`FnStatic` does not have an associated type: {:?}", goal); + } + fn consider_builtin_fn_trait_candidates( ecx: &mut EvalCtxt<'_, D>, goal: Goal, diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 5ae19b2eb6935..ac479594911ab 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -355,6 +355,33 @@ where } } + fn consider_builtin_fn_static_trait_candidate( + ecx: &mut EvalCtxt<'_, D>, + goal: Goal, + ) -> Result, NoSolutionOrRerunNonErased> { + let self_ty = goal.predicate.self_ty(); + match goal.predicate.polarity { + // impl FnStatic for FnDef {} + ty::ClausePolarity::Positive => match self_ty.kind() { + ty::FnDef(_, _) => { + ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { + ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) + }) + } + _ => Err(NoSolution.into()), + }, + // impl !FnStatic for T where T != FnDef && T is rigid {} + ty::ClausePolarity::Negative => match self_ty.kind() { + ty::FnDef(_, _) if self_ty.is_known_rigid() => { + ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { + ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) + }) + } + _ => Err(NoSolution.into()), + }, + } + } + fn consider_builtin_fn_trait_candidates( ecx: &mut EvalCtxt<'_, D>, goal: Goal, diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 218b998cd233a..85e4281edcc2b 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -128,6 +128,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } Some(LangItem::FnAddrTrait) => { self.assemble_candidates_for_fn_ptr_trait(obligation, &mut candidates); + self.assemble_candidates_for_fn_static_trait(obligation, &mut candidates); } Some(LangItem::BikeshedGuaranteedNoDrop) => { self.assemble_candidates_for_bikeshed_guaranteed_no_drop_trait( @@ -1418,6 +1419,22 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } + fn assemble_candidates_for_fn_static_trait( + &mut self, + obligation: &PolyTraitObligation<'tcx>, + candidates: &mut SelectionCandidateSet<'tcx>, + ) { + let self_ty = self.infcx.deeply_resolve_ignoring_regions(obligation.self_ty()); + + match *self_ty.skip_binder().kind() { + ty::FnDef(_, _) => candidates.vec.push(BuiltinCandidate), + ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) => { + candidates.ambiguous = true; + } + _ => {} + } + } + fn assemble_candidates_for_bikeshed_guaranteed_no_drop_trait( &mut self, obligation: &PolyTraitObligation<'tcx>, diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index ad5749a44387f..62c831f2a3e13 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -313,7 +313,7 @@ fn resolve_associated_item<'tcx>( } } else if tcx.is_lang_item(trait_ref.def_id, LangItem::FnAddrTrait) { let self_ty = trait_ref.self_ty(); - if !matches!(self_ty.kind(), ty::FnPtr(..)) { + if !matches!(self_ty.kind(), ty::FnPtr(..) | ty::FnDef(..)) { return Ok(None); } match tcx.as_lang_item(trait_item_id) { diff --git a/tests/ui/fn/fn-ptr-trait-run.rs b/tests/ui/fn/fn-ptr-trait-run.rs index d3b2e8f269073..e90bb019dca22 100644 --- a/tests/ui/fn/fn-ptr-trait-run.rs +++ b/tests/ui/fn/fn-ptr-trait-run.rs @@ -11,5 +11,6 @@ fn main() { type F = fn(u64) -> u64; let b: F = bar; assert_eq!(b.addr(), bar as *const () as usize); + assert_eq!(b.addr(), bar.addr()); assert_eq!(b(42), unsafe { F::from_ptr(b.as_ptr())(42) }); } From 2de7a6698dfbf123bec1925713281db904c11fba Mon Sep 17 00:00:00 2001 From: Zalathar Date: Wed, 11 Nov 2026 20:33:26 +1100 Subject: [PATCH 04/10] Avoid raw pointers in `LLVMRustConstPtrAuth` This pulls some less-trivial changes out of the main migration to `Value<'ll>`. --- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 10 +++++----- compiler/rustc_codegen_llvm/src/llvm/mod.rs | 8 +------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 11b276f565d4b..ecc4fe510370c 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -2689,11 +2689,11 @@ unsafe extern "C" { pub(crate) fn LLVMRustSetNoSanitizeAddress(Global: &Value); pub(crate) fn LLVMRustSetNoSanitizeHWAddress(Global: &Value); - pub(crate) fn LLVMRustConstPtrAuth( - ptr: *const Value, + pub(crate) fn LLVMRustConstPtrAuth<'ll>( + ptr: &'ll Value, key: u32, disc: u64, - addr_diversity: *const Value, - deactivation_symbol: *const Value, - ) -> *const Value; + addr_diversity: Option<&'ll Value>, + deactivation_symbol: Option<&'ll Value>, + ) -> &'ll Value; } diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 168cc40ee579c..6d48e551ac92a 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -518,11 +518,5 @@ pub(crate) fn const_ptr_auth<'ll>( disc: u64, addr_diversity: Option<&'ll Value>, ) -> &'ll Value { - unsafe { - let addr_div_ptr = addr_diversity.map_or(std::ptr::null(), |v| v as *const Value); - let deactivation_symbol = std::ptr::null(); - let result = - LLVMRustConstPtrAuth(ptr as *const Value, key, disc, addr_div_ptr, deactivation_symbol); - &*result - } + unsafe { LLVMRustConstPtrAuth(ptr, key, disc, addr_diversity, None) } } From 6c0a3dfc9e7afb2971bf61027d6abae31cbc9dcf Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 9 Nov 2026 20:27:56 +1100 Subject: [PATCH 05/10] Use an invariant lifetime brand for LLVM values --- compiler/rustc_codegen_llvm/src/abi.rs | 52 +- compiler/rustc_codegen_llvm/src/asm.rs | 12 +- compiler/rustc_codegen_llvm/src/attributes.rs | 14 +- compiler/rustc_codegen_llvm/src/back/write.rs | 4 +- compiler/rustc_codegen_llvm/src/base.rs | 12 +- compiler/rustc_codegen_llvm/src/builder.rs | 338 +++--- .../src/builder/autodiff.rs | 16 +- .../src/builder/gpu_offload.rs | 112 +- compiler/rustc_codegen_llvm/src/callee.rs | 2 +- compiler/rustc_codegen_llvm/src/common.rs | 88 +- compiler/rustc_codegen_llvm/src/consts.rs | 40 +- compiler/rustc_codegen_llvm/src/context.rs | 83 +- .../src/coverageinfo/llvm_cov.rs | 4 +- .../src/coverageinfo/mod.rs | 6 +- .../src/debuginfo/di_builder.rs | 2 +- .../rustc_codegen_llvm/src/debuginfo/gdb.rs | 2 +- .../src/debuginfo/metadata.rs | 8 +- .../src/debuginfo/metadata/enums/cpp_like.rs | 2 +- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 4 +- compiler/rustc_codegen_llvm/src/declare.rs | 20 +- compiler/rustc_codegen_llvm/src/intrinsic.rs | 98 +- .../rustc_codegen_llvm/src/llvm/diagnostic.rs | 2 +- .../rustc_codegen_llvm/src/llvm/enzyme_ffi.rs | 59 +- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 1015 +++++++++-------- .../src/llvm/ffi/branded.rs | 14 + compiler/rustc_codegen_llvm/src/llvm/mod.rs | 76 +- .../src/llvm/offload_ffi.rs | 10 +- compiler/rustc_codegen_llvm/src/mono_item.rs | 12 +- compiler/rustc_codegen_llvm/src/type_.rs | 12 +- compiler/rustc_codegen_llvm/src/typetree.rs | 2 +- compiler/rustc_codegen_llvm/src/va_arg.rs | 56 +- compiler/rustc_codegen_llvm/src/value.rs | 21 +- 32 files changed, 1121 insertions(+), 1077 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index d29fb14e5bd40..49c07652c8261 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -27,12 +27,17 @@ use crate::llvm::{self, Attribute, AttributePlace, Type, Value}; use crate::type_of::LayoutLlvmExt; trait ArgAttributesExt { - fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value); - fn apply_attrs_to_callsite( + fn apply_attrs_to_llfn<'ll>( &self, idx: AttributePlace, - cx: &CodegenCx<'_, '_>, - callsite: &Value, + cx: &CodegenCx<'ll, '_>, + llfn: Value<'ll>, + ); + fn apply_attrs_to_callsite<'ll>( + &self, + idx: AttributePlace, + cx: &CodegenCx<'ll, '_>, + callsite: Value<'ll>, ); } @@ -116,16 +121,21 @@ fn get_attrs<'ll>(this: &ArgAttributes, cx: &CodegenCx<'ll, '_>) -> SmallVec<[&' } impl ArgAttributesExt for ArgAttributes { - fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value) { + fn apply_attrs_to_llfn<'ll>( + &self, + idx: AttributePlace, + cx: &CodegenCx<'ll, '_>, + llfn: Value<'ll>, + ) { let attrs = get_attrs(self, cx); attributes::apply_to_llfn(llfn, idx, &attrs); } - fn apply_attrs_to_callsite( + fn apply_attrs_to_callsite<'ll>( &self, idx: AttributePlace, - cx: &CodegenCx<'_, '_>, - callsite: &Value, + cx: &CodegenCx<'ll, '_>, + callsite: Value<'ll>, ) { let attrs = get_attrs(self, cx); attributes::apply_to_callsite(callsite, idx, &attrs); @@ -236,14 +246,14 @@ trait ArgAbiExt<'ll, 'tcx> { fn store( &self, bx: &mut Builder<'_, 'll, 'tcx>, - val: &'ll Value, - dst: PlaceRef<'tcx, &'ll Value>, + val: Value<'ll>, + dst: PlaceRef<'tcx, Value<'ll>>, ); fn store_fn_arg( &self, bx: &mut Builder<'_, 'll, 'tcx>, idx: &mut usize, - dst: PlaceRef<'tcx, &'ll Value>, + dst: PlaceRef<'tcx, Value<'ll>>, ); } @@ -255,8 +265,8 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { fn store( &self, bx: &mut Builder<'_, 'll, 'tcx>, - val: &'ll Value, - dst: PlaceRef<'tcx, &'ll Value>, + val: Value<'ll>, + dst: PlaceRef<'tcx, Value<'ll>>, ) { match &self.mode { PassMode::Ignore => {} @@ -310,7 +320,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { &self, bx: &mut Builder<'_, 'll, 'tcx>, idx: &mut usize, - dst: PlaceRef<'tcx, &'ll Value>, + dst: PlaceRef<'tcx, Value<'ll>>, ) { let mut next = || { let val = llvm::get_param(bx.llfn(), *idx as c_uint); @@ -347,8 +357,8 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn store_arg( &mut self, arg_abi: &ArgAbi<'tcx, Ty<'tcx>>, - val: &'ll Value, - dst: PlaceRef<'tcx, &'ll Value>, + val: Value<'ll>, + dst: PlaceRef<'tcx, Value<'ll>>, ) { arg_abi.store(self, val, dst) } @@ -363,12 +373,12 @@ pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> { fn apply_attrs_llfn( &self, cx: &CodegenCx<'ll, 'tcx>, - llfn: &'ll Value, + llfn: Value<'ll>, instance: Option>, ); /// Apply attributes to a function call. - fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value); + fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: Value<'ll>); } impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { @@ -470,7 +480,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { fn apply_attrs_llfn( &self, cx: &CodegenCx<'ll, 'tcx>, - llfn: &'ll Value, + llfn: Value<'ll>, instance: Option>, ) { let mut func_attrs = SmallVec::<[_; 3]>::new(); @@ -648,7 +658,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { } } - fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: &'ll Value) { + fn apply_attrs_callsite(&self, bx: &mut Builder<'_, 'll, 'tcx>, callsite: Value<'ll>) { let mut func_attrs = SmallVec::<[_; 2]>::new(); if self.ret.layout.is_uninhabited() { func_attrs.push(llvm::AttributeKind::NoReturn.create_attr(bx.cx.llcx)); @@ -659,7 +669,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { attributes::apply_to_callsite(callsite, llvm::AttributePlace::Function, &{ func_attrs }); let mut i = 0; - let mut apply = |cx: &CodegenCx<'_, '_>, attrs: &ArgAttributes| { + let mut apply = |cx: &CodegenCx<'ll, '_>, attrs: &ArgAttributes| { attrs.apply_attrs_to_callsite(llvm::AttributePlace::Argument(i), cx, callsite); i += 1; i - 1 diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 317dc3d55a62c..c6fb235059fd1 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -537,7 +537,7 @@ pub(crate) fn inline_asm_call<'ll>( bx: &mut Builder<'_, 'll, '_>, asm: &str, cons: &str, - inputs: &[&'ll Value], + inputs: &[Value<'ll>], output: llvm::Type<'ll>, labels: &[&'ll llvm::BasicBlock], volatile: bool, @@ -547,7 +547,7 @@ pub(crate) fn inline_asm_call<'ll>( unwind: bool, dest: Option<&'ll llvm::BasicBlock>, catch_funclet: Option<(&'ll llvm::BasicBlock, Option<&Funclet<'ll>>)>, -) -> Option<&'ll Value> { +) -> Option> { let argtys = inputs .iter() .map(|v| { @@ -1170,11 +1170,11 @@ fn any_target_feature_enabled( /// Fix up an input value to work around LLVM bugs. fn llvm_fixup_input<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - mut value: &'ll Value, + mut value: Value<'ll>, reg: InlineAsmRegClass, layout: &TyAndLayout<'tcx>, instance: Instance<'_>, -) -> &'ll Value { +) -> Value<'ll> { use InlineAsmRegClass::*; let dl = &bx.tcx.data_layout; match (reg, layout.backend_repr) { @@ -1373,11 +1373,11 @@ fn llvm_fixup_input<'ll, 'tcx>( /// Fix up an output value to work around LLVM bugs. fn llvm_fixup_output<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - mut value: &'ll Value, + mut value: Value<'ll>, reg: InlineAsmRegClass, layout: &TyAndLayout<'tcx>, instance: Instance<'_>, -) -> &'ll Value { +) -> Value<'ll> { use InlineAsmRegClass::*; match (reg, layout.backend_repr) { (AArch64(AArch64InlineAsmRegClass::vreg), BackendRepr::Scalar(s)) => { diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index d74c6dd68564b..6fdc2a1589f47 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -26,23 +26,27 @@ use crate::llvm::{ }; use crate::{attributes, llvm_util}; -pub(crate) fn apply_to_llfn(llfn: &Value, idx: AttributePlace, attrs: &[&Attribute]) { +pub(crate) fn apply_to_llfn<'ll>(llfn: Value<'ll>, idx: AttributePlace, attrs: &[&'ll Attribute]) { if !attrs.is_empty() { llvm::AddFunctionAttributes(llfn, idx, attrs); } } -pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[&Attribute]) { +pub(crate) fn apply_to_callsite<'ll>( + callsite: Value<'ll>, + idx: AttributePlace, + attrs: &[&'ll Attribute], +) { if !attrs.is_empty() { llvm::AddCallSiteAttributes(callsite, idx, attrs); } } -pub(crate) fn has_string_attr(llfn: &Value, name: &str) -> bool { +pub(crate) fn has_string_attr<'ll>(llfn: Value<'ll>, name: &str) -> bool { llvm::HasStringAttribute(llfn, name) } -pub(crate) fn remove_string_attr_from_llfn(llfn: &Value, name: &str) { +pub(crate) fn remove_string_attr_from_llfn<'ll>(llfn: Value<'ll>, name: &str) { llvm::RemoveStringAttrFromFn(llfn, name); } @@ -503,7 +507,7 @@ fn create_alloc_family_attr<'ll>(llcx: llvm::Context<'ll>) -> &'ll llvm::Attribu pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( cx: &SimpleCx<'ll>, tcx: TyCtxt<'tcx>, - llfn: &'ll Value, + llfn: Value<'ll>, codegen_fn_attrs: &CodegenFnAttrs, instance: Option>, sanitizer_ignorelist: Option<&SanitizerIgnoreList>, diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index 4e1a3f998a265..83b5b7405d63d 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -659,8 +659,8 @@ pub(crate) unsafe fn llvm_optimize<'ll>( // Returns the new function, or `None` if nothing was wrapped fn handle_offload<'ll>( cx: &SimpleCx<'ll>, - old_fn: &'ll llvm::Value, - ) -> Option<&'ll llvm::Value> { + old_fn: llvm::Value<'ll>, + ) -> Option> { let old_fn_ty = cx.get_type_of_global(old_fn); let old_param_types = cx.func_params_types(old_fn_ty); let old_param_count = old_param_types.len(); diff --git a/compiler/rustc_codegen_llvm/src/base.rs b/compiler/rustc_codegen_llvm/src/base.rs index 7909072db1d8d..0b230f1608da1 100644 --- a/compiler/rustc_codegen_llvm/src/base.rs +++ b/compiler/rustc_codegen_llvm/src/base.rs @@ -34,14 +34,14 @@ use crate::llvm::{self, Value}; use crate::{ModuleLlvm, attributes}; pub(crate) struct ValueIter<'ll> { - cur: Option<&'ll Value>, - step: unsafe extern "C" fn(&'ll Value) -> Option<&'ll Value>, + cur: Option>, + step: unsafe extern "C" fn(Value<'ll>) -> Option>, } impl<'ll> Iterator for ValueIter<'ll> { - type Item = &'ll Value; + type Item = Value<'ll>; - fn next(&mut self) -> Option<&'ll Value> { + fn next(&mut self) -> Option> { let old = self.cur; if let Some(old) = old { self.cur = unsafe { (self.step)(old) }; @@ -221,7 +221,7 @@ pub(crate) fn compile_codegen_unit( (module, cost) } -pub(crate) fn set_link_section(llval: &Value, attrs: &CodegenFnAttrs) { +pub(crate) fn set_link_section<'ll>(llval: Value<'ll>, attrs: &CodegenFnAttrs) { let Some(sect) = attrs.link_section else { return }; let buf = SmallCStr::new(sect.as_str()); llvm::set_section(llval, &buf); @@ -248,7 +248,7 @@ pub(crate) fn visibility_to_llvm(linkage: Visibility) -> llvm::Visibility { } } -pub(crate) fn set_variable_sanitizer_attrs(llval: &Value, attrs: &CodegenFnAttrs) { +pub(crate) fn set_variable_sanitizer_attrs<'ll>(llval: Value<'ll>, attrs: &CodegenFnAttrs) { if attrs.sanitizers.disabled.contains(SanitizerSet::ADDRESS) || attrs.sanitizers.disabled.contains(SanitizerSet::KERNELADDRESS) { diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index ed5da8e69246f..32e9578355976 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -61,10 +61,10 @@ impl<'a, 'll> SBuilder<'a, 'll> { pub(crate) fn call( &mut self, llty: Type<'ll>, - llfn: &'ll Value, - args: &[&'ll Value], + llfn: Value<'ll>, + args: &[Value<'ll>], funclet: Option<&Funclet<'ll>>, - ) -> &'ll Value { + ) -> Value<'ll> { debug!("call {:?} with args ({:?})", llfn, args); let args = self.check_call("call", llty, llfn, args); @@ -79,7 +79,7 @@ impl<'a, 'll> SBuilder<'a, 'll> { self.llbuilder(), llty, llfn, - args.as_ptr() as *const &llvm::Value, + args.as_ptr(), args.len() as c_uint, bundles.as_ptr(), bundles.len() as c_uint, @@ -99,7 +99,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { pub(crate) fn append_block( cx: &'a GenericCx<'ll, CX>, - llfn: &'ll Value, + llfn: Value<'ll>, name: &str, ) -> &'ll BasicBlock { unsafe { @@ -116,11 +116,11 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { unsafe { self.llbuilder_raw.as_ref() } } - pub(crate) fn trunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + pub(crate) fn trunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildTrunc(self.llbuilder(), val, dest_ty, UNNAMED) } } - pub(crate) fn bitcast(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + pub(crate) fn bitcast(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildBitCast(self.llbuilder(), val, dest_ty, UNNAMED) } } @@ -128,7 +128,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { llvm::LLVMBuildRetVoid(self.llbuilder()); } - pub(crate) fn ret(&mut self, v: &'ll Value) { + pub(crate) fn ret(&mut self, v: Value<'ll>) { unsafe { llvm::LLVMBuildRet(self.llbuilder(), v); } @@ -146,7 +146,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { // easily jump to the beginning of the function to place our allocas there. We trust the user // to manually do that. FIXME(offload): improve the genericCx and add more llvm wrappers to // handle this. - pub(crate) fn direct_alloca(&mut self, size: Size, align: Align, name: &str) -> &'ll Value { + pub(crate) fn direct_alloca(&mut self, size: Size, align: Align, name: &str) -> Value<'ll> { let ty = self.cx.type_array(self.cx.type_i8(), size.bytes()); let val = unsafe { let alloca = llvm::LLVMBuildAlloca(self.llbuilder(), ty, UNNAMED); @@ -163,10 +163,10 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { fn build_gep( &mut self, stride: Size, - ptr: &'ll Value, - index: &'ll Value, + ptr: Value<'ll>, + index: Value<'ll>, flags: GEPNoWrapFlags, - ) -> &'ll Value { + ) -> Value<'ll> { let ty = if stride.bytes() == 1 { // LLVM prefers `i8` as the canonical form for a single-byte GEP. self.cx.type_i8() @@ -187,7 +187,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { } } - pub(crate) fn store(&mut self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value { + pub(crate) fn store(&mut self, val: Value<'ll>, ptr: Value<'ll>, align: Align) -> Value<'ll> { debug!("Store {:?} -> {:?}", val, ptr); assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer); unsafe { @@ -197,7 +197,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { } } - pub(crate) fn load(&mut self, ty: Type<'ll>, ptr: &'ll Value, align: Align) -> &'ll Value { + pub(crate) fn load(&mut self, ty: Type<'ll>, ptr: Value<'ll>, align: Align) -> Value<'ll> { unsafe { let load = llvm::LLVMBuildLoad2(self.llbuilder(), ty, ptr, UNNAMED); llvm::LLVMSetAlignment(load, align.bytes() as c_uint); @@ -281,7 +281,7 @@ impl<'ll, 'tcx> Deref for Builder<'_, 'll, 'tcx> { macro_rules! math_builder_methods { ($($name:ident($($arg:ident),*) => $llvm_capi:ident),+ $(,)?) => { - $(fn $name(&mut self, $($arg: &'ll Value),*) -> &'ll Value { + $(fn $name(&mut self, $($arg: Value<'ll>),*) -> Value<'ll> { unsafe { llvm::$llvm_capi(self.llbuilder(), $($arg,)* UNNAMED) } @@ -291,7 +291,7 @@ macro_rules! math_builder_methods { macro_rules! set_math_builder_methods { ($($name:ident($($arg:ident),*) => ($llvm_capi:ident, $llvm_set_math:ident)),+ $(,)?) => { - $(fn $name(&mut self, $($arg: &'ll Value),*) -> &'ll Value { + $(fn $name(&mut self, $($arg: Value<'ll>),*) -> Value<'ll> { unsafe { let instr = llvm::$llvm_capi(self.llbuilder(), $($arg,)* UNNAMED); llvm::$llvm_set_math(instr); @@ -324,7 +324,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { self.span = span; } - fn append_block(cx: &'a CodegenCx<'ll, 'tcx>, llfn: &'ll Value, name: &str) -> &'ll BasicBlock { + fn append_block(cx: &'a CodegenCx<'ll, 'tcx>, llfn: Value<'ll>, name: &str) -> &'ll BasicBlock { unsafe { let name = SmallCStr::new(name); llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, name.as_ptr()) @@ -343,7 +343,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { llvm::LLVMBuildRetVoid(self.llbuilder()); } - fn ret(&mut self, v: &'ll Value) { + fn ret(&mut self, v: Value<'ll>) { unsafe { llvm::LLVMBuildRet(self.llbuilder(), v); } @@ -399,7 +399,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn cond_br( &mut self, - cond: &'ll Value, + cond: Value<'ll>, then_llbb: &'ll BasicBlock, else_llbb: &'ll BasicBlock, ) { @@ -410,7 +410,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn switch( &mut self, - v: &'ll Value, + v: Value<'ll>, else_llbb: &'ll BasicBlock, cases: impl ExactSizeIterator, ) { @@ -465,14 +465,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { llty: Type<'ll>, fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, - llfn: &'ll Value, - return_slot: ReturnSlot<&'ll Value>, - args: &[&'ll Value], + llfn: Value<'ll>, + return_slot: ReturnSlot>, + args: &[Value<'ll>], then: &'ll BasicBlock, catch: &'ll BasicBlock, funclet: Option<&Funclet<'ll>>, instance: Option>, - ) -> &'ll Value { + ) -> Value<'ll> { // If this function returns indirectly (`PassMode::Indirect`), // the `return_slot` should be the first argument. let args = match return_slot { @@ -563,7 +563,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unchecked_umul(x, y) => LLVMBuildNUWMul, } - fn unchecked_suadd(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value { + fn unchecked_suadd(&mut self, a: Value<'ll>, b: Value<'ll>) -> Value<'ll> { unsafe { let add = llvm::LLVMBuildAdd(self.llbuilder(), a, b, UNNAMED); if llvm::LLVMIsAInstruction(add).is_some() { @@ -573,7 +573,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { add } } - fn unchecked_susub(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value { + fn unchecked_susub(&mut self, a: Value<'ll>, b: Value<'ll>) -> Value<'ll> { unsafe { let sub = llvm::LLVMBuildSub(self.llbuilder(), a, b, UNNAMED); if llvm::LLVMIsAInstruction(sub).is_some() { @@ -583,7 +583,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { sub } } - fn unchecked_sumul(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value { + fn unchecked_sumul(&mut self, a: Value<'ll>, b: Value<'ll>) -> Value<'ll> { unsafe { let mul = llvm::LLVMBuildMul(self.llbuilder(), a, b, UNNAMED); if llvm::LLVMIsAInstruction(mul).is_some() { @@ -594,7 +594,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn or_disjoint(&mut self, a: &'ll Value, b: &'ll Value) -> &'ll Value { + fn or_disjoint(&mut self, a: Value<'ll>, b: Value<'ll>) -> Value<'ll> { unsafe { let or = llvm::LLVMBuildOr(self.llbuilder(), a, b, UNNAMED); @@ -679,7 +679,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { val } - fn alloca(&mut self, size: Size, align: Align) -> &'ll Value { + fn alloca(&mut self, size: Size, align: Align) -> Value<'ll> { let mut bx = Builder::with_cx(self.cx); bx.position_at_start(unsafe { llvm::LLVMGetFirstBasicBlock(self.llfn()) }); bx.direct_alloca(size, align, "") @@ -697,7 +697,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn load(&mut self, ty: Type<'ll>, ptr: &'ll Value, align: Align) -> &'ll Value { + fn load(&mut self, ty: Type<'ll>, ptr: Value<'ll>, align: Align) -> Value<'ll> { unsafe { let load = llvm::LLVMBuildLoad2(self.llbuilder(), ty, ptr, UNNAMED); let align = align.min(self.cx().tcx.sess.target.max_reliable_alignment()); @@ -706,7 +706,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn volatile_load(&mut self, ty: Type<'ll>, ptr: &'ll Value, align: Align) -> &'ll Value { + fn volatile_load(&mut self, ty: Type<'ll>, ptr: Value<'ll>, align: Align) -> Value<'ll> { unsafe { let load = self.load(ty, ptr, align); llvm::LLVMSetVolatile(load, llvm::TRUE); @@ -717,11 +717,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn atomic_load( &mut self, ty: Type<'ll>, - ptr: &'ll Value, + ptr: Value<'ll>, order: rustc_middle::ty::AtomicOrdering, volatile: bool, size: Size, - ) -> &'ll Value { + ) -> Value<'ll> { unsafe { let load = llvm::LLVMBuildLoad2(self.llbuilder(), ty, ptr, UNNAMED); // Set atomic ordering @@ -736,7 +736,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } #[instrument(level = "trace", skip(self))] - fn load_operand(&mut self, place: PlaceRef<'tcx, &'ll Value>) -> OperandRef<'tcx, &'ll Value> { + fn load_operand(&mut self, place: PlaceRef<'tcx, Value<'ll>>) -> OperandRef<'tcx, Value<'ll>> { if place.layout.is_unsized() { let tail = self.tcx.struct_tail_for_codegen(place.layout.ty, self.typing_env()); if matches!(tail.kind(), ty::Foreign(..)) { @@ -755,7 +755,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { #[instrument(level = "trace", skip(bx))] fn scalar_load_metadata<'a, 'll, 'tcx>( bx: &mut Builder<'a, 'll, 'tcx>, - load: &'ll Value, + load: Value<'ll>, scalar: abi::Scalar, layout: TyAndLayout<'tcx>, offset: Size, @@ -842,9 +842,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn write_operand_repeatedly( &mut self, - cg_elem: OperandRef<'tcx, &'ll Value>, + cg_elem: OperandRef<'tcx, Value<'ll>>, count: u64, - dest: PlaceRef<'tcx, &'ll Value>, + dest: PlaceRef<'tcx, Value<'ll>>, ) { if self.cx.sess().opts.optimize == OptLevel::No { // To let debuggers single-step over lines like @@ -860,7 +860,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) { + fn range_metadata(&mut self, load: Value<'ll>, range: WrappingRange) { if self.cx.sess().opts.optimize == OptLevel::No { // Don't emit metadata we're not going to use return; @@ -874,14 +874,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { self.set_metadata_node(load, llvm::MD_range, &md); } - fn nonnull_metadata(&mut self, load: &'ll Value) { + fn nonnull_metadata(&mut self, load: Value<'ll>) { self.set_metadata_node(load, llvm::MD_nonnull, &[]); } fn store_with_flags( &mut self, - val: &'ll Value, - ptr: &'ll Value, + val: Value<'ll>, + ptr: Value<'ll>, align: Align, flags: MemFlags, ) { @@ -940,8 +940,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn atomic_store( &mut self, - val: &'ll Value, - ptr: &'ll Value, + val: Value<'ll>, + ptr: Value<'ll>, order: rustc_middle::ty::AtomicOrdering, volatile: bool, size: Size, @@ -960,24 +960,24 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn gep(&mut self, stride: Size, ptr: &'ll Value, index: &'ll Value) -> &'ll Value { + fn gep(&mut self, stride: Size, ptr: Value<'ll>, index: Value<'ll>) -> Value<'ll> { self.build_gep(stride, ptr, index, GEPNoWrapFlags::default()) } - fn inbounds_gep(&mut self, stride: Size, ptr: &'ll Value, index: &'ll Value) -> &'ll Value { + fn inbounds_gep(&mut self, stride: Size, ptr: Value<'ll>, index: Value<'ll>) -> Value<'ll> { self.build_gep(stride, ptr, index, GEPNoWrapFlags::InBounds) } - fn inbounds_nuw_gep(&mut self, stride: Size, ptr: &'ll Value, index: &'ll Value) -> &'ll Value { + fn inbounds_nuw_gep(&mut self, stride: Size, ptr: Value<'ll>, index: Value<'ll>) -> Value<'ll> { self.build_gep(stride, ptr, index, GEPNoWrapFlags::InBounds | GEPNoWrapFlags::NUW) } /* Casts */ - fn trunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn trunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildTrunc(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn unchecked_utrunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn unchecked_utrunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { debug_assert_ne!(self.val_ty(val), dest_ty); let trunc = self.trunc(val, dest_ty); @@ -989,7 +989,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { trunc } - fn unchecked_strunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn unchecked_strunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { debug_assert_ne!(self.val_ty(val), dest_ty); let trunc = self.trunc(val, dest_ty); @@ -1001,19 +1001,19 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { trunc } - fn sext(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn sext(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildSExt(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn fptoui_sat(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptoui_sat(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.fptoui.sat", &[dest_ty, self.val_ty(val)], &[val]) } - fn fptosi_sat(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptosi_sat(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.fptosi.sat", &[dest_ty, self.val_ty(val)], &[val]) } - fn fptoui(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptoui(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { // On WebAssembly the `fptoui` and `fptosi` instructions currently have // poor codegen. The reason for this is that the corresponding wasm // instructions, `i32.trunc_f32_s` for example, will trap when the float @@ -1044,7 +1044,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unsafe { llvm::LLVMBuildFPToUI(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn fptosi(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptosi(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { // see `fptoui` above for why wasm is different here if self.sess().target.is_like_wasm { let src_ty = self.cx.val_ty(val); @@ -1062,35 +1062,35 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { unsafe { llvm::LLVMBuildFPToSI(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn uitofp(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn uitofp(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildUIToFP(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn sitofp(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn sitofp(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildSIToFP(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn fptrunc(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fptrunc(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildFPTrunc(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn fpext(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn fpext(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildFPExt(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn ptrtoint(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn ptrtoint(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildPtrToInt(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn inttoptr(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn inttoptr(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildIntToPtr(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn bitcast(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn bitcast(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildBitCast(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn intcast(&mut self, val: &'ll Value, dest_ty: Type<'ll>, is_signed: bool) -> &'ll Value { + fn intcast(&mut self, val: Value<'ll>, dest_ty: Type<'ll>, is_signed: bool) -> Value<'ll> { unsafe { llvm::LLVMBuildIntCast2( self.llbuilder(), @@ -1102,17 +1102,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn pointercast(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn pointercast(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildPointerCast(self.llbuilder(), val, dest_ty, UNNAMED) } } /* Comparisons */ - fn icmp(&mut self, op: IntPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { + fn icmp(&mut self, op: IntPredicate, lhs: Value<'ll>, rhs: Value<'ll>) -> Value<'ll> { let op = llvm::IntPredicate::from_generic(op); unsafe { llvm::LLVMBuildICmp(self.llbuilder(), op as c_uint, lhs, rhs, UNNAMED) } } - fn fcmp(&mut self, op: RealPredicate, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { + fn fcmp(&mut self, op: RealPredicate, lhs: Value<'ll>, rhs: Value<'ll>) -> Value<'ll> { let op = llvm::RealPredicate::from_generic(op); unsafe { llvm::LLVMBuildFCmp(self.llbuilder(), op as c_uint, lhs, rhs, UNNAMED) } } @@ -1132,11 +1132,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { /* Miscellaneous instructions */ fn memcpy( &mut self, - dst: &'ll Value, + dst: Value<'ll>, dst_align: Align, - src: &'ll Value, + src: Value<'ll>, src_align: Align, - size: &'ll Value, + size: Value<'ll>, flags: MemFlags, tt: Option, ) { @@ -1167,11 +1167,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn memmove( &mut self, - dst: &'ll Value, + dst: Value<'ll>, dst_align: Align, - src: &'ll Value, + src: Value<'ll>, src_align: Align, - size: &'ll Value, + size: Value<'ll>, flags: MemFlags, ) { assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memmove not supported"); @@ -1192,9 +1192,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn memset( &mut self, - ptr: &'ll Value, - fill_byte: &'ll Value, - size: &'ll Value, + ptr: Value<'ll>, + fill_byte: Value<'ll>, + size: Value<'ll>, align: Align, flags: MemFlags, ) { @@ -1212,28 +1212,28 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn vscale(&mut self, ty: Type<'ll>) -> &'ll Value { + fn vscale(&mut self, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMRustBuildVScale(self.llbuilder(), ty) } } fn select( &mut self, - cond: &'ll Value, - then_val: &'ll Value, - else_val: &'ll Value, - ) -> &'ll Value { + cond: Value<'ll>, + then_val: Value<'ll>, + else_val: Value<'ll>, + ) -> Value<'ll> { unsafe { llvm::LLVMBuildSelect(self.llbuilder(), cond, then_val, else_val, UNNAMED) } } - fn va_arg(&mut self, list: &'ll Value, ty: Type<'ll>) -> &'ll Value { + fn va_arg(&mut self, list: Value<'ll>, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildVAArg(self.llbuilder(), list, ty, UNNAMED) } } - fn extract_element(&mut self, vec: &'ll Value, idx: &'ll Value) -> &'ll Value { + fn extract_element(&mut self, vec: Value<'ll>, idx: Value<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildExtractElement(self.llbuilder(), vec, idx, UNNAMED) } } - fn vector_splat(&mut self, num_elts: u64, elt: &'ll Value) -> &'ll Value { + fn vector_splat(&mut self, num_elts: u64, elt: Value<'ll>) -> Value<'ll> { unsafe { let elt_ty = self.cx.val_ty(elt); let undef = llvm::LLVMGetUndef(self.type_vector(elt_ty, num_elts)); @@ -1243,25 +1243,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn extract_value(&mut self, agg_val: &'ll Value, idx: u64) -> &'ll Value { + fn extract_value(&mut self, agg_val: Value<'ll>, idx: u64) -> Value<'ll> { assert_eq!(idx as c_uint as u64, idx); unsafe { llvm::LLVMBuildExtractValue(self.llbuilder(), agg_val, idx as c_uint, UNNAMED) } } - fn insert_value(&mut self, agg_val: &'ll Value, elt: &'ll Value, idx: u64) -> &'ll Value { + fn insert_value(&mut self, agg_val: Value<'ll>, elt: Value<'ll>, idx: u64) -> Value<'ll> { assert_eq!(idx as c_uint as u64, idx); unsafe { llvm::LLVMBuildInsertValue(self.llbuilder(), agg_val, elt, idx as c_uint, UNNAMED) } } - fn set_personality_fn(&mut self, personality: &'ll Value) { + fn set_personality_fn(&mut self, personality: Value<'ll>) { unsafe { llvm::LLVMSetPersonalityFn(self.llfn(), personality); } } - fn cleanup_landing_pad(&mut self, pers_fn: &'ll Value) -> (&'ll Value, &'ll Value) { + fn cleanup_landing_pad(&mut self, pers_fn: Value<'ll>) -> (Value<'ll>, Value<'ll>) { let ty = self.type_struct(&[self.type_ptr(), self.type_i32()]); let landing_pad = self.landing_pad(ty, pers_fn, 0); unsafe { @@ -1270,13 +1270,13 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { (self.extract_value(landing_pad, 0), self.extract_value(landing_pad, 1)) } - fn filter_landing_pad(&mut self, pers_fn: &'ll Value) { + fn filter_landing_pad(&mut self, pers_fn: Value<'ll>) { let ty = self.type_struct(&[self.type_ptr(), self.type_i32()]); let landing_pad = self.landing_pad(ty, pers_fn, 1); self.add_clause(landing_pad, self.const_array(self.type_ptr(), &[])); } - fn resume(&mut self, exn0: &'ll Value, exn1: &'ll Value) { + fn resume(&mut self, exn0: Value<'ll>, exn1: Value<'ll>) { let ty = self.type_struct(&[self.type_ptr(), self.type_i32()]); let mut exn = self.const_poison(ty); exn = self.insert_value(exn, exn0, 0); @@ -1286,7 +1286,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn cleanup_pad(&mut self, parent: Option<&'ll Value>, args: &[&'ll Value]) -> Funclet<'ll> { + fn cleanup_pad(&mut self, parent: Option>, args: &[Value<'ll>]) -> Funclet<'ll> { let ret = unsafe { llvm::LLVMBuildCleanupPad( self.llbuilder(), @@ -1306,7 +1306,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn catch_pad(&mut self, parent: &'ll Value, args: &[&'ll Value]) -> Funclet<'ll> { + fn catch_pad(&mut self, parent: Value<'ll>, args: &[Value<'ll>]) -> Funclet<'ll> { let ret = unsafe { llvm::LLVMBuildCatchPad( self.llbuilder(), @@ -1321,10 +1321,10 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn catch_switch( &mut self, - parent: Option<&'ll Value>, + parent: Option>, unwind: Option<&'ll BasicBlock>, handlers: &[&'ll BasicBlock], - ) -> &'ll Value { + ) -> Value<'ll> { let ret = unsafe { llvm::LLVMBuildCatchSwitch( self.llbuilder(), @@ -1343,20 +1343,20 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { ret } - fn get_funclet_cleanuppad(&self, funclet: &Funclet<'ll>) -> &'ll Value { + fn get_funclet_cleanuppad(&self, funclet: &Funclet<'ll>) -> Value<'ll> { funclet.cleanuppad() } // Atomic Operations fn atomic_cmpxchg( &mut self, - dst: &'ll Value, - cmp: &'ll Value, - src: &'ll Value, + dst: Value<'ll>, + cmp: Value<'ll>, + src: Value<'ll>, order: rustc_middle::ty::AtomicOrdering, failure_order: rustc_middle::ty::AtomicOrdering, weak: bool, - ) -> (&'ll Value, &'ll Value) { + ) -> (Value<'ll>, Value<'ll>) { unsafe { let value = llvm::LLVMBuildAtomicCmpXchg( self.llbuilder(), @@ -1377,11 +1377,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { fn atomic_rmw( &mut self, op: rustc_codegen_ssa::common::AtomicRmwBinOp, - dst: &'ll Value, - src: &'ll Value, + dst: Value<'ll>, + src: Value<'ll>, order: rustc_middle::ty::AtomicOrdering, ret_ptr: bool, - ) -> &'ll Value { + ) -> Value<'ll> { // FIXME: If `ret_ptr` is true and `src` is not a pointer, we *should* tell LLVM that the // LHS is a pointer and the operation should be provenance-preserving, but LLVM does not // currently support that (https://github.com/llvm/llvm-project/issues/120837). @@ -1420,15 +1420,15 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn set_invariant_load(&mut self, load: &'ll Value) { + fn set_invariant_load(&mut self, load: Value<'ll>) { self.set_metadata_node(load, llvm::MD_invariant_load, &[]); } - fn lifetime_start(&mut self, ptr: &'ll Value, size: Size) { + fn lifetime_start(&mut self, ptr: Value<'ll>, size: Size) { self.call_lifetime_intrinsic("llvm.lifetime.start", ptr, size); } - fn lifetime_end(&mut self, ptr: &'ll Value, size: Size) { + fn lifetime_end(&mut self, ptr: Value<'ll>, size: Size) { self.call_lifetime_intrinsic("llvm.lifetime.end", ptr, size); } @@ -1437,12 +1437,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { llty: Type<'ll>, caller_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, - llfn: &'ll Value, - return_slot: ReturnSlot<&'ll Value>, - args: &[&'ll Value], + llfn: Value<'ll>, + return_slot: ReturnSlot>, + args: &[Value<'ll>], funclet: Option<&Funclet<'ll>>, callee_instance: Option>, - ) -> &'ll Value { + ) -> Value<'ll> { // If this function returns indirectly (`PassMode::Indirect`), // the `return_slot` should be the first argument. let args = match return_slot { @@ -1480,7 +1480,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { self.llbuilder(), llty, llfn, - args.as_ptr() as *const &llvm::Value, + args.as_ptr(), args.len() as c_uint, bundles.as_ptr(), bundles.len() as c_uint, @@ -1524,11 +1524,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } } - fn zext(&mut self, val: &'ll Value, dest_ty: Type<'ll>) -> &'ll Value { + fn zext(&mut self, val: Value<'ll>, dest_ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildZExt(self.llbuilder(), val, dest_ty, UNNAMED) } } - fn apply_attrs_to_cleanup_callsite(&mut self, llret: &'ll Value) { + fn apply_attrs_to_cleanup_callsite(&mut self, llret: Value<'ll>) { // Cleanup is always the cold path. let cold_inline = llvm::AttributeKind::Cold.create_attr(self.llcx); attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[cold_inline]); @@ -1536,7 +1536,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { } impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> { - fn get_static(&mut self, def_id: DefId) -> &'ll Value { + fn get_static(&mut self, def_id: DefId) -> Value<'ll> { // Forward to the `get_static` method of `CodegenCx` let global = self.cx().get_static(def_id); if self.cx().tcx.is_thread_local_static(def_id) { @@ -1552,7 +1552,7 @@ impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> { } impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { - pub(crate) fn llfn(&self) -> &'ll Value { + pub(crate) fn llfn(&self) -> Value<'ll> { unsafe { llvm::LLVMGetBasicBlockParent(self.llbb()) } } @@ -1561,7 +1561,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { span: rustc_span::Span, expected_ty: String, check_kind: u8, - ) -> &'ll Value { + ) -> Value<'ll> { let cx = self.cx(); let tcx = cx.tcx; @@ -1610,24 +1610,24 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { } } impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { - fn align_metadata(&mut self, load: &'ll Value, align: Align) { + fn align_metadata(&mut self, load: Value<'ll>, align: Align) { let md = [llvm::LLVMValueAsMetadata(self.cx.const_u64(align.bytes()))]; self.set_metadata_node(load, llvm::MD_align, &md); } - fn noundef_metadata(&mut self, load: &'ll Value) { + fn noundef_metadata(&mut self, load: Value<'ll>) { self.set_metadata_node(load, llvm::MD_noundef, &[]); } - pub(crate) fn set_unpredictable(&mut self, inst: &'ll Value) { + pub(crate) fn set_unpredictable(&mut self, inst: Value<'ll>) { self.set_metadata_node(inst, llvm::MD_unpredictable, &[]); } fn write_operand_repeatedly_optimized( &mut self, - cg_elem: OperandRef<'tcx, &'ll Value>, + cg_elem: OperandRef<'tcx, Value<'ll>>, count: u64, - dest: PlaceRef<'tcx, &'ll Value>, + dest: PlaceRef<'tcx, Value<'ll>>, ) { let zero = self.const_usize(0); let count = self.const_usize(count); @@ -1657,9 +1657,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn write_operand_repeatedly_unoptimized( &mut self, - cg_elem: OperandRef<'tcx, &'ll Value>, + cg_elem: OperandRef<'tcx, Value<'ll>>, count: u64, - dest: PlaceRef<'tcx, &'ll Value>, + dest: PlaceRef<'tcx, Value<'ll>>, ) { let zero = self.const_usize(0); let count = self.const_usize(count); @@ -1691,13 +1691,13 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { *self = Self::build(self.cx, next_bb); } - pub(crate) fn minimum_number_nsz(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { + pub(crate) fn minimum_number_nsz(&mut self, lhs: Value<'ll>, rhs: Value<'ll>) -> Value<'ll> { let call = self.call_intrinsic("llvm.minimumnum", &[self.val_ty(lhs)], &[lhs, rhs]); unsafe { llvm::LLVMRustSetNoSignedZeros(call) }; call } - pub(crate) fn maximum_number_nsz(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value { + pub(crate) fn maximum_number_nsz(&mut self, lhs: Value<'ll>, rhs: Value<'ll>) -> Value<'ll> { let call = self.call_intrinsic("llvm.maximumnum", &[self.val_ty(lhs)], &[lhs, rhs]); unsafe { llvm::LLVMRustSetNoSignedZeros(call) }; call @@ -1705,33 +1705,33 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { pub(crate) fn insert_element( &mut self, - vec: &'ll Value, - elt: &'ll Value, - idx: &'ll Value, - ) -> &'ll Value { + vec: Value<'ll>, + elt: Value<'ll>, + idx: Value<'ll>, + ) -> Value<'ll> { unsafe { llvm::LLVMBuildInsertElement(self.llbuilder(), vec, elt, idx, UNNAMED) } } pub(crate) fn shuffle_vector( &mut self, - v1: &'ll Value, - v2: &'ll Value, - mask: &'ll Value, - ) -> &'ll Value { + v1: Value<'ll>, + v2: Value<'ll>, + mask: Value<'ll>, + ) -> Value<'ll> { unsafe { llvm::LLVMBuildShuffleVector(self.llbuilder(), v1, v2, mask, UNNAMED) } } - pub(crate) fn vector_reduce_fadd(&mut self, acc: &'ll Value, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_fadd(&mut self, acc: Value<'ll>, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], &[acc, src]) } - pub(crate) fn vector_reduce_fmul(&mut self, acc: &'ll Value, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_fmul(&mut self, acc: Value<'ll>, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], &[acc, src]) } pub(crate) fn vector_reduce_fadd_reassoc( &mut self, - acc: &'ll Value, - src: &'ll Value, - ) -> &'ll Value { + acc: Value<'ll>, + src: Value<'ll>, + ) -> Value<'ll> { unsafe { let instr = self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], &[acc, src]); @@ -1741,9 +1741,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { } pub(crate) fn vector_reduce_fmul_reassoc( &mut self, - acc: &'ll Value, - src: &'ll Value, - ) -> &'ll Value { + acc: Value<'ll>, + src: Value<'ll>, + ) -> Value<'ll> { unsafe { let instr = self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], &[acc, src]); @@ -1751,29 +1751,29 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { instr } } - pub(crate) fn vector_reduce_add(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_add(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.add", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_mul(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_mul(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.mul", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_and(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_and(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.and", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_or(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_or(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.or", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_xor(&mut self, src: &'ll Value) -> &'ll Value { + pub(crate) fn vector_reduce_xor(&mut self, src: Value<'ll>) -> Value<'ll> { self.call_intrinsic("llvm.vector.reduce.xor", &[self.val_ty(src)], &[src]) } - pub(crate) fn vector_reduce_min(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value { + pub(crate) fn vector_reduce_min(&mut self, src: Value<'ll>, is_signed: bool) -> Value<'ll> { self.call_intrinsic( if is_signed { "llvm.vector.reduce.smin" } else { "llvm.vector.reduce.umin" }, &[self.val_ty(src)], &[src], ) } - pub(crate) fn vector_reduce_max(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value { + pub(crate) fn vector_reduce_max(&mut self, src: Value<'ll>, is_signed: bool) -> Value<'ll> { self.call_intrinsic( if is_signed { "llvm.vector.reduce.smax" } else { "llvm.vector.reduce.umax" }, &[self.val_ty(src)], @@ -1782,7 +1782,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { } } impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { - pub(crate) fn add_clause(&mut self, landing_pad: &'ll Value, clause: &'ll Value) { + pub(crate) fn add_clause(&mut self, landing_pad: Value<'ll>, clause: Value<'ll>) { unsafe { llvm::LLVMAddClause(landing_pad, clause); } @@ -1792,7 +1792,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { &mut self, funclet: &Funclet<'ll>, unwind: &'ll BasicBlock, - ) -> &'ll Value { + ) -> Value<'ll> { let ret = unsafe { llvm::LLVMBuildCatchRet(self.llbuilder(), funclet.cleanuppad(), unwind) }; ret.expect("LLVM does not have support for catchret") @@ -1802,9 +1802,9 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { &mut self, typ: &str, fn_ty: Type<'ll>, - llfn: &'ll Value, - args: &'b [&'ll Value], - ) -> Cow<'b, [&'ll Value]> { + llfn: Value<'ll>, + args: &'b [Value<'ll>], + ) -> Cow<'b, [Value<'ll>]> { assert!( self.cx.type_kind(fn_ty) == TypeKind::Function, "builder::{typ} not passed a function, but {fn_ty:?}" @@ -1839,7 +1839,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { Cow::Owned(casted_args) } - pub(crate) fn va_arg(&mut self, list: &'ll Value, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn va_arg(&mut self, list: Value<'ll>, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMBuildVAArg(self.llbuilder(), list, ty, UNNAMED) } } } @@ -1849,14 +1849,14 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { &mut self, base_name: impl Into>, type_params: &[Type<'ll>], - args: &[&'ll Value], - ) -> &'ll Value { + args: &[Value<'ll>], + ) -> Value<'ll> { let (ty, f) = self.cx.get_intrinsic(base_name.into(), type_params); // No LLVM intrinsic returns its data indirectly (via `sret`). self.call(ty, None, None, f, ReturnSlot::Direct, args, None, None) } - fn call_lifetime_intrinsic(&mut self, intrinsic: &'static str, ptr: &'ll Value, size: Size) { + fn call_lifetime_intrinsic(&mut self, intrinsic: &'static str, ptr: Value<'ll>, size: Size) { let size = size.bytes(); if size == 0 { return; @@ -1876,9 +1876,9 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { pub(crate) fn phi( &mut self, ty: Type<'ll>, - vals: &[&'ll Value], + vals: &[Value<'ll>], bbs: &[&'ll BasicBlock], - ) -> &'ll Value { + ) -> Value<'ll> { assert_eq!(vals.len(), bbs.len()); let phi = unsafe { llvm::LLVMBuildPhi(self.llbuilder(), ty, UNNAMED) }; unsafe { @@ -1887,7 +1887,7 @@ impl<'a, 'll, CX: Borrow>> GenericBuilder<'a, 'll, CX> { } } - fn add_incoming_to_phi(&mut self, phi: &'ll Value, val: &'ll Value, bb: &'ll BasicBlock) { + fn add_incoming_to_phi(&mut self, phi: Value<'ll>, val: Value<'ll>, bb: &'ll BasicBlock) { unsafe { llvm::LLVMAddIncoming(phi, &val, &bb, 1 as c_uint); } @@ -1897,9 +1897,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { pub(crate) fn landing_pad( &mut self, ty: Type<'ll>, - pers_fn: &'ll Value, + pers_fn: Value<'ll>, num_clauses: usize, - ) -> &'ll Value { + ) -> Value<'ll> { // Use LLVMSetPersonalityFn to set the personality. It supports arbitrary Consts while, // LLVMBuildLandingPad requires the argument to be a Function (as of LLVM 12). The // personality lives on the parent function anyway. @@ -1914,13 +1914,13 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { llty: Type<'ll>, fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, - llfn: &'ll Value, - args: &[&'ll Value], + llfn: Value<'ll>, + args: &[Value<'ll>], default_dest: &'ll BasicBlock, indirect_dest: &[&'ll BasicBlock], funclet: Option<&Funclet<'ll>>, instance: Option>, - ) -> &'ll Value { + ) -> Value<'ll> { debug!("invoke {:?} with args ({:?})", llfn, args); let args = self.check_call("callbr", llty, llfn, args); @@ -1971,7 +1971,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, instance: Option>, - llfn: &'ll Value, + llfn: Value<'ll>, ) { let is_indirect_call = unsafe { llvm::LLVMRustIsNonGVFunctionPointerTy(llfn) }; if self.tcx.sess.is_sanitizer_cfi_enabled() @@ -2107,7 +2107,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, instance: Option>, - llfn: &'ll Value, + llfn: Value<'ll>, ) -> Option> { let is_indirect_call = unsafe { llvm::LLVMRustIsNonGVFunctionPointerTy(llfn) }; let kcfi_bundle = if self.tcx.sess.is_sanitizer_kcfi_enabled() @@ -2151,7 +2151,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { // Emits pauth operand bundle. fn ptrauth_operand_bundle( &mut self, - llfn: &'ll Value, + llfn: Value<'ll>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, ) -> Option> { let schema = self.sess().pointer_authentication_functions()?; @@ -2186,10 +2186,10 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> { #[instrument(level = "debug", skip(self))] pub(crate) fn instrprof_increment( &mut self, - fn_name: &'ll Value, - hash: &'ll Value, - num_counters: &'ll Value, - index: &'ll Value, + fn_name: Value<'ll>, + hash: Value<'ll>, + num_counters: Value<'ll>, + index: Value<'ll>, ) { self.call_intrinsic("llvm.instrprof.increment", &[], &[fn_name, hash, num_counters, index]); } diff --git a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs index 4c83f0a64248f..72ce05213fb7d 100644 --- a/compiler/rustc_codegen_llvm/src/builder/autodiff.rs +++ b/compiler/rustc_codegen_llvm/src/builder/autodiff.rs @@ -136,9 +136,9 @@ pub(crate) fn adjust_activity_to_abi<'tcx>( fn match_args_from_caller_to_enzyme<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, width: u32, - args: &mut Vec<&'ll Value>, + args: &mut Vec>, inputs: &[DiffActivity], - outer_args: &[&'ll Value], + outer_args: &[Value<'ll>], ) { debug!("matching autodiff arguments"); // We now handle the issue that Rust level arguments not always match the llvm-ir level @@ -166,7 +166,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>( let diff_activity = inputs[activity_pos as usize]; // Duplicated arguments received a shadow argument, into which enzyme will write the // gradient. - let (activity, duplicated): (&Value, bool) = match diff_activity { + let (activity, duplicated): (Value<'ll>, bool) = match diff_activity { DiffActivity::None => panic!("not a valid input activity"), DiffActivity::Const => (global_const, false), DiffActivity::Active => (global_out, false), @@ -284,15 +284,15 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>( // cover some assumptions of enzyme/autodiff, which could lead to UB otherwise. pub(crate) fn generate_enzyme_call<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - fn_to_diff: &'ll Value, + fn_to_diff: Value<'ll>, outer_name: &str, ret_ty: Type<'ll>, - fn_args: &[&'ll Value], + fn_args: &[Value<'ll>], attrs: &RustcAutodiff, dest_layout: ty::layout::TyAndLayout<'tcx>, - dest_place: Option>, + dest_place: Option>>, fnc_tree: FncTree, -) -> IntrinsicResult<'tcx, &'ll Value> { +) -> IntrinsicResult<'tcx, Value<'ll>> { let cx: &SimpleCx<'ll> = &bx.scx; // We have to pick the name depending on whether we want forward or reverse mode autodiff. let mut ad_name: String = match attrs.mode { @@ -346,7 +346,7 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>( enzyme_ty, ); - let num_args = llvm::LLVMCountParams(&fn_to_diff); + let num_args = llvm::LLVMCountParams(fn_to_diff); let mut args = Vec::with_capacity(num_args as usize + 1); args.push(fn_to_diff); diff --git a/compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs b/compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs index 46526b6bce421..f26c02fe394eb 100644 --- a/compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs +++ b/compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs @@ -21,18 +21,18 @@ use crate::llvm::{self, Linkage, Type, TypeKind, Value}; // LLVM kernel-independent globals required for offloading pub(crate) struct OffloadGlobals<'ll> { - pub launcher_fn: &'ll llvm::Value, + pub launcher_fn: llvm::Value<'ll>, pub launcher_ty: llvm::Type<'ll>, pub kernel_args_ty: KernelArgsTy, pub offload_entry_ty: llvm::Type<'ll>, - pub begin_mapper: &'ll llvm::Value, - pub end_mapper: &'ll llvm::Value, + pub begin_mapper: llvm::Value<'ll>, + pub end_mapper: llvm::Value<'ll>, pub mapper_fn_ty: llvm::Type<'ll>, - pub ident_t_global: &'ll llvm::Value, + pub ident_t_global: llvm::Value<'ll>, } impl<'ll> OffloadGlobals<'ll> { @@ -61,22 +61,22 @@ impl<'ll> OffloadGlobals<'ll> { } pub(crate) struct OffloadKernelDims<'ll> { - num_workgroups: &'ll Value, - threads_per_block: &'ll Value, - workgroup_dims: [&'ll Value; 3], - thread_dims: [&'ll Value; 3], + num_workgroups: Value<'ll>, + threads_per_block: Value<'ll>, + workgroup_dims: [Value<'ll>; 3], + thread_dims: [Value<'ll>; 3], } impl<'ll> OffloadKernelDims<'ll> { pub(crate) fn from_operands<'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, - workgroup_op: &OperandRef<'tcx, &'ll llvm::Value>, - thread_op: &OperandRef<'tcx, &'ll llvm::Value>, + workgroup_op: &OperandRef<'tcx, llvm::Value<'ll>>, + thread_op: &OperandRef<'tcx, llvm::Value<'ll>>, ) -> Self { fn load_3_u32<'ll>( builder: &mut Builder<'_, 'll, '_>, - place: PlaceValue<&'ll Value>, - ) -> [&'ll Value; 3] { + place: PlaceValue>, + ) -> [Value<'ll>; 3] { let ty = builder.type_i32(); let size = 4; let v0 = builder.load(ty, place.llval, place.align); @@ -100,8 +100,8 @@ impl<'ll> OffloadKernelDims<'ll> { fn mul_dim3<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, - [x, y, z]: [&'ll Value; 3], - ) -> &'ll Value { + [x, y, z]: [Value<'ll>; 3], + ) -> Value<'ll> { let xy = builder.mul(x, y); builder.mul(xy, z) } @@ -120,7 +120,7 @@ impl<'ll> OffloadKernelDims<'ll> { // ; Function Attrs: nounwind // declare i32 @__tgt_target_kernel(ptr, i64, i32, i32, ptr, ptr) #2 -fn generate_launcher<'ll>(cx: &CodegenCx<'ll, '_>) -> (&'ll llvm::Value, llvm::Type<'ll>) { +fn generate_launcher<'ll>(cx: &CodegenCx<'ll, '_>) -> (llvm::Value<'ll>, llvm::Type<'ll>) { let tptr = cx.type_ptr(); let ti64 = cx.type_i64(); let ti32 = cx.type_i32(); @@ -137,7 +137,7 @@ fn generate_launcher<'ll>(cx: &CodegenCx<'ll, '_>) -> (&'ll llvm::Value, llvm::T /// declaration together with its type. pub(crate) fn declare_omp_get_num_devices<'ll>( cx: &CodegenCx<'ll, '_>, -) -> (&'ll llvm::Value, llvm::Type<'ll>) { +) -> (llvm::Value<'ll>, llvm::Type<'ll>) { let ti32 = cx.type_i32(); let tgt_fn_ty = cx.type_func(&[], ti32); let name = "omp_get_num_devices"; @@ -152,7 +152,7 @@ pub(crate) fn declare_omp_get_num_devices<'ll>( // @1 = private unnamed_addr constant %struct.ident_t { i32 0, i32 2, i32 0, i32 22, ptr @0 }, align 8 // FIXME(offload): @0 should include the file name (e.g. lib.rs) in which the function to be // offloaded was defined. -pub(crate) fn generate_at_one<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll llvm::Value { +pub(crate) fn generate_at_one<'ll>(cx: &CodegenCx<'ll, '_>) -> llvm::Value<'ll> { let unknown_txt = ";unknown;unknown;0;0;;"; let c_entry_name = CString::new(unknown_txt).unwrap(); let c_val = c_entry_name.as_bytes_with_nul(); @@ -205,9 +205,9 @@ impl TgtOffloadEntry { fn new<'ll>( cx: &CodegenCx<'ll, '_>, - region_id: &'ll Value, - llglobal: &'ll Value, - ) -> [&'ll Value; 9] { + region_id: Value<'ll>, + llglobal: Value<'ll>, + ) -> [Value<'ll>; 9] { let reserved = cx.get_const_i64(0); let version = cx.get_const_i16(1); let kind = cx.get_const_i16(1); @@ -291,12 +291,12 @@ impl KernelArgsTy { fn new<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, num_args: u64, - memtransfer_types: &'ll Value, - geps: [&'ll Value; 3], - workgroup_dims: [&'ll Value; 3], - thread_dims: [&'ll Value; 3], - dyn_cache: &'ll Value, - ) -> [&'ll Value; Self::FIELD_COUNT] { + memtransfer_types: Value<'ll>, + geps: [Value<'ll>; 3], + workgroup_dims: [Value<'ll>; 3], + thread_dims: [Value<'ll>; 3], + dyn_cache: Value<'ll>, + ) -> [Value<'ll>; Self::FIELD_COUNT] { [ // Version cx.get_const_i32(KernelArgsTy::OFFLOAD_VERSION), @@ -336,16 +336,16 @@ impl KernelArgsTy { // Contains LLVM values needed to manage offloading for a single kernel. #[derive(Copy, Clone)] pub(crate) struct OffloadKernelGlobals<'ll> { - pub offload_sizes: &'ll llvm::Value, - pub memtransfer_begin: &'ll llvm::Value, - pub memtransfer_kernel: &'ll llvm::Value, - pub memtransfer_end: &'ll llvm::Value, - pub region_id: &'ll llvm::Value, + pub offload_sizes: llvm::Value<'ll>, + pub memtransfer_begin: llvm::Value<'ll>, + pub memtransfer_kernel: llvm::Value<'ll>, + pub memtransfer_end: llvm::Value<'ll>, + pub region_id: llvm::Value<'ll>, } fn gen_tgt_data_mappers<'ll>( cx: &CodegenCx<'ll, '_>, -) -> (&'ll llvm::Value, &'ll llvm::Value, &'ll llvm::Value, llvm::Type<'ll>) { +) -> (llvm::Value<'ll>, llvm::Value<'ll>, llvm::Value<'ll>, llvm::Type<'ll>) { let tptr = cx.type_ptr(); let ti64 = cx.type_i64(); let ti32 = cx.type_i32(); @@ -367,7 +367,7 @@ fn gen_tgt_data_mappers<'ll>( (begin_mapper_decl, update_mapper_decl, end_mapper_decl, mapper_fn_ty) } -fn add_priv_unnamed_arr<'ll>(cx: &SimpleCx<'ll>, name: &str, vals: &[u64]) -> &'ll llvm::Value { +fn add_priv_unnamed_arr<'ll>(cx: &SimpleCx<'ll>, name: &str, vals: &[u64]) -> llvm::Value<'ll> { let ti64 = cx.type_i64(); let mut size_val = Vec::with_capacity(vals.len()); for &val in vals { @@ -380,9 +380,9 @@ fn add_priv_unnamed_arr<'ll>(cx: &SimpleCx<'ll>, name: &str, vals: &[u64]) -> &' pub(crate) fn add_unnamed_global<'ll>( cx: &SimpleCx<'ll>, name: &str, - initializer: &'ll llvm::Value, + initializer: llvm::Value<'ll>, l: Linkage, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { let llglobal = add_global(cx, name, initializer, l); llvm::LLVMSetUnnamedAddress(llglobal, llvm::UnnamedAddr::Global); llglobal @@ -391,11 +391,11 @@ pub(crate) fn add_unnamed_global<'ll>( pub(crate) fn add_global<'ll>( cx: &SimpleCx<'ll>, name: &str, - initializer: &'ll llvm::Value, + initializer: llvm::Value<'ll>, l: Linkage, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { let c_name = CString::new(name).unwrap(); - let llglobal: &'ll llvm::Value = llvm::add_global(cx.llmod, cx.val_ty(initializer), &c_name); + let llglobal: llvm::Value<'ll> = llvm::add_global(cx.llmod, cx.val_ty(initializer), &c_name); llvm::set_global_constant(llglobal, true); llvm::set_linkage(llglobal, l); llvm::set_initializer(llglobal, initializer); @@ -513,7 +513,7 @@ fn declare_offload_fn<'ll>( cx: &CodegenCx<'ll, '_>, name: &str, ty: llvm::Type<'ll>, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { crate::declare::declare_simple_fn( cx, name, @@ -538,10 +538,10 @@ pub(crate) fn scalar_width<'ll>(cx: &SimpleCx<'ll>, ty: Type<'ll>) -> u64 { fn get_runtime_size<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, - args: &[&'ll Value], + args: &[Value<'ll>], index: usize, meta: &OffloadMetadata, -) -> &'ll Value { +) -> Value<'ll> { match meta.payload_size { OffloadSize::Slice { element_size } => { let length_idx = index + 1; @@ -574,23 +574,23 @@ fn get_runtime_size<'ll, 'tcx>( pub(crate) fn gen_call_handling<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, offload_data: &OffloadKernelGlobals<'ll>, - args: &[&'ll Value], + args: &[Value<'ll>], types: &[Type<'ll>], metadata: &[OffloadMetadata], offload_globals: &OffloadGlobals<'ll>, offload_dims: &OffloadKernelDims<'ll>, - dyn_cache: &'ll Value, - device_id: &'ll Value, + dyn_cache: Value<'ll>, + device_id: Value<'ll>, ) { let cx = builder.cx; - let OffloadKernelGlobals { + let &OffloadKernelGlobals { offload_sizes, memtransfer_begin, memtransfer_kernel, memtransfer_end, region_id, } = offload_data; - let OffloadKernelDims { num_workgroups, threads_per_block, workgroup_dims, thread_dims } = + let &OffloadKernelDims { num_workgroups, threads_per_block, workgroup_dims, thread_dims } = offload_dims; let has_dynamic = metadata.iter().any(|m| !matches!(m.payload_size, OffloadSize::Static(_))); @@ -696,22 +696,22 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>( // offload_{baseptrs,ptrs,sizes}. We will probably improve this along with our gpu frontend pr. fn get_geps<'ll, 'tcx>( _builder: &mut Builder<'_, 'll, 'tcx>, - a1: &'ll Value, - a2: &'ll Value, - a4: &'ll Value, + a1: Value<'ll>, + a2: Value<'ll>, + a4: Value<'ll>, _is_dynamic: bool, - ) -> [&'ll Value; 3] { + ) -> [Value<'ll>; 3] { [a1, a2, a4] } fn generate_mapper_call<'ll, 'tcx>( builder: &mut Builder<'_, 'll, 'tcx>, - geps: [&'ll Value; 3], - o_type: &'ll Value, - fn_to_call: &'ll Value, + geps: [Value<'ll>; 3], + o_type: Value<'ll>, + fn_to_call: Value<'ll>, fn_ty: Type<'ll>, num_args: u64, - s_ident_t: &'ll Value, + s_ident_t: Value<'ll>, ) { let cx = builder.cx; let nullptr = cx.const_null(cx.type_ptr()); @@ -739,8 +739,8 @@ pub(crate) fn gen_call_handling<'ll, 'tcx>( num_args, memtransfer_kernel, geps, - *workgroup_dims, - *thread_dims, + workgroup_dims, + thread_dims, dyn_cache, ); diff --git a/compiler/rustc_codegen_llvm/src/callee.rs b/compiler/rustc_codegen_llvm/src/callee.rs index df18b029b02c0..743324fab7f98 100644 --- a/compiler/rustc_codegen_llvm/src/callee.rs +++ b/compiler/rustc_codegen_llvm/src/callee.rs @@ -16,7 +16,7 @@ use crate::llvm::{self, Value}; /// Codegens a reference to a fn/method item, monomorphizing and /// inlining as it goes. -pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value { +pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> Value<'ll> { let tcx = cx.tcx(); debug!("get_fn(instance={:?})", instance); diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index b2ce873154bcc..7e47267a29f8b 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -28,9 +28,9 @@ use crate::llvm::{ pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>( cx: &CodegenCx<'ll, '_>, instance: Instance<'tcx>, - llfn: &'ll llvm::Value, + llfn: llvm::Value<'ll>, schema: &PointerAuthSchema, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { if cx.tcx.sess.pointer_authentication_functions().is_none() { return llfn; } @@ -106,16 +106,16 @@ pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>( /// annotated with which landing pad it's a part of. This is accomplished via /// the `OperandBundleDef` value created for MSVC landing pads. pub(crate) struct Funclet<'ll> { - cleanuppad: &'ll Value, + cleanuppad: Value<'ll>, operand: llvm::OperandBundleBox<'ll>, } impl<'ll> Funclet<'ll> { - pub(crate) fn new(cleanuppad: &'ll Value) -> Self { + pub(crate) fn new(cleanuppad: Value<'ll>) -> Self { Funclet { cleanuppad, operand: llvm::OperandBundleBox::new("funclet", &[cleanuppad]) } } - pub(crate) fn cleanuppad(&self) -> &'ll Value { + pub(crate) fn cleanuppad(&self) -> Value<'ll> { self.cleanuppad } @@ -126,11 +126,11 @@ impl<'ll> Funclet<'ll> { impl<'ll, CX: Borrow>> BackendTypes for GenericCx<'ll, CX> { // FIXME(eddyb) replace this with a `Function` "subclass" of `Value`. - type Function = &'ll Value; + type Function = Value<'ll>; type BasicBlock = &'ll BasicBlock; type Funclet = Funclet<'ll>; - type Value = &'ll Value; + type Value = Value<'ll>; type Type = Type<'ll>; type FunctionSignature = Type<'ll>; @@ -140,20 +140,20 @@ impl<'ll, CX: Borrow>> BackendTypes for GenericCx<'ll, CX> { } impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { - pub(crate) fn const_array(&self, ty: Type<'ll>, elts: &[&'ll Value]) -> &'ll Value { + pub(crate) fn const_array(&self, ty: Type<'ll>, elts: &[Value<'ll>]) -> Value<'ll> { let len = u64::try_from(elts.len()).expect("LLVMConstArray2 elements len overflow"); unsafe { llvm::LLVMConstArray2(ty, elts.as_ptr(), len) } } - pub(crate) fn const_bytes(&self, bytes: &[u8]) -> &'ll Value { + pub(crate) fn const_bytes(&self, bytes: &[u8]) -> Value<'ll> { bytes_in_context(self.llcx(), bytes) } - pub(crate) fn null_terminate_const_bytes(&self, bytes: &[u8]) -> &'ll Value { + pub(crate) fn null_terminate_const_bytes(&self, bytes: &[u8]) -> Value<'ll> { null_terminate_bytes_in_context(self.llcx(), bytes) } - pub(crate) fn const_get_elt(&self, v: &'ll Value, idx: u64) -> &'ll Value { + pub(crate) fn const_get_elt(&self, v: Value<'ll>, idx: u64) -> Value<'ll> { unsafe { let idx = c_uint::try_from(idx).expect("LLVMGetAggregateElement index overflow"); let r = llvm::LLVMGetAggregateElement(v, idx).unwrap(); @@ -164,11 +164,11 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { } } - pub(crate) fn const_null(&self, t: Type<'ll>) -> &'ll Value { + pub(crate) fn const_null(&self, t: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMConstNull(t) } } - pub(crate) fn const_struct(&self, elts: &[&'ll Value], packed: bool) -> &'ll Value { + pub(crate) fn const_struct(&self, elts: &[Value<'ll>], packed: bool) -> Value<'ll> { struct_in_context(self.llcx(), elts, packed) } } @@ -179,7 +179,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { global_alloc: GlobalAlloc<'tcx>, need_symbol_name: bool, schema: Option<&PointerAuthSchema>, - ) -> Result<&'ll Value, u64> { + ) -> Result, u64> { let alloc = match global_alloc { GlobalAlloc::Function { instance, .. } => { return Ok(self.get_fn_addr(instance, schema)); @@ -262,39 +262,39 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { } impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { - fn const_null(&self, t: Type<'ll>) -> &'ll Value { + fn const_null(&self, t: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMConstNull(t) } } - fn const_undef(&self, t: Type<'ll>) -> &'ll Value { + fn const_undef(&self, t: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMGetUndef(t) } } - fn const_poison(&self, t: Type<'ll>) -> &'ll Value { + fn const_poison(&self, t: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMGetPoison(t) } } - fn const_bool(&self, val: bool) -> &'ll Value { + fn const_bool(&self, val: bool) -> Value<'ll> { self.const_uint(self.type_i1(), val as u64) } - fn const_i8(&self, i: i8) -> &'ll Value { + fn const_i8(&self, i: i8) -> Value<'ll> { self.const_int(self.type_i8(), i as i64) } - fn const_i16(&self, i: i16) -> &'ll Value { + fn const_i16(&self, i: i16) -> Value<'ll> { self.const_int(self.type_i16(), i as i64) } - fn const_i32(&self, i: i32) -> &'ll Value { + fn const_i32(&self, i: i32) -> Value<'ll> { self.const_int(self.type_i32(), i as i64) } - fn const_i64(&self, i: i64) -> &'ll Value { + fn const_i64(&self, i: i64) -> Value<'ll> { self.const_int(self.type_i64(), i as i64) } - fn const_int(&self, t: Type<'ll>, i: i64) -> &'ll Value { + fn const_int(&self, t: Type<'ll>, i: i64) -> Value<'ll> { debug_assert!( self.type_kind(t) == TypeKind::Integer, "only allows integer types in const_int" @@ -302,23 +302,23 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { unsafe { llvm::LLVMConstInt(t, i as u64, TRUE) } } - fn const_u8(&self, i: u8) -> &'ll Value { + fn const_u8(&self, i: u8) -> Value<'ll> { self.const_uint(self.type_i8(), i as u64) } - fn const_u32(&self, i: u32) -> &'ll Value { + fn const_u32(&self, i: u32) -> Value<'ll> { self.const_uint(self.type_i32(), i as u64) } - fn const_u64(&self, i: u64) -> &'ll Value { + fn const_u64(&self, i: u64) -> Value<'ll> { self.const_uint(self.type_i64(), i) } - fn const_u128(&self, i: u128) -> &'ll Value { + fn const_u128(&self, i: u128) -> Value<'ll> { self.const_uint_big(self.type_i128(), i) } - fn const_usize(&self, i: u64) -> &'ll Value { + fn const_usize(&self, i: u64) -> Value<'ll> { let bit_size = self.data_layout().pointer_size().bits(); if bit_size < 64 { // make sure it doesn't overflow @@ -328,7 +328,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { self.const_uint(self.isize_ty, i) } - fn const_uint(&self, t: Type<'ll>, i: u64) -> &'ll Value { + fn const_uint(&self, t: Type<'ll>, i: u64) -> Value<'ll> { debug_assert!( self.type_kind(t) == TypeKind::Integer, "only allows integer types in const_uint" @@ -336,7 +336,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { unsafe { llvm::LLVMConstInt(t, i, FALSE) } } - fn const_uint_big(&self, t: Type<'ll>, u: u128) -> &'ll Value { + fn const_uint_big(&self, t: Type<'ll>, u: u128) -> Value<'ll> { debug_assert!( self.type_kind(t) == TypeKind::Integer, "only allows integer types in const_uint_big" @@ -347,11 +347,11 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { } } - fn const_real(&self, t: Type<'ll>, val: f64) -> &'ll Value { + fn const_real(&self, t: Type<'ll>, val: f64) -> Value<'ll> { unsafe { llvm::LLVMConstReal(t, val) } } - fn const_str(&self, s: &str) -> (&'ll Value, &'ll Value) { + fn const_str(&self, s: &str) -> (Value<'ll>, Value<'ll>) { let mut const_str_cache = self.const_str_cache.borrow_mut(); let str_global = const_str_cache.get(s).copied().unwrap_or_else(|| { let sc = self.const_bytes(s.as_bytes()); @@ -374,16 +374,16 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { (str_global, self.const_usize(len as u64)) } - fn const_struct(&self, elts: &[&'ll Value], packed: bool) -> &'ll Value { + fn const_struct(&self, elts: &[Value<'ll>], packed: bool) -> Value<'ll> { struct_in_context(self.llcx, elts, packed) } - fn const_vector(&self, elts: &[&'ll Value]) -> &'ll Value { + fn const_vector(&self, elts: &[Value<'ll>]) -> Value<'ll> { let len = c_uint::try_from(elts.len()).expect("LLVMConstVector elements len overflow"); unsafe { llvm::LLVMConstVector(elts.as_ptr(), len) } } - fn const_to_opt_uint(&self, v: &'ll Value) -> Option { + fn const_to_opt_uint(&self, v: Value<'ll>) -> Option { try_as_const_integral(v).and_then(|v| unsafe { let mut i = 0u64; let success = llvm::LLVMRustConstIntGetZExtValue(v, &mut i); @@ -391,7 +391,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { }) } - fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option { + fn const_to_opt_u128(&self, v: Value<'ll>, sign_ext: bool) -> Option { try_as_const_integral(v).and_then(|v| unsafe { let (mut lo, mut hi) = (0u64, 0u64); let success = llvm::LLVMRustConstInt128Get(v, sign_ext, &mut hi, &mut lo); @@ -405,7 +405,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { layout: abi::Scalar, llty: Type<'ll>, schema: Option<&PointerAuthSchema>, - ) -> &'ll Value { + ) -> Value<'ll> { let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() }; match cv { Scalar::Int(int) => { @@ -464,31 +464,31 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> { } /// Get the [LLVM type][Type] of a [`Value`]. -pub(crate) fn val_ty<'ll>(v: &'ll Value) -> Type<'ll> { +pub(crate) fn val_ty<'ll>(v: Value<'ll>) -> Type<'ll> { unsafe { llvm::LLVMTypeOf(v) } } -pub(crate) fn bytes_in_context<'ll>(llcx: llvm::Context<'ll>, bytes: &[u8]) -> &'ll Value { +pub(crate) fn bytes_in_context<'ll>(llcx: llvm::Context<'ll>, bytes: &[u8]) -> Value<'ll> { unsafe { llvm::LLVMConstStringInContext2(llcx, bytes.as_ptr(), bytes.len(), TRUE) } } pub(crate) fn null_terminate_bytes_in_context<'ll>( llcx: llvm::Context<'ll>, bytes: &[u8], -) -> &'ll Value { +) -> Value<'ll> { unsafe { llvm::LLVMConstStringInContext2(llcx, bytes.as_ptr(), bytes.len(), FALSE) } } -pub(crate) fn named_struct<'ll>(ty: Type<'ll>, elts: &[&'ll Value]) -> &'ll Value { +pub(crate) fn named_struct<'ll>(ty: Type<'ll>, elts: &[Value<'ll>]) -> Value<'ll> { let len = c_uint::try_from(elts.len()).expect("LLVMConstStructInContext elements len overflow"); unsafe { llvm::LLVMConstNamedStruct(ty, elts.as_ptr(), len) } } fn struct_in_context<'ll>( llcx: llvm::Context<'ll>, - elts: &[&'ll Value], + elts: &[Value<'ll>], packed: bool, -) -> &'ll Value { +) -> Value<'ll> { let len = c_uint::try_from(elts.len()).expect("LLVMConstStructInContext elements len overflow"); unsafe { llvm::LLVMConstStructInContext(llcx, elts.as_ptr(), len, packed.to_llvm_bool()) } } @@ -498,7 +498,7 @@ fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 { ((hi as u128) << 64) | (lo as u128) } -fn try_as_const_integral(v: &Value) -> Option<&ConstantInt> { +fn try_as_const_integral<'ll>(v: Value<'ll>) -> Option<&'ll ConstantInt> { unsafe { llvm::LLVMIsAConstantInt(v) } } diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 33d48642812e6..4952fdc732e9f 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -40,7 +40,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>( alloc: &Allocation, is_static: IsStatic, is_init_fini: IsInitOrFini, -) -> &'ll Value { +) -> Value<'ll> { // We expect that callers of const_alloc_to_llvm will instead directly codegen a pointer or // integer for any &ZST where the ZST is a constant (i.e. not a static). We should never be // producing empty LLVM allocations as they're just adding noise to binaries and forcing less @@ -59,7 +59,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>( // Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`, so `range` // must be within the bounds of `alloc` and not contain or overlap a pointer provenance. fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>( - llvals: &mut Vec<&'ll Value>, + llvals: &mut Vec>, cx: &'a CodegenCx<'ll, 'b>, alloc: &'a Allocation, range: Range, @@ -157,7 +157,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>( fn codegen_static_initializer<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, def_id: DefId, -) -> Result<(&'ll Value, ConstAllocation<'tcx>), ErrorHandled> { +) -> Result<(Value<'ll>, ConstAllocation<'tcx>), ErrorHandled> { let alloc = cx.tcx.eval_static_initializer(def_id)?; let attrs = cx.tcx.codegen_fn_attrs(def_id); // FIXME(jchlanda) Decide if this could be better served by `ctor` crate. See the discussion @@ -176,7 +176,7 @@ fn codegen_static_initializer<'ll, 'tcx>( Ok((const_alloc_to_llvm(cx, alloc.inner(), IsStatic::Yes, is_in_init_fini), alloc)) } -fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align: Align) { +fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: Value<'ll>, mut align: Align) { // The target may require greater alignment for globals than the type does. // Note: GCC and Clang also allow `__attribute__((aligned))` on variables, // which can force it to be smaller. Rust doesn't support this yet. @@ -192,7 +192,7 @@ fn check_and_apply_linkage<'ll, 'tcx>( llty: Type<'ll>, sym: &str, def_id: DefId, -) -> &'ll Value { +) -> Value<'ll> { if let Some(linkage) = attrs.import_linkage { debug!("get_static: sym={} linkage={:?}", sym, linkage); @@ -281,11 +281,11 @@ fn check_and_apply_linkage<'ll, 'tcx>( } impl<'ll> CodegenCx<'ll, '_> { - pub(crate) fn const_bitcast(&self, val: &'ll Value, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn const_bitcast(&self, val: Value<'ll>, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMConstBitCast(val, ty) } } - pub(crate) fn const_pointercast(&self, val: &'ll Value, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn const_pointercast(&self, val: Value<'ll>, ty: Type<'ll>) -> Value<'ll> { unsafe { llvm::LLVMConstPointerCast(val, ty) } } @@ -295,10 +295,10 @@ impl<'ll> CodegenCx<'ll, '_> { /// Fails if a symbol with the given name already exists. pub(crate) fn static_addr_of_mut( &self, - cv: &'ll Value, + cv: Value<'ll>, align: Align, kind: Option<&str>, - ) -> &'ll Value { + ) -> Value<'ll> { let gv = match kind { Some(kind) if !self.tcx.sess.fewer_names() => { let name = self.generate_local_symbol_name(kind); @@ -323,10 +323,10 @@ impl<'ll> CodegenCx<'ll, '_> { /// The returned global variable is a pointer in the default address space for globals. pub(crate) fn static_addr_of_impl( &self, - cv: &'ll Value, + cv: Value<'ll>, align: Align, kind: Option<&str>, - ) -> &'ll Value { + ) -> Value<'ll> { if let Some(&gv) = self.const_globals.borrow().get(&cv) { unsafe { // Upgrade the alignment in cases where the same constant is used with different @@ -346,7 +346,7 @@ impl<'ll> CodegenCx<'ll, '_> { } #[instrument(level = "debug", skip(self))] - pub(crate) fn get_static(&self, def_id: DefId) -> &'ll Value { + pub(crate) fn get_static(&self, def_id: DefId) -> Value<'ll> { let instance = Instance::mono(self.tcx, def_id); trace!(?instance); @@ -364,7 +364,7 @@ impl<'ll> CodegenCx<'ll, '_> { } #[instrument(level = "debug", skip(self, llty))] - fn get_static_inner(&self, def_id: DefId, llty: Type<'ll>) -> &'ll Value { + fn get_static_inner(&self, def_id: DefId, llty: Type<'ll>) -> Value<'ll> { let instance = Instance::mono(self.tcx, def_id); if let Some(&g) = self.instances.borrow().get(&instance) { trace!("used cached value"); @@ -474,7 +474,7 @@ impl<'ll> CodegenCx<'ll, '_> { fn codegen_static_item(&mut self, def_id: DefId) { assert!( llvm::LLVMGetInitializer( - self.instances.borrow().get(&Instance::mono(self.tcx, def_id)).unwrap() + self.instances.borrow().get(&Instance::mono(self.tcx, def_id)).copied().unwrap() ) .is_none() ); @@ -678,20 +678,20 @@ impl<'ll> CodegenCx<'ll, '_> { } /// Add a global value to a list to be stored in the `llvm.used` variable, an array of ptr. - pub(crate) fn add_used_global(&mut self, global: &'ll Value) { + pub(crate) fn add_used_global(&mut self, global: Value<'ll>) { self.used_statics.push(global); } /// Add a global value to a list to be stored in the `llvm.compiler.used` variable, /// an array of ptr. - pub(crate) fn add_compiler_used_global(&self, global: &'ll Value) { + pub(crate) fn add_compiler_used_global(&self, global: Value<'ll>) { self.compiler_used_statics.borrow_mut().push(global); } // We do our best here to match what Clang does when compiling Objective-C natively. // See Clang's `CGObjCCommonMac::CreateCStringLiteral`: // https://github.com/llvm/llvm-project/blob/llvmorg-20.1.8/clang/lib/CodeGen/CGObjCMac.cpp#L4134 - fn define_objc_classname(&self, classname: &str) -> &'ll Value { + fn define_objc_classname(&self, classname: &str) -> Value<'ll> { assert_eq!(self.objc_abi_version(), 1); let llval = self.null_terminate_const_bytes(classname.as_bytes()); @@ -742,7 +742,7 @@ impl<'ll> CodegenCx<'ll, '_> { // deduplicate references within a CGU, but we need a reference definition in each referencing // CGU. All attempts at using external references to a single reference definition result in // linker errors. - fn get_objc_classref(&self, classname: Symbol) -> &'ll Value { + fn get_objc_classref(&self, classname: Symbol) -> Value<'ll> { let mut classrefs = self.objc_classrefs.borrow_mut(); if let Some(classref) = classrefs.get(&classname).copied() { return classref; @@ -800,7 +800,7 @@ impl<'ll> CodegenCx<'ll, '_> { // Newer versions of Apple Clang generate calls to `@"objc_msgSend$methname"` selector stub // functions. We don't currently do that. The code we generate is closer to what Apple Clang // generates with the `-fno-objc-msgsend-selector-stubs` option. - fn get_objc_selref(&self, methname: Symbol) -> &'ll Value { + fn get_objc_selref(&self, methname: Symbol) -> Value<'ll> { let mut selrefs = self.objc_selrefs.borrow_mut(); if let Some(selref) = selrefs.get(&methname).copied() { return selref; @@ -911,7 +911,7 @@ impl<'ll> StaticCodegenMethods for CodegenCx<'ll, '_> { /// /// The pointer will always be in the default address space. If global variables default to a /// different address space, an addrspacecast is inserted. - fn static_addr_of(&self, alloc: ConstAllocation<'_>, kind: Option<&str>) -> &'ll Value { + fn static_addr_of(&self, alloc: ConstAllocation<'_>, kind: Option<&str>) -> Value<'ll> { // FIXME: should we cache `const_alloc_to_llvm` to avoid repeating this for the // same `ConstAllocation`? let cv = const_alloc_to_llvm(self, alloc.inner(), IsStatic::No, IsInitOrFini::No); diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 2156ac783758a..56f0be1a89e2a 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -101,30 +101,30 @@ pub(crate) struct FullCx<'ll, 'tcx> { pub codegen_unit: &'tcx CodegenUnit<'tcx>, /// Cache instances of monomorphic and polymorphic items - pub instances: RefCell, &'ll Value>>, + pub instances: RefCell, Value<'ll>>>, /// Cache instances of intrinsics - pub intrinsic_instances: RefCell, &'ll Value>>, + pub intrinsic_instances: RefCell, Value<'ll>>>, /// Cache generated vtables - pub vtables: RefCell, Option>), &'ll Value>>, + pub vtables: RefCell, Option>), Value<'ll>>>, /// Cache of constant strings, - pub const_str_cache: RefCell>, + pub const_str_cache: RefCell>>, /// Cache of emitted const globals (value -> global) - pub const_globals: RefCell>, + pub const_globals: RefCell, Value<'ll>>>, /// List of globals for static variables which need to be passed to the /// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete. /// (We have to make sure we don't invalidate any Values referring /// to constants.) - pub statics_to_rauw: RefCell>, + pub statics_to_rauw: RefCell, Value<'ll>)>>, /// Statics that will be placed in the llvm.used variable /// See for details - pub used_statics: Vec<&'ll Value>, + pub used_statics: Vec>, /// Statics that will be placed in the llvm.compiler.used variable /// See for details - pub compiler_used_statics: RefCell>, + pub compiler_used_statics: RefCell>>, /// Mapping of non-scalar types to llvm types. pub type_lowering: RefCell, Option), Type<'ll>>>, @@ -137,11 +137,11 @@ pub(crate) struct FullCx<'ll, 'tcx> { pub dbg_cx: Option>, pub sanitizer_ignorelist: Option, - eh_personality: Cell>, - pub rust_try_fn: Cell, &'ll Value)>>, + eh_personality: Cell>>, + pub rust_try_fn: Cell, Value<'ll>)>>, intrinsics: - RefCell, SmallVec<[Type<'ll>; 2]>), (Type<'ll>, &'ll Value)>>, + RefCell, SmallVec<[Type<'ll>; 2]>), (Type<'ll>, Value<'ll>)>>, /// A counter that is used for generating local symbol names local_gen_sym_counter: Cell, @@ -153,16 +153,16 @@ pub(crate) struct FullCx<'ll, 'tcx> { /// different type and clear the symbol name of the original global. /// `global_asm!` needs to be able to find this new global so that it can /// compute the correct mangled symbol name to insert into the asm. - pub renamed_statics: RefCell>, + pub renamed_statics: RefCell>>, /// Cached Objective-C class type pub objc_class_t: Cell>>, /// Cache of Objective-C class references - pub objc_classrefs: RefCell>, + pub objc_classrefs: RefCell>>, /// Cache of Objective-C selector references - pub objc_selrefs: RefCell>, + pub objc_selrefs: RefCell>>, /// Globals shared by the offloading runtime pub offload_globals: RefCell>>, @@ -739,7 +739,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { ) } - pub(crate) fn statics_to_rauw(&self) -> &RefCell> { + pub(crate) fn statics_to_rauw(&self) -> &RefCell, Value<'ll>)>> { &self.statics_to_rauw } @@ -750,7 +750,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { self.coverage_cx.as_ref().expect("only called when coverage instrumentation is enabled") } - pub(crate) fn create_used_variable_impl(&self, name: &'static CStr, values: &[&'ll Value]) { + pub(crate) fn create_used_variable_impl(&self, name: &'static CStr, values: &[Value<'ll>]) { let array = self.const_array(self.type_ptr(), values); let g = llvm::add_global(self.llmod, self.val_ty(array), name); @@ -875,10 +875,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { } } impl<'ll> SimpleCx<'ll> { - pub(crate) fn get_type_of_global(&self, val: &'ll Value) -> Type<'ll> { + pub(crate) fn get_type_of_global(&self, val: Value<'ll>) -> Type<'ll> { unsafe { llvm::LLVMGlobalGetValueType(val) } } - pub(crate) fn val_ty(&self, v: &'ll Value) -> Type<'ll> { + pub(crate) fn val_ty(&self, v: Value<'ll>) -> Type<'ll> { common::val_ty(v) } } @@ -894,27 +894,27 @@ impl<'ll> SimpleCx<'ll> { } impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { - pub(crate) fn get_metadata_value(&self, metadata: &'ll Metadata) -> &'ll Value { + pub(crate) fn get_metadata_value(&self, metadata: &'ll Metadata) -> Value<'ll> { llvm::LLVMMetadataAsValue(self.llcx(), metadata) } - pub(crate) fn get_const_int(&self, ty: Type<'ll>, val: u64) -> &'ll Value { + pub(crate) fn get_const_int(&self, ty: Type<'ll>, val: u64) -> Value<'ll> { unsafe { llvm::LLVMConstInt(ty, val, llvm::FALSE) } } - pub(crate) fn get_const_i64(&self, n: u64) -> &'ll Value { + pub(crate) fn get_const_i64(&self, n: u64) -> Value<'ll> { self.get_const_int(self.type_i64(), n) } - pub(crate) fn get_const_i32(&self, n: u64) -> &'ll Value { + pub(crate) fn get_const_i32(&self, n: u64) -> Value<'ll> { self.get_const_int(self.type_i32(), n) } - pub(crate) fn get_const_i16(&self, n: u64) -> &'ll Value { + pub(crate) fn get_const_i16(&self, n: u64) -> Value<'ll> { self.get_const_int(self.type_i16(), n) } - pub(crate) fn get_const_i8(&self, n: u64) -> &'ll Value { + pub(crate) fn get_const_i8(&self, n: u64) -> Value<'ll> { self.get_const_int(self.type_i8(), n) } @@ -926,7 +926,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { unsafe { llvm::LLVMMDStringInContext2(self.llcx(), name.as_ptr(), name.len()) } } - pub(crate) fn get_functions(&self) -> Vec<&'ll Value> { + pub(crate) fn get_functions(&self) -> Vec> { let mut functions = vec![]; let mut func = unsafe { llvm::LLVMGetFirstFunction(self.llmod()) }; while let Some(f) = func { @@ -940,7 +940,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn vtables( &self, - ) -> &RefCell, Option>), &'ll Value>> { + ) -> &RefCell, Option>), Value<'ll>>> { &self.vtables } @@ -948,12 +948,12 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { &self, ty: Ty<'tcx>, poly_trait_ref: Option>, - vtable: &'ll Value, + vtable: Value<'ll>, ) { apply_vcall_visibility_metadata(self, ty, poly_trait_ref, vtable); } - fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value { + fn get_fn(&self, instance: Instance<'tcx>) -> Value<'ll> { get_fn(self, instance) } @@ -961,7 +961,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { &self, instance: Instance<'tcx>, pointer_auth_schema: Option<&PointerAuthSchema>, - ) -> &'ll Value { + ) -> Value<'ll> { // When pointer authentication metadata is provided, `get_fn_addr` will // attempt to sign the pointer using LLVM's `ConstPtrAuth` constant // expression. @@ -981,7 +981,7 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { } } - fn eh_personality(&self) -> &'ll Value { + fn eh_personality(&self) -> Value<'ll> { // The exception handling personality function. // // If our compilation unit has the `eh_personality` lang item somewhere @@ -1058,20 +1058,20 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { self.tcx.sess } - fn set_frame_pointer_type(&self, llfn: &'ll Value) { + fn set_frame_pointer_type(&self, llfn: Value<'ll>) { if let Some(attr) = attributes::frame_pointer_type_attr(self, self.sess()) { attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[attr]); } } - fn apply_target_cpu_attr(&self, llfn: &'ll Value) { + fn apply_target_cpu_attr(&self, llfn: Value<'ll>) { let mut attrs = SmallVec::<[_; 2]>::new(); attrs.push(attributes::target_cpu_attr(self, self.sess())); attrs.extend(attributes::tune_cpu_attr(self, self.sess())); attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs); } - fn apply_default_optimisation_attrs(&self, llfn: &'ll Value) { + fn apply_default_optimisation_attrs(&self, llfn: Value<'ll>) { let attrs = attributes::default_optimisation_attrs(self, self.sess()); attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs); } @@ -1108,7 +1108,7 @@ impl<'ll> CodegenCx<'ll, '_> { &self, base_name: Cow<'static, str>, type_params: &[Type<'ll>], - ) -> (Type<'ll>, &'ll Value) { + ) -> (Type<'ll>, Value<'ll>) { *self .intrinsics .borrow_mut() @@ -1122,7 +1122,7 @@ impl<'ll> CodegenCx<'ll, '_> { &self, base_name: &str, type_params: &[Type<'ll>], - ) -> (Type<'ll>, &'ll Value) { + ) -> (Type<'ll>, Value<'ll>) { match base_name { // This isn't an "LLVM intrinsic", but LLVM's optimization passes // recognize it like one (including turning it into `bcmp` sometimes) @@ -1204,12 +1204,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { } /// A wrapper for [`llvm::LLVMSetMetadata`], but it takes `Metadata` as a parameter instead of `Value`. - pub(crate) fn set_metadata<'a>( - &self, - val: &'a Value, - kind_id: MetadataKindId, - md: &'ll Metadata, - ) { + pub(crate) fn set_metadata(&self, val: Value<'ll>, kind_id: MetadataKindId, md: &'ll Metadata) { let node = self.get_metadata_value(md); llvm::LLVMSetMetadata(val, kind_id, node); } @@ -1220,7 +1215,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// - `LLVMSetMetadata` (to set that node as metadata of `kind_id` for `instruction`) pub(crate) fn set_metadata_node( &self, - instruction: &'ll Value, + instruction: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], ) -> &'ll Metadata { @@ -1249,7 +1244,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// - `LLVMGlobalAddMetadata` (to set that node as metadata of `kind_id` for `global`) pub(crate) fn global_add_metadata_node( &self, - global: &'ll Value, + global: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], ) { @@ -1262,7 +1257,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// - `LLVMGlobalSetMetadata` (to set that node as metadata of `kind_id` for `global`) pub(crate) fn global_set_metadata_node( &self, - global: &'ll Value, + global: Value<'ll>, kind_id: MetadataKindId, md_list: &[&'ll Metadata], ) { diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs index 92abe16eb4109..4467204abc7cd 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs @@ -27,9 +27,9 @@ pub(crate) fn covfun_section_name<'ll>(llmod: llvm::Module<'ll>) -> CString { } pub(crate) fn create_pgo_func_name_var<'ll>( - llfn: &'ll llvm::Value, + llfn: llvm::Value<'ll>, mangled_fn_name: &str, -) -> &'ll llvm::Value { +) -> llvm::Value<'ll> { unsafe { llvm::LLVMRustCoverageCreatePGOFuncNameVar( llfn, diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index b33e6dbb3409a..e677b5fa62250 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -26,7 +26,7 @@ pub(crate) struct CguCoverageContext<'ll, 'tcx> { /// emitting covfun records. Every covfun record holds a hash of its /// symbol name, and `llvm-cov` will exit fatally if it can't resolve that /// hash back to an entry in the binary's `__llvm_prf_names` linker section. - pub(crate) pgo_func_name_var_map: RefCell, &'ll llvm::Value>>, + pub(crate) pgo_func_name_var_map: RefCell, llvm::Value<'ll>>>, covfun_section_name: OnceCell, } @@ -71,10 +71,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { /// /// This has the side-effect of causing coverage codegen to consider this /// function "used", making it eligible to emit an associated covfun record. - fn ensure_pgo_func_name_var(&self, instance: Instance<'tcx>) -> &'ll llvm::Value { + fn ensure_pgo_func_name_var(&self, instance: Instance<'tcx>) -> llvm::Value<'ll> { debug!("getting pgo_func_name_var for instance={:?}", instance); let mut pgo_func_name_var_map = self.coverage_cx().pgo_func_name_var_map.borrow_mut(); - pgo_func_name_var_map.entry(instance).or_insert_with(|| { + *pgo_func_name_var_map.entry(instance).or_insert_with(|| { let llfn = self.get_fn(instance); let mangled_fn_name: &str = self.tcx.symbol_name(instance).name; llvm_cov::create_pgo_func_name_var(llfn, mangled_fn_name) diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs b/compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs index 9237c8be87473..c6cd73673de67 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/di_builder.rs @@ -52,7 +52,7 @@ pub(crate) trait DIBuilderExt<'ll> { line_number: c_uint, ty: &'ll llvm::Metadata, is_local_to_unit: bool, - val: &'ll llvm::Value, + val: llvm::Value<'ll>, decl: Option<&'ll llvm::Metadata>, align: Option, ) -> &'ll llvm::Metadata { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index 7665c824f1c48..c5c535ff26e59 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs @@ -28,7 +28,7 @@ pub(crate) fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Buil /// section. pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>( cx: &CodegenCx<'ll, '_>, -) -> &'ll Value { +) -> Value<'ll> { let c_section_var_name = c"__rustc_debug_gdb_scripts_section__"; let section_var_name = c_section_var_name.to_str().unwrap(); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 585d0b20420a4..ff0b924f5701e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1513,7 +1513,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>( pub(crate) fn build_global_var_di_node<'ll>( cx: &CodegenCx<'ll, '_>, def_id: DefId, - global: &'ll Value, + global: Value<'ll>, ) { if cx.dbg_cx.is_none() { return; @@ -1722,7 +1722,7 @@ fn build_unsafe_binder_type_di_node<'ll, 'tcx>( /// global variable (which is simply returned), or an addrspacecast constant expression. /// If the given value is an addrspacecast, the cast is removed and the global variable behind /// the cast is returned. -fn find_vtable_behind_cast<'ll>(vtable: &'ll Value) -> &'ll Value { +fn find_vtable_behind_cast<'ll>(vtable: Value<'ll>) -> Value<'ll> { // The vtable is a global variable, which may be behind an addrspacecast. unsafe { if let Some(c) = llvm::LLVMIsAConstantExpr(vtable) { @@ -1738,7 +1738,7 @@ pub(crate) fn apply_vcall_visibility_metadata<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, trait_ref: Option>, - vtable: &'ll Value, + vtable: Value<'ll>, ) { // FIXME(flip1995): The virtual function elimination optimization only works with full LTO in // LLVM at the moment. @@ -1803,7 +1803,7 @@ pub(crate) fn create_vtable_di_node<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, poly_trait_ref: Option>, - vtable: &'ll Value, + vtable: Value<'ll>, ) { if cx.dbg_cx.is_none() { return; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index fe7f38fb195bc..100037d55b79d 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -982,7 +982,7 @@ fn create_static_member_type<'ll>( line_number: c_uint, ty: &'ll llvm::Metadata, flags: DIFlags, - value: Option<&'ll llvm::Value>, + value: Option>, align: Align, ) -> &'ll llvm::Metadata { unsafe { diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index 5fe5ee3e92fea..687d3bbd6b780 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -130,7 +130,7 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { &mut self, instance: Instance<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, - maybe_definition_llfn: Option<&'ll Value>, + maybe_definition_llfn: Option>, ) -> &'ll DIScope { let tcx = self.tcx; @@ -590,7 +590,7 @@ impl<'ll, 'tcx> DebugInfoBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { gdb::insert_reference_to_gdb_debug_scripts_section_global(self) } - fn set_var_name(&mut self, value: &'ll Value, name: &str) { + fn set_var_name(&mut self, value: Value<'ll>, name: &str) { // Avoid wasting time if LLVM value names aren't even enabled. if self.sess().fewer_names() { return; diff --git a/compiler/rustc_codegen_llvm/src/declare.rs b/compiler/rustc_codegen_llvm/src/declare.rs index a0c9faf47a1a5..e6fef61285c6b 100644 --- a/compiler/rustc_codegen_llvm/src/declare.rs +++ b/compiler/rustc_codegen_llvm/src/declare.rs @@ -40,7 +40,7 @@ pub(crate) fn declare_simple_fn<'ll>( unnamed: llvm::UnnamedAddr, visibility: llvm::Visibility, ty: Type<'ll>, -) -> &'ll Value { +) -> Value<'ll> { debug!("declare_simple_fn(name={:?}, ty={:?})", name, ty); let llfn = unsafe { llvm::LLVMGetOrInsertFunction(cx.llmod, name.as_ptr(), name.len(), ty) }; @@ -62,7 +62,7 @@ pub(crate) fn declare_raw_fn<'ll, 'tcx>( unnamed: llvm::UnnamedAddr, visibility: llvm::Visibility, ty: Type<'ll>, -) -> &'ll Value { +) -> Value<'ll> { debug!("declare_raw_fn(name={:?}, ty={:?})", name, ty); let llfn = declare_simple_fn(cx, name, callconv, unnamed, visibility, ty); @@ -91,7 +91,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// /// If there’s a value with the same name already declared, the function will /// return its Value instead. - pub(crate) fn declare_global(&self, name: &str, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn declare_global(&self, name: &str, ty: Type<'ll>) -> Value<'ll> { debug!("declare_global(name={:?})", name); unsafe { llvm::LLVMRustGetOrInsertGlobal((**self).borrow().llmod, name.as_ptr(), name.len(), ty) @@ -107,7 +107,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { name: &str, ty: Type<'ll>, addr_space: AddressSpace, - ) -> &'ll Value { + ) -> Value<'ll> { debug!("declare_global(name={name:?}, addrspace={addr_space:?})"); unsafe { llvm::LLVMRustGetOrInsertGlobalInAddrspace( @@ -134,7 +134,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { name: &str, unnamed: llvm::UnnamedAddr, fn_type: Type<'ll>, - ) -> &'ll Value { + ) -> Value<'ll> { // Visibility should always be default for declarations, otherwise the linker may report an // error. declare_raw_fn(self, name, llvm::CCallConv, unnamed, Visibility::Default, fn_type) @@ -153,7 +153,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { callconv: llvm::CallConv, unnamed: llvm::UnnamedAddr, fn_type: Type<'ll>, - ) -> &'ll Value { + ) -> Value<'ll> { let visibility = Visibility::from_generic(self.tcx.sess.default_visibility()); declare_raw_fn(self, name, callconv, unnamed, visibility, fn_type) } @@ -167,7 +167,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, instance: Option>, - ) -> &'ll Value { + ) -> Value<'ll> { debug!("declare_rust_fn(name={:?}, fn_abi={:?})", name, fn_abi); // Some calling conventions (such as fastcall and vectorcall) decorate // symbols with the argument byte count. Use rustc's original argument @@ -256,7 +256,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { /// return `None` if the name already has a definition associated with it. In that /// case an error should be reported to the user, because it usually happens due /// to user’s fault (e.g., misuse of `#[no_mangle]` or `#[export_name]` attributes). - pub(crate) fn define_global(&self, name: &str, ty: Type<'ll>) -> Option<&'ll Value> { + pub(crate) fn define_global(&self, name: &str, ty: Type<'ll>) -> Option> { if self.get_defined_value(name).is_some() { None } else { @@ -265,14 +265,14 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { } /// Gets declared value by name. - pub(crate) fn get_declared_value(&self, name: &str) -> Option<&'ll Value> { + pub(crate) fn get_declared_value(&self, name: &str) -> Option> { debug!("get_declared_value(name={:?})", name); unsafe { llvm::LLVMRustGetNamedValue(self.llmod(), name.as_ptr(), name.len()) } } /// Gets defined or externally defined (AvailableExternally linkage) value by /// name. - pub(crate) fn get_defined_value(&self, name: &str) -> Option<&'ll Value> { + pub(crate) fn get_defined_value(&self, name: &str) -> Option> { self.get_declared_value(name).and_then(|val| { let declaration = llvm::is_declaration(val); if !declaration { Some(val) } else { None } diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index d163b7304fbdd..c499cfc811a22 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -51,8 +51,8 @@ use crate::va_arg::emit_va_arg; fn call_simple_intrinsic<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, name: Symbol, - args: &[OperandRef<'tcx, &'ll Value>], -) -> Option<&'ll Value> { + args: &[OperandRef<'tcx, Value<'ll>>], +) -> Option> { let llvm_version = crate::llvm_util::get_version(); // minimum/maximum were broken for f64/f128 before // . @@ -85,7 +85,7 @@ fn call_simple_intrinsic<'ll, 'tcx>( } impl<'ll, 'tcx> Builder<'_, 'll, 'tcx> { - fn black_box(&mut self, result: PlaceRef<'tcx, &'ll Value>, span: Span) { + fn black_box(&mut self, result: PlaceRef<'tcx, Value<'ll>>, span: Span) { let result_val_span = [result.val.llval]; // We need to "use" the argument in some way LLVM can't introspect, and on // targets that support it we can typically leverage inline assembly to do @@ -124,11 +124,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn codegen_intrinsic_call( &mut self, instance: ty::Instance<'tcx>, - args: &[OperandRef<'tcx, &'ll Value>], + args: &[OperandRef<'tcx, Value<'ll>>], result_layout: ty::layout::TyAndLayout<'tcx>, - result_place: Option>, + result_place: Option>>, span: Span, - ) -> IntrinsicResult<'tcx, &'ll Value> { + ) -> IntrinsicResult<'tcx, Value<'ll>> { let tcx = self.tcx; let llvm_version = crate::llvm_util::get_version(); @@ -209,7 +209,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { assert_eq!(args[1].layout, args[2].layout); let select = |bx: &mut Self, true_val, false_val| { let result = bx.select(cond, true_val, false_val); - bx.set_unpredictable(&result); + bx.set_unpredictable(result); result }; match (args[1].val, args[2].val) { @@ -952,13 +952,13 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { debug!("call intrinsic {:?} with args ({:?})", instance, llargs); for (dest_ty, arg) in iter::zip(self.func_params_types(fn_ty), &mut llargs) { - let src_ty = self.val_ty(arg); + let src_ty = self.val_ty(*arg); assert!( can_autocast(self, src_ty, dest_ty), "Cannot match `{dest_ty:?}` (expected) with {src_ty:?} (found) in `{fn_ptr:?}" ); - *arg = autocast(self, arg, src_ty, dest_ty); + *arg = autocast(self, *arg, src_ty, dest_ty); } let llret = unsafe { @@ -1013,7 +1013,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { fn type_checked_load( &mut self, - llvtable: &'ll Value, + llvtable: Value<'ll>, vtable_byte_offset: u64, typeid: &[u8], ) -> Self::Value { @@ -1028,7 +1028,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { self.extract_value(type_checked_load, 0) } - fn va_start(&mut self, va_list: &'ll Value) { + fn va_start(&mut self, va_list: Value<'ll>) { self.call_intrinsic("llvm.va_start", &[self.val_ty(va_list)], &[va_list]); } @@ -1119,10 +1119,10 @@ fn can_autocast<'ll>(cx: &CodegenCx<'ll, '_>, rust_ty: Type<'ll>, llvm_ty: Type< fn autocast<'ll>( bx: &mut Builder<'_, 'll, '_>, - val: &'ll Value, + val: Value<'ll>, src_ty: Type<'ll>, dest_ty: Type<'ll>, -) -> &'ll Value { +) -> Value<'ll> { if src_ty == dest_ty { return val; } @@ -1202,7 +1202,7 @@ fn intrinsic_fn<'ll, 'tcx>( rust_return_ty: Type<'ll>, rust_argument_tys: Vec>, instance: ty::Instance<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let tcx = bx.tcx; let rust_fn_ty = bx.type_func(&rust_argument_tys, rust_return_ty); @@ -1301,10 +1301,10 @@ fn intrinsic_fn<'ll, 'tcx>( fn catch_unwind_intrinsic<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - try_func: &'ll Value, - data: &'ll Value, - catch_func: &'ll Value, -) -> &'ll Value { + try_func: Value<'ll>, + data: Value<'ll>, + catch_func: Value<'ll>, +) -> Value<'ll> { if !bx.sess().panic_strategy().unwinds() { let try_func_ty = bx.type_func(&[bx.type_ptr()], bx.type_void()); bx.call(try_func_ty, None, None, try_func, ReturnSlot::Direct, &[data], None, None); @@ -1329,10 +1329,10 @@ fn catch_unwind_intrinsic<'ll, 'tcx>( // as the old ones are still more optimized. fn codegen_msvc_try<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - try_func: &'ll Value, - data: &'ll Value, - catch_func: &'ll Value, -) -> &'ll Value { + try_func: Value<'ll>, + data: Value<'ll>, + catch_func: Value<'ll>, +) -> Value<'ll> { let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| { bx.set_personality_fn(bx.eh_personality()); @@ -1515,10 +1515,10 @@ fn codegen_msvc_try<'ll, 'tcx>( // WASM's definition of the `rust_try` function. fn codegen_wasm_try<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - try_func: &'ll Value, - data: &'ll Value, - catch_func: &'ll Value, -) -> &'ll Value { + try_func: Value<'ll>, + data: Value<'ll>, + catch_func: Value<'ll>, +) -> Value<'ll> { let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| { bx.set_personality_fn(bx.eh_personality()); @@ -1626,10 +1626,10 @@ fn codegen_wasm_try<'ll, 'tcx>( // the right personality function. fn codegen_gnu_try<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - try_func: &'ll Value, - data: &'ll Value, - catch_func: &'ll Value, -) -> &'ll Value { + try_func: Value<'ll>, + data: Value<'ll>, + catch_func: Value<'ll>, +) -> Value<'ll> { let (llty, llfn) = get_rust_try_fn(bx, &mut |mut bx| { // Codegens the shims described above: // @@ -1705,7 +1705,7 @@ fn gen_fn<'a, 'll, 'tcx>( name: &str, rust_fn_sig: ty::PolyFnSig<'tcx>, codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>), -) -> (Type<'ll>, &'ll Value) { +) -> (Type<'ll>, Value<'ll>) { let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty()); let llty = fn_abi.llvm_type(cx); let llfn = cx.declare_fn(name, fn_abi, None); @@ -1727,7 +1727,7 @@ fn gen_fn<'a, 'll, 'tcx>( fn get_rust_try_fn<'a, 'll, 'tcx>( cx: &'a CodegenCx<'ll, 'tcx>, codegen: &mut dyn FnMut(Builder<'a, 'll, 'tcx>), -) -> (Type<'ll>, &'ll Value) { +) -> (Type<'ll>, Value<'ll>) { if let Some(llfn) = cx.rust_try_fn.get() { return llfn; } @@ -1769,9 +1769,9 @@ fn get_rust_try_fn<'a, 'll, 'tcx>( fn codegen_retag_inner<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, name: &'static str, - ptr: &'ll Value, - info: &RetagInfo<&'ll Value>, -) -> &'ll Value { + ptr: Value<'ll>, + info: &RetagInfo>, +) -> Value<'ll> { let size = bx.const_usize(info.size.bytes()); let perms = bx.const_u8(info.flags.bits()); @@ -1787,10 +1787,10 @@ fn codegen_retag_inner<'ll, 'tcx>( fn codegen_autodiff<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, instance: ty::Instance<'tcx>, - args: &[OperandRef<'tcx, &'ll Value>], + args: &[OperandRef<'tcx, Value<'ll>>], result_layout: ty::layout::TyAndLayout<'tcx>, - result_place: Option>, -) -> IntrinsicResult<'tcx, &'ll Value> { + result_place: Option>>, +) -> IntrinsicResult<'tcx, Value<'ll>> { let tcx = bx.tcx; if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) { let _ = tcx.dcx().emit_err(AutoDiffWithoutEnable); @@ -1877,7 +1877,7 @@ fn codegen_offload<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, tcx: TyCtxt<'tcx>, instance: ty::Instance<'tcx>, - args: &[OperandRef<'tcx, &'ll Value>], + args: &[OperandRef<'tcx, Value<'ll>>], ) { let cx = bx.cx; let fn_args = instance.args; @@ -1949,16 +1949,16 @@ fn codegen_offload<'ll, 'tcx>( &metadata, offload_globals, &offload_dims, - &dyn_cache, - &device_id, + dyn_cache, + device_id, ); } fn get_args_from_tuple<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - tuple_op: OperandRef<'tcx, &'ll Value>, + tuple_op: OperandRef<'tcx, Value<'ll>>, fn_instance: Instance<'tcx>, -) -> Vec<&'ll Value> { +) -> Vec> { let cx = bx.cx; let fn_abi = cx.fn_abi_of_instance(fn_instance, ty::List::empty()); @@ -2011,11 +2011,11 @@ fn generic_simd_intrinsic<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, name: Symbol, fn_args: GenericArgs<'tcx>, - args: &[OperandRef<'tcx, &'ll Value>], + args: &[OperandRef<'tcx, Value<'ll>>], ret_ty: Ty<'tcx>, llret_ty: Type<'ll>, span: Span, -) -> Result<&'ll Value, ErrorGuaranteed> { +) -> Result, ErrorGuaranteed> { macro_rules! return_error { ($diag: expr) => {{ let err = bx.sess().dcx().emit_err($diag); @@ -2087,10 +2087,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>( /// efficiently converted to an all ones / all zeroes mask by comparing whether each element is negative. fn vector_mask_to_bitmask<'a, 'll, 'tcx>( bx: &mut Builder<'a, 'll, 'tcx>, - i_xn: &'ll Value, + i_xn: Value<'ll>, in_elem_bitwidth: u64, in_len: u64, - ) -> &'ll Value { + ) -> Value<'ll> { // Shift the MSB to the right by "in_elem_bitwidth - 1" into the first bit position. let shift_idx = bx.cx.const_int(bx.type_ix(in_elem_bitwidth), (in_elem_bitwidth - 1) as _); let shift_indices = vec![shift_idx; in_len as _]; @@ -2463,8 +2463,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>( in_len: u64, bx: &mut Builder<'_, 'll, 'tcx>, span: Span, - args: &[OperandRef<'tcx, &'ll Value>], - ) -> Result<&'ll Value, ErrorGuaranteed> { + args: &[OperandRef<'tcx, Value<'ll>>], + ) -> Result, ErrorGuaranteed> { macro_rules! return_error { ($diag: expr) => {{ let err = bx.sess().dcx().emit_err($diag); diff --git a/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs b/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs index 978a718cda590..8060308b5d34e 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs @@ -23,7 +23,7 @@ pub(crate) struct OptimizationDiagnostic<'ll> { pub kind: OptimizationDiagnosticKind, pub pass_name: String, #[expect(dead_code)] - pub function: &'ll Value, + pub function: Value<'ll>, pub line: c_uint, pub column: c_uint, pub filename: String, diff --git a/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs index 549cf5be70387..46edf657a4d24 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs @@ -36,53 +36,60 @@ pub(crate) struct TypeTree { #[link(name = "llvm-wrapper", kind = "static")] unsafe extern "C" { // Enzyme - pub(crate) safe fn LLVMRustHasMetadata(I: &Value, KindID: MetadataKindId) -> bool; - pub(crate) fn LLVMRustEraseInstUntilInclusive(BB: &BasicBlock, I: &Value); - pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>; - pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>; - pub(crate) fn LLVMRustEraseInstFromParent(V: &Value); - pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value; - pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool; - pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool; + pub(crate) safe fn LLVMRustHasMetadata<'ll>(I: Value<'ll>, KindID: MetadataKindId) -> bool; + pub(crate) fn LLVMRustEraseInstUntilInclusive<'ll>(BB: &'ll BasicBlock, I: Value<'ll>); + pub(crate) fn LLVMRustGetLastInstruction<'ll>(BB: &'ll BasicBlock) -> Option>; + pub(crate) fn LLVMRustDIGetInstMetadata<'ll>(I: Value<'ll>) -> Option<&'ll Metadata>; + pub(crate) fn LLVMRustEraseInstFromParent<'ll>(V: Value<'ll>); + pub(crate) fn LLVMRustGetTerminator<'ll>(B: &'ll BasicBlock) -> Value<'ll>; + pub(crate) fn LLVMRustVerifyFunction<'ll>( + V: Value<'ll>, + action: LLVMRustVerifierFailureAction, + ) -> Bool; + pub(crate) fn LLVMRustHasAttributeAtIndex<'ll>( + V: Value<'ll>, + i: c_uint, + Kind: AttributeKind, + ) -> bool; pub(crate) fn LLVMRustGetArrayNumElements<'ll>(Ty: Type<'ll>) -> u64; - pub(crate) fn LLVMRustHasFnAttribute( - F: &Value, + pub(crate) fn LLVMRustHasFnAttribute<'ll>( + F: Value<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: libc::size_t, ) -> bool; - pub(crate) fn LLVMRustRemoveFnAttribute( - F: &Value, + pub(crate) fn LLVMRustRemoveFnAttribute<'ll>( + F: Value<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: libc::size_t, ); - pub(crate) fn LLVMGetFirstFunction<'ll>(M: Module<'ll>) -> Option<&'ll Value>; - pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>; - pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex( - Fn: &Value, + pub(crate) fn LLVMGetFirstFunction<'ll>(M: Module<'ll>) -> Option>; + pub(crate) fn LLVMGetNextFunction<'ll>(Fn: Value<'ll>) -> Option>; + pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex<'ll>( + Fn: Value<'ll>, index: c_uint, kind: AttributeKind, ); - pub(crate) fn LLVMRustPositionBefore<'a>(B: &'a Builder<'_>, I: &'a Value); - pub(crate) fn LLVMRustPositionAfter<'a>(B: &'a Builder<'_>, I: &'a Value); - pub(crate) fn LLVMRustGetFunctionCall( - F: &Value, + pub(crate) fn LLVMRustPositionBefore<'ll>(B: &Builder<'ll>, I: Value<'ll>); + pub(crate) fn LLVMRustPositionAfter<'ll>(B: &Builder<'ll>, I: Value<'ll>); + pub(crate) fn LLVMRustGetFunctionCall<'ll>( + F: Value<'ll>, name: *const c_char, NameLen: libc::size_t, - ) -> Option<&Value>; + ) -> Option>; - pub(crate) safe fn LLVMRustIsCall(V: &Value) -> bool; + pub(crate) safe fn LLVMRustIsCall<'ll>(V: Value<'ll>) -> bool; } unsafe extern "C" { // Enzyme pub(crate) fn LLVMDumpModule<'ll>(M: Module<'ll>); - pub(crate) fn LLVMDumpValue(V: &Value); - pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint; - pub(crate) fn LLVMGetParams(Fnc: &Value, params: *mut &Value); + pub(crate) fn LLVMDumpValue<'ll>(V: Value<'ll>); + pub(crate) fn LLVMGetFunctionCallConv<'ll>(F: Value<'ll>) -> c_uint; + pub(crate) fn LLVMGetParams<'ll>(Fnc: Value<'ll>, params: *mut Value<'ll>); pub(crate) fn LLVMGetNamedFunction<'ll>( M: Module<'ll>, Name: *const c_char, - ) -> Option<&'ll Value>; + ) -> Option>; } #[repr(C)] diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index ecc4fe510370c..c53dfe6fe5d05 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -21,7 +21,7 @@ use bitflags::bitflags; use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t}; pub(crate) use self::branded::{ - Context, ContextRaw, Module, ModuleRaw, Type, wrap_llcx, wrap_llmod, + Context, ContextRaw, Module, ModuleRaw, Type, Value, wrap_llcx, wrap_llmod, }; use super::RustString; use super::debuginfo::{ @@ -707,7 +707,6 @@ struct InvariantOpaque<'a> { // Opaque pointer types unsafe extern "C" { - pub(crate) type Value; pub(crate) type ConstantInt; pub(crate) type Attribute; pub(crate) type Metadata; @@ -929,7 +928,7 @@ unsafe extern "C" { IsAlignStack: llvm::Bool, Dialect: AsmDialect, CanThrow: llvm::Bool, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) safe fn LLVMGetTypeKind<'ll>(Ty: Type<'ll>) -> RawEnum; @@ -992,35 +991,39 @@ unsafe extern "C" { pub(crate) fn LLVMVoidTypeInContext<'ll>(C: Context<'ll>) -> Type<'ll>; // Operations on all values - pub(crate) fn LLVMTypeOf<'ll>(Val: &'ll Value) -> Type<'ll>; - pub(crate) fn LLVMGetValueName2(Val: &Value, Length: *mut size_t) -> *const c_char; - pub(crate) fn LLVMSetValueName2( - Val: &Value, + pub(crate) fn LLVMTypeOf<'ll>(Val: Value<'ll>) -> Type<'ll>; + pub(crate) fn LLVMGetValueName2<'ll>(Val: Value<'ll>, Length: *mut size_t) -> *const c_char; + pub(crate) fn LLVMSetValueName2<'ll>( + Val: Value<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, ); - pub(crate) fn LLVMReplaceAllUsesWith<'a>(OldVal: &'a Value, NewVal: &'a Value); - pub(crate) safe fn LLVMGetMetadata<'a>( - Val: &'a Value, + pub(crate) fn LLVMReplaceAllUsesWith<'ll>(OldVal: Value<'ll>, NewVal: Value<'ll>); + pub(crate) safe fn LLVMGetMetadata<'ll>( + Val: Value<'ll>, KindID: MetadataKindId, - ) -> Option<&'a Value>; - pub(crate) safe fn LLVMSetMetadata<'a>(Val: &'a Value, KindID: MetadataKindId, Node: &'a Value); - pub(crate) fn LLVMGlobalSetMetadata<'a>( - Val: &'a Value, + ) -> Option>; + pub(crate) safe fn LLVMSetMetadata<'ll>( + Val: Value<'ll>, KindID: MetadataKindId, - Metadata: &'a Metadata, + Node: Value<'ll>, + ); + pub(crate) fn LLVMGlobalSetMetadata<'ll>( + Val: Value<'ll>, + KindID: MetadataKindId, + Metadata: &'ll Metadata, ); pub(crate) fn LLVMGlobalAddMetadata<'ll>( - Global: &'ll Value, + Global: Value<'ll>, Kind: MetadataKindId, MD: &'ll Metadata, ); - pub(crate) safe fn LLVMValueAsMetadata(Node: &Value) -> &Metadata; + pub(crate) safe fn LLVMValueAsMetadata<'ll>(Node: Value<'ll>) -> &'ll Metadata; // Operations on constants of any type - pub(crate) fn LLVMConstNull<'ll>(Ty: Type<'ll>) -> &'ll Value; - pub(crate) fn LLVMGetUndef<'ll>(Ty: Type<'ll>) -> &'ll Value; - pub(crate) fn LLVMGetPoison<'ll>(Ty: Type<'ll>) -> &'ll Value; + pub(crate) fn LLVMConstNull<'ll>(Ty: Type<'ll>) -> Value<'ll>; + pub(crate) fn LLVMGetUndef<'ll>(Ty: Type<'ll>) -> Value<'ll>; + pub(crate) fn LLVMGetPoison<'ll>(Ty: Type<'ll>) -> Value<'ll>; // Operations on metadata pub(crate) fn LLVMMDStringInContext2<'ll>( @@ -1036,113 +1039,123 @@ unsafe extern "C" { pub(crate) fn LLVMAddNamedMetadataOperand<'ll>( M: Module<'ll>, Name: *const c_char, - Val: &'ll Value, + Val: Value<'ll>, + ); + pub(crate) fn LLVMReplaceMDNodeOperandWith<'ll>( + Val: Value<'ll>, + index: u32, + replacement: &'ll Metadata, ); - pub(crate) fn LLVMReplaceMDNodeOperandWith(Val: &Value, index: u32, replacement: &Metadata); // Operations on scalar constants pub(crate) fn LLVMConstInt<'ll>( IntTy: Type<'ll>, N: c_ulonglong, SignExtend: Bool, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMConstIntOfArbitraryPrecision<'ll>( IntTy: Type<'ll>, Wn: c_uint, Ws: *const u64, - ) -> &'ll Value; - pub(crate) fn LLVMConstReal<'ll>(RealTy: Type<'ll>, N: f64) -> &'ll Value; + ) -> Value<'ll>; + pub(crate) fn LLVMConstReal<'ll>(RealTy: Type<'ll>, N: f64) -> Value<'ll>; // Operations on composite constants pub(crate) fn LLVMConstArray2<'ll>( ElementTy: Type<'ll>, - ConstantVals: *const &'ll Value, + ConstantVals: *const Value<'ll>, Length: u64, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMArrayType2<'ll>(ElementType: Type<'ll>, ElementCount: u64) -> Type<'ll>; pub(crate) fn LLVMConstStringInContext2<'ll>( C: Context<'ll>, Str: *const c_uchar, // See "PTR_LEN_STR". Length: size_t, DontNullTerminate: Bool, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMConstStructInContext<'ll>( C: Context<'ll>, - ConstantVals: *const &'ll Value, + ConstantVals: *const Value<'ll>, Count: c_uint, Packed: Bool, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMConstNamedStruct<'ll>( StructTy: Type<'ll>, - ConstantVals: *const &'ll Value, + ConstantVals: *const Value<'ll>, Count: c_uint, - ) -> &'ll Value; - pub(crate) fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value; + ) -> Value<'ll>; + pub(crate) fn LLVMConstVector<'ll>( + ScalarConstantVals: *const Value<'ll>, + Size: c_uint, + ) -> Value<'ll>; // Constant expressions pub(crate) fn LLVMConstInBoundsGEP2<'ll>( ty: Type<'ll>, - ConstantVal: &'ll Value, - ConstantIndices: *const &'ll Value, + ConstantVal: Value<'ll>, + ConstantIndices: *const Value<'ll>, NumIndices: c_uint, - ) -> &'ll Value; - pub(crate) fn LLVMConstPtrToInt<'ll>(ConstantVal: &'ll Value, ToType: Type<'ll>) -> &'ll Value; - pub(crate) fn LLVMConstIntToPtr<'ll>(ConstantVal: &'ll Value, ToType: Type<'ll>) -> &'ll Value; - pub(crate) fn LLVMConstBitCast<'ll>(ConstantVal: &'ll Value, ToType: Type<'ll>) -> &'ll Value; + ) -> Value<'ll>; + pub(crate) fn LLVMConstPtrToInt<'ll>(ConstantVal: Value<'ll>, ToType: Type<'ll>) -> Value<'ll>; + pub(crate) fn LLVMConstIntToPtr<'ll>(ConstantVal: Value<'ll>, ToType: Type<'ll>) -> Value<'ll>; + pub(crate) fn LLVMConstBitCast<'ll>(ConstantVal: Value<'ll>, ToType: Type<'ll>) -> Value<'ll>; pub(crate) fn LLVMConstPointerCast<'ll>( - ConstantVal: &'ll Value, + ConstantVal: Value<'ll>, ToType: Type<'ll>, - ) -> &'ll Value; - pub(crate) fn LLVMGetAggregateElement(ConstantVal: &Value, Idx: c_uint) -> Option<&Value>; - pub(crate) fn LLVMGetConstOpcode(ConstantVal: &Value) -> Opcode; - pub(crate) fn LLVMIsAConstantExpr(Val: &Value) -> Option<&Value>; + ) -> Value<'ll>; + pub(crate) fn LLVMGetAggregateElement<'ll>( + ConstantVal: Value<'ll>, + Idx: c_uint, + ) -> Option>; + pub(crate) fn LLVMGetConstOpcode<'ll>(ConstantVal: Value<'ll>) -> Opcode; + pub(crate) fn LLVMIsAConstantExpr<'ll>(Val: Value<'ll>) -> Option>; // Operations on global variables, functions, and aliases (globals) - pub(crate) fn LLVMIsDeclaration(Global: &Value) -> Bool; - pub(crate) fn LLVMGetLinkage(Global: &Value) -> RawEnum; - pub(crate) fn LLVMSetLinkage(Global: &Value, RustLinkage: Linkage); - pub(crate) fn LLVMSetSection(Global: &Value, Section: *const c_char); - pub(crate) fn LLVMGetVisibility(Global: &Value) -> RawEnum; - pub(crate) fn LLVMSetVisibility(Global: &Value, Viz: Visibility); - pub(crate) fn LLVMGetAlignment(Global: &Value) -> c_uint; - pub(crate) fn LLVMSetAlignment(Global: &Value, Bytes: c_uint); - pub(crate) fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass); - pub(crate) fn LLVMGlobalGetValueType<'ll>(Global: &'ll Value) -> Type<'ll>; + pub(crate) fn LLVMIsDeclaration<'ll>(Global: Value<'ll>) -> Bool; + pub(crate) fn LLVMGetLinkage<'ll>(Global: Value<'ll>) -> RawEnum; + pub(crate) fn LLVMSetLinkage<'ll>(Global: Value<'ll>, RustLinkage: Linkage); + pub(crate) fn LLVMSetSection<'ll>(Global: Value<'ll>, Section: *const c_char); + pub(crate) fn LLVMGetVisibility<'ll>(Global: Value<'ll>) -> RawEnum; + pub(crate) fn LLVMSetVisibility<'ll>(Global: Value<'ll>, Viz: Visibility); + pub(crate) fn LLVMGetAlignment<'ll>(Global: Value<'ll>) -> c_uint; + pub(crate) fn LLVMSetAlignment<'ll>(Global: Value<'ll>, Bytes: c_uint); + pub(crate) fn LLVMSetDLLStorageClass<'ll>(V: Value<'ll>, C: DLLStorageClass); + pub(crate) fn LLVMGlobalGetValueType<'ll>(Global: Value<'ll>) -> Type<'ll>; // Operations on global variables - pub(crate) safe fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>; + pub(crate) safe fn LLVMIsAGlobalVariable<'ll>(GlobalVar: Value<'ll>) -> Option>; pub(crate) fn LLVMAddGlobal<'ll>( M: Module<'ll>, Ty: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMGetNamedGlobal<'ll>( M: Module<'ll>, Name: *const c_char, - ) -> Option<&'ll Value>; - pub(crate) fn LLVMGetFirstGlobal<'ll>(M: Module<'ll>) -> Option<&'ll Value>; - pub(crate) fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>; - pub(crate) fn LLVMDeleteGlobal(GlobalVar: &Value); - pub(crate) safe fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>; - pub(crate) fn LLVMSetInitializer<'a>(GlobalVar: &'a Value, ConstantVal: &'a Value); - pub(crate) safe fn LLVMIsThreadLocal(GlobalVar: &Value) -> Bool; - pub(crate) fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode); - pub(crate) safe fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool; - pub(crate) safe fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool); - pub(crate) safe fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool); - pub(crate) safe fn LLVMSetTailCallKind(CallInst: &Value, kind: TailCallKind); - pub(crate) safe fn LLVMSetExternallyInitialized(GlobalVar: &Value, IsExtInit: Bool); + ) -> Option>; + pub(crate) fn LLVMGetFirstGlobal<'ll>(M: Module<'ll>) -> Option>; + pub(crate) fn LLVMGetNextGlobal<'ll>(GlobalVar: Value<'ll>) -> Option>; + pub(crate) fn LLVMDeleteGlobal<'ll>(GlobalVar: Value<'ll>); + pub(crate) safe fn LLVMGetInitializer<'ll>(GlobalVar: Value<'ll>) -> Option>; + pub(crate) fn LLVMSetInitializer<'ll>(GlobalVar: Value<'ll>, ConstantVal: Value<'ll>); + pub(crate) safe fn LLVMIsThreadLocal<'ll>(GlobalVar: Value<'ll>) -> Bool; + pub(crate) fn LLVMSetThreadLocalMode<'ll>(GlobalVar: Value<'ll>, Mode: ThreadLocalMode); + pub(crate) safe fn LLVMIsGlobalConstant<'ll>(GlobalVar: Value<'ll>) -> Bool; + pub(crate) safe fn LLVMSetGlobalConstant<'ll>(GlobalVar: Value<'ll>, IsConstant: Bool); + pub(crate) safe fn LLVMSetTailCall<'ll>(CallInst: Value<'ll>, IsTailCall: Bool); + pub(crate) safe fn LLVMSetTailCallKind<'ll>(CallInst: Value<'ll>, kind: TailCallKind); + pub(crate) safe fn LLVMSetExternallyInitialized<'ll>(GlobalVar: Value<'ll>, IsExtInit: Bool); // Operations on global aliases pub(crate) fn LLVMAddAlias2<'ll>( M: Module<'ll>, ValueTy: Type<'ll>, AddressSpace: c_uint, - Aliasee: &Value, + Aliasee: Value<'ll>, Name: *const c_char, - ) -> &'ll Value; - pub(crate) fn LLVMGetFirstGlobalAlias<'ll>(M: Module<'ll>) -> Option<&'ll Value>; - pub(crate) fn LLVMGetNextGlobalAlias(GlobalAlias: &Value) -> Option<&Value>; + ) -> Value<'ll>; + pub(crate) fn LLVMGetFirstGlobalAlias<'ll>(M: Module<'ll>) -> Option>; + pub(crate) fn LLVMGetNextGlobalAlias<'ll>(GlobalAlias: Value<'ll>) -> Option>; // Operations on attributes pub(crate) fn LLVMCreateStringAttribute<'ll>( @@ -1154,19 +1167,19 @@ unsafe extern "C" { ) -> &'ll Attribute; // Operations on functions - pub(crate) fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint); + pub(crate) fn LLVMSetFunctionCallConv<'ll>(Fn: Value<'ll>, CC: c_uint); pub(crate) fn LLVMAddFunction<'ll>( Mod: Module<'ll>, Name: *const c_char, FunctionTy: Type<'ll>, - ) -> &'ll Value; - pub(crate) fn LLVMDeleteFunction(Fn: &Value); + ) -> Value<'ll>; + pub(crate) fn LLVMDeleteFunction<'ll>(Fn: Value<'ll>); pub(crate) fn LLVMGetOrInsertFunction<'ll>( M: Module<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, FunctionTy: Type<'ll>, - ) -> &'ll Value; + ) -> Value<'ll>; // Operations about llvm intrinsics pub(crate) fn LLVMLookupIntrinsicID( @@ -1179,43 +1192,43 @@ unsafe extern "C" { ID: NonZero, ParamTypes: *const Type<'ll>, ParamCount: size_t, - ) -> &'ll Value; - pub(crate) fn LLVMRustUpgradeIntrinsicFunction<'a>( - Fn: &'a Value, - NewFn: &mut Option<&'a Value>, + ) -> Value<'ll>; + pub(crate) fn LLVMRustUpgradeIntrinsicFunction<'ll>( + Fn: Value<'ll>, + NewFn: &mut Option>, ) -> bool; pub(crate) fn LLVMRustIsTargetIntrinsic(ID: NonZero) -> bool; // Operations on parameters - pub(crate) fn LLVMIsAArgument(Val: &Value) -> Option<&Value>; - pub(crate) safe fn LLVMCountParams(Fn: &Value) -> c_uint; - pub(crate) fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value; + pub(crate) fn LLVMIsAArgument<'ll>(Val: Value<'ll>) -> Option>; + pub(crate) safe fn LLVMCountParams<'ll>(Fn: Value<'ll>) -> c_uint; + pub(crate) fn LLVMGetParam<'ll>(Fn: Value<'ll>, Index: c_uint) -> Value<'ll>; // Operations on basic blocks - pub(crate) fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value; + pub(crate) fn LLVMGetBasicBlockParent<'ll>(BB: &'ll BasicBlock) -> Value<'ll>; pub(crate) fn LLVMAppendBasicBlockInContext<'ll>( C: Context<'ll>, - Fn: &'ll Value, + Fn: Value<'ll>, Name: *const c_char, ) -> &'ll BasicBlock; // Operations on instructions - pub(crate) fn LLVMIsAInstruction(Val: &Value) -> Option<&Value>; - pub(crate) fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock; - pub(crate) fn LLVMGetOperand(Val: &Value, Index: c_uint) -> Option<&Value>; + pub(crate) fn LLVMIsAInstruction<'ll>(Val: Value<'ll>) -> Option>; + pub(crate) fn LLVMGetFirstBasicBlock<'ll>(Fn: Value<'ll>) -> &'ll BasicBlock; + pub(crate) fn LLVMGetOperand<'ll>(Val: Value<'ll>, Index: c_uint) -> Option>; // Operations on call sites - pub(crate) fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint); + pub(crate) fn LLVMSetInstructionCallConv<'ll>(Instr: Value<'ll>, CC: c_uint); // Operations on load/store instructions (only) - pub(crate) fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool); - pub(crate) fn LLVMSetOrdering(MemoryAccessInst: &Value, Ordering: AtomicOrdering); + pub(crate) fn LLVMSetVolatile<'ll>(MemoryAccessInst: Value<'ll>, volatile: Bool); + pub(crate) fn LLVMSetOrdering<'ll>(MemoryAccessInst: Value<'ll>, Ordering: AtomicOrdering); // Operations on phi nodes - pub(crate) fn LLVMAddIncoming<'a>( - PhiNode: &'a Value, - IncomingValues: *const &'a Value, - IncomingBlocks: *const &'a BasicBlock, + pub(crate) fn LLVMAddIncoming<'ll>( + PhiNode: Value<'ll>, + IncomingValues: *const Value<'ll>, + IncomingBlocks: *const &'ll BasicBlock, Count: c_uint, ); @@ -1230,455 +1243,465 @@ unsafe extern "C" { pub(crate) fn LLVMGetCurrentDebugLocation2<'a>(Builder: &Builder<'a>) -> Option<&'a Metadata>; // Terminators - pub(crate) safe fn LLVMBuildRetVoid<'a>(B: &Builder<'a>) -> &'a Value; - pub(crate) fn LLVMBuildRet<'a>(B: &Builder<'a>, V: &'a Value) -> &'a Value; - pub(crate) fn LLVMBuildBr<'a>(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value; - pub(crate) fn LLVMBuildCondBr<'a>( - B: &Builder<'a>, - If: &'a Value, - Then: &'a BasicBlock, - Else: &'a BasicBlock, - ) -> &'a Value; - pub(crate) fn LLVMBuildSwitch<'a>( - B: &Builder<'a>, - V: &'a Value, - Else: &'a BasicBlock, + pub(crate) safe fn LLVMBuildRetVoid<'ll>(B: &Builder<'ll>) -> Value<'ll>; + pub(crate) fn LLVMBuildRet<'ll>(B: &Builder<'ll>, V: Value<'ll>) -> Value<'ll>; + pub(crate) fn LLVMBuildBr<'ll>(B: &Builder<'ll>, Dest: &'ll BasicBlock) -> Value<'ll>; + pub(crate) fn LLVMBuildCondBr<'ll>( + B: &Builder<'ll>, + If: Value<'ll>, + Then: &'ll BasicBlock, + Else: &'ll BasicBlock, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSwitch<'ll>( + B: &Builder<'ll>, + V: Value<'ll>, + Else: &'ll BasicBlock, NumCases: c_uint, - ) -> &'a Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildLandingPad<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - PersFn: Option<&'ll Value>, + PersFn: Option>, NumClauses: c_uint, Name: *const c_char, - ) -> &'ll Value; - pub(crate) fn LLVMBuildResume<'a>(B: &Builder<'a>, Exn: &'a Value) -> &'a Value; - pub(crate) fn LLVMBuildUnreachable<'a>(B: &Builder<'a>) -> &'a Value; + ) -> Value<'ll>; + pub(crate) fn LLVMBuildResume<'ll>(B: &Builder<'ll>, Exn: Value<'ll>) -> Value<'ll>; + pub(crate) fn LLVMBuildUnreachable<'ll>(B: &Builder<'ll>) -> Value<'ll>; - pub(crate) fn LLVMBuildCleanupPad<'a>( - B: &Builder<'a>, - ParentPad: Option<&'a Value>, - Args: *const &'a Value, + pub(crate) fn LLVMBuildCleanupPad<'ll>( + B: &Builder<'ll>, + ParentPad: Option>, + Args: *const Value<'ll>, NumArgs: c_uint, Name: *const c_char, - ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCleanupRet<'a>( - B: &Builder<'a>, - CleanupPad: &'a Value, - BB: Option<&'a BasicBlock>, - ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchPad<'a>( - B: &Builder<'a>, - ParentPad: &'a Value, - Args: *const &'a Value, + ) -> Option>; + pub(crate) fn LLVMBuildCleanupRet<'ll>( + B: &Builder<'ll>, + CleanupPad: Value<'ll>, + BB: Option<&'ll BasicBlock>, + ) -> Option>; + pub(crate) fn LLVMBuildCatchPad<'ll>( + B: &Builder<'ll>, + ParentPad: Value<'ll>, + Args: *const Value<'ll>, NumArgs: c_uint, Name: *const c_char, - ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchRet<'a>( - B: &Builder<'a>, - CatchPad: &'a Value, - BB: &'a BasicBlock, - ) -> Option<&'a Value>; - pub(crate) fn LLVMBuildCatchSwitch<'a>( - Builder: &Builder<'a>, - ParentPad: Option<&'a Value>, - UnwindBB: Option<&'a BasicBlock>, + ) -> Option>; + pub(crate) fn LLVMBuildCatchRet<'ll>( + B: &Builder<'ll>, + CatchPad: Value<'ll>, + BB: &'ll BasicBlock, + ) -> Option>; + pub(crate) fn LLVMBuildCatchSwitch<'ll>( + Builder: &Builder<'ll>, + ParentPad: Option>, + UnwindBB: Option<&'ll BasicBlock>, NumHandlers: c_uint, Name: *const c_char, - ) -> Option<&'a Value>; - pub(crate) fn LLVMAddHandler<'a>(CatchSwitch: &'a Value, Dest: &'a BasicBlock); - pub(crate) fn LLVMSetPersonalityFn<'a>(Func: &'a Value, Pers: &'a Value); + ) -> Option>; + pub(crate) fn LLVMAddHandler<'ll>(CatchSwitch: Value<'ll>, Dest: &'ll BasicBlock); + pub(crate) fn LLVMSetPersonalityFn<'ll>(Func: Value<'ll>, Pers: Value<'ll>); // Add a case to the switch instruction - pub(crate) fn LLVMAddCase<'a>(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock); + pub(crate) fn LLVMAddCase<'ll>(Switch: Value<'ll>, OnVal: Value<'ll>, Dest: &'ll BasicBlock); // Add a clause to the landing pad instruction - pub(crate) fn LLVMAddClause<'a>(LandingPad: &'a Value, ClauseVal: &'a Value); + pub(crate) fn LLVMAddClause<'ll>(LandingPad: Value<'ll>, ClauseVal: Value<'ll>); // Set the cleanup on a landing pad instruction - pub(crate) fn LLVMSetCleanup(LandingPad: &Value, Val: Bool); + pub(crate) fn LLVMSetCleanup<'ll>(LandingPad: Value<'ll>, Val: Bool); // Arithmetic - pub(crate) fn LLVMBuildAdd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFAdd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildSub<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFSub<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildMul<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFMul<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildUDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildExactUDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildSDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildExactSDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFDiv<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildURem<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildSRem<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFRem<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildShl<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildLShr<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildAShr<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNSWAdd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNUWAdd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNSWSub<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNUWSub<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNSWMul<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNUWMul<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildAnd<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildOr<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildXor<'a>( - B: &Builder<'a>, - LHS: &'a Value, - RHS: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNeg<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) - -> &'a Value; - pub(crate) fn LLVMBuildFNeg<'a>( - B: &Builder<'a>, - V: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildNot<'a>(B: &Builder<'a>, V: &'a Value, Name: *const c_char) - -> &'a Value; + pub(crate) fn LLVMBuildAdd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFAdd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSub<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFSub<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildMul<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFMul<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildUDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildExactUDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildExactSDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFDiv<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildURem<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSRem<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFRem<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildShl<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildLShr<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildAShr<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNSWAdd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNUWAdd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNSWSub<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNUWSub<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNSWMul<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNUWMul<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildAnd<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildOr<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildXor<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + RHS: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNeg<'ll>( + B: &Builder<'ll>, + V: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFNeg<'ll>( + B: &Builder<'ll>, + V: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildNot<'ll>( + B: &Builder<'ll>, + V: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; // Extra flags on arithmetic - pub(crate) fn LLVMSetIsDisjoint(Instr: &Value, IsDisjoint: Bool); - pub(crate) fn LLVMSetNUW(ArithInst: &Value, HasNUW: Bool); - pub(crate) fn LLVMSetNSW(ArithInst: &Value, HasNSW: Bool); + pub(crate) fn LLVMSetIsDisjoint<'ll>(Instr: Value<'ll>, IsDisjoint: Bool); + pub(crate) fn LLVMSetNUW<'ll>(ArithInst: Value<'ll>, HasNUW: Bool); + pub(crate) fn LLVMSetNSW<'ll>(ArithInst: Value<'ll>, HasNSW: Bool); // Memory pub(crate) fn LLVMBuildAlloca<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildLoad2<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - PointerVal: &'ll Value, + PointerVal: Value<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; - pub(crate) fn LLVMBuildStore<'a>(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value; + pub(crate) fn LLVMBuildStore<'ll>( + B: &Builder<'ll>, + Val: Value<'ll>, + Ptr: Value<'ll>, + ) -> Value<'ll>; pub(crate) fn LLVMBuildGEPWithNoWrapFlags<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - Pointer: &'ll Value, - Indices: *const &'ll Value, + Pointer: Value<'ll>, + Indices: *const Value<'ll>, NumIndices: c_uint, Name: *const c_char, Flags: GEPNoWrapFlags, - ) -> &'ll Value; + ) -> Value<'ll>; // Casts pub(crate) fn LLVMBuildTrunc<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildZExt<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildSExt<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildFPToUI<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildFPToSI<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildUIToFP<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildSIToFP<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildFPTrunc<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildFPExt<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildPtrToInt<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildIntToPtr<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildBitCast<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildPointerCast<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildIntCast2<'ll>( B: &Builder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, DestTy: Type<'ll>, IsSigned: Bool, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; // Comparisons - pub(crate) fn LLVMBuildICmp<'a>( - B: &Builder<'a>, + pub(crate) fn LLVMBuildICmp<'ll>( + B: &Builder<'ll>, Op: c_uint, - LHS: &'a Value, - RHS: &'a Value, + LHS: Value<'ll>, + RHS: Value<'ll>, Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildFCmp<'a>( - B: &Builder<'a>, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildFCmp<'ll>( + B: &Builder<'ll>, Op: c_uint, - LHS: &'a Value, - RHS: &'a Value, + LHS: Value<'ll>, + RHS: Value<'ll>, Name: *const c_char, - ) -> &'a Value; + ) -> Value<'ll>; // Miscellaneous instructions pub(crate) fn LLVMBuildPhi<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; - pub(crate) fn LLVMBuildSelect<'a>( - B: &Builder<'a>, - If: &'a Value, - Then: &'a Value, - Else: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildSelect<'ll>( + B: &Builder<'ll>, + If: Value<'ll>, + Then: Value<'ll>, + Else: Value<'ll>, Name: *const c_char, - ) -> &'a Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildVAArg<'ll>( B: &Builder<'ll>, - list: &'ll Value, + list: Value<'ll>, Ty: Type<'ll>, Name: *const c_char, - ) -> &'ll Value; - pub(crate) fn LLVMBuildExtractElement<'a>( - B: &Builder<'a>, - VecVal: &'a Value, - Index: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildInsertElement<'a>( - B: &Builder<'a>, - VecVal: &'a Value, - EltVal: &'a Value, - Index: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildShuffleVector<'a>( - B: &Builder<'a>, - V1: &'a Value, - V2: &'a Value, - Mask: &'a Value, - Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildExtractValue<'a>( - B: &Builder<'a>, - AggVal: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildExtractElement<'ll>( + B: &Builder<'ll>, + VecVal: Value<'ll>, + Index: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildInsertElement<'ll>( + B: &Builder<'ll>, + VecVal: Value<'ll>, + EltVal: Value<'ll>, + Index: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildShuffleVector<'ll>( + B: &Builder<'ll>, + V1: Value<'ll>, + V2: Value<'ll>, + Mask: Value<'ll>, + Name: *const c_char, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildExtractValue<'ll>( + B: &Builder<'ll>, + AggVal: Value<'ll>, Index: c_uint, Name: *const c_char, - ) -> &'a Value; - pub(crate) fn LLVMBuildInsertValue<'a>( - B: &Builder<'a>, - AggVal: &'a Value, - EltVal: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMBuildInsertValue<'ll>( + B: &Builder<'ll>, + AggVal: Value<'ll>, + EltVal: Value<'ll>, Index: c_uint, Name: *const c_char, - ) -> &'a Value; + ) -> Value<'ll>; // Atomic Operations - pub(crate) fn LLVMBuildAtomicCmpXchg<'a>( - B: &Builder<'a>, - LHS: &'a Value, - CMP: &'a Value, - RHS: &'a Value, + pub(crate) fn LLVMBuildAtomicCmpXchg<'ll>( + B: &Builder<'ll>, + LHS: Value<'ll>, + CMP: Value<'ll>, + RHS: Value<'ll>, Order: AtomicOrdering, FailureOrder: AtomicOrdering, SingleThreaded: Bool, - ) -> &'a Value; + ) -> Value<'ll>; - pub(crate) fn LLVMSetWeak(CmpXchgInst: &Value, IsWeak: Bool); + pub(crate) fn LLVMSetWeak<'ll>(CmpXchgInst: Value<'ll>, IsWeak: Bool); - pub(crate) fn LLVMBuildAtomicRMW<'a>( - B: &Builder<'a>, + pub(crate) fn LLVMBuildAtomicRMW<'ll>( + B: &Builder<'ll>, Op: AtomicRmwBinOp, - LHS: &'a Value, - RHS: &'a Value, + LHS: Value<'ll>, + RHS: Value<'ll>, Order: AtomicOrdering, SingleThreaded: Bool, - ) -> &'a Value; + ) -> Value<'ll>; - pub(crate) fn LLVMBuildFence<'a>( - B: &Builder<'a>, + pub(crate) fn LLVMBuildFence<'ll>( + B: &Builder<'ll>, Order: AtomicOrdering, SingleThreaded: Bool, Name: *const c_char, - ) -> &'a Value; + ) -> Value<'ll>; /// Writes a module to the specified path. Returns 0 on success. pub(crate) fn LLVMWriteBitcodeToFile<'ll>(M: Module<'ll>, Path: *const c_char) -> c_int; @@ -1701,58 +1724,58 @@ unsafe extern "C" { pub(crate) fn LLVMCountStructElementTypes<'ll>(StructTy: Type<'ll>) -> c_uint; pub(crate) fn LLVMGetStructElementTypes<'ll>(StructTy: Type<'ll>, Dest: *mut Type<'ll>); - pub(crate) safe fn LLVMMetadataAsValue<'ll>(C: Context<'ll>, MD: &'ll Metadata) -> &'ll Value; + pub(crate) safe fn LLVMMetadataAsValue<'ll>(C: Context<'ll>, MD: &'ll Metadata) -> Value<'ll>; - pub(crate) safe fn LLVMSetUnnamedAddress(Global: &Value, UnnamedAddr: UnnamedAddr); + pub(crate) safe fn LLVMSetUnnamedAddress<'ll>(Global: Value<'ll>, UnnamedAddr: UnnamedAddr); - pub(crate) fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&ConstantInt>; + pub(crate) fn LLVMIsAConstantInt<'ll>(value_ref: Value<'ll>) -> Option<&'ll ConstantInt>; pub(crate) fn LLVMGetOrInsertComdat<'ll>(M: Module<'ll>, Name: *const c_char) -> &'ll Comdat; - pub(crate) fn LLVMSetComdat(V: &Value, C: &Comdat); + pub(crate) fn LLVMSetComdat<'ll>(V: Value<'ll>, C: &Comdat); - pub(crate) fn LLVMCreateOperandBundle( + pub(crate) fn LLVMCreateOperandBundle<'ll>( Tag: *const c_uchar, // See "PTR_LEN_STR". TagLen: size_t, - Args: *const &'_ Value, + Args: *const Value<'ll>, NumArgs: c_uint, - ) -> *mut OperandBundle<'_>; + ) -> *mut OperandBundle<'ll>; pub(crate) fn LLVMDisposeOperandBundle(Bundle: ptr::NonNull>); pub(crate) fn LLVMBuildCallWithOperandBundles<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - Fn: &'ll Value, - Args: *const &'ll Value, + Fn: Value<'ll>, + Args: *const Value<'ll>, NumArgs: c_uint, Bundles: *const &OperandBundle<'ll>, NumBundles: c_uint, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildInvokeWithOperandBundles<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - Fn: &'ll Value, - Args: *const &'ll Value, + Fn: Value<'ll>, + Args: *const Value<'ll>, NumArgs: c_uint, Then: &'ll BasicBlock, Catch: &'ll BasicBlock, Bundles: *const &OperandBundle<'ll>, NumBundles: c_uint, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMBuildCallBr<'ll>( B: &Builder<'ll>, Ty: Type<'ll>, - Fn: &'ll Value, + Fn: Value<'ll>, DefaultDest: &'ll BasicBlock, IndirectDests: *const &'ll BasicBlock, NumIndirectDests: c_uint, - Args: *const &'ll Value, + Args: *const Value<'ll>, NumArgs: c_uint, Bundles: *const &OperandBundle<'ll>, NumBundles: c_uint, Name: *const c_char, - ) -> &'ll Value; + ) -> Value<'ll>; } // FFI bindings for `DIBuilder` functions in the LLVM-C API. @@ -1902,7 +1925,7 @@ unsafe extern "C" { LineNumber: c_uint, Type: &'ll Metadata, Flags: DIFlags, - ConstantVal: Option<&'ll Value>, + ConstantVal: Option>, AlignInBits: u32, ) -> &'ll Metadata; @@ -1961,7 +1984,7 @@ unsafe extern "C" { pub(crate) fn LLVMDIBuilderInsertDeclareRecordAtEnd<'ll>( Builder: &DIBuilder<'ll>, - Storage: &'ll Value, + Storage: Value<'ll>, VarInfo: &'ll Metadata, Expr: &'ll Metadata, DebugLoc: &'ll Metadata, @@ -1970,7 +1993,7 @@ unsafe extern "C" { pub(crate) fn LLVMDIBuilderInsertDbgValueRecordAtEnd<'ll>( Builder: &DIBuilder<'ll>, - Val: &'ll Value, + Val: Value<'ll>, VarInfo: &'ll Metadata, Expr: &'ll Metadata, DebugLoc: &'ll Metadata, @@ -2010,8 +2033,8 @@ unsafe extern "C" { pub(crate) fn LLVMRustDisableSystemDialogsOnCrash(); // Operations on all values - pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool; - pub(crate) fn LLVMRustStripPointerCasts<'a>(Val: &'a Value) -> &'a Value; + pub(crate) fn LLVMRustIsNonGVFunctionPointerTy<'ll>(Val: Value<'ll>) -> bool; + pub(crate) fn LLVMRustStripPointerCasts<'ll>(Val: Value<'ll>) -> Value<'ll>; // Operations on scalar constants pub(crate) fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool; @@ -2023,7 +2046,7 @@ unsafe extern "C" { ) -> bool; // Operations on global variables, functions, and aliases (globals) - pub(crate) fn LLVMRustSetDSOLocal(Global: &Value, is_dso_local: bool); + pub(crate) fn LLVMRustSetDSOLocal<'ll>(Global: Value<'ll>, is_dso_local: bool); // Operations on global variables pub(crate) fn LLVMRustGetOrInsertGlobal<'ll>( @@ -2031,19 +2054,19 @@ unsafe extern "C" { Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, T: Type<'ll>, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMRustGetOrInsertGlobalInAddrspace<'ll>( M: Module<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, T: Type<'ll>, AddressSpace: c_uint, - ) -> &'ll Value; + ) -> Value<'ll>; pub(crate) fn LLVMRustGetNamedValue<'ll>( M: Module<'ll>, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, - ) -> Option<&'ll Value>; + ) -> Option>; // Operations on attributes pub(crate) fn LLVMRustCreateAttrNoValue<'ll>( @@ -2096,55 +2119,55 @@ unsafe extern "C" { ) -> &'ll Attribute; // Operations on functions - pub(crate) fn LLVMRustAddFunctionAttributes<'a>( - Fn: &'a Value, + pub(crate) fn LLVMRustAddFunctionAttributes<'ll>( + Fn: Value<'ll>, index: c_uint, - Attrs: *const &'a Attribute, + Attrs: *const &'ll Attribute, AttrsLen: size_t, ); // Operations on call sites - pub(crate) fn LLVMRustAddCallSiteAttributes<'a>( - Instr: &'a Value, + pub(crate) fn LLVMRustAddCallSiteAttributes<'ll>( + Instr: Value<'ll>, index: c_uint, - Attrs: *const &'a Attribute, + Attrs: *const &'ll Attribute, AttrsLen: size_t, ); - pub(crate) fn LLVMRustSetFastMath(Instr: &Value); - pub(crate) fn LLVMRustSetAlgebraicMath(Instr: &Value); - pub(crate) fn LLVMRustSetAllowReassoc(Instr: &Value); - pub(crate) fn LLVMRustSetNoSignedZeros(Instr: &Value); + pub(crate) fn LLVMRustSetFastMath<'ll>(Instr: Value<'ll>); + pub(crate) fn LLVMRustSetAlgebraicMath<'ll>(Instr: Value<'ll>); + pub(crate) fn LLVMRustSetAllowReassoc<'ll>(Instr: Value<'ll>); + pub(crate) fn LLVMRustSetNoSignedZeros<'ll>(Instr: Value<'ll>); // Miscellaneous instructions - pub(crate) fn LLVMRustBuildMemCpy<'a>( - B: &Builder<'a>, - Dst: &'a Value, + pub(crate) fn LLVMRustBuildMemCpy<'ll>( + B: &Builder<'ll>, + Dst: Value<'ll>, DstAlign: c_uint, - Src: &'a Value, + Src: Value<'ll>, SrcAlign: c_uint, - Size: &'a Value, + Size: Value<'ll>, IsVolatile: bool, - ) -> &'a Value; - pub(crate) fn LLVMRustBuildMemMove<'a>( - B: &Builder<'a>, - Dst: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMRustBuildMemMove<'ll>( + B: &Builder<'ll>, + Dst: Value<'ll>, DstAlign: c_uint, - Src: &'a Value, + Src: Value<'ll>, SrcAlign: c_uint, - Size: &'a Value, + Size: Value<'ll>, IsVolatile: bool, - ) -> &'a Value; - pub(crate) fn LLVMRustBuildMemSet<'a>( - B: &Builder<'a>, - Dst: &'a Value, + ) -> Value<'ll>; + pub(crate) fn LLVMRustBuildMemSet<'ll>( + B: &Builder<'ll>, + Dst: Value<'ll>, DstAlign: c_uint, - Val: &'a Value, - Size: &'a Value, + Val: Value<'ll>, + Size: Value<'ll>, IsVolatile: bool, - ) -> &'a Value; + ) -> Value<'ll>; - pub(crate) fn LLVMRustBuildVScale<'ll>(B: &Builder<'ll>, Ty: Type<'ll>) -> &'ll Value; + pub(crate) fn LLVMRustBuildVScale<'ll>(B: &Builder<'ll>, Ty: Type<'ll>) -> Value<'ll>; pub(crate) fn LLVMRustTimeTraceProfilerInitialize(); @@ -2206,11 +2229,11 @@ unsafe extern "C" { BufferOut: &RustString, ); - pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar( - F: &Value, + pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar<'ll>( + F: Value<'ll>, FuncName: *const c_uchar, // See "PTR_LEN_STR". FuncNameLen: size_t, - ) -> &Value; + ) -> Value<'ll>; pub(crate) fn LLVMRustCoverageHashBytes( Bytes: *const c_uchar, // See "PTR_LEN_STR". NumBytes: size_t, @@ -2295,23 +2318,23 @@ unsafe extern "C" { /// We can't use LLVM-C's `LLVMDIBuilderCreateFunction` because it only /// supports a subset of `DISubprogram::DISPFlags`. - pub(crate) fn LLVMRustDIBuilderCreateFunction<'a>( - Builder: &DIBuilder<'a>, - Scope: &'a DIDescriptor, + pub(crate) fn LLVMRustDIBuilderCreateFunction<'ll>( + Builder: &DIBuilder<'ll>, + Scope: &'ll DIDescriptor, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, LinkageName: *const c_uchar, // See "PTR_LEN_STR". LinkageNameLen: size_t, - File: &'a DIFile, + File: &'ll DIFile, LineNo: c_uint, - Ty: &'a DIType, + Ty: &'ll DIType, ScopeLine: c_uint, Flags: DIFlags, SPFlags: DISPFlags, - MaybeFn: Option<&'a Value>, - TParam: &'a DIArray, - Decl: Option<&'a DIDescriptor>, - ) -> &'a DISubprogram; + MaybeFn: Option>, + TParam: &'ll DIArray, + Decl: Option<&'ll DIDescriptor>, + ) -> &'ll DISubprogram; /// As of LLVM 22 there is no corresponding LLVM-C function. pub(crate) fn LLVMRustDIBuilderCreateMethod<'a>( @@ -2330,20 +2353,20 @@ unsafe extern "C" { ) -> &'a DISubprogram; /// As of LLVM 22 there is no corresponding LLVM-C function. - pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'a>( - Builder: &DIBuilder<'a>, - Scope: &'a DIScope, + pub(crate) fn LLVMRustDIBuilderCreateVariantMemberType<'ll>( + Builder: &DIBuilder<'ll>, + Scope: &'ll DIScope, Name: *const c_uchar, // See "PTR_LEN_STR". NameLen: size_t, - File: &'a DIFile, + File: &'ll DIFile, LineNumber: c_uint, SizeInBits: u64, AlignInBits: u32, OffsetInBits: u64, - Discriminant: Option<&'a Value>, + Discriminant: Option>, Flags: DIFlags, - Ty: &'a DIType, - ) -> &'a DIType; + Ty: &'ll DIType, + ) -> &'ll DIType; /// As of LLVM 22 there is no corresponding LLVM-C function. pub(crate) fn LLVMRustDIBuilderCreateEnumerationType<'a>( @@ -2423,7 +2446,7 @@ unsafe extern "C" { ) -> Option<&'a DILocation>; pub(crate) fn LLVMRustWriteTypeToString<'ll>(Type: Type<'ll>, s: &RustString); - pub(crate) fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString); + pub(crate) fn LLVMRustWriteValueToString<'ll>(value_ref: Value<'ll>, s: &RustString); pub(crate) fn LLVMRustTargetHasMnemonic(T: &TargetMachine, s: *const c_char) -> bool; @@ -2543,10 +2566,10 @@ unsafe extern "C" { pub(crate) fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString); - pub(crate) fn LLVMRustUnpackOptimizationDiagnostic<'a>( - DI: &'a DiagnosticInfo, + pub(crate) fn LLVMRustUnpackOptimizationDiagnostic<'ll>( + DI: &'ll DiagnosticInfo, pass_name_out: &RustString, - function_out: &mut Option<&'a Value>, + function_out: &mut Option>, loc_line_out: &mut c_uint, loc_column_out: &mut c_uint, loc_filename_out: &RustString, @@ -2579,7 +2602,7 @@ unsafe extern "C" { pub(crate) fn LLVMRustSetDataLayoutFromTargetMachine<'ll>(M: Module<'ll>, TM: &TargetMachine); - pub(crate) fn LLVMRustPositionBuilderPastAllocas<'a>(B: &Builder<'a>, Fn: &'a Value); + pub(crate) fn LLVMRustPositionBuilderPastAllocas<'ll>(B: &Builder<'ll>, Fn: Value<'ll>); pub(crate) fn LLVMRustPositionBuilderAtStart<'a>(B: &Builder<'a>, BB: &'a BasicBlock); pub(crate) fn LLVMRustSetModulePICLevel<'ll>(M: Module<'ll>); @@ -2665,9 +2688,9 @@ unsafe extern "C" { pgo_available: bool, ); - pub(crate) fn LLVMRustGetMangledName(V: &Value, out: &RustString); + pub(crate) fn LLVMRustGetMangledName<'ll>(V: Value<'ll>, out: &RustString); - pub(crate) fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32; + pub(crate) fn LLVMRustGetElementTypeArgIndex<'ll>(CallSite: Value<'ll>) -> i32; pub(crate) safe fn LLVMRustLLVMHasZlibCompression() -> bool; pub(crate) safe fn LLVMRustLLVMHasZstdCompression() -> bool; @@ -2686,14 +2709,14 @@ unsafe extern "C" { pub(crate) fn LLVMRustIsAnyArm64Coff(buf_ptr: *const u8, buf_len: usize) -> bool; - pub(crate) fn LLVMRustSetNoSanitizeAddress(Global: &Value); - pub(crate) fn LLVMRustSetNoSanitizeHWAddress(Global: &Value); + pub(crate) fn LLVMRustSetNoSanitizeAddress<'ll>(Global: Value<'ll>); + pub(crate) fn LLVMRustSetNoSanitizeHWAddress<'ll>(Global: Value<'ll>); pub(crate) fn LLVMRustConstPtrAuth<'ll>( - ptr: &'ll Value, + ptr: Value<'ll>, key: u32, disc: u64, - addr_diversity: Option<&'ll Value>, - deactivation_symbol: Option<&'ll Value>, - ) -> &'ll Value; + addr_diversity: Option>, + deactivation_symbol: Option>, + ) -> Value<'ll>; } diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs index 4086c41459a4c..3cdcc78fa760d 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi/branded.rs @@ -75,3 +75,17 @@ unsafe extern "C" { /// Pointee type of the raw pointer wrapped by [`Type`]. type TypeRaw; } + +/// Corresponds to `LLVMValueRef`. +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +#[repr(transparent)] +#[rustc_pass_by_value] +pub(crate) struct Value<'ll> { + llval_raw: ptr::NonNull, + _invariant_ll: PhantomInvariantLifetime<'ll>, +} + +unsafe extern "C" { + /// Pointee type of the raw pointer wrapped by [`Value`]. + type ValueRaw; +} diff --git a/compiler/rustc_codegen_llvm/src/llvm/mod.rs b/compiler/rustc_codegen_llvm/src/llvm/mod.rs index 6d48e551ac92a..c662ad09f49d7 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/mod.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/mod.rs @@ -34,7 +34,7 @@ impl LLVMRustResult { } pub(crate) fn AddFunctionAttributes<'ll>( - llfn: &'ll Value, + llfn: Value<'ll>, idx: AttributePlace, attrs: &[&'ll Attribute], ) { @@ -43,16 +43,16 @@ pub(crate) fn AddFunctionAttributes<'ll>( } } -pub(crate) fn HasStringAttribute<'ll>(llfn: &'ll Value, name: &str) -> bool { +pub(crate) fn HasStringAttribute<'ll>(llfn: Value<'ll>, name: &str) -> bool { unsafe { LLVMRustHasFnAttribute(llfn, name.as_ptr(), name.len()) } } -pub(crate) fn RemoveStringAttrFromFn<'ll>(llfn: &'ll Value, name: &str) { +pub(crate) fn RemoveStringAttrFromFn<'ll>(llfn: Value<'ll>, name: &str) { unsafe { LLVMRustRemoveFnAttribute(llfn, name.as_ptr(), name.len()) } } pub(crate) fn AddCallSiteAttributes<'ll>( - callsite: &'ll Value, + callsite: Value<'ll>, idx: AttributePlace, attrs: &[&'ll Attribute], ) { @@ -194,12 +194,12 @@ impl AttributePlace { } } -pub(crate) fn SetInstructionCallConv(instr: &Value, cc: CallConv) { +pub(crate) fn SetInstructionCallConv<'ll>(instr: Value<'ll>, cc: CallConv) { unsafe { LLVMSetInstructionCallConv(instr, cc as c_uint); } } -pub(crate) fn SetFunctionCallConv(fn_: &Value, cc: CallConv) { +pub(crate) fn SetFunctionCallConv<'ll>(fn_: Value<'ll>, cc: CallConv) { unsafe { LLVMSetFunctionCallConv(fn_, cc as c_uint); } @@ -211,18 +211,18 @@ pub(crate) fn SetFunctionCallConv(fn_: &Value, cc: CallConv) { // value's name as the comdat value to make sure that it is in a 1-to-1 relationship to the // function. // For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52 -pub(crate) fn SetUniqueComdat<'ll>(llmod: Module<'ll>, val: &'ll Value) { +pub(crate) fn SetUniqueComdat<'ll>(llmod: Module<'ll>, val: Value<'ll>) { let name_buf = get_value_name(val); let name = CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap(); set_comdat(llmod, val, &name); } -pub(crate) fn set_unnamed_address(global: &Value, unnamed: UnnamedAddr) { +pub(crate) fn set_unnamed_address<'ll>(global: Value<'ll>, unnamed: UnnamedAddr) { LLVMSetUnnamedAddress(global, unnamed); } -pub(crate) fn set_thread_local_mode(global: &Value, mode: ThreadLocalMode) { +pub(crate) fn set_thread_local_mode<'ll>(global: Value<'ll>, mode: ThreadLocalMode) { unsafe { LLVMSetThreadLocalMode(global, mode); } @@ -242,17 +242,17 @@ impl MemoryEffects { } } -pub(crate) fn set_section(llglobal: &Value, section_name: &CStr) { +pub(crate) fn set_section<'ll>(llglobal: Value<'ll>, section_name: &CStr) { unsafe { LLVMSetSection(llglobal, section_name.as_ptr()); } } -pub(crate) fn add_global<'ll>(llmod: Module<'ll>, ty: Type<'ll>, name_cstr: &CStr) -> &'ll Value { +pub(crate) fn add_global<'ll>(llmod: Module<'ll>, ty: Type<'ll>, name_cstr: &CStr) -> Value<'ll> { unsafe { LLVMAddGlobal(llmod, ty, name_cstr.as_ptr()) } } -pub(crate) fn set_initializer(llglobal: &Value, constant_val: &Value) { +pub(crate) fn set_initializer<'ll>(llglobal: Value<'ll>, constant_val: Value<'ll>) { unsafe { assert_eq!( crate::llvm::LLVMGlobalGetValueType(llglobal), @@ -264,41 +264,41 @@ pub(crate) fn set_initializer(llglobal: &Value, constant_val: &Value) { } } -pub(crate) fn set_global_constant(llglobal: &Value, is_constant: bool) { +pub(crate) fn set_global_constant<'ll>(llglobal: Value<'ll>, is_constant: bool) { LLVMSetGlobalConstant(llglobal, is_constant.to_llvm_bool()); } -pub(crate) fn get_linkage(llglobal: &Value) -> Linkage { +pub(crate) fn get_linkage<'ll>(llglobal: Value<'ll>) -> Linkage { unsafe { LLVMGetLinkage(llglobal) }.to_rust() } -pub(crate) fn set_linkage(llglobal: &Value, linkage: Linkage) { +pub(crate) fn set_linkage<'ll>(llglobal: Value<'ll>, linkage: Linkage) { unsafe { LLVMSetLinkage(llglobal, linkage); } } -pub(crate) fn is_declaration(llglobal: &Value) -> bool { +pub(crate) fn is_declaration<'ll>(llglobal: Value<'ll>) -> bool { unsafe { LLVMIsDeclaration(llglobal) }.is_true() } -pub(crate) fn get_visibility(llglobal: &Value) -> Visibility { +pub(crate) fn get_visibility<'ll>(llglobal: Value<'ll>) -> Visibility { unsafe { LLVMGetVisibility(llglobal) }.to_rust() } -pub(crate) fn set_visibility(llglobal: &Value, visibility: Visibility) { +pub(crate) fn set_visibility<'ll>(llglobal: Value<'ll>, visibility: Visibility) { unsafe { LLVMSetVisibility(llglobal, visibility); } } -pub(crate) fn set_alignment(llglobal: &Value, align: Align) { +pub(crate) fn set_alignment<'ll>(llglobal: Value<'ll>, align: Align) { unsafe { ffi::LLVMSetAlignment(llglobal, align.bytes() as c_uint); } } -pub(crate) fn set_externally_initialized(llglobal: &Value, is_ext_init: bool) { +pub(crate) fn set_externally_initialized<'ll>(llglobal: Value<'ll>, is_ext_init: bool) { LLVMSetExternallyInitialized(llglobal, is_ext_init.to_llvm_bool()); } @@ -306,19 +306,19 @@ pub(crate) fn set_externally_initialized(llglobal: &Value, is_ext_init: bool) { /// /// Inserts the comdat into `llmod` if it does not exist. /// It is an error to call this if the target does not support comdat. -pub(crate) fn set_comdat<'ll>(llmod: Module<'ll>, llglobal: &'ll Value, name: &CStr) { +pub(crate) fn set_comdat<'ll>(llmod: Module<'ll>, llglobal: Value<'ll>, name: &CStr) { unsafe { let comdat = LLVMGetOrInsertComdat(llmod, name.as_ptr()); LLVMSetComdat(llglobal, comdat); } } -pub(crate) fn count_params(llfn: &Value) -> c_uint { +pub(crate) fn count_params<'ll>(llfn: Value<'ll>) -> c_uint { LLVMCountParams(llfn) } /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun. -pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value { +pub(crate) fn get_param<'ll>(llfn: Value<'ll>, index: c_uint) -> Value<'ll> { unsafe { assert!( index < LLVMCountParams(llfn), @@ -333,7 +333,7 @@ pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value { /// Safe wrapper for `LLVMGetValueName2` /// Needs to allocate the value, because `set_value_name` will invalidate /// the pointer. -pub(crate) fn get_value_name(value: &Value) -> Vec { +pub(crate) fn get_value_name<'ll>(value: Value<'ll>) -> Vec { unsafe { let mut len = 0; let data = LLVMGetValueName2(value, &mut len); @@ -364,7 +364,7 @@ impl Intrinsic { self, llmod: Module<'ll>, type_params: &[Type<'ll>], - ) -> &'ll Value { + ) -> Value<'ll> { unsafe { LLVMGetIntrinsicDeclaration(llmod, self.id, type_params.as_ptr(), type_params.len()) } @@ -372,7 +372,7 @@ impl Intrinsic { } /// Safe wrapper for `LLVMSetValueName2` from a byte slice -pub(crate) fn set_value_name(value: &Value, name: &[u8]) { +pub(crate) fn set_value_name<'ll>(value: Value<'ll>, name: &[u8]) { assert!(!name.contains(&0)); unsafe { LLVMSetValueName2(value, name.as_ptr(), name.len()) }; } @@ -407,12 +407,12 @@ pub(crate) fn last_error() -> Option { /// Owning pointer to an [`OperandBundle`] that will dispose of the bundle /// when dropped. -pub(crate) struct OperandBundleBox<'a> { - raw: ptr::NonNull>, +pub(crate) struct OperandBundleBox<'ll> { + raw: ptr::NonNull>, } -impl<'a> OperandBundleBox<'a> { - pub(crate) fn new(name: &str, vals: &[&'a Value]) -> Self { +impl<'ll> OperandBundleBox<'ll> { + pub(crate) fn new(name: &str, vals: &[Value<'ll>]) -> Self { let raw = unsafe { LLVMCreateOperandBundle(name.as_ptr(), name.len(), vals.as_ptr(), vals.len() as c_uint) }; @@ -423,7 +423,7 @@ impl<'a> OperandBundleBox<'a> { /// /// This can't be a `Deref` implementation because `OperandBundle` transitively /// contains an extern type, which is incompatible with `Deref::Target: ?Sized`. - pub(crate) fn as_ref(&self) -> &OperandBundle<'a> { + pub(crate) fn as_ref(&self) -> &OperandBundle<'ll> { // SAFETY: The returned reference is opaque and can only used for FFI. // It is valid for as long as `&self` is. unsafe { self.raw.as_ref() } @@ -467,13 +467,13 @@ pub(crate) fn add_module_flag_str<'ll>( } } -pub(crate) fn set_dllimport_storage_class<'ll>(v: &'ll Value) { +pub(crate) fn set_dllimport_storage_class<'ll>(v: Value<'ll>) { unsafe { LLVMSetDLLStorageClass(v, DLLStorageClass::DllImport); } } -pub(crate) fn set_dso_local<'ll>(v: &'ll Value) { +pub(crate) fn set_dso_local<'ll>(v: Value<'ll>) { unsafe { LLVMRustSetDSOLocal(v, true); } @@ -505,18 +505,18 @@ pub(crate) fn add_alias<'ll>( module: Module<'ll>, ty: Type<'ll>, address_space: AddressSpace, - aliasee: &Value, + aliasee: Value<'ll>, name: &CStr, -) -> &'ll Value { +) -> Value<'ll> { unsafe { LLVMAddAlias2(module, ty, address_space.0, aliasee, name.as_ptr()) } } /// Safe wrapper for `LLVMRustConstPtrAuth`. pub(crate) fn const_ptr_auth<'ll>( - ptr: &'ll Value, + ptr: Value<'ll>, key: u32, disc: u64, - addr_diversity: Option<&'ll Value>, -) -> &'ll Value { + addr_diversity: Option>, +) -> Value<'ll> { unsafe { LLVMRustConstPtrAuth(ptr, key, disc, addr_diversity, None) } } diff --git a/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs index 4f2369aef0d53..d66554491b6c3 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/offload_ffi.rs @@ -4,7 +4,8 @@ use std::sync::OnceLock; use super::ffi::{Module, Value}; -type LLVMRustOffloadMapperFn = unsafe extern "C" fn(&Value, &Value, *const &Value); +type LLVMRustOffloadMapperFn = + for<'ll> unsafe extern "C" fn(Value<'ll>, Value<'ll>, *const Value<'ll>); type LLVMRustOffloadWrapImagesFn = for<'ll> unsafe extern "C" fn(Module<'ll>, *const c_char) -> bool; @@ -50,7 +51,12 @@ impl RustOffloadWrapper { .expect("RustOffloadWrapper not initialized. Call get_or_init with sysroot first.") } - pub(crate) unsafe fn llvm_rust_offload_wrapper(&self, v1: &Value, v2: &Value, vs: &[&Value]) { + pub(crate) unsafe fn llvm_rust_offload_wrapper<'ll>( + &self, + v1: Value<'ll>, + v2: Value<'ll>, + vs: &[Value<'ll>], + ) { unsafe { (self.LLVMRustOffloadMapper)(v1, v2, vs.as_ptr()) } } diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index 82bd5584211c0..cf674b1fd2f71 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -82,7 +82,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { linkage: Linkage, visibility: Visibility, symbol_name: &str, - ) -> &'ll llvm::Value { + ) -> llvm::Value<'ll> { let fn_abi: &FnAbi<'tcx, Ty<'tcx>> = self.fn_abi_of_instance(instance, ty::List::empty()); let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance)); llvm::set_linkage(lldecl, base::linkage_to_llvm(linkage)); @@ -132,7 +132,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { /// So, this function is for static aliases. See [`add_function_aliases`](Self::add_function_aliases) for the alternative. fn add_static_aliases( &self, - aliasee: &'ll llvm::Value, + aliasee: llvm::Value<'ll>, aliases: &[(DefId, Linkage, Visibility)], ) { let ty = self.get_type_of_global(aliasee); @@ -166,7 +166,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { fn add_function_aliases( &self, aliasee_instance: Instance<'tcx>, - aliasee: &'ll llvm::Value, + aliasee: llvm::Value<'ll>, attrs: &Cow<'_, CodegenFnAttrs>, aliases: &[(DefId, Linkage, Visibility)], ) { @@ -233,7 +233,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { /// A definition or declaration can be assumed to be local to a group of /// libraries that form a single DSO or executable. /// Marks the local as DSO if so. - pub(crate) fn assume_dso_local(&self, llval: &llvm::Value, is_declaration: bool) -> bool { + pub(crate) fn assume_dso_local(&self, llval: llvm::Value<'ll>, is_declaration: bool) -> bool { let assume = self.should_assume_dso_local(llval, is_declaration); if assume { llvm::set_dso_local(llval); @@ -241,7 +241,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { assume } - fn set_visibility(&self, lldecl: &llvm::Value, linkage: Linkage, visibility: Visibility) { + fn set_visibility(&self, lldecl: llvm::Value<'ll>, linkage: Linkage, visibility: Visibility) { // If we're compiling the compiler-builtins crate, i.e., the equivalent of // compiler-rt, then we want to implicitly compile everything with hidden // visibility as we're going to link this object all over the place but @@ -253,7 +253,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { } } - fn should_assume_dso_local(&self, llval: &llvm::Value, is_declaration: bool) -> bool { + fn should_assume_dso_local(&self, llval: llvm::Value<'ll>, is_declaration: bool) -> bool { let linkage = llvm::get_linkage(llval); let visibility = llvm::get_visibility(llval); diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index 55c546538611b..d69559593e227 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -56,7 +56,7 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { unsafe { llvm::LLVMScalableVectorType(ty, count as c_uint) } } - pub(crate) fn add_func(&self, name: &str, ty: Type<'ll>) -> &'ll Value { + pub(crate) fn add_func(&self, name: &str, ty: Type<'ll>) -> Value<'ll> { let name = SmallCStr::new(name); unsafe { llvm::LLVMAddFunction(self.llmod(), name.as_ptr(), ty) } } @@ -274,7 +274,7 @@ impl<'ll, CX: Borrow>> BaseTypeCodegenMethods for GenericCx<'ll, CX> { } } - fn val_ty(&self, v: &'ll Value) -> Type<'ll> { + fn val_ty(&self, v: Value<'ll>) -> Type<'ll> { common::val_ty(v) } } @@ -320,24 +320,24 @@ impl<'ll, 'tcx> LayoutTypeCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { } impl<'ll, 'tcx> TypeMembershipCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> { - fn add_type_metadata(&self, function: &'ll Value, typeid: &[u8]) { + fn add_type_metadata(&self, function: Value<'ll>, typeid: &[u8]) { let typeid_metadata = self.create_metadata(typeid); let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata]; self.global_add_metadata_node(function, llvm::MD_type, &v); } - fn set_type_metadata(&self, function: &'ll Value, typeid: &[u8]) { + fn set_type_metadata(&self, function: Value<'ll>, typeid: &[u8]) { let typeid_metadata = self.create_metadata(typeid); let v = [llvm::LLVMValueAsMetadata(self.const_usize(0)), typeid_metadata]; self.global_set_metadata_node(function, llvm::MD_type, &v); } - fn add_kcfi_type_metadata(&self, function: &'ll Value, kcfi_typeid: u32) { + fn add_kcfi_type_metadata(&self, function: Value<'ll>, kcfi_typeid: u32) { let kcfi_type_metadata = [llvm::LLVMValueAsMetadata(self.const_u32(kcfi_typeid))]; self.global_add_metadata_node(function, llvm::MD_kcfi_type, &kcfi_type_metadata); } - fn set_kcfi_type_metadata(&self, function: &'ll Value, kcfi_typeid: u32) { + fn set_kcfi_type_metadata(&self, function: Value<'ll>, kcfi_typeid: u32) { let kcfi_type_metadata = [llvm::LLVMValueAsMetadata(self.const_u32(kcfi_typeid))]; self.global_set_metadata_node(function, llvm::MD_kcfi_type, &kcfi_type_metadata); } diff --git a/compiler/rustc_codegen_llvm/src/typetree.rs b/compiler/rustc_codegen_llvm/src/typetree.rs index efda11f399ba4..48959a0ae6739 100644 --- a/compiler/rustc_codegen_llvm/src/typetree.rs +++ b/compiler/rustc_codegen_llvm/src/typetree.rs @@ -75,7 +75,7 @@ enum TTLocation { Callsite, } -pub(crate) fn add_tt<'tcx, 'll>(cx: &FullCx<'ll, 'tcx>, fn_def: &'ll Value, tt: FncTree) { +pub(crate) fn add_tt<'tcx, 'll>(cx: &FullCx<'ll, 'tcx>, fn_def: Value<'ll>, tt: FncTree) { // TypeTree processing uses functions from Enzyme. This feature is not strictly necessary, // but skipping this function increases the chance that Enzyme fails to compile some code. diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index 7c2c20c2671e4..e06cdaca0ae5a 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -17,18 +17,18 @@ use crate::type_of::LayoutLlvmExt; fn round_up_to_alignment<'ll>( bx: &mut Builder<'_, 'll, '_>, - mut value: &'ll Value, + mut value: Value<'ll>, align: Align, -) -> &'ll Value { +) -> Value<'ll> { value = bx.add(value, bx.cx().const_i32(align.bytes() as i32 - 1)); return bx.and(value, bx.cx().const_i32(-(align.bytes() as i32))); } fn round_pointer_up_to_alignment<'ll>( bx: &mut Builder<'_, 'll, '_>, - addr: &'ll Value, + addr: Value<'ll>, align: Align, -) -> &'ll Value { +) -> Value<'ll> { let ptr = bx.inbounds_ptradd(addr, bx.const_i32(align.bytes() as i32 - 1)); let pointer_width = bx.tcx().sess.target.pointer_width; let mask = align.bytes().wrapping_neg() & (u64::MAX >> (64 - pointer_width)); @@ -41,13 +41,13 @@ fn round_pointer_up_to_alignment<'ll>( fn emit_direct_ptr_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, size: Size, align: Align, slot_size: Align, allow_higher_align: bool, force_right_adjust: bool, -) -> (&'ll Value, Align) { +) -> (Value<'ll>, Align) { let va_list_ty = bx.type_ptr(); let va_list_addr = list.immediate(); @@ -155,13 +155,13 @@ enum ForceRightAdjust { fn emit_ptr_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, pass_mode: PassMode, slot_size: SlotSize, allow_higher_align: AllowHigherAlign, force_right_adjust: ForceRightAdjust, -) -> &'ll Value { +) -> Value<'ll> { let indirect = matches!(pass_mode, PassMode::Indirect); let allow_higher_align = matches!(allow_higher_align, AllowHigherAlign::Yes); let force_right_adjust = matches!(force_right_adjust, ForceRightAdjust::Yes); @@ -195,9 +195,9 @@ fn emit_ptr_va_arg<'ll, 'tcx>( fn emit_aapcs_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); // Implementation of the AAPCS64 calling convention for va_args see @@ -315,9 +315,9 @@ fn is_powerpc_softfloat_abi(target: &Target) -> bool { fn emit_powerpc_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); // struct __va_list_tag { @@ -443,9 +443,9 @@ fn emit_powerpc_va_arg<'ll, 'tcx>( fn emit_s390x_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); // Implementation of the s390x ELF ABI calling convention for va_args see @@ -551,9 +551,9 @@ fn emit_s390x_va_arg<'ll, 'tcx>( fn emit_x86_64_sysv64_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); // Implementation of the systemv x86_64 ABI calling convention for va_args, see @@ -797,10 +797,10 @@ fn emit_x86_64_sysv64_va_arg<'ll, 'tcx>( /// Copy into a temporary if the type is more aligned than the register save area. fn copy_to_temporary_if_more_aligned<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - reg_addr: &'ll Value, + reg_addr: Value<'ll>, layout: TyAndLayout<'tcx>, src_align: Align, -) -> &'ll Value { +) -> Value<'ll> { if layout.layout.align > src_align { assert!(layout.ty.is_integral()); @@ -816,9 +816,9 @@ fn copy_to_temporary_if_more_aligned<'ll, 'tcx>( fn x86_64_sysv64_va_arg_from_memory<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - va_list_addr: &'ll Value, + va_list_addr: Value<'ll>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { let dl = bx.cx.data_layout(); let ptr_align_abi = dl.data_layout().pointer_align(); @@ -855,9 +855,9 @@ fn x86_64_sysv64_va_arg_from_memory<'ll, 'tcx>( fn emit_hexagon_va_arg_musl<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { // Implementation of va_arg for Hexagon musl target. // Based on LLVM's HexagonBuiltinVaList implementation. // @@ -934,9 +934,9 @@ fn emit_hexagon_va_arg_musl<'ll, 'tcx>( fn emit_hexagon_va_arg_bare_metal<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { // Implementation of va_arg for Hexagon bare-metal (non-musl) targets. // Based on LLVM's EmitVAArgForHexagon implementation. // @@ -971,9 +971,9 @@ fn emit_hexagon_va_arg_bare_metal<'ll, 'tcx>( fn emit_xtensa_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - list: OperandRef<'tcx, &'ll Value>, + list: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { // Implementation of va_arg for Xtensa. There doesn't seem to be an authoritative source for // this, other than "what GCC does". // @@ -1072,9 +1072,9 @@ fn emit_xtensa_va_arg<'ll, 'tcx>( /// pub(super) fn emit_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, - addr: OperandRef<'tcx, &'ll Value>, + addr: OperandRef<'tcx, Value<'ll>>, layout: TyAndLayout<'tcx>, -) -> &'ll Value { +) -> Value<'ll> { // Some ABIs have special behavior for zero-sized types. currently `VaArgSafe` is not // implemented for any zero-sized types, so this assert should always hold. assert!(!layout.is_zst()); diff --git a/compiler/rustc_codegen_llvm/src/value.rs b/compiler/rustc_codegen_llvm/src/value.rs index 37f05f10c50cd..221b51851fa30 100644 --- a/compiler/rustc_codegen_llvm/src/value.rs +++ b/compiler/rustc_codegen_llvm/src/value.rs @@ -1,27 +1,12 @@ -use std::hash::{Hash, Hasher}; -use std::{fmt, ptr}; +use std::fmt; use crate::llvm::{self, Value}; -impl PartialEq for Value { - fn eq(&self, other: &Self) -> bool { - ptr::eq(self, other) - } -} - -impl Eq for Value {} - -impl Hash for Value { - fn hash(&self, hasher: &mut H) { - (self as *const Self).hash(hasher); - } -} - -impl fmt::Debug for Value { +impl<'ll> fmt::Debug for Value<'ll> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str( &llvm::build_string(|s| unsafe { - llvm::LLVMRustWriteValueToString(self, s); + llvm::LLVMRustWriteValueToString(*self, s); }) .expect("non-UTF8 value description from LLVM"), ) From 3a046855263de67308f39ebd95c43350e06c2d82 Mon Sep 17 00:00:00 2001 From: albab-hasan Date: Wed, 11 Nov 2026 21:23:17 +0600 Subject: [PATCH 06/10] do not lint `redundant_lifetimes` on items from external macros derived impls kept the lifetime spans of the derive input so the external macro check missed them and `#[expect(redundant_lifetimes)]` on a derived struct went unfulfilled. the lint now skips items whose own span is in an external macro. --- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 6 ++++++ .../derive-expect-issue-150553.rs | 9 +++------ .../derive-expect-issue-150553.stderr | 15 --------------- 3 files changed, 9 insertions(+), 21 deletions(-) delete mode 100644 tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index f4b4e50400530..d3ebb2b173da7 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -2681,6 +2681,12 @@ fn lint_redundant_lifetimes<'tcx>( owner_id: LocalDefId, outlives_env: &OutlivesEnvironment<'tcx>, ) { + // Items produced by external macros (e.g. derived impls) reuse the lifetime spans of the + // macro input, so the usual external macro check on the lint span does not catch them. + if tcx.def_span(owner_id).in_external_macro(tcx.sess.source_map()) { + return; + } + let def_kind = tcx.def_kind(owner_id); match def_kind { DefKind::Struct diff --git a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs index 06ec71bb6c84d..4c09b40344c0f 100644 --- a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs +++ b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.rs @@ -1,11 +1,9 @@ -// FIXME: Bring back duplication of the `#[expect]` attribute when deriving. -// -// Make sure we properly copy the `#[expect]` attr to the derived code and that no -// unfulfilled expectations are trigerred. +// Make sure `#[expect]` on an item with a derive is fulfilled when the lint is only emitted on the +// item itself, and not also on the derived impl, which reuses the lifetime spans of the input. // // See for rational. -//@ check-fail +//@ check-pass #![deny(redundant_lifetimes)] @@ -14,7 +12,6 @@ use std::fmt::Debug; #[derive(Debug)] #[expect(redundant_lifetimes)] pub struct RefWrapper<'a, T> -//~^ ERROR redundant_lifetimes where 'a: 'static, T: Debug, diff --git a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr b/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr deleted file mode 100644 index c4047329d5c1f..0000000000000 --- a/tests/ui/lint/rfc-2383-lint-reason/derive-expect-issue-150553.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error: unnecessary lifetime parameter `'a` - --> $DIR/derive-expect-issue-150553.rs:16:23 - | -LL | pub struct RefWrapper<'a, T> - | ^^ - | - = note: you can use the `'static` lifetime directly, in place of `'a` -note: the lint level is defined here - --> $DIR/derive-expect-issue-150553.rs:10:9 - | -LL | #![deny(redundant_lifetimes)] - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - From 0923cf0d789581824cb818e5be30c7507bb4498d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Wed, 4 Nov 2026 23:05:20 +0100 Subject: [PATCH 07/10] Don't blindly say that a macro call doesn't expand to a certain fragment Just because the parser of a specific syntax fragment kind returns an `Err(_)` doesn't automatically mean that the problematic token sequence isn't "of" that fragment's kind. The token sequence might "almost" be of that kind (i.e., share a non-empty prefix) but simply contain a syntax error in it. On a side note, it's rather odd that the now removed `annotate_err_with_kind` only added the note "this macro call doesn't expand to a $fragkind" if the target fragment kind was *type* or *pat*, there are 20 kinds at the of writing. --- compiler/rustc_expand/src/expand.rs | 2 -- compiler/rustc_expand/src/mbe/diagnostics.rs | 16 ++-------------- .../early/macro_rules-braces.stderr | 4 ++-- .../min_const_generics/macro-fail-const.stderr | 10 ++-------- .../min_const_generics/macro-fail.stderr | 15 +++------------ .../derives/debug/nonsense-input-to-debug.stderr | 1 - .../field_representing_types/invalid.next.stderr | 15 +++------------ .../field_representing_types/invalid.old.stderr | 15 +++------------ tests/ui/macros/macro-interpolation.stderr | 5 +---- tests/ui/proc-macro/lifetimes.stderr | 5 +---- 10 files changed, 17 insertions(+), 71 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index af1e4be5e8399..326014b2699db 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -41,7 +41,6 @@ use crate::diagnostics::{ GlobDelegationTraitlessQpath, IncompleteParse, RecursionLimitReached, RemoveExprNotSupported, UnsupportedKeyValue, WrongFragmentKind, }; -use crate::mbe::diagnostics::annotate_err_with_kind; use crate::module::{ DirOwnership, ParsedExternalMod, mod_dir_path, mod_file_path_from_attr, parse_external_mod, }; @@ -1067,7 +1066,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> { if err.span.is_dummy() { err.span(span); } - annotate_err_with_kind(&mut err, kind, span); let guar = err.emit_err(); self.cx.macro_error_and_trace_macros_diag(); kind.dummy(span, guar) diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index c724857d572ec..281f55f8ec090 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -434,8 +434,8 @@ pub(super) fn emit_frag_parse_err( } } }, - _ => annotate_err_with_kind(&mut e, kind, site_span), - }; + _ => {} + } if parser.token.kind == token::Dollar { let dollar_span = parser.token.span; @@ -504,18 +504,6 @@ pub(super) fn emit_frag_parse_err( e.emit_err() } -pub(crate) fn annotate_err_with_kind(err: &mut Diag<'_>, kind: AstFragmentKind, span: Span) { - match kind { - AstFragmentKind::Ty => { - err.span_label(span, "this macro call doesn't expand to a type"); - } - AstFragmentKind::Pat => { - err.span_label(span, "this macro call doesn't expand to a pattern"); - } - _ => {} - }; -} - #[derive(Subdiagnostic)] enum ExplainDocComment { #[label( diff --git a/tests/ui/const-generics/early/macro_rules-braces.stderr b/tests/ui/const-generics/early/macro_rules-braces.stderr index 6cc9a67f194b7..98e905d71c04b 100644 --- a/tests/ui/const-generics/early/macro_rules-braces.stderr +++ b/tests/ui/const-generics/early/macro_rules-braces.stderr @@ -2,7 +2,7 @@ error: expressions must be enclosed in braces to be used as const generic argume --> $DIR/macro_rules-braces.rs:44:17 | LL | let _: baz!(m::P); - | -----^^^^- this macro call doesn't expand to a type + | ^^^^ | help: enclose the `const` expression in braces | @@ -13,7 +13,7 @@ error: expressions must be enclosed in braces to be used as const generic argume --> $DIR/macro_rules-braces.rs:64:17 | LL | let _: baz!(10 + 7); - | -----^^^^^^- this macro call doesn't expand to a type + | ^^^^^^ | help: enclose the `const` expression in braces | diff --git a/tests/ui/const-generics/min_const_generics/macro-fail-const.stderr b/tests/ui/const-generics/min_const_generics/macro-fail-const.stderr index 2fa529c750d10..2688675f3aa43 100644 --- a/tests/ui/const-generics/min_const_generics/macro-fail-const.stderr +++ b/tests/ui/const-generics/min_const_generics/macro-fail-const.stderr @@ -2,10 +2,7 @@ error: expected type, found `{` --> $DIR/macro-fail-const.rs:16:27 | LL | fn make_marker() -> impl Marker { - | ---------------------- - | | - | this macro call doesn't expand to a type - | in this macro invocation + | ---------------------- in this macro invocation ... LL | macro_rules! gimme_a_const { LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} @@ -15,10 +12,7 @@ error: expected type, found `{` --> $DIR/macro-fail-const.rs:16:27 | LL | Example:: - | ---------------------- - | | - | this macro call doesn't expand to a type - | in this macro invocation + | ---------------------- in this macro invocation ... LL | macro_rules! gimme_a_const { LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} diff --git a/tests/ui/const-generics/min_const_generics/macro-fail.stderr b/tests/ui/const-generics/min_const_generics/macro-fail.stderr index 23eeec7f6daa0..c190ceb40a82d 100644 --- a/tests/ui/const-generics/min_const_generics/macro-fail.stderr +++ b/tests/ui/const-generics/min_const_generics/macro-fail.stderr @@ -2,10 +2,7 @@ error: expected type, found `{` --> $DIR/macro-fail.rs:27:27 | LL | fn make_marker() -> impl Marker { - | ---------------------- - | | - | this macro call doesn't expand to a type - | in this macro invocation + | ---------------------- in this macro invocation ... LL | macro_rules! gimme_a_const { LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} @@ -15,10 +12,7 @@ error: expected type, found `{` --> $DIR/macro-fail.rs:27:27 | LL | Example:: - | ---------------------- - | | - | this macro call doesn't expand to a type - | in this macro invocation + | ---------------------- in this macro invocation ... LL | macro_rules! gimme_a_const { LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} @@ -32,10 +26,7 @@ LL | () => {{ | ^ expected type ... LL | let _fail = Example::; - | ----------------- - | | - | this macro call doesn't expand to a type - | in this macro invocation + | ----------------- in this macro invocation error: unexpected end of macro invocation --> $DIR/macro-fail.rs:36:25 diff --git a/tests/ui/derives/debug/nonsense-input-to-debug.stderr b/tests/ui/derives/debug/nonsense-input-to-debug.stderr index 207d7b1969de5..ee35d5e624856 100644 --- a/tests/ui/derives/debug/nonsense-input-to-debug.stderr +++ b/tests/ui/derives/debug/nonsense-input-to-debug.stderr @@ -12,7 +12,6 @@ LL | should_be_vec_t: vec![T], | | | expected type | in this macro invocation - | this macro call doesn't expand to a type error[E0392]: type parameter `T` is never used --> $DIR/nonsense-input-to-debug.rs:5:17 diff --git a/tests/ui/field_representing_types/invalid.next.stderr b/tests/ui/field_representing_types/invalid.next.stderr index 82b2aa81451ab..3d6775fe8b376 100644 --- a/tests/ui/field_representing_types/invalid.next.stderr +++ b/tests/ui/field_representing_types/invalid.next.stderr @@ -37,10 +37,7 @@ error: `field_of` expects dot-separated field and variant names --> $DIR/invalid.rs:28:12 | LL | let _: field_of!(Enum, Variant..field); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | in this macro invocation - | this macro call doesn't expand to a type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation error: offset_of expects dot-separated field and variant names --> $DIR/invalid.rs:30:30 @@ -52,19 +49,13 @@ error: `field_of` expects dot-separated field and variant names --> $DIR/invalid.rs:30:12 | LL | let _: field_of!(Struct, [42]); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | in this macro invocation - | this macro call doesn't expand to a type + | ^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation error: `field_of` only supports a single field or a variant with a field --> $DIR/invalid.rs:32:30 | LL | let _: field_of!(Struct, field1.field2.field3); - | ------------------^^^^^^-^^^^^^-^^^^^^- - | | - | in this macro invocation - | this macro call doesn't expand to a type + | ------------------^^^^^^-^^^^^^-^^^^^^- in this macro invocation error: aborting due to 8 previous errors diff --git a/tests/ui/field_representing_types/invalid.old.stderr b/tests/ui/field_representing_types/invalid.old.stderr index 82b2aa81451ab..3d6775fe8b376 100644 --- a/tests/ui/field_representing_types/invalid.old.stderr +++ b/tests/ui/field_representing_types/invalid.old.stderr @@ -37,10 +37,7 @@ error: `field_of` expects dot-separated field and variant names --> $DIR/invalid.rs:28:12 | LL | let _: field_of!(Enum, Variant..field); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | in this macro invocation - | this macro call doesn't expand to a type + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation error: offset_of expects dot-separated field and variant names --> $DIR/invalid.rs:30:30 @@ -52,19 +49,13 @@ error: `field_of` expects dot-separated field and variant names --> $DIR/invalid.rs:30:12 | LL | let _: field_of!(Struct, [42]); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | | - | in this macro invocation - | this macro call doesn't expand to a type + | ^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation error: `field_of` only supports a single field or a variant with a field --> $DIR/invalid.rs:32:30 | LL | let _: field_of!(Struct, field1.field2.field3); - | ------------------^^^^^^-^^^^^^-^^^^^^- - | | - | in this macro invocation - | this macro call doesn't expand to a type + | ------------------^^^^^^-^^^^^^-^^^^^^- in this macro invocation error: aborting due to 8 previous errors diff --git a/tests/ui/macros/macro-interpolation.stderr b/tests/ui/macros/macro-interpolation.stderr index 3dc6ef6132d2a..304e7311e2d4e 100644 --- a/tests/ui/macros/macro-interpolation.stderr +++ b/tests/ui/macros/macro-interpolation.stderr @@ -7,10 +7,7 @@ LL | <$type as $trait>::$name | ^^^^^^ expected identifier, found metavariable ... LL | let _: qpath!(ty, ::Owned); - | ----------------------------- - | | - | this macro call doesn't expand to a type - | in this macro invocation + | ----------------------------- in this macro invocation error: aborting due to 1 previous error diff --git a/tests/ui/proc-macro/lifetimes.stderr b/tests/ui/proc-macro/lifetimes.stderr index 315b4c5917243..aa5ef8559ced3 100644 --- a/tests/ui/proc-macro/lifetimes.stderr +++ b/tests/ui/proc-macro/lifetimes.stderr @@ -2,10 +2,7 @@ error: expected type, found `'` --> $DIR/lifetimes.rs:7:10 | LL | type A = single_quote_alone!(); - | ^^^^^^^^^^^^^^^^^^^^^ - | | - | expected type - | this macro call doesn't expand to a type + | ^^^^^^^^^^^^^^^^^^^^^ expected type | = note: this error originates in the macro `single_quote_alone` (in Nightly builds, run with -Z macro-backtrace for more info) From 7f07f66dd79494e724eaaa754b605efb9879e5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Thu, 3 Sep 2026 18:00:16 +0200 Subject: [PATCH 08/10] Turn `pattern_type` into a macro 2.0 that expands to `k#pattern_type(..)` This also means that it's now available under `core::pat` instead of `core` directly. This makes it consistent with the `std` re-export which is only available under `std::pat` and not under `std` directly. Moreover, drop library feature `pattern_type_macro` and demote language feature `pattern_types` to a library feature. This is nice because it means `std::pat::pattern_type` is no longer unnecessarily gated behind two (!) feature gates. --- compiler/rustc_ast_passes/src/feature_gate.rs | 3 - compiler/rustc_builtin_macros/src/lib.rs | 2 - .../rustc_builtin_macros/src/pattern_type.rs | 75 ------------------- .../example/mini_core.rs | 12 ++- .../example/mini_core_hello_world.rs | 10 +-- .../build_system/src/test.rs | 2 + .../rustc_codegen_gcc/example/mini_core.rs | 28 ++++--- compiler/rustc_data_structures/src/lib.rs | 2 +- compiler/rustc_feature/src/unstable.rs | 2 - compiler/rustc_index_macros/src/lib.rs | 2 +- compiler/rustc_parse/src/parser/ty.rs | 56 +++++++++++++- compiler/rustc_span/src/symbol.rs | 2 +- library/core/src/lib.rs | 5 +- library/core/src/num/niche_types.rs | 3 +- library/core/src/pat.rs | 12 ++- library/core/src/prelude/v1.rs | 4 +- library/core/src/ptr/non_null.rs | 2 +- library/std/src/lib.rs | 2 +- library/std/src/pat.rs | 2 +- .../clippy/tests/ui/eager_transmute.fixed | 2 +- src/tools/clippy/tests/ui/eager_transmute.rs | 2 +- src/tools/miri/tests/fail/validity/nonzero.rs | 2 +- src/tools/miri/tests/pass/pattern-types.rs | 2 +- .../src/external_deps/rustc.rs | 2 +- tests/auxiliary/minicore.rs | 12 ++- tests/codegen-llvm/enum/enum-aggregate.rs | 2 +- tests/codegen-llvm/pattern_type_symbols.rs | 3 +- tests/debuginfo/msvc-pretty-enums.rs | 6 +- tests/mir-opt/dataflow-const-prop/enum.rs | 2 +- tests/mir-opt/gvn.rs | 2 +- tests/mir-opt/jump_threading.rs | 2 +- tests/mir-opt/pattern_types.rs | 1 - .../pattern-types-implementors.rs | 2 +- tests/ui/consts/const-eval/raw-bytes.rs | 2 +- tests/ui/consts/const-eval/ub-ref-ptr.rs | 2 +- tests/ui/enum-discriminant/ptr_niche.rs | 2 +- tests/ui/lint/clashing-extern-fn.rs | 2 +- tests/ui/lint/invalid_value.rs | 2 +- tests/ui/mir/ssa-analysis-regression-50041.rs | 2 +- tests/ui/pattern/overflowing-literals.rs | 1 - tests/ui/pattern/overflowing-literals.stderr | 8 +- tests/ui/print_type_sizes/niche-filling.rs | 2 +- .../pattern_types/assoc_const.default.stderr | 8 +- tests/ui/type/pattern_types/assoc_const.rs | 2 - tests/ui/type/pattern_types/bad_pat.rs | 3 +- tests/ui/type/pattern_types/bad_pat.stderr | 16 ++-- tests/ui/type/pattern_types/chars.rs | 1 - tests/ui/type/pattern_types/const_generics.rs | 2 +- tests/ui/type/pattern_types/derives.rs | 3 +- tests/ui/type/pattern_types/derives.stderr | 2 +- tests/ui/type/pattern_types/derives_fail.rs | 3 +- .../ui/type/pattern_types/derives_fail.stderr | 12 +-- ...eature-gate-pattern_types.disabled.stderr} | 32 ++++---- ...feature-gate-pattern_types.enabled.stderr} | 2 +- .../feature-gate-pattern_types.rs | 14 ++-- .../feature-gate-pattern_types2.rs | 12 --- tests/ui/type/pattern_types/free_const.rs | 1 - tests/ui/type/pattern_types/literals.rs | 1 - tests/ui/type/pattern_types/literals.stderr | 40 +++++----- tests/ui/type/pattern_types/matching.rs | 2 +- tests/ui/type/pattern_types/matching_fail.rs | 2 +- tests/ui/type/pattern_types/missing-is.rs | 2 +- tests/ui/type/pattern_types/nested.rs | 1 - tests/ui/type/pattern_types/nested.stderr | 26 +++---- tests/ui/type/pattern_types/non_null.rs | 2 +- tests/ui/type/pattern_types/or_patterns.rs | 8 +- .../ui/type/pattern_types/or_patterns.stderr | 16 ++-- .../type/pattern_types/or_patterns_invalid.rs | 10 +-- .../pattern_types/or_patterns_invalid.stderr | 8 +- .../pattern_types/pattern_type_mismatch.rs | 1 - .../pattern_type_mismatch.stderr | 8 +- tests/ui/type/pattern_types/range_patterns.rs | 2 - .../type/pattern_types/range_patterns.stderr | 24 +++--- .../range_patterns_inherent_impls.rs | 2 - .../range_patterns_inherent_impls.stderr | 4 +- .../range_patterns_trait_impls.rs | 2 - .../range_patterns_trait_impls2.rs | 2 - .../range_patterns_trait_impls2.stderr | 2 +- .../pattern_types/range_patterns_unusable.rs | 2 - .../range_patterns_unusable.stderr | 2 +- .../range_patterns_unusable_math.rs | 2 - .../range_patterns_unusable_math.stderr | 2 +- .../pattern_types/range_patterns_usage.rs | 2 - tests/ui/type/pattern_types/reverse_range.rs | 1 - .../type/pattern_types/reverse_range.stderr | 2 +- tests/ui/type/pattern_types/signed_ranges.rs | 1 - .../type/pattern_types/signed_ranges.stderr | 8 +- tests/ui/type/pattern_types/transmute.rs | 2 +- .../type/pattern_types/unimplemented_pat.rs | 2 +- tests/ui/type/pattern_types/unsize.rs | 2 +- tests/ui/type/pattern_types/validity.rs | 1 - tests/ui/type/pattern_types/validity.stderr | 16 ++-- tests/ui/unpretty/exhaustive.expanded.stdout | 3 +- tests/ui/unpretty/exhaustive.hir.stderr | 40 +++++----- tests/ui/unpretty/exhaustive.hir.stdout | 5 +- tests/ui/unpretty/exhaustive.rs | 3 +- 96 files changed, 282 insertions(+), 383 deletions(-) delete mode 100644 compiler/rustc_builtin_macros/src/pattern_type.rs rename tests/ui/type/pattern_types/{feature-gate-pattern_types.stderr => feature-gate-pattern_types.disabled.stderr} (64%) rename tests/ui/type/pattern_types/{feature-gate-pattern_types2.stderr => feature-gate-pattern_types.enabled.stderr} (81%) delete mode 100644 tests/ui/type/pattern_types/feature-gate-pattern_types2.rs diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 862d4736ca33c..02adcc2296610 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -241,9 +241,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { // Function pointers cannot be `const` self.check_late_bound_lifetime_defs(&fn_ptr_ty.generic_params); } - ast::TyKind::Pat(..) => { - gate!(self, pattern_types, ty.span, "pattern types are unstable"); - } ast::TyKind::View(..) => { gate!(self, view_types, ty.span, "view types are unstable"); } diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index f1e7846f54f9b..40c7872eda563 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -45,7 +45,6 @@ mod global_allocator; mod iter; mod log_syntax; mod offload; -mod pattern_type; mod rustdoc_skip_body; mod source_util; mod test; @@ -100,7 +99,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { module_path: source_util::expand_mod, naked_asm: asm::expand_naked_asm, option_env: env::expand_option_env, - pattern_type: pattern_type::expand, std_panic: edition_panic::expand_panic, stringify: source_util::expand_stringify, test_binder_constraints: test_binder_constraints::expand, diff --git a/compiler/rustc_builtin_macros/src/pattern_type.rs b/compiler/rustc_builtin_macros/src/pattern_type.rs deleted file mode 100644 index 4d34ba963e4e8..0000000000000 --- a/compiler/rustc_builtin_macros/src/pattern_type.rs +++ /dev/null @@ -1,75 +0,0 @@ -use rustc_ast::tokenstream::TokenStream; -use rustc_ast::{AnonConst, DUMMY_NODE_ID, Ty, TyPat, TyPatKind, ast, token}; -use rustc_errors::PResult; -use rustc_expand::base::{self, DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult}; -use rustc_parse::exp; -use rustc_parse::parser::{CommaRecoveryMode, RecoverColon, RecoverComma}; -use rustc_span::Span; - -pub(crate) fn expand<'cx>( - cx: &'cx mut ExtCtxt<'_>, - sp: Span, - tts: TokenStream, -) -> MacroExpanderResult<'cx> { - let (ty, pat) = match parse_pat_ty(cx, tts) { - Ok(parsed) => parsed, - Err(err) => { - return ExpandResult::Ready(DummyResult::any(sp, err.emit_err())); - } - }; - - ExpandResult::Ready(base::MacEager::ty(cx.ty(sp, ast::TyKind::Pat(ty, pat)))) -} - -fn parse_pat_ty<'a>( - cx: &mut ExtCtxt<'a>, - stream: TokenStream, -) -> PResult<'a, (Box, Box)> { - let mut parser = cx.new_parser_from_tts(stream); - - let ty = parser.parse_ty()?; - parser.expect_keyword(exp!(Is))?; - - let start = parser.token.span; - let pat = if parser.eat(exp!(Bang)) { - parser.expect_keyword(exp!(Null))?; - ty_pat(TyPatKind::NotNull, start.to(parser.token.span)) - } else { - pat_to_ty_pat( - cx, - parser.parse_pat_no_top_guard( - None, - RecoverComma::No, - RecoverColon::No, - CommaRecoveryMode::EitherTupleOrPipe, - )?, - ) - }; - - if parser.token != token::Eof { - parser.unexpected()?; - } - - Ok((ty, Box::new(pat))) -} - -fn ty_pat(kind: TyPatKind, span: Span) -> TyPat { - TyPat { id: DUMMY_NODE_ID, kind, span } -} - -fn pat_to_ty_pat(cx: &mut ExtCtxt<'_>, pat: ast::Pat) -> TyPat { - let kind = match pat.kind { - ast::PatKind::Range(start, end, include_end) => TyPatKind::Range( - start.map(|value| Box::new(AnonConst { id: DUMMY_NODE_ID, value })), - end.map(|value| Box::new(AnonConst { id: DUMMY_NODE_ID, value })), - include_end, - ), - ast::PatKind::Or(variants) => { - TyPatKind::Or(variants.into_iter().map(|pat| pat_to_ty_pat(cx, pat)).collect()) - } - ast::PatKind::Err(guar) => TyPatKind::Err(guar), - ast::PatKind::Paren(p) => pat_to_ty_pat(cx, *p).kind, - _ => TyPatKind::Err(cx.dcx().span_err(pat.span, "pattern not supported in pattern types")), - }; - ty_pat(kind, pat.span) -} diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index d6d82a9d2af69..3c9f6bdddc129 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -6,9 +6,10 @@ extern_types, decl_macro, rustc_attrs, + allow_internal_unstable, + forced_keywords, rustc_private, transparent_unions, - pattern_types, auto_traits, freeze_impls )] @@ -591,12 +592,9 @@ pub trait Deref { fn deref(&self) -> &Self::Target; } -#[rustc_builtin_macro(pattern_type)] -#[macro_export] -macro_rules! pattern_type { - ($($arg:tt)*) => { - /* compiler built-in */ - }; +#[allow_internal_unstable(internal_syntax)] +pub macro pattern_type($($arg:tt)*) { + k#pattern_type($($arg)*) } impl CoerceUnsized for pattern_type!(*const T is !null) where diff --git a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs index c53ec2ec6710d..2db42f3bd5930 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs @@ -1,12 +1,4 @@ -#![feature( - no_core, - lang_items, - extern_types, - thread_local, - repr_simd, - pattern_types, - rustc_private -)] +#![feature(no_core, lang_items, extern_types, thread_local, repr_simd, rustc_private)] #![cfg_attr(not(any(jit, target_vendor = "apple", windows)), feature(linkage))] #![no_core] #![allow(dead_code, non_camel_case_types, internal_features)] diff --git a/compiler/rustc_codegen_gcc/build_system/src/test.rs b/compiler/rustc_codegen_gcc/build_system/src/test.rs index fe36adba0587e..5ae6d5fee5770 100644 --- a/compiler/rustc_codegen_gcc/build_system/src/test.rs +++ b/compiler/rustc_codegen_gcc/build_system/src/test.rs @@ -247,6 +247,8 @@ fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> { &"mini_core", &"--crate-type", &crate_types, + &"--edition", + &"2024", &"--target", &args.config_info.target_triple, ]); diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index 383fbfc678922..e5e8f6042e4a2 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -6,10 +6,11 @@ extern_types, decl_macro, rustc_attrs, + allow_internal_unstable, + forced_keywords, transparent_unions, auto_traits, freeze_impls, - pattern_types, thread_local, rustc_private )] @@ -40,9 +41,9 @@ unsafe extern "C" { type VTable; } -#[no_mangle] +#[unsafe(no_mangle)] unsafe extern "C" fn _Unwind_Resume() { - intrinsics::unreachable(); + unsafe { intrinsics::unreachable(); } } #[lang = "pointee_sized"] @@ -607,12 +608,9 @@ impl Allocator for Global {} #[rustc_nonnull_optimization_guaranteed] pub struct NonNull(pub pattern_type!(*const T is !null)); -#[rustc_builtin_macro(pattern_type)] -#[macro_export] -macro_rules! pattern_type { - ($($arg:tt)*) => { - /* compiler built-in */ - }; +#[allow_internal_unstable(internal_syntax)] +pub macro pattern_type($($arg:tt)*) { + k#pattern_type($($arg)*) } impl CoerceUnsized for pattern_type!(*const T is !null) where @@ -703,11 +701,11 @@ pub mod intrinsics { #[rustc_intrinsic] pub const fn size_of() -> usize; #[rustc_intrinsic] - pub unsafe fn size_of_val(val: *const T) -> usize; + pub unsafe fn size_of_val(val: *const T) -> usize; #[rustc_intrinsic] pub const fn align_of() -> usize; #[rustc_intrinsic] - pub unsafe fn align_of_val(val: *const T) -> usize; + pub unsafe fn align_of_val(val: *const T) -> usize; #[rustc_intrinsic] pub unsafe fn copy(src: *const T, dst: *mut T, count: usize); #[rustc_intrinsic] @@ -715,7 +713,7 @@ pub mod intrinsics { #[rustc_intrinsic] pub unsafe fn ctlz_nonzero(x: T) -> u32; #[rustc_intrinsic] - pub const fn needs_drop() -> bool; + pub const fn needs_drop() -> bool; #[rustc_intrinsic] pub fn bitreverse(x: T) -> T; #[rustc_intrinsic] @@ -728,7 +726,7 @@ pub mod intrinsics { pub mod libc { #[link(name = "c")] - extern "C" { + unsafe extern "C" { pub fn puts(s: *const u8) -> i32; pub fn printf(format: *const i8, ...) -> i32; pub fn malloc(size: usize) -> *mut u8; @@ -783,7 +781,7 @@ impl Index for [T] { } } -extern "C" { +unsafe extern "C" { type VaListImpl; } @@ -824,7 +822,7 @@ struct PanicLocation { column: u32, } -#[no_mangle] +#[unsafe(no_mangle)] pub fn get_tls() -> u8 { #[thread_local] static A: u8 = 42; diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 7f82aeb0cbc63..088ee8ebfe0ec 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -10,6 +10,7 @@ #![allow(internal_features)] #![allow(rustc::default_hash_types)] #![allow(rustc::potential_query_instability)] +#![cfg_attr(bootstrap, feature(pattern_type_macro))] #![cfg_attr(bootstrap, feature(ptr_alignment_type))] #![cfg_attr(bootstrap, feature(unwrap_infallible))] #![cfg_attr(test, feature(test))] @@ -27,7 +28,6 @@ #![feature(min_specialization)] #![feature(negative_impls)] #![feature(nonzero_internals)] -#![feature(pattern_type_macro)] #![feature(pattern_types)] #![feature(rustc_attrs)] #![feature(sized_hierarchy)] diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 57e9d1d5e137d..a0d3e6e6d0de7 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -318,8 +318,6 @@ declare_features! ( (internal, needs_panic_runtime, "1.10.0", Some(32837)), /// Allows using the `#![panic_runtime]` attribute. (internal, panic_runtime, "1.10.0", Some(32837)), - /// Allows using pattern types. - (internal, pattern_types, "1.79.0", Some(123646)), /// Allows `repr(simd)` and importing the various simd intrinsics. (internal, repr_simd, "1.4.0", Some(27731)), /// Allows using compiler's own crates. diff --git a/compiler/rustc_index_macros/src/lib.rs b/compiler/rustc_index_macros/src/lib.rs index b0bc40a9d8b1a..86681332ceb47 100644 --- a/compiler/rustc_index_macros/src/lib.rs +++ b/compiler/rustc_index_macros/src/lib.rs @@ -41,7 +41,7 @@ mod newtype; rustc_attrs, trusted_step, pattern_types, - pattern_type_macro, + pattern_type_macro, // cfg(bootstrap) FIXME: remove on bump structural_match, ) )] diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index b66d7310dbea5..029aab9e0e601 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -4,7 +4,7 @@ use rustc_ast::{ self as ast, BoundAsyncness, BoundConstness, BoundPolarity, DUMMY_NODE_ID, FnPtrTy, FnRetTy, GenericBound, GenericBounds, GenericParam, Generics, Lifetime, MacCall, Mutability, Path, Pinnedness, PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty, - TyKind, UnsafeBinderTy, + TyKind, TyPatKind, UnsafeBinderTy, }; use rustc_errors::{Applicability, Diag, E0516, PResult}; use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym}; @@ -423,6 +423,8 @@ impl<'a> Parser<'a> { self.parse_unsafe_binder_ty()? } else if self.eat_forced_keyword_noexpect(kw::FieldOf) { self.parse_ty_field_of(lo)? + } else if self.eat_forced_keyword_noexpect(kw::PatternType) { + self.parse_pat_ty(lo)? } else { let msg = format!("expected type, found {}", super::token_descr(&self.token)); let mut err = self.dcx().struct_span_err(lo, msg); @@ -826,7 +828,7 @@ impl<'a> Parser<'a> { Ok(TyKind::Err(guar)) } - pub(crate) fn parse_ty_field_of(&mut self, lo: Span) -> PResult<'a, TyKind> { + fn parse_ty_field_of(&mut self, lo: Span) -> PResult<'a, TyKind> { self.expect(exp!(OpenParen))?; let container = self.parse_ty()?; @@ -871,6 +873,56 @@ impl<'a> Parser<'a> { } } + fn parse_pat_ty(&mut self, lo: Span) -> PResult<'a, TyKind> { + self.expect(exp!(OpenParen))?; + + let ty = self.parse_ty()?; + self.expect_keyword(exp!(Is))?; + + let pat = if self.eat(exp!(Bang)) { + let lo = self.prev_token.span; + self.expect_keyword(exp!(Null))?; + Self::mk_ty_pat(TyPatKind::NotNull, lo.to(self.token.span)) + } else { + let pat = self.parse_pat_no_top_guard( + None, + super::RecoverComma::No, + super::RecoverColon::No, + super::CommaRecoveryMode::EitherTupleOrPipe, + )?; + self.pat_to_ty_pat(pat) + }; + + self.expect(exp!(CloseParen))?; + + self.psess.gated_spans.gate(sym::internal_syntax, lo.to(self.token.span)); + + Ok(TyKind::Pat(ty, Box::new(pat))) + } + + fn pat_to_ty_pat(&self, pat: ast::Pat) -> ast::TyPat { + let kind = match pat.kind { + ast::PatKind::Range(start, end, include_end) => TyPatKind::Range( + start.map(|value| Box::new(ast::AnonConst { id: DUMMY_NODE_ID, value })), + end.map(|value| Box::new(ast::AnonConst { id: DUMMY_NODE_ID, value })), + include_end, + ), + ast::PatKind::Or(variants) => { + TyPatKind::Or(variants.into_iter().map(|pat| self.pat_to_ty_pat(pat)).collect()) + } + ast::PatKind::Err(guar) => TyPatKind::Err(guar), + ast::PatKind::Paren(p) => self.pat_to_ty_pat(*p).kind, + _ => TyPatKind::Err( + self.dcx().span_err(pat.span, "pattern not supported in pattern types"), + ), + }; + Self::mk_ty_pat(kind, pat.span) + } + + fn mk_ty_pat(kind: TyPatKind, span: Span) -> ast::TyPat { + ast::TyPat { id: DUMMY_NODE_ID, kind, span } + } + /// Parses a function pointer type (`TyKind::FnPtr`). /// ```ignore (illustrative) /// [unsafe] [extern "ABI"] fn (S) -> T diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 650aa6d3205da..5c6998685e606 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -133,6 +133,7 @@ symbols! { FieldOf: "field_of", MacroRules: "macro_rules", OffsetOf: "offset_of", + PatternType: "pattern_type", Pin: "pin", Raw: "raw", Reuse: "reuse", @@ -1609,7 +1610,6 @@ symbols! { path, pattern_complexity_limit, pattern_parentheses, - pattern_type, pattern_type_range_trait, pattern_types, phantom_data, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 822e62b5867ac..b2000fa7192a2 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -98,7 +98,7 @@ #![feature(io_const_error)] #![feature(offset_of_enum)] #![feature(panic_internals)] -#![feature(pattern_type_macro)] +#![feature(pattern_types)] #![feature(ub_checks)] // tidy-alphabetical-end // @@ -146,7 +146,6 @@ #![feature(must_not_suspend)] #![feature(negative_impls)] #![feature(no_core)] -#![feature(pattern_types)] #![feature(pin_macro_internals)] #![feature(prelude_import)] #![feature(register_tool)] @@ -314,7 +313,7 @@ pub mod option; pub mod os; pub mod panic; pub mod panicking; -#[unstable(feature = "pattern_type_macro", issue = "123646")] +#[unstable(feature = "pattern_types", issue = "123646")] pub mod pat; pub mod pin; #[unstable(feature = "abort_immediate", issue = "154601")] diff --git a/library/core/src/num/niche_types.rs b/library/core/src/num/niche_types.rs index 37037d8145fb0..6d3e59b05a2c3 100644 --- a/library/core/src/num/niche_types.rs +++ b/library/core/src/num/niche_types.rs @@ -5,9 +5,10 @@ )] use crate::cmp::Ordering; +use crate::fmt; use crate::hash::{Hash, Hasher}; use crate::marker::StructuralPartialEq; -use crate::{fmt, pattern_type}; +use crate::pat::pattern_type; macro_rules! define_valid_range_type { ($( diff --git a/library/core/src/pat.rs b/library/core/src/pat.rs index 0cf9f10fc8c28..1315c2a46d128 100644 --- a/library/core/src/pat.rs +++ b/library/core/src/pat.rs @@ -7,13 +7,11 @@ use crate::ops::{CoerceUnsized, DispatchFromDyn}; /// ```ignore (cannot test this from within core yet) /// type Positive = std::pat::pattern_type!(i32 is 1..); /// ``` -#[macro_export] -#[rustc_builtin_macro(pattern_type)] -#[unstable(feature = "pattern_type_macro", issue = "123646")] -macro_rules! pattern_type { - ($($arg:tt)*) => { - /* compiler built-in */ - }; +#[allow_internal_unstable(internal_syntax)] +#[unstable(feature = "pattern_types", issue = "123646")] +#[diagnostic::opaque] +pub macro pattern_type($( $arg:tt )*) { + k#pattern_type($( $arg )*) } /// A trait implemented for integer types and `char`. diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index f68d3e614c53f..d21fa351f5bce 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -104,9 +104,9 @@ pub use crate::const_format_args; #[doc(no_inline)] pub use crate::log_syntax; -#[unstable(feature = "pattern_type_macro", issue = "123646")] +#[unstable(feature = "pattern_types", issue = "123646")] #[doc(no_inline)] -pub use crate::pattern_type; +pub use crate::pat::pattern_type; #[unstable( feature = "trace_macros", diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 7d444cc8698a5..cf23690992ef1 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -76,7 +76,7 @@ use crate::{fmt, hash, intrinsics, mem, ptr}; #[rustc_nonnull_optimization_guaranteed] #[lang = "non_null"] pub struct NonNull<#[rustc_assert_variance(covariant)] T: PointeeSized> { - pointer: crate::pattern_type!(*const T is !null), + pointer: crate::pat::pattern_type!(*const T is !null), } /// `NonNull` pointers are not `Send` because the data they reference may be aliased. diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 1f684c162496b..0c3d29324c9ae 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -641,7 +641,7 @@ pub mod num; #[allow(unreachable_pub)] pub mod os; pub mod panic; -#[unstable(feature = "pattern_type_macro", issue = "123646")] +#[unstable(feature = "pattern_types", issue = "123646")] pub mod pat; pub mod path; pub mod process; diff --git a/library/std/src/pat.rs b/library/std/src/pat.rs index aeddd84c2cb54..3d227b1903f33 100644 --- a/library/std/src/pat.rs +++ b/library/std/src/pat.rs @@ -1,3 +1,3 @@ //! Helper module for exporting the `pattern_type` macro -pub use core::pattern_type; +pub use core::pat::pattern_type; diff --git a/src/tools/clippy/tests/ui/eager_transmute.fixed b/src/tools/clippy/tests/ui/eager_transmute.fixed index a62b4ff7c75e5..30e741755d9b4 100644 --- a/src/tools/clippy/tests/ui/eager_transmute.fixed +++ b/src/tools/clippy/tests/ui/eager_transmute.fixed @@ -1,4 +1,4 @@ -#![feature(rustc_attrs, pattern_types, pattern_type_macro)] +#![feature(rustc_attrs, pattern_types)] #![warn(clippy::eager_transmute)] #![expect(clippy::missing_transmute_annotations, clippy::transmute_int_to_non_zero)] diff --git a/src/tools/clippy/tests/ui/eager_transmute.rs b/src/tools/clippy/tests/ui/eager_transmute.rs index cc6fbc2ebd37d..c9f4c19d8837d 100644 --- a/src/tools/clippy/tests/ui/eager_transmute.rs +++ b/src/tools/clippy/tests/ui/eager_transmute.rs @@ -1,4 +1,4 @@ -#![feature(rustc_attrs, pattern_types, pattern_type_macro)] +#![feature(rustc_attrs, pattern_types)] #![warn(clippy::eager_transmute)] #![expect(clippy::missing_transmute_annotations, clippy::transmute_int_to_non_zero)] diff --git a/src/tools/miri/tests/fail/validity/nonzero.rs b/src/tools/miri/tests/fail/validity/nonzero.rs index fba37ee170e3a..1e847c4792442 100644 --- a/src/tools/miri/tests/fail/validity/nonzero.rs +++ b/src/tools/miri/tests/fail/validity/nonzero.rs @@ -1,4 +1,4 @@ -#![feature(rustc_attrs, pattern_types, pattern_type_macro)] +#![feature(rustc_attrs, pattern_types)] #![allow(unused_attributes)] #[repr(transparent)] diff --git a/src/tools/miri/tests/pass/pattern-types.rs b/src/tools/miri/tests/pass/pattern-types.rs index 90fe0de546915..2422f79d25d88 100644 --- a/src/tools/miri/tests/pass/pattern-types.rs +++ b/src/tools/miri/tests/pass/pattern-types.rs @@ -1,4 +1,4 @@ -#![feature(pattern_types, pattern_type_macro, sized_hierarchy)] +#![feature(pattern_types, sized_hierarchy)] #![allow(dead_code)] use std::marker::PointeeSized; diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index fab7f2098ea1c..d023f29d2dce8 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -57,7 +57,7 @@ pub fn rustc_minicore() -> Rustc { let mut builder = rustc(); let minicore_path = source_root().join("tests/auxiliary/minicore.rs"); - builder.input(minicore_path).crate_name("minicore").crate_type("rlib"); + builder.input(minicore_path).crate_name("minicore").crate_type("rlib").edition("2024"); builder } diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index 737587c4d5403..aca69642057ab 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -24,11 +24,12 @@ lang_items, adt_const_params, auto_traits, + forced_keywords, freeze_impls, negative_impls, - pattern_types, rustc_attrs, decl_macro, + allow_internal_unstable, f16, f16b, cfg_target_has_reliable_f16b, @@ -522,12 +523,9 @@ pub enum c_void { __variant2, } -#[rustc_builtin_macro(pattern_type)] -#[macro_export] -macro_rules! pattern_type { - ($($arg:tt)*) => { - /* compiler built-in */ - }; +#[allow_internal_unstable(internal_syntax)] +pub macro pattern_type($($arg:tt)*) { + k#pattern_type($($arg)*) } #[lang = "Ordering"] diff --git a/tests/codegen-llvm/enum/enum-aggregate.rs b/tests/codegen-llvm/enum/enum-aggregate.rs index 46a1a03e96371..1e359480ad6a6 100644 --- a/tests/codegen-llvm/enum/enum-aggregate.rs +++ b/tests/codegen-llvm/enum/enum-aggregate.rs @@ -2,7 +2,7 @@ //@ only-64bit #![crate_type = "lib"] -#![feature(pattern_types, pattern_type_macro)] +#![feature(pattern_types)] use std::cmp::Ordering; use std::num::NonZero; diff --git a/tests/codegen-llvm/pattern_type_symbols.rs b/tests/codegen-llvm/pattern_type_symbols.rs index a90262ff12d21..f20940780d84d 100644 --- a/tests/codegen-llvm/pattern_type_symbols.rs +++ b/tests/codegen-llvm/pattern_type_symbols.rs @@ -4,11 +4,10 @@ //@ compile-flags: -Csymbol-mangling-version=v0 -Copt-level=0 --crate-type=lib #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; -type NanoU32 = crate::pattern_type!(u32 is 0..=999_999_999); +type NanoU32 = pattern_type!(u32 is 0..=999_999_999); fn foo() {} diff --git a/tests/debuginfo/msvc-pretty-enums.rs b/tests/debuginfo/msvc-pretty-enums.rs index d418d8f0987e6..2ec127390ca75 100644 --- a/tests/debuginfo/msvc-pretty-enums.rs +++ b/tests/debuginfo/msvc-pretty-enums.rs @@ -232,7 +232,7 @@ //@ cdb-command: dx c_style_i128_d //@ cdb-check: c_style_i128_d : D [Type: enum2$] -#![feature(pattern_types, pattern_type_macro)] +#![feature(pattern_types)] use std::num::NonZero; @@ -271,9 +271,7 @@ enum NicheLayoutWithFields3 { } #[repr(transparent)] -struct Wrapping128( - std::pat::pattern_type!(i128 is -2..=1), -); +struct Wrapping128(std::pat::pattern_type!(i128 is -2..=1)); enum Wrapping128Niche { X(Wrapping128), diff --git a/tests/mir-opt/dataflow-const-prop/enum.rs b/tests/mir-opt/dataflow-const-prop/enum.rs index 80553a3974881..454e2849597f1 100644 --- a/tests/mir-opt/dataflow-const-prop/enum.rs +++ b/tests/mir-opt/dataflow-const-prop/enum.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Zdump-mir-exclude-alloc-bytes // EMIT_MIR_FOR_EACH_BIT_WIDTH -#![feature(custom_mir, core_intrinsics, rustc_attrs, pattern_types, pattern_type_macro)] +#![feature(custom_mir, core_intrinsics, rustc_attrs, pattern_types)] use std::intrinsics::mir::*; diff --git a/tests/mir-opt/gvn.rs b/tests/mir-opt/gvn.rs index 2ce475f7401ac..366af8355c031 100644 --- a/tests/mir-opt/gvn.rs +++ b/tests/mir-opt/gvn.rs @@ -6,7 +6,7 @@ #![feature(rustc_attrs)] #![feature(custom_mir)] #![feature(core_intrinsics)] -#![feature(freeze, pattern_type_range_trait, const_trait_impl, pattern_types, pattern_type_macro)] +#![feature(freeze, pattern_type_range_trait, const_trait_impl, pattern_types)] #![allow(ambiguous_wide_pointer_comparisons)] #![allow(unconditional_panic)] #![allow(unnecessary_transmutes)] diff --git a/tests/mir-opt/jump_threading.rs b/tests/mir-opt/jump_threading.rs index ae56921bb1d44..cdf49fb36bef4 100644 --- a/tests/mir-opt/jump_threading.rs +++ b/tests/mir-opt/jump_threading.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Zmir-enable-passes=+Inline // EMIT_MIR_FOR_EACH_PANIC_STRATEGY -#![feature(try_trait_v2, pattern_type_macro, pattern_types)] +#![feature(try_trait_v2, pattern_types)] #![feature(custom_mir, core_intrinsics, rustc_attrs)] use std::intrinsics::mir::*; diff --git a/tests/mir-opt/pattern_types.rs b/tests/mir-opt/pattern_types.rs index dfa4c40d2dd7b..c714060619c16 100644 --- a/tests/mir-opt/pattern_types.rs +++ b/tests/mir-opt/pattern_types.rs @@ -1,5 +1,4 @@ #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/rustdoc-html/pattern-types-implementors.rs b/tests/rustdoc-html/pattern-types-implementors.rs index 2f49837b27e74..030b8b85f58dc 100644 --- a/tests/rustdoc-html/pattern-types-implementors.rs +++ b/tests/rustdoc-html/pattern-types-implementors.rs @@ -1,4 +1,4 @@ -#![feature(pattern_types, pattern_type_macro)] +#![feature(pattern_types)] #![crate_name = "pattern_types_implementors"] use std::pat::pattern_type; diff --git a/tests/ui/consts/const-eval/raw-bytes.rs b/tests/ui/consts/const-eval/raw-bytes.rs index c682a17b8decf..8d13b5513fb9f 100644 --- a/tests/ui/consts/const-eval/raw-bytes.rs +++ b/tests/ui/consts/const-eval/raw-bytes.rs @@ -4,7 +4,7 @@ // ignore-tidy-file-linelength #![allow(invalid_value, unnecessary_transmutes)] -#![feature(pattern_types, pattern_type_macro)] +#![feature(pattern_types)] #![feature(rustc_attrs, ptr_metadata, slice_from_ptr_range, const_slice_from_ptr_range)] use std::mem; diff --git a/tests/ui/consts/const-eval/ub-ref-ptr.rs b/tests/ui/consts/const-eval/ub-ref-ptr.rs index 9cd47e4b155e3..eadb7ccf1126c 100644 --- a/tests/ui/consts/const-eval/ub-ref-ptr.rs +++ b/tests/ui/consts/const-eval/ub-ref-ptr.rs @@ -6,7 +6,7 @@ //@ normalize-stderr: "0x[0-9](\.\.|\])" -> "0x%$1" //@ normalize-stderr: "╾ALLOC\$ID╼\s+│.*╾.*╼" -> "╾ALLOC$$ID╼ │ ╾─╼" -#![feature(pattern_types, pattern_type_macro)] +#![feature(pattern_types)] #![allow(invalid_value)] use std::{mem, pat::pattern_type}; diff --git a/tests/ui/enum-discriminant/ptr_niche.rs b/tests/ui/enum-discriminant/ptr_niche.rs index 45dbe50248217..4390b69de0516 100644 --- a/tests/ui/enum-discriminant/ptr_niche.rs +++ b/tests/ui/enum-discriminant/ptr_niche.rs @@ -2,7 +2,7 @@ //! Check that we can codegen setting and getting discriminants, including non-null niches, //! for enums with a pointer-like ABI. This used to crash llvm. -#![feature(rustc_attrs, pattern_types, pattern_type_macro)] +#![feature(rustc_attrs, pattern_types)] use std::{ptr, mem, pat::pattern_type}; #[derive(Copy, Clone)] diff --git a/tests/ui/lint/clashing-extern-fn.rs b/tests/ui/lint/clashing-extern-fn.rs index e4477c9620221..195aab24899cf 100644 --- a/tests/ui/lint/clashing-extern-fn.rs +++ b/tests/ui/lint/clashing-extern-fn.rs @@ -1,7 +1,7 @@ //@ check-pass //@ aux-build:external_extern_fn.rs #![crate_type = "lib"] -#![feature(pattern_type_macro, pattern_types)] +#![feature(pattern_types)] mod redeclared_different_signature { mod a { extern "C" { diff --git a/tests/ui/lint/invalid_value.rs b/tests/ui/lint/invalid_value.rs index 301283853eb26..f76d988f44c68 100644 --- a/tests/ui/lint/invalid_value.rs +++ b/tests/ui/lint/invalid_value.rs @@ -2,7 +2,7 @@ // in a lint. #![allow(deprecated)] #![deny(invalid_value)] -#![feature(rustc_attrs, pattern_types, pattern_type_macro)] +#![feature(rustc_attrs, pattern_types)] use std::mem::{self, MaybeUninit}; use std::num::NonZero; diff --git a/tests/ui/mir/ssa-analysis-regression-50041.rs b/tests/ui/mir/ssa-analysis-regression-50041.rs index 28690624f63ec..37d78acc2c452 100644 --- a/tests/ui/mir/ssa-analysis-regression-50041.rs +++ b/tests/ui/mir/ssa-analysis-regression-50041.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Z mir-opt-level=4 #![crate_type = "lib"] -#![feature(lang_items, pattern_type_macro, pattern_types)] +#![feature(lang_items, pattern_types)] #![no_std] struct NonNull(pattern_type!(*const T is !null)); diff --git a/tests/ui/pattern/overflowing-literals.rs b/tests/ui/pattern/overflowing-literals.rs index 13016d3f7d197..9e33d49963ee0 100644 --- a/tests/ui/pattern/overflowing-literals.rs +++ b/tests/ui/pattern/overflowing-literals.rs @@ -1,7 +1,6 @@ //! Check that overflowing literals are in patterns are rejected #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/pattern/overflowing-literals.stderr b/tests/ui/pattern/overflowing-literals.stderr index 8164b97fd4720..54525cf6cd9f8 100644 --- a/tests/ui/pattern/overflowing-literals.stderr +++ b/tests/ui/pattern/overflowing-literals.stderr @@ -1,5 +1,5 @@ error: literal out of range for `u8` - --> $DIR/overflowing-literals.rs:8:35 + --> $DIR/overflowing-literals.rs:7:35 | LL | type TooBig = pattern_type!(u8 is 500..); | ^^^ @@ -8,7 +8,7 @@ LL | type TooBig = pattern_type!(u8 is 500..); = note: `#[deny(overflowing_literals)]` on by default error: literal out of range for `i8` - --> $DIR/overflowing-literals.rs:10:37 + --> $DIR/overflowing-literals.rs:9:37 | LL | type TooSmall = pattern_type!(i8 is -500..); | ^^^^ @@ -17,7 +17,7 @@ LL | type TooSmall = pattern_type!(i8 is -500..); = help: consider using the type `i16` instead error: literal out of range for `i8` - --> $DIR/overflowing-literals.rs:12:41 + --> $DIR/overflowing-literals.rs:11:41 | LL | type TooBigSigned = pattern_type!(i8 is 200..); | ^^^ @@ -26,7 +26,7 @@ LL | type TooBigSigned = pattern_type!(i8 is 200..); = help: consider using the type `u8` instead error: literal out of range for `u8` - --> $DIR/overflowing-literals.rs:17:9 + --> $DIR/overflowing-literals.rs:16:9 | LL | 500 => {} | ^^^ diff --git a/tests/ui/print_type_sizes/niche-filling.rs b/tests/ui/print_type_sizes/niche-filling.rs index 2fcb1dfe3c8c2..ecd243cd01ba8 100644 --- a/tests/ui/print_type_sizes/niche-filling.rs +++ b/tests/ui/print_type_sizes/niche-filling.rs @@ -15,7 +15,7 @@ // ^-- needed because `--pass check` does not emit the output needed. // FIXME: consider using an attribute instead of side-effects. #![allow(dead_code)] -#![feature(rustc_attrs, pattern_types, pattern_type_macro)] +#![feature(rustc_attrs, pattern_types)] use std::num::NonZero; diff --git a/tests/ui/type/pattern_types/assoc_const.default.stderr b/tests/ui/type/pattern_types/assoc_const.default.stderr index 8b1184877af83..db79eaff48753 100644 --- a/tests/ui/type/pattern_types/assoc_const.default.stderr +++ b/tests/ui/type/pattern_types/assoc_const.default.stderr @@ -1,5 +1,5 @@ error: generic parameters may not be used in const operations - --> $DIR/assoc_const.rs:17:41 + --> $DIR/assoc_const.rs:15:41 | LL | fn foo(_: pattern_type!(u32 is ::START..=::END)) {} | ^ cannot perform const operation using `T` @@ -9,7 +9,7 @@ LL | fn foo(_: pattern_type!(u32 is ::START..=::END) = help: alternatively, you can use `#![feature(gca_const_items)]` and wrap the expression in the `gca!` macro error: generic parameters may not be used in const operations - --> $DIR/assoc_const.rs:17:61 + --> $DIR/assoc_const.rs:15:61 | LL | fn foo(_: pattern_type!(u32 is ::START..=::END)) {} | ^ cannot perform const operation using `T` @@ -19,7 +19,7 @@ LL | fn foo(_: pattern_type!(u32 is ::START..=::END) = help: alternatively, you can use `#![feature(gca_const_items)]` and wrap the expression in the `gca!` macro error: generic parameters may not be used in const operations - --> $DIR/assoc_const.rs:20:40 + --> $DIR/assoc_const.rs:18:40 | LL | fn bar(_: pattern_type!(u32 is T::START..=T::END)) {} | ^ cannot perform const operation using `T` @@ -29,7 +29,7 @@ LL | fn bar(_: pattern_type!(u32 is T::START..=T::END)) {} = help: alternatively, you can use `#![feature(gca_const_items)]` and wrap the expression in the `gca!` macro error: generic parameters may not be used in const operations - --> $DIR/assoc_const.rs:20:51 + --> $DIR/assoc_const.rs:18:51 | LL | fn bar(_: pattern_type!(u32 is T::START..=T::END)) {} | ^ cannot perform const operation using `T` diff --git a/tests/ui/type/pattern_types/assoc_const.rs b/tests/ui/type/pattern_types/assoc_const.rs index 90508801990e8..6b5de2042f5d0 100644 --- a/tests/ui/type/pattern_types/assoc_const.rs +++ b/tests/ui/type/pattern_types/assoc_const.rs @@ -1,7 +1,5 @@ #![feature(pattern_types)] -#![feature(pattern_type_macro)] #![cfg_attr(const_arg, feature(generic_const_exprs, generic_pattern_types))] -#![expect(incomplete_features)] // gate-test-generic_pattern_types line to the test file. //@ revisions: default const_arg diff --git a/tests/ui/type/pattern_types/bad_pat.rs b/tests/ui/type/pattern_types/bad_pat.rs index 7e2b4cb996f27..75c8169188011 100644 --- a/tests/ui/type/pattern_types/bad_pat.rs +++ b/tests/ui/type/pattern_types/bad_pat.rs @@ -1,5 +1,4 @@ #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; @@ -12,7 +11,7 @@ type Wild = pattern_type!(() is _); // FIXME: confusing diagnostic because `not` can be a binding type NonNull = pattern_type!(*const () is not null); -//~^ ERROR: expected one of `@` or `|`, found `null` +//~^ ERROR: expected one of //~| ERROR: pattern not supported in pattern types type NonNull2 = pattern_type!(*const () is !nil); diff --git a/tests/ui/type/pattern_types/bad_pat.stderr b/tests/ui/type/pattern_types/bad_pat.stderr index e72279542280c..07ced579c6512 100644 --- a/tests/ui/type/pattern_types/bad_pat.stderr +++ b/tests/ui/type/pattern_types/bad_pat.stderr @@ -1,5 +1,5 @@ error[E0586]: inclusive range with no end - --> $DIR/bad_pat.rs:6:43 + --> $DIR/bad_pat.rs:5:43 | LL | type NonNullU32_2 = pattern_type!(u32 is 1..=); | ^^^ @@ -12,7 +12,7 @@ LL + type NonNullU32_2 = pattern_type!(u32 is 1..); | error[E0586]: inclusive range with no end - --> $DIR/bad_pat.rs:8:40 + --> $DIR/bad_pat.rs:7:40 | LL | type Positive2 = pattern_type!(i32 is 0..=); | ^^^ @@ -25,25 +25,25 @@ LL + type Positive2 = pattern_type!(i32 is 0..); | error: pattern not supported in pattern types - --> $DIR/bad_pat.rs:10:33 + --> $DIR/bad_pat.rs:9:33 | LL | type Wild = pattern_type!(() is _); | ^ error: pattern not supported in pattern types - --> $DIR/bad_pat.rs:14:43 + --> $DIR/bad_pat.rs:13:43 | LL | type NonNull = pattern_type!(*const () is not null); | ^^^ -error: expected one of `@` or `|`, found `null` - --> $DIR/bad_pat.rs:14:47 +error: expected one of `)`, `@`, or `|`, found `null` + --> $DIR/bad_pat.rs:13:47 | LL | type NonNull = pattern_type!(*const () is not null); - | ^^^^ expected one of `@` or `|` + | ^^^^ expected one of `)`, `@`, or `|` error: expected `null`, found `nil` - --> $DIR/bad_pat.rs:18:45 + --> $DIR/bad_pat.rs:17:45 | LL | type NonNull2 = pattern_type!(*const () is !nil); | ^^^ expected `null` diff --git a/tests/ui/type/pattern_types/chars.rs b/tests/ui/type/pattern_types/chars.rs index 9073998b387b7..285c4f3abdf75 100644 --- a/tests/ui/type/pattern_types/chars.rs +++ b/tests/ui/type/pattern_types/chars.rs @@ -3,7 +3,6 @@ //@ check-pass #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/const_generics.rs b/tests/ui/type/pattern_types/const_generics.rs index f5eb90e94d4fd..aff5e72f2c9e8 100644 --- a/tests/ui/type/pattern_types/const_generics.rs +++ b/tests/ui/type/pattern_types/const_generics.rs @@ -3,7 +3,7 @@ //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver -#![feature(pattern_types, generic_pattern_types, pattern_type_macro)] +#![feature(pattern_types, generic_pattern_types)] #![expect(incomplete_features)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/derives.rs b/tests/ui/type/pattern_types/derives.rs index 12af19e5f7ea6..2a3d1164c9772 100644 --- a/tests/ui/type/pattern_types/derives.rs +++ b/tests/ui/type/pattern_types/derives.rs @@ -2,7 +2,6 @@ //! Exceptions are `Clone` and `Copy`, which have builtin impls for pattern types. #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; @@ -11,7 +10,7 @@ use std::pat::pattern_type; struct Nanoseconds(NanoI32); //~^ ERROR: binary operation `==` cannot be applied to type `pattern_type!(i32 is 0..=999999999)` -type NanoI32 = crate::pattern_type!(i32 is 0..=999_999_999); +type NanoI32 = pattern_type!(i32 is 0..=999_999_999); fn main() { let x = Nanoseconds(unsafe { std::mem::transmute(42) }); diff --git a/tests/ui/type/pattern_types/derives.stderr b/tests/ui/type/pattern_types/derives.stderr index 6fb0c0994082a..f196cec5a1dc5 100644 --- a/tests/ui/type/pattern_types/derives.stderr +++ b/tests/ui/type/pattern_types/derives.stderr @@ -1,5 +1,5 @@ error[E0369]: binary operation `==` cannot be applied to type `pattern_type!(i32 is 0..=999999999)` - --> $DIR/derives.rs:11:20 + --> $DIR/derives.rs:10:20 | LL | #[derive(Clone, Copy, PartialEq)] | --------- in this derive macro expansion diff --git a/tests/ui/type/pattern_types/derives_fail.rs b/tests/ui/type/pattern_types/derives_fail.rs index 8251fa9f38c0b..60b4eb06db901 100644 --- a/tests/ui/type/pattern_types/derives_fail.rs +++ b/tests/ui/type/pattern_types/derives_fail.rs @@ -2,7 +2,6 @@ //! Exceptions are `Clone` and `Copy`, which have bultin impls for pattern types. #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; @@ -16,7 +15,7 @@ struct Nanoseconds(NanoI32); //~| ERROR: the trait bound `pattern_type!(i32 is 0..=999999999): Default` is not satisfied //~| ERROR: `==` cannot be applied -type NanoI32 = crate::pattern_type!(i32 is 0..=999_999_999); +type NanoI32 = pattern_type!(i32 is 0..=999_999_999); fn main() { let x = Nanoseconds(unsafe { std::mem::transmute(42) }); diff --git a/tests/ui/type/pattern_types/derives_fail.stderr b/tests/ui/type/pattern_types/derives_fail.stderr index a6814d8cba2a0..ac194b9be8990 100644 --- a/tests/ui/type/pattern_types/derives_fail.stderr +++ b/tests/ui/type/pattern_types/derives_fail.stderr @@ -1,5 +1,5 @@ error[E0369]: binary operation `==` cannot be applied to type `pattern_type!(i32 is 0..=999999999)` - --> $DIR/derives_fail.rs:11:20 + --> $DIR/derives_fail.rs:10:20 | LL | #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash, Default)] | --------- in this derive macro expansion @@ -8,7 +8,7 @@ LL | struct Nanoseconds(NanoI32); | ^^^^^^^ error[E0277]: the trait bound `pattern_type!(i32 is 0..=999999999): Eq` is not satisfied - --> $DIR/derives_fail.rs:11:20 + --> $DIR/derives_fail.rs:10:20 | LL | #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash, Default)] | -- in this derive macro expansion @@ -20,7 +20,7 @@ note: required by a bound in `std::cmp::AssertParamIsEq` --> $SRC_DIR/core/src/cmp.rs:LL:COL error[E0277]: `pattern_type!(i32 is 0..=999999999)` doesn't implement `Debug` - --> $DIR/derives_fail.rs:11:20 + --> $DIR/derives_fail.rs:10:20 | LL | #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash, Default)] | ----- in this derive macro expansion @@ -29,7 +29,7 @@ LL | struct Nanoseconds(NanoI32); | ^^^^^^^ the trait `Debug` is not implemented for `pattern_type!(i32 is 0..=999999999)` error[E0277]: the trait bound `pattern_type!(i32 is 0..=999999999): Ord` is not satisfied - --> $DIR/derives_fail.rs:11:20 + --> $DIR/derives_fail.rs:10:20 | LL | #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash, Default)] | --- in this derive macro expansion @@ -38,7 +38,7 @@ LL | struct Nanoseconds(NanoI32); | ^^^^^^^ the trait `Ord` is not implemented for `pattern_type!(i32 is 0..=999999999)` error[E0277]: the trait bound `pattern_type!(i32 is 0..=999999999): Hash` is not satisfied - --> $DIR/derives_fail.rs:11:20 + --> $DIR/derives_fail.rs:10:20 | LL | #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash, Default)] | ---- in this derive macro expansion @@ -47,7 +47,7 @@ LL | struct Nanoseconds(NanoI32); | ^^^^^^^ the trait `Hash` is not implemented for `pattern_type!(i32 is 0..=999999999)` error[E0277]: the trait bound `pattern_type!(i32 is 0..=999999999): Default` is not satisfied - --> $DIR/derives_fail.rs:11:20 + --> $DIR/derives_fail.rs:10:20 | LL | #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash, Default)] | ------- in this derive macro expansion diff --git a/tests/ui/type/pattern_types/feature-gate-pattern_types.stderr b/tests/ui/type/pattern_types/feature-gate-pattern_types.disabled.stderr similarity index 64% rename from tests/ui/type/pattern_types/feature-gate-pattern_types.stderr rename to tests/ui/type/pattern_types/feature-gate-pattern_types.disabled.stderr index 12508bcb54a34..b03af26289efc 100644 --- a/tests/ui/type/pattern_types/feature-gate-pattern_types.stderr +++ b/tests/ui/type/pattern_types/feature-gate-pattern_types.disabled.stderr @@ -1,55 +1,55 @@ -error[E0658]: use of unstable library feature `pattern_type_macro` - --> $DIR/feature-gate-pattern_types.rs:5:19 +error[E0658]: use of unstable library feature `pattern_types` + --> $DIR/feature-gate-pattern_types.rs:7:19 | LL | type NonNullU32 = pattern_type!(u32 is 1..); | ^^^^^^^^^^^^ | = note: see issue #123646 for more information - = help: add `#![feature(pattern_type_macro)]` to the crate attributes to enable + = help: add `#![feature(pattern_types)]` 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[E0658]: use of unstable library feature `pattern_type_macro` - --> $DIR/feature-gate-pattern_types.rs:7:16 +error[E0658]: use of unstable library feature `pattern_types` + --> $DIR/feature-gate-pattern_types.rs:9:16 | LL | type Percent = pattern_type!(u32 is 0..=100); | ^^^^^^^^^^^^ | = note: see issue #123646 for more information - = help: add `#![feature(pattern_type_macro)]` to the crate attributes to enable + = help: add `#![feature(pattern_types)]` 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[E0658]: use of unstable library feature `pattern_type_macro` - --> $DIR/feature-gate-pattern_types.rs:9:17 +error[E0658]: use of unstable library feature `pattern_types` + --> $DIR/feature-gate-pattern_types.rs:11:17 | LL | type Negative = pattern_type!(i32 is ..=0); | ^^^^^^^^^^^^ | = note: see issue #123646 for more information - = help: add `#![feature(pattern_type_macro)]` to the crate attributes to enable + = help: add `#![feature(pattern_types)]` 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[E0658]: use of unstable library feature `pattern_type_macro` - --> $DIR/feature-gate-pattern_types.rs:11:17 +error[E0658]: use of unstable library feature `pattern_types` + --> $DIR/feature-gate-pattern_types.rs:13:17 | LL | type Positive = pattern_type!(i32 is 0..); | ^^^^^^^^^^^^ | = note: see issue #123646 for more information - = help: add `#![feature(pattern_type_macro)]` to the crate attributes to enable + = help: add `#![feature(pattern_types)]` 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[E0658]: use of unstable library feature `pattern_type_macro` - --> $DIR/feature-gate-pattern_types.rs:13:15 +error[E0658]: use of unstable library feature `pattern_types` + --> $DIR/feature-gate-pattern_types.rs:15:15 | LL | type Always = pattern_type!(Option is Some(_)); | ^^^^^^^^^^^^ | = note: see issue #123646 for more information - = help: add `#![feature(pattern_type_macro)]` to the crate attributes to enable + = help: add `#![feature(pattern_types)]` 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: pattern not supported in pattern types - --> $DIR/feature-gate-pattern_types.rs:13:44 + --> $DIR/feature-gate-pattern_types.rs:15:44 | LL | type Always = pattern_type!(Option is Some(_)); | ^^^^^^^ diff --git a/tests/ui/type/pattern_types/feature-gate-pattern_types2.stderr b/tests/ui/type/pattern_types/feature-gate-pattern_types.enabled.stderr similarity index 81% rename from tests/ui/type/pattern_types/feature-gate-pattern_types2.stderr rename to tests/ui/type/pattern_types/feature-gate-pattern_types.enabled.stderr index 81bf9dea0e2fd..c77bbd2756bf0 100644 --- a/tests/ui/type/pattern_types/feature-gate-pattern_types2.stderr +++ b/tests/ui/type/pattern_types/feature-gate-pattern_types.enabled.stderr @@ -1,5 +1,5 @@ error: pattern not supported in pattern types - --> $DIR/feature-gate-pattern_types2.rs:11:44 + --> $DIR/feature-gate-pattern_types.rs:15:44 | LL | type Always = pattern_type!(Option is Some(_)); | ^^^^^^^ diff --git a/tests/ui/type/pattern_types/feature-gate-pattern_types.rs b/tests/ui/type/pattern_types/feature-gate-pattern_types.rs index a51741675bbd6..91241c00d56c9 100644 --- a/tests/ui/type/pattern_types/feature-gate-pattern_types.rs +++ b/tests/ui/type/pattern_types/feature-gate-pattern_types.rs @@ -1,15 +1,17 @@ +//@ revisions: disabled enabled //@ compile-flags: -Zno-analysis +#![cfg_attr(enabled, feature(pattern_types))] use std::pat::pattern_type; type NonNullU32 = pattern_type!(u32 is 1..); -//~^ ERROR use of unstable library feature `pattern_type_macro` +//[disabled]~^ ERROR use of unstable library feature `pattern_types` type Percent = pattern_type!(u32 is 0..=100); -//~^ ERROR use of unstable library feature `pattern_type_macro` +//[disabled]~^ ERROR use of unstable library feature `pattern_types` type Negative = pattern_type!(i32 is ..=0); -//~^ ERROR use of unstable library feature `pattern_type_macro` +//[disabled]~^ ERROR use of unstable library feature `pattern_types` type Positive = pattern_type!(i32 is 0..); -//~^ ERROR use of unstable library feature `pattern_type_macro` +//[disabled]~^ ERROR use of unstable library feature `pattern_types` type Always = pattern_type!(Option is Some(_)); -//~^ ERROR use of unstable library feature `pattern_type_macro` -//~| ERROR pattern not supported in pattern types +//[disabled]~^ ERROR use of unstable library feature `pattern_types` +//~^^ ERROR pattern not supported in pattern types diff --git a/tests/ui/type/pattern_types/feature-gate-pattern_types2.rs b/tests/ui/type/pattern_types/feature-gate-pattern_types2.rs deleted file mode 100644 index c6b4b325fa35a..0000000000000 --- a/tests/ui/type/pattern_types/feature-gate-pattern_types2.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ compile-flags: -Zno-analysis - -#![feature(pattern_type_macro)] - -use std::pat::pattern_type; - -type NonNullU32 = pattern_type!(u32 is 1..); -type Percent = pattern_type!(u32 is 0..=100); -type Negative = pattern_type!(i32 is ..=0); -type Positive = pattern_type!(i32 is 0..); -type Always = pattern_type!(Option is Some(_)); -//~^ ERROR: pattern not supported in pattern types diff --git a/tests/ui/type/pattern_types/free_const.rs b/tests/ui/type/pattern_types/free_const.rs index 2e29fce237970..96601622a352f 100644 --- a/tests/ui/type/pattern_types/free_const.rs +++ b/tests/ui/type/pattern_types/free_const.rs @@ -1,7 +1,6 @@ //@ check-pass #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/literals.rs b/tests/ui/type/pattern_types/literals.rs index 5ec15d1b6bd8e..407123ca8f7ef 100644 --- a/tests/ui/type/pattern_types/literals.rs +++ b/tests/ui/type/pattern_types/literals.rs @@ -1,7 +1,6 @@ //! Check where literals can be used to initialize pattern types and where not. #![feature(pattern_types, const_trait_impl, pattern_type_range_trait)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/literals.stderr b/tests/ui/type/pattern_types/literals.stderr index caf5667c8f314..f36c477126020 100644 --- a/tests/ui/type/pattern_types/literals.stderr +++ b/tests/ui/type/pattern_types/literals.stderr @@ -1,35 +1,35 @@ error[E0080]: evaluation panicked: exclusive range end at minimum value of type - --> $DIR/literals.rs:86:62 + --> $DIR/literals.rs:85:62 | LL | fn empty_range_at_base_type_min() -> pattern_type!(u32 is 0..0) { | ^ evaluation of `empty_range_at_base_type_min::{constant#1}` failed here error[E0080]: evaluation panicked: exclusive range end at minimum value of type - --> $DIR/literals.rs:91:63 + --> $DIR/literals.rs:90:63 | LL | fn empty_range_at_base_type_min2() -> pattern_type!(u32 is 0..0) { | ^ evaluation of `empty_range_at_base_type_min2::{constant#1}` failed here error[E0080]: evaluation panicked: exclusive range end at minimum value of type - --> $DIR/literals.rs:106:65 + --> $DIR/literals.rs:105:65 | LL | fn wraparound_range_at_base_ty_end() -> pattern_type!(u32 is 1..0) { | ^ evaluation of `wraparound_range_at_base_ty_end::{constant#1}` failed here error[E0080]: evaluation panicked: exclusive range end at minimum value of type - --> $DIR/literals.rs:111:66 + --> $DIR/literals.rs:110:66 | LL | fn wraparound_range_at_base_ty_end2() -> pattern_type!(u32 is 1..0) { | ^ evaluation of `wraparound_range_at_base_ty_end2::{constant#1}` failed here error[E0080]: evaluation panicked: exclusive range end at minimum value of type - --> $DIR/literals.rs:116:66 + --> $DIR/literals.rs:115:66 | LL | fn wraparound_range_at_base_ty_end3() -> pattern_type!(u32 is 1..0) { | ^ evaluation of `wraparound_range_at_base_ty_end3::{constant#1}` failed here error[E0308]: mismatched types - --> $DIR/literals.rs:9:5 + --> $DIR/literals.rs:8:5 | LL | fn out_of_range() -> pattern_type!(u32 is 1..) { | ------------------------- expected `pattern_type!(u32 is 1..)` because of return type @@ -40,19 +40,19 @@ LL | 0 found type `{integer}` error[E0600]: cannot apply unary operator `-` to type `pattern_type!(u32 is 1..)` - --> $DIR/literals.rs:22:5 + --> $DIR/literals.rs:21:5 | LL | -3 | ^^ cannot apply unary operator `-` error[E0600]: cannot apply unary operator `-` to type `pattern_type!(i8 is -5..=4)` - --> $DIR/literals.rs:27:5 + --> $DIR/literals.rs:26:5 | LL | -2 | ^^ cannot apply unary operator `-` error[E0308]: mismatched types - --> $DIR/literals.rs:36:5 + --> $DIR/literals.rs:35:5 | LL | fn negative_lit_at_range_start() -> pattern_type!(i8 is -5..5) { | -------------------------- expected `pattern_type!(i8 is -5..=4)` because of return type @@ -63,7 +63,7 @@ LL | -5 found type `{integer}` error[E0308]: mismatched types - --> $DIR/literals.rs:45:5 + --> $DIR/literals.rs:44:5 | LL | fn lit_one_beyond_range_end() -> pattern_type!(i8 is -5..5) { | -------------------------- expected `pattern_type!(i8 is -5..=4)` because of return type @@ -74,7 +74,7 @@ LL | 5 found type `{integer}` error[E0308]: mismatched types - --> $DIR/literals.rs:50:5 + --> $DIR/literals.rs:49:5 | LL | fn wrong_lit_kind() -> pattern_type!(u32 is 1..) { | ------------------------- expected `pattern_type!(u32 is 1..)` because of return type @@ -85,7 +85,7 @@ LL | '3' found type `char` error[E0308]: mismatched types - --> $DIR/literals.rs:55:5 + --> $DIR/literals.rs:54:5 | LL | fn char_lit_in_range() -> pattern_type!(char is 'a'..'z') { | ------------------------------- expected `pattern_type!(char is 'a'..='y')` because of return type @@ -96,7 +96,7 @@ LL | 'b' found type `char` error[E0308]: mismatched types - --> $DIR/literals.rs:60:5 + --> $DIR/literals.rs:59:5 | LL | fn char_lit_out_of_range() -> pattern_type!(char is 'a'..'z') { | ------------------------------- expected `pattern_type!(char is 'a'..='y')` because of return type @@ -107,7 +107,7 @@ LL | 'A' found type `char` error[E0308]: mismatched types - --> $DIR/literals.rs:73:5 + --> $DIR/literals.rs:72:5 | LL | fn lit_oob_single_element_range() -> pattern_type!(u32 is 0..=0) { | --------------------------- expected `pattern_type!(u32 is 0..=0)` because of return type @@ -118,7 +118,7 @@ LL | 1 found type `{integer}` error[E0308]: mismatched types - --> $DIR/literals.rs:78:5 + --> $DIR/literals.rs:77:5 | LL | fn lit_oob_single_element_range_exclusive() -> pattern_type!(u32 is 0..1) { | -------------------------- expected `pattern_type!(u32 is 0..=0)` because of return type @@ -131,7 +131,7 @@ LL | 1 error: pattern type ranges cannot wrap: 1..=0 error[E0308]: mismatched types - --> $DIR/literals.rs:97:5 + --> $DIR/literals.rs:96:5 | LL | fn empty_range() -> pattern_type!(u32 is 1..1) { | -------------------------- expected `pattern_type!(u32 is 1..=0)` because of return type @@ -142,7 +142,7 @@ LL | 0 found type `{integer}` error[E0308]: mismatched types - --> $DIR/literals.rs:102:5 + --> $DIR/literals.rs:101:5 | LL | fn empty_range2() -> pattern_type!(u32 is 1..1) { | -------------------------- expected `pattern_type!(u32 is 1..=0)` because of return type @@ -155,7 +155,7 @@ LL | 1 error: pattern type ranges cannot wrap: 2..=0 error[E0308]: mismatched types - --> $DIR/literals.rs:122:5 + --> $DIR/literals.rs:121:5 | LL | fn wraparound_range() -> pattern_type!(u32 is 2..1) { | -------------------------- expected `pattern_type!(u32 is 2..=0)` because of return type @@ -166,7 +166,7 @@ LL | 1 found type `{integer}` error[E0308]: mismatched types - --> $DIR/literals.rs:127:5 + --> $DIR/literals.rs:126:5 | LL | fn lit_in_wraparound_range() -> pattern_type!(u32 is 2..1) { | -------------------------- expected `pattern_type!(u32 is 2..=0)` because of return type @@ -177,7 +177,7 @@ LL | 0 found type `{integer}` error[E0308]: mismatched types - --> $DIR/literals.rs:132:5 + --> $DIR/literals.rs:131:5 | LL | fn lit_at_wraparound_range_start() -> pattern_type!(u32 is 2..1) { | -------------------------- expected `pattern_type!(u32 is 2..=0)` because of return type diff --git a/tests/ui/type/pattern_types/matching.rs b/tests/ui/type/pattern_types/matching.rs index 21f89b3b673be..1086baab876c1 100644 --- a/tests/ui/type/pattern_types/matching.rs +++ b/tests/ui/type/pattern_types/matching.rs @@ -1,4 +1,4 @@ -#![feature(pattern_types, pattern_type_macro, structural_match)] +#![feature(pattern_types, structural_match)] //@ check-pass //@ compile-flags: -Zvalidate-mir diff --git a/tests/ui/type/pattern_types/matching_fail.rs b/tests/ui/type/pattern_types/matching_fail.rs index 8e2c741e3e0ab..2a345635378a6 100644 --- a/tests/ui/type/pattern_types/matching_fail.rs +++ b/tests/ui/type/pattern_types/matching_fail.rs @@ -1,4 +1,4 @@ -#![feature(pattern_types, pattern_type_macro, structural_match)] +#![feature(pattern_types, structural_match)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/missing-is.rs b/tests/ui/type/pattern_types/missing-is.rs index 564b41649d899..619f37eb007e0 100644 --- a/tests/ui/type/pattern_types/missing-is.rs +++ b/tests/ui/type/pattern_types/missing-is.rs @@ -1,4 +1,4 @@ -#![feature(pattern_type_macro)] +#![feature(pattern_types)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/nested.rs b/tests/ui/type/pattern_types/nested.rs index bff83dd43902b..96fbfea9e5e6f 100644 --- a/tests/ui/type/pattern_types/nested.rs +++ b/tests/ui/type/pattern_types/nested.rs @@ -1,7 +1,6 @@ //! Check that pattern types can only have specific base types #![feature(pattern_types, const_trait_impl, pattern_type_range_trait)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/nested.stderr b/tests/ui/type/pattern_types/nested.stderr index 72f0ccc1bfb9f..f75405241ae9e 100644 --- a/tests/ui/type/pattern_types/nested.stderr +++ b/tests/ui/type/pattern_types/nested.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/nested.rs:10:63 + --> $DIR/nested.rs:9:63 | LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!(); | ------------------------- ^ expected `pattern_type!(u32 is 1..)`, found integer @@ -10,7 +10,7 @@ LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!( found type `{integer}` error[E0277]: `pattern_type!(u32 is 1..)` is not a valid base type for range patterns - --> $DIR/nested.rs:10:34 + --> $DIR/nested.rs:9:34 | LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ only integer types and `char` are supported @@ -28,7 +28,7 @@ LL | const BAD_NESTING: pattern_type!(pattern_type!(u32 is 1..) is 0..) = todo!( and 5 others error[E0277]: `pattern_type!(i32 is 1..)` is not a valid base type for range patterns - --> $DIR/nested.rs:15:35 + --> $DIR/nested.rs:14:35 | LL | const BAD_NESTING2: pattern_type!(pattern_type!(i32 is 1..) is ..=-1) = todo!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ only integer types and `char` are supported @@ -46,13 +46,13 @@ LL | const BAD_NESTING2: pattern_type!(pattern_type!(i32 is 1..) is ..=-1) = tod and 5 others error[E0600]: cannot apply unary operator `-` to type `pattern_type!(i32 is 1..)` - --> $DIR/nested.rs:15:67 + --> $DIR/nested.rs:14:67 | LL | const BAD_NESTING2: pattern_type!(pattern_type!(i32 is 1..) is ..=-1) = todo!(); | ^^ cannot apply unary operator `-` error[E0277]: `pattern_type!(i32 is 1..)` is not a valid base type for range patterns - --> $DIR/nested.rs:19:35 + --> $DIR/nested.rs:18:35 | LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!(); | ^^^^^^^^^^^^^^^^^^^^^^^^^ only integer types and `char` are supported @@ -70,7 +70,7 @@ LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo! and 5 others error[E0308]: mismatched types - --> $DIR/nested.rs:19:66 + --> $DIR/nested.rs:18:66 | LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!(); | ^ @@ -81,7 +81,7 @@ LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo! = note: expected pattern type `pattern_type!(i32 is 1..)` found type `{integer}` help: the return type of this call is `{integer}` due to the type of the argument passed - --> $DIR/nested.rs:19:66 + --> $DIR/nested.rs:18:66 | LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!(); | ^ this argument influences the return type of `RangeSub` @@ -89,7 +89,7 @@ note: method defined here --> $SRC_DIR/core/src/pat.rs:LL:COL error[E0277]: `pattern_type!(i32 is 1..)` is not a valid base type for range patterns - --> $DIR/nested.rs:19:66 + --> $DIR/nested.rs:18:66 | LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo!(); | ^ only integer types and `char` are supported @@ -107,7 +107,7 @@ LL | const BAD_NESTING3: pattern_type!(pattern_type!(i32 is 1..) is ..0) = todo! and 5 others error[E0277]: `()` is not a valid base type for range patterns - --> $DIR/nested.rs:24:35 + --> $DIR/nested.rs:23:35 | LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); | ^^ only integer types and `char` are supported @@ -125,7 +125,7 @@ LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); and 5 others error[E0308]: mismatched types - --> $DIR/nested.rs:24:43 + --> $DIR/nested.rs:23:43 | LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); | ^ @@ -134,7 +134,7 @@ LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); | arguments to this function are incorrect | help: the return type of this call is `{integer}` due to the type of the argument passed - --> $DIR/nested.rs:24:43 + --> $DIR/nested.rs:23:43 | LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); | ^ this argument influences the return type of `RangeSub` @@ -142,7 +142,7 @@ note: method defined here --> $SRC_DIR/core/src/pat.rs:LL:COL error[E0277]: `()` is not a valid base type for range patterns - --> $DIR/nested.rs:24:43 + --> $DIR/nested.rs:23:43 | LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); | ^ only integer types and `char` are supported @@ -160,7 +160,7 @@ LL | const BAD_NESTING4: pattern_type!(() is ..0) = todo!(); and 5 others error[E0277]: `f32` is not a valid base type for range patterns - --> $DIR/nested.rs:29:49 + --> $DIR/nested.rs:28:49 | LL | const BAD_NESTING5: pattern_type!(f32 is 1.0 .. 2.0) = todo!(); | ^^^ only integer types and `char` are supported diff --git a/tests/ui/type/pattern_types/non_null.rs b/tests/ui/type/pattern_types/non_null.rs index e3c634da48b8e..5ce15eb5da319 100644 --- a/tests/ui/type/pattern_types/non_null.rs +++ b/tests/ui/type/pattern_types/non_null.rs @@ -3,7 +3,7 @@ //@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED" //@ only-64bit -#![feature(pattern_type_macro, pattern_types, rustc_attrs)] +#![feature(pattern_types, rustc_attrs)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/or_patterns.rs b/tests/ui/type/pattern_types/or_patterns.rs index d90f36983d0a0..e744025ddd673 100644 --- a/tests/ui/type/pattern_types/or_patterns.rs +++ b/tests/ui/type/pattern_types/or_patterns.rs @@ -2,13 +2,7 @@ //@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED" -#![feature( - pattern_type_macro, - pattern_types, - rustc_attrs, - const_trait_impl, - pattern_type_range_trait -)] +#![feature(pattern_types, rustc_attrs, const_trait_impl, pattern_type_range_trait)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/or_patterns.stderr b/tests/ui/type/pattern_types/or_patterns.stderr index ab757f7405eba..bda319b4be19b 100644 --- a/tests/ui/type/pattern_types/or_patterns.stderr +++ b/tests/ui/type/pattern_types/or_patterns.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/or_patterns.rs:26:24 + --> $DIR/or_patterns.rs:20:24 | LL | let _: NonNullI8 = 0; | --------- ^ expected `pattern_type!(i8 is (i8::MIN..=-1 | 1..))`, found integer @@ -10,31 +10,31 @@ LL | let _: NonNullI8 = 0; found type `{integer}` error[E0600]: cannot apply unary operator `-` to type `pattern_type!(i8 is (i8::MIN..=-1 | 1..))` - --> $DIR/or_patterns.rs:28:24 + --> $DIR/or_patterns.rs:22:24 | LL | let _: NonNullI8 = -1; | ^^ cannot apply unary operator `-` error[E0600]: cannot apply unary operator `-` to type `pattern_type!(i8 is (i8::MIN..=-1 | 1..))` - --> $DIR/or_patterns.rs:30:24 + --> $DIR/or_patterns.rs:24:24 | LL | let _: NonNullI8 = -128; | ^^^^ cannot apply unary operator `-` error[E0600]: cannot apply unary operator `-` to type `pattern_type!(i8 is (i8::MIN..=-2 | 0..))` - --> $DIR/or_patterns.rs:37:26 + --> $DIR/or_patterns.rs:31:26 | LL | let _: NonNegOneI8 = -1; | ^^ cannot apply unary operator `-` error[E0600]: cannot apply unary operator `-` to type `pattern_type!(i8 is (i8::MIN..=-2 | 0..))` - --> $DIR/or_patterns.rs:39:26 + --> $DIR/or_patterns.rs:33:26 | LL | let _: NonNegOneI8 = -2; | ^^ cannot apply unary operator `-` error[E0600]: cannot apply unary operator `-` to type `pattern_type!(i8 is (i8::MIN..=-2 | 0..))` - --> $DIR/or_patterns.rs:41:26 + --> $DIR/or_patterns.rs:35:26 | LL | let _: NonNegOneI8 = -128; | ^^^^ cannot apply unary operator `-` @@ -69,7 +69,7 @@ error: layout_of(pattern_type!(i8 is (i8::MIN..=-1 | 1..))) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/or_patterns.rs:16:1 + --> $DIR/or_patterns.rs:10:1 | LL | type NonNullI8 = pattern_type!(i8 is ..0 | 1..); | ^^^^^^^^^^^^^^ @@ -104,7 +104,7 @@ error: layout_of(pattern_type!(i8 is (i8::MIN..=-2 | 0..))) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/or_patterns.rs:20:1 + --> $DIR/or_patterns.rs:14:1 | LL | type NonNegOneI8 = pattern_type!(i8 is ..-1 | 0..); | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type/pattern_types/or_patterns_invalid.rs b/tests/ui/type/pattern_types/or_patterns_invalid.rs index a99667c5412ce..e416d5d8ae45d 100644 --- a/tests/ui/type/pattern_types/or_patterns_invalid.rs +++ b/tests/ui/type/pattern_types/or_patterns_invalid.rs @@ -1,12 +1,6 @@ //! Demonstrate some use cases of or patterns -#![feature( - pattern_type_macro, - pattern_types, - rustc_attrs, - const_trait_impl, - pattern_type_range_trait -)] +#![feature(pattern_types, rustc_attrs, const_trait_impl, pattern_type_range_trait)] use std::pat::pattern_type; @@ -26,5 +20,5 @@ fn main() { //~? ERROR: allowed are two range patterns that are directly connected let not_simple_enough_for_mvp: pattern_type!(i8 is ..0 | 1..10 | 10..) = unsafe { std::mem::transmute(0) }; - //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types + //~^ ERROR: cannot transmute between types of different sizes, or dependently-sized types } diff --git a/tests/ui/type/pattern_types/or_patterns_invalid.stderr b/tests/ui/type/pattern_types/or_patterns_invalid.stderr index a931b76b0d0be..669721dd0bab7 100644 --- a/tests/ui/type/pattern_types/or_patterns_invalid.stderr +++ b/tests/ui/type/pattern_types/or_patterns_invalid.stderr @@ -1,7 +1,7 @@ error: only non-overlapping pattern type ranges are allowed at present error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> $DIR/or_patterns_invalid.rs:15:69 + --> $DIR/or_patterns_invalid.rs:9:69 | LL | let not_adjacent: pattern_type!(i8 is -127..0 | 1..) = unsafe { std::mem::transmute(0) }; | ^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | let not_adjacent: pattern_type!(i8 is -127..0 | 1..) = unsafe { std::me error: one pattern needs to end at `i8::MAX`, but was 29 instead error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> $DIR/or_patterns_invalid.rs:19:71 + --> $DIR/or_patterns_invalid.rs:13:71 | LL | let not_wrapping: pattern_type!(i8 is 10..20 | 20..30) = unsafe { std::mem::transmute(0) }; | ^^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | let not_wrapping: pattern_type!(i8 is 10..20 | 20..30) = unsafe { std:: error: only signed integer base types are allowed for or-pattern pattern types at present error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> $DIR/or_patterns_invalid.rs:23:65 + --> $DIR/or_patterns_invalid.rs:17:65 | LL | let not_signed: pattern_type!(u8 is 10.. | 0..5) = unsafe { std::mem::transmute(0) }; | ^^^^^^^^^^^^^^^^^^^ @@ -34,7 +34,7 @@ LL | let not_signed: pattern_type!(u8 is 10.. | 0..5) = unsafe { std::mem::t error: the only or-pattern types allowed are two range patterns that are directly connected at their overflow site error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> $DIR/or_patterns_invalid.rs:28:18 + --> $DIR/or_patterns_invalid.rs:22:18 | LL | unsafe { std::mem::transmute(0) }; | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type/pattern_types/pattern_type_mismatch.rs b/tests/ui/type/pattern_types/pattern_type_mismatch.rs index 0c88f27d83686..30c368033b099 100644 --- a/tests/ui/type/pattern_types/pattern_type_mismatch.rs +++ b/tests/ui/type/pattern_types/pattern_type_mismatch.rs @@ -1,7 +1,6 @@ //! Check that pattern types patterns must be of the type of the base type #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/pattern_type_mismatch.stderr b/tests/ui/type/pattern_types/pattern_type_mismatch.stderr index 129e4b5cdc7be..bfbee74897a1b 100644 --- a/tests/ui/type/pattern_types/pattern_type_mismatch.stderr +++ b/tests/ui/type/pattern_types/pattern_type_mismatch.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/pattern_type_mismatch.rs:8:41 + --> $DIR/pattern_type_mismatch.rs:7:41 | LL | const BAD_NESTING4: pattern_type!(u8 is 'a'..='a') = todo!(); | -- ^^^ expected `u8`, found `char` @@ -12,7 +12,7 @@ LL | const BAD_NESTING4: pattern_type!(u8 is b'a'..='a') = todo!(); | + error[E0308]: mismatched types - --> $DIR/pattern_type_mismatch.rs:8:47 + --> $DIR/pattern_type_mismatch.rs:7:47 | LL | const BAD_NESTING4: pattern_type!(u8 is 'a'..='a') = todo!(); | -- ^^^ expected `u8`, found `char` @@ -25,7 +25,7 @@ LL | const BAD_NESTING4: pattern_type!(u8 is 'a'..=b'a') = todo!(); | + error[E0308]: mismatched types - --> $DIR/pattern_type_mismatch.rs:12:43 + --> $DIR/pattern_type_mismatch.rs:11:43 | LL | const BAD_NESTING5: pattern_type!(char is 1..=1) = todo!(); | ---- ^ expected `char`, found `u8` @@ -33,7 +33,7 @@ LL | const BAD_NESTING5: pattern_type!(char is 1..=1) = todo!(); | the pattern must match the type error[E0308]: mismatched types - --> $DIR/pattern_type_mismatch.rs:12:47 + --> $DIR/pattern_type_mismatch.rs:11:47 | LL | const BAD_NESTING5: pattern_type!(char is 1..=1) = todo!(); | ---- ^ expected `char`, found `u8` diff --git a/tests/ui/type/pattern_types/range_patterns.rs b/tests/ui/type/pattern_types/range_patterns.rs index 1ad6469967cbc..5edf357299c98 100644 --- a/tests/ui/type/pattern_types/range_patterns.rs +++ b/tests/ui/type/pattern_types/range_patterns.rs @@ -1,6 +1,4 @@ #![feature(pattern_types, rustc_attrs, const_trait_impl, pattern_type_range_trait)] -#![feature(pattern_type_macro)] -#![allow(incomplete_features)] //@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED" diff --git a/tests/ui/type/pattern_types/range_patterns.stderr b/tests/ui/type/pattern_types/range_patterns.stderr index a1e085ffe44ff..5ed826fa66331 100644 --- a/tests/ui/type/pattern_types/range_patterns.stderr +++ b/tests/ui/type/pattern_types/range_patterns.stderr @@ -28,7 +28,7 @@ error: layout_of(NonZero) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/range_patterns.rs:10:1 + --> $DIR/range_patterns.rs:8:1 | LL | type X = std::num::NonZeroU32; | ^^^^^^ @@ -63,7 +63,7 @@ error: layout_of(pattern_type!(u32 is 1..)) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/range_patterns.rs:12:1 + --> $DIR/range_patterns.rs:10:1 | LL | type Y = pattern_type!(u32 is 1..); | ^^^^^^ @@ -130,7 +130,7 @@ error: layout_of(Option) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/range_patterns.rs:14:1 + --> $DIR/range_patterns.rs:12:1 | LL | type Z = Option; | ^^^^^^ @@ -197,7 +197,7 @@ error: layout_of(Option>) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/range_patterns.rs:16:1 + --> $DIR/range_patterns.rs:14:1 | LL | type A = Option; | ^^^^^^ @@ -232,7 +232,7 @@ error: layout_of(NonZeroU32New) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/range_patterns.rs:18:1 + --> $DIR/range_patterns.rs:16:1 | LL | struct NonZeroU32New(pattern_type!(u32 is 1..)); | ^^^^^^^^^^^^^^^^^^^^ @@ -240,19 +240,19 @@ LL | struct NonZeroU32New(pattern_type!(u32 is 1..)); error: pattern type ranges cannot wrap: 1..=0 error: the type has an unknown layout - --> $DIR/range_patterns.rs:21:1 + --> $DIR/range_patterns.rs:19:1 | LL | type EMPTY = pattern_type!(u32 is 1..1); | ^^^^^^^^^^ error[E0080]: evaluation panicked: exclusive range end at minimum value of type - --> $DIR/range_patterns.rs:24:37 + --> $DIR/range_patterns.rs:22:37 | LL | type WRAP = pattern_type!(u32 is 1..0); | ^ evaluation of `WRAP::{constant#1}` failed here error: the type has an unknown layout - --> $DIR/range_patterns.rs:24:1 + --> $DIR/range_patterns.rs:22:1 | LL | type WRAP = pattern_type!(u32 is 1..0); | ^^^^^^^^^ @@ -260,7 +260,7 @@ LL | type WRAP = pattern_type!(u32 is 1..0); error: pattern type ranges cannot wrap: 5..=1 error: the type has an unknown layout - --> $DIR/range_patterns.rs:28:1 + --> $DIR/range_patterns.rs:26:1 | LL | type WRAP2 = pattern_type!(u32 is 5..2); | ^^^^^^^^^^ @@ -295,7 +295,7 @@ error: layout_of(pattern_type!(i8 is -10..=10)) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/range_patterns.rs:31:1 + --> $DIR/range_patterns.rs:29:1 | LL | type SIGN = pattern_type!(i8 is -10..=10); | ^^^^^^^^^ @@ -330,7 +330,7 @@ error: layout_of(pattern_type!(i8 is i8::MIN..=0)) = Layout { repr_c: false, randomization_seed: $SEED, } - --> $DIR/range_patterns.rs:34:1 + --> $DIR/range_patterns.rs:32:1 | LL | type MIN = pattern_type!(i8 is -128..=0); | ^^^^^^^^ @@ -338,7 +338,7 @@ LL | type MIN = pattern_type!(i8 is -128..=0); error: pattern type ranges cannot wrap: 120..=-120 error: the type has an unknown layout - --> $DIR/range_patterns.rs:37:1 + --> $DIR/range_patterns.rs:35:1 | LL | type SignedWrap = pattern_type!(i8 is 120..=-120); | ^^^^^^^^^^^^^^^ diff --git a/tests/ui/type/pattern_types/range_patterns_inherent_impls.rs b/tests/ui/type/pattern_types/range_patterns_inherent_impls.rs index fe8feda0934e2..14107463511f3 100644 --- a/tests/ui/type/pattern_types/range_patterns_inherent_impls.rs +++ b/tests/ui/type/pattern_types/range_patterns_inherent_impls.rs @@ -1,6 +1,4 @@ #![feature(pattern_types, rustc_attrs)] -#![feature(pattern_type_macro)] -#![allow(incomplete_features)] //! check that pattern types can have traits implemented for them if //! their base type is a local type. diff --git a/tests/ui/type/pattern_types/range_patterns_inherent_impls.stderr b/tests/ui/type/pattern_types/range_patterns_inherent_impls.stderr index ed2e4c0bd5f8c..f01510557588c 100644 --- a/tests/ui/type/pattern_types/range_patterns_inherent_impls.stderr +++ b/tests/ui/type/pattern_types/range_patterns_inherent_impls.stderr @@ -1,12 +1,12 @@ error[E0390]: cannot define inherent `impl` for primitive types outside of `core` - --> $DIR/range_patterns_inherent_impls.rs:12:1 + --> $DIR/range_patterns_inherent_impls.rs:10:1 | LL | impl Y { | ^^^^^^ | = help: consider moving this inherent impl into `core` if possible help: alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items - --> $DIR/range_patterns_inherent_impls.rs:14:5 + --> $DIR/range_patterns_inherent_impls.rs:12:5 | LL | fn foo() {} | ^^^^^^^^ diff --git a/tests/ui/type/pattern_types/range_patterns_trait_impls.rs b/tests/ui/type/pattern_types/range_patterns_trait_impls.rs index 1731cd470fe2c..e7c5479e43d0c 100644 --- a/tests/ui/type/pattern_types/range_patterns_trait_impls.rs +++ b/tests/ui/type/pattern_types/range_patterns_trait_impls.rs @@ -1,6 +1,4 @@ #![feature(pattern_types, rustc_attrs)] -#![feature(pattern_type_macro)] -#![allow(incomplete_features)] //! check that pattern types can have local traits //! implemented for them. diff --git a/tests/ui/type/pattern_types/range_patterns_trait_impls2.rs b/tests/ui/type/pattern_types/range_patterns_trait_impls2.rs index 90f80a2f34645..d367bd174f3ef 100644 --- a/tests/ui/type/pattern_types/range_patterns_trait_impls2.rs +++ b/tests/ui/type/pattern_types/range_patterns_trait_impls2.rs @@ -1,6 +1,4 @@ #![feature(pattern_types, rustc_attrs)] -#![feature(pattern_type_macro)] -#![allow(incomplete_features)] //! check that pattern types can have local traits //! implemented for them. diff --git a/tests/ui/type/pattern_types/range_patterns_trait_impls2.stderr b/tests/ui/type/pattern_types/range_patterns_trait_impls2.stderr index 4517c7e910f4e..2f372751277a2 100644 --- a/tests/ui/type/pattern_types/range_patterns_trait_impls2.stderr +++ b/tests/ui/type/pattern_types/range_patterns_trait_impls2.stderr @@ -1,5 +1,5 @@ error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/range_patterns_trait_impls2.rs:12:1 + --> $DIR/range_patterns_trait_impls2.rs:10:1 | LL | impl Eq for Y {} | ^^^^^^^^^^^^- diff --git a/tests/ui/type/pattern_types/range_patterns_unusable.rs b/tests/ui/type/pattern_types/range_patterns_unusable.rs index 98f13ca0bc0bb..d023541d12e48 100644 --- a/tests/ui/type/pattern_types/range_patterns_unusable.rs +++ b/tests/ui/type/pattern_types/range_patterns_unusable.rs @@ -1,6 +1,4 @@ #![feature(pattern_types, rustc_attrs)] -#![feature(pattern_type_macro)] -#![allow(incomplete_features)] //! Some practical niche checks. diff --git a/tests/ui/type/pattern_types/range_patterns_unusable.stderr b/tests/ui/type/pattern_types/range_patterns_unusable.stderr index 5c61f6347bbfc..15e83bfad5228 100644 --- a/tests/ui/type/pattern_types/range_patterns_unusable.stderr +++ b/tests/ui/type/pattern_types/range_patterns_unusable.stderr @@ -1,5 +1,5 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-sized types - --> $DIR/range_patterns_unusable.rs:13:35 + --> $DIR/range_patterns_unusable.rs:11:35 | LL | let _: Option = unsafe { std::mem::transmute(z) }; | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type/pattern_types/range_patterns_unusable_math.rs b/tests/ui/type/pattern_types/range_patterns_unusable_math.rs index 71becd28d1cac..f44ac1e7be392 100644 --- a/tests/ui/type/pattern_types/range_patterns_unusable_math.rs +++ b/tests/ui/type/pattern_types/range_patterns_unusable_math.rs @@ -1,6 +1,4 @@ #![feature(pattern_types, rustc_attrs)] -#![feature(pattern_type_macro)] -#![allow(incomplete_features)] //! check that pattern types don't have an `Add` impl. diff --git a/tests/ui/type/pattern_types/range_patterns_unusable_math.stderr b/tests/ui/type/pattern_types/range_patterns_unusable_math.stderr index b55031dc3cf8b..5dab944cfe2de 100644 --- a/tests/ui/type/pattern_types/range_patterns_unusable_math.stderr +++ b/tests/ui/type/pattern_types/range_patterns_unusable_math.stderr @@ -1,5 +1,5 @@ error[E0369]: cannot add `u32` to `pattern_type!(u32 is 1..)` - --> $DIR/range_patterns_unusable_math.rs:14:15 + --> $DIR/range_patterns_unusable_math.rs:12:15 | LL | let x = x + 1_u32; | - ^ ----- u32 diff --git a/tests/ui/type/pattern_types/range_patterns_usage.rs b/tests/ui/type/pattern_types/range_patterns_usage.rs index 0ecbdcaa0f7a3..5d09785e8faa8 100644 --- a/tests/ui/type/pattern_types/range_patterns_usage.rs +++ b/tests/ui/type/pattern_types/range_patterns_usage.rs @@ -1,6 +1,4 @@ #![feature(pattern_types, rustc_attrs)] -#![feature(pattern_type_macro)] -#![allow(incomplete_features)] //@ check-pass //! check that pattern types can actually be part of code that compiles successfully. diff --git a/tests/ui/type/pattern_types/reverse_range.rs b/tests/ui/type/pattern_types/reverse_range.rs index 34c931e4e965a..8d0fd8ca1b628 100644 --- a/tests/ui/type/pattern_types/reverse_range.rs +++ b/tests/ui/type/pattern_types/reverse_range.rs @@ -1,6 +1,5 @@ //! Check that the range start must be smaller than the range end #![feature(pattern_types, const_trait_impl, pattern_type_range_trait)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/reverse_range.stderr b/tests/ui/type/pattern_types/reverse_range.stderr index 6e6e34409a39e..bcaf19790ba38 100644 --- a/tests/ui/type/pattern_types/reverse_range.stderr +++ b/tests/ui/type/pattern_types/reverse_range.stderr @@ -1,5 +1,5 @@ error[E0080]: evaluation panicked: exclusive range end at minimum value of type - --> $DIR/reverse_range.rs:7:36 + --> $DIR/reverse_range.rs:6:36 | LL | const NONE: pattern_type!(u8 is 1..0) = unsafe { std::mem::transmute(3_u8) }; | ^ evaluation of `NONE::{constant#1}` failed here diff --git a/tests/ui/type/pattern_types/signed_ranges.rs b/tests/ui/type/pattern_types/signed_ranges.rs index 3725fbda7292a..e18c0299cbba6 100644 --- a/tests/ui/type/pattern_types/signed_ranges.rs +++ b/tests/ui/type/pattern_types/signed_ranges.rs @@ -1,5 +1,4 @@ #![feature(pattern_types)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/signed_ranges.stderr b/tests/ui/type/pattern_types/signed_ranges.stderr index 79bf8501b639f..66df48363af65 100644 --- a/tests/ui/type/pattern_types/signed_ranges.stderr +++ b/tests/ui/type/pattern_types/signed_ranges.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `u8: Neg` is not satisfied - --> $DIR/signed_ranges.rs:14:9 + --> $DIR/signed_ranges.rs:13:9 | LL | -10..253 => {} | ^^^ the trait `Neg` is not implemented for `u8` @@ -16,13 +16,13 @@ LL | -10..253 => {} and 12 others error[E0277]: the trait bound `char: Neg` is not satisfied - --> $DIR/signed_ranges.rs:20:9 + --> $DIR/signed_ranges.rs:19:9 | LL | -'\0'..'a' => {} | ^^^^^ the trait `Neg` is not implemented for `char` error[E0600]: cannot apply unary operator `-` to type `u32` - --> $DIR/signed_ranges.rs:6:34 + --> $DIR/signed_ranges.rs:5:34 | LL | type Sign = pattern_type!(u32 is -10..); | ^^^ cannot apply unary operator `-` @@ -30,7 +30,7 @@ LL | type Sign = pattern_type!(u32 is -10..); = note: unsigned values cannot be negated error[E0600]: cannot apply unary operator `-` to type `char` - --> $DIR/signed_ranges.rs:9:41 + --> $DIR/signed_ranges.rs:8:41 | LL | type SignedChar = pattern_type!(char is -'A'..); | ^^^^ cannot apply unary operator `-` diff --git a/tests/ui/type/pattern_types/transmute.rs b/tests/ui/type/pattern_types/transmute.rs index 4e686245f9375..77f99253543ca 100644 --- a/tests/ui/type/pattern_types/transmute.rs +++ b/tests/ui/type/pattern_types/transmute.rs @@ -1,7 +1,7 @@ //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) //@[next] compile-flags: -Znext-solver -#![feature(pattern_types, pattern_type_macro, generic_pattern_types)] +#![feature(pattern_types, generic_pattern_types)] #![expect(incomplete_features)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/unimplemented_pat.rs b/tests/ui/type/pattern_types/unimplemented_pat.rs index 44851ec1a1049..7e57e1f7ff8d6 100644 --- a/tests/ui/type/pattern_types/unimplemented_pat.rs +++ b/tests/ui/type/pattern_types/unimplemented_pat.rs @@ -1,7 +1,7 @@ //! This test ensures we do not ICE for unimplemented //! patterns even if the feature gate is enabled. -#![feature(pattern_type_macro, pattern_types)] +#![feature(pattern_types)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/unsize.rs b/tests/ui/type/pattern_types/unsize.rs index 1020dd8c21544..18d9a52a9195e 100644 --- a/tests/ui/type/pattern_types/unsize.rs +++ b/tests/ui/type/pattern_types/unsize.rs @@ -2,7 +2,7 @@ //@ check-pass -#![feature(pattern_type_macro, pattern_types)] +#![feature(pattern_types)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/validity.rs b/tests/ui/type/pattern_types/validity.rs index f4c62dc6712e9..cbabe06c312ce 100644 --- a/tests/ui/type/pattern_types/validity.rs +++ b/tests/ui/type/pattern_types/validity.rs @@ -3,7 +3,6 @@ //@ normalize-stderr: "([[:xdigit:]]{2}\s){4,8}\s+│\s.{4,8}" -> "HEX_DUMP" #![feature(pattern_types, const_trait_impl, pattern_type_range_trait)] -#![feature(pattern_type_macro)] use std::pat::pattern_type; diff --git a/tests/ui/type/pattern_types/validity.stderr b/tests/ui/type/pattern_types/validity.stderr index 7cfa6b3400a41..9ddc07ce89cee 100644 --- a/tests/ui/type/pattern_types/validity.stderr +++ b/tests/ui/type/pattern_types/validity.stderr @@ -1,5 +1,5 @@ error[E0080]: constructing invalid value of type pattern_type!(u32 is 1..): encountered 0, but expected something greater or equal to 1 - --> $DIR/validity.rs:10:1 + --> $DIR/validity.rs:9:1 | LL | const BAD: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -10,7 +10,7 @@ LL | const BAD: pattern_type!(u32 is 1..) = unsafe { std::mem::transmute(0) }; } error[E0080]: reading memory at ALLOC$ID[0x0..0x4], but memory is uninitialized at [0x0..0x4], and this operation requires initialized memory - --> $DIR/validity.rs:13:1 + --> $DIR/validity.rs:12:1 | LL | const BAD_UNINIT: pattern_type!(u32 is 1..) = | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `BAD_UNINIT` failed here @@ -20,7 +20,7 @@ LL | const BAD_UNINIT: pattern_type!(u32 is 1..) = } error[E0080]: unable to turn pointer into integer - --> $DIR/validity.rs:17:1 + --> $DIR/validity.rs:16:1 | LL | const BAD_PTR: pattern_type!(usize is 1..) = unsafe { std::mem::transmute(&42) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `BAD_PTR` failed here @@ -29,7 +29,7 @@ LL | const BAD_PTR: pattern_type!(usize is 1..) = unsafe { std::mem::transmute(& = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported error[E0080]: constructing invalid value of type (pattern_type!(u32 is 1..), u32): at .0, encountered 0, but expected something greater or equal to 1 - --> $DIR/validity.rs:20:1 + --> $DIR/validity.rs:19:1 | LL | const BAD_AGGREGATE: (pattern_type!(u32 is 1..), u32) = (unsafe { std::mem::transmute(0) }, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -40,7 +40,7 @@ LL | const BAD_AGGREGATE: (pattern_type!(u32 is 1..), u32) = (unsafe { std::mem: } error[E0080]: constructing invalid value of type Foo: at .0.0, encountered 0, but expected something greater or equal to 1 - --> $DIR/validity.rs:26:1 + --> $DIR/validity.rs:25:1 | LL | const BAD_FOO: Foo = Foo(Bar(unsafe { std::mem::transmute(0) })); | ^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -51,7 +51,7 @@ LL | const BAD_FOO: Foo = Foo(Bar(unsafe { std::mem::transmute(0) })); } error[E0080]: reading memory at ALLOC$ID[0x0..0x4], but memory is uninitialized at [0x0..0x4], and this operation requires initialized memory - --> $DIR/validity.rs:29:1 + --> $DIR/validity.rs:28:1 | LL | const CHAR_UNINIT: pattern_type!(char is 'A'..'Z') = | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `CHAR_UNINIT` failed here @@ -61,7 +61,7 @@ LL | const CHAR_UNINIT: pattern_type!(char is 'A'..'Z') = } error[E0080]: constructing invalid value of type pattern_type!(char is 'A'..='Y'): encountered 97, but expected something in the range 65..=89 - --> $DIR/validity.rs:33:1 + --> $DIR/validity.rs:32:1 | LL | const CHAR_OOB_PAT: pattern_type!(char is 'A'..'Z') = unsafe { std::mem::transmute('a') }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value @@ -72,7 +72,7 @@ LL | const CHAR_OOB_PAT: pattern_type!(char is 'A'..'Z') = unsafe { std::mem::tr } error[E0080]: constructing invalid value of type pattern_type!(char is 'A'..='Y'): encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`) - --> $DIR/validity.rs:36:1 + --> $DIR/validity.rs:35:1 | LL | const CHAR_OOB: pattern_type!(char is 'A'..'Z') = unsafe { std::mem::transmute(u32::MAX) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value diff --git a/tests/ui/unpretty/exhaustive.expanded.stdout b/tests/ui/unpretty/exhaustive.expanded.stdout index 3551d40dffbfc..0bd7aca6a007b 100644 --- a/tests/ui/unpretty/exhaustive.expanded.stdout +++ b/tests/ui/unpretty/exhaustive.expanded.stdout @@ -21,7 +21,6 @@ #![feature(more_qualified_paths)] #![feature(never_patterns)] #![feature(pattern_types)] -#![feature(pattern_type_macro)] #![feature(prelude_import)] #![feature(specialization)] #![feature(trace_macros)] @@ -632,7 +631,7 @@ mod types { /*! FIXME: todo */ } /// TyKind::Pat - fn ty_pat() { let _: u32 is const 1..; } + fn ty_pat() { let _: k#pattern_type(u32 is const 1..); } } mod visibilities { /// VisibilityKind::Public diff --git a/tests/ui/unpretty/exhaustive.hir.stderr b/tests/ui/unpretty/exhaustive.hir.stderr index 276bc5b5d2573..5ca4b080a95e5 100644 --- a/tests/ui/unpretty/exhaustive.hir.stderr +++ b/tests/ui/unpretty/exhaustive.hir.stderr @@ -1,17 +1,17 @@ error[E0697]: closures cannot be static - --> $DIR/exhaustive.rs:210:9 + --> $DIR/exhaustive.rs:209:9 | LL | static || value; | ^^^^^^^^^ error[E0697]: closures cannot be static - --> $DIR/exhaustive.rs:211:9 + --> $DIR/exhaustive.rs:210:9 | LL | static move || value; | ^^^^^^^^^^^^^^ error[E0728]: `await` is only allowed inside `async` functions and blocks - --> $DIR/exhaustive.rs:240:13 + --> $DIR/exhaustive.rs:239:13 | LL | fn expr_await() { | --------------- this is not `async` @@ -20,19 +20,19 @@ LL | fut.await; | ^^^^^ only allowed inside `async` functions and blocks error: in expressions, `_` can only be used on the left-hand side of an assignment - --> $DIR/exhaustive.rs:291:9 + --> $DIR/exhaustive.rs:290:9 | LL | _; | ^ `_` not allowed here error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:301:9 + --> $DIR/exhaustive.rs:300:9 | LL | x::(); | ^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:302:9 + --> $DIR/exhaustive.rs:301:9 | LL | x::(T, T) -> T; | ^^^^^^^^^^^^^^ only `Fn` traits may use parentheses @@ -44,31 +44,31 @@ LL + x:: -> T; | error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:303:9 + --> $DIR/exhaustive.rs:302:9 | LL | crate::() -> ()::expressions::() -> ()::expr_path; | ^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:303:26 + --> $DIR/exhaustive.rs:302:26 | LL | crate::() -> ()::expressions::() -> ()::expr_path; | ^^^^^^^^^^^^^^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:306:9 + --> $DIR/exhaustive.rs:305:9 | LL | core::()::marker::()::PhantomData; | ^^^^^^^^ only `Fn` traits may use parentheses error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:306:19 + --> $DIR/exhaustive.rs:305:19 | LL | core::()::marker::()::PhantomData; | ^^^^^^^^^^ only `Fn` traits may use parentheses error: `yield` can only be used in `#[coroutine]` closures, or `gen` blocks - --> $DIR/exhaustive.rs:393:9 + --> $DIR/exhaustive.rs:392:9 | LL | yield; | ^^^^^ @@ -79,7 +79,7 @@ LL | #[coroutine] fn expr_yield() { | ++++++++++++ error[E0703]: invalid ABI: found `C++` - --> $DIR/exhaustive.rs:473:23 + --> $DIR/exhaustive.rs:472:23 | LL | unsafe extern "C++" {} | ^^^^^ invalid ABI @@ -87,7 +87,7 @@ LL | unsafe extern "C++" {} = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions error: `..` patterns are not allowed here - --> $DIR/exhaustive.rs:675:13 + --> $DIR/exhaustive.rs:674:13 | LL | let ..; | ^^ @@ -95,13 +95,13 @@ LL | let ..; = note: only allowed in tuple, tuple struct, and slice patterns error[E0214]: parenthesized type parameters may only be used with a `Fn` trait - --> $DIR/exhaustive.rs:790:16 + --> $DIR/exhaustive.rs:789:16 | LL | let _: T() -> !; | ^^^^^^^^ only `Fn` traits may use parentheses error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:804:16 + --> $DIR/exhaustive.rs:803:16 | LL | let _: impl Send; | ^^^^^^^^^ @@ -112,7 +112,7 @@ LL | let _: impl Send; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:805:16 + --> $DIR/exhaustive.rs:804:16 | LL | let _: impl Send + 'static; | ^^^^^^^^^^^^^^^^^^^ @@ -123,7 +123,7 @@ LL | let _: impl Send + 'static; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:806:16 + --> $DIR/exhaustive.rs:805:16 | LL | let _: impl 'static + Send; | ^^^^^^^^^^^^^^^^^^^ @@ -134,7 +134,7 @@ LL | let _: impl 'static + Send; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:807:16 + --> $DIR/exhaustive.rs:806:16 | LL | let _: impl ?Sized; | ^^^^^^^^^^^ @@ -145,7 +145,7 @@ LL | let _: impl ?Sized; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:808:16 + --> $DIR/exhaustive.rs:807:16 | LL | let _: impl [const] Clone; | ^^^^^^^^^^^^^^^^^^ @@ -156,7 +156,7 @@ LL | let _: impl [const] Clone; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/exhaustive.rs:809:16 + --> $DIR/exhaustive.rs:808:16 | LL | let _: impl for<'a> Send; | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index 6af4d3b5b81de..4726e9aa762e7 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -1,9 +1,8 @@ #![attr = Feature([auto_traits#0, internal_syntax#0, const_trait_impl#0, coroutines#0, decl_macro#0, deref_patterns#0, explicit_tail_calls#0, forced_keywords#0, gen_blocks#0, more_qualified_paths#0, never_patterns#0, -pattern_types#0, pattern_type_macro#0, prelude_import#0, specialization#0, -trace_macros#0, trait_alias#0, try_blocks#0, try_blocks_heterogeneous#0, -yeet_expr#0])] +pattern_types#0, prelude_import#0, specialization#0, trace_macros#0, +trait_alias#0, try_blocks#0, try_blocks_heterogeneous#0, yeet_expr#0])] #![attr = LintCheck([LintCheck {lint_name: LintName { tool: None, name: "incomplete_features" }, kind: Allow}, LintCheck {lint_name: LintName { tool: None, name: "unused_attributes" }, diff --git a/tests/ui/unpretty/exhaustive.rs b/tests/ui/unpretty/exhaustive.rs index 15f684fc3dd72..36cc724351a64 100644 --- a/tests/ui/unpretty/exhaustive.rs +++ b/tests/ui/unpretty/exhaustive.rs @@ -20,7 +20,6 @@ #![feature(more_qualified_paths)] #![feature(never_patterns)] #![feature(pattern_types)] -#![feature(pattern_type_macro)] #![feature(prelude_import)] #![feature(specialization)] #![feature(trace_macros)] @@ -846,7 +845,7 @@ mod types { /// TyKind::Pat fn ty_pat() { - let _: core::pattern_type!(u32 is 1..); + let _: pattern_type!(u32 is 1..); } } From d965694821bb54c861f7096d1a4d331985a23371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Le=C3=B3n=20Orell=20Valerian=20Liehr?= Date: Thu, 5 Nov 2026 00:49:56 +0100 Subject: [PATCH 09/10] Turn `view_type` into a macro 2.0 that expands to `k#view_type(...)` This also means that it's now available under `core::view` instead of `core` directly. This makes it consistent with the `std` re-export which is only available under `std::view` and not under `std` directly. Moreover, drop library feature `view_type_macro` and demote language feature `view_types` to a library feature. This is nice because it means `std::view::view_type` is no longer unnecessarily gated behind two (!) feature gates. --- compiler/rustc_ast_passes/src/feature_gate.rs | 4 -- compiler/rustc_ast_pretty/src/pprust/state.rs | 6 +++ compiler/rustc_ast_pretty/src/pprust/tests.rs | 2 +- compiler/rustc_builtin_macros/src/lib.rs | 2 - .../rustc_builtin_macros/src/view_type.rs | 47 ------------------- compiler/rustc_feature/src/unstable.rs | 2 - compiler/rustc_parse/src/parser/mod.rs | 4 +- compiler/rustc_parse/src/parser/ty.rs | 15 ++++++ compiler/rustc_span/src/symbol.rs | 2 +- library/core/src/lib.rs | 2 +- library/core/src/view.rs | 14 +++--- library/std/src/lib.rs | 2 +- library/std/src/view.rs | 2 +- tests/ui/view-types/auxiliary/hygiene.rs | 2 +- tests/ui/view-types/duplicate_field.rs | 3 +- tests/ui/view-types/duplicate_field.stderr | 8 ++-- .../ui/view-types/feature-gate-view-types.rs | 4 +- .../view-types/feature-gate-view-types.stderr | 8 ++-- tests/ui/view-types/hygiene.rs | 2 +- tests/ui/view-types/must-be-struct.rs | 3 +- tests/ui/view-types/must-be-struct.stderr | 6 +-- tests/ui/view-types/must-exist.rs | 3 +- tests/ui/view-types/must-exist.stderr | 4 +- tests/ui/view-types/must-restrict.rs | 2 +- tests/ui/view-types/syntax-errors.rs | 3 +- tests/ui/view-types/syntax-errors.stderr | 20 ++++---- tests/ui/view-types/tuple-structs.rs | 2 +- 27 files changed, 67 insertions(+), 107 deletions(-) delete mode 100644 compiler/rustc_builtin_macros/src/view_type.rs diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 02adcc2296610..89105722f6c8e 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -241,9 +241,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { // Function pointers cannot be `const` self.check_late_bound_lifetime_defs(&fn_ptr_ty.generic_params); } - ast::TyKind::View(..) => { - gate!(self, view_types, ty.span, "view types are unstable"); - } _ => {} } visit::walk_ty(self, ty) @@ -466,7 +463,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { gate_all!(unnamed_enum_variants, "unnamed enum variants are experimental"); gate_all!(unsafe_binders, "unsafe binder types are experimental"); gate_all!(unsafe_fields, "`unsafe` fields are experimental"); - gate_all!(view_types, "view types are experimental"); gate_all!(where_clause_attrs, "attributes in `where` clause are unstable"); gate_all!(yeet_expr, "`do yeet` expression is experimental"); // tidy-alphabetical-end diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index a5dbaf81376c1..36096cb09eb1b 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1437,9 +1437,12 @@ impl<'a> State<'a> { self.word("..."); } ast::TyKind::Pat(ty, pat) => { + self.word("k#pattern_type"); + self.popen(); self.print_type(ty); self.word(" is "); self.print_ty_pat(pat); + self.pclose(); } ast::TyKind::FieldOf(ty, variant, field) => { self.word("k#field_of"); @@ -1459,8 +1462,11 @@ impl<'a> State<'a> { self.pclose(); } ast::TyKind::View(ty, fields) => { + self.word("k#view_type"); + self.popen(); self.print_type(ty); self.print_view(fields); + self.pclose(); } ast::TyKind::GcaMacro(expr) => { self.word_nbsp("core::gca!"); diff --git a/compiler/rustc_ast_pretty/src/pprust/tests.rs b/compiler/rustc_ast_pretty/src/pprust/tests.rs index 43bb68216d929..1a5a518ee41e0 100644 --- a/compiler/rustc_ast_pretty/src/pprust/tests.rs +++ b/compiler/rustc_ast_pretty/src/pprust/tests.rs @@ -80,6 +80,6 @@ fn test_field_view() { }; let ty_str = ty_to_string(&ty); - assert_eq!(ty_str, "(/*DUMMY*/).{ milhouse, apu }"); + assert_eq!(ty_str, "k#view_type((/*DUMMY*/).{ milhouse, apu })"); }); } diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 40c7872eda563..b2089f9b4567a 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -50,7 +50,6 @@ mod source_util; mod test; mod test_binder_constraints; mod trace_macros; -mod view_type; pub mod asm; pub mod cmdline_attrs; @@ -104,7 +103,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { test_binder_constraints: test_binder_constraints::expand, trace_macros: trace_macros::expand_trace_macros, unreachable: edition_panic::expand_unreachable, - view_type: view_type::expand, // tidy-alphabetical-end } diff --git a/compiler/rustc_builtin_macros/src/view_type.rs b/compiler/rustc_builtin_macros/src/view_type.rs deleted file mode 100644 index 69bd8f2727fc3..0000000000000 --- a/compiler/rustc_builtin_macros/src/view_type.rs +++ /dev/null @@ -1,47 +0,0 @@ -use rustc_ast::token::TokenKind; -use rustc_ast::tokenstream::TokenStream; -use rustc_ast::{Ty, ast}; -use rustc_errors::PResult; -use rustc_expand::base::{self, DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult}; -use rustc_parse::parser::{ExpTokenPair, TokenType}; -use rustc_span::{Ident, Span}; -use thin_vec::ThinVec; - -pub(crate) fn expand<'cx>( - cx: &'cx mut ExtCtxt<'_>, - sp: Span, - tts: TokenStream, -) -> MacroExpanderResult<'cx> { - let (ty, pat) = match parse_view_ty(cx, tts) { - Ok(parsed) => parsed, - Err(err) => { - return ExpandResult::Ready(DummyResult::any(sp, err.emit_err())); - } - }; - - ExpandResult::Ready(base::MacEager::ty(cx.ty(sp, ast::TyKind::View(ty, pat)))) -} - -fn parse_view_ty<'a>( - cx: &mut ExtCtxt<'a>, - stream: TokenStream, -) -> PResult<'a, (Box, ThinVec)> { - let mut parser = cx.new_parser_from_tts(stream); - - let ty = parser.parse_ty()?; - - parser.expect(ExpTokenPair { tok: TokenKind::Dot, token_type: TokenType::Dot })?; - - let fields = match parser.parse_delim_comma_seq( - ExpTokenPair { tok: TokenKind::OpenBrace, token_type: TokenType::OpenBrace }, - ExpTokenPair { tok: TokenKind::CloseBrace, token_type: TokenType::CloseBrace }, - |p| p.parse_field_name(), - ) { - Ok((fields, _)) => fields, - Err(diag) => { - return Err(diag); - } - }; - - Ok((ty, fields)) -} diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index a0d3e6e6d0de7..0347be78e3572 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -782,8 +782,6 @@ declare_features! ( (internal, unsized_fn_params, "1.49.0", Some(48055)), /// Allows using the `#[used(linker)]` (or `#[used(compiler)]`) attribute. (unstable, used_with_arg, "1.60.0", Some(93798)), - /// Allows view types. - (unstable, view_types, "1.97.0", Some(155938)), /// Target features on wasm. (unstable, wasm_target_feature, "1.30.0", Some(150260)), /// Allows use of attributes in `where` clauses. diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index a89fd9b6298f3..10f4d73e3e4cd 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1101,7 +1101,7 @@ impl<'a> Parser<'a> { /// Parses a comma-separated sequence, including both delimiters. /// The function `f` must consume tokens until reaching the next separator or /// closing bracket. - pub fn parse_delim_comma_seq( + fn parse_delim_comma_seq( &mut self, open: ExpTokenPair, close: ExpTokenPair, @@ -1351,7 +1351,7 @@ impl<'a> Parser<'a> { /// ```enbf /// FieldName = IntLit | Ident /// ``` - pub fn parse_field_name(&mut self) -> PResult<'a, Ident> { + fn parse_field_name(&mut self) -> PResult<'a, Ident> { if let token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) = self.token.kind { if let Some(suffix) = suffix { diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 029aab9e0e601..f09faad96e16a 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -425,6 +425,8 @@ impl<'a> Parser<'a> { self.parse_ty_field_of(lo)? } else if self.eat_forced_keyword_noexpect(kw::PatternType) { self.parse_pat_ty(lo)? + } else if self.eat_forced_keyword_noexpect(kw::ViewType) { + self.parse_view_ty(lo)? } else { let msg = format!("expected type, found {}", super::token_descr(&self.token)); let mut err = self.dcx().struct_span_err(lo, msg); @@ -923,6 +925,19 @@ impl<'a> Parser<'a> { ast::TyPat { id: DUMMY_NODE_ID, kind, span } } + fn parse_view_ty(&mut self, lo: Span) -> PResult<'a, ast::TyKind> { + self.expect(exp!(OpenParen))?; + let ty = self.parse_ty()?; + self.expect(exp!(Dot))?; + let (fields, _) = self + .parse_delim_comma_seq(exp!(OpenBrace), exp!(CloseBrace), |p| p.parse_field_name())?; + self.expect(exp!(CloseParen))?; + + self.psess.gated_spans.gate(sym::internal_syntax, lo.to(self.prev_token.span)); + + Ok(ast::TyKind::View(ty, fields)) + } + /// Parses a function pointer type (`TyKind::FnPtr`). /// ```ignore (illustrative) /// [unsafe] [extern "ABI"] fn (S) -> T diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 5c6998685e606..3c3e916ff8c1a 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -141,6 +141,7 @@ symbols! { TypeAscribe: "type_ascribe", Union: "union", UnwrapBinder: "unwrap_binder", + ViewType: "view_type", WrapBinder: "wrap_binder", Yeet: "yeet", // tidy-alphabetical-end @@ -2390,7 +2391,6 @@ symbols! { vgpr384, vgpr512, vgpr1024, - view_type, view_types, vis, visible_private_types, diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index b2000fa7192a2..41f8749a9399b 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -350,7 +350,7 @@ mod bool; mod escape; mod tuple; mod unit; -#[unstable(feature = "view_type_macro", issue = "155938")] +#[unstable(feature = "view_types", issue = "155938")] pub mod view; #[stable(feature = "core_primitive", since = "1.43.0")] diff --git a/library/core/src/view.rs b/library/core/src/view.rs index 68eca3f3598d2..c68382b2effc9 100644 --- a/library/core/src/view.rs +++ b/library/core/src/view.rs @@ -2,7 +2,7 @@ /// Creates a view type. /// ``` -/// #![feature(view_types, view_type_macro)] +/// #![feature(view_types)] // /// struct Foo { /// bar: usize, @@ -11,11 +11,9 @@ /// /// type FooBar = std::view::view_type!(Foo.{ bar }); /// ``` -#[macro_export] -#[rustc_builtin_macro(view_type)] -#[unstable(feature = "view_type_macro", issue = "155938")] -macro_rules! view_type { - ($($arg:tt)*) => { - /* compiler built-in */ - }; +#[allow_internal_unstable(internal_syntax)] +#[unstable(feature = "view_types", issue = "155938")] +#[diagnostic::opaque] +pub macro view_type($($arg:tt)*) { + k#view_type($($arg)*) } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 0c3d29324c9ae..6b0d32f3ba5f2 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -649,7 +649,7 @@ pub mod process; pub mod random; pub mod sync; pub mod time; -#[unstable(feature = "view_type_macro", issue = "155938")] +#[unstable(feature = "view_types", issue = "155938")] pub mod view; // Pull in `std_float` crate into std. The contents of diff --git a/library/std/src/view.rs b/library/std/src/view.rs index 5806cf27c2cc8..3e0e7d1d1038a 100644 --- a/library/std/src/view.rs +++ b/library/std/src/view.rs @@ -1,3 +1,3 @@ //! Helper module for exporting the `view_types` macro. -pub use core::view_type; +pub use core::view::view_type; diff --git a/tests/ui/view-types/auxiliary/hygiene.rs b/tests/ui/view-types/auxiliary/hygiene.rs index cf842b56e6970..3b022299733c9 100644 --- a/tests/ui/view-types/auxiliary/hygiene.rs +++ b/tests/ui/view-types/auxiliary/hygiene.rs @@ -1,6 +1,6 @@ //@ edition:2015 -#![feature(view_types, view_type_macro)] +#![feature(view_types)] pub use std::view::view_type; diff --git a/tests/ui/view-types/duplicate_field.rs b/tests/ui/view-types/duplicate_field.rs index b45580510b6cb..4b3e0ca0850e0 100644 --- a/tests/ui/view-types/duplicate_field.rs +++ b/tests/ui/view-types/duplicate_field.rs @@ -1,5 +1,4 @@ -#![feature(view_types, view_type_macro)] -#![allow(unused)] +#![feature(view_types)] use std::view::view_type; diff --git a/tests/ui/view-types/duplicate_field.stderr b/tests/ui/view-types/duplicate_field.stderr index f0162f6e0a67d..c974b0ead238a 100644 --- a/tests/ui/view-types/duplicate_field.stderr +++ b/tests/ui/view-types/duplicate_field.stderr @@ -1,5 +1,5 @@ error: field `bar` is already part of the view - --> $DIR/duplicate_field.rs:13:38 + --> $DIR/duplicate_field.rs:12:38 | LL | _foo: &mut view_type!(Foo.{ bar, bar }), | --- ^^^ @@ -7,7 +7,7 @@ LL | _foo: &mut view_type!(Foo.{ bar, bar }), | field `bar` is declared as viewed here error: field `0` is already part of the view - --> $DIR/duplicate_field.rs:15:38 + --> $DIR/duplicate_field.rs:14:38 | LL | _pair: &mut view_type!(Pair.{ 0, 0 }), | - ^ @@ -15,7 +15,7 @@ LL | _pair: &mut view_type!(Pair.{ 0, 0 }), | field `0` is declared as viewed here error: field `bar` is already part of the view - --> $DIR/duplicate_field.rs:21:44 + --> $DIR/duplicate_field.rs:20:44 | LL | fn f(self: &mut view_type!(Self.{ bar, bar })) {} | --- ^^^ @@ -23,7 +23,7 @@ LL | fn f(self: &mut view_type!(Self.{ bar, bar })) {} | field `bar` is declared as viewed here error: field `0` is already part of the view - --> $DIR/duplicate_field.rs:26:42 + --> $DIR/duplicate_field.rs:25:42 | LL | fn f(self: &mut view_type!(Self.{ 0, 0 })) {} | - ^ diff --git a/tests/ui/view-types/feature-gate-view-types.rs b/tests/ui/view-types/feature-gate-view-types.rs index 961f96e18bb99..d30c737c130c7 100644 --- a/tests/ui/view-types/feature-gate-view-types.rs +++ b/tests/ui/view-types/feature-gate-view-types.rs @@ -8,6 +8,6 @@ struct Foo { } type FooBar = view_type!(Foo.{ bar }); -//~^ ERROR use of unstable library feature `view_type_macro` +//~^ ERROR use of unstable library feature `view_types` type FooBaz = view_type!(Foo.{ baz }); -//~^ ERROR use of unstable library feature `view_type_macro` +//~^ ERROR use of unstable library feature `view_types` diff --git a/tests/ui/view-types/feature-gate-view-types.stderr b/tests/ui/view-types/feature-gate-view-types.stderr index 407bf343ca13b..bda3aebf2b744 100644 --- a/tests/ui/view-types/feature-gate-view-types.stderr +++ b/tests/ui/view-types/feature-gate-view-types.stderr @@ -1,21 +1,21 @@ -error[E0658]: use of unstable library feature `view_type_macro` +error[E0658]: use of unstable library feature `view_types` --> $DIR/feature-gate-view-types.rs:10:15 | LL | type FooBar = view_type!(Foo.{ bar }); | ^^^^^^^^^ | = note: see issue #155938 for more information - = help: add `#![feature(view_type_macro)]` to the crate attributes to enable + = help: add `#![feature(view_types)]` 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[E0658]: use of unstable library feature `view_type_macro` +error[E0658]: use of unstable library feature `view_types` --> $DIR/feature-gate-view-types.rs:12:15 | LL | type FooBaz = view_type!(Foo.{ baz }); | ^^^^^^^^^ | = note: see issue #155938 for more information - = help: add `#![feature(view_type_macro)]` to the crate attributes to enable + = help: add `#![feature(view_types)]` 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 diff --git a/tests/ui/view-types/hygiene.rs b/tests/ui/view-types/hygiene.rs index 15a9f7f228f90..20d184e184697 100644 --- a/tests/ui/view-types/hygiene.rs +++ b/tests/ui/view-types/hygiene.rs @@ -1,7 +1,7 @@ //@ run-pass //@ aux-build: hygiene.rs -#![feature(view_types, view_type_macro, decl_macro)] +#![feature(view_types, decl_macro)] #![allow(unused)] extern crate hygiene; diff --git a/tests/ui/view-types/must-be-struct.rs b/tests/ui/view-types/must-be-struct.rs index fb30ef1234cc5..2ee8fb6430f13 100644 --- a/tests/ui/view-types/must-be-struct.rs +++ b/tests/ui/view-types/must-be-struct.rs @@ -1,5 +1,4 @@ -#![feature(view_types, view_type_macro)] -#![allow(unused)] +#![feature(view_types)] use std::view::view_type; diff --git a/tests/ui/view-types/must-be-struct.stderr b/tests/ui/view-types/must-be-struct.stderr index 3d47e4903af6c..51b6f0bec8ebe 100644 --- a/tests/ui/view-types/must-be-struct.stderr +++ b/tests/ui/view-types/must-be-struct.stderr @@ -1,17 +1,17 @@ error: only structs can be viewed - --> $DIR/must-be-struct.rs:11:9 + --> $DIR/must-be-struct.rs:10:9 | LL | fn f(_: view_type!(Foo.{})) {} | ^^^^^^^^^^^^^^^^^^ `Foo` is an enum, it cannot be viewed error: only structs can be viewed - --> $DIR/must-be-struct.rs:13:9 + --> $DIR/must-be-struct.rs:12:9 | LL | fn g(_: view_type!(u8.{})) {} | ^^^^^^^^^^^^^^^^^ type `u8` cannot be viewed error: only structs can be viewed - --> $DIR/must-be-struct.rs:15:9 + --> $DIR/must-be-struct.rs:14:9 | LL | fn h(_: view_type!(char.{})) {} | ^^^^^^^^^^^^^^^^^^^ type `char` cannot be viewed diff --git a/tests/ui/view-types/must-exist.rs b/tests/ui/view-types/must-exist.rs index efb43eb509e9c..da912c1ee9749 100644 --- a/tests/ui/view-types/must-exist.rs +++ b/tests/ui/view-types/must-exist.rs @@ -1,5 +1,4 @@ -#![feature(view_types, view_type_macro)] -#![allow(unused)] +#![feature(view_types)] use std::view::view_type; diff --git a/tests/ui/view-types/must-exist.stderr b/tests/ui/view-types/must-exist.stderr index a775ad84a7edf..d977f060754d2 100644 --- a/tests/ui/view-types/must-exist.stderr +++ b/tests/ui/view-types/must-exist.stderr @@ -1,11 +1,11 @@ error[E0609]: no field `bar` on type `S` - --> $DIR/must-exist.rs:10:24 + --> $DIR/must-exist.rs:9:24 | LL | fn f(_: view_type!(S.{ bar })) {} | ^^^ error[E0609]: no field `bar` on type `S` - --> $DIR/must-exist.rs:12:29 + --> $DIR/must-exist.rs:11:29 | LL | fn g(_: view_type!(S.{ foo, bar })) {} | ^^^ diff --git a/tests/ui/view-types/must-restrict.rs b/tests/ui/view-types/must-restrict.rs index c0e1f5115d27c..a523f07e9aadd 100644 --- a/tests/ui/view-types/must-restrict.rs +++ b/tests/ui/view-types/must-restrict.rs @@ -1,7 +1,7 @@ //@ known-bug: unknown //@ run-pass -#![feature(view_types, view_type_macro)] +#![feature(view_types)] #![allow(unused)] use std::view::view_type; diff --git a/tests/ui/view-types/syntax-errors.rs b/tests/ui/view-types/syntax-errors.rs index 18ccb859d549e..84bcb977827e0 100644 --- a/tests/ui/view-types/syntax-errors.rs +++ b/tests/ui/view-types/syntax-errors.rs @@ -1,5 +1,4 @@ -#![feature(view_types, view_type_macro)] -#![allow(unused)] +#![feature(view_types)] use std::view::view_type; diff --git a/tests/ui/view-types/syntax-errors.stderr b/tests/ui/view-types/syntax-errors.stderr index 1c1e5fdafae1a..479151b267e2e 100644 --- a/tests/ui/view-types/syntax-errors.stderr +++ b/tests/ui/view-types/syntax-errors.stderr @@ -1,17 +1,17 @@ error: expected identifier, found reserved identifier `_` - --> $DIR/syntax-errors.rs:12:49 + --> $DIR/syntax-errors.rs:11:49 | LL | fn not_a_field(self: &mut view_type!(Self.{ _ }), _: &mut view_type!(Foo.{ _ })) {} | ^ expected identifier, found reserved identifier error: expected identifier, found reserved identifier `_` - --> $DIR/syntax-errors.rs:12:80 + --> $DIR/syntax-errors.rs:11:80 | LL | fn not_a_field(self: &mut view_type!(Self.{ _ }), _: &mut view_type!(Foo.{ _ })) {} | ^ expected identifier, found reserved identifier error: expected identifier, found keyword `where` - --> $DIR/syntax-errors.rs:18:44 + --> $DIR/syntax-errors.rs:17:44 | LL | fn keyword(self: &mut view_type!(Foo.{ where }), _: &mut view_type!(Foo.{ for })) {} | ^^^^^ expected identifier, found keyword @@ -22,7 +22,7 @@ LL | fn keyword(self: &mut view_type!(Foo.{ r#where }), _: &mut view_type!(F | ++ error: expected identifier, found keyword `for` - --> $DIR/syntax-errors.rs:18:79 + --> $DIR/syntax-errors.rs:17:79 | LL | fn keyword(self: &mut view_type!(Foo.{ where }), _: &mut view_type!(Foo.{ for })) {} | ^^^ expected identifier, found keyword @@ -33,7 +33,7 @@ LL | fn keyword(self: &mut view_type!(Foo.{ where }), _: &mut view_type!(Foo | ++ error: expected one of `,` or `}`, found `baz` - --> $DIR/syntax-errors.rs:24:49 + --> $DIR/syntax-errors.rs:23:49 | LL | fn no_comma(self: &mut view_type!(Foo.{ bar baz }), _: &mut view_type!(Foo.{ bar baz })) {} | -^^^ expected one of `,` or `}` @@ -41,7 +41,7 @@ LL | fn no_comma(self: &mut view_type!(Foo.{ bar baz }), _: &mut view_type!( | help: missing `,` error: expected one of `,` or `}`, found `baz` - --> $DIR/syntax-errors.rs:24:86 + --> $DIR/syntax-errors.rs:23:86 | LL | fn no_comma(self: &mut view_type!(Foo.{ bar baz }), _: &mut view_type!(Foo.{ bar baz })) {} | -^^^ expected one of `,` or `}` @@ -49,25 +49,25 @@ LL | fn no_comma(self: &mut view_type!(Foo.{ bar baz }), _: &mut view_type!( | help: missing `,` error[E0609]: no field `_` on type `Foo` - --> $DIR/syntax-errors.rs:12:49 + --> $DIR/syntax-errors.rs:11:49 | LL | fn not_a_field(self: &mut view_type!(Self.{ _ }), _: &mut view_type!(Foo.{ _ })) {} | ^ error[E0609]: no field `_` on type `Foo` - --> $DIR/syntax-errors.rs:12:80 + --> $DIR/syntax-errors.rs:11:80 | LL | fn not_a_field(self: &mut view_type!(Self.{ _ }), _: &mut view_type!(Foo.{ _ })) {} | ^ error[E0609]: no field `r#where` on type `Foo` - --> $DIR/syntax-errors.rs:18:44 + --> $DIR/syntax-errors.rs:17:44 | LL | fn keyword(self: &mut view_type!(Foo.{ where }), _: &mut view_type!(Foo.{ for })) {} | ^^^^^ error[E0609]: no field `r#for` on type `Foo` - --> $DIR/syntax-errors.rs:18:79 + --> $DIR/syntax-errors.rs:17:79 | LL | fn keyword(self: &mut view_type!(Foo.{ where }), _: &mut view_type!(Foo.{ for })) {} | ^^^ diff --git a/tests/ui/view-types/tuple-structs.rs b/tests/ui/view-types/tuple-structs.rs index f0442d4e308fb..04dd222cef98d 100644 --- a/tests/ui/view-types/tuple-structs.rs +++ b/tests/ui/view-types/tuple-structs.rs @@ -1,6 +1,6 @@ //@ run-pass -#![feature(view_types, view_type_macro)] +#![feature(view_types)] #![allow(unused)] use std::view::view_type; From 50f93bcd35408b993986c0c664bdccda2f91d369 Mon Sep 17 00:00:00 2001 From: zakrad <49591476+zakrad@users.noreply.github.com> Date: Wed, 11 Nov 2026 20:13:45 +0330 Subject: [PATCH 10/10] Add regression test for HRTB projection bound with TryFrom error --- .../try-from-error-debug-bound-81162.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/ui/higher-ranked/trait-bounds/normalize-under-binder/try-from-error-debug-bound-81162.rs diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/try-from-error-debug-bound-81162.rs b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/try-from-error-debug-bound-81162.rs new file mode 100644 index 0000000000000..b5a233672f594 --- /dev/null +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/try-from-error-debug-bound-81162.rs @@ -0,0 +1,17 @@ +//! Regression test for . +//@ check-pass + +use std::convert::TryFrom; +use std::fmt::Debug; + +fn read() -> Vec +where + for<'a> T: TryFrom<&'a [f32]>, + for<'a> >::Error: Debug, +{ + Vec::new() +} + +fn main() { + let _ = read::<[f32; 128]>(); +}