Skip to content

Commit d4ecf31

Browse files
committed
Auto merge of rust-lang#73367 - RalfJung:rollup-4ewvk9b, r=RalfJung
Rollup of 10 pull requests Successful merges: - rust-lang#71824 (Check for live drops in constants after drop elaboration) - rust-lang#72389 (Explain move errors that occur due to method calls involving `self`) - rust-lang#72556 (Fix trait alias inherent impl resolution) - rust-lang#72584 (Stabilize vec::Drain::as_slice) - rust-lang#72598 (Display information about captured variable in `FnMut` error) - rust-lang#73336 (Group `Pattern::strip_*` method together) - rust-lang#73341 (_match.rs: fix module doc comment) - rust-lang#73342 (Fix iterator copied() documentation example code) - rust-lang#73351 (Update E0446.md) - rust-lang#73353 (structural_match: non-structural-match ty closures) Failed merges: r? @ghost
2 parents ce6d3a7 + bca9e90 commit d4ecf31

File tree

87 files changed

+1574
-507
lines changed

Some content is hidden

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

87 files changed

+1574
-507
lines changed

src/liballoc/vec.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -2779,19 +2779,25 @@ impl<'a, T> Drain<'a, T> {
27792779
/// # Examples
27802780
///
27812781
/// ```
2782-
/// # #![feature(vec_drain_as_slice)]
27832782
/// let mut vec = vec!['a', 'b', 'c'];
27842783
/// let mut drain = vec.drain(..);
27852784
/// assert_eq!(drain.as_slice(), &['a', 'b', 'c']);
27862785
/// let _ = drain.next().unwrap();
27872786
/// assert_eq!(drain.as_slice(), &['b', 'c']);
27882787
/// ```
2789-
#[unstable(feature = "vec_drain_as_slice", reason = "recently added", issue = "58957")]
2788+
#[stable(feature = "vec_drain_as_slice", since = "1.46.0")]
27902789
pub fn as_slice(&self) -> &[T] {
27912790
self.iter.as_slice()
27922791
}
27932792
}
27942793

2794+
#[stable(feature = "vec_drain_as_slice", since = "1.46.0")]
2795+
impl<'a, T> AsRef<[T]> for Drain<'a, T> {
2796+
fn as_ref(&self) -> &[T] {
2797+
self.as_slice()
2798+
}
2799+
}
2800+
27952801
#[stable(feature = "drain", since = "1.6.0")]
27962802
unsafe impl<T: Sync> Sync for Drain<'_, T> {}
27972803
#[stable(feature = "drain", since = "1.6.0")]

