Skip to content

Rollup of 11 pull requests #70343

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 50 commits into from
Mar 24, 2020
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5b66f27
Use `const_eval_limit` instead of infinite loop detector
ecstatic-morse Mar 17, 2020
e15c486
Remove infinite loop detector
ecstatic-morse Mar 17, 2020
044dc6e
Update const-eval tests
ecstatic-morse Mar 17, 2020
2daaf2b
replace some adhoc logic with article_and_descr
mark-i-m Mar 16, 2020
99ae428
Improve E0308 error message wording
DeeDeeG Mar 21, 2020
1661a0a
convert a couple more errors
mark-i-m Mar 22, 2020
cdb2c3c
use static strs
mark-i-m Mar 22, 2020
1e5d81d
Fix invalid suggestion on `&mut` iterators yielding `&` references
tirr-c Mar 22, 2020
82f4a1a
get rid of ConstPropUnsupported; use ZST marker structs instead
RalfJung Mar 22, 2020
d40dff9
the crate and tests
mark-i-m Mar 22, 2020
b5636b8
Rename `TimeLimitReached` -> `StepLimitReached`
ecstatic-morse Mar 22, 2020
bd1df44
Add regression test for #70155.
Mar 22, 2020
cda81da
avoid unsafe code, use upcasting-trait instead (trick by oli)
RalfJung Mar 22, 2020
5e8b795
fix one more test
mark-i-m Mar 22, 2020
410385d
add macro to reduce boilerplate and keep readable messages
RalfJung Mar 23, 2020
e619b85
make sure we are checking the size of the right thing
RalfJung Mar 23, 2020
19e6935
Clean up E0452 explanation
GuillaumeGomez Mar 23, 2020
799b15e
Evaluate repeat expression lengths as late as possible
oli-obk Mar 14, 2020
fa5a15c
Document most methods on `ty::Const`
oli-obk Mar 14, 2020
3f89c38
Inline `const_param_def_id` at its only use site
oli-obk Mar 14, 2020
770be24
Use `DefId`s to identify anon consts when converting from HIR to ty::…
oli-obk Mar 17, 2020
c3b9881
Remove `ReClosureBound`
matthewjasper Mar 11, 2020
f080f94
Add const generics test for all range types.
Mar 23, 2020
9bcd9fe
Address review comments
oli-obk Mar 23, 2020
9fdde0a
Merge tests.
Mar 23, 2020
124ab20
Limit `from_anon_const` to `AnonConst`s.
oli-obk Mar 23, 2020
e75158d
Account for bad placeholder types in where clauses
estebank Mar 23, 2020
5aa15bf
Remove leftover mentions of `from_anon_const`
oli-obk Mar 23, 2020
4f513b5
Split out some impls from rustc::mir into a separate submodule
oli-obk Mar 23, 2020
a7e2641
Move dep_graph to new crate librustc_query_system.
cjgillot Dec 31, 2019
6624dc4
Make librustc_query_system compile.
cjgillot Mar 18, 2020
db7bd5f
Fallout in other crates.
cjgillot Mar 18, 2020
2326ae3
Merge ensure_node_can_be_forced into force_from_dep_node.
cjgillot Mar 20, 2020
3a8bb20
Remove assert_ignored and with_ignore_deps.
cjgillot Mar 20, 2020
d08cc0b
Put extract_def_id back on DepNode.
cjgillot Mar 21, 2020
e0f7b89
Address review.
cjgillot Mar 22, 2020
9f4c888
Fully qualify the path to DepKind.
cjgillot Mar 22, 2020
0f918cb
Move import.
cjgillot Mar 23, 2020
9b1893f
Run rustfmt
oli-obk Mar 23, 2020
9da25d9
Rollup merge of #67761 - cjgillot:split_graph, r=Zoxc
Centril Mar 23, 2020
ee90948
Rollup merge of #69740 - mark-i-m:describe-it-3, r=eddyb
Centril Mar 23, 2020
a73ed5a
Rollup merge of #69981 - oli-obk:const_blocks, r=eddyb
Centril Mar 23, 2020
72c99f2
Rollup merge of #70087 - ecstatic-morse:remove-const-eval-loop-detect…
Centril Mar 23, 2020
7a47df8
Rollup merge of #70242 - DeeDeeG:improve-e0308, r=Dylan-DPC
Centril Mar 23, 2020
ab2817b
Rollup merge of #70264 - tirr-c:issue-69789-mut-suggestion, r=estebank
Centril Mar 23, 2020
3184506
Rollup merge of #70267 - RalfJung:const-prop-unsup, r=oli-obk,wesleyw…
Centril Mar 23, 2020
6c58e01
Rollup merge of #70277 - matthewjasper:remove-closurebound, r=nikomat…
Centril Mar 23, 2020
7cdab7f
Rollup merge of #70283 - CDirkx:regression-test-70155, r=oli-obk
Centril Mar 23, 2020
54db0cf
Rollup merge of #70294 - estebank:bad-placeholder-in-where, r=Centril
Centril Mar 23, 2020
3b8872d
Rollup merge of #70309 - GuillaumeGomez:cleanup-e0452, r=Dylan-DPC
Centril Mar 23, 2020
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
Inline const_param_def_id at its only use site
  • Loading branch information
