Skip to content

Commit 367612f

Browse files
committed
Auto merge of rust-lang#134480 - matthiaskrgr:rollup-yrdb1n4, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#132056 (Stabilize `#[diagnostic::do_not_recommend]`) - rust-lang#133643 (-Znext-solver: modify candidate preference rules) - rust-lang#134418 (Advent of `tests/ui` (misc cleanups and improvements) [3/N]) - rust-lang#134432 (Fix intra doc links not generated inside footnote definitions) - rust-lang#134473 (chore: fix some typos) - rust-lang#134474 (Forbid overwriting types in typeck) - rust-lang#134477 (move lint_unused_mut into sub-fn) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4ba4ac6 + e01e132 commit 367612f

File tree

90 files changed

+823
-430
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

+823
-430
lines changed

compiler/rustc_borrowck/src/lib.rs

+33-29
Original file line numberDiff line numberDiff line change
@@ -334,35 +334,7 @@ fn do_mir_borrowck<'tcx>(
334334
mbcx.gather_used_muts(temporary_used_locals, unused_mut_locals);
335335

336336
debug!("mbcx.used_mut: {:?}", mbcx.used_mut);
337-
let used_mut = std::mem::take(&mut mbcx.used_mut);
338-
for local in mbcx.body.mut_vars_and_args_iter().filter(|local| !used_mut.contains(local)) {
339-
let local_decl = &mbcx.body.local_decls[local];
340-
let lint_root = match &mbcx.body.source_scopes[local_decl.source_info.scope].local_data {
341-
ClearCrossCrate::Set(data) => data.lint_root,
342-
_ => continue,
343-
};
344-
345-
// Skip over locals that begin with an underscore or have no name
346-
match mbcx.local_names[local] {
347-
Some(name) => {
348-
if name.as_str().starts_with('_') {
349-
continue;
350-
}
351-
}
352-
None => continue,
353-
}
354-
355-
let span = local_decl.source_info.span;
356-
if span.desugaring_kind().is_some() {
357-
// If the `mut` arises as part of a desugaring, we should ignore it.
358-
continue;
359-
}
360-
361-
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
362-
363-
tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
364-
}
365-
337+
mbcx.lint_unused_mut();
366338
let tainted_by_errors = mbcx.emit_errors();
367339

368340
let result = BorrowCheckResult {
@@ -2390,6 +2362,38 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
23902362
// `BasicBlocks` computes dominators on-demand and caches them.
23912363
self.body.basic_blocks.dominators()
23922364
}
2365+
2366+
fn lint_unused_mut(&self) {
2367+
let tcx = self.infcx.tcx;
2368+
let body = self.body;
2369+
for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) {
2370+
let local_decl = &body.local_decls[local];
2371+
let lint_root = match &body.source_scopes[local_decl.source_info.scope].local_data {
2372+
ClearCrossCrate::Set(data) => data.lint_root,
2373+
_ => continue,
2374+
};
2375+
2376+
// Skip over locals that begin with an underscore or have no name
2377+
match self.local_names[local] {
2378+
Some(name) => {
2379+
if name.as_str().starts_with('_') {
2380+
continue;
2381+
}
2382+
}
2383+
None => continue,
2384+
}
2385+
2386+
let span = local_decl.source_info.span;
2387+
if span.desugaring_kind().is_some() {
2388+
// If the `mut` arises as part of a desugaring, we should ignore it.
2389+
continue;
2390+
}
2391+
2392+
let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);
2393+
2394+
tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
2395+
}
2396+
}
23932397
}
23942398

