Skip to content

Rollup of 7 pull requests #112625

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

Merged
merged 17 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
22a4525
loongarch64-none*: Remove environment component from llvm target
heiher Jun 13, 2023
af4040a
Use a Stable trait to translate mir -> smir
celinval Jun 13, 2023
9e21052
Improve docs/clean up negative overlap functions
compiler-errors Jun 14, 2023
bc78d0c
Error on unconstrained lifetime in RPITIT
compiler-errors Jun 14, 2023
72531b7
Fix explicit-outlives-requirements lint span
sginnett Jun 14, 2023
2f9fac0
Update browser-ui-test version to 0.16.7
GuillaumeGomez Jun 14, 2023
fd4320c
Transform backslash into slashes in DOC_FOLDER variable for browser-u…
GuillaumeGomez Jun 14, 2023
df9a46f
Replace unicode value with character in shortcuts.goml test
GuillaumeGomez Jun 14, 2023
fced638
Fix `href` attribute value check on Windows (`DOC_PATH` lacks an extr…
GuillaumeGomez Jun 14, 2023
cb093fc
Fix typo
AntoniosBarotsis Jun 14, 2023
2759a7d
Rollup merge of #112584 - loongarch-rs:remove-env, r=petrochenkov
matthiaskrgr Jun 14, 2023
502ac47
Rollup merge of #112600 - celinval:stable-mir-rvalue, r=oli-obk
matthiaskrgr Jun 14, 2023
7240943
Rollup merge of #112605 - compiler-errors:negative-docs, r=spastorino
matthiaskrgr Jun 14, 2023
8aff112
Rollup merge of #112611 - compiler-errors:unconstrained-lt-in-rpitit,…
matthiaskrgr Jun 14, 2023
41d5aec
Rollup merge of #112612 - sginnett:issue-105150, r=compiler-errors
matthiaskrgr Jun 14, 2023
77b307f
Rollup merge of #112613 - GuillaumeGomez:fix-gui-test-windows, r=notr…
matthiaskrgr Jun 14, 2023
3616388
Rollup merge of #112620 - AntoniosBarotsis:master, r=Nilstrieb
matthiaskrgr Jun 14, 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
59 changes: 38 additions & 21 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ pub(super) fn compare_impl_method<'tcx>(
debug!("compare_impl_method(impl_trait_ref={:?})", impl_trait_ref);

let _: Result<_, ErrorGuaranteed> = try {
compare_self_type(tcx, impl_m, trait_m, impl_trait_ref)?;
compare_number_of_generics(tcx, impl_m, trait_m, false)?;
compare_generic_param_kinds(tcx, impl_m, trait_m, false)?;
compare_number_of_method_arguments(tcx, impl_m, trait_m)?;
compare_synthetic_generics(tcx, impl_m, trait_m)?;
compare_asyncness(tcx, impl_m, trait_m)?;
check_method_is_structurally_compatible(tcx, impl_m, trait_m, impl_trait_ref, false)?;
compare_method_predicate_entailment(
tcx,
impl_m,
Expand All @@ -61,6 +56,26 @@ pub(super) fn compare_impl_method<'tcx>(
};
}

/// Checks a bunch of different properties of the impl/trait methods for
/// compatibility, such as asyncness, number of argument, self receiver kind,
/// and number of early- and late-bound generics.
fn check_method_is_structurally_compatible<'tcx>(
tcx: TyCtxt<'tcx>,
impl_m: ty::AssocItem,
trait_m: ty::AssocItem,
impl_trait_ref: ty::TraitRef<'tcx>,
delay: bool,
) -> Result<(), ErrorGuaranteed> {
compare_self_type(tcx, impl_m, trait_m, impl_trait_ref, delay)?;
compare_number_of_generics(tcx, impl_m, trait_m, delay)?;
compare_generic_param_kinds(tcx, impl_m, trait_m, delay)?;
compare_number_of_method_arguments(tcx, impl_m, trait_m, delay)?;
compare_synthetic_generics(tcx, impl_m, trait_m, delay)?;
compare_asyncness(tcx, impl_m, trait_m, delay)?;
check_region_bounds_on_impl_item(tcx, impl_m, trait_m, delay)?;
Ok(())
}

