Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #126979

Merged
merged 24 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2a6a423
Change E0369 diagnostic give note information for foreign items.
surechen Jun 25, 2024
d9a3423
miri: make sure we can find link_section statics even for the local c…
RalfJung Jun 25, 2024
b6074ff
resolve: Tweak some naming around import ambiguities
petrochenkov Jun 25, 2024
6ba0a84
rewrite lto-empty to rmake
Oneirical Jun 25, 2024
fe2406b
rewrite invalid-so to rmake
Oneirical Jun 25, 2024
ee529b7
rewrite and rename issue-20626 to rmake
Oneirical Jun 25, 2024
6402909
delay bug in RPITIT refinement checking with resolution errors
lqd Jun 25, 2024
133e7b1
fix Drop items getting leaked in Filter::next_chunk
the8472 Jun 23, 2024
2be2d77
add comments explaining optimizations for Filter::next_chunk
the8472 Jun 24, 2024
0d7aef9
regression test for leaks in the the Filter::next_chunk implementation
the8472 Jun 25, 2024
275d922
Rename tcx to cx
compiler-errors Jun 21, 2024
efa48bf
Bump black, ruff and platformdirs
DianQK Jun 20, 2024
cf0251d
Fix a span in `parse_ty_bare_fn`.
nnethercote Jun 17, 2024
0addda6
Fix bad replacement for unsafe extern block suggestion
chenyukang Jun 26, 2024
dd6b046
Rollup merge of #126724 - nnethercote:fix-parse_ty_bare_fn-span, r=co…
matthiaskrgr Jun 26, 2024
dc22ffc
Rollup merge of #126812 - compiler-errors:tcx-cx, r=lcnr
matthiaskrgr Jun 26, 2024
cf22be1
Rollup merge of #126879 - the8472:next-chunk-filter-drop, r=cuviper
matthiaskrgr Jun 26, 2024
95332b8
Rollup merge of #126925 - surechen:fix_125631, r=compiler-errors
matthiaskrgr Jun 26, 2024
5c4ede8
Rollup merge of #126938 - RalfJung:link_section, r=compiler-errors
matthiaskrgr Jun 26, 2024
8b3bbee
Rollup merge of #126954 - petrochenkov:globamb, r=compiler-errors
matthiaskrgr Jun 26, 2024
bf8da39
Rollup merge of #126964 - Oneirical:total-catestrophe, r=Kobzol
matthiaskrgr Jun 26, 2024
8c6c6a7
Rollup merge of #126968 - lqd:issue-126670, r=compiler-errors
matthiaskrgr Jun 26, 2024
ee07d90
Rollup merge of #126971 - DianQK:bump, r=Kobzol
matthiaskrgr Jun 26, 2024
b272086
Rollup merge of #126973 - chenyukang:yukang-fix-126756-unsafe-suggest…
matthiaskrgr Jun 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,8 @@ pub struct BareFnTy {
pub ext: Extern,
pub generic_params: ThinVec<GenericParam>,
pub decl: P<FnDecl>,
/// Span of the `fn(...) -> ...` part.
/// Span of the `[unsafe] [extern] fn(...) -> ...` part, i.e. everything
/// after the generic params (if there are any, e.g. `for<'a>`).
pub decl_span: Span,
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl<'a> AstValidator<'a> {
{
self.dcx().emit_err(errors::InvalidSafetyOnExtern {
item_span: span,
block: self.current_extern_span(),
block: self.current_extern_span().shrink_to_lo(),
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub enum ExternBlockSuggestion {
pub struct InvalidSafetyOnExtern {
#[primary_span]
pub item_span: Span,
#[suggestion(code = "", applicability = "maybe-incorrect")]
#[suggestion(code = "unsafe ", applicability = "machine-applicable", style = "verbose")]
pub block: Span,
}

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

// For quicker lookup, use an `IndexSet` (we don't use one earlier because
Expand Down
102 changes: 76 additions & 26 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2831,69 +2831,119 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
errors: Vec<FulfillmentError<'tcx>>,
suggest_derive: bool,
) {
let all_local_types_needing_impls =
errors.iter().all(|e| match e.obligation.predicate.kind().skip_binder() {
let preds: Vec<_> = errors
.iter()
.filter_map(|e| match e.obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
match pred.self_ty().kind() {
ty::Adt(def, _) => def.did().is_local(),
_ => false,
ty::Adt(_, _) => Some(pred),
_ => None,
}
}
_ => false,
});
let mut preds: Vec<_> = errors
.iter()
.filter_map(|e| match e.obligation.predicate.kind().skip_binder() {
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => Some(pred),
_ => None,
})
.collect();
preds.sort_by_key(|pred| pred.trait_ref.to_string());
let def_ids = preds

// Note for local items and foreign items respectively.
let (mut local_preds, mut foreign_preds): (Vec<_>, Vec<_>) =
preds.iter().partition(|&pred| {
if let ty::Adt(def, _) = pred.self_ty().kind() {
def.did().is_local()
} else {
false
}
});

local_preds.sort_by_key(|pred: &&ty::TraitPredicate<'_>| pred.trait_ref.to_string());
let local_def_ids = local_preds
.iter()
.filter_map(|pred| match pred.self_ty().kind() {
ty::Adt(def, _) => Some(def.did()),
_ => None,
})
.collect::<FxIndexSet<_>>();
let mut spans: MultiSpan = def_ids
let mut local_spans: MultiSpan = local_def_ids
.iter()
.filter_map(|def_id| {
let span = self.tcx.def_span(*def_id);
if span.is_dummy() { None } else { Some(span) }
})
.collect::<Vec<_>>()
.into();

for pred in &preds {
for pred in &local_preds {
match pred.self_ty().kind() {
ty::Adt(def, _) if def.did().is_local() => {
spans.push_span_label(
ty::Adt(def, _) => {
local_spans.push_span_label(
self.tcx.def_span(def.did()),
format!("must implement `{}`", pred.trait_ref.print_trait_sugared()),
);
}
_ => {}
}
}

if all_local_types_needing_impls && spans.primary_span().is_some() {
let msg = if preds.len() == 1 {
if local_spans.primary_span().is_some() {
let msg = if local_preds.len() == 1 {
format!(
"an implementation of `{}` might be missing for `{}`",
preds[0].trait_ref.print_trait_sugared(),
preds[0].self_ty()
local_preds[0].trait_ref.print_trait_sugared(),
local_preds[0].self_ty()
)
} else {
format!(
"the following type{} would have to `impl` {} required trait{} for this \
operation to be valid",
pluralize!(def_ids.len()),
if def_ids.len() == 1 { "its" } else { "their" },
pluralize!(preds.len()),
pluralize!(local_def_ids.len()),
if local_def_ids.len() == 1 { "its" } else { "their" },
pluralize!(local_preds.len()),
)
};
err.span_note(local_spans, msg);
}

foreign_preds.sort_by_key(|pred: &&ty::TraitPredicate<'_>| pred.trait_ref.to_string());
let foreign_def_ids = foreign_preds
.iter()
.filter_map(|pred| match pred.self_ty().kind() {
ty::Adt(def, _) => Some(def.did()),
_ => None,
})
.collect::<FxIndexSet<_>>();
let mut foreign_spans: MultiSpan = foreign_def_ids
.iter()
.filter_map(|def_id| {
let span = self.tcx.def_span(*def_id);
if span.is_dummy() { None } else { Some(span) }
})
.collect::<Vec<_>>()
.into();
for pred in &foreign_preds {
match pred.self_ty().kind() {
ty::Adt(def, _) => {
foreign_spans.push_span_label(
self.tcx.def_span(def.did()),
format!("not implement `{}`", pred.trait_ref.print_trait_sugared()),
);
}
_ => {}
}
}
if foreign_spans.primary_span().is_some() {
let msg = if foreign_preds.len() == 1 {
format!(
"the foreign item type `{}` doesn't implement `{}`",
foreign_preds[0].self_ty(),
foreign_preds[0].trait_ref.print_trait_sugared()
)
} else {
format!(
"the foreign item type{} {} implement required trait{} for this \
operation to be valid",
pluralize!(foreign_def_ids.len()),
if foreign_def_ids.len() > 1 { "don't" } else { "doesn't" },
pluralize!(foreign_preds.len()),
)
};
err.span_note(spans, msg);
err.span_note(foreign_spans, msg);
}

let preds: Vec<_> = errors
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_next_trait_solver/src/solve/alias_relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ where
&mut self,
goal: Goal<I, (I::Term, I::Term, ty::AliasRelationDirection)>,
) -> QueryResult<I> {
let tcx = self.cx();
let cx = self.cx();
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
debug_assert!(lhs.to_alias_term().is_some() || rhs.to_alias_term().is_some());

// Structurally normalize the lhs.
let lhs = if let Some(alias) = lhs.to_alias_term() {
let term = self.next_term_infer_of_kind(lhs);
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
term
} else {
lhs
Expand All @@ -48,7 +48,7 @@ where
// Structurally normalize the rhs.
let rhs = if let Some(alias) = rhs.to_alias_term() {
let term = self.next_term_infer_of_kind(rhs);
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
self.add_normalizes_to_goal(goal.with(cx, ty::NormalizesTo { alias, term }));
term
} else {
rhs
Expand Down
Loading
Loading