Skip to content

Commit 42e8f2b

Browse files
committed
1 parent 5f5c243 commit 42e8f2b

File tree

20 files changed

+179
-10
lines changed

20 files changed

+179
-10
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
204204
AllowReturnTypeNotation::No,
205205
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
206206
None,
207+
false,
207208
);
208209
hir::InlineAsmOperand::SymStatic { path, def_id }
209210
} else {

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
326326
GenericArgsMode::Err,
327327
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
328328
None,
329+
false
329330
);
330331
let segment = self.arena.alloc(segment);
331332

@@ -343,6 +344,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
343344
AllowReturnTypeNotation::No,
344345
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
345346
None,
347+
false
346348
);
347349

348350
let callee_path = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(path), span));

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
111111
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
112112
// Method calls can't have bound modifiers
113113
None,
114+
false,
114115
));
115116
let receiver = self.lower_expr(receiver);
116117
let args =
@@ -284,6 +285,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
284285
AllowReturnTypeNotation::No,
285286
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
286287
None,
288+
false
287289
);
288290
hir::ExprKind::Path(qpath)
289291
}
@@ -332,6 +334,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
332334
AllowReturnTypeNotation::No,
333335
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
334336
None,
337+
false
335338
)),
336339
self.arena
337340
.alloc_from_iter(se.fields.iter().map(|x| self.lower_expr_field(x))),
@@ -1294,6 +1297,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
12941297
AllowReturnTypeNotation::No,
12951298
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
12961299
None,
1300+
false
12971301
);
12981302
// Destructure like a tuple struct.
12991303
let tuple_struct_pat = hir::PatKind::TupleStruct(
@@ -1315,6 +1319,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13151319
AllowReturnTypeNotation::No,
13161320
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
13171321
None,
1322+
false
13181323
);
13191324
// Destructure like a unit struct.
13201325
let unit_struct_pat = hir::PatKind::Path(qpath);
@@ -1341,6 +1346,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13411346
AllowReturnTypeNotation::No,
13421347
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
13431348
None,
1349+
false
13441350
);
13451351
let fields_omitted = match &se.rest {
13461352
StructRest::Base(e) => {

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
349349
modifiers,
350350
trait_ref,
351351
ImplTraitContext::Disallowed(ImplTraitPosition::Trait),
352+
false,
352353
)
353354
});
354355

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10071007
let gen_args = if let Some(gen_args) = &constraint.gen_args {
10081008
let gen_args_ctor = match gen_args {
10091009
GenericArgs::AngleBracketed(data) => {
1010-
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
1010+
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx, None).0
10111011
}
10121012
GenericArgs::Parenthesized(data) => {
10131013
if let Some(first_char) = constraint.ident.as_str().chars().next()
@@ -1050,6 +1050,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10501050
&data.as_angle_bracketed_args(),
10511051
ParamMode::Explicit,
10521052
itctx,
1053+
None
10531054
)
10541055
.0
10551056
}
@@ -1220,6 +1221,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12201221
span: t.span,
12211222
},
12221223
itctx,
1224+
false,
12231225
);
12241226
let bounds = this.arena.alloc_from_iter([bound]);
12251227
let lifetime_bound = this.elided_dyn_bound(t.span);
@@ -1238,6 +1240,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12381240
AllowReturnTypeNotation::Yes,
12391241
itctx,
12401242
None,
1243+
false,
12411244
);
12421245
self.ty_path(id, t.span, qpath)
12431246
}
@@ -1348,7 +1351,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13481351
// takes care of rejecting invalid modifier combinations and
13491352
// const trait bounds in trait object types.
13501353
GenericBound::Trait(ty) => {
1351-
let trait_ref = this.lower_poly_trait_ref(ty, itctx);
1354+
let trait_ref = this.lower_poly_trait_ref(ty, itctx, false);
13521355
Some(trait_ref)
13531356
}
13541357
GenericBound::Outlives(lifetime) => {
@@ -1963,7 +1966,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19631966
itctx: ImplTraitContext,
19641967
) -> hir::GenericBound<'hir> {
19651968
match tpb {
1966-
GenericBound::Trait(p) => hir::GenericBound::Trait(self.lower_poly_trait_ref(p, itctx)),
1969+
GenericBound::Trait(p) => hir::GenericBound::Trait(self.lower_poly_trait_ref(p, itctx, true)),
19671970
GenericBound::Outlives(lifetime) => {
19681971
hir::GenericBound::Outlives(self.lower_lifetime(lifetime))
19691972
}
@@ -2141,6 +2144,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21412144
modifiers: ast::TraitBoundModifiers,
21422145
p: &TraitRef,
21432146
itctx: ImplTraitContext,
2147+
is_param_fn_trait: bool,
21442148
) -> hir::TraitRef<'hir> {
21452149
let path = match self.lower_qpath(
21462150
p.ref_id,
@@ -2150,6 +2154,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21502154
AllowReturnTypeNotation::No,
21512155
itctx,
21522156
Some(modifiers),
2157+
is_param_fn_trait,
21532158
) {
21542159
hir::QPath::Resolved(None, path) => path,
21552160
qpath => panic!("lower_trait_ref: unexpected QPath `{qpath:?}`"),
@@ -2162,10 +2167,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21622167
&mut self,
21632168
p: &PolyTraitRef,
21642169
itctx: ImplTraitContext,
2170+
is_param_fn_trait: bool,
21652171
) -> hir::PolyTraitRef<'hir> {
21662172
let bound_generic_params =
21672173
self.lower_lifetime_binder(p.trait_ref.ref_id, &p.bound_generic_params);
2168-
let trait_ref = self.lower_trait_ref(p.modifiers, &p.trait_ref, itctx);
2174+
let trait_ref = self.lower_trait_ref(p.modifiers, &p.trait_ref, itctx, is_param_fn_trait);
21692175
let modifiers = self.lower_trait_bound_modifiers(p.modifiers);
21702176
hir::PolyTraitRef {
21712177
bound_generic_params,
@@ -2294,6 +2300,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22942300
AllowReturnTypeNotation::No,
22952301
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
22962302
None,
2303+
false,
22972304
);
22982305
hir::ConstArgKind::Path(qpath)
22992306
}
@@ -2373,6 +2380,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23732380
AllowReturnTypeNotation::No,
23742381
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
23752382
None,
2383+
false
23762384
);
23772385

