Skip to content

Commit a988faa

Browse files
committedJul 25, 2024
initial implementation for default auto traits
1 parent 28e684b commit a988faa

File tree

60 files changed

+1258
-200
lines changed

Some content is hidden

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

60 files changed

+1258
-200
lines changed
 

‎compiler/rustc_ast_lowering/src/item.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1525,8 +1525,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
15251525
continue;
15261526
}
15271527
let is_param = *is_param.get_or_insert_with(compute_is_param);
1528-
if !is_param {
1529-
self.dcx().emit_err(MisplacedRelaxTraitBound { span: bound.span() });
1528+
if !is_param && !self.tcx.features().more_maybe_bounds {
1529+
self.tcx
1530+
.sess
1531+
.create_feature_err(
1532+
MisplacedRelaxTraitBound { span: bound.span() },
1533+
sym::more_maybe_bounds,
1534+
)
1535+
.emit();
15301536
}
15311537
}
15321538
}

‎compiler/rustc_ast_lowering/src/lib.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12161216
itctx,
12171217
TraitBoundModifiers::NONE,
12181218
);
1219+
let bound = (bound, hir::TraitBoundModifier::None);
12191220
let bounds = this.arena.alloc_from_iter([bound]);
12201221
let lifetime_bound = this.elided_dyn_bound(t.span);
12211222
(bounds, lifetime_bound)
@@ -1348,21 +1349,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13481349
// We can safely ignore constness here since AST validation
13491350
// takes care of rejecting invalid modifier combinations and
13501351
// const trait bounds in trait object types.
1351-
GenericBound::Trait(ty, modifiers) => match modifiers.polarity {
1352-
BoundPolarity::Positive | BoundPolarity::Negative(_) => {
1353-
Some(this.lower_poly_trait_ref(
1354-
ty,
1355-
itctx,
1356-
// Still, don't pass along the constness here; we don't want to
1357-
// synthesize any host effect args, it'd only cause problems.
1358-
TraitBoundModifiers {
1359-
constness: BoundConstness::Never,
1360-
..*modifiers
1361-
},
1362-
))
1363-
}
1364-
BoundPolarity::Maybe(_) => None,
1365-
},
1352+
GenericBound::Trait(ty, modifiers) => {
1353+
// Still, don't pass along the constness here; we don't want to
1354+
// synthesize any host effect args, it'd only cause problems.
1355+
let modifiers = TraitBoundModifiers {
1356+
constness: BoundConstness::Never,
1357+
..*modifiers
1358+
};
1359+
let trait_ref = this.lower_poly_trait_ref(ty, itctx, modifiers);
1360+
let polarity = this.lower_trait_bound_modifiers(modifiers);
1361+
Some((trait_ref, polarity))
1362+
}
13661363
GenericBound::Outlives(lifetime) => {
13671364
if lifetime_bound.is_none() {
13681365
lifetime_bound = Some(this.lower_lifetime(lifetime));
@@ -2688,6 +2685,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
26882685
trait_ref: hir::TraitRef { path, hir_ref_id: hir_id },
26892686
span: self.lower_span(span),
26902687
};
2688+
let principal = (principal, hir::TraitBoundModifier::None);
26912689

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

0 commit comments

Comments
 (0)