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 8 pull requests #94533

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
47aaf79
Add documentation about `BorrowedFd::to_owned`.
sunfishcode Jan 26, 2022
ca42a1b
Update the documentation for `{As,Into,From}Raw{Fd,Handle,Socket}`.
sunfishcode Feb 1, 2022
713bb19
Add missing `pub` keywords.
sunfishcode Feb 1, 2022
8516895
Fix two copy+pastos.
sunfishcode Feb 1, 2022
6ef7ee3
Fix unresolved doc links.
sunfishcode Feb 1, 2022
89544e9
Fix errors.
sunfishcode Feb 1, 2022
656d2a3
Use `From`/`Into` rather than the traits they replaced.
sunfishcode Feb 1, 2022
f88fb2a
x.py fmt
sunfishcode Feb 1, 2022
ba6050f
Remove the documentation comment for `OwnedSocket::from_raw_socket`.
sunfishcode Feb 3, 2022
4c4e430
Rename `BorrowedFd::borrow_raw_fd` to `BorrowedFd::borrow_raw`.
sunfishcode Feb 4, 2022
7d603dc
x.py fmt
sunfishcode Feb 4, 2022
4c7fb9e
Add helper function to suggest multiple constraints
WaffleLapkin Feb 25, 2022
400d343
Suggest adding `Copy` bound when Adt is moved out
WaffleLapkin Feb 25, 2022
879efa8
Add a test for Adt copy suggestions
WaffleLapkin Feb 25, 2022
f0a16b8
Use rustfix in copy suggestion test
WaffleLapkin Mar 1, 2022
f287866
Demote Windows XP to no_std only
RandomInsano Mar 1, 2022
6739299
Miri/CTFE: properly treat overflow in (signed) division/rem as UB
RalfJung Mar 2, 2022
3768f0b
update char signess for openbsd
semarie Mar 2, 2022
fa8e1be
merge the char signess list of archs with freebsd as it is the same
semarie Mar 2, 2022
2d854f9
Remove num_cpus dependency from bootstrap, build-manifest and rustc_s…
bjorn3 Mar 2, 2022
e7a6375
Rollup merge of #92061 - semarie:openbsd-archs, r=joshtriplett
matthiaskrgr Mar 2, 2022
3fec69a
Rollup merge of #93354 - sunfishcode:sunfishcode/document-borrowedfd-…
matthiaskrgr Mar 2, 2022
e66c8de
Rollup merge of #93562 - sunfishcode:sunfishcode/io-docs, r=joshtriplett
matthiaskrgr Mar 2, 2022
212e878
Rollup merge of #93663 - sunfishcode:sunfishcode/as-raw-name, r=josht…
matthiaskrgr Mar 2, 2022
0c40ca0
Rollup merge of #94375 - WaffleLapkin:copy-suggestion, r=estebank
matthiaskrgr Mar 2, 2022
a41efcc
Rollup merge of #94499 - RandomInsano:patch-1, r=Dylan-DPC
matthiaskrgr Mar 2, 2022
1c7348e
Rollup merge of #94512 - RalfJung:sdiv-ub, r=oli-obk
matthiaskrgr Mar 2, 2022
c4e9c10
Rollup merge of #94524 - bjorn3:remove_num_cpus, r=Mark-Simulacrum
matthiaskrgr Mar 2, 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
3 changes: 0 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ dependencies = [
"getopts",
"ignore",
"libc",
"num_cpus",
"once_cell",
"opener",
"pretty_assertions",
Expand Down Expand Up @@ -249,7 +248,6 @@ dependencies = [
"anyhow",
"flate2",
"hex 0.4.2",
"num_cpus",
"rayon",
"serde",
"serde_json",
Expand Down Expand Up @@ -4241,7 +4239,6 @@ name = "rustc_session"
version = "0.0.0"
dependencies = [
"getopts",
"num_cpus",
"rustc_ast",
"rustc_data_structures",
"rustc_errors",
Expand Down
63 changes: 62 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::{AsyncGeneratorKind, GeneratorKind};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::ObligationCause;
use rustc_middle::mir::{
self, AggregateKind, BindingForm, BorrowKind, ClearCrossCrate, ConstraintCategory,
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
};
use rustc_middle::ty::{self, suggest_constraining_type_param, Ty};
use rustc_middle::ty::{
self, suggest_constraining_type_param, 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, DUMMY_SP};
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::TraitEngineExt as _;

use crate::borrow_set::TwoPhaseActivation;
use crate::borrowck_errors;
Expand Down Expand Up @@ -423,7 +428,63 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
None,
);
}
} 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, ty, copy_did, cause);
let errors = fulfill_cx.select_where_possible(&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()
});

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)
}),
);
}
}
}

