Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5e97fc9
Make `NonNull::new` `const`
lilasta Jan 23, 2022
1ab97db
add note suggesting that predicate is satisfied but is not const
compiler-errors Jan 27, 2022
c6de4d5
drive-by: use is_const and is_const_if_const
compiler-errors Jan 27, 2022
c6f6e3e
do not register infer var for GAT projection in opaque
compiler-errors Jan 27, 2022
da0d506
kmc-solid: Implement `FileDesc::duplicate`
kawadakk Jan 28, 2022
8454972
More informative error message for E0015
fee1-dead Nov 3, 2021
2b0bbfd
Improve error messages even more
fee1-dead Dec 9, 2021
c3d3f80
bless you
fee1-dead Dec 9, 2021
f9f7d13
Rebased and improved errors
fee1-dead Dec 29, 2021
ba8fb09
Handle Fn family trait call errror
fee1-dead Dec 29, 2021
ca1fbc1
Adapt new change
fee1-dead Jan 28, 2022
cdd0873
Add a test case for using NonNull::new in const context
lilasta Jan 28, 2022
2188c55
Move unstable is_{arch}_feature_detected! macros to std::arch
Amanieu Jan 28, 2022
7a01e66
Report the selection error when possible
fee1-dead Jan 28, 2022
9a814b8
Update stdarch submodule
Amanieu Jan 28, 2022
9d65342
fix nit
lcnr Jan 28, 2022
f9e0eb3
remove unused `jemallocator` crate
lqd Jan 28, 2022
5b2747a
Add test for old ICE
BGR360 Dec 27, 2021
2819d90
Add test for old ICE in #91594
BGR360 Dec 27, 2021
3f849a8
Add test for old ICE in #89066
BGR360 Dec 27, 2021
abac45a
Rollup merge of #90532 - fee1-dead:improve-const-fn-err-msg, r=oli-obk
matthiaskrgr Jan 29, 2022
ee9307d
Rollup merge of #92312 - BGR360:needs-test, r=Mark-Simulacrum
matthiaskrgr Jan 29, 2022
5cbe671
Rollup merge of #93236 - woppopo:const_nonnull_new, r=oli-obk
matthiaskrgr Jan 29, 2022
93e1c55
Rollup merge of #93358 - compiler-errors:is-not-const, r=fee1-dead
matthiaskrgr Jan 29, 2022
8574cdd
Rollup merge of #93362 - compiler-errors:ice-gat-in-rpit, r=oli-obk
matthiaskrgr Jan 29, 2022
38c9798
Rollup merge of #93410 - solid-rs:feat-kmc-solid-net-dup, r=dtolnay
matthiaskrgr Jan 29, 2022
0bde009
Rollup merge of #93414 - Amanieu:std_arch_detect, r=m-ou-se
matthiaskrgr Jan 29, 2022
c6c4894
Rollup merge of #93424 - lcnr:nit, r=spastorino
matthiaskrgr Jan 29, 2022
bc2bf3e
Rollup merge of #93431 - lqd:remove-jemallocator, r=Mark-Simulacrum
matthiaskrgr Jan 29, 2022
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
More informative error message for E0015
  • Loading branch information
fee1-dead committed Jan 28, 2022
commit 8454972d3371dce882222bcd8895c6605dcb6ef5
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/src/transform/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
if let Some(trait_id) = tcx.trait_of_item(callee) {
trace!("attempting to call a trait method");
if !self.tcx.features().const_trait_impl {
self.check_op(ops::FnCallNonConst(Some((callee, substs))));
self.check_op(ops::FnCallNonConst(callee, substs));
return;
}

Expand Down Expand Up @@ -854,7 +854,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
}

if !nonconst_call_permission {
self.check_op(ops::FnCallNonConst(None));
self.check_op(ops::FnCallNonConst(callee, substs));
return;
}
}
Expand Down Expand Up @@ -923,7 +923,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
}

