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 14 pull requests #91650

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
951dad6
Update certificates in some Ubuntu 16 images.
ehuss Nov 3, 2021
b38a540
Print a suggestion when comparing references to primitive types in co…
FabianWolff Nov 26, 2021
49aa5ba
Emphasise that an OsStr[ing] is not necessarily a platform string
ChrisDenton Dec 2, 2021
74437e4
Do not add `;` to expected tokens list when it's wrong
notriddle Dec 4, 2021
70855b2
Add spin_loop hint for RISC-V architecture
luojia65 Dec 5, 2021
6afbfca
Remove unnecessary FIXME (answered by Oli)
ecstatic-morse Dec 5, 2021
2a95958
Evaluate inline const pat early and report error if too generic
nbdd0121 Dec 5, 2021
f04b8f2
Make treatment of generator drop shims explicit
ecstatic-morse Dec 6, 2021
6199592
Add better comments for FnParseMode
notriddle Dec 6, 2021
6611567
Expect extern fn with no body when parsing
notriddle 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
4dd3f4e
Add missing whitespace before disabled HTML attribute
GuillaumeGomez Dec 7, 2021
9b6c510
Future compatibility warning on cfg_attr on crate_type and crate_name
bjorn3 Apr 1, 2021
a79b702
Remove unneeded access to pretty printer's `s` field in favor of deref
dtolnay Dec 5, 2021
db5a2ae
Define c_char using cfg_if rather than repeating 40-line cfg
dtolnay Dec 7, 2021
0a84930
Lock x.py build state
worldeva Aug 24, 2021
a124924
Remove `in_band_lifetimes` from `rustc_mir_transform`
scottmcm Dec 6, 2021
0f12afd
Rollup merge of #83744 - bjorn3:deprecate_cfg_attr_crate_type_name, r…
matthiaskrgr Dec 8, 2021
7379ca9
Rollup merge of #88310 - worldeva:bootstrap-locking, r=Mark-Simulacrum
matthiaskrgr Dec 8, 2021
da9f1ee
Rollup merge of #90550 - ehuss:update-ca, r=Mark-Simulacrum
matthiaskrgr Dec 8, 2021
9bc499e
Rollup merge of #90709 - estebank:erase-known-type-params, r=nagisa
matthiaskrgr Dec 8, 2021
ad29287
Rollup merge of #91272 - FabianWolff:issue-90870-const-fn-eq, r=wesle…
matthiaskrgr Dec 8, 2021
2d75df1
Rollup merge of #91467 - ChrisDenton:confusing-os-string, r=Mark-Simu…
matthiaskrgr Dec 8, 2021
0e8c1b8
Rollup merge of #91531 - notriddle:notriddle/issue-87647-expected-sem…
matthiaskrgr Dec 8, 2021
9e39487
Rollup merge of #91548 - luojia65:hint-spin-loop-riscv, r=Amanieu
matthiaskrgr Dec 8, 2021
01bd578
Rollup merge of #91570 - nbdd0121:const_typeck, r=oli-obk
matthiaskrgr Dec 8, 2021
cafbdc3
Rollup merge of #91571 - dtolnay:printerderef, r=Mark-Simulacrum
matthiaskrgr Dec 8, 2021
bd75333
Rollup merge of #91577 - ecstatic-morse:mir-pass-manager-cleanup, r=o…
matthiaskrgr Dec 8, 2021
60cd4c7
Rollup merge of #91630 - GuillaumeGomez:missing-whitespace, r=notriddle
matthiaskrgr Dec 8, 2021
a300c2e
Rollup merge of #91638 - scottmcm:less-inband-2-of-28, r=petrochenkov
matthiaskrgr Dec 8, 2021
46010eb
Rollup merge of #91641 - dtolnay:cchar-if, r=Mark-Simulacrum
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
330 changes: 165 additions & 165 deletions compiler/rustc_ast_pretty/src/pprust/state.rs

Large diffs are not rendered by default.

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 @@ -801,7 +801,7 @@ impl Visitor<'tcx> for Checker<'mir, '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);
self.check_op(ops::FnCallNonConst(Some((callee, substs))));
return;
}

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

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

if !nonconst_call_permission {
self.check_op(ops::FnCallNonConst);
self.check_op(ops::FnCallNonConst(None));
return;
}
}
Expand Down
70 changes: 63 additions & 7 deletions compiler/rustc_const_eval/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
//! Concrete error types for all operations which may be invalid in a certain const context.

use rustc_errors::{struct_span_err, DiagnosticBuilder};
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::mir;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::{mir, ty::AssocKind};
use rustc_session::parse::feature_err;
use rustc_span::symbol::sym;
use rustc_span::{Span, Symbol};
use rustc_span::{symbol::Ident, Span, Symbol};
use rustc_span::{BytePos, Pos};

use super::ConstCx;

Expand Down Expand Up @@ -72,17 +74,71 @@ impl NonConstOp for FnCallIndirect {

/// A function call where the callee is not marked as `const`.
#[derive(Debug)]
pub struct FnCallNonConst;
impl NonConstOp for FnCallNonConst {
pub struct FnCallNonConst<'tcx>(pub Option<(DefId, SubstsRef<'tcx>)>);
impl<'a> NonConstOp for FnCallNonConst<'a> {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
struct_span_err!(
let mut err = struct_span_err!(
ccx.tcx.sess,
span,
E0015,
"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,
);
}
}
}
}
_ => {}
}
}
}
}
}

err
}
}

Expand Down
19 changes: 18 additions & 1 deletion compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,24 @@ impl<'a> StripUnconfigured<'a> {
);
trees.push((bracket_group, Spacing::Alone));
let tokens = Some(LazyTokenStream::new(AttrAnnotatedTokenStream::new(trees)));
self.process_cfg_attr(attr::mk_attr_from_item(item, tokens, attr.style, span))
let attr = attr::mk_attr_from_item(item, tokens, attr.style, span);
if attr.has_name(sym::crate_type) {
self.sess.parse_sess.buffer_lint(
rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
attr.span,
ast::CRATE_NODE_ID,
"`crate_type` within an `#![cfg_attr] attribute is deprecated`",
);
}
if attr.has_name(sym::crate_name) {
self.sess.parse_sess.buffer_lint(
rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME,
attr.span,
ast::CRATE_NODE_ID,
"`crate_name` within an `#![cfg_attr] attribute is deprecated`",
);
}
self.process_cfg_attr(attr)
})
.collect()
}
Expand Down
Loading