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 6 pull requests #116820

Merged
merged 25 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
46c545c
coverage: Rename `check_invoked_macro_name_span` to `maybe_push_macro…
Zalathar Oct 16, 2023
9b6ce4f
coverage: Rename `check_pending_dups` to `maybe_flush_pending_dups`
Zalathar Oct 16, 2023
d928d3e
coverage: Rename `hold_pending_dups_unless_dominated` to `update_pend…
Zalathar Oct 15, 2023
fa2e262
coverage: Use `DUMMY_SP` instead of creating a dummy span manually
Zalathar Oct 15, 2023
5f1e8f9
coverage: Simplify `push_refined_span`
Zalathar Oct 14, 2023
97d1a91
coverage: Flatten guard logic in `maybe_push_macro_name_span`
Zalathar Oct 16, 2023
7bbe4be
coverage: Flatten guard logic in `maybe_flush_pending_dups`
Zalathar Oct 16, 2023
9bb27f3
coverage: Remove redundant field `prev_expn_span`
Zalathar Oct 15, 2023
b1c44f4
coverage: Call `prev`/`curr` less in `to_refined_spans`
Zalathar Oct 15, 2023
41038db
coverage: Call `prev`/`curr` less in other places
Zalathar Oct 15, 2023
25e6303
coverage: Move `take_curr` and note what its callers are doing
Zalathar Oct 15, 2023
4ab4273
coverage: Inline `prev_starts_after_next`
Zalathar Oct 14, 2023
5e5a8e7
coverage: Inline `span_bcb_dominates`
Zalathar Oct 15, 2023
7aa1b83
coverage: Explain why we temporarily steal `pending_dups`
Zalathar Oct 14, 2023
17ec3cd
Fix outlives suggestion for GAT in RPITIT
compiler-errors Oct 16, 2023
414135d
Make `rustc_onunimplemented` export path agnostic
Noratrieb Oct 16, 2023
5e6da1e
add myself to smir triage
ouz-a Oct 16, 2023
ad26a0b
Improve display of parallel jobs in rustdoc-gui tester script
GuillaumeGomez Oct 16, 2023
587899e
Preserve unicode escapes in format string literals when pretty-printi…
narpfel Oct 16, 2023
581f88d
Rollup merge of #116754 - Zalathar:spans, r=oli-obk
GuillaumeGomez Oct 16, 2023
4c1c8ab
Rollup merge of #116798 - GuillaumeGomez:rustdoc-gui-tester-cleanup, …
GuillaumeGomez Oct 16, 2023
d0ade3f
Rollup merge of #116800 - compiler-errors:rpitit-gat-outlives, r=jack…
GuillaumeGomez Oct 16, 2023
347f7f3
Rollup merge of #116805 - Nilstrieb:onunimplemented-std-core-alloc-wh…
GuillaumeGomez Oct 16, 2023
23000c3
Rollup merge of #116808 - ouz-a:add_myself_to_triage, r=Nilstrieb
GuillaumeGomez Oct 16, 2023
05e2056
Rollup merge of #116811 - narpfel:unpretty-unicode-escape-in-format-s…
GuillaumeGomez Oct 16, 2023
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
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ pub fn reconstruct_format_args_template_string(pieces: &[FormatArgsPiece]) -> St
for piece in pieces {
match piece {
FormatArgsPiece::Literal(s) => {
for c in s.as_str().escape_debug() {
template.push(c);
for c in s.as_str().chars() {
template.extend(c.escape_debug());
if let '{' | '}' = c {
template.push(c);
}
Expand Down
60 changes: 27 additions & 33 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,10 @@ fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) {
/// fn into_iter<'a>(&'a self) -> Self::Iter<'a>;
/// }
/// ```
fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRef]) {
fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
// Associates every GAT's def_id to a list of possibly missing bounds detected by this lint.
let mut required_bounds_by_item = FxHashMap::default();
let associated_items = tcx.associated_items(trait_def_id);

// Loop over all GATs together, because if this lint suggests adding a where-clause bound
// to one GAT, it might then require us to an additional bound on another GAT.
Expand All @@ -325,8 +326,8 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
// those GATs.
loop {
let mut should_continue = false;
for gat_item in associated_items {
let gat_def_id = gat_item.id.owner_id;
for gat_item in associated_items.in_definition_order() {
let gat_def_id = gat_item.def_id.expect_local();
let gat_item = tcx.associated_item(gat_def_id);
// If this item is not an assoc ty, or has no args, then it's not a GAT
if gat_item.kind != ty::AssocKind::Type {
Expand All @@ -342,18 +343,18 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
// This is calculated by taking the intersection of the bounds that each item
// constrains the GAT with individually.
let mut new_required_bounds: Option<FxHashSet<ty::Clause<'_>>> = None;
for item in associated_items {
let item_def_id = item.id.owner_id;
for item in associated_items.in_definition_order() {
let item_def_id = item.def_id.expect_local();
// Skip our own GAT, since it does not constrain itself at all.
if item_def_id == gat_def_id {
continue;
}

let param_env = tcx.param_env(item_def_id);

let item_required_bounds = match item.kind {
let item_required_bounds = match tcx.associated_item(item_def_id).kind {
// In our example, this corresponds to `into_iter` method
hir::AssocItemKind::Fn { .. } => {
ty::AssocKind::Fn => {
// For methods, we check the function signature's return type for any GATs
// to constrain. In the `into_iter` case, we see that the return type
// `Self::Iter<'a>` is a GAT we want to gather any potential missing bounds from.
Expand All @@ -369,12 +370,12 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
// We also assume that all of the function signature's parameter types
// are well formed.
&sig.inputs().iter().copied().collect(),
gat_def_id.def_id,
gat_def_id,
gat_generics,
)
}
// In our example, this corresponds to the `Iter` and `Item` associated types
hir::AssocItemKind::Type => {
ty::AssocKind::Type => {
// If our associated item is a GAT with missing bounds, add them to
// the param-env here. This allows this GAT to propagate missing bounds
// to other GATs.
Expand All @@ -391,11 +392,11 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
.instantiate_identity_iter_copied()
.collect::<Vec<_>>(),
&FxIndexSet::default(),
gat_def_id.def_id,
gat_def_id,
gat_generics,
)
}
hir::AssocItemKind::Const => None,
ty::AssocKind::Const => None,
};

if let Some(item_required_bounds) = item_required_bounds {
Expand Down Expand Up @@ -431,7 +432,12 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
}

for (gat_def_id, required_bounds) in required_bounds_by_item {
let gat_item_hir = tcx.hir().expect_trait_item(gat_def_id.def_id);
// Don't suggest adding `Self: 'a` to a GAT that can't be named
if tcx.is_impl_trait_in_trait(gat_def_id.to_def_id()) {
continue;
}

let gat_item_hir = tcx.hir().expect_trait_item(gat_def_id);
debug!(?required_bounds);
let param_env = tcx.param_env(gat_def_id);

Expand All @@ -441,21 +447,16 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => {
!region_known_to_outlive(
tcx,
gat_def_id.def_id,
gat_def_id,
param_env,
&FxIndexSet::default(),
a,
b,
)
}
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => !ty_known_to_outlive(
tcx,
gat_def_id.def_id,
param_env,
&FxIndexSet::default(),
a,
b,
),
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(a, b)) => {
!ty_known_to_outlive(tcx, gat_def_id, param_env, &FxIndexSet::default(), a, b)
}
_ => bug!("Unexpected ClauseKind"),
})
.map(|clause| clause.to_string())
Expand Down Expand Up @@ -534,7 +535,7 @@ fn augment_param_env<'tcx>(
fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
item_def_id: hir::OwnerId,
item_def_id: LocalDefId,
to_check: T,
wf_tys: &FxIndexSet<Ty<'tcx>>,
gat_def_id: LocalDefId,
Expand Down Expand Up @@ -567,7 +568,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// reflected in a where clause on the GAT itself.
for (ty, ty_idx) in &types {
// In our example, requires that `Self: 'a`
if ty_known_to_outlive(tcx, item_def_id.def_id, param_env, &wf_tys, *ty, *region_a) {
if ty_known_to_outlive(tcx, item_def_id, param_env, &wf_tys, *ty, *region_a) {
debug!(?ty_idx, ?region_a_idx);
debug!("required clause: {ty} must outlive {region_a}");
// Translate into the generic parameters of the GAT. In
Expand Down Expand Up @@ -606,14 +607,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
if matches!(**region_b, ty::ReStatic | ty::ReError(_)) || region_a == region_b {
continue;
}
if region_known_to_outlive(
tcx,
item_def_id.def_id,
param_env,
&wf_tys,
*region_a,
*region_b,
) {
if region_known_to_outlive(tcx, item_def_id, param_env, &wf_tys, *region_a, *region_b) {
debug!(?region_a_idx, ?region_b_idx);
debug!("required clause: {region_a} must outlive {region_b}");
// Translate into the generic parameters of the GAT.
Expand Down Expand Up @@ -1114,8 +1108,8 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
});

// Only check traits, don't check trait aliases
if let hir::ItemKind::Trait(_, _, _, _, items) = item.kind {
check_gat_where_clauses(tcx, items);
if let hir::ItemKind::Trait(..) = item.kind {
check_gat_where_clauses(tcx, item.owner_id.def_id);
}
}

Expand Down
Loading
Loading