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 13 pull requests #89005

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
4e76c38
Fix ICE in `improper_ctypes_definitions` lint with all-ZST transparen…
FabianWolff Jul 27, 2021
ced597e
Add TcpListener::into_incoming and IntoIncoming
piegamesde Aug 25, 2021
3feddf7
Add `ConstraintCategory::Usage` for handling aggregate construction
Aaron1011 Sep 6, 2021
e1873ba
cleanup(rustc_trait_selection): remove vestigial code from rustc_on_u…
notriddle Sep 11, 2021
cbd7983
Improve error message for type mismatch in generator arguments
FabianWolff Sep 13, 2021
6b7f916
Document the closure arguments for `reduce`.
lefth Sep 14, 2021
349ac4f
Const Deref
fee1-dead Sep 12, 2021
9762116
Move object safety suggestions to the end of the error
estebank Sep 12, 2021
ef44452
chore(rustc_expand): fix typo in comment
notriddle Sep 15, 2021
cc7929b
docs(std): add docs for cof_from_cstr impls
notriddle Sep 15, 2021
09745a6
Update clobber_abi list to include k[1-7] regs
Sep 15, 2021
4e61d11
Update the backtrace crate
hargoniX Sep 15, 2021
4fd39dd
Make rustc_mir_dataflow::framework::graphviz and rustc_mir_transform:…
willcrichton Sep 15, 2021
47104a3
Allow call to get_body_with_borrowck_facts without -Z polonius
willcrichton Sep 15, 2021
26eb5bb
Add rustdoc version into the help popup
GuillaumeGomez Sep 15, 2021
dc7a66c
Rollup merge of #87529 - FabianWolff:issue-87496, r=nikomatsakis
GuillaumeGomez Sep 16, 2021
d7a656f
Rollup merge of #88339 - piegamesde:master, r=joshtriplett
GuillaumeGomez Sep 16, 2021
0dd5e22
Rollup merge of #88708 - Aaron1011:aggregate-usage, r=oli-obk
GuillaumeGomez Sep 16, 2021
581c34d
Rollup merge of #88875 - notriddle:notriddle/cleanup-unused-trait-sel…
GuillaumeGomez Sep 16, 2021
33f1fde
Rollup merge of #88887 - fee1-dead:const-deref, r=oli-obk
GuillaumeGomez Sep 16, 2021
21f0b13
Rollup merge of #88892 - estebank:trait-objects, r=petrochenkov
GuillaumeGomez Sep 16, 2021
c68fc7b
Rollup merge of #88911 - FabianWolff:issue-88653, r=petrochenkov
GuillaumeGomez Sep 16, 2021
757b316
Rollup merge of #88928 - lefth:master, r=Mark-Simulacrum
GuillaumeGomez Sep 16, 2021
aa75a6f
Rollup merge of #88964 - GuillaumeGomez:version-help, r=Nemo157
GuillaumeGomez Sep 16, 2021
c217488
Rollup merge of #88976 - notriddle:notriddle/cow-from-cstr-docs, r=Ma…
GuillaumeGomez Sep 16, 2021
ad960d4
Rollup merge of #88983 - willcrichton:allow-single-polonius-call, r=e…
GuillaumeGomez Sep 16, 2021
8dc7446
Rollup merge of #88985 - Commeownist:patch-1, r=Amanieu
GuillaumeGomez Sep 16, 2021
f070ffa
Rollup merge of #88986 - hargoniX:master, r=Mark-Simulacrum
GuillaumeGomez Sep 16, 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
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/consumers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ pub use super::{
};

