Skip to content

Commit c9f9648

Browse files
authored
Merge pull request #4485 from rust-lang/rustup-2025-07-20
Automatic Rustup
2 parents 627c031 + c317580 commit c9f9648

File tree

379 files changed

+4858
-2039
lines changed

Some content is hidden

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

379 files changed

+4858
-2039
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::fmt;
4343
#[cfg(feature = "nightly")]
4444
use std::iter::Step;
4545
use std::num::{NonZeroUsize, ParseIntError};
46-
use std::ops::{Add, AddAssign, Deref, Mul, RangeInclusive, Sub};
46+
use std::ops::{Add, AddAssign, Deref, Mul, RangeFull, RangeInclusive, Sub};
4747
use std::str::FromStr;
4848

4949
use bitflags::bitflags;
@@ -1391,12 +1391,45 @@ impl WrappingRange {
13911391
}
13921392

13931393
/// Returns `true` if `size` completely fills the range.
1394+
///
1395+
/// Note that this is *not* the same as `self == WrappingRange::full(size)`.
1396+
/// Niche calculations can produce full ranges which are not the canonical one;
1397+
/// for example `Option<NonZero<u16>>` gets `valid_range: (..=0) | (1..)`.
13941398
#[inline]
13951399
fn is_full_for(&self, size: Size) -> bool {
13961400
let max_value = size.unsigned_int_max();
13971401
debug_assert!(self.start <= max_value && self.end <= max_value);
13981402
self.start == (self.end.wrapping_add(1) & max_value)
13991403
}
1404+
1405+
/// Checks whether this range is considered non-wrapping when the values are
1406+
/// interpreted as *unsigned* numbers of width `size`.
1407+
///
1408+
/// Returns `Ok(true)` if there's no wrap-around, `Ok(false)` if there is,
1409+
/// and `Err(..)` if the range is full so it depends how you think about it.
1410+
#[inline]
1411+
pub fn no_unsigned_wraparound(&self, size: Size) -> Result<bool, RangeFull> {
1412+
if self.is_full_for(size) { Err(..) } else { Ok(self.start <= self.end) }
1413+
}
1414+
1415+
/// Checks whether this range is considered non-wrapping when the values are
1416+
/// interpreted as *signed* numbers of width `size`.
1417+
///
1418+
/// This is heavily dependent on the `size`, as `100..=200` does wrap when
1419+
/// interpreted as `i8`, but doesn't when interpreted as `i16`.
1420+
///
1421+
/// Returns `Ok(true)` if there's no wrap-around, `Ok(false)` if there is,
1422+
/// and `Err(..)` if the range is full so it depends how you think about it.
1423+
#[inline]
1424+
pub fn no_signed_wraparound(&self, size: Size) -> Result<bool, RangeFull> {
1425+
if self.is_full_for(size) {
1426+
Err(..)
1427+
} else {
1428+
let start: i128 = size.sign_extend(self.start);
1429+
let end: i128 = size.sign_extend(self.end);
1430+
Ok(start <= end)
1431+
}
1432+
}
14001433
}
14011434

