Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7731802

Browse files
committedJun 26, 2024
Auto merge of rust-lang#126979 - matthiaskrgr:rollup-fdqledz, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#126724 (Fix a span in `parse_ty_bare_fn`.) - rust-lang#126812 (Rename `tcx` to `cx` in new solver generic code) - rust-lang#126879 (fix Drop items getting leaked in Filter::next_chunk) - rust-lang#126925 (Change E0369 to give note informations for foreign items.) - rust-lang#126938 (miri: make sure we can find link_section statics even for the local crate) - rust-lang#126954 (resolve: Tweak some naming around import ambiguities) - rust-lang#126964 (Migrate `lto-empty`, `invalid-so` and `issue-20626` `run-make` tests to rmake.rs) - rust-lang#126968 (Don't ICE during RPITIT refinement checking for resolution errors after normalization) - rust-lang#126971 (Bump black, ruff and platformdirs) - rust-lang#126973 (Fix bad replacement for unsafe extern block suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a299aa5 + b272086 commit 7731802

File tree

62 files changed

+904
-605
lines changed

Some content is hidden

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

62 files changed

+904
-605
lines changed
 

‎compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
171171
}
172172
// Resolve any lifetime variables that may have been introduced during normalization.
173173
let Ok((trait_bounds, impl_bounds)) = infcx.fully_resolve((trait_bounds, impl_bounds)) else {
174-
// This code path is not reached in any tests, but may be reachable. If
175-
// this is triggered, it should be converted to `delayed_bug` and the
176-
// triggering case turned into a test.
177-
tcx.dcx().bug("encountered errors when checking RPITIT refinement (resolution)");
174+
// If resolution didn't fully complete, we cannot continue checking RPITIT refinement, and
175+
// delay a bug as the original code contains load-bearing errors.
176+
tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (resolution)");
177+
return;
178178
};
179179

180180
// For quicker lookup, use an `IndexSet` (we don't use one earlier because

‎compiler/rustc_hir_typeck/src/method/suggest.rs

