Skip to content

Commit 941343e

Browse files
committed
Auto merge of rust-lang#81596 - jonas-schievink:rollup-utk14gr, r=jonas-schievink
Rollup of 11 pull requests Successful merges: - rust-lang#80092 (2229: Fix issues with move closures and mutability) - rust-lang#80404 (Remove const_in_array_repeat) - rust-lang#81255 (Don't link with --export-dynamic on wasm32-wasi) - rust-lang#81480 (Add suggestion for nested fields) - rust-lang#81549 (Misc ip documentation fixes) - rust-lang#81566 (Add a test for rust-lang#71202) - rust-lang#81568 (Fix an old FIXME in redundant paren lint) - rust-lang#81571 (Fix typo in E0759) - rust-lang#81572 (Edit multiple error code Markdown files) - rust-lang#81589 (Fix small typo in string.rs) - rust-lang#81590 (Stabilize int_bits_const) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0e63af5 + 9165676 commit 941343e

File tree

90 files changed

+1599
-326
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1599
-326
lines changed

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![feature(unboxed_closures)]
1414
#![feature(generator_trait)]
1515
#![feature(fn_traits)]
16-
#![feature(int_bits_const)]
1716
#![feature(min_specialization)]
1817
#![feature(auto_traits)]
1918
#![feature(nll)]

compiler/rustc_error_codes/src/error_codes/E0013.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ static X: i32 = 42;
88
const Y: i32 = X;
99
```
1010

11-
In this example, `Y` cannot refer to `X` here. To fix this, the value can be
11+
In this example, `Y` cannot refer to `X`. To fix this, the value can be
1212
extracted as a const and then used:
1313

1414
```

compiler/rustc_error_codes/src/error_codes/E0038.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,5 +287,5 @@ the method `get_a()` would return an object of unknown type when called on the
287287
function. `Self` type parameters let us make object safe traits no longer safe,
288288
so they are forbidden when specifying supertraits.
289289

290-
There's no easy fix for this, generally code will need to be refactored so that
290+
There's no easy fix for this. Generally, code will need to be refactored so that
291291
you no longer need to derive from `Super<Self>`.

compiler/rustc_error_codes/src/error_codes/E0107.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
An incorrect number of generic arguments were provided.
1+
An incorrect number of generic arguments was provided.
22

33
Erroneous code example:
44

compiler/rustc_error_codes/src/error_codes/E0116.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can only define an inherent implementation for a type in the same crate
1010
where the type was defined. For example, an `impl` block as above is not allowed
1111
since `Vec` is defined in the standard library.
1212

13-
To fix this problem, you can do either of these things:
13+
To fix this problem, you can either:
1414

1515
- define a trait that has the desired associated functions/types/constants and
1616
implement the trait for the type in question

compiler/rustc_error_codes/src/error_codes/E0277.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ fn main() {
5959
}
6060
```
6161

62-
Note that the error here is in the definition of the generic function: Although
62+
Note that the error here is in the definition of the generic function. Although
6363
we only call it with a parameter that does implement `Debug`, the compiler
64-
still rejects the function: It must work with all possible input types. In
64+
still rejects the function. It must work with all possible input types. In
6565
order to make this example compile, we need to restrict the generic type we're
6666
accepting:
6767

compiler/rustc_error_codes/src/error_codes/E0309.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ where
2525

2626
The type definition contains some field whose type requires an outlives
2727
annotation. Outlives annotations (e.g., `T: 'a`) are used to guarantee that all
28-
the data in T is valid for at least the lifetime `'a`. This scenario most
28+
the data in `T` is valid for at least the lifetime `'a`. This scenario most
2929
commonly arises when the type contains an associated type reference like
3030
`<T as SomeTrait<'a>>::Output`, as shown in the previous code.
3131

compiler/rustc_error_codes/src/error_codes/E0597.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This error occurs because a value was dropped while it was still borrowed
1+
This error occurs because a value was dropped while it was still borrowed.
22

33
Erroneous code example:
44

@@ -15,7 +15,7 @@ let mut x = Foo { x: None };
1515
println!("{:?}", x.x);
1616
```
1717

18-
In here, `y` is dropped at the end of the inner scope, but it is borrowed by
18+
Here, `y` is dropped at the end of the inner scope, but it is borrowed by
1919
`x` until the `println`. To fix the previous example, just remove the scope
2020
so that `y` isn't dropped until after the println
2121

compiler/rustc_error_codes/src/error_codes/E0658.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum Foo {
1111

1212
If you're using a stable or a beta version of rustc, you won't be able to use
1313
any unstable features. In order to do so, please switch to a nightly version of
14-
rustc (by using rustup).
14+
rustc (by using [rustup]).
1515

1616
If you're using a nightly version of rustc, just add the corresponding feature
1717
to be able to use it:
@@ -24,3 +24,5 @@ enum Foo {
2424
Bar(u64),
2525
}
2626
```
27+
28+
[rustup]: https://rust-lang.github.io/rustup/concepts/channels.html

