Skip to content

Commit f79fae3

Browse files
committed
Auto merge of rust-lang#131723 - matthiaskrgr:rollup-krcslig, 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#131095 (Use environment variables instead of command line arguments for merged doctests) - rust-lang#131339 (Expand set_ptr_value / with_metadata_of docs) - 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#131702 (Suppress import errors for traits that couldve applied for method lookup error) - rust-lang#131703 (Resolved python deprecation warning in publish_toolstate.py) - rust-lang#131710 (Remove `'apostrophes'` from `rustc_parse_format`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 00367d5 + c99c4d4 commit f79fae3

File tree

93 files changed

+558
-420
lines changed

Some content is hidden

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

93 files changed

+558
-420
lines changed

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
}
@@ -2972,16 +2974,25 @@ pub struct PolyTraitRef {
29722974
/// The `'a` in `for<'a> Foo<&'a T>`.
29732975
pub bound_generic_params: ThinVec<GenericParam>,
29742976

2977+
// Optional constness, asyncness, or polarity.
2978+
pub modifiers: TraitBoundModifiers,
2979+
29752980
/// The `Foo<&'a T>` in `<'a> Foo<&'a T>`.
29762981
pub trait_ref: TraitRef,
29772982

29782983
pub span: Span,
29792984
}
29802985