/// This function is best explained by example. Consider a trait with it's implementation:
///
/// ```rust
Expand Down Expand Up @@ -177,9 +192,6 @@ fn compare_method_predicate_entailment<'tcx>(
let impl_m_predicates = tcx.predicates_of(impl_m.def_id);
let trait_m_predicates = tcx.predicates_of(trait_m.def_id);

// Check region bounds.
check_region_bounds_on_impl_item(tcx, impl_m, trait_m, false)?;

// Create obligations for each predicate declared by the impl
// definition in the context of the trait's parameter
// environment. We can't just use `impl_env.caller_bounds`,
Expand Down Expand Up @@ -534,6 +546,7 @@ fn compare_asyncness<'tcx>(
tcx: TyCtxt<'tcx>,
impl_m: ty::AssocItem,
trait_m: ty::AssocItem,
delay: bool,
) -> Result<(), ErrorGuaranteed> {
if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async {
match tcx.fn_sig(impl_m.def_id).skip_binder().skip_binder().output().kind() {
Expand All @@ -544,11 +557,14 @@ fn compare_asyncness<'tcx>(
// We don't know if it's ok, but at least it's already an error.
}
_ => {
return Err(tcx.sess.emit_err(crate::errors::AsyncTraitImplShouldBeAsync {
span: tcx.def_span(impl_m.def_id),
method_name: trait_m.name,
trait_item_span: tcx.hir().span_if_local(trait_m.def_id),
}));
return Err(tcx
.sess
.create_err(crate::errors::AsyncTraitImplShouldBeAsync {
span: tcx.def_span(impl_m.def_id),
method_name: trait_m.name,
trait_item_span: tcx.hir().span_if_local(trait_m.def_id),
})
.emit_unless(delay));
}
};
}
Expand Down Expand Up @@ -602,9 +618,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(

// First, check a few of the same things as `compare_impl_method`,
// just so we don't ICE during substitution later.
compare_number_of_generics(tcx, impl_m, trait_m, true)?;
compare_generic_param_kinds(tcx, impl_m, trait_m, true)?;
check_region_bounds_on_impl_item(tcx, impl_m, trait_m, true)?;
check_method_is_structurally_compatible(tcx, impl_m, trait_m, impl_trait_ref, true)?;

let trait_to_impl_substs = impl_trait_ref.substs;

Expand Down Expand Up @@ -1097,6 +1111,7 @@ fn compare_self_type<'tcx>(
impl_m: ty::AssocItem,
trait_m: ty::AssocItem,
impl_trait_ref: ty::TraitRef<'tcx>,
delay: bool,
) -> Result<(), ErrorGuaranteed> {
// Try to give more informative error messages about self typing
// mismatches. Note that any mismatch will also be detected
Expand Down Expand Up @@ -1145,7 +1160,7 @@ fn compare_self_type<'tcx>(
} else {
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
}
return Err(err.emit());
return Err(err.emit_unless(delay));
}

(true, false) => {
Expand All @@ -1166,7 +1181,7 @@ fn compare_self_type<'tcx>(
err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
}

return Err(err.emit());
return Err(err.emit_unless(delay));
}
}

Expand Down Expand Up @@ -1352,6 +1367,7 @@ fn compare_number_of_method_arguments<'tcx>(
tcx: TyCtxt<'tcx>,
impl_m: ty::AssocItem,
trait_m: ty::AssocItem,
delay: bool,
) -> Result<(), ErrorGuaranteed> {
let impl_m_fty = tcx.fn_sig(impl_m.def_id);
let trait_m_fty = tcx.fn_sig(trait_m.def_id);
Expand Down Expand Up @@ -1422,7 +1438,7 @@ fn compare_number_of_method_arguments<'tcx>(
),
);