if !nonconst_call_permission {
self.check_op(ops::FnCallNonConst(None));
self.check_op(ops::FnCallNonConst(callee, substs));
return;
}
}
Expand Down
94 changes: 48 additions & 46 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,65 +74,67 @@ impl NonConstOp for FnCallIndirect {

/// A function call where the callee is not marked as `const`.
#[derive(Debug)]
pub struct FnCallNonConst<'tcx>(pub Option<(DefId, SubstsRef<'tcx>)>);
pub struct FnCallNonConst<'tcx>(pub DefId, pub SubstsRef<'tcx>);
impl<'a> NonConstOp for FnCallNonConst<'a> {
fn build_error<'tcx>(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
let FnCallNonConst(def_id, substs) = *self;
let mut err = struct_span_err!(
ccx.tcx.sess,
span,
E0015,
"cannot call non-const fn `{}` in {}s",
ccx.tcx.def_path_str_with_substs(def_id, substs),
ccx.const_kind()
);
err.note(&format!(
"calls in {}s are limited to constant functions, \
tuple structs and tuple variants",
ccx.const_kind(),
);

if let FnCallNonConst(Some((callee, substs))) = *self {
if let Some(trait_def_id) = ccx.tcx.lang_items().eq_trait() {
if let Some(eq_item) = ccx.tcx.associated_items(trait_def_id).find_by_name_and_kind(
ccx.tcx,
Ident::with_dummy_span(sym::eq),
AssocKind::Fn,
trait_def_id,
) {
if callee == eq_item.def_id && substs.len() == 2 {
match (substs[0].unpack(), substs[1].unpack()) {
(GenericArgKind::Type(self_ty), GenericArgKind::Type(rhs_ty))
if self_ty == rhs_ty
&& self_ty.is_ref()
&& self_ty.peel_refs().is_primitive() =>
{
let mut num_refs = 0;
let mut tmp_ty = self_ty;
while let rustc_middle::ty::Ref(_, inner_ty, _) = tmp_ty.kind() {
num_refs += 1;
tmp_ty = inner_ty;
}
let deref = "*".repeat(num_refs);

if let Ok(call_str) =
ccx.tcx.sess.source_map().span_to_snippet(span)
{
if let Some(eq_idx) = call_str.find("==") {
if let Some(rhs_idx) = call_str[(eq_idx + 2)..]
.find(|c: char| !c.is_whitespace())
{
let rhs_pos = span.lo()
+ BytePos::from_usize(eq_idx + 2 + rhs_idx);
let rhs_span = span.with_lo(rhs_pos).with_hi(rhs_pos);
err.multipart_suggestion(
"consider dereferencing here",
vec![
(span.shrink_to_lo(), deref.clone()),
(rhs_span, deref),
],
Applicability::MachineApplicable,
);
}
));

if let Some(trait_def_id) = ccx.tcx.lang_items().eq_trait() {
if let Some(eq_item) = ccx.tcx.associated_items(trait_def_id).find_by_name_and_kind(
ccx.tcx,
Ident::with_dummy_span(sym::eq),
AssocKind::Fn,
trait_def_id,
) {
if callee == eq_item.def_id && substs.len() == 2 {
match (substs[0].unpack(), substs[1].unpack()) {
(GenericArgKind::Type(self_ty), GenericArgKind::Type(rhs_ty))
if self_ty == rhs_ty
&& self_ty.is_ref()
&& self_ty.peel_refs().is_primitive() =>
{
let mut num_refs = 0;
let mut tmp_ty = self_ty;
while let rustc_middle::ty::Ref(_, inner_ty, _) = tmp_ty.kind() {
num_refs += 1;
tmp_ty = inner_ty;
}
let deref = "*".repeat(num_refs);

if let Ok(call_str) = ccx.tcx.sess.source_map().span_to_snippet(span) {
if let Some(eq_idx) = call_str.find("==") {
if let Some(rhs_idx) =
call_str[(eq_idx + 2)..].find(|c: char| !c.is_whitespace())
{
let rhs_pos =
span.lo() + BytePos::from_usize(eq_idx + 2 + rhs_idx);
let rhs_span = span.with_lo(rhs_pos).with_hi(rhs_pos);
err.multipart_suggestion(
"consider dereferencing here",
vec![
(span.shrink_to_lo(), deref.clone()),
(rhs_span, deref),
],
Applicability::MachineApplicable,
);
}
}
}
_ => {}
}
_ => {}
}
}
}
Expand Down