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 10 pull requests #95056

Merged
merged 34 commits into from
Mar 18, 2022
Merged
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
3a13a72
Improve `unsafe` diagnostic
terrarier2111 Nov 17, 2021
60f5cad
try to fix issue 57017, but not quite there yet
nikomatsakis Feb 18, 2022
513a9c6
Move test to right place
eholk Feb 23, 2022
ac804f2
Trying to detect autorefs to avoid unnecessary borrowed temporaries
eholk Feb 23, 2022
87ad668
Distinguish borrows of copies from other borrows
eholk Feb 23, 2022
9f0f46f
Update clippy to new ExprUseVisitor delegate
eholk Feb 26, 2022
170b027
Add comments based on code review feedback
eholk Mar 2, 2022
74d0866
Remove redundant code from copy-suggestions
WaffleLapkin Mar 7, 2022
529fd2d
suggest adding `{ .. }` around a const function with arguments
TaKO8Ki Mar 8, 2022
527b1f3
initialize unclosed_delims field
TaKO8Ki Mar 9, 2022
a34015c
implement and use `diagnostic_snapshot`
TaKO8Ki Mar 9, 2022
3514741
remove an unnecessary comment
TaKO8Ki Mar 9, 2022
192acb4
take over unclosed_delims
TaKO8Ki Mar 9, 2022
3ded252
implement `SnapshotParser` struct
TaKO8Ki Mar 9, 2022
2db8236
add doc comments
TaKO8Ki Mar 10, 2022
9a65322
replace `self.clone()` with `self.create_snapshot_for_diagnostic()`
TaKO8Ki Mar 10, 2022
12d8ca1
Use projections rather than is_autoref
eholk Mar 11, 2022
2fcd542
Remove is_autoref parameter
eholk Mar 11, 2022
78567df
Stabilize ADX target feature
tarcieri Feb 7, 2022
e4f1179
Add deprecated_safe feature gate and attribute, cc #94978
User1785604260 Mar 15, 2022
f1cf544
Update issue-92111.rs
fee1-dead Mar 16, 2022
01dbfb3
resolve the conflict in compiler/rustc_session/src/parse.rs
codehorseman Mar 16, 2022
243e2a6
debuginfo: Fix ICE when generating name for type that produces a layo…
michaelwoerister Mar 16, 2022
bb8d430
rustc_error: make ErrorReported impossible to construct
mark-i-m Jan 23, 2022
c8133f6
Rollup merge of #91133 - terrarier2111:unsafe-diagnostic, r=jackh726
Dylan-DPC Mar 17, 2022
7e1415e
Rollup merge of #93222 - mark-i-m:errorreported, r=oli-obk
Dylan-DPC Mar 17, 2022
07121c8
Rollup merge of #93745 - tarcieri:stabilize-adx, r=cjgillot
Dylan-DPC Mar 17, 2022
8499a8b
Rollup merge of #94309 - eholk:issue-57017, r=tmandry
Dylan-DPC Mar 17, 2022
a8956e6
Rollup merge of #94698 - WaffleLapkin:simplify-copy-suggestions, r=es…
Dylan-DPC Mar 17, 2022
5eb3433
Rollup merge of #94731 - TaKO8Ki:const-generic-expr-recovery, r=david…
Dylan-DPC Mar 17, 2022
270a41c
Rollup merge of #94960 - codehorseman:master, r=oli-obk
Dylan-DPC Mar 17, 2022
0c73b25
Rollup merge of #94982 - skippy10110:deprecated_safe, r=Dylan-DPC
Dylan-DPC Mar 17, 2022
e55400c
Rollup merge of #94997 - michaelwoerister:fix-enum-type-name-layout-e…
Dylan-DPC Mar 17, 2022
4493826
Rollup merge of #95000 - fee1-dead:fee1-dead-patch-1, r=Mark-Simulacrum
Dylan-DPC Mar 17, 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
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(super) struct ItemLowerer<'a, 'lowering, 'hir> {
}