/// This function computes Polonius facts for the given body. It makes a copy of
/// the body because it needs to regenerate the region identifiers.
/// the body because it needs to regenerate the region identifiers. This function
/// should never be invoked during a typical compilation session due to performance
/// issues with Polonius.
///
/// Note:
/// * This function will panic if the required body was already stolen. This
/// can, for example, happen when requesting a body of a `const` function
/// because they are evaluated during typechecking. The panic can be avoided
/// by overriding the `mir_borrowck` query. You can find a complete example
/// that shows how to do this at `src/test/run-make/obtain-borrowck/`.
/// * This function will also panic if computation of Polonius facts
/// (`-Zpolonius` flag) is not enabled.
///
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
pub fn get_body_with_borrowck_facts<'tcx>(
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl ConstraintDescription for ConstraintCategory {
ConstraintCategory::CopyBound => "copying this value ",
ConstraintCategory::OpaqueType => "opaque type ",
ConstraintCategory::ClosureUpvar(_) => "closure capture ",
ConstraintCategory::Usage => "this usage ",
ConstraintCategory::Boring
| ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal => "",
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ fn do_mir_borrowck<'a, 'tcx>(

debug!("do_mir_borrowck(def = {:?})", def);

assert!(
!return_body_with_facts || infcx.tcx.sess.opts.debugging_opts.polonius,
"borrowck facts can be requested only when Polonius is enabled"
);

let tcx = infcx.tcx;
let param_env = tcx.param_env(def.did);
let id = tcx.hir().local_def_id_to_hir_id(def.did);
Expand Down Expand Up @@ -235,6 +230,8 @@ fn do_mir_borrowck<'a, 'tcx>(
let borrow_set =
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));

let use_polonius = return_body_with_facts || infcx.tcx.sess.opts.debugging_opts.polonius;

// Compute non-lexical lifetimes.
let nll::NllOutput {
regioncx,
Expand All @@ -254,6 +251,7 @@ fn do_mir_borrowck<'a, 'tcx>(
&mdpe.move_data,
&borrow_set,
&upvars,
use_polonius,
);

// Dump MIR results into a file, if that is enabled. This let us
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
move_data: &MoveData<'tcx>,
borrow_set: &BorrowSet<'tcx>,
upvars: &[Upvar<'tcx>],
use_polonius: bool,
) -> NllOutput<'tcx> {
let mut all_facts = AllFacts::enabled(infcx.tcx).then_some(AllFacts::default());
let mut all_facts =
(use_polonius || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());

let universal_regions = Rc::new(universal_regions);

Expand Down Expand Up @@ -281,7 +283,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
all_facts.write_to_dir(dir_path, location_table).unwrap();
}

if infcx.tcx.sess.opts.debugging_opts.polonius {
if use_polonius {
let algorithm =
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid"));
let algorithm = Algorithm::from_str(&algorithm).unwrap();
Expand Down
13 changes: 13 additions & 0 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1388,11 +1388,24 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
ConstraintCategory::Return(ReturnConstraint::Normal)
}
}
Some(l)
if matches!(
body.local_decls[l].local_info,
Some(box LocalInfo::AggregateTemp)
) =>
{
ConstraintCategory::Usage
}
Some(l) if !body.local_decls[l].is_user_variable() => {
ConstraintCategory::Boring
}
_ => ConstraintCategory::Assignment,
};
debug!(
"assignment category: {:?} {:?}",
category,
place.as_local().map(|l| &body.local_decls[l])
);

let place_ty = place.ty(body, tcx).ty;
let place_ty = self.normalize(place_ty, location);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(super) fn parse(
// this with just `span.edition()`. A
// `SyntaxContext::root()` from the current crate will
// have the edition of the current crate, and a
// `SyntaxxContext::root()` from a foreign crate will
// `SyntaxContext::root()` from a foreign crate will
// have the edition of that crate (which we manually
// retrieve via the `edition` parameter).
if span.ctxt() == SyntaxContext::root() {
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ pub fn report_object_safety_error(
messages.push(msg.clone());
}
}
if trait_span.is_some() {
// Only provide the help if its a local trait, otherwise it's not actionable.
violation.solution(&mut err);
}
}
}
let has_multi_span = !multi_span.is_empty();
Expand All @@ -104,5 +100,13 @@ pub fn report_object_safety_error(
to be resolvable dynamically; for more information visit \
<https://doc.rust-lang.org/reference/items/traits.html#object-safety>",
);
if trait_span.is_some() {
let mut reported_violations: Vec<_> = reported_violations.into_iter().collect();
reported_violations.sort();
for violation in reported_violations {
// Only provide the help if its a local trait, otherwise it's not actionable.
violation.solution(&mut err);
}
}
err
}
10 changes: 8 additions & 2 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
use FfiResult::*;

