Skip to content

Commit 8ff7850

Browse files
committed
Auto merge of #70296 - Centril:rollup-wvfmb3n, r=Centril
Rollup of 9 pull requests Successful merges: - #69251 (#[track_caller] in traits) - #69880 (miri engine: turn error sanity checks into assertions) - #70207 (Use getentropy(2) on macos) - #70227 (Only display definition when suggesting a typo) - #70236 (resolve: Avoid "self-confirming" import resolutions in one more case) - #70248 (parser: simplify & remove unused field) - #70249 (handle ConstKind::Unresolved after monomorphizing) - #70269 (remove redundant closures (clippy::redundant_closure)) - #70270 (Clean up E0449 explanation) Failed merges: r? @ghost
2 parents 37c945d + 5f91f30 commit 8ff7850

File tree

67 files changed

+468
-340
lines changed

Some content is hidden

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

67 files changed

+468
-340
lines changed

src/liballoc/collections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
196196
(root, length)
197197
};
198198

199-
out_node.push(k, v, subroot.unwrap_or_else(|| node::Root::new_leaf()));
199+
out_node.push(k, v, subroot.unwrap_or_else(node::Root::new_leaf));
200200
out_tree.length += 1 + sublength;
201201
}
202202
}
@@ -2147,7 +2147,7 @@ impl<K, V> BTreeMap<K, V> {
21472147
/// If the root node is the empty (non-allocated) root node, allocate our
21482148
/// own node.
21492149
fn ensure_root_is_owned(&mut self) -> &mut node::Root<K, V> {
2150-
self.root.get_or_insert_with(|| node::Root::new_leaf())
2150+
self.root.get_or_insert_with(node::Root::new_leaf)
21512151
}
21522152
}
21532153