/// When we have a ty alias we *may* have two where clauses. To give the best diagnostics, we set the span
/// to the where clause that is prefered, if it exists. Otherwise, it sets the span to the other where
/// to the where clause that is preferred, if it exists. Otherwise, it sets the span to the other where
/// clause if it exists.
fn add_ty_alias_where_clause(
generics: &mut ast::Generics,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
sess.diagnostic().delay_span_bug(
span,
"unexpected delimiter in key-value attribute's value",
)
);
}
unwrap_single_token(sess, tokens, span)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl<'a> AstValidator<'a> {
attr.span,
"allow, cfg, cfg_attr, deny, \
forbid, and warn are the only allowed built-in attributes in function parameters",
)
);
}
});
}
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,12 @@ impl<'a> PostExpansionVisitor<'a> {
"wasm ABI is experimental and subject to change"
);
}
abi => self
.sess
.parse_sess
.span_diagnostic
.delay_span_bug(span, &format!("unrecognized ABI not caught in lowering: {}", abi)),
abi => {
self.sess.parse_sess.span_diagnostic.delay_span_bug(
span,
&format!("unrecognized ABI not caught in lowering: {}", abi),
);
}
}
}

Expand Down
135 changes: 55 additions & 80 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ use rustc_middle::mir::{
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
};
use rustc_middle::ty::{
self, suggest_constraining_type_param, suggest_constraining_type_params, PredicateKind, Ty,
};
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
use rustc_span::symbol::sym;
use rustc_span::{BytePos, MultiSpan, Span};
Expand Down Expand Up @@ -285,86 +283,63 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Some(ref name) => format!("`{}`", name),
None => "value".to_owned(),
};
if let ty::Param(param_ty) = ty.kind() {
let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id());
let param = generics.type_param(&param_ty, tcx);
if let Some(generics) = tcx
.typeck_root_def_id(self.mir_def_id().to_def_id())
.as_local()
.and_then(|def_id| tcx.hir().get_generics(def_id))
{
suggest_constraining_type_param(
tcx,
generics,
&mut err,
param.name.as_str(),
"Copy",
None,

// Try to find predicates on *generic params* that would allow copying `ty`
let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id());
if let Some(hir_generics) = tcx
.typeck_root_def_id(self.mir_def_id().to_def_id())
.as_local()
.and_then(|def_id| tcx.hir().get_generics(def_id))
{
let predicates: Result<Vec<_>, _> = tcx.infer_ctxt().enter(|infcx| {
let mut fulfill_cx =
<dyn rustc_infer::traits::TraitEngine<'_>>::new(infcx.tcx);

let copy_did = infcx.tcx.lang_items().copy_trait().unwrap();
let cause = ObligationCause::new(
span,
self.mir_hir_id(),
rustc_infer::traits::ObligationCauseCode::MiscObligation,
);
}
} else {
// Try to find predicates on *generic params* that would allow copying `ty`

let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id());
if let Some(hir_generics) = tcx
.typeck_root_def_id(self.mir_def_id().to_def_id())
.as_local()
.and_then(|def_id| tcx.hir().get_generics(def_id))
{
let predicates: Result<Vec<_>, _> = tcx.infer_ctxt().enter(|infcx| {
let mut fulfill_cx =
<dyn rustc_infer::traits::TraitEngine<'_>>::new(infcx.tcx);

let copy_did = infcx.tcx.lang_items().copy_trait().unwrap();
let cause = ObligationCause::new(
span,
self.mir_hir_id(),
rustc_infer::traits::ObligationCauseCode::MiscObligation,
);
fulfill_cx.register_bound(
&infcx,
self.param_env,
// Erase any region vids from the type, which may not be resolved
infcx.tcx.erase_regions(ty),
copy_did,
cause,
);
// Select all, including ambiguous predicates
let errors = fulfill_cx.select_all_or_error(&infcx);

// Only emit suggestion if all required predicates are on generic
errors
.into_iter()
.map(|err| match err.obligation.predicate.kind().skip_binder() {
PredicateKind::Trait(predicate) => {
match predicate.self_ty().kind() {
ty::Param(param_ty) => Ok((
generics.type_param(param_ty, tcx),
predicate
.trait_ref
.print_only_trait_path()
.to_string(),
)),
_ => Err(()),
}
fulfill_cx.register_bound(
&infcx,
self.param_env,
// Erase any region vids from the type, which may not be resolved
infcx.tcx.erase_regions(ty),
copy_did,
cause,
);
// Select all, including ambiguous predicates
let errors = fulfill_cx.select_all_or_error(&infcx);

// Only emit suggestion if all required predicates are on generic
errors
.into_iter()
.map(|err| match err.obligation.predicate.kind().skip_binder() {
PredicateKind::Trait(predicate) => {
match predicate.self_ty().kind() {
ty::Param(param_ty) => Ok((
generics.type_param(param_ty, tcx),
predicate.trait_ref.print_only_trait_path().to_string(),
)),
_ => Err(()),
}
_ => Err(()),
})
.collect()
});
}
_ => Err(()),
})
.collect()
});

if let Ok(predicates) = predicates {
suggest_constraining_type_params(
tcx,
hir_generics,
&mut err,
predicates.iter().map(|(param, constraint)| {
(param.name.as_str(), &**constraint, None)
}),
);
}
if let Ok(predicates) = predicates {
suggest_constraining_type_params(
tcx,
hir_generics,
&mut err,
predicates.iter().map(|(param, constraint)| {
(param.name.as_str(), &**constraint, None)
}),
);
}
}

Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn do_mir_borrowck<'a, 'tcx>(

// Gather the upvars of a closure, if any.
let tables = tcx.typeck_opt_const_arg(def);
if let Some(ErrorGuaranteed) = tables.tainted_by_errors {
if let Some(ErrorGuaranteed { .. }) = tables.tainted_by_errors {
infcx.set_tainted_by_errors();
errors.set_tainted_by_errors();
}
Expand Down Expand Up @@ -2274,6 +2274,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}

mod error {
use rustc_errors::ErrorGuaranteed;

use super::*;

pub struct BorrowckErrors<'tcx> {
Expand Down Expand Up @@ -2311,7 +2313,7 @@ mod error {
// FIXME(eddyb) this is a suboptimal API because `tainted_by_errors` is
// set before any emission actually happens (weakening the guarantee).
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
self.tainted_by_errors = Some(ErrorGuaranteed {});
self.tainted_by_errors = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
t.buffer(&mut self.buffered);
}

Expand All @@ -2320,7 +2322,7 @@ mod error {
}

pub fn set_tainted_by_errors(&mut self) {
self.tainted_by_errors = Some(ErrorGuaranteed {});
self.tainted_by_errors = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted());
}
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Handling of `static`s, `const`s and promoted allocations

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::ErrorGuaranteed;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::interpret::{
read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
Expand Down Expand Up @@ -54,7 +53,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool {
{
all_constants_ok = false;
match err {
ErrorHandled::Reported(ErrorGuaranteed) | ErrorHandled::Linted => {
ErrorHandled::Reported(_) | ErrorHandled::Linted => {
fx.tcx.sess.span_err(constant.span, "erroneous constant encountered");
}
ErrorHandled::TooGeneric => {
Expand Down
25 changes: 23 additions & 2 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,30 @@ fn push_debuginfo_type_name<'tcx>(
ty::Float(float_ty) => output.push_str(float_ty.name_str()),
ty::Foreign(def_id) => push_item_name(tcx, def_id, qualified, output),
ty::Adt(def, substs) => {
let ty_and_layout = tcx.layout_of(ParamEnv::reveal_all().and(t)).expect("layout error");
// `layout_for_cpp_like_fallback` will be `Some` if we want to use the fallback encoding.
let layout_for_cpp_like_fallback = if cpp_like_debuginfo && def.is_enum() {
match tcx.layout_of(ParamEnv::reveal_all().and(t)) {
Ok(layout) => {
if !wants_c_like_enum_debuginfo(layout) {
Some(layout)
} else {
// This is a C-like enum so we don't want to use the fallback encoding
// for the name.
None
}
}
Err(e) => {
// Computing the layout can still fail here, e.g. if the target architecture
// cannot represent the type. See https://github.com/rust-lang/rust/issues/94961.
tcx.sess.fatal(&format!("{}", e));
}
}
} else {
// We are not emitting cpp-like debuginfo or this isn't even an enum.
None
};

if def.is_enum() && cpp_like_debuginfo && !wants_c_like_enum_debuginfo(ty_and_layout) {
if let Some(ty_and_layout) = layout_for_cpp_like_fallback {
msvc_enum_fallback(
tcx,
ty_and_layout,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::traits::*;
use rustc_errors::ErrorGuaranteed;
use rustc_middle::mir;
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, TyAndLayout};
Expand Down Expand Up @@ -191,7 +190,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
all_consts_ok = false;
match err {
// errored or at least linted
ErrorHandled::Reported(ErrorGuaranteed) | ErrorHandled::Linted => {}
ErrorHandled::Reported(_) | ErrorHandled::Linted => {}
ErrorHandled::TooGeneric => {
span_bug!(const_.span, "codgen encountered polymorphic constant: {:?}", err)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const AARCH64_TIED_FEATURES: &[&[&str]] = &[
];

const X86_ALLOWED_FEATURES: &[(&str, Option<Symbol>)] = &[
("adx", Some(sym::adx_target_feature)),
("adx", None),
("aes", None),
("avx", None),
("avx2", None),
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::DefKind;
use rustc_middle::mir;
use rustc_middle::ty::{self, Ty};
Expand Down Expand Up @@ -247,11 +246,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
if ecx.tcx.is_ctfe_mir_available(def.did) {
Ok(ecx.tcx.mir_for_ctfe_opt_const_arg(def))
} else if ecx.tcx.def_kind(def.did) == DefKind::AssocConst {
ecx.tcx.sess.delay_span_bug(
let guar = ecx.tcx.sess.delay_span_bug(
rustc_span::DUMMY_SP,
"This is likely a const item that is missing from its impl",
);
throw_inval!(AlreadyReported(ErrorGuaranteed {}));
throw_inval!(AlreadyReported(guar));
} else {
let path = ecx.tcx.def_path_str(def.did);
Err(ConstEvalErrKind::NeedsRfc(format!("calling extern function `{}`", path))
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_const_eval/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,11 @@ pub fn intern_const_alloc_recursive<
} else if ecx.memory.dead_alloc_map.contains_key(&alloc_id) {
// Codegen does not like dangling pointers, and generally `tcx` assumes that
// all allocations referenced anywhere actually exist. So, make sure we error here.
ecx.tcx.sess.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
return Err(ErrorGuaranteed);
let reported = ecx
.tcx
.sess
.span_err(ecx.tcx.span, "encountered dangling pointer in final constant");
return Err(reported);
} else if ecx.tcx.get_global_alloc(alloc_id).is_none() {
// We have hit an `AllocId` that is neither in local or global memory and isn't
// marked as dangling by local memory. That should be impossible.
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
use std::convert::TryFrom;
use std::fmt::Write;

use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::Namespace;
use rustc_macros::HashStable;
use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt, TyAndLayout};
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Printer};
use rustc_middle::ty::{ConstInt, Ty};
use rustc_middle::ty::{ConstInt, DelaySpanBugEmitted, Ty};
use rustc_middle::{mir, ty};
use rustc_target::abi::{Abi, HasDataLayout, Size, TagEncoding};
use rustc_target::abi::{VariantIdx, Variants};
Expand Down Expand Up @@ -565,7 +564,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
match val.val() {
ty::ConstKind::Param(_) | ty::ConstKind::Bound(..) => throw_inval!(TooGeneric),
ty::ConstKind::Error(_) => throw_inval!(AlreadyReported(ErrorGuaranteed)),
ty::ConstKind::Error(DelaySpanBugEmitted { reported, .. }) => {
throw_inval!(AlreadyReported(reported))
}
ty::ConstKind::Unevaluated(uv) => {
let instance = self.resolve(uv.def, uv.substs)?;
Ok(self.eval_to_allocation(GlobalId { instance, promoted: uv.promoted })?.into())
Expand Down
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 @@ -259,7 +259,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
self.tcx.sess.diagnostic().emit_diagnostic(&error);
}
} else {
assert!(self.tcx.sess.has_errors());
assert!(self.tcx.sess.has_errors().is_some());
}
}

Expand Down Expand Up @@ -327,8 +327,8 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {

match op.importance() {
ops::DiagnosticImportance::Primary => {
self.error_emitted = Some(ErrorGuaranteed);
err.emit();
let reported = err.emit();
self.error_emitted = Some(reported);
}

ops::DiagnosticImportance::Secondary => err.buffer(&mut self.secondary_errors),
Expand Down
Loading