oli-obk committed Mar 23, 2020
commit 3f89c38bc0231f08e0eee6fa9942e7c71b5544f3
62 changes: 29 additions & 33 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2401,26 +2401,6 @@ pub struct Const<'tcx> {
#[cfg(target_arch = "x86_64")]
static_assert_size!(Const<'_>, 48);

/// Returns the `DefId` of the constant parameter that the provided expression is a path to.
fn const_param_def_id(expr: &hir::Expr<'_>) -> Option<DefId> {
// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
// currently have to be wrapped in curly brackets, so it's necessary to special-case.
let expr = match &expr.kind {
hir::ExprKind::Block(block, _) if block.stmts.is_empty() && block.expr.is_some() => {
block.expr.as_ref().unwrap()
}
_ => expr,
};

match &expr.kind {
hir::ExprKind::Path(hir::QPath::Resolved(_, path)) => match path.res {
hir::def::Res::Def(hir::def::DefKind::ConstParam, did) => Some(did),
_ => None,
},
_ => None,
}
}

impl<'tcx> Const<'tcx> {
/// Literals and const generic parameters are eagerly converted to a constant, everything else
/// becomes `Unevaluated`.
Expand Down Expand Up @@ -2456,20 +2436,36 @@ impl<'tcx> Const<'tcx> {
}
}

let kind = if let Some(def_id) = const_param_def_id(expr) {
// Find the name and index of the const parameter by indexing the generics of the
// parent item and construct a `ParamConst`.
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item_id = tcx.hir().get_parent_node(hir_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(hir_id)];
let name = tcx.hir().name(hir_id);
ty::ConstKind::Param(ty::ParamConst::new(index, name))
} else {
ty::ConstKind::Unevaluated(def_id, InternalSubsts::identity_for_item(tcx, def_id), None)
// Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
// currently have to be wrapped in curly brackets, so it's necessary to special-case.
let expr = match &expr.kind {
hir::ExprKind::Block(block, _) if block.stmts.is_empty() && block.expr.is_some() => {
block.expr.as_ref().unwrap()
}
_ => expr,
};
tcx.mk_const(ty::Const { val: kind, ty })

use hir::{def::DefKind::ConstParam, def::Res, ExprKind, Path, QPath};
let val = match expr.kind {
ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => {
// Find the name and index of the const parameter by indexing the generics of
// the parent item and construct a `ParamConst`.
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let item_id = tcx.hir().get_parent_node(hir_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(hir_id)];
let name = tcx.hir().name(hir_id);
ty::ConstKind::Param(ty::ParamConst::new(index, name))
}
_ => ty::ConstKind::Unevaluated(
def_id,
InternalSubsts::identity_for_item(tcx, def_id),
None,
),
};

tcx.mk_const(ty::Const { val, ty })
}

#[inline]
Expand Down