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 9 pull requests #130671

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9a7644e
rustc_expand: remember module #[path]s during expansion
dianne Sep 11, 2024
a187d0a
add regression test for #97589
dianne Sep 11, 2024
b94c5a1
Avoid re-validating UTF-8 in `FromUtf8Error::into_utf8_lossy`
okaneco Aug 25, 2024
6d788a1
Resolve RTN for TyKind::Path ending in (..)
compiler-errors Aug 23, 2024
19881b5
Conditionally allow lowering RTN (..) in paths
compiler-errors Aug 26, 2024
51b51bb
Implement RTN in resolve_bound_vars and HIR ty lowering
compiler-errors Aug 26, 2024
7c8e281
Flesh out some TODOs
compiler-errors Aug 26, 2024
174c3f9
Add missing diagnostics and flesh out tests
compiler-errors Aug 26, 2024
af24d0b
Resolve self type alias in impl for RTN
compiler-errors Aug 26, 2024
50b8915
Add --enable-profiler to armhf dist
qwertynerd97 Sep 21, 2024
b94f293
ABI compatibility: mention Result guarantee
RalfJung Sep 21, 2024
1ddd67a
add `C-cmse-nonsecure-entry` ABI
folkertdev Aug 15, 2024
5722a80
remove `#[cmse_nonsecure_entry]`
folkertdev Jul 31, 2024
a33dcb3
add test that accepts a `C-cmse-nonsecure-call` function pointer
folkertdev Jul 16, 2024
a41c209
Add assembly test for the cmse unstable features
folkertdev Jul 18, 2024
4d75a4f
disallow cmse ABIs on unsupported platforms
folkertdev Aug 1, 2024
ac9a49f
mark `E0775` as no longer emitte by the compiler
folkertdev Sep 21, 2024
1de894f
More tests and tweak comments
compiler-errors Sep 21, 2024
a35da65
Update Tests
veera-sivarajan Sep 21, 2024
669f610
Prevent Deduplication of `LongRunningWarn`
veera-sivarajan Sep 21, 2024
93993c7
compiler: Accept "improper" ctypes in extern "rust-cold" fn
workingjubilee Sep 21, 2024
a846d55
Assert that explicit_super_predicates_of and explicit_item_bounds tru…
compiler-errors Sep 21, 2024
4f3d06f
Don't elaborate effects predicates into bounds list unless we're actu…
compiler-errors Sep 21, 2024
bc8631e
Rollup merge of #127766 - folkertdev:c-cmse-nonsecure-entry, r=jackh726
matthiaskrgr Sep 21, 2024
7b36e60
Rollup merge of #129629 - compiler-errors:rtn-in-path, r=jackh726
matthiaskrgr Sep 21, 2024
d4c78f2
Rollup merge of #130246 - dianne:issue-97589-fix, r=petrochenkov
matthiaskrgr Sep 21, 2024
6d76140
Rollup merge of #130408 - okaneco:into_lossy_refactor, r=Noratrieb
matthiaskrgr Sep 21, 2024
9df13d0
Rollup merge of #130651 - qwertynerd97:patch-1, r=Kobzol
matthiaskrgr Sep 21, 2024
6fde507
Rollup merge of #130653 - RalfJung:result-abi-compat, r=traviscross
matthiaskrgr Sep 21, 2024
c261642
Rollup merge of #130665 - veera-sivarajan:fix-118612, r=compiler-errors
matthiaskrgr Sep 21, 2024
653e9a2
Rollup merge of #130666 - compiler-errors:super-bounds, r=fee1-dead,f…
matthiaskrgr Sep 21, 2024
0fc976d
Rollup merge of #130667 - workingjubilee:she-is-c-c-c-cold, r=compile…
matthiaskrgr Sep 21, 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
Prev Previous commit
Next Next commit
Implement RTN in resolve_bound_vars and HIR ty lowering
  • Loading branch information