return Err(err.emit());
return Err(err.emit_unless(delay));
}

Ok(())
Expand All @@ -1432,6 +1448,7 @@ fn compare_synthetic_generics<'tcx>(
tcx: TyCtxt<'tcx>,
impl_m: ty::AssocItem,
trait_m: ty::AssocItem,
delay: bool,
) -> Result<(), ErrorGuaranteed> {
// FIXME(chrisvittal) Clean up this function, list of FIXME items:
// 1. Better messages for the span labels
Expand Down Expand Up @@ -1551,7 +1568,7 @@ fn compare_synthetic_generics<'tcx>(
}
_ => unreachable!(),
}
error_found = Some(err.emit());
error_found = Some(err.emit_unless(delay));
}
}
if let Some(reported) = error_found { Err(reported) } else { Ok(()) }
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_hir_analysis/src/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,23 @@ fn enforce_impl_params_are_constrained(tcx: TyCtxt<'_>, impl_def_id: LocalDefId)
if item.defaultness(tcx).has_value() {
cgp::parameters_for(&tcx.type_of(def_id).subst_identity(), true)
} else {
Vec::new()
vec![]
}
}
ty::AssocKind::Fn | ty::AssocKind::Const => Vec::new(),
ty::AssocKind::Fn => {
if !tcx.lower_impl_trait_in_trait_to_assoc_ty()
&& item.defaultness(tcx).has_value()
&& tcx.impl_method_has_trait_impl_trait_tys(item.def_id)
&& let Ok(table) = tcx.collect_return_position_impl_trait_in_trait_tys(def_id)
{
table.values().copied().flat_map(|ty| {
cgp::parameters_for(&ty.subst_identity(), true)
}).collect()
} else {
vec![]
}
}
ty::AssocKind::Const => vec![],
}
})
.collect();
Expand Down
19 changes: 12 additions & 7 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,12 +2124,16 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
}

let ty_generics = cx.tcx.generics_of(def_id);
let num_where_predicates = hir_generics
.predicates
.iter()
.filter(|predicate| predicate.in_where_clause())
.count();

let mut bound_count = 0;
let mut lint_spans = Vec::new();
let mut where_lint_spans = Vec::new();
let mut dropped_predicate_count = 0;
let num_predicates = hir_generics.predicates.len();
let mut dropped_where_predicate_count = 0;
for (i, where_predicate) in hir_generics.predicates.iter().enumerate() {
let (relevant_lifetimes, bounds, predicate_span, in_where_clause) =
match where_predicate {
Expand Down Expand Up @@ -2186,8 +2190,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
bound_count += bound_spans.len();

let drop_predicate = bound_spans.len() == bounds.len();
if drop_predicate {
dropped_predicate_count += 1;
if drop_predicate && in_where_clause {
dropped_where_predicate_count += 1;
}

if drop_predicate {
Expand All @@ -2196,7 +2200,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
} else if predicate_span.from_expansion() {
// Don't try to extend the span if it comes from a macro expansion.
where_lint_spans.push(predicate_span);
} else if i + 1 < num_predicates {
} else if i + 1 < num_where_predicates {
// If all the bounds on a predicate were inferable and there are
// further predicates, we want to eat the trailing comma.
let next_predicate_span = hir_generics.predicates[i + 1].span();
Expand Down Expand Up @@ -2224,9 +2228,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
}
}

// If all predicates are inferable, drop the entire clause
// If all predicates in where clause are inferable, drop the entire clause
// (including the `where`)
if hir_generics.has_where_clause_predicates && dropped_predicate_count == num_predicates
if hir_generics.has_where_clause_predicates
&& dropped_where_predicate_count == num_where_predicates
{
let where_span = hir_generics.where_clause_span;
// Extend the where clause back to the closing `>` of the
Expand Down
Loading