23782386
return ConstArg {
@@ -2652,6 +2660,7 @@ impl<'hir> GenericArgsCtor<'hir> {
26522660
}
26532661

26542662
fn into_generic_args(self, this: &LoweringContext<'_, 'hir>) -> &'hir hir::GenericArgs<'hir> {
2663+
tracing::debug!("+++++++ constraints_2: {:#?}", self.constraints);
26552664
let ga = hir::GenericArgs {
26562665
args: this.arena.alloc_from_iter(self.args),
26572666
constraints: self.constraints,

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4141
AllowReturnTypeNotation::No,
4242
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
4343
None,
44+
false,
4445
);
4546
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct");
4647
break hir::PatKind::TupleStruct(qpath, pats, ddpos);
@@ -59,6 +60,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
5960
AllowReturnTypeNotation::No,
6061
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
6162
None,
63+
false
6264
);
6365
break hir::PatKind::Path(qpath);
6466
}
@@ -71,6 +73,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7173
AllowReturnTypeNotation::No,
7274
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
7375
None,
76+
false
7477
);
7578

7679
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| {

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3232
itctx: ImplTraitContext,
3333
// modifiers of the impl/bound if this is a trait path
3434
modifiers: Option<ast::TraitBoundModifiers>,
35+
is_param_fn_trait: bool,
3536
) -> hir::QPath<'hir> {
3637
let qself_position = qself.as_ref().map(|q| q.position);
3738
let qself = qself.as_ref().map(|q| self.lower_ty(&q.ty, itctx));
@@ -123,6 +124,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
123124
generic_args_mode,
124125
itctx,
125126
bound_modifier_allowed_features.clone(),
127+
is_param_fn_trait
126128
)
127129
},
128130
)),
@@ -187,6 +189,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
187189
generic_args_mode,
188190
itctx,
189191
None,
192+
false,
190193
));
191194
let qpath = hir::QPath::TypeRelative(ty, hir_segment);
192195