compiler-errors committed Sep 21, 2024
commit 51b51bb570e076d981e12a8e221ed3a74b3025c6
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,12 @@ enum ParamMode {

#[derive(Copy, Clone, Debug)]
enum AllowReturnTypeNotation {
/// Only in types, since RTN is denied later during HIR lowering.
Yes,
/// All other positions (path expr, method, use tree).
No,
}

#[derive(Copy, Clone, Debug)]
enum GenericArgsMode {
ParenSugar,
ReturnTypeNotation,
Expand Down Expand Up @@ -1239,7 +1240,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
qself,
path,
param_mode,
// We deny these after the fact in HIR->middle type lowering.
AllowReturnTypeNotation::Yes,
itctx,
None,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ use super::errors::{
GenericTypeWithParentheses, UseAngleBrackets,
};
use super::{
AllowReturnTypeNotation, GenericArgsCtor, GenericArgsMode, ImplTraitContext, LifetimeRes,
LoweringContext, ParamMode, ResolverAstLoweringExt,
AllowReturnTypeNotation, GenericArgsCtor, GenericArgsMode, ImplTraitContext, ImplTraitPosition,
LifetimeRes, LoweringContext, ParamMode, ResolverAstLoweringExt,
};
use crate::ImplTraitPosition;

impl<'a, 'hir> LoweringContext<'a, 'hir> {
#[instrument(level = "trace", skip(self))]
Expand Down
13 changes: 7 additions & 6 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
for predicate in hir_generics.predicates {
match predicate {
hir::WherePredicate::BoundPredicate(bound_pred) => {
let ty = icx.lower_ty(bound_pred.bounded_ty);
let ty = icx.lowerer().lower_ty_maybe_return_type_notation(bound_pred.bounded_ty);

let bound_vars = tcx.late_bound_vars(bound_pred.hir_id);
// Keep the type around in a dummy predicate, in case of no bounds.
// That way, `where Ty:` is not a complete noop (see #53696) and `Ty`
Expand Down Expand Up @@ -770,6 +771,10 @@ impl<'tcx> ItemCtxt<'tcx> {
continue;
};

// Subtle: If we're collecting `SelfAndAssociatedTypeBounds`, then we
// want to only consider predicates with `Self: ...`, but we don't want
// `OnlySelfBounds(true)` since we want to collect the nested associated
// type bound as well.
let (only_self_bounds, assoc_name) = match filter {
PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => {
(OnlySelfBounds(false), None)
Expand All @@ -780,14 +785,10 @@ impl<'tcx> ItemCtxt<'tcx> {
}
};

// Subtle: If we're collecting `SelfAndAssociatedTypeBounds`, then we
// want to only consider predicates with `Self: ...`, but we don't want
// `OnlySelfBounds(true)` since we want to collect the nested associated
// type bound as well.
let bound_ty = if predicate.is_param_bound(param_def_id.to_def_id()) {
ty
} else if matches!(filter, PredicateFilter::All) {
self.lower_ty(predicate.bounded_ty)
self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty)
} else {
continue;
};
Expand Down
109 changes: 109 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
(pair, r)
})
.unzip();

self.record_late_bound_vars(hir_id, binders);

// If this is an RTN type in the self type, then append those to the binder.
self.try_append_return_type_notation_params(hir_id, bounded_ty);

// Even if there are no lifetimes defined here, we still wrap it in a binder
// scope. If there happens to be a nested poly trait ref (an error), that
// will be `Concatenating` anyways, so we don't have to worry about the depth
Expand Down Expand Up @@ -1839,6 +1844,110 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
let old_value = self.map.defs.swap_remove(&lifetime_ref.hir_id);
assert_eq!(old_value, Some(bad_def));
}

// TODO:
fn try_append_return_type_notation_params(
&mut self,
hir_id: HirId,
hir_ty: &'tcx hir::Ty<'tcx>,
) {
let hir::TyKind::Path(qpath) = hir_ty.kind else {
// TODO:
return;
};

let (mut bound_vars, item_def_id, item_segment) = match qpath {
// TODO:
hir::QPath::Resolved(_, path)
if let [.., item_segment] = &path.segments[..]
&& item_segment.args.is_some_and(|args| {
matches!(
args.parenthesized,
hir::GenericArgsParentheses::ReturnTypeNotation
)
}) =>
{
let Res::Def(DefKind::AssocFn, item_def_id) = path.res else {
bug!();
};
(vec![], item_def_id, item_segment)
}

// TODO:
hir::QPath::TypeRelative(qself, item_segment)
if item_segment.args.is_some_and(|args| {
matches!(args.parenthesized, hir::GenericArgsParentheses::ReturnTypeNotation)
}) =>
{
let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = qself.kind else {
return;
};

match path.res {
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { trait_: _ } => {
let Some(generics) = self.tcx.hir_owner_node(hir_id.owner).generics()
else {
return;
};

let one_bound = generics.predicates.iter().find_map(|predicate| {
let hir::WherePredicate::BoundPredicate(predicate) = predicate else {
return None;
};
let hir::TyKind::Path(hir::QPath::Resolved(None, bounded_path)) =
predicate.bounded_ty.kind
else {
return None;
};
if bounded_path.res != path.res {
return None;
}
predicate.bounds.iter().find_map(|bound| {
let hir::GenericBound::Trait(trait_, _) = bound else {
return None;
};
BoundVarContext::supertrait_hrtb_vars(
self.tcx,
trait_.trait_ref.trait_def_id()?,
item_segment.ident,
ty::AssocKind::Fn,
)
})
});
let Some((bound_vars, assoc_item)) = one_bound else {
return;
};
(bound_vars, assoc_item.def_id, item_segment)
}
Res::SelfTyAlias { is_trait_impl: true, .. } => todo!(),
_ => return,
}
}

_ => return,
};

// TODO:
bound_vars.extend(self.tcx.generics_of(item_def_id).own_params.iter().map(|param| {
match param.kind {
ty::GenericParamDefKind::Lifetime => ty::BoundVariableKind::Region(
ty::BoundRegionKind::BrNamed(param.def_id, param.name),
),
ty::GenericParamDefKind::Type { .. } => {
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id, param.name))
}
ty::GenericParamDefKind::Const { .. } => ty::BoundVariableKind::Const,
}
}));
bound_vars.extend(self.tcx.fn_sig(item_def_id).instantiate_identity().bound_vars());

// TODO:
let existing_bound_vars = self.map.late_bound_vars.get_mut(&hir_id).unwrap();
let existing_bound_vars_saved = existing_bound_vars.clone();
existing_bound_vars.extend(bound_vars);
// TODO: subtle
self.record_late_bound_vars(item_segment.hir_id, existing_bound_vars_saved);
}
}

/// Detects late-bound lifetimes and inserts them into
Expand Down
Loading