src/librustc/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl DepGraph {
245245
C: DepGraphSafe + StableHashingContextProvider<'a>,
246246
{
247247
if let Some(ref data) = self.data {
248-
let task_deps = create_task(key).map(|deps| Lock::new(deps));
248+
let task_deps = create_task(key).map(Lock::new);
249249

250250
// In incremental mode, hash the result of the task. We don't
251251
// do anything with the hash yet, but we are computing it

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#![feature(extern_types)]
3939
#![feature(nll)]
4040
#![feature(option_expect_none)]
41+
#![feature(or_patterns)]
4142
#![feature(range_is_empty)]
4243
#![feature(specialization)]
4344
#![feature(trusted_len)]

src/librustc/mir/interpret/allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ impl UndefMask {
796796
}
797797

798798
// FIXME(oli-obk): optimize this for allocations larger than a block.
799-
let idx = (start.bytes()..end.bytes()).map(|i| Size::from_bytes(i)).find(|&i| !self.get(i));
799+
let idx = (start.bytes()..end.bytes()).map(Size::from_bytes).find(|&i| !self.get(i));
800800

801801
match idx {
802802
Some(idx) => Err(idx),

src/librustc/ty/mod.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3535
use rustc_data_structures::sync::{self, par_iter, Lrc, ParallelIterator};
3636
use rustc_hir as hir;
3737
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res};
38-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
38+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
3939
use rustc_hir::{Constness, GlobMap, Node, TraitMap};
4040
use rustc_index::vec::{Idx, IndexVec};
4141
use rustc_macros::HashStable;
@@ -2875,8 +2875,8 @@ impl<'tcx> TyCtxt<'tcx> {
28752875
_ => false,
28762876
}
28772877
} else {
2878-
match self.def_kind(def_id).expect("no def for `DefId`") {
2879-
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => true,
2878+
match self.def_kind(def_id) {
2879+
Some(DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy) => true,
28802880
_ => false,
28812881
}
28822882
};
@@ -3054,17 +3054,7 @@ impl<'tcx> TyCtxt<'tcx> {
30543054
/// If the given defid describes a method belonging to an impl, returns the
30553055
/// `DefId` of the impl that the method belongs to; otherwise, returns `None`.
30563056
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
3057-
let item = if def_id.krate != LOCAL_CRATE {
3058-
if let Some(DefKind::AssocFn) = self.def_kind(def_id) {
3059-
Some(self.associated_item(def_id))
3060-
} else {
3061-
None
3062-
}
3063-
} else {
3064-
self.opt_associated_item(def_id)
3065-
};
3066-
3067-
item.and_then(|trait_item| match trait_item.container {
3057+
self.opt_associated_item(def_id).and_then(|trait_item| match trait_item.container {
30683058
TraitContainer(_) => None,
30693059
ImplContainer(def_id) => Some(def_id),
30703060
})

src/librustc_ast/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl ParenthesizedArgs {
250250
pub fn as_angle_bracketed_args(&self) -> AngleBracketedArgs {
251251
AngleBracketedArgs {
252252
span: self.span,
253-
args: self.inputs.iter().cloned().map(|input| GenericArg::Type(input)).collect(),
253+
args: self.inputs.iter().cloned().map(GenericArg::Type).collect(),
254254
constraints: vec![],
255255
}
256256
}

src/librustc_ast_lowering/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
274274
if !generic_args.parenthesized && !has_lifetimes {
275275
generic_args.args = self
276276
.elided_path_lifetimes(path_span, expected_lifetimes)
277-
.map(|lt| GenericArg::Lifetime(lt))
277+
.map(GenericArg::Lifetime)
278278
.chain(generic_args.args.into_iter())
279279
.collect();
280280
if expected_lifetimes > 0 && param_mode == ParamMode::Explicit {

src/librustc_builtin_macros/deriving/generic/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl<'a> Path<'a> {
7676
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
7777
let params = lt
7878
.into_iter()
79-
.map(|lt| GenericArg::Lifetime(lt))
80-
.chain(tys.into_iter().map(|ty| GenericArg::Type(ty)))
79+
.map(GenericArg::Lifetime)
80+
.chain(tys.into_iter().map(GenericArg::Type))
8181
.collect();
8282

8383
match self.kind {

src/librustc_builtin_macros/source_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_ast_pretty::pprust;
66
use rustc_expand::base::{self, *};
77
use rustc_expand::module::DirectoryOwnership;
88
use rustc_expand::panictry;
9-
use rustc_parse::{self, new_sub_parser_from_file, parser::Parser};
9+
use rustc_parse::{self, new_parser_from_file, parser::Parser};
1010
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
1111
use rustc_span::symbol::Symbol;
1212
use rustc_span::{self, Pos, Span};
@@ -110,7 +110,7 @@ pub fn expand_include<'cx>(
110110
return DummyResult::any(sp);
111111
}
112112
};
113-
let p = new_sub_parser_from_file(cx.parse_sess(), &file, None, sp);
113+
let p = new_parser_from_file(cx.parse_sess(), &file, Some(sp));
114114

115115
// If in the included file we have e.g., `mod bar;`,
116116
// then the path of `bar.rs` should be relative to the directory of `file`.

src/librustc_codegen_ssa/mir/constant.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4040
&mut self,
4141
constant: &mir::Constant<'tcx>,
4242
) -> Result<ConstValue<'tcx>, ErrorHandled> {
43-
match constant.literal.val {
44-
ty::ConstKind::Unevaluated(def_id, substs, promoted) => {
45-
let substs = self.monomorphize(&substs);
46-
self.cx
47-
.tcx()
48-
.const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None)
49-
.map_err(|err| {
50-
if promoted.is_none() {
51-
self.cx
52-
.tcx()
53-
.sess
54-
.span_err(constant.span, "erroneous constant encountered");
55-
}
56-
err
57-
})
58-
}
43+
match self.monomorphize(&constant.literal).val {
44+
ty::ConstKind::Unevaluated(def_id, substs, promoted) => self
45+
.cx
46+
.tcx()
47+
.const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None)
48+
.map_err(|err| {
49+
if promoted.is_none() {
50+
self.cx
51+
.tcx()
52+
.sess
53+
.span_err(constant.span, "erroneous constant encountered");
54+
}
55+
err
56+
}),
5957
ty::ConstKind::Value(value) => Ok(value),
60-
_ => {
61-
let const_ = self.monomorphize(&constant.literal);
62-
if let ty::ConstKind::Value(value) = const_.val {
63-
Ok(value)
64-
} else {
65-
span_bug!(constant.span, "encountered bad ConstKind in codegen: {:?}", const_);
66-
}
67-
}
58+
err => span_bug!(
59+
constant.span,
60+
"encountered bad ConstKind after monomorphizing: {:?}",
61+
err
62+
),
6863
}
6964
}
7065

src/librustc_data_structures/sharded.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct Sharded<T> {
3030
impl<T: Default> Default for Sharded<T> {
3131
#[inline]
3232
fn default() -> Self {
33-
Self::new(|| T::default())
33+
Self::new(T::default)
3434
}
3535
}
3636

src/librustc_error_codes/error_codes/E0449.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
A visibility qualifier was used when it was unnecessary. Erroneous code
2-
examples:
1+
A visibility qualifier was used when it was unnecessary.
2+
3+
Erroneous code examples:
34

45
```compile_fail,E0449
56
struct Bar;
+4-41
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,11 @@
1-
`#[track_caller]` cannot be used in traits yet. This is due to limitations in
2-
the compiler which are likely to be temporary. See [RFC 2091] for details on
3-
this and other restrictions.
1+
`#[track_caller]` cannot be used to annotate foreign functions.
42

5-
Erroneous example with a trait method implementation:
3+
Erroneous example:
64

75
```compile_fail,E0738
86
#![feature(track_caller)]
9-
10-
trait Foo {
11-
fn bar(&self);
12-
}
13-
14-
impl Foo for u64 {
15-
#[track_caller]
16-
fn bar(&self) {}
17-
}
18-
```
19-
20-
Erroneous example with a blanket trait method implementation:
21-
22-
```compile_fail,E0738
23-
#![feature(track_caller)]
24-
25-
trait Foo {
7+
extern "Rust" {
268
#[track_caller]
27-
fn bar(&self) {}
28-
fn baz(&self);
9+
fn bar();
2910
}
3011
```
31-
32-
Erroneous example with a trait method declaration:
33-
34-
```compile_fail,E0738
35-
#![feature(track_caller)]
36-
37-
trait Foo {
38-
fn bar(&self) {}
39-
40-
#[track_caller]
41-
fn baz(&self);
42-
}
43-
```
44-
45-
Note that while the compiler may be able to support the attribute in traits in
46-
the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
47-
48-
[RFC 2091]: https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md

src/librustc_errors/diagnostic_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a> DiagnosticBuilder<'a> {
162162
message: &str,
163163
span: Option<S>,
164164
) -> &mut Self {
165-
let span = span.map(|s| s.into()).unwrap_or_else(|| MultiSpan::new());
165+
let span = span.map(|s| s.into()).unwrap_or_else(MultiSpan::new);
166166
self.0.diagnostic.sub(level, message, span, None);
167167
self
168168
}

src/librustc_expand/mbe/macro_rules.rs

-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ fn generic_extension<'cx>(
259259
}
260260

261261
let mut p = Parser::new(sess, tts, false, None);
262-
p.root_module_name =
263-
cx.current_expansion.module.mod_path.last().map(|id| id.to_string());
264262
p.last_type_ascription = cx.current_expansion.prior_type_ascription;
265263

266264
// Let the context choose how to interpret the result.

src/librustc_expand/module.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_ast::ast::{self, Attribute, Ident, Mod};
22
use rustc_ast::{attr, token};
33
use rustc_errors::{struct_span_err, PResult};
4-
use rustc_parse::new_sub_parser_from_file;
4+
use rustc_parse::new_parser_from_file;
55
use rustc_session::parse::ParseSess;
66
use rustc_span::source_map::{FileName, Span};
77
use rustc_span::symbol::sym;
@@ -59,9 +59,8 @@ crate fn parse_external_mod(
5959
*pop_mod_stack = true; // We have pushed, so notify caller.
6060
drop(included_mod_stack);
6161

62-
// Actually parse the external file as amodule.
63-
let mut p0 = new_sub_parser_from_file(sess, &mp.path, Some(id.to_string()), span);
64-
let mut module = p0.parse_mod(&token::Eof)?;
62+
// Actually parse the external file as a module.
63+
let mut module = new_parser_from_file(sess, &mp.path, Some(span)).parse_mod(&token::Eof)?;
6564
module.0.inline = false;
6665
module
6766
};

src/librustc_feature/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct Feature {
5151

5252
impl Feature {
5353
fn issue(&self) -> Option<NonZeroU32> {
54-
self.issue.and_then(|i| NonZeroU32::new(i))
54+
self.issue.and_then(NonZeroU32::new)
5555
}
5656
}
5757

src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ impl<'tcx> QueryContext<'tcx> {
707707
where
708708
F: FnOnce(TyCtxt<'tcx>) -> R,
709709
{
710-
ty::tls::enter_global(self.0, |tcx| f(tcx))
710+
ty::tls::enter_global(self.0, f)
711711
}
712712

713713
pub fn print_stats(&mut self) {

src/librustc_metadata/locator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl<'a> CrateLocator<'a> {
327327
.into_iter()
328328
.filter_map(|entry| entry.files())
329329
.flatten()
330-
.map(|location| PathBuf::from(location))
330+
.map(PathBuf::from)
331331
.collect()
332332
} else {
333333
// SVH being specified means this is a transitive dependency,

src/librustc_mir/dataflow/generic/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ fn write_diff<A: Analysis<'tcx>>(
577577
let mut clear = HybridBitSet::new_empty(len);
578578

579579
// FIXME: Implement a lazy iterator over the symmetric difference of two bitsets.
580-
for i in (0..len).map(|i| A::Idx::new(i)) {
580+
for i in (0..len).map(A::Idx::new) {
581581
match (from.contains(i), to.contains(i)) {
582582
(false, true) => set.insert(i),
583583
(true, false) => clear.insert(i),

src/librustc_mir/interpret/validity.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -825,11 +825,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
825825
// Run it.
826826
match visitor.visit_value(op) {
827827
Ok(()) => Ok(()),
828+
// We should only get validation errors here. Avoid other errors as
829+
// those do not show *where* in the value the issue lies.
828830
Err(err) if matches!(err.kind, err_ub!(ValidationFailure { .. })) => Err(err),
829-
Err(err) if cfg!(debug_assertions) => {
830-
bug!("Unexpected error during validation: {}", err)
831-
}
832-
Err(err) => Err(err),
831+
Err(err) => bug!("Unexpected error during validation: {}", err),
833832
}
834833
}
835834

src/librustc_mir/monomorphize/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
895895
.unwrap()
896896
})
897897
.filter(|&instance| should_monomorphize_locally(tcx, &instance))
898-
.map(|instance| create_fn_mono_item(instance));
898+
.map(create_fn_mono_item);
899899
output.extend(methods);
900900
}
901901

src/librustc_mir/transform/const_prop.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
404404
// Some errors shouldn't come up because creating them causes
405405
// an allocation, which we should avoid. When that happens,
406406
// dedicated error variants should be introduced instead.
407-
// Only test this in debug builds though to avoid disruptions.
408-
debug_assert!(
407+
assert!(
409408
!error.kind.allocates(),
410409
"const-prop encountered allocating error: {}",
411410
error

src/librustc_mir_build/hair/pattern/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ fn split_grouped_constructors<'p, 'tcx>(
20662066
}
20672067
intersection
20682068
})
2069-
.flat_map(|range| range_borders(range));
2069+
.flat_map(range_borders);
20702070
let ctor_borders = range_borders(ctor_range.clone());
20712071
let mut borders: Vec<_> = row_borders.chain(ctor_borders).collect();
20722072
borders.sort_unstable();

0 commit comments

Comments
 (0)