23952399
mod diags {

compiler/rustc_codegen_cranelift/src/compiler_builtins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ffi::c_int;
33
#[cfg(feature = "jit")]
44
use std::ffi::c_void;
55

6-
// FIXME replace with core::ffi::c_size_t once stablized
6+
// FIXME replace with core::ffi::c_size_t once stabilized
77
#[allow(non_camel_case_types)]
88
#[cfg(feature = "jit")]
99
type size_t = usize;

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
6666
sym::log2f64 => "log2",
6767
sym::fmaf32 => "fmaf",
6868
sym::fmaf64 => "fma",
69-
// FIXME: calling `fma` from libc without FMA target feature uses expensive sofware emulation
69+
// FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
7070
sym::fmuladdf32 => "fmaf", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f32
7171
sym::fmuladdf64 => "fma", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f64
7272
sym::fabsf32 => "fabsf",

compiler/rustc_errors/src/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,7 @@ impl HumanEmitter {
25232523
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
25242524
}
25252525
[] => {
2526-
// FIXME: needed? Doesn't get excercised in any test.
2526+
// FIXME: needed? Doesn't get exercised in any test.
25272527
self.draw_col_separator_no_space(buffer, *row_num, max_line_num_len + 1);
25282528
}
25292529
_ => {

compiler/rustc_errors/src/markdown/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ fn parse_with_end_pat<'a>(
346346
None
347347
}
348348

349-
/// Resturn `(match, residual)` to end of line. The EOL is returned with the
349+
/// Return `(match, residual)` to end of line. The EOL is returned with the
350350
/// residual.
351351
fn parse_to_newline(buf: &[u8]) -> (&[u8], &[u8]) {
352352
buf.iter().position(|ch| *ch == b'\n').map_or((buf, &[]), |pos| buf.split_at(pos))

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ declare_features! (
178178
(accepted, destructuring_assignment, "1.59.0", Some(71126)),
179179
/// Allows using the `#[diagnostic]` attribute tool namespace
180180
(accepted, diagnostic_namespace, "1.78.0", Some(111996)),
181+
/// Controls errors in trait implementations.
182+
(accepted, do_not_recommend, "CURRENT_RUSTC_VERSION", Some(51992)),
181183
/// Allows `#[doc(alias = "...")]`.
182184
(accepted, doc_alias, "1.48.0", Some(50146)),
183185
/// Allows `..` in tuple (struct) patterns.

compiler/rustc_feature/src/builtin_attrs.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1187,10 +1187,9 @@ pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>>
11871187
map
11881188
});
11891189

1190-
pub fn is_stable_diagnostic_attribute(sym: Symbol, features: &Features) -> bool {
1190+
pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
11911191
match sym {
1192-
sym::on_unimplemented => true,
1193-
sym::do_not_recommend => features.do_not_recommend(),
1192+
sym::on_unimplemented | sym::do_not_recommend => true,
11941193
_ => false,
11951194
}
11961195
}

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,6 @@ declare_features! (
462462
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
463463
/// Allows deref patterns.
464464
(incomplete, deref_patterns, "1.79.0", Some(87121)),
465-
/// Controls errors in trait implementations.
466-
(unstable, do_not_recommend, "1.67.0", Some(51992)),
467465
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
468466
(unstable, doc_auto_cfg, "1.58.0", Some(43781)),
469467
/// Allows `#[doc(cfg(...))]`.

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
146146
debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
147147
let mut typeck = self.typeck_results.borrow_mut();
148148
let mut node_ty = typeck.node_types_mut();
149-
if let Some(ty) = node_ty.get(id)
150-
&& let Err(e) = ty.error_reported()
151-
{
152-
// Do not overwrite nodes that were already marked as `{type error}`. This allows us to
153-
// silence unnecessary errors from obligations that were set earlier than a type error
154-
// was produced, but that is overwritten by later analysis. This happens in particular
155-
// for `Sized` obligations introduced in gather_locals. (#117846)
156-
self.set_tainted_by_errors(e);
157-
return;
158-
}
159149

160-
node_ty.insert(id, ty);
150+
if let Some(prev) = node_ty.insert(id, ty) {
151+
if prev.references_error() {
152+
node_ty.insert(id, prev);
153+
} else if !ty.references_error() {
154+
// Could change this to a bug, but there's lots of diagnostic code re-lowering
155+
// or re-typechecking nodes that were already typecked.
156+
// Lots of that diagnostics code relies on subtle effects of re-lowering, so we'll
157+
// let it keep doing that and just ensure that compilation won't succeed.
158+
self.dcx().span_delayed_bug(
159+
self.tcx.hir().span(id),
160+
format!("`{prev}` overridden by `{ty}` for {id:?} in {:?}", self.body_id),
161+
);
162+
}
163+
}
161164

162165
if let Err(e) = ty.error_reported() {
163166
self.set_tainted_by_errors(e);
@@ -1104,7 +1107,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11041107
if let Res::Local(hid) = res {
11051108
let ty = self.local_ty(span, hid);
11061109
let ty = self.normalize(span, ty);
1107-
self.write_ty(hir_id, ty);
11081110
return (ty, res);
11091111
}
11101112

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1750,10 +1750,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17501750
}
17511751
}
17521752

1753-
pub(in super::super) fn check_decl(&self, decl: Declaration<'tcx>) {
1753+
pub(in super::super) fn check_decl(&self, decl: Declaration<'tcx>) -> Ty<'tcx> {
17541754
// Determine and write the type which we'll check the pattern against.
17551755
let decl_ty = self.local_ty(decl.span, decl.hir_id);
1756-
self.write_ty(decl.hir_id, decl_ty);
17571756

17581757
// Type check the initializer.
17591758
if let Some(ref init) = decl.init {
@@ -1785,11 +1784,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17851784
}
17861785
self.diverges.set(previous_diverges);
17871786
}
1787+
decl_ty
17881788
}
17891789

17901790
/// Type check a `let` statement.
17911791
fn check_decl_local(&self, local: &'tcx hir::LetStmt<'tcx>) {
1792-
self.check_decl(local.into());
1792+
let ty = self.check_decl(local.into());
1793+
self.write_ty(local.hir_id, ty);
17931794
if local.pat.is_never_pattern() {
17941795
self.diverges.set(Diverges::Always {
17951796
span: local.pat.span,

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ pub struct ParamEnv<'tcx> {
971971
}
972972

973973
impl<'tcx> rustc_type_ir::inherent::ParamEnv<TyCtxt<'tcx>> for ParamEnv<'tcx> {
974-
fn caller_bounds(self) -> impl IntoIterator<Item = ty::Clause<'tcx>> {
974+
fn caller_bounds(self) -> impl inherent::SliceLike<Item = ty::Clause<'tcx>> {
975975
self.caller_bounds()
976976
}
977977
}

0 commit comments

Comments
 (0)