Skip to content

Commit b96d9e0

Browse files
committed
Auto merge of rust-lang#105644 - matthiaskrgr:rollup-qc6hlzq, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#104864 (Account for item-local in inner scope for E0425) - rust-lang#105332 (Point out the type of associated types in every method call of iterator chains) - rust-lang#105620 (Remove unnecessary uses of `clone`) - rust-lang#105625 (minor code cleanups) - rust-lang#105629 (rustdoc: stop treating everything in a trait item as a method) - rust-lang#105636 (Add check for local-storage value when changing "display line numbers" settings) - rust-lang#105639 (rustdoc: remove `type="text/css" from stylesheet links) - rust-lang#105640 (Adjust miri to still be optional) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ed97493 + 5af0447 commit b96d9e0

File tree

60 files changed

+865
-244
lines changed

Some content is hidden

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

60 files changed

+865
-244
lines changed

compiler/rustc_abi/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -802,12 +802,9 @@ impl Integer {
802802
pub fn for_align<C: HasDataLayout>(cx: &C, wanted: Align) -> Option<Integer> {
803803
let dl = cx.data_layout();
804804

805-
for candidate in [I8, I16, I32, I64, I128] {
806-
if wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes() {
807-
return Some(candidate);
808-
}
809-
}
810-
None
805+
[I8, I16, I32, I64, I128].into_iter().find(|&candidate| {
806+
wanted == candidate.align(dl).abi && wanted.bytes() == candidate.size().bytes()
807+
})
811808
}
812809

813810
/// Find the largest integer with the given alignment or less.

compiler/rustc_ast/src/token.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl Lit {
114114
if let NtExpr(expr) | NtLiteral(expr) = &**nt
115115
&& let ast::ExprKind::Lit(token_lit) = expr.kind =>
116116
{
117-
Some(token_lit.clone())
117+
Some(token_lit)
118118
}
119119
_ => None,
120120
}

compiler/rustc_ast_passes/src/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ fn check_incompatible_features(sess: &Session) {
630630
{
631631
let spans = vec![f1_span, f2_span];
632632
sess.struct_span_err(
633-
spans.clone(),
633+
spans,
634634
&format!(
635635
"features `{}` and `{}` are incompatible, using them at the same time \
636636
is not allowed",

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
745745
err.span_suggestion_verbose(
746746
span.shrink_to_hi(),
747747
"consider cloning the value if the performance cost is acceptable",
748-
".clone()".to_string(),
748+
".clone()",
749749
Applicability::MachineApplicable,
750750
);
751751
}

compiler/rustc_builtin_macros/src/alloc_error_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn expand(
3232
(item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
3333
} else {
3434
ecx.sess.parse_sess.span_diagnostic.span_err(item.span(), "alloc_error_handler must be a function");
35-
return vec![orig_item.clone()];
35+
return vec![orig_item];
3636
};
3737

3838
// Generate a bunch of new items using the AllocFnFactory

compiler/rustc_builtin_macros/src/concat_bytes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn expand_concat_bytes(
196196
}
197197
}
198198
if !missing_literals.is_empty() {
199-
let mut err = cx.struct_span_err(missing_literals.clone(), "expected a byte literal");
199+
let mut err = cx.struct_span_err(missing_literals, "expected a byte literal");
200200
err.note("only byte literals (like `b\"foo\"`, `b's'`, and `[3, 4, 5]`) can be passed to `concat_bytes!()`");
201201
err.emit();
202202
return base::MacEager::expr(DummyResult::raw_expr(sp, true));

compiler/rustc_codegen_llvm/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub(crate) fn run_thin(
210210
}
211211

212212
pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBuffer) {
213-
let name = module.name.clone();
213+
let name = module.name;
214214
let buffer = ThinBuffer::new(module.module_llvm.llmod(), true);
215215
(name, buffer)
216216
}

compiler/rustc_data_structures/src/base_n.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub const MAX_BASE: usize = 64;
99
pub const ALPHANUMERIC_ONLY: usize = 62;
1010
pub const CASE_INSENSITIVE: usize = 36;
1111

12-
const BASE_64: &[u8; MAX_BASE as usize] =
12+
const BASE_64: &[u8; MAX_BASE] =
1313
b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$";
1414

1515
#[inline]

compiler/rustc_errors/src/diagnostic.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ impl Diagnostic {
370370
self.set_span(after);
371371
for span_label in before.span_labels() {
372372
if let Some(label) = span_label.label {
373-
self.span.push_span_label(after, label);
373+
if span_label.is_primary {
374+
self.span.push_span_label(after, label);
375+
} else {
376+
self.span.push_span_label(span_label.span, label);
377+
}
374378
}
375379
}
376380
self
@@ -802,7 +806,7 @@ impl Diagnostic {
802806
debug_assert!(
803807
!(suggestions
804808
.iter()
805-
.flat_map(|suggs| suggs)
809+
.flatten()
806810
.any(|(sp, suggestion)| sp.is_empty() && suggestion.is_empty())),
807811
"Span must not be empty and have no suggestion"
808812
);

compiler/rustc_errors/src/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ impl EmitterWriter {
13081308
// see how it *looks* with
13091309
// very *weird* formats
13101310
// see?
1311-
for &(ref text, ref style) in msg.iter() {
1311+
for (text, style) in msg.iter() {
13121312
let text = self.translate_message(text, args);
13131313
let lines = text.split('\n').collect::<Vec<_>>();
13141314
if lines.len() > 1 {
@@ -1370,7 +1370,7 @@ impl EmitterWriter {
13701370
buffer.append(0, ": ", header_style);
13711371
label_width += 2;
13721372
}
1373-
for &(ref text, _) in msg.iter() {
1373+
for (text, _) in msg.iter() {
13741374
let text = self.translate_message(text, args);
13751375
// Account for newlines to align output to its label.
13761376
for (line, text) in normalize_whitespace(&text).lines().enumerate() {

compiler/rustc_hir/src/hir.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,7 @@ impl<'hir> Generics<'hir> {
548548
}
549549

550550
pub fn get_named(&self, name: Symbol) -> Option<&GenericParam<'hir>> {
551-
for param in self.params {
552-
if name == param.name.ident().name {
553-
return Some(param);
554-
}
555-
}
556-
None
551+
self.params.iter().find(|&param| name == param.name.ident().name)
557552
}
558553

559554
pub fn spans(&self) -> MultiSpan {

compiler/rustc_index/src/bit_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<T: Idx> BitSet<T> {
209209
self.words[start_word_index] |= !(start_mask - 1);
210210
// And all trailing bits (i.e. from 0..=end) in the end word,
211211
// including the end.
212-
self.words[end_word_index] |= end_mask | end_mask - 1;
212+
self.words[end_word_index] |= end_mask | (end_mask - 1);
213213
} else {
214214
self.words[start_word_index] |= end_mask | (end_mask - start_mask);
215215
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ pub fn suggest_new_region_bound(
330330
Applicability::MaybeIncorrect,
331331
);
332332
}
333-
if let Some((param_span, param_ty)) = param.clone() {
333+
if let Some((param_span, ref param_ty)) = param {
334334
err.span_suggestion_verbose(
335335
param_span,
336336
add_static_bound,

compiler/rustc_lexer/src/unescape.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,13 @@ fn scan_escape(chars: &mut Chars<'_>, is_byte: bool) -> Result<char, EscapeError
204204
})?;
205205
}
206206
Some(c) => {
207-
let digit =
207+
let digit: u32 =
208208
c.to_digit(16).ok_or(EscapeError::InvalidCharInUnicodeEscape)?;
209209
n_digits += 1;
210210
if n_digits > 6 {
211211
// Stop updating value since we're sure that it's incorrect already.
212212
continue;
213213
}
214-
let digit = digit as u32;
215214
value = value * 16 + digit;
216215
}
217216
};

compiler/rustc_resolve/src/late.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
566566
/// FIXME #4948: Reuse ribs to avoid allocation.
567567
ribs: PerNS<Vec<Rib<'a>>>,
568568

569+
/// Previous poped `rib`, only used for diagnostic.
570+
last_block_rib: Option<Rib<'a>>,
571+
569572
/// The current set of local scopes, for labels.
570573
label_ribs: Vec<Rib<'a, NodeId>>,
571574

@@ -873,6 +876,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
873876
// Ignore errors in function bodies if this is rustdoc
874877
// Be sure not to set this until the function signature has been resolved.
875878
let previous_state = replace(&mut this.in_func_body, true);
879+
// We only care block in the same function
880+
this.last_block_rib = None;
876881
// Resolve the function body, potentially inside the body of an async closure
877882
this.with_lifetime_rib(
878883
LifetimeRibKind::Elided(LifetimeRes::Infer),
@@ -1168,6 +1173,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11681173
type_ns: vec![Rib::new(start_rib_kind)],
11691174
macro_ns: vec![Rib::new(start_rib_kind)],
11701175
},
1176+
last_block_rib: None,
11711177
label_ribs: Vec::new(),
11721178
lifetime_ribs: Vec::new(),
11731179
lifetime_elision_candidates: None,
@@ -3769,7 +3775,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
37693775
self.ribs[ValueNS].pop();
37703776
self.label_ribs.pop();
37713777
}
3772-
self.ribs[ValueNS].pop();
3778+
self.last_block_rib = self.ribs[ValueNS].pop();
37733779
if anonymous_module.is_some() {
37743780
self.ribs[TypeNS].pop();
37753781
}

compiler/rustc_resolve/src/late/diagnostics.rs

+16
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,22 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
623623
return (true, candidates);
624624
}
625625
}
626+
627+
// Try to find in last block rib
628+
if let Some(rib) = &self.last_block_rib && let RibKind::NormalRibKind = rib.kind {
629+
for (ident, &res) in &rib.bindings {
630+
if let Res::Local(_) = res && path.len() == 1 &&
631+
ident.span.eq_ctxt(path[0].ident.span) &&
632+
ident.name == path[0].ident.name {
633+
err.span_help(
634+
ident.span,
635+
&format!("the binding `{}` is available in a different scope in the same function", path_str),
636+
);
637+
return (true, candidates);
638+
}
639+
}
640+
}
641+
626642
return (false, candidates);
627643
}
628644

compiler/rustc_span/src/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ impl FilePathMapping {
11501150
// NOTE: We are iterating over the mapping entries from last to first
11511151
// because entries specified later on the command line should
11521152
// take precedence.
1153-
for &(ref from, ref to) in mapping.iter().rev() {
1153+
for (from, to) in mapping.iter().rev() {
11541154
debug!("Trying to apply {from:?} => {to:?}");
11551155

11561156
if let Ok(rest) = path.strip_prefix(from) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use crate::infer::InferCtxt;
2+
3+
use rustc_middle::ty::error::TypeError;
4+
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
5+
use rustc_middle::ty::{self, Ty, TyCtxt};
6+
7+
pub struct CollectAllMismatches<'a, 'tcx> {
8+
pub infcx: &'a InferCtxt<'tcx>,
9+
pub param_env: ty::ParamEnv<'tcx>,
10+
pub errors: Vec<TypeError<'tcx>>,
11+
}
12+
13+
impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
14+
fn tag(&self) -> &'static str {
15+
"CollectAllMismatches"
16+
}
17+
fn tcx(&self) -> TyCtxt<'tcx> {
18+
self.infcx.tcx
19+
}
20+
fn intercrate(&self) -> bool {
21+
false
22+
}
23+
fn param_env(&self) -> ty::ParamEnv<'tcx> {
24+
self.param_env
25+
}
26+
fn a_is_expected(&self) -> bool {
27+
true
28+
} // irrelevant
29+
fn mark_ambiguous(&mut self) {
30+
bug!()
31+
}
32+
fn relate_with_variance<T: Relate<'tcx>>(
33+
&mut self,
34+
_: ty::Variance,
35+
_: ty::VarianceDiagInfo<'tcx>,
36+
a: T,
37+
b: T,
38+
) -> RelateResult<'tcx, T> {
39+
self.relate(a, b)
40+
}
41+
fn regions(
42+
&mut self,
43+
a: ty::Region<'tcx>,
44+
_b: ty::Region<'tcx>,
45+
) -> RelateResult<'tcx, ty::Region<'tcx>> {
46+
Ok(a)
47+
}
48+
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
49+
if a == b || matches!(a.kind(), ty::Infer(_)) || matches!(b.kind(), ty::Infer(_)) {
50+
return Ok(a);
51+
}
52+
relate::super_relate_tys(self, a, b).or_else(|e| {
53+
self.errors.push(e);
54+
Ok(a)
55+
})
56+
}
57+
fn consts(
58+
&mut self,
59+
a: ty::Const<'tcx>,
60+
b: ty::Const<'tcx>,
61+
) -> RelateResult<'tcx, ty::Const<'tcx>> {
62+
if a == b {
63+
return Ok(a);
64+
}
65+
relate::super_relate_consts(self, a, b) // could do something similar here for constants!
66+
}
67+
fn binders<T: Relate<'tcx>>(
68+
&mut self,
69+
a: ty::Binder<'tcx, T>,
70+
b: ty::Binder<'tcx, T>,
71+
) -> RelateResult<'tcx, ty::Binder<'tcx, T>> {
72+
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
73+
}
74+
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod ambiguity;
2+
pub mod method_chain;
23
pub mod on_unimplemented;
34
pub mod suggestions;
45

@@ -536,7 +537,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
536537
|err| {
537538
self.note_obligation_cause_code(
538539
err,
539-
&predicate,
540+
predicate,
540541
obligation.param_env,
541542
obligation.cause.code(),
542543
&mut vec![],
@@ -1587,7 +1588,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
15871588
{
15881589
self.note_obligation_cause_code(
15891590
&mut diag,
1590-
&error.obligation.predicate,
1591+
error.obligation.predicate,
15911592
error.obligation.param_env,
15921593
code,
15931594
&mut vec![],
@@ -2602,7 +2603,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
26022603
if !self.maybe_note_obligation_cause_for_async_await(err, obligation) {
26032604
self.note_obligation_cause_code(
26042605
err,
2605-
&obligation.predicate,
2606+
obligation.predicate,
26062607
obligation.param_env,
26072608
obligation.cause.code(),
26082609
&mut vec![],

0 commit comments

Comments
 (0)