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 #81593

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9abcfa5
Don't link with --export-dynamic on wasm32-wasi
sunfishcode Jan 21, 2021
77a9e3e
combine: stop eagerly evaluating consts
lcnr Jan 24, 2021
fe39653
Check that value is explicitly none
JulianKnodt Dec 27, 2020
d1727ed
Add lint for 2229 migrations
arora-aman Dec 28, 2020
2c651eb
Process mentioned upvars for analysis first pass after ExprUseVisitor
arora-aman Nov 21, 2020
36352d2
Migrations first pass
arora-aman Dec 15, 2020
d30a5bf
Tests for 2229 lint
arora-aman Dec 30, 2020
9ac023d
Mark the lint doc as compile_fail
arora-aman Jan 3, 2021
f106e18
PR fixup
arora-aman Jan 19, 2021
11abaa1
New migration
arora-aman Jan 26, 2021
b421cd5
Restrict precision of captures with `capture_disjoint_fields` set
arora-aman Dec 4, 2020
3488082
Compute mutability of closure captures
arora-aman Dec 2, 2020
1373f98
Test cases for handling mutable references
arora-aman Dec 13, 2020
0897db5
Test for restricting capture precision
arora-aman Dec 14, 2020
604cbdc
Fix unused 'mut' warning for capture's root variable
arora-aman Dec 16, 2020
c748f32
Fix incorrect use mut diagnostics
arora-aman Dec 13, 2020
ffd5327
Add fixme for precise path diagnostics
arora-aman Jan 12, 2021
fadf03e
Fix typos
arora-aman Jan 29, 2021
0f4bab2
Fixme for closure origin when reborrow is implemented
arora-aman Jan 29, 2021
5a3b85c
Remove changes to Cargo.lock
arora-aman Jan 30, 2021
9946b54
add suggestion for nested fields
b-naber Jan 28, 2021
6946534
Remove const_in_array_rep_expr
JulianKnodt Jan 26, 2021
6695690
Fix small typo
Seppel3210 Jan 31, 2021
8940a26
stabilize int_bits_const
KodrAus Jan 31, 2021
cd9a250
Rollup merge of #80092 - sexxi-goose:restrict_precision, r=nikomatsakis
jonas-schievink Jan 31, 2021
0155051
Rollup merge of #80404 - JulianKnodt:arr_ref, r=oli-obk
jonas-schievink Jan 31, 2021
61ab140
Rollup merge of #80629 - sexxi-goose:migrations_1, r=nikomatsakis
jonas-schievink Jan 31, 2021
666d2ad
Rollup merge of #81255 - sunfishcode:wasi-no-export-dynamic, r=alexcr…
jonas-schievink Jan 31, 2021
9fc2952
Rollup merge of #81351 - lcnr:big-money-big-prices, r=oli-obk
jonas-schievink Jan 31, 2021
6443825
Rollup merge of #81480 - b-naber:nested_fields_suggestion, r=estebank
jonas-schievink Jan 31, 2021
2b9fec7
Rollup merge of #81589 - Seppel3210:master, r=jonas-schievink
jonas-schievink Jan 31, 2021
bd990cc
Rollup merge of #81590 - KodrAus:stabilize/int_bits_const, r=m-ou-se
jonas-schievink Jan 31, 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
1 change: 0 additions & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#![feature(unboxed_closures)]
#![feature(generator_trait)]
#![feature(fn_traits)]
#![feature(int_bits_const)]
#![feature(min_specialization)]
#![feature(auto_traits)]
#![feature(nll)]
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,6 @@ declare_features! (
/// Allows `async || body` closures.
(active, async_closure, "1.37.0", Some(62290), None),

/// Allows `[x; N]` where `x` is a constant (RFC 2203).
(active, const_in_array_repeat_expressions, "1.37.0", Some(49147), None),

/// Allows `impl Trait` to be used inside type aliases (RFC 2515).
(active, type_alias_impl_trait, "1.38.0", Some(63063), None),

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ declare_features! (
(removed, extern_in_paths, "1.33.0", Some(55600), None,
Some("subsumed by `::foo::bar` paths")),
(removed, quote, "1.33.0", Some(29601), None, None),
/// Allows `[x; N]` where `x` is a constant (RFC 2203).
(removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None,
Some("removed due to causing promotable bugs")),
/// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
(removed, dropck_parametricity, "1.38.0", Some(28498), None, None),
(removed, await_macro, "1.38.0", Some(50547), None,
Expand Down
28 changes: 20 additions & 8 deletions compiler/rustc_infer/src/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,6 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
true
}

fn visit_ct_substs(&self) -> bool {
true
}

fn binders<T>(
&mut self,
a: ty::Binder<T>,
Expand Down Expand Up @@ -736,6 +732,16 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
}
}
}
ty::ConstKind::Unevaluated(def, substs, promoted)
if self.tcx().lazy_normalization() =>
{
assert_eq!(promoted, None);
let substs = self.relate_with_variance(ty::Variance::Invariant, substs, substs)?;
Ok(self.tcx().mk_const(ty::Const {
ty: c.ty,
val: ty::ConstKind::Unevaluated(def, substs, promoted),
}))
}
_ => relate::super_relate_consts(self, c, c),
}
}
Expand Down Expand Up @@ -821,10 +827,6 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
true
}

