Skip to content

Commit c322cd5

Browse files
committed
Auto merge of #133393 - compiler-errors:dyn-tweaks, r=lcnr,spastorino
Some minor dyn-related tweaks Each commit should be self-explanatory, but I'm happy to explain what's going on if not. These are tweaks I pulled out of #133388, but they can be reviewed sooner than that. r? types
2 parents 39cb338 + bcfc8ab commit c322cd5

File tree

4 files changed

+11
-74
lines changed

4 files changed

+11
-74
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
136136

137137
for (base_trait_ref, original_span) in regular_traits_refs_spans {
138138
let base_pred: ty::Predicate<'tcx> = base_trait_ref.upcast(tcx);
139-
for ClauseWithSupertraitSpan { pred, original_span, supertrait_span } in
139+
for ClauseWithSupertraitSpan { pred, supertrait_span } in
140140
traits::elaborate(tcx, [ClauseWithSupertraitSpan::new(base_pred, original_span)])
141141
.filter_only_self()
142142
{
@@ -204,7 +204,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
204204
for def_ids in associated_types.values_mut() {
205205
for (projection_bound, span) in &projection_bounds {
206206
let def_id = projection_bound.projection_def_id();
207-
// FIXME(#120456) - is `swap_remove` correct?
208207
def_ids.swap_remove(&def_id);
209208
if tcx.generics_require_sized_self(def_id) {
210209
tcx.emit_node_span_lint(

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+1-34
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
727727
let tcx = self.tcx();
728728
// FIXME: Marked `mut` so that we can replace the spans further below with a more
729729
// appropriate one, but this should be handled earlier in the span assignment.
730-
let mut associated_types: FxIndexMap<Span, Vec<_>> = associated_types
730+
let associated_types: FxIndexMap<Span, Vec<_>> = associated_types
731731
.into_iter()
732732
.map(|(span, def_ids)| {
733733
(span, def_ids.into_iter().map(|did| tcx.associated_item(did)).collect())
@@ -769,39 +769,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
769769
hir::Node::Expr(_) | hir::Node::Pat(_) => true,
770770
_ => false,
771771
};
772-
match bound.trait_ref.path.segments {
773-
// FIXME: `trait_ref.path.span` can point to a full path with multiple
774-
// segments, even though `trait_ref.path.segments` is of length `1`. Work
775-
// around that bug here, even though it should be fixed elsewhere.
776-
// This would otherwise cause an invalid suggestion. For an example, look at
777-
// `tests/ui/issues/issue-28344.rs` where instead of the following:
778-
//
779-
// error[E0191]: the value of the associated type `Output`
780-
// (from trait `std::ops::BitXor`) must be specified
781-
// --> $DIR/issue-28344.rs:4:17
782-
// |
783-
// LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
784-
// | ^^^^^^ help: specify the associated type:
785-
// | `BitXor<Output = Type>`
786-
//
787-
// we would output:
788-
//
789-
// error[E0191]: the value of the associated type `Output`
790-
// (from trait `std::ops::BitXor`) must be specified
791-
// --> $DIR/issue-28344.rs:4:17
792-
// |
793-
// LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
794-
// | ^^^^^^^^^^^^^ help: specify the associated type:
795-
// | `BitXor::bitor<Output = Type>`
796-
[segment] if segment.args.is_none() => {
797-
trait_bound_spans = vec![segment.ident.span];
798-
associated_types = associated_types
799-
.into_values()
800-
.map(|items| (segment.ident.span, items))
801-
.collect();
802-
}
803-
_ => {}
804-
}
805772
}
806773

807774
// We get all the associated items that _are_ set,

compiler/rustc_trait_selection/src/traits/wf.rs

+7-29
Original file line numberDiff line numberDiff line change
@@ -963,30 +963,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
963963
/// bounds that must hold on the elided self type. These are derived
964964
/// from the declarations of `SomeTrait`, `Send`, and friends -- if
965965
/// they declare `trait SomeTrait : 'static`, for example, then
966-
/// `'static` would appear in the list. The hard work is done by
967-
/// `infer::required_region_bounds`, see that for more information.
968-
pub fn object_region_bounds<'tcx>(
969-
tcx: TyCtxt<'tcx>,
970-
existential_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
971-
) -> Vec<ty::Region<'tcx>> {
972-
let predicates = existential_predicates.iter().filter_map(|predicate| {
973-
if let ty::ExistentialPredicate::Projection(_) = predicate.skip_binder() {
974-
None
975-
} else {
976-
Some(predicate.with_self_ty(tcx, tcx.types.trait_object_dummy_self))
977-
}
978-
});
979-
980-
required_region_bounds(tcx, tcx.types.trait_object_dummy_self, predicates)
981-
}
982-
983-
/// Given a set of predicates that apply to an object type, returns
984-
/// the region bounds that the (erased) `Self` type must
985-
/// outlive. Precisely *because* the `Self` type is erased, the
986-
/// parameter `erased_self_ty` must be supplied to indicate what type
987-
/// has been used to represent `Self` in the predicates
988-
/// themselves. This should really be a unique type; `FreshTy(0)` is a
989-
/// popular choice.
966+
/// `'static` would appear in the list.
990967
///
991968
/// N.B., in some cases, particularly around higher-ranked bounds,
992969
/// this function returns a kind of conservative approximation.
@@ -996,13 +973,14 @@ pub fn object_region_bounds<'tcx>(
996973
///
997974
/// Requires that trait definitions have been processed so that we can
998975
/// elaborate predicates and walk supertraits.
999-
#[instrument(skip(tcx, predicates), level = "debug", ret)]
1000-
pub(crate) fn required_region_bounds<'tcx>(
976+
pub fn object_region_bounds<'tcx>(
1001977
tcx: TyCtxt<'tcx>,
1002-
erased_self_ty: Ty<'tcx>,
1003-
predicates: impl Iterator<Item = ty::Clause<'tcx>>,
978+
existential_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
1004979
) -> Vec<ty::Region<'tcx>> {
1005-
assert!(!erased_self_ty.has_escaping_bound_vars());
980+
let erased_self_ty = tcx.types.trait_object_dummy_self;
981+
982+
let predicates =
983+
existential_predicates.iter().map(|predicate| predicate.with_self_ty(tcx, erased_self_ty));
1006984

1007985
traits::elaborate(tcx, predicates)
1008986
.filter_map(|pred| {

compiler/rustc_type_ir/src/elaborate.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ pub trait Elaboratable<I: Interner> {
4545

4646
pub struct ClauseWithSupertraitSpan<I: Interner> {
4747
pub pred: I::Predicate,
48-
// Span of the original elaborated predicate.
49-
pub original_span: I::Span,
5048
// Span of the supertrait predicatae that lead to this clause.
5149
pub supertrait_span: I::Span,
5250
}
5351
impl<I: Interner> ClauseWithSupertraitSpan<I> {
5452
pub fn new(pred: I::Predicate, span: I::Span) -> Self {
55-
ClauseWithSupertraitSpan { pred, original_span: span, supertrait_span: span }
53+
ClauseWithSupertraitSpan { pred, supertrait_span: span }
5654
}
5755
}
5856
impl<I: Interner> Elaboratable<I> for ClauseWithSupertraitSpan<I> {
@@ -63,7 +61,6 @@ impl<I: Interner> Elaboratable<I> for ClauseWithSupertraitSpan<I> {
6361
fn child(&self, clause: <I as Interner>::Clause) -> Self {
6462
ClauseWithSupertraitSpan {
6563
pred: clause.as_predicate(),
66-
original_span: self.original_span,
6764
supertrait_span: self.supertrait_span,
6865
}
6966
}
@@ -75,11 +72,7 @@ impl<I: Interner> Elaboratable<I> for ClauseWithSupertraitSpan<I> {
7572
_parent_trait_pred: crate::Binder<I, crate::TraitPredicate<I>>,
7673
_index: usize,
7774
) -> Self {
78-
ClauseWithSupertraitSpan {
79-
pred: clause.as_predicate(),
80-
original_span: self.original_span,
81-
supertrait_span: supertrait_span,
82-
}
75+
ClauseWithSupertraitSpan { pred: clause.as_predicate(), supertrait_span: supertrait_span }
8376
}
8477
}
8578

0 commit comments

Comments
 (0)