29812986
impl PolyTraitRef {
2982-
pub fn new(generic_params: ThinVec<GenericParam>, path: Path, span: Span) -> Self {
2987+
pub fn new(
2988+
generic_params: ThinVec<GenericParam>,
2989+
path: Path,
2990+
modifiers: TraitBoundModifiers,
2991+
span: Span,
2992+
) -> Self {
29832993
PolyTraitRef {
29842994
bound_generic_params: generic_params,
2995+
modifiers,
29852996
trait_ref: TraitRef { path, ref_id: DUMMY_NODE_ID },
29862997
span,
29872998
}

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
@@ -265,7 +265,7 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
265265

266266
ast::TyKind::TraitObject(bounds, _) | ast::TyKind::ImplTrait(_, bounds) => {
267267
match bounds.last() {
268-
Some(ast::GenericBound::Trait(bound, _)) => {
268+
Some(ast::GenericBound::Trait(bound)) => {
269269
match path_return_type(&bound.trait_ref.path) {
270270
Some(trailing_ty) => ty = trailing_ty,
271271
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
}
@@ -721,7 +721,7 @@ impl WalkItemKind for ForeignItemKind {
721721

722722
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) -> V::Result {
723723
match bound {
724-
GenericBound::Trait(typ, _modifier) => visitor.visit_poly_trait_ref(typ),
724+
GenericBound::Trait(trait_ref) => visitor.visit_poly_trait_ref(trait_ref),
725725
GenericBound::Outlives(lifetime) => visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound),
726726
GenericBound::Use(args, _span) => {
727727
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
@@ -1224,13 +1224,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12241224
let bound = this.lower_poly_trait_ref(
12251225
&PolyTraitRef {
12261226
bound_generic_params: ThinVec::new(),
1227+
modifiers: TraitBoundModifiers::NONE,
12271228
trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
12281229
span: t.span,
12291230
},
12301231
itctx,
1231-
TraitBoundModifiers::NONE,
12321232
);
1233-
let bound = (bound, hir::TraitBoundModifier::None);
12341233
let bounds = this.arena.alloc_from_iter([bound]);
12351234
let lifetime_bound = this.elided_dyn_bound(t.span);
12361235
(bounds, lifetime_bound)
@@ -1357,10 +1356,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13571356
// We can safely ignore constness here since AST validation
13581357
// takes care of rejecting invalid modifier combinations and
13591358
// const trait bounds in trait object types.
1360-
GenericBound::Trait(ty, modifiers) => {
1361-
let trait_ref = this.lower_poly_trait_ref(ty, itctx, *modifiers);
1362-
let polarity = this.lower_trait_bound_modifiers(*modifiers);
1363-
Some((trait_ref, polarity))
1359+
GenericBound::Trait(ty) => {
1360+
let trait_ref = this.lower_poly_trait_ref(ty, itctx);
1361+
Some(trait_ref)
13641362
}
13651363
GenericBound::Outlives(lifetime) => {
13661364
if lifetime_bound.is_none() {
@@ -1993,21 +1991,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19931991
span_ext: DUMMY_SP,
19941992
});
19951993

1996-
hir::GenericBound::Trait(
1997-
hir::PolyTraitRef {
1998-
bound_generic_params: &[],
1999-
trait_ref: hir::TraitRef {
2000-
path: self.make_lang_item_path(
2001-
trait_lang_item,
2002-
opaque_ty_span,
2003-
Some(bound_args),
2004-
),
2005-
hir_ref_id: self.next_id(),
2006-
},
2007-
span: opaque_ty_span,
1994+
hir::GenericBound::Trait(hir::PolyTraitRef {
1995+
bound_generic_params: &[],
1996+
modifiers: hir::TraitBoundModifier::None,
1997+
trait_ref: hir::TraitRef {
1998+
path: self.make_lang_item_path(trait_lang_item, opaque_ty_span, Some(bound_args)),
1999+
hir_ref_id: self.next_id(),
20082000
},
2009-
hir::TraitBoundModifier::None,
2010-
)
2001+
span: opaque_ty_span,
2002+
})
20112003
}
20122004

20132005
#[instrument(level = "trace", skip(self))]
@@ -2017,10 +2009,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20172009
itctx: ImplTraitContext,
20182010
) -> hir::GenericBound<'hir> {
20192011
match tpb {
2020-
GenericBound::Trait(p, modifiers) => hir::GenericBound::Trait(
2021-
self.lower_poly_trait_ref(p, itctx, *modifiers),
2022-
self.lower_trait_bound_modifiers(*modifiers),
2023-
),
2012+
GenericBound::Trait(p) => hir::GenericBound::Trait(self.lower_poly_trait_ref(p, itctx)),
20242013
GenericBound::Outlives(lifetime) => {
20252014
hir::GenericBound::Outlives(self.lower_lifetime(lifetime))
20262015
}
@@ -2224,12 +2213,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22242213
&mut self,
22252214
p: &PolyTraitRef,
22262215
itctx: ImplTraitContext,
2227-
modifiers: ast::TraitBoundModifiers,
22282216
) -> hir::PolyTraitRef<'hir> {
22292217
let bound_generic_params =
22302218
self.lower_lifetime_binder(p.trait_ref.ref_id, &p.bound_generic_params);
2231-
let trait_ref = self.lower_trait_ref(modifiers, &p.trait_ref, itctx);
2232-
hir::PolyTraitRef { bound_generic_params, trait_ref, span: self.lower_span(p.span) }
2219+
let trait_ref = self.lower_trait_ref(p.modifiers, &p.trait_ref, itctx);
2220+
let modifiers = self.lower_trait_bound_modifiers(p.modifiers);
2221+
hir::PolyTraitRef {
2222+
bound_generic_params,
2223+
modifiers,
2224+
trait_ref,
2225+
span: self.lower_span(p.span),
2226+
}
22332227
}
22342228

22352229
fn lower_mt(&mut self, mt: &MutTy, itctx: ImplTraitContext) -> hir::MutTy<'hir> {
@@ -2669,10 +2663,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26692663
Res::Def(DefKind::Trait | DefKind::TraitAlias, _) => {
26702664
let principal = hir::PolyTraitRef {
26712665
bound_generic_params: &[],
2666+
modifiers: hir::TraitBoundModifier::None,
26722667
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
26732668
span: self.lower_span(span),
26742669
};
2675-
let principal = (principal, hir::TraitBoundModifier::None);
26762670

26772671
// The original ID is taken by the `PolyTraitRef`,
26782672
// 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::{
@@ -1259,6 +1258,27 @@ impl<'a> State<'a> {
12591258

12601259
fn print_poly_trait_ref(&mut self, t: &ast::PolyTraitRef) {
12611260
self.print_formal_generic_params(&t.bound_generic_params);
1261+
1262+
let ast::TraitBoundModifiers { constness, asyncness, polarity } = t.modifiers;
1263+
match constness {
1264+
ast::BoundConstness::Never => {}
1265+
ast::BoundConstness::Always(_) | ast::BoundConstness::Maybe(_) => {
1266+
self.word_space(constness.as_str());
1267+
}
1268+
}
1269+
match asyncness {
1270+
ast::BoundAsyncness::Normal => {}
1271+
ast::BoundAsyncness::Async(_) => {
1272+
self.word_space(asyncness.as_str());
1273+
}
1274+
}
1275+
match polarity {
1276+
ast::BoundPolarity::Positive => {}
1277+
ast::BoundPolarity::Negative(_) | ast::BoundPolarity::Maybe(_) => {
1278+
self.word(polarity.as_str());
1279+
}
1280+
}
1281+
12621282
self.print_trait_ref(&t.trait_ref)
12631283
}
12641284

@@ -1746,31 +1766,7 @@ impl<'a> State<'a> {
17461766
}
17471767

17481768
match bound {
1749-
GenericBound::Trait(
1750-
tref,
1751-
TraitBoundModifiers { constness, asyncness, polarity },
1752-
) => {
1753-
match constness {
1754-
ast::BoundConstness::Never => {}
1755-
ast::BoundConstness::Always(_) | ast::BoundConstness::Maybe(_) => {
1756-
self.word_space(constness.as_str());
1757-
}
1758-
}
1759-
1760-
match asyncness {
1761-
ast::BoundAsyncness::Normal => {}
1762-
ast::BoundAsyncness::Async(_) => {
1763-
self.word_space(asyncness.as_str());
1764-
}
1765-
}
1766-
1767-
match polarity {
1768-
ast::BoundPolarity::Positive => {}
1769-
ast::BoundPolarity::Negative(_) | ast::BoundPolarity::Maybe(_) => {
1770-
self.word(polarity.as_str());
1771-
}
1772-
}
1773-
1769+
GenericBound::Trait(tref) => {
17741770
self.print_poly_trait_ref(tref);
17751771
}
17761772
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)