compiler/rustc_error_codes/src/error_codes/E0754.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
An non-ascii identifier was used in an invalid context.
1+
A non-ASCII identifier was used in an invalid context.
22

33
Erroneous code examples:
44

@@ -13,7 +13,7 @@ fn řųśť() {} // error!
1313
fn main() {}
1414
```
1515

16-
Non-ascii can be used as module names if it is inlined or if a `#[path]`
16+
Non-ASCII can be used as module names if it is inlined or if a `#[path]`
1717
attribute is specified. For example:
1818

1919
```

compiler/rustc_error_codes/src/error_codes/E0759.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn bar(x: &i32) -> Box<dyn Debug + 'static> { // ok!
2727
}
2828
```
2929

30-
Both [`dyn Trait`] and [`impl Trait`] in return types have a an implicit
30+
Both [`dyn Trait`] and [`impl Trait`] in return types have an implicit
3131
`'static` requirement, meaning that the value implementing them that is being
3232
returned has to be either a `'static` borrow or an owned value.
3333

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,6 @@ declare_features! (
485485
/// Allows `async || body` closures.
486486
(active, async_closure, "1.37.0", Some(62290), None),
487487

488-
/// Allows `[x; N]` where `x` is a constant (RFC 2203).
489-
(active, const_in_array_repeat_expressions, "1.37.0", Some(49147), None),
490-
491488
/// Allows `impl Trait` to be used inside type aliases (RFC 2515).
492489
(active, type_alias_impl_trait, "1.38.0", Some(63063), None),
493490

compiler/rustc_feature/src/removed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ declare_features! (
9797
(removed, extern_in_paths, "1.33.0", Some(55600), None,
9898
Some("subsumed by `::foo::bar` paths")),
9999
(removed, quote, "1.33.0", Some(29601), None, None),
100+
/// Allows `[x; N]` where `x` is a constant (RFC 2203).
101+
(removed, const_in_array_repeat_expressions, "1.37.0", Some(49147), None,
102+
Some("removed due to causing promotable bugs")),
100103
/// Allows using `#[unsafe_destructor_blind_to_params]` (RFC 1238).
101104
(removed, dropck_parametricity, "1.38.0", Some(28498), None, None),
102105
(removed, await_macro, "1.38.0", Some(50547), None,

compiler/rustc_lint/src/unused.rs

-2
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,6 @@ impl UnusedDelimLint for UnusedBraces {
977977
}
978978
}
979979
ast::ExprKind::Let(_, ref expr) => {
980-
// FIXME(#60336): Properly handle `let true = (false && true)`
981-
// actually needing the parenthesis.
982980
self.check_unused_delims_expr(
983981
cx,
984982
expr,

compiler/rustc_middle/src/traits/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ pub enum ObligationCauseCode<'tcx> {
228228
/// Inline asm operand type must be `Sized`.
229229
InlineAsmSized,
230230
/// `[T, ..n]` implies that `T` must be `Copy`.
231-
/// If `true`, suggest `const_in_array_repeat_expressions` feature flag.
232-
RepeatVec(bool),
231+
RepeatVec,
233232

234233
/// Types of fields (other than the last, except for packed structs) in a struct must be sized.
235234
FieldSized {

compiler/rustc_middle/src/ty/mod.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,28 @@ pub type RootVariableMinCaptureList<'tcx> = FxIndexMap<hir::HirId, MinCaptureLis
661661
/// Part of `MinCaptureInformationMap`; List of `CapturePlace`s.
662662
pub type MinCaptureList<'tcx> = Vec<CapturedPlace<'tcx>>;
663663

664-
/// A `Place` and the corresponding `CaptureInfo`.
664+
/// A composite describing a `Place` that is captured by a closure.
665665
#[derive(PartialEq, Clone, Debug, TyEncodable, TyDecodable, TypeFoldable, HashStable)]
666666
pub struct CapturedPlace<'tcx> {
667+
/// The `Place` that is captured.
667668
pub place: HirPlace<'tcx>,
669+
670+
/// `CaptureKind` and expression(s) that resulted in such capture of `place`.
668671
pub info: CaptureInfo<'tcx>,
672+
673+
/// Represents if `place` can be mutated or not.
674+
pub mutability: hir::Mutability,
675+
}
676+
677+
impl CapturedPlace<'tcx> {
678+
/// Returns the hir-id of the root variable for the captured place.
679+
/// e.g., if `a.b.c` was captured, would return the hir-id for `a`.
680+
pub fn get_root_variable(&self) -> hir::HirId {
681+
match self.place.base {
682+
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
683+
base => bug!("Expected upvar, found={:?}", base),
684+
}
685+
}
669686
}
670687

671688
pub fn place_to_string_for_capture(tcx: TyCtxt<'tcx>, place: &HirPlace<'tcx>) -> String {

compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
215215
PlaceRef { local, projection: [proj_base @ .., elem] } => {
216216
match elem {
217217
ProjectionElem::Deref => {
218+
// FIXME(project-rfc_2229#36): print capture precisely here.
218219
let upvar_field_projection = self.is_upvar_field_projection(place);
219220
if let Some(field) = upvar_field_projection {
220221
let var_index = field.index();
@@ -259,6 +260,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
259260
ProjectionElem::Field(field, _ty) => {
260261
autoderef = true;
261262

263+
// FIXME(project-rfc_2229#36): print capture precisely here.
262264
let upvar_field_projection = self.is_upvar_field_projection(place);
263265
if let Some(field) = upvar_field_projection {
264266
let var_index = field.index();

compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
345345
};
346346

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

compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs

+26-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,29 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
6464
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
6565
));
6666

67-
item_msg = format!("`{}`", access_place_desc.unwrap());
68-
if self.is_upvar_field_projection(access_place.as_ref()).is_some() {
69-
reason = ", as it is not declared as mutable".to_string();
67+
let imm_borrow_derefed = self.upvars[upvar_index.index()]
68+
.place
69+
.place
70+
.deref_tys()
71+
.any(|ty| matches!(ty.kind(), ty::Ref(.., hir::Mutability::Not)));
72+
73+
// If the place is immutable then:
74+
//
75+
// - Either we deref a immutable ref to get to our final place.
76+
// - We don't capture derefs of raw ptrs
77+
// - Or the final place is immut because the root variable of the capture
78+
// isn't marked mut and we should suggest that to the user.
79+
if imm_borrow_derefed {
80+
// If we deref an immutable ref then the suggestion here doesn't help.
81+
return;
7082
} else {
71-
let name = self.upvars[upvar_index.index()].name;
72-
reason = format!(", as `{}` is not declared as mutable", name);
83+
item_msg = format!("`{}`", access_place_desc.unwrap());
84+
if self.is_upvar_field_projection(access_place.as_ref()).is_some() {
85+
reason = ", as it is not declared as mutable".to_string();
86+
} else {
87+
let name = self.upvars[upvar_index.index()].name;
88+
reason = format!(", as `{}` is not declared as mutable", name);
89+
}
7390
}
7491
}
7592

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

279+
let captured_place = &self.upvars[upvar_index.index()].place;
280+
262281
err.span_label(span, format!("cannot {ACT}", ACT = act));
263282

264-
let upvar_hir_id = self.upvars[upvar_index.index()].var_hir_id;
283+
let upvar_hir_id = captured_place.get_root_variable();
284+
265285
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id) {
266286
if let hir::PatKind::Binding(
267287
hir::BindingAnnotation::Unannotated,

compiler/rustc_mir/src/borrow_check/diagnostics/var_name.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1212
tcx: TyCtxt<'tcx>,
1313
body: &Body<'tcx>,
1414
local_names: &IndexVec<Local, Option<Symbol>>,
15-
upvars: &[Upvar],
15+
upvars: &[Upvar<'tcx>],
1616
fr: RegionVid,
1717
) -> Option<(Option<Symbol>, Span)> {
1818
debug!("get_var_name_and_span_for_region(fr={:?})", fr);
@@ -21,6 +21,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2121
debug!("get_var_name_and_span_for_region: attempting upvar");
2222
self.get_upvar_index_for_region(tcx, fr)
2323
.map(|index| {
24+
// FIXME(project-rfc-2229#8): Use place span for diagnostics
2425
let (name, span) = self.get_upvar_name_and_span_for_region(tcx, upvars, index);
2526
(Some(name), span)
2627
})
@@ -59,10 +60,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5960
crate fn get_upvar_name_and_span_for_region(
6061
&self,
6162
tcx: TyCtxt<'tcx>,
62-
upvars: &[Upvar],
63+
upvars: &[Upvar<'tcx>],
6364
upvar_index: usize,
6465
) -> (Symbol, Span) {
65-
let upvar_hir_id = upvars[upvar_index].var_hir_id;
66+
let upvar_hir_id = upvars[upvar_index].place.get_root_variable();
6667
debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id);
6768

6869
let upvar_name = tcx.hir().name(upvar_hir_id);

0 commit comments

Comments
 (0)