let span = if let Some(local) = place.as_local() {
let decl = &self.body.local_decls[local];
Some(decl.source_info.span)
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,15 +500,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`.
// First, check x % y != 0 (or if that computation overflows).
let (res, overflow, _ty) = self.overflowing_binary_op(BinOp::Rem, &a, &b)?;
if overflow || res.assert_bits(a.layout.size) != 0 {
// Then, check if `b` is -1, which is the "MIN / -1" case.
let minus1 = Scalar::from_int(-1, dest.layout.size);
let b_scalar = b.to_scalar().unwrap();
if b_scalar == minus1 {
throw_ub_format!("exact_div: result of dividing MIN by -1 cannot be represented")
} else {
throw_ub_format!("exact_div: {} cannot be divided by {} without remainder", a, b,)
}
assert!(!overflow); // All overflow is UB, so this should never return on overflow.
if res.assert_bits(a.layout.size) != 0 {
throw_ub_format!("exact_div: {} cannot be divided by {} without remainder", a, b)
}
// `Rem` says this is all right, so we can let `Div` do its job.
self.binop_ignore_overflow(BinOp::Div, &a, &b, dest)
Expand Down
18 changes: 11 additions & 7 deletions compiler/rustc_const_eval/src/interpret/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
_ => None,
};
if let Some(op) = op {
let l = self.sign_extend(l, left_layout) as i128;
let r = self.sign_extend(r, right_layout) as i128;
// We need a special check for overflowing remainder:
// "int_min % -1" overflows and returns 0, but after casting things to a larger int
// type it does *not* overflow nor give an unrepresentable result!
if bin_op == Rem {
if r == -1 && l == (1 << (size.bits() - 1)) {
return Ok((Scalar::from_int(0, size), true, left_layout.ty));

// We need a special check for overflowing Rem and Div since they are *UB*
// on overflow, which can happen with "int_min $OP -1".
if matches!(bin_op, Rem | Div) {
if l == size.signed_int_min() && r == -1 {
if bin_op == Rem {
throw_ub!(RemainderOverflow)
} else {
throw_ub!(DivisionOverflow)
}
}
}
let l = self.sign_extend(l, left_layout) as i128;

let (result, oflo) = op(l, r);
// This may be out-of-bounds for the result type, so we have to truncate ourselves.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#![feature(nonzero_ops)]
#![feature(unwrap_infallible)]
#![feature(decl_macro)]
#![feature(drain_filter)]
#![recursion_limit = "512"]
#![allow(rustc::potential_query_instability)]

Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ pub enum UndefinedBehaviorInfo<'tcx> {
DivisionByZero,
/// Something was "remainded" by 0 (x % 0).
RemainderByZero,
/// Signed division overflowed (INT_MIN / -1).
DivisionOverflow,
/// Signed remainder overflowed (INT_MIN % -1).
RemainderOverflow,
/// Overflowing inbounds pointer arithmetic.
PointerArithOverflow,
/// Invalid metadata in a wide pointer (using `str` to avoid allocations).
Expand Down Expand Up @@ -310,6 +314,8 @@ impl fmt::Display for UndefinedBehaviorInfo<'_> {
}
DivisionByZero => write!(f, "dividing by zero"),
RemainderByZero => write!(f, "calculating the remainder with a divisor of zero"),
DivisionOverflow => write!(f, "overflow in signed division (dividing MIN by -1)"),
RemainderOverflow => write!(f, "overflow in signed remainder (dividing MIN by -1)"),
PointerArithOverflow => write!(f, "overflowing in-bounds pointer arithmetic"),
InvalidMeta(msg) => write!(f, "invalid metadata in wide pointer: {}", msg),
InvalidVtableDropFn(sig) => write!(
Expand Down
Loading