Skip to content

Commit 69fef92

Browse files
committed
Auto merge of #111526 - Dylan-DPC:rollup-h75agro, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #110454 (Require impl Trait in associated types to appear in method signatures) - #111096 (Add support for `cfg(overflow_checks)`) - #111451 (Note user-facing types of coercion failure) - #111469 (Fix data race in llvm source code coverage) - #111494 (Encode `VariantIdx` so we can decode ADT variants in the right order) - #111499 (asm: loongarch64: Drop efiapi) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 16d3e18 + 1533eaf commit 69fef92

File tree

116 files changed

+831
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+831
-318
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
305305
);
306306
this.arena.alloc(this.ty(span, hir::TyKind::Err(guar)))
307307
}
308-
Some(ty) => this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy),
308+
Some(ty) => this.lower_ty(
309+
ty,
310+
&ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty: false },
311+
),
309312
},
310313
);
311314
hir::ItemKind::TyAlias(ty, generics)
@@ -852,7 +855,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
852855
hir::ImplItemKind::Type(ty)
853856
}
854857
Some(ty) => {
855-
let ty = this.lower_ty(ty, &ImplTraitContext::TypeAliasesOpaqueTy);
858+
let ty = this.lower_ty(
859+
ty,
860+
&ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty: true },
861+
);
856862
hir::ImplItemKind::Type(ty)
857863
}
858864
},

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ enum ImplTraitContext {
247247
in_trait: bool,
248248
},
249249
/// Impl trait in type aliases.
250-
TypeAliasesOpaqueTy,
250+
TypeAliasesOpaqueTy { in_assoc_ty: bool },
251251
/// `impl Trait` is unstably accepted in this position.
252252
FeatureGated(ImplTraitPosition, Symbol),
253253
/// `impl Trait` is not accepted in this position.
@@ -1407,14 +1407,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14071407
*in_trait,
14081408
itctx,
14091409
),
1410-
ImplTraitContext::TypeAliasesOpaqueTy => self.lower_opaque_impl_trait(
1411-
span,
1412-
hir::OpaqueTyOrigin::TyAlias,
1413-
*def_node_id,
1414-
bounds,
1415-
false,
1416-
itctx,
1417-
),
1410+
&ImplTraitContext::TypeAliasesOpaqueTy { in_assoc_ty } => self
1411+
.lower_opaque_impl_trait(
1412+
span,
1413+
hir::OpaqueTyOrigin::TyAlias { in_assoc_ty },
1414+
*def_node_id,
1415+
bounds,
1416+
false,
1417+
itctx,
1418+
),
14181419
ImplTraitContext::Universal => {
14191420
let span = t.span;
14201421
self.create_def(
@@ -1534,13 +1535,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15341535
// If this came from a TAIT (as opposed to a function that returns an RPIT), we only want
15351536
// to capture the lifetimes that appear in the bounds. So visit the bounds to find out
15361537
// exactly which ones those are.
1537-
let lifetimes_to_remap = if origin == hir::OpaqueTyOrigin::TyAlias {
1538-
// in a TAIT like `type Foo<'a> = impl Foo<'a>`, we don't keep all the lifetime parameters
1539-
Vec::new()
1540-
} else {
1541-
// in fn return position, like the `fn test<'a>() -> impl Debug + 'a` example,
1542-
// we only keep the lifetimes that appear in the `impl Debug` itself:
1543-
lifetime_collector::lifetimes_in_bounds(&self.resolver, bounds)
1538+
let lifetimes_to_remap = match origin {
1539+
hir::OpaqueTyOrigin::TyAlias { .. } => {
1540+
// in a TAIT like `type Foo<'a> = impl Foo<'a>`, we don't keep all the lifetime parameters
1541+
Vec::new()
1542+
}
1543+
hir::OpaqueTyOrigin::AsyncFn(..) | hir::OpaqueTyOrigin::FnReturn(..) => {
1544+
// in fn return position, like the `fn test<'a>() -> impl Debug + 'a` example,
1545+
// we only keep the lifetimes that appear in the `impl Debug` itself:
1546+
lifetime_collector::lifetimes_in_bounds(&self.resolver, bounds)
1547+
}
15441548
};
15451549
debug!(?lifetimes_to_remap);
15461550

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
265265

266266
// Only check this for TAIT. RPIT already supports `tests/ui/impl-trait/nested-return-type2.rs`
267267
// on stable and we'd break that.
268-
let OpaqueTyOrigin::TyAlias = origin else {
268+
let OpaqueTyOrigin::TyAlias { .. } = origin else {
269269
return definition_ty;
270270
};
271271
let def_id = opaque_type_key.def_id;
@@ -360,7 +360,7 @@ fn check_opaque_type_parameter_valid(
360360
// which would error here on all of the `'static` args.
361361
OpaqueTyOrigin::FnReturn(..) | OpaqueTyOrigin::AsyncFn(..) => return Ok(()),
362362
// Check these
363-
OpaqueTyOrigin::TyAlias => {}
363+
OpaqueTyOrigin::TyAlias { .. } => {}
364364
}
365365
let opaque_generics = tcx.generics_of(opaque_type_key.def_id);
366366
let mut seen_params: FxIndexMap<_, Vec<_>> = FxIndexMap::default();

compiler/rustc_feature/src/active.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ declare_features! (
321321
(active, c_unwind, "1.52.0", Some(74990), None),
322322
/// Allows using C-variadics.
323323
(active, c_variadic, "1.34.0", Some(44930), None),
324+
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.
325+
(active, cfg_overflow_checks, "CURRENT_RUSTC_VERSION", Some(111466), None),
324326
/// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
325327
(active, cfg_sanitize, "1.41.0", Some(39699), None),
326328
/// Allows `cfg(target_abi = "...")`.

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub type GatedCfg = (Symbol, Symbol, GateFn);
2424
/// `cfg(...)`'s that are feature gated.
2525
const GATED_CFGS: &[GatedCfg] = &[
2626
// (name in cfg, feature, function to check if the feature is enabled)
27+
(sym::overflow_checks, sym::cfg_overflow_checks, cfg_fn!(cfg_overflow_checks)),
2728
(sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)),
2829
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
2930
(

compiler/rustc_hir/src/hir.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,10 @@ pub enum OpaqueTyOrigin {
26622662
/// `async fn`
26632663
AsyncFn(LocalDefId),
26642664
/// type aliases: `type Foo = impl Trait;`
2665-
TyAlias,
2665+
TyAlias {
2666+
/// associated types in impl blocks for traits.
2667+
in_assoc_ty: bool,
2668+
},
26662669
}
26672670

26682671
/// The various kinds of types recognized by the compiler.

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ fn check_opaque_meets_bounds<'tcx>(
397397
) {
398398
let defining_use_anchor = match *origin {
399399
hir::OpaqueTyOrigin::FnReturn(did) | hir::OpaqueTyOrigin::AsyncFn(did) => did,
400-
hir::OpaqueTyOrigin::TyAlias => def_id,
400+
hir::OpaqueTyOrigin::TyAlias { .. } => tcx.impl_trait_parent(def_id),
401401
};
402402
let param_env = tcx.param_env(defining_use_anchor);
403403

@@ -455,10 +455,10 @@ fn check_opaque_meets_bounds<'tcx>(
455455
// They can only be referenced as `<Opaque<T> as Trait<&'static T>>::AssocTy`.
456456
// We don't have to check them here because their well-formedness follows from the WF of
457457
// the projection input types in the defining- and use-sites.
458-
hir::OpaqueTyOrigin::TyAlias
458+
hir::OpaqueTyOrigin::TyAlias { .. }
459459
if tcx.def_kind(tcx.parent(def_id.to_def_id())) == DefKind::OpaqueTy => {}
460460
// Can have different predicates to their defining use
461-
hir::OpaqueTyOrigin::TyAlias => {
461+
hir::OpaqueTyOrigin::TyAlias { .. } => {
462462
let wf_tys = ocx.assumed_wf_types(param_env, span, def_id);
463463
let implied_bounds = infcx.implied_bounds_tys(param_env, def_id, wf_tys);
464464
let outlives_env = OutlivesEnvironment::with_bounds(param_env, implied_bounds);

compiler/rustc_hir_analysis/src/check/dropck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::{struct_span_err, ErrorGuaranteed};
66
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
77
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
88
use rustc_middle::ty::subst::SubstsRef;
9-
use rustc_middle::ty::util::IgnoreRegions;
9+
use rustc_middle::ty::util::CheckRegions;
1010
use rustc_middle::ty::{self, TyCtxt};
1111
use rustc_trait_selection::traits::{self, ObligationCtxt};
1212

@@ -81,7 +81,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
8181
self_type_did: DefId,
8282
adt_to_impl_substs: SubstsRef<'tcx>,
8383
) -> Result<(), ErrorGuaranteed> {
84-
let Err(arg) = tcx.uses_unique_generic_params(adt_to_impl_substs, IgnoreRegions::No) else {
84+
let Err(arg) = tcx.uses_unique_generic_params(adt_to_impl_substs, CheckRegions::OnlyEarlyBound) else {
8585
return Ok(())
8686
};
8787

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::{struct_span_err, DelayDm};
66
use rustc_errors::{Diagnostic, ErrorGuaranteed};
77
use rustc_hir as hir;
88
use rustc_middle::ty::subst::InternalSubsts;
9-
use rustc_middle::ty::util::IgnoreRegions;
9+
use rustc_middle::ty::util::CheckRegions;
1010
use rustc_middle::ty::{
1111
self, AliasKind, ImplPolarity, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
1212
TypeVisitor,
@@ -507,7 +507,7 @@ fn lint_auto_trait_impl<'tcx>(
507507
// Impls which completely cover a given root type are fine as they
508508
// disable auto impls entirely. So only lint if the substs
509509
// are not a permutation of the identity substs.
510-
let Err(arg) = tcx.uses_unique_generic_params(substs, IgnoreRegions::Yes) else {
510+
let Err(arg) = tcx.uses_unique_generic_params(substs, CheckRegions::No) else {
511511
// ok
512512
return;
513513
};

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ fn generator_kind(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<hir::GeneratorK
14831483
fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> bool {
14841484
match tcx.hir().get_by_def_id(def_id) {
14851485
Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(opaque), .. }) => {
1486-
matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias)
1486+
matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias { .. })
14871487
}
14881488
_ => bug!("tried getting opaque_ty_origin for non-opaque: {:?}", def_id),
14891489
}

0 commit comments

Comments
 (0)