if def.repr.transparent() {
// Can assume that only one field is not a ZST, so only check
// Can assume that at most one field is not a ZST, so only check
// that field's type for FFI-safety.
if let Some(field) = transparent_newtype_field(self.cx.tcx, variant) {
self.check_field_type_for_ffi(cache, field, substs)
} else {
bug!("malformed transparent type");
// All fields are ZSTs; this means that the type should behave
// like (), which is FFI-unsafe
FfiUnsafe {
ty,
reason: "this struct contains only zero-sized fields".into(),
help: None,
}
}
} else {
// We can't completely trust repr(C) markings; make sure the fields are
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,9 @@ pub enum LocalInfo<'tcx> {
StaticRef { def_id: DefId, is_thread_local: bool },
/// A temporary created that references the const with the given `DefId`
ConstRef { def_id: DefId },
/// A temporary created during the creation of an aggregate
/// (e.g. a temporary for `foo` in `MyStruct { my_field: foo }`)
AggregateTemp,
}

impl<'tcx> LocalDecl<'tcx> {
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_middle/src/mir/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,15 @@ pub enum ConstraintCategory {
CopyBound,
SizedBound,
Assignment,
/// A constraint that came from a usage of a variable (e.g. in an ADT expression
/// like `Foo { field: my_val }`)
Usage,
OpaqueType,
ClosureUpvar(hir::HirId),

/// A "boring" constraint (caused by the given location) is one that
/// the user probably doesn't want to see described in diagnostics,
/// because it is kind of an artifact of the type system setup.
/// Example: `x = Foo { field: y }` technically creates
/// intermediate regions representing the "type of `Foo { field: y
/// }`", and data flows from `y` into those variables, but they
/// are not very interesting. The assignment into `x` on the other
/// hand might be.
Boring,
// Boring and applicable everywhere.
BoringNoLocation,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ pub struct ImplSourceTraitAliasData<'tcx, N> {
pub nested: Vec<N>,
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
pub enum ObjectSafetyViolation {
/// `Self: Sized` declared on the trait.
SizedSelf(SmallVec<[Span; 1]>),
Expand Down Expand Up @@ -879,7 +879,7 @@ impl ObjectSafetyViolation {
}

/// Reasons a method might not be object-safe.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
pub enum MethodViolationCode {
/// e.g., `fn foo()`
StaticMethod(Option<(&'static str, Span)>, Span, bool /* has args */),
Expand Down
17 changes: 13 additions & 4 deletions compiler/rustc_mir_build/src/build/expr/as_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
expr: &Expr<'tcx>,
) -> BlockAnd<Operand<'tcx>> {
let local_scope = self.local_scope();
self.as_operand(block, Some(local_scope), expr)
self.as_operand(block, Some(local_scope), expr, None)
}

/// Returns an operand suitable for use until the end of the current scope expression and
Expand Down Expand Up @@ -85,6 +85,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// temporary `tmp = x`, so that we capture the value of `x` at
/// this time.
///
/// If we end up needing to create a temporary, then we will use
/// `local_info` as its `LocalInfo`, unless `as_temporary`
/// has already assigned it a non-`None` `LocalInfo`.
/// Normally, you should use `None` for `local_info`
///
/// The operand is known to be live until the end of `scope`.
///
/// Like `as_local_call_operand`, except that the argument will
Expand All @@ -94,15 +99,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
mut block: BasicBlock,
scope: Option<region::Scope>,
expr: &Expr<'tcx>,
local_info: Option<Box<LocalInfo<'tcx>>>,
) -> BlockAnd<Operand<'tcx>> {
debug!("as_operand(block={:?}, expr={:?})", block, expr);
debug!("as_operand(block={:?}, expr={:?} local_info={:?})", block, expr, local_info);
let this = self;

if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind {
let source_info = this.source_info(expr.span);
let region_scope = (region_scope, source_info);
return this.in_scope(region_scope, lint_level, |this| {
this.as_operand(block, scope, &this.thir[value])
this.as_operand(block, scope, &this.thir[value], local_info)
});
}

Expand All @@ -115,6 +121,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
Category::Place | Category::Rvalue(..) => {
let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut));
if this.local_decls[operand].local_info.is_none() {
this.local_decls[operand].local_info = local_info;
}
block.and(Operand::Move(Place::from(operand)))
}
}
Expand Down Expand Up @@ -167,6 +176,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}

