Skip to content

Commit eed0e12

Browse files
committed
Auto merge of rust-lang#131711 - matthiaskrgr:rollup-an3kr9k, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#122670 (Fix bug where `option_env!` would return `None` when env var is present but not valid Unicode) - rust-lang#130568 (Make some float methods unstable `const fn`) - rust-lang#131137 (Add 1.82 release notes) - rust-lang#131328 (Remove unnecessary sorts in `rustc_hir_analysis`) - rust-lang#131652 (Move polarity into `PolyTraitRef` rather than storing it on the side) - rust-lang#131675 (Update lint message for ABI not supported) - rust-lang#131681 (Fix up-to-date checking for run-make tests) - rust-lang#131703 (Resolved python deprecation warning in publish_toolstate.py) - rust-lang#131706 (Fix two const-hacks) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9322d18 + 2fa07c7 commit eed0e12

File tree

86 files changed

+1052
-582
lines changed

Some content is hidden

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

86 files changed

+1052
-582
lines changed

RELEASES.md

+177
Large diffs are not rendered by default.

compiler/rustc_ast/src/ast.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl TraitBoundModifiers {
308308

309309
#[derive(Clone, Encodable, Decodable, Debug)]
310310
pub enum GenericBound {
311-
Trait(PolyTraitRef, TraitBoundModifiers),
311+
Trait(PolyTraitRef),
312312
Outlives(Lifetime),
313313
/// Precise capturing syntax: `impl Sized + use<'a>`
314314
Use(ThinVec<PreciseCapturingArg>, Span),
@@ -1213,10 +1213,12 @@ impl Expr {
12131213

12141214
pub fn to_bound(&self) -> Option<GenericBound> {
12151215
match &self.kind {
1216-
ExprKind::Path(None, path) => Some(GenericBound::Trait(
1217-
PolyTraitRef::new(ThinVec::new(), path.clone(), self.span),
1216+
ExprKind::Path(None, path) => Some(GenericBound::Trait(PolyTraitRef::new(
1217+
ThinVec::new(),
1218+
path.clone(),
12181219
TraitBoundModifiers::NONE,
1219-
)),
1220+
self.span,
1221+
))),
12201222
_ => None,
12211223
}
12221224
}
@@ -2965,16 +2967,25 @@ pub struct PolyTraitRef {
29652967
/// The `'a` in `for<'a> Foo<&'a T>`.
29662968
pub bound_generic_params: ThinVec<GenericParam>,
29672969

2970+
// Optional constness, asyncness, or polarity.
2971+
pub modifiers: TraitBoundModifiers,
2972+
29682973
/// The `Foo<&'a T>` in `<'a> Foo<&'a T>`.
29692974
pub trait_ref: TraitRef,
29702975

29712976
pub span: Span,
29722977
}
29732978

29742979
impl PolyTraitRef {
2975-
pub fn new(generic_params: ThinVec<GenericParam>, path: Path, span: Span) -> Self {
2980+
pub fn new(
2981+
generic_params: ThinVec<GenericParam>,
2982+
path: Path,
2983+
modifiers: TraitBoundModifiers,
2984+
span: Span,
2985+
) -> Self {
29762986
PolyTraitRef {
29772987
bound_generic_params: generic_params,
2988+
modifiers,
29782989
trait_ref: TraitRef { path, ref_id: DUMMY_NODE_ID },
29792990
span,
29802991
}

compiler/rustc_ast/src/mut_visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ fn walk_fn_ret_ty<T: MutVisitor>(vis: &mut T, fn_ret_ty: &mut FnRetTy) {
913913

914914
fn walk_param_bound<T: MutVisitor>(vis: &mut T, pb: &mut GenericBound) {
915915
match pb {
916-
GenericBound::Trait(ty, _modifier) => vis.visit_poly_trait_ref(ty),
916+
GenericBound::Trait(trait_ref) => vis.visit_poly_trait_ref(trait_ref),
917917
GenericBound::Outlives(lifetime) => walk_lifetime(vis, lifetime),
918918
GenericBound::Use(args, span) => {
919919
for arg in args {
@@ -1034,7 +1034,7 @@ fn walk_trait_ref<T: MutVisitor>(vis: &mut T, TraitRef { path, ref_id }: &mut Tr
10341034
}
10351035

10361036
fn walk_poly_trait_ref<T: MutVisitor>(vis: &mut T, p: &mut PolyTraitRef) {
1037-
let PolyTraitRef { bound_generic_params, trait_ref, span } = p;
1037+
let PolyTraitRef { bound_generic_params, modifiers: _, trait_ref, span } = p;
10381038
bound_generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
10391039
vis.visit_trait_ref(trait_ref);
10401040
vis.visit_span(span);

compiler/rustc_ast/src/util/classify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
263263

264264
ast::TyKind::TraitObject(bounds, _) | ast::TyKind::ImplTrait(_, bounds) => {
265265
match bounds.last() {
266-
Some(ast::GenericBound::Trait(bound, _)) => {
266+
Some(ast::GenericBound::Trait(bound)) => {
267267
match path_return_type(&bound.trait_ref.path) {
268268
Some(trailing_ty) => ty = trailing_ty,
269269
None => break None,

compiler/rustc_ast/src/visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef)
329329
where
330330
V: Visitor<'a>,
331331
{
332-
let PolyTraitRef { bound_generic_params, trait_ref, span: _ } = trait_ref;
332+
let PolyTraitRef { bound_generic_params, modifiers: _, trait_ref, span: _ } = trait_ref;
333333
walk_list!(visitor, visit_generic_param, bound_generic_params);
334334
visitor.visit_trait_ref(trait_ref)
335335
}
@@ -720,7 +720,7 @@ impl WalkItemKind for ForeignItemKind {
720720

721721
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) -> V::Result {
722722
match bound {
723-
GenericBound::Trait(typ, _modifier) => visitor.visit_poly_trait_ref(typ),
723+
GenericBound::Trait(trait_ref) => visitor.visit_poly_trait_ref(trait_ref),
724724
GenericBound::Outlives(lifetime) => visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound),
725725
GenericBound::Use(args, _span) => {
726726
walk_list!(visitor, visit_precise_capturing_arg, args);

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1504,8 +1504,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
15041504
for bound in &bound_pred.bounds {
15051505
if !matches!(
15061506
*bound,
1507-
GenericBound::Trait(_, TraitBoundModifiers {
1508-
polarity: BoundPolarity::Maybe(_),
1507+
GenericBound::Trait(PolyTraitRef {
1508+
modifiers: TraitBoundModifiers { polarity: BoundPolarity::Maybe(_), .. },
15091509
..
15101510
})
15111511
) {

compiler/rustc_ast_lowering/src/lib.rs

+22-28
Original file line numberDiff line numberDiff line change
@@ -1219,13 +1219,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12191219
let bound = this.lower_poly_trait_ref(
12201220
&PolyTraitRef {
12211221
bound_generic_params: ThinVec::new(),
1222+
modifiers: TraitBoundModifiers::NONE,
12221223
trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
12231224
span: t.span,
12241225
},
12251226
itctx,
1226-
TraitBoundModifiers::NONE,
12271227
);
1228-
let bound = (bound, hir::TraitBoundModifier::None);
12291228
let bounds = this.arena.alloc_from_iter([bound]);
12301229
let lifetime_bound = this.elided_dyn_bound(t.span);
12311230
(bounds, lifetime_bound)
@@ -1326,10 +1325,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13261325
// We can safely ignore constness here since AST validation
13271326
// takes care of rejecting invalid modifier combinations and
13281327
// const trait bounds in trait object types.
1329-
GenericBound::Trait(ty, modifiers) => {
1330-
let trait_ref = this.lower_poly_trait_ref(ty, itctx, *modifiers);
1331-
let polarity = this.lower_trait_bound_modifiers(*modifiers);
1332-
Some((trait_ref, polarity))
1328+
GenericBound::Trait(ty) => {
1329+
let trait_ref = this.lower_poly_trait_ref(ty, itctx);
1330+
Some(trait_ref)
13331331
}
13341332
GenericBound::Outlives(lifetime) => {
13351333
if lifetime_bound.is_none() {
@@ -1958,21 +1956,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19581956
span_ext: DUMMY_SP,
19591957
});
19601958

1961-
hir::GenericBound::Trait(
1962-
hir::PolyTraitRef {
1963-
bound_generic_params: &[],
1964-
trait_ref: hir::TraitRef {
1965-
path: self.make_lang_item_path(
1966-
trait_lang_item,
1967-
opaque_ty_span,
1968-
Some(bound_args),
1969-
),
1970-
hir_ref_id: self.next_id(),
1971-
},
1972-
span: opaque_ty_span,
1959+
hir::GenericBound::Trait(hir::PolyTraitRef {
1960+
bound_generic_params: &[],
1961+
modifiers: hir::TraitBoundModifier::None,
1962+
trait_ref: hir::TraitRef {
1963+
path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
1964+
hir_ref_id: self.next_id(),
19731965
},
1974-
hir::TraitBoundModifier::None,
1975-
)
1966+
span: opaque_ty_span,
1967+
})
19761968
}
19771969

19781970
#[instrument(level = "trace", skip(self))]
@@ -1982,10 +1974,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19821974
itctx: ImplTraitContext,
19831975
) -> hir::GenericBound<'hir> {
19841976
match tpb {
1985-
GenericBound::Trait(p, modifiers) => hir::GenericBound::Trait(
1986-
self.lower_poly_trait_ref(p, itctx, *modifiers),
1987-
self.lower_trait_bound_modifiers(*modifiers),
1988-
),
1977+
GenericBound::Trait(p) => hir::GenericBound::Trait(self.lower_poly_trait_ref(p, itctx)),
19891978
GenericBound::Outlives(lifetime) => {
19901979
hir::GenericBound::Outlives(self.lower_lifetime(lifetime))
19911980
}
@@ -2189,12 +2178,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21892178
&mut self,
21902179
p: &PolyTraitRef,
21912180
itctx: ImplTraitContext,
2192-
modifiers: ast::TraitBoundModifiers,
21932181
) -> hir::PolyTraitRef<'hir> {
21942182
let bound_generic_params =
21952183
self.lower_lifetime_binder(p.trait_ref.ref_id, &p.bound_generic_params);
2196-
let trait_ref = self.lower_trait_ref(modifiers, &p.trait_ref, itctx);
2197-
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
2184+
let trait_ref = self.lower_trait_ref(p.modifiers, &p.trait_ref, itctx);
2185+
let modifiers = self.lower_trait_bound_modifiers(p.modifiers);
2186+
hir::PolyTraitRef {
2187+
bound_generic_params,
2188+
modifiers,
2189+
trait_ref,
2190+
span: self.lower_span(p.span),
2191+
}
21982192
}
21992193

22002194
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
@@ -2634,10 +2628,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26342628
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
26352629
let principal = hir::PolyTraitRef {
26362630
bound_generic_params: &[],
2631+
modifiers: hir::TraitBoundModifier::None,
26372632
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
26382633
span: self.lower_span(span),
26392634
};
2640-
let principal = (principal, hir::TraitBoundModifier::None);
26412635

26422636
// The original ID is taken by the `PolyTraitRef`,
26432637
// so the `Ty` itself needs a different one.

compiler/rustc_ast_passes/src/ast_validation.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12631263
if !bound_pred.bound_generic_params.is_empty() {
12641264
for bound in &bound_pred.bounds {
12651265
match bound {
1266-
GenericBound::Trait(t, _) => {
1266+
GenericBound::Trait(t) => {
12671267
if !t.bound_generic_params.is_empty() {
12681268
self.dcx()
12691269
.emit_err(errors::NestedLifetimes { span: t.span });
@@ -1283,8 +1283,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12831283

12841284
fn visit_param_bound(&mut self, bound: &'a GenericBound, ctxt: BoundKind) {
12851285
match bound {
1286-
GenericBound::Trait(trait_ref, modifiers) => {
1287-
match (ctxt, modifiers.constness, modifiers.polarity) {
1286+
GenericBound::Trait(trait_ref) => {
1287+
match (ctxt, trait_ref.modifiers.constness, trait_ref.modifiers.polarity) {
12881288
(BoundKind::SuperTraits, BoundConstness::Never, BoundPolarity::Maybe(_))
12891289
if !self.features.more_maybe_bounds =>
12901290
{
@@ -1324,7 +1324,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13241324
}
13251325

13261326
// Negative trait bounds are not allowed to have associated constraints
1327-
if let BoundPolarity::Negative(_) = modifiers.polarity
1327+
if let BoundPolarity::Negative(_) = trait_ref.modifiers.polarity
13281328
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
13291329
{
13301330
match segment.args.as_deref() {
@@ -1672,7 +1672,9 @@ fn deny_equality_constraints(
16721672
}),
16731673
) {
16741674
for bound in bounds {
1675-
if let GenericBound::Trait(poly, TraitBoundModifiers::NONE) = bound {
1675+
if let GenericBound::Trait(poly) = bound
1676+
&& poly.modifiers == TraitBoundModifiers::NONE
1677+
{
16761678
if full_path.segments[..full_path.segments.len() - 1]
16771679
.iter()
16781680
.map(|segment| segment.ident.name)
@@ -1700,7 +1702,9 @@ fn deny_equality_constraints(
17001702
) {
17011703
if ident == potential_param.ident {
17021704
for bound in bounds {
1703-
if let ast::GenericBound::Trait(poly, TraitBoundModifiers::NONE) = bound {
1705+
if let ast::GenericBound::Trait(poly) = bound
1706+
&& poly.modifiers == TraitBoundModifiers::NONE
1707+
{
17041708
suggest(poly, potential_assoc, predicate);
17051709
}
17061710
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+22-26
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ mod item;
88

99
use std::borrow::Cow;
1010

11-
use ast::TraitBoundModifiers;
1211
use rustc_ast::attr::AttrIdGenerator;
1312
use rustc_ast::ptr::P;
1413
use rustc_ast::token::{
@@ -1253,6 +1252,27 @@ impl<'a> State<'a> {
12531252

12541253
fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) {
12551254
self.print_formal_generic_params(&t.bound_generic_params);
1255+
1256+
let ast::TraitBoundModifiers { constness, asyncness, polarity } = t.modifiers;
1257+
match constness {
1258+
ast::BoundConstness::Never => {}
1259+
ast::BoundConstness::Always(_) | ast::BoundConstness::Maybe(_) => {
1260+
self.word_space(constness.as_str());
1261+
}
1262+
}
1263+
match asyncness {
1264+
ast::BoundAsyncness::Normal => {}
1265+
ast::BoundAsyncness::Async(_) => {
1266+
self.word_space(asyncness.as_str());
1267+
}
1268+
}
1269+
match polarity {
1270+
ast::BoundPolarity::Positive => {}
1271+
ast::BoundPolarity::Negative(_) | ast::BoundPolarity::Maybe(_) => {
1272+
self.word(polarity.as_str());
1273+
}
1274+
}
1275+
12561276
self.print_trait_ref(&t.trait_ref)
12571277
}
12581278

@@ -1740,31 +1760,7 @@ impl<'a> State<'a> {
17401760
}
17411761

17421762
match bound {
1743-
GenericBound::Trait(
1744-
tref,
1745-
TraitBoundModifiers { constness, asyncness, polarity },
1746-
) => {
1747-
match constness {
1748-
ast::BoundConstness::Never => {}
1749-
ast::BoundConstness::Always(_) | ast::BoundConstness::Maybe(_) => {
1750-
self.word_space(constness.as_str());
1751-
}
1752-
}
1753-
1754-
match asyncness {
1755-
ast::BoundAsyncness::Normal => {}
1756-
ast::BoundAsyncness::Async(_) => {
1757-
self.word_space(asyncness.as_str());
1758-
}
1759-
}
1760-
1761-
match polarity {
1762-
ast::BoundPolarity::Positive => {}
1763-
ast::BoundPolarity::Negative(_) | ast::BoundPolarity::Maybe(_) => {
1764-
self.word(polarity.as_str());
1765-
}
1766-
}
1767-
1763+
GenericBound::Trait(tref) => {
17681764
self.print_poly_trait_ref(tref);
17691765
}
17701766
GenericBound::Outlives(lt) => self.print_lifetime(*lt),

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
254254
debug!(?hrtb_bounds);
255255

256256
hrtb_bounds.iter().for_each(|bound| {
257-
let Trait(PolyTraitRef { trait_ref, span: trait_span, .. }, _) = bound else {
257+
let Trait(PolyTraitRef { trait_ref, span: trait_span, .. }) = bound else {
258258
return;
259259
};
260260
diag.span_note(*trait_span, fluent::borrowck_limitations_implies_static);
@@ -277,7 +277,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
277277
return;
278278
};
279279
bounds.iter().for_each(|bd| {
280-
if let Trait(PolyTraitRef { trait_ref: tr_ref, .. }, _) = bd
280+
if let Trait(PolyTraitRef { trait_ref: tr_ref, .. }) = bd
281281
&& let Def(_, res_defid) = tr_ref.path.res
282282
&& res_defid == trait_res_defid // trait id matches
283283
&& let TyKind::Path(Resolved(_, path)) = bounded_ty.kind

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
837837
hir_ty
838838
);
839839
};
840-
if let hir::OpaqueTy { bounds: [hir::GenericBound::Trait(trait_ref, _)], .. } = opaque_ty
840+
if let hir::OpaqueTy { bounds: [hir::GenericBound::Trait(trait_ref)], .. } = opaque_ty
841841
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
842842
&& let Some(args) = segment.args
843843
&& let [constraint] = args.constraints

compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,12 @@ fn contains_maybe_sized_bound_on_pointee(predicates: &[WherePredicate], pointee:
333333
}
334334

335335
fn is_maybe_sized_bound(bound: &GenericBound) -> bool {
336-
if let GenericBound::Trait(
337-
trait_ref,
338-
TraitBoundModifiers { polarity: ast::BoundPolarity::Maybe(_), .. },
339-
) = bound
336+
if let GenericBound::Trait(trait_ref) = bound
337+
&& let TraitBoundModifiers { polarity: ast::BoundPolarity::Maybe(_), .. } =
338+
trait_ref.modifiers
339+
&& is_sized_marker(&trait_ref.trait_ref.path)
340340
{
341-
is_sized_marker(&trait_ref.trait_ref.path)
341+
true
342342
} else {
343343
false
344344
}

0 commit comments

Comments
 (0)