src/libcore/future/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
5656
where
5757
T: Generator<ResumeTy, Yield = ()>,
5858
{
59+
#[rustc_diagnostic_item = "gen_future"]
5960
struct GenFuture<T: Generator<ResumeTy, Yield = ()>>(T);
6061

6162
// We rely on the fact that async/await futures are immovable in order to create

src/libcore/iter/traits/iterator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2717,12 +2717,12 @@ pub trait Iterator {
27172717
/// ```
27182718
/// let a = [1, 2, 3];
27192719
///
2720-
/// let v_cloned: Vec<_> = a.iter().copied().collect();
2720+
/// let v_copied: Vec<_> = a.iter().copied().collect();
27212721
///
27222722
/// // copied is the same as .map(|&x| x)
27232723
/// let v_map: Vec<_> = a.iter().map(|&x| x).collect();
27242724
///
2725-
/// assert_eq!(v_cloned, vec![1, 2, 3]);
2725+
/// assert_eq!(v_copied, vec![1, 2, 3]);
27262726
/// assert_eq!(v_map, vec![1, 2, 3]);
27272727
/// ```
27282728
#[stable(feature = "iter_copied", since = "1.36.0")]

src/libcore/str/pattern.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use crate::slice::memchr;
6969
/// |--------------------------|-------------------------------------------|
7070
/// | `&str` | is substring |
7171
/// | `char` | is contained in string |
72-
/// | `&[char] | any char in slice is contained in string |
72+
/// | `&[char]` | any char in slice is contained in string |
7373
/// | `F: FnMut(char) -> bool` | `F` returns `true` for a char in string |
7474
/// | `&&str` | is substring |
7575
/// | `&String` | is substring |
@@ -117,6 +117,15 @@ pub trait Pattern<'a>: Sized {
117117
matches!(self.into_searcher(haystack).next(), SearchStep::Match(0, _))
118118
}
119119

120+
/// Checks whether the pattern matches at the back of the haystack
121+
#[inline]
122+
fn is_suffix_of(self, haystack: &'a str) -> bool
123+
where
124+
Self::Searcher: ReverseSearcher<'a>,
125+
{
126+
matches!(self.into_searcher(haystack).next_back(), SearchStep::Match(_, j) if haystack.len() == j)
127+
}
128+
120129
/// Removes the pattern from the front of haystack, if it matches.
121130
#[inline]
122131
fn strip_prefix_of(self, haystack: &'a str) -> Option<&'a str> {
@@ -133,15 +142,6 @@ pub trait Pattern<'a>: Sized {
133142
}
134143
}
135144

136-
/// Checks whether the pattern matches at the back of the haystack
137-
#[inline]
138-
fn is_suffix_of(self, haystack: &'a str) -> bool
139-
where
140-
Self::Searcher: ReverseSearcher<'a>,
141-
{
142-
matches!(self.into_searcher(haystack).next_back(), SearchStep::Match(_, j) if haystack.len() == j)
143-
}
144-
145145
/// Removes the pattern from the back of haystack, if it matches.
146146
#[inline]
147147
fn strip_suffix_of(self, haystack: &'a str) -> Option<&'a str>

src/librustc_ast_lowering/expr.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::thin_vec::ThinVec;
99
use rustc_errors::struct_span_err;
1010
use rustc_hir as hir;
1111
use rustc_hir::def::Res;
12-
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
12+
use rustc_span::source_map::{respan, DesugaringKind, ForLoopLoc, Span, Spanned};
1313
use rustc_span::symbol::{sym, Ident, Symbol};
1414
use rustc_target::asm;
1515
use std::collections::hash_map::Entry;
@@ -25,6 +25,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
2525
}
2626

2727
pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
28+
let mut span = e.span;
2829
ensure_sufficient_stack(|| {
2930
let kind = match e.kind {
3031
ExprKind::Box(ref inner) => hir::ExprKind::Box(self.lower_expr(inner)),
@@ -53,6 +54,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
5354
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args, span)
5455
}
5556
ExprKind::Binary(binop, ref lhs, ref rhs) => {
57+
span = self.mark_span_with_reason(DesugaringKind::Operator, e.span, None);
5658
let binop = self.lower_binop(binop);
5759
let lhs = self.lower_expr(lhs);
5860
let rhs = self.lower_expr(rhs);
@@ -222,7 +224,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
222224
hir::Expr {
223225
hir_id: self.lower_node_id(e.id),
224226
kind,
225-
span: e.span,
227+
span,
226228
attrs: e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
227229
}
228230
})
@@ -237,6 +239,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
237239
}
238240

239241
fn lower_binop(&mut self, b: BinOp) -> hir::BinOp {
242+
let span = self.mark_span_with_reason(DesugaringKind::Operator, b.span, None);
240243
Spanned {
241244
node: match b.node {
242245
BinOpKind::Add => hir::BinOpKind::Add,
@@ -258,7 +261,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
258261
BinOpKind::Ge => hir::BinOpKind::Ge,
259262
BinOpKind::Gt => hir::BinOpKind::Gt,
260263
},
261-
span: b.span,
264+
span,
262265
}
263266
}
264267

@@ -1360,9 +1363,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
13601363
body: &Block,
13611364
opt_label: Option<Label>,
13621365
) -> hir::Expr<'hir> {
1366+
let orig_head_span = head.span;
13631367
// expand <head>
13641368
let mut head = self.lower_expr_mut(head);
1365-
let desugared_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None);
1369+
let desugared_span = self.mark_span_with_reason(
1370+
DesugaringKind::ForLoop(ForLoopLoc::Head),
1371+
orig_head_span,
1372+
None,
1373+
);
13661374
head.span = desugared_span;
13671375

13681376
let iter = Ident::with_dummy_span(sym::iter);
@@ -1457,10 +1465,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
14571465
// `mut iter => { ... }`
14581466
let iter_arm = self.arm(iter_pat, loop_expr);
14591467

1468+
let into_iter_span = self.mark_span_with_reason(
1469+
DesugaringKind::ForLoop(ForLoopLoc::IntoIter),
1470+
orig_head_span,
1471+
None,
1472+
);
1473+
14601474
// `match ::std::iter::IntoIterator::into_iter(<head>) { ... }`
14611475
let into_iter_expr = {
14621476
let into_iter_path = &[sym::iter, sym::IntoIterator, sym::into_iter];
1463-
self.expr_call_std_path(desugared_span, into_iter_path, arena_vec![self; head])
1477+
self.expr_call_std_path(into_iter_span, into_iter_path, arena_vec![self; head])
14641478
};
14651479