@@ -229,6 +232,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
229232
GenericArgsMode::Err,
230233
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
231234
None,
235+
false
232236
)
233237
})),
234238
span: self.lower_span(p.span),
@@ -246,12 +250,23 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
246250
// This is passed down to the implicit associated type binding in
247251
// parenthesized bounds.
248252
bound_modifier_allowed_features: Option<Lrc<[Symbol]>>,
253+
is_param_bound: bool,
249254
) -> hir::PathSegment<'hir> {
250255
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment);
256+
let res = self.expect_full_res(segment.id);
251257
let (mut generic_args, infer_args) = if let Some(generic_args) = segment.args.as_deref() {
252258
match generic_args {
253259
GenericArgs::AngleBracketed(data) => {
254-
self.lower_angle_bracketed_parameter_data(data, param_mode, itctx)
260+
tracing::debug!("is_param_bound: {:#?}", is_param_bound);
261+
let is_param_fn_trait =
262+
res.opt_def_id().map_or(false, |did| self.tcx.is_fn_trait(did) && is_param_bound);
263+
tracing::debug!("{:#?} is_param_fn_trait: {:#?}", res.opt_def_id(), is_param_fn_trait);
264+
self.lower_angle_bracketed_parameter_data(
265+
data,
266+
param_mode,
267+
itctx,
268+
Some(is_param_fn_trait),
269+
)
255270
}
256271
GenericArgs::Parenthesized(data) => match generic_args_mode {
257272
GenericArgsMode::ReturnTypeNotation => {
@@ -323,6 +338,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
323338
&data.as_angle_bracketed_args(),
324339
param_mode,
325340
itctx,
341+
None,
326342
)
327343
.0,
328344
false,
@@ -374,7 +390,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
374390
);
375391
}
376392

377-
let res = self.expect_full_res(segment.id);
378393
let hir_id = self.lower_node_id(segment.id);
379394
debug!(
380395
"lower_path_segment: ident={:?} original-id={:?} new-id={:?}",
@@ -444,6 +459,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
444459
data: &AngleBracketedArgs,
445460
param_mode: ParamMode,
446461
itctx: ImplTraitContext,
462+
fn_trait: Option<bool>,
447463
) -> (GenericArgsCtor<'hir>, bool) {
448464
let has_non_lt_args = data.args.iter().any(|arg| match arg {
449465
AngleBracketedArg::Arg(ast::GenericArg::Lifetime(_))
@@ -458,13 +474,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
458474
AngleBracketedArg::Constraint(_) => None,
459475
})
460476
.collect();
461-
let constraints =
477+
tracing::debug!("+++++++ data: {data:#?}");
478+
tracing::debug!("+++++++ fn_trait: {fn_trait:#?}");
479+
let constraints = if fn_trait.unwrap_or_default()
480+
&& data.args.iter().all(|arg| matches!(arg, AngleBracketedArg::Arg(_)))
481+
{
482+
// eg. `impl<T: Fn<(i32,)>> Trait for T {}``
483+
// let span = data.span;
484+
// let output_ty = self.arena.alloc(self.ty(span, hir::TyKind::Infer));
485+
// arena_vec![self; self.assoc_ty_binding(sym::Output, span, output_ty)]
486+
self.arena.alloc_from_iter([])
487+
} else {
462488
self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
463489
AngleBracketedArg::Constraint(c) => {
464490
Some(self.lower_assoc_item_constraint(c, itctx))
465491
}
466492
AngleBracketedArg::Arg(_) => None,
467-
}));
493+
}))
494+
};
495+
// let constraints = self.arena.alloc_from_iter(data.args.iter().filter_map(|arg| match arg {
496+
// AngleBracketedArg::Constraint(c) => {
497+
// Some(self.lower_assoc_item_constraint(c, itctx))
498+
// }
499+
// AngleBracketedArg::Arg(_) => None,
500+
// }));
468501
let ctor = GenericArgsCtor {
469502
args,
470503
constraints,
@@ -549,6 +582,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
549582
let kind = hir::AssocItemConstraintKind::Equality { term: ty.into() };
550583
let args = arena_vec![self;];
551584
let constraints = arena_vec![self;];
585+
tracing::debug!("+++++++ constraints_1: {constraints:#?}");
552586
let gen_args = self.arena.alloc(hir::GenericArgs {
553587
args,
554588
constraints,

compiler/rustc_data_structures/src/obligation_forest/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ impl<O: ForestObligation> ObligationForest<O> {
381381
} else {
382382
let new_index = self.nodes.len();
383383
v.insert(new_index);
384+
tracing::debug!("______ insert at new_index({new_index:#?}), with new obligation: {obligation:?} and parent is {parent:#?}");
384385
self.nodes.push(Node::new(parent, obligation, obligation_tree_id));
385386
Ok(())
386387
}
@@ -448,6 +449,7 @@ impl<O: ForestObligation> ObligationForest<O> {
448449
// be computed with the initial length, and we would miss the appended
449450
// nodes. Therefore we use a `while` loop.
450451
while let Some(node) = self.nodes.get_mut(index) {
452+
tracing::debug!("-------process_obligations: index:{index:#?}, node={:?}", node);
451453
// This is the moderately fast path when the prefix skipping above didn't work out.
452454
if node.state.get() != NodeState::Pending
453455
|| !processor.needs_process_obligation(&node.obligation)
@@ -473,6 +475,7 @@ impl<O: ForestObligation> ObligationForest<O> {
473475
node.state.set(NodeState::Success);
474476

475477
for child in children {
478+
tracing::debug!("------child: {child:#?}");
476479
let st = self.register_obligation_at(child, Some(index));
477480
if let Err(()) = st {
478481
// Error already reported - propagate it

0 commit comments

Comments
 (0)