14021435
impl fmt::Debug for WrappingRange {

compiler/rustc_ast_lowering/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ ast_lowering_misplaced_impl_trait =
127127
`impl Trait` is not allowed in {$position}
128128
.note = `impl Trait` is only allowed in arguments and return types of functions and methods
129129
130-
ast_lowering_misplaced_relax_trait_bound =
131-
`?Trait` bounds are only permitted at the point where a type parameter is declared
132-
133130
ast_lowering_never_pattern_with_body =
134131
a never pattern is always unreachable
135132
.label = this will never be executed

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,6 @@ pub(crate) struct MisplacedDoubleDot {
324324
pub span: Span,
325325
}
326326

327-
#[derive(Diagnostic)]
328-
#[diag(ast_lowering_misplaced_relax_trait_bound)]
329-
pub(crate) struct MisplacedRelaxTraitBound {
330-
#[primary_span]
331-
pub span: Span,
332-
}
333-
334327
#[derive(Diagnostic)]
335328
#[diag(ast_lowering_match_arm_with_no_body)]
336329
pub(crate) struct MatchArmWithNoBody {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 38 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@ use smallvec::{SmallVec, smallvec};
1616
use thin_vec::ThinVec;
1717
use tracing::instrument;
1818

19-
use super::errors::{
20-
InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
21-
UnionWithDefault,
22-
};
19+
use super::errors::{InvalidAbi, InvalidAbiSuggestion, TupleStructWithDefault, UnionWithDefault};
2320
use super::stability::{enabled_names, gate_unstable_abi};
2421
use super::{
2522
AstOwner, FnDeclKind, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode,
26-
ResolverAstLoweringExt,
23+
RelaxedBoundForbiddenReason, RelaxedBoundPolicy, ResolverAstLoweringExt,
2724
};
2825

2926
pub(super) struct ItemLowerer<'a, 'hir> {
@@ -435,6 +432,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
435432
|this| {
436433
let bounds = this.lower_param_bounds(
437434
bounds,
435+
RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::SuperTrait),
438436
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
439437
);
440438
let items = this.arena.alloc_from_iter(
@@ -455,6 +453,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
455453
|this| {
456454
this.lower_param_bounds(
457455
bounds,
456+
RelaxedBoundPolicy::Allowed,
458457
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
459458
)
460459
},
@@ -940,6 +939,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
940939
hir::TraitItemKind::Type(
941940
this.lower_param_bounds(
942941
bounds,
942+
RelaxedBoundPolicy::Allowed,
943943
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
944944
),
945945
ty,
@@ -1677,61 +1677,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
16771677
assert!(self.impl_trait_defs.is_empty());
16781678
assert!(self.impl_trait_bounds.is_empty());
16791679

1680-
// Error if `?Trait` bounds in where clauses don't refer directly to type parameters.
1681-
// Note: we used to clone these bounds directly onto the type parameter (and avoid lowering
1682-
// these into hir when we lower thee where clauses), but this makes it quite difficult to
1683-
// keep track of the Span info. Now, `<dyn HirTyLowerer>::add_implicit_sized_bound`
1684-
// checks both param bounds and where clauses for `?Sized`.
1685-
for pred in &generics.where_clause.predicates {
1686-
let WherePredicateKind::BoundPredicate(bound_pred) = &pred.kind else {
1687-
continue;
1688-
};
1689-
let compute_is_param = || {
1690-
// Check if the where clause type is a plain type parameter.
1691-
match self
1692-
.resolver
1693-
.get_partial_res(bound_pred.bounded_ty.id)
1694-
.and_then(|r| r.full_res())
1695-
{
1696-
Some(Res::Def(DefKind::TyParam, def_id))
1697-
if bound_pred.bound_generic_params.is_empty() =>
1698-
{
1699-
generics
1700-
.params
1701-
.iter()
1702-
.any(|p| def_id == self.local_def_id(p.id).to_def_id())
1703-
}
1704-
// Either the `bounded_ty` is not a plain type parameter, or
1705-
// it's not found in the generic type parameters list.
1706-
_ => false,
1707-
}
1708-
};
1709-
// We only need to compute this once per `WherePredicate`, but don't
1710-
// need to compute this at all unless there is a Maybe bound.
1711-
let mut is_param: Option<bool> = None;
1712-
for bound in &bound_pred.bounds {
1713-
if !matches!(
1714-
*bound,
1715-
GenericBound::Trait(PolyTraitRef {
1716-
modifiers: TraitBoundModifiers { polarity: BoundPolarity::Maybe(_), .. },
1717-
..
1718-
})
1719-
) {
1720-
continue;
1721-
}
1722-
let is_param = *is_param.get_or_insert_with(compute_is_param);
1723-
if !is_param && !self.tcx.features().more_maybe_bounds() {
1724-
self.tcx
1725-
.sess
1726-
.create_feature_err(
1727-
MisplacedRelaxTraitBound { span: bound.span() },
1728-
sym::more_maybe_bounds,
1729-
)
1730-
.emit();
1731-
}
1732-
}
1733-
}
1734-
17351680
let mut predicates: SmallVec<[hir::WherePredicate<'hir>; 4]> = SmallVec::new();
17361681
predicates.extend(generics.params.iter().filter_map(|param| {
17371682
self.lower_generic_bound_predicate(
@@ -1741,6 +1686,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17411686
&param.bounds,
17421687
param.colon_span,
17431688
generics.span,
1689+
RelaxedBoundPolicy::Allowed,
17441690
itctx,
17451691
PredicateOrigin::GenericParam,
17461692
)
@@ -1750,7 +1696,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17501696
.where_clause
17511697
.predicates
17521698
.iter()
1753-
.map(|predicate| self.lower_where_predicate(predicate)),
1699+
.map(|predicate| self.lower_where_predicate(predicate, &generics.params)),
17541700
);
17551701

17561702
let mut params: SmallVec<[hir::GenericParam<'hir>; 4]> = self
@@ -1827,6 +1773,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18271773
bounds: &[GenericBound],
18281774
colon_span: Option<Span>,
18291775
parent_span: Span,
1776+
rbp: RelaxedBoundPolicy<'_>,
18301777
itctx: ImplTraitContext,
18311778
origin: PredicateOrigin,
18321779
) -> Option<hir::WherePredicate<'hir>> {
@@ -1835,7 +1782,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18351782
return None;
18361783
}
18371784

1838-
let bounds = self.lower_param_bounds(bounds, itctx);
1785+
let bounds = self.lower_param_bounds(bounds, rbp, itctx);
18391786

18401787
let param_span = ident.span;
18411788

@@ -1887,7 +1834,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
18871834
Some(hir::WherePredicate { hir_id, span, kind })
18881835
}
18891836

1890-
fn lower_where_predicate(&mut self, pred: &WherePredicate) -> hir::WherePredicate<'hir> {
1837+
fn lower_where_predicate(
1838+
&mut self,
1839+
pred: &WherePredicate,
1840+
params: &[ast::GenericParam],
1841+
) -> hir::WherePredicate<'hir> {
18911842
let hir_id = self.lower_node_id(pred.id);
18921843
let span = self.lower_span(pred.span);
18931844
self.lower_attrs(hir_id, &pred.attrs, span);
@@ -1896,17 +1847,29 @@ impl<'hir> LoweringContext<'_, 'hir> {
18961847
bound_generic_params,
18971848
bounded_ty,
18981849
bounds,
1899-
}) => hir::WherePredicateKind::BoundPredicate(hir::WhereBoundPredicate {
1900-
bound_generic_params: self
1901-
.lower_generic_params(bound_generic_params, hir::GenericParamSource::Binder),
1902-
bounded_ty: self
1903-
.lower_ty(bounded_ty, ImplTraitContext::Disallowed(ImplTraitPosition::Bound)),
1904-
bounds: self.lower_param_bounds(
1905-
bounds,
1906-
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
1907-
),
1908-
origin: PredicateOrigin::WhereClause,
1909-
}),
1850+
}) => {
1851+
let rbp = if bound_generic_params.is_empty() {
1852+
RelaxedBoundPolicy::AllowedIfOnTyParam(bounded_ty.id, params)
1853+
} else {
1854+
RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::LateBoundVarsInScope)
1855+
};
1856+
hir::WherePredicateKind::BoundPredicate(hir::WhereBoundPredicate {
1857+
bound_generic_params: self.lower_generic_params(
1858+
bound_generic_params,
1859+
hir::GenericParamSource::Binder,
1860+
),
1861+
bounded_ty: self.lower_ty(
1862+
bounded_ty,
1863+
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
1864+
),
1865+
bounds: self.lower_param_bounds(
1866+
bounds,
1867+
rbp,
1868+
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
1869+
),
1870+
origin: PredicateOrigin::WhereClause,
1871+
})
1872+
}
19101873
WherePredicateKind::RegionPredicate(WhereRegionPredicate { lifetime, bounds }) => {
19111874
hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {
19121875
lifetime: self.lower_lifetime(
@@ -1916,6 +1879,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19161879
),
19171880
bounds: self.lower_param_bounds(
19181881
bounds,
1882+
RelaxedBoundPolicy::Allowed,
19191883
ImplTraitContext::Disallowed(ImplTraitPosition::Bound),
19201884
),
19211885
in_where_clause: true,

0 commit comments

Comments
 (0)