this.as_operand(block, scope, expr)
this.as_operand(block, scope, expr, None)
}
}
24 changes: 14 additions & 10 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
ExprKind::Repeat { value, count } => {
let value_operand =
unpack!(block = this.as_operand(block, scope, &this.thir[value]));
unpack!(block = this.as_operand(block, scope, &this.thir[value], None));
block.and(Rvalue::Repeat(value_operand, count))
}
ExprKind::Binary { op, lhs, rhs } => {
let lhs = unpack!(block = this.as_operand(block, scope, &this.thir[lhs]));
let rhs = unpack!(block = this.as_operand(block, scope, &this.thir[rhs]));
let lhs = unpack!(block = this.as_operand(block, scope, &this.thir[lhs], None));
let rhs = unpack!(block = this.as_operand(block, scope, &this.thir[rhs], None));
this.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs)
}
ExprKind::Unary { op, arg } => {
let arg = unpack!(block = this.as_operand(block, scope, &this.thir[arg]));
let arg = unpack!(block = this.as_operand(block, scope, &this.thir[arg], None));
// Check for -MIN on signed integers
if this.check_overflow && op == UnOp::Neg && expr.ty.is_signed() {
let bool_ty = this.tcx.types.bool;
Expand Down Expand Up @@ -116,11 +116,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
block.and(Rvalue::Use(Operand::Move(Place::from(result))))
}
ExprKind::Cast { source } => {
let source = unpack!(block = this.as_operand(block, scope, &this.thir[source]));
let source =
unpack!(block = this.as_operand(block, scope, &this.thir[source], None));
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
}
ExprKind::Pointer { cast, source } => {
let source = unpack!(block = this.as_operand(block, scope, &this.thir[source]));
let source =
unpack!(block = this.as_operand(block, scope, &this.thir[source], None));
block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty))
}
ExprKind::Array { ref fields } => {
Expand Down Expand Up @@ -155,7 +157,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let fields: Vec<_> = fields
.into_iter()
.copied()
.map(|f| unpack!(block = this.as_operand(block, scope, &this.thir[f])))
.map(|f| unpack!(block = this.as_operand(block, scope, &this.thir[f], None)))
.collect();

block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(el_ty)), fields))
Expand All @@ -166,7 +168,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let fields: Vec<_> = fields
.into_iter()
.copied()
.map(|f| unpack!(block = this.as_operand(block, scope, &this.thir[f])))
.map(|f| unpack!(block = this.as_operand(block, scope, &this.thir[f], None)))
.collect();

block.and(Rvalue::Aggregate(Box::new(AggregateKind::Tuple), fields))
Expand Down Expand Up @@ -242,7 +244,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&this.thir[arg],
)
),
_ => unpack!(block = this.as_operand(block, scope, upvar)),
_ => {
unpack!(block = this.as_operand(block, scope, upvar, None))
}
}
}
}
Expand Down Expand Up @@ -304,7 +308,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Category::of(&expr.kind),
Some(Category::Rvalue(RvalueFunc::AsRvalue))
));
let operand = unpack!(block = this.as_operand(block, scope, expr));
let operand = unpack!(block = this.as_operand(block, scope, expr, None));
block.and(Rvalue::Use(operand))
}
}
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let fields_map: FxHashMap<_, _> = fields
.into_iter()
.map(|f| {
let local_info = Box::new(LocalInfo::AggregateTemp);
(
f.name,
unpack!(
block = this.as_operand(block, Some(scope), &this.thir[f.expr])
block = this.as_operand(
block,
Some(scope),
&this.thir[f.expr],
Some(local_info)
)
),
)
})
Expand Down Expand Up @@ -508,7 +514,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

ExprKind::Yield { value } => {
let scope = this.local_scope();
let value = unpack!(block = this.as_operand(block, Some(scope), &this.thir[value]));
let value =
unpack!(block = this.as_operand(block, Some(scope), &this.thir[value], None));
let resume = this.cfg.start_new_block();
this.cfg.terminate(
block,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_dataflow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub use self::drop_flag_effects::{
on_lookup_result_bits,
};
pub use self::framework::{
fmt, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine, Forward,
GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor,
fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine,
Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor,
ResultsVisitable, ResultsVisitor,
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod unreachable_prop;
use rustc_const_eval::transform::check_consts;
use rustc_const_eval::transform::promote_consts;
use rustc_const_eval::transform::validate;
use rustc_const_eval::transform::MirPass;
pub use rustc_const_eval::transform::MirPass;
use rustc_mir_dataflow::rustc_peek;

pub fn provide(providers: &mut Providers) {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,6 @@ symbols! {
panic_unwind,
panicking,
param_attrs,
parent_trait,
partial_cmp,
partial_ord,
passes,
Expand Down
Loading