+76-26
Original file line numberDiff line numberDiff line change
@@ -2831,69 +2831,119 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28312831
errors: Vec<FulfillmentError<'tcx>>,
28322832
suggest_derive: bool,
28332833
) {
2834-
let all_local_types_needing_impls =
2835-
errors.iter().all(|e| match e.obligation.predicate.kind().skip_binder() {
2834+
let preds: Vec<_> = errors
2835+
.iter()
2836+
.filter_map(|e| match e.obligation.predicate.kind().skip_binder() {
28362837
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
28372838
match pred.self_ty().kind() {
2838-
ty::Adt(def, _) => def.did().is_local(),
2839-
_ => false,
2839+
ty::Adt(_, _) => Some(pred),
2840+
_ => None,
28402841
}
28412842
}
2842-
_ => false,
2843-
});
2844-
let mut preds: Vec<_> = errors
2845-
.iter()
2846-
.filter_map(|e| match e.obligation.predicate.kind().skip_binder() {
2847-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => Some(pred),
28482843
_ => None,
28492844
})
28502845
.collect();
2851-
preds.sort_by_key(|pred| pred.trait_ref.to_string());
2852-
let def_ids = preds
2846+
2847+
// Note for local items and foreign items respectively.
2848+
let (mut local_preds, mut foreign_preds): (Vec<_>, Vec<_>) =
2849+
preds.iter().partition(|&pred| {
2850+
if let ty::Adt(def, _) = pred.self_ty().kind() {
2851+
def.did().is_local()
2852+
} else {
2853+
false
2854+
}
2855+
});
2856+
2857+
local_preds.sort_by_key(|pred: &&ty::TraitPredicate<'_>| pred.trait_ref.to_string());
2858+
let local_def_ids = local_preds
28532859
.iter()
28542860
.filter_map(|pred| match pred.self_ty().kind() {
28552861
ty::Adt(def, _) => Some(def.did()),
28562862
_ => None,
28572863
})
28582864
.collect::<FxIndexSet<_>>();
2859-
let mut spans: MultiSpan = def_ids
2865+
let mut local_spans: MultiSpan = local_def_ids
28602866
.iter()
28612867
.filter_map(|def_id| {
28622868
let span = self.tcx.def_span(*def_id);
28632869
if span.is_dummy() { None } else { Some(span) }
28642870
})
28652871
.collect::<Vec<_>>()
28662872
.into();
2867-
2868-
for pred in &preds {
2873+
for pred in &local_preds {
28692874
match pred.self_ty().kind() {
2870-
ty::Adt(def, _) if def.did().is_local() => {
2871-
spans.push_span_label(
2875+
ty::Adt(def, _) => {
2876+
local_spans.push_span_label(
28722877
self.tcx.def_span(def.did()),
28732878
format!("must implement `{}`", pred.trait_ref.print_trait_sugared()),
28742879
);
28752880
}
28762881
_ => {}
28772882
}
28782883
}
2879-
2880-
if all_local_types_needing_impls && spans.primary_span().is_some() {
2881-
let msg = if preds.len() == 1 {
2884+
if local_spans.primary_span().is_some() {
2885+
let msg = if local_preds.len() == 1 {
28822886
format!(
28832887
"an implementation of `{}` might be missing for `{}`",
2884-
preds[0].trait_ref.print_trait_sugared(),
2885-
preds[0].self_ty()
2888+
local_preds[0].trait_ref.print_trait_sugared(),
2889+
local_preds[0].self_ty()
28862890
)
28872891
} else {
28882892
format!(
28892893
"the following type{} would have to `impl` {} required trait{} for this \
28902894
operation to be valid",
2891-
pluralize!(def_ids.len()),
2892-
if def_ids.len() == 1 { "its" } else { "their" },
2893-
pluralize!(preds.len()),
2895+
pluralize!(local_def_ids.len()),
2896+
if local_def_ids.len() == 1 { "its" } else { "their" },
2897+
pluralize!(local_preds.len()),
2898+
)
2899+
};
2900+
err.span_note(local_spans, msg);
2901+
}
2902+
2903+
foreign_preds.sort_by_key(|pred: &&ty::TraitPredicate<'_>| pred.trait_ref.to_string());
2904+
let foreign_def_ids = foreign_preds
2905+
.iter()
2906+
.filter_map(|pred| match pred.self_ty().kind() {
2907+
ty::Adt(def, _) => Some(def.did()),
2908+
_ => None,
2909+
})
2910+
.collect::<FxIndexSet<_>>();
2911+
let mut foreign_spans: MultiSpan = foreign_def_ids
2912+
.iter()
2913+
.filter_map(|def_id| {
2914+
let span = self.tcx.def_span(*def_id);
2915+
if span.is_dummy() { None } else { Some(span) }
2916+
})
2917+
.collect::<Vec<_>>()
2918+
.into();
2919+
for pred in &foreign_preds {
2920+
match pred.self_ty().kind() {
2921+
ty::Adt(def, _) => {
2922+
foreign_spans.push_span_label(
2923+
self.tcx.def_span(def.did()),
2924+
format!("not implement `{}`", pred.trait_ref.print_trait_sugared()),
2925+
);
2926+
}
2927+
_ => {}
2928+
}
2929+
}
2930+
if foreign_spans.primary_span().is_some() {
2931+
let msg = if foreign_preds.len() == 1 {
2932+
format!(
2933+
"the foreign item type `{}` doesn't implement `{}`",
2934+
foreign_preds[0].self_ty(),
2935+
foreign_preds[0].trait_ref.print_trait_sugared()
2936+
)
2937+
} else {
2938+
format!(
2939+
"the foreign item type{} {} implement required trait{} for this \
2940+
operation to be valid",
2941+
pluralize!(foreign_def_ids.len()),
2942+
if foreign_def_ids.len() > 1 { "don't" } else { "doesn't" },
2943+
pluralize!(foreign_preds.len()),
28942944
)
28952945
};
2896-
err.span_note(spans, msg);
2946+
err.span_note(foreign_spans, msg);
28972947
}
28982948

28992949
let preds: Vec<_> = errors

‎compiler/rustc_next_trait_solver/src/solve/alias_relate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ where
3232
&mut self,
3333
goal: Goal<I, (I::Term, I::Term, ty::AliasRelationDirection)>,
3434
) -> QueryResult<I> {
35-
let tcx = self.cx();
35+
let cx = self.cx();
3636
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
3737
debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some());
3838

3939
// Structurally normalize the lhs.
4040
let lhs = if let Some(alias) = lhs.to_alias_term() {
4141
let term = self.next_term_infer_of_kind(lhs);
42-
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
42+
self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
4343
term
4444
} else {
4545
lhs
@@ -48,7 +48,7 @@ where
4848
// Structurally normalize the rhs.
4949
let rhs = if let Some(alias) = rhs.to_alias_term() {
5050
let term = self.next_term_infer_of_kind(rhs);
51-
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
51+
self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
5252
term
5353
} else {
5454
rhs
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.