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 12 pull requests #91658

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
413ca98
Update std::env::temp_dir to use GetTempPath2 on Windows when available.
talagrand Oct 17, 2021
1d26e41
Clarify platform availability of GetTempPath2
talagrand Oct 27, 2021
70855b2
Add spin_loop hint for RISC-V architecture
luojia65 Dec 5, 2021
61cab77
allow for failure of subst_normalize_erasing_regions in const_eval
b-naber Dec 5, 2021
3f831c6
add test and bless existing ones
b-naber Dec 5, 2021
2a95958
Evaluate inline const pat early and report error if too generic
nbdd0121 Dec 5, 2021
97952f4
Link to rustdoc_json_types docs instead of rustdoc-json RFC
aDotInTheVoid Dec 6, 2021
78e88f4
Only shown relevant type params in E0283 label
estebank Nov 8, 2021
3fd15c8
Refer to uninferred `const` params by their name, instead of `{ _: _ }`
estebank Nov 8, 2021
6a691b1
Refer to const params as "const params" and not "type params"
estebank Nov 8, 2021
7271d1f
Add test with multiple type params failing inference
estebank Nov 19, 2021
4aceaed
Update cargo
ehuss Dec 7, 2021
1b27b69
don't allocate strings when str is enought for using as key
klensy Dec 7, 2021
4dd3f4e
Add missing whitespace before disabled HTML attribute
GuillaumeGomez Dec 7, 2021
a79b702
Remove unneeded access to pretty printer's `s` field in favor of deref
dtolnay Dec 5, 2021
6e7ec0c
Simplify collect_in_band_defs.
cjgillot Nov 12, 2021
72b6f70
Use collect_in_band_defs for async lifetime captures.
cjgillot Nov 29, 2021
8576ab4
Store impl_trait_fn inside OpaqueTyOrigin.
cjgillot Nov 30, 2021
54ff721
Simplify match.
cjgillot Dec 7, 2021
908f300
Remove the reg_thumb register class for asm! on ARM
Amanieu Nov 11, 2021
5d1aa35
Rollup merge of #89999 - talagrand:GetTempPath2, r=m-ou-se
matthiaskrgr Dec 8, 2021
97fca83
Rollup merge of #90709 - estebank:erase-known-type-params, r=nagisa
matthiaskrgr Dec 8, 2021
a713341
Rollup merge of #90796 - Amanieu:remove_reg_thumb, r=joshtriplett
matthiaskrgr Dec 8, 2021
22afb94
Rollup merge of #91548 - luojia65:hint-spin-loop-riscv, r=Amanieu
matthiaskrgr Dec 8, 2021
4da7fcc
Rollup merge of #91551 - b-naber:const-eval-normalization-ice, r=oli-obk
matthiaskrgr Dec 8, 2021
2429f11
Rollup merge of #91570 - nbdd0121:const_typeck, r=oli-obk
matthiaskrgr Dec 8, 2021
5be5182
Rollup merge of #91571 - dtolnay:printerderef, r=Mark-Simulacrum
matthiaskrgr Dec 8, 2021
d00e238
Rollup merge of #91610 - aDotInTheVoid:patch-2, r=GuillaumeGomez
matthiaskrgr Dec 8, 2021
c4bd406
Rollup merge of #91619 - ehuss:update-cargo, r=ehuss
matthiaskrgr Dec 8, 2021
4f05c4a
Rollup merge of #91626 - klensy:json-less-alloc, r=petrochenkov
matthiaskrgr Dec 8, 2021
1839c1a
Rollup merge of #91630 - GuillaumeGomez:missing-whitespace, r=notriddle
matthiaskrgr Dec 8, 2021
efa06f3
Rollup merge of #91640 - cjgillot:in-band-collect, r=oli-obk
matthiaskrgr Dec 8, 2021
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
6 changes: 3 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,11 @@ dependencies = [

[[package]]
name = "clap"
version = "2.33.3"
version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [
"ansi_term 0.11.0",
"ansi_term 0.12.1",
"atty",
"bitflags",
"strsim",
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
AnonymousLifetimeMode::PassThrough,
|this, idty| {
let ret_id = asyncness.opt_return_id();
this.lower_fn_decl(
&decl,
Some((fn_def_id.to_def_id(), idty)),
true,
ret_id,
)
this.lower_fn_decl(&decl, Some((fn_def_id, idty)), true, ret_id)
},
);
let sig = hir::FnSig {
Expand Down Expand Up @@ -1264,7 +1259,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|this, idty| {
this.lower_fn_decl(
&sig.decl,
Some((fn_def_id.to_def_id(), idty)),
Some((fn_def_id, idty)),
impl_trait_return_allow,
is_async,
)
Expand Down
192 changes: 87 additions & 105 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ enum ImplTraitContext<'b, 'a> {
ReturnPositionOpaqueTy {
/// `DefId` for the parent function, used to look up necessary
/// information later.
fn_def_id: DefId,
fn_def_id: LocalDefId,
/// Origin: Either OpaqueTyOrigin::FnReturn or OpaqueTyOrigin::AsyncFn,
origin: hir::OpaqueTyOrigin,
},
Expand Down Expand Up @@ -646,31 +646,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
/// parameter while `f` is running (and restored afterwards).
fn collect_in_band_defs<T>(
&mut self,
parent_def_id: LocalDefId,
anonymous_lifetime_mode: AnonymousLifetimeMode,
f: impl FnOnce(&mut Self) -> (Vec<hir::GenericParam<'hir>>, T),
) -> (Vec<hir::GenericParam<'hir>>, T) {
assert!(!self.is_collecting_in_band_lifetimes);
assert!(self.lifetimes_to_define.is_empty());
let old_anonymous_lifetime_mode = self.anonymous_lifetime_mode;

self.anonymous_lifetime_mode = anonymous_lifetime_mode;
self.is_collecting_in_band_lifetimes = true;

let (in_band_ty_params, res) = f(self);

self.is_collecting_in_band_lifetimes = false;
self.anonymous_lifetime_mode = old_anonymous_lifetime_mode;

let lifetimes_to_define = self.lifetimes_to_define.split_off(0);
f: impl FnOnce(&mut Self) -> T,
) -> (Vec<(Span, ParamName)>, T) {
let was_collecting = std::mem::replace(&mut self.is_collecting_in_band_lifetimes, true);
let len = self.lifetimes_to_define.len();

let params = lifetimes_to_define
.into_iter()
.map(|(span, hir_name)| self.lifetime_to_generic_param(span, hir_name, parent_def_id))
.chain(in_band_ty_params.into_iter())
.collect();
let res = f(self);

(params, res)
let lifetimes_to_define = self.lifetimes_to_define.split_off(len);
self.is_collecting_in_band_lifetimes = was_collecting;
(lifetimes_to_define, res)
}

/// Converts a lifetime into a new generic parameter.
Expand Down Expand Up @@ -785,27 +770,39 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
anonymous_lifetime_mode: AnonymousLifetimeMode,
f: impl FnOnce(&mut Self, &mut Vec<hir::GenericParam<'hir>>) -> T,
) -> (hir::Generics<'hir>, T) {
let (in_band_defs, (mut lowered_generics, res)) =
self.with_in_scope_lifetime_defs(&generics.params, |this| {
this.collect_in_band_defs(parent_def_id, anonymous_lifetime_mode, |this| {
let mut params = Vec::new();
// Note: it is necessary to lower generics *before* calling `f`.
// When lowering `async fn`, there's a final step when lowering
// the return type that assumes that all in-scope lifetimes have
// already been added to either `in_scope_lifetimes` or
// `lifetimes_to_define`. If we swapped the order of these two,
// in-band-lifetimes introduced by generics or where-clauses
// wouldn't have been added yet.
let generics = this.lower_generics_mut(
generics,
ImplTraitContext::Universal(&mut params, this.current_hir_id_owner),
);
let res = f(this, &mut params);
(params, (generics, res))
let (lifetimes_to_define, (mut lowered_generics, impl_trait_defs, res)) = self
.collect_in_band_defs(|this| {
this.with_anonymous_lifetime_mode(anonymous_lifetime_mode, |this| {
this.with_in_scope_lifetime_defs(&generics.params, |this| {
let mut impl_trait_defs = Vec::new();
// Note: it is necessary to lower generics *before* calling `f`.
// When lowering `async fn`, there's a final step when lowering
// the return type that assumes that all in-scope lifetimes have
// already been added to either `in_scope_lifetimes` or
// `lifetimes_to_define`. If we swapped the order of these two,
// in-band-lifetimes introduced by generics or where-clauses
// wouldn't have been added yet.
let generics = this.lower_generics_mut(
generics,
ImplTraitContext::Universal(
&mut impl_trait_defs,
this.current_hir_id_owner,
),
);
let res = f(this, &mut impl_trait_defs);
(generics, impl_trait_defs, res)
})
})
});

lowered_generics.params.extend(in_band_defs);
lowered_generics.params.extend(
lifetimes_to_define
.into_iter()
.map(|(span, hir_name)| {
self.lifetime_to_generic_param(span, hir_name, parent_def_id)
})
.chain(impl_trait_defs),
);

let lowered_generics = lowered_generics.into_generics(self.arena);
(lowered_generics, res)
Expand Down Expand Up @@ -1380,7 +1377,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_opaque_impl_trait(
&mut self,
span: Span,
fn_def_id: Option<DefId>,
fn_def_id: Option<LocalDefId>,
origin: hir::OpaqueTyOrigin,
opaque_ty_node_id: NodeId,
capturable_lifetimes: Option<&FxHashSet<hir::LifetimeName>>,
Expand Down Expand Up @@ -1452,7 +1449,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: lctx.lower_span(span),
},
bounds: hir_bounds,
impl_trait_fn: fn_def_id,
origin,
};

Expand Down Expand Up @@ -1522,7 +1518,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_fn_decl(
&mut self,
decl: &FnDecl,
mut in_band_ty_params: Option<(DefId, &mut Vec<hir::GenericParam<'hir>>)>,
mut in_band_ty_params: Option<(LocalDefId, &mut Vec<hir::GenericParam<'hir>>)>,
impl_trait_return_allow: bool,
make_ret_async: Option<NodeId>,
) -> &'hir hir::FnDecl<'hir> {
Expand Down Expand Up @@ -1580,7 +1576,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
Some((def_id, _)) if impl_trait_return_allow => {
ImplTraitContext::ReturnPositionOpaqueTy {
fn_def_id: def_id,
origin: hir::OpaqueTyOrigin::FnReturn,
origin: hir::OpaqueTyOrigin::FnReturn(def_id),
}
}
_ => ImplTraitContext::disallowed(),
Expand Down Expand Up @@ -1635,7 +1631,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_async_fn_ret_ty(
&mut self,
output: &FnRetTy,
fn_def_id: DefId,
fn_def_id: LocalDefId,
opaque_ty_node_id: NodeId,
) -> hir::FnRetTy<'hir> {
debug!(
Expand Down Expand Up @@ -1689,18 +1685,29 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// this is because the elided lifetimes from the return type
// should be figured out using the ordinary elision rules, and
// this desugaring achieves that.

debug!("lower_async_fn_ret_ty: in_scope_lifetimes={:#?}", self.in_scope_lifetimes);
debug!("lower_async_fn_ret_ty: lifetimes_to_define={:#?}", self.lifetimes_to_define);

// Calculate all the lifetimes that should be captured
// by the opaque type. This should include all in-scope
// lifetime parameters, including those defined in-band.
//
// The variable `input_lifetimes_count` tracks the number of
// lifetime parameters to the opaque type *not counting* those
// lifetimes elided in the return type. This includes those
// that are explicitly declared (`in_scope_lifetimes`) and
// those elided lifetimes we found in the arguments (current
// content of `lifetimes_to_define`). Next, we will process
// the return type, which will cause `lifetimes_to_define` to
// grow.
let input_lifetimes_count = self.in_scope_lifetimes.len() + self.lifetimes_to_define.len();

let mut lifetime_params = Vec::new();
// `lifetime_params` is a vector of tuple (span, parameter name, lifetime name).

// Input lifetime like `'a` or `'1`:
let mut lifetime_params: Vec<_> = self
.in_scope_lifetimes
.iter()
.cloned()
.map(|name| (name.ident().span, name, hir::LifetimeName::Param(name)))
.chain(
self.lifetimes_to_define
.iter()
.map(|&(span, name)| (span, name, hir::LifetimeName::Param(name))),
)
.collect();

self.with_hir_id_owner(opaque_ty_node_id, |this| {
// We have to be careful to get elision right here. The
// idea is that we create a lifetime parameter for each
Expand All @@ -1710,34 +1717,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
//
// Then, we will create `fn foo(..) -> Foo<'_, '_>`, and
// hence the elision takes place at the fn site.
let future_bound = this
.with_anonymous_lifetime_mode(AnonymousLifetimeMode::CreateParameter, |this| {
this.lower_async_fn_output_type_to_future_bound(output, fn_def_id, span)
let (lifetimes_to_define, future_bound) =
this.with_anonymous_lifetime_mode(AnonymousLifetimeMode::CreateParameter, |this| {
this.collect_in_band_defs(|this| {
this.lower_async_fn_output_type_to_future_bound(output, fn_def_id, span)
})
});

debug!("lower_async_fn_ret_ty: future_bound={:#?}", future_bound);
debug!("lower_async_fn_ret_ty: lifetimes_to_define={:#?}", lifetimes_to_define);

// Calculate all the lifetimes that should be captured
// by the opaque type. This should include all in-scope
// lifetime parameters, including those defined in-band.
//
// Note: this must be done after lowering the output type,
// as the output type may introduce new in-band lifetimes.
lifetime_params = this
.in_scope_lifetimes
.iter()
.cloned()
.map(|name| (name.ident().span, name))
.chain(this.lifetimes_to_define.iter().cloned())
.collect();

debug!("lower_async_fn_ret_ty: in_scope_lifetimes={:#?}", this.in_scope_lifetimes);
debug!("lower_async_fn_ret_ty: lifetimes_to_define={:#?}", this.lifetimes_to_define);
lifetime_params.extend(
// Output lifetime like `'_`:
lifetimes_to_define
.into_iter()
.map(|(span, name)| (span, name, hir::LifetimeName::Implicit(false))),
);
debug!("lower_async_fn_ret_ty: lifetime_params={:#?}", lifetime_params);

let generic_params =
this.arena.alloc_from_iter(lifetime_params.iter().map(|(span, hir_name)| {
this.lifetime_to_generic_param(*span, *hir_name, opaque_ty_def_id)
this.arena.alloc_from_iter(lifetime_params.iter().map(|&(span, hir_name, _)| {
this.lifetime_to_generic_param(span, hir_name, opaque_ty_def_id)
}));

let opaque_ty_item = hir::OpaqueTy {
Expand All @@ -1747,8 +1746,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
span: this.lower_span(span),
},
bounds: arena_vec![this; future_bound],
impl_trait_fn: Some(fn_def_id),
origin: hir::OpaqueTyOrigin::AsyncFn,
origin: hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
};

trace!("exist ty from async fn def id: {:#?}", opaque_ty_def_id);
Expand All @@ -1771,25 +1769,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
//
// For the "output" lifetime parameters, we just want to
// generate `'_`.
let mut generic_args = Vec::with_capacity(lifetime_params.len());
generic_args.extend(lifetime_params[..input_lifetimes_count].iter().map(
|&(span, hir_name)| {
// Input lifetime like `'a` or `'1`:
let generic_args =
self.arena.alloc_from_iter(lifetime_params.into_iter().map(|(span, _, name)| {
GenericArg::Lifetime(hir::Lifetime {
hir_id: self.next_id(),
span: self.lower_span(span),
name: hir::LifetimeName::Param(hir_name),
name,
})
},
));
generic_args.extend(lifetime_params[input_lifetimes_count..].iter().map(|&(span, _)|
// Output lifetime like `'_`.
GenericArg::Lifetime(hir::Lifetime {
hir_id: self.next_id(),
span: self.lower_span(span),
name: hir::LifetimeName::Implicit(false),
})));
let generic_args = self.arena.alloc_from_iter(generic_args);
}));

// Create the `Foo<...>` reference itself. Note that the `type
// Foo = impl Trait` is, internally, created as a child of the
Expand All @@ -1805,7 +1792,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_async_fn_output_type_to_future_bound(
&mut self,
output: &FnRetTy,
fn_def_id: DefId,
fn_def_id: LocalDefId,
span: Span,
) -> hir::GenericBound<'hir> {
// Compute the `T` in `Future<Output = T>` from the return type.
Expand All @@ -1816,7 +1803,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// generates.
let context = ImplTraitContext::ReturnPositionOpaqueTy {
fn_def_id,
origin: hir::OpaqueTyOrigin::FnReturn,
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
};
self.lower_ty(ty, context)
}
Expand Down Expand Up @@ -2453,17 +2440,12 @@ impl<'hir> GenericArgsCtor<'hir> {
}
}

#[tracing::instrument(level = "debug")]
fn lifetimes_from_impl_trait_bounds(
opaque_ty_id: NodeId,
bounds: hir::GenericBounds<'_>,
lifetimes_to_include: Option<&FxHashSet<hir::LifetimeName>>,
) -> Vec<(hir::LifetimeName, Span)> {
debug!(
"lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \
bounds={:#?})",
opaque_ty_id, bounds,
);

// This visitor walks over `impl Trait` bounds and creates defs for all lifetimes that
// appear in the bounds, excluding lifetimes that are created within the bounds.
// E.g., `'a`, `'b`, but not `'c` in `impl for<'c> SomeTrait<'a, 'b, 'c>`.
Expand Down
Loading