14661480
let match_expr = self.arena.alloc(self.expr_match(

src/librustc_error_codes/error_codes/E0446.md

+24-8
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Erroneous code example:
44

55
```compile_fail,E0446
66
#![deny(private_in_public)]
7+
struct Bar(u32);
78
8-
mod Foo {
9-
struct Bar(u32);
10-
9+
mod foo {
10+
use crate::Bar;
1111
pub fn bar() -> Bar { // error: private type in public interface
1212
Bar(0)
1313
}
@@ -16,15 +16,31 @@ mod Foo {
1616
fn main() {}
1717
```
1818

19-
To solve this error, please ensure that the type is also public. The type
20-
can be made inaccessible if necessary by placing it into a private inner
21-
module, but it still has to be marked with `pub`.
19+
There are two ways to solve this error. The first is to make the public type
20+
signature only public to a module that also has access to the private type.
21+
This is done by using pub(crate) or pub(in crate::my_mod::etc)
2222
Example:
2323

2424
```
25-
mod Foo {
26-
pub struct Bar(u32); // we set the Bar type public
25+
struct Bar(u32);
26+
27+
mod foo {
28+
use crate::Bar;
29+
pub(crate) fn bar() -> Bar { // only public to crate root
30+
Bar(0)
31+
}
32+
}
2733
34+
fn main() {}
35+
```
36+
37+
The other way to solve this error is to make the private type public.
38+
Example:
39+
40+
```
41+
pub struct Bar(u32); // we set the Bar type public
42+
mod foo {
43+
use crate::Bar;
2844
pub fn bar() -> Bar { // ok!
2945
Bar(0)
3046
}

src/librustc_error_codes/error_codes/E0493.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
A type with a `Drop` implementation was destructured when trying to initialize
2-
a static item.
1+
A value with a custom `Drop` implementation may be dropped during const-eval.
32

43
Erroneous code example:
54

@@ -16,13 +15,14 @@ struct Foo {
1615
field1: DropType,
1716
}
1817
19-
static FOO: Foo = Foo { ..Foo { field1: DropType::A } }; // error!
18+
static FOO: Foo = Foo { field1: (DropType::A, DropType::A).1 }; // error!
2019
```
2120

2221
The problem here is that if the given type or one of its fields implements the
23-
`Drop` trait, this `Drop` implementation cannot be called during the static
24-
type initialization which might cause a memory leak. To prevent this issue,
25-
you need to instantiate all the static type's fields by hand.
22+
`Drop` trait, this `Drop` implementation cannot be called within a const
23+
context since it may run arbitrary, non-const-checked code. To prevent this
24+
issue, ensure all values with custom a custom `Drop` implementation escape the
25+
initializer.
2626

2727
```
2828
enum DropType {

src/librustc_feature/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ declare_features! (
577577
/// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
578578
(active, abi_avr_interrupt, "1.45.0", Some(69664), None),
579579

580+
/// Be more precise when looking for live drops in a const context.
581+
(active, const_precise_live_drops, "1.46.0", Some(73255), None),
582+
580583
// -------------------------------------------------------------------------
581584
// feature-group-end: actual feature gates
582585
// -------------------------------------------------------------------------

src/librustc_infer/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
455455
let msg = if let Some(simple_ident) = pattern.simple_ident() {
456456
match pattern.span.desugaring_kind() {
457457
None => format!("consider giving `{}` {}", simple_ident, suffix),
458-
Some(DesugaringKind::ForLoop) => {
458+
Some(DesugaringKind::ForLoop(_)) => {
459459
"the element type for this iterator is not specified".to_string()
460460
}
461461
_ => format!("this needs {}", suffix),

src/librustc_interface/passes.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
847847

848848
sess.time("MIR_effect_checking", || {
849849
for def_id in tcx.body_owners() {
850-
mir::transform::check_unsafety::check_unsafety(tcx, def_id)
850+
mir::transform::check_unsafety::check_unsafety(tcx, def_id);
851+
852+
if tcx.hir().body_const_context(def_id).is_some() {
853+
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
854+
}
851855
}
852856
});
853857

src/librustc_metadata/rmeta/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1315,13 +1315,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13151315
}
13161316
}
13171317

1318-
fn get_fn_param_names(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Symbol] {
1318+
fn get_fn_param_names(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Ident] {
13191319
let param_names = match self.kind(id) {
13201320
EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).param_names,
13211321
EntryKind::AssocFn(data) => data.decode(self).fn_data.param_names,
13221322
_ => Lazy::empty(),
13231323
};
1324-
tcx.arena.alloc_from_iter(param_names.decode(self))
1324+
tcx.arena.alloc_from_iter(param_names.decode((self, tcx)))
13251325
}
13261326

13271327
fn exported_symbols(

src/librustc_metadata/rmeta/encoder.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
3030
use rustc_serialize::{opaque, Encodable, Encoder, SpecializedEncoder};
3131
use rustc_session::config::CrateType;
3232
use rustc_span::source_map::Spanned;
33-
use rustc_span::symbol::{kw, sym, Ident, Symbol};
33+
use rustc_span::symbol::{sym, Ident, Symbol};
3434
use rustc_span::{self, ExternalSource, FileName, SourceFile, Span};
3535
use rustc_target::abi::VariantIdx;
3636
use std::hash::Hash;
@@ -994,18 +994,12 @@ impl EncodeContext<'tcx> {
994994
}
995995
}
996996

997-
fn encode_fn_param_names_for_body(&mut self, body_id: hir::BodyId) -> Lazy<[Symbol]> {
998-
self.tcx.dep_graph.with_ignore(|| {
999-
let body = self.tcx.hir().body(body_id);
1000-
self.lazy(body.params.iter().map(|arg| match arg.pat.kind {
1001-
hir::PatKind::Binding(_, _, ident, _) => ident.name,
1002-
_ => kw::Invalid,
1003-
}))
1004-
})
997+
fn encode_fn_param_names_for_body(&mut self, body_id: hir::BodyId) -> Lazy<[Ident]> {
998+
self.tcx.dep_graph.with_ignore(|| self.lazy(self.tcx.hir().body_param_names(body_id)))
1005999
}
10061000

1007-
fn encode_fn_param_names(&mut self, param_names: &[Ident]) -> Lazy<[Symbol]> {
1008-
self.lazy(param_names.iter().map(|ident| ident.name))
1001+
fn encode_fn_param_names(&mut self, param_names: &[Ident]) -> Lazy<[Ident]> {
1002+
self.lazy(param_names.iter())
10091003
}
10101004

10111005
fn encode_optimized_mir(&mut self, def_id: LocalDefId) {

src/librustc_metadata/rmeta/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_serialize::opaque::Encoder;
1919
use rustc_session::config::SymbolManglingVersion;
2020
use rustc_session::CrateDisambiguator;
2121
use rustc_span::edition::Edition;
22-
use rustc_span::symbol::Symbol;
22+
use rustc_span::symbol::{Ident, Symbol};
2323
use rustc_span::{self, Span};
2424
use rustc_target::spec::{PanicStrategy, TargetTriple};
2525

@@ -326,7 +326,7 @@ struct ModData {
326326
struct FnData {
327327
asyncness: hir::IsAsync,
328328
constness: hir::Constness,
329-
param_names: Lazy<[Symbol]>,
329+
param_names: Lazy<[Ident]>,
330330
}
331331

332332
#[derive(RustcEncodable, RustcDecodable)]

src/librustc_middle/hir/map/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::*;
1414
use rustc_index::vec::IndexVec;
1515
use rustc_span::hygiene::MacroKind;
1616
use rustc_span::source_map::Spanned;
17-
use rustc_span::symbol::{kw, Symbol};
17+
use rustc_span::symbol::{kw, Ident, Symbol};
1818
use rustc_span::Span;
1919
use rustc_target::spec::abi::Abi;
2020

@@ -374,6 +374,13 @@ impl<'hir> Map<'hir> {
374374
})
375375
}
376376

377+
pub fn body_param_names(&self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir {
378+
self.body(id).params.iter().map(|arg| match arg.pat.kind {
379+
PatKind::Binding(_, _, ident, _) => ident,
380+
_ => Ident::new(kw::Invalid, rustc_span::DUMMY_SP),
381+
})
382+
}
383+
377384
/// Returns the `BodyOwnerKind` of this `LocalDefId`.
378385
///
379386
/// Panics if `LocalDefId` does not have an associated body.

0 commit comments

Comments
 (0)