fn visit_ct_substs(&self) -> bool {
true
}

fn relate_with_variance<T: Relate<'tcx>>(
&mut self,
_variance: ty::Variance,
Expand Down Expand Up @@ -958,6 +960,16 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
}
}
}
ty::ConstKind::Unevaluated(def, substs, promoted)
if self.tcx().lazy_normalization() =>
{
assert_eq!(promoted, None);
let substs = self.relate_with_variance(ty::Variance::Invariant, substs, substs)?;
Ok(self.tcx().mk_const(ty::Const {
ty: c.ty,
val: ty::ConstKind::Unevaluated(def, substs, promoted),
}))
}
_ => relate::super_relate_consts(self, c, c),
}
}
Expand Down
46 changes: 46 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2968,6 +2968,7 @@ declare_lint_pass! {
UNSUPPORTED_NAKED_FUNCTIONS,
MISSING_ABI,
SEMICOLON_IN_EXPRESSIONS_FROM_MACROS,
DISJOINT_CAPTURE_DROP_REORDER,
]
}

Expand All @@ -2994,6 +2995,51 @@ declare_lint! {
"detects doc comments that aren't used by rustdoc"
}

declare_lint! {
/// The `disjoint_capture_drop_reorder` lint detects variables that aren't completely
/// captured when the feature `capture_disjoint_fields` is enabled and it affects the Drop
/// order of at least one path starting at this variable.
///
/// ### Example
///
/// ```rust,compile_fail
/// # #![deny(disjoint_capture_drop_reorder)]
/// # #![allow(unused)]
/// struct FancyInteger(i32);
///
/// impl Drop for FancyInteger {
/// fn drop(&mut self) {
/// println!("Just dropped {}", self.0);
/// }
/// }
///
/// struct Point { x: FancyInteger, y: FancyInteger }
///
/// fn main() {
/// let p = Point { x: FancyInteger(10), y: FancyInteger(20) };
///
/// let c = || {
/// let x = p.x;
/// };
///
/// c();
///
/// // ... More code ...
/// }
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// In the above example `p.y` will be dropped at the end of `f` instead of with `c` if
/// the feature `capture_disjoint_fields` is enabled.
pub DISJOINT_CAPTURE_DROP_REORDER,
Allow,
"Drop reorder because of `capture_disjoint_fields`"

}

declare_lint_pass!(UnusedDocComment => [UNUSED_DOC_COMMENTS]);

declare_lint! {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ pub enum ObligationCauseCode<'tcx> {
/// Inline asm operand type must be `Sized`.
InlineAsmSized,
/// `[T, ..n]` implies that `T` must be `Copy`.
/// If `true`, suggest `const_in_array_repeat_expressions` feature flag.
RepeatVec(bool),
RepeatVec,

/// Types of fields (other than the last, except for packed structs) in a struct must be sized.
FieldSized {
Expand Down
19 changes: 18 additions & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,28 @@ pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<hir::HirId, MinCaptureLis
/// Part of `MinCaptureInformationMap`; List of `CapturePlace`s.
pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>;

/// A `Place` and the corresponding `CaptureInfo`.
/// A composite describing a `Place` that is captured by a closure.
#[derive(PartialEq, Clone, Debug, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
pub struct CapturedPlace<'tcx> {
/// The `Place` that is captured.
pub place: HirPlace<'tcx>,

/// `CaptureKind` and expression(s) that resulted in such capture of `place`.
pub info: CaptureInfo<'tcx>,

/// Represents if `place` can be mutated or not.
pub mutability: hir::Mutability,
}

impl CapturedPlace<'tcx> {
/// Returns the hir-id of the root variable for the captured place.
/// e.g., if `a.b.c` was captured, would return the hir-id for `a`.
pub fn get_root_variable(&self) -> hir::HirId {
match self.place.base {
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
base => bug!("Expected upvar, found={:?}", base),
}
}
}

pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String {
Expand Down
11 changes: 1 addition & 10 deletions compiler/rustc_middle/src/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ pub trait TypeRelation<'tcx>: Sized {
/// relation. Just affects error messages.
fn a_is_expected(&self) -> bool;

/// Whether we should look into the substs of unevaluated constants
/// even if `feature(const_evaluatable_checked)` is active.
///
/// This is needed in `combine` to prevent accidentially creating
/// infinite types as we abuse `TypeRelation` to walk a type there.
fn visit_ct_substs(&self) -> bool {
false
}

fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R
where
F: FnOnce(&mut Self) -> R,
Expand Down Expand Up @@ -588,7 +579,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
(
ty::ConstKind::Unevaluated(a_def, a_substs, None),
ty::ConstKind::Unevaluated(b_def, b_substs, None),
) if tcx.features().const_evaluatable_checked && !relation.visit_ct_substs() => {
) if tcx.features().const_evaluatable_checked => {
if tcx.try_unify_abstract_consts(((a_def, a_substs), (b_def, b_substs))) {
Ok(a.val)
} else {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
PlaceRef { local, projection: [proj_base @ .., elem] } => {
match elem {
ProjectionElem::Deref => {
// FIXME(project-rfc_2229#36): print capture precisely here.
let upvar_field_projection = self.is_upvar_field_projection(place);
if let Some(field) = upvar_field_projection {
let var_index = field.index();
Expand Down Expand Up @@ -259,6 +260,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ProjectionElem::Field(field, _ty) => {
autoderef = true;

// FIXME(project-rfc_2229#36): print capture precisely here.
let upvar_field_projection = self.is_upvar_field_projection(place);
if let Some(field) = upvar_field_projection {
let var_index = field.index();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
};

let upvar = &self.upvars[upvar_field.unwrap().index()];
let upvar_hir_id = upvar.var_hir_id;
// FIXME(project-rfc-2229#8): Improve borrow-check diagnostics in case of precise
// capture.
let upvar_hir_id = upvar.place.get_root_variable();
let upvar_name = upvar.name;
let upvar_span = self.infcx.tcx.hir().span(upvar_hir_id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,29 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
));

item_msg = format!("`{}`", access_place_desc.unwrap());
if self.is_upvar_field_projection(access_place.as_ref()).is_some() {
reason = ", as it is not declared as mutable".to_string();
let imm_borrow_derefed = self.upvars[upvar_index.index()]
.place
.place
.deref_tys()
.any(|ty| matches!(ty.kind(), ty::Ref(.., hir::Mutability::Not)));

// If the place is immutable then:
//
// - Either we deref a immutable ref to get to our final place.
// - We don't capture derefs of raw ptrs
// - Or the final place is immut because the root variable of the capture
// isn't marked mut and we should suggest that to the user.
if imm_borrow_derefed {
// If we deref an immutable ref then the suggestion here doesn't help.
return;
} else {
let name = self.upvars[upvar_index.index()].name;
reason = format!(", as `{}` is not declared as mutable", name);
item_msg = format!("`{}`", access_place_desc.unwrap());
if self.is_upvar_field_projection(access_place.as_ref()).is_some() {
reason = ", as it is not declared as mutable".to_string();
} else {
let name = self.upvars[upvar_index.index()].name;
reason = format!(", as `{}` is not declared as mutable", name);
}
}
}

Expand Down Expand Up @@ -259,9 +276,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
));

let captured_place = &self.upvars[upvar_index.index()].place;

err.span_label(span, format!("cannot {ACT}", ACT = act));

let upvar_hir_id = self.upvars[upvar_index.index()].var_hir_id;
let upvar_hir_id = captured_place.get_root_variable();

if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id) {
if let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated,
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_mir/src/borrow_check/diagnostics/var_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
local_names: &IndexVec<Local, Option<Symbol>>,
upvars: &[Upvar],
upvars: &[Upvar<'tcx>],
fr: RegionVid,
) -> Option<(Option<Symbol>, Span)> {
debug!("get_var_name_and_span_for_region(fr={:?})", fr);
Expand All @@ -21,6 +21,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
debug!("get_var_name_and_span_for_region: attempting upvar");
self.get_upvar_index_for_region(tcx, fr)
.map(|index| {
// FIXME(project-rfc-2229#8): Use place span for diagnostics
let (name, span) = self.get_upvar_name_and_span_for_region(tcx, upvars, index);
(Some(name), span)
})
Expand Down Expand Up @@ -59,10 +60,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
crate fn get_upvar_name_and_span_for_region(
&self,
tcx: TyCtxt<'tcx>,
upvars: &[Upvar],
upvars: &[Upvar<'tcx>],
upvar_index: usize,
) -> (Symbol, Span) {
let upvar_hir_id = upvars[upvar_index].var_hir_id;
let upvar_hir_id = upvars[upvar_index].place.get_root_variable();
debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id);

let upvar_name = tcx.hir().name(upvar_hir_id);
Expand Down
Loading