Skip to content

Commit

Permalink
Auto merge of #134480 - matthiaskrgr:rollup-yrdb1n4, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #132056 (Stabilize `#[diagnostic::do_not_recommend]`)
 - #133643 (-Znext-solver: modify candidate preference rules)
 - #134418 (Advent of `tests/ui` (misc cleanups and improvements) [3/N])
 - #134432 (Fix intra doc links not generated inside footnote definitions)
 - #134473 (chore: fix some typos)
 - #134474 (Forbid overwriting types in typeck)
 - #134477 (move lint_unused_mut into sub-fn)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 18, 2024
2 parents 4ba4ac6 + e01e132 commit 367612f
Show file tree
Hide file tree
Showing 90 changed files with 823 additions and 430 deletions.
62 changes: 33 additions & 29 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,35 +334,7 @@ fn do_mir_borrowck<'tcx>(
mbcx.gather_used_muts(temporary_used_locals, unused_mut_locals);

debug!("mbcx.used_mut: {:?}", mbcx.used_mut);
let used_mut = std::mem::take(&mut mbcx.used_mut);
for local in mbcx.body.mut_vars_and_args_iter().filter(|local| !used_mut.contains(local)) {
let local_decl = &mbcx.body.local_decls[local];
let lint_root = match &mbcx.body.source_scopes[local_decl.source_info.scope].local_data {
ClearCrossCrate::Set(data) => data.lint_root,
_ => continue,
};

// Skip over locals that begin with an underscore or have no name
match mbcx.local_names[local] {
Some(name) => {
if name.as_str().starts_with('_') {
continue;
}
}
None => continue,
}

let span = local_decl.source_info.span;
if span.desugaring_kind().is_some() {
// If the `mut` arises as part of a desugaring, we should ignore it.
continue;
}

let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);

tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
}

mbcx.lint_unused_mut();
let tainted_by_errors = mbcx.emit_errors();

let result = BorrowCheckResult {
Expand Down Expand Up @@ -2390,6 +2362,38 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
// `BasicBlocks` computes dominators on-demand and caches them.
self.body.basic_blocks.dominators()
}

fn lint_unused_mut(&self) {
let tcx = self.infcx.tcx;
let body = self.body;
for local in body.mut_vars_and_args_iter().filter(|local| !self.used_mut.contains(local)) {
let local_decl = &body.local_decls[local];
let lint_root = match &body.source_scopes[local_decl.source_info.scope].local_data {
ClearCrossCrate::Set(data) => data.lint_root,
_ => continue,
};

// Skip over locals that begin with an underscore or have no name
match self.local_names[local] {
Some(name) => {
if name.as_str().starts_with('_') {
continue;
}
}
None => continue,
}

let span = local_decl.source_info.span;
if span.desugaring_kind().is_some() {
// If the `mut` arises as part of a desugaring, we should ignore it.
continue;
}

let mut_span = tcx.sess.source_map().span_until_non_whitespace(span);

tcx.emit_node_span_lint(UNUSED_MUT, lint_root, span, VarNeedNotMut { span: mut_span })
}
}
}

mod diags {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/compiler_builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ffi::c_int;
#[cfg(feature = "jit")]
use std::ffi::c_void;

// FIXME replace with core::ffi::c_size_t once stablized
// FIXME replace with core::ffi::c_size_t once stabilized
#[allow(non_camel_case_types)]
#[cfg(feature = "jit")]
type size_t = usize;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/intrinsic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
sym::log2f64 => "log2",
sym::fmaf32 => "fmaf",
sym::fmaf64 => "fma",
// FIXME: calling `fma` from libc without FMA target feature uses expensive sofware emulation
// FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
sym::fmuladdf32 => "fmaf", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f32
sym::fmuladdf64 => "fma", // TODO: use gcc intrinsic analogous to llvm.fmuladd.f64
sym::fabsf32 => "fabsf",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,7 @@ impl HumanEmitter {
buffer.puts(*row_num, max_line_num_len + 1, "+ ", Style::Addition);
}
[] => {
// FIXME: needed? Doesn't get excercised in any test.
// FIXME: needed? Doesn't get exercised in any test.
self.draw_col_separator_no_space(buffer, *row_num, max_line_num_len + 1);
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/markdown/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn parse_with_end_pat<'a>(
None
}

/// Resturn `(match, residual)` to end of line. The EOL is returned with the
/// Return `(match, residual)` to end of line. The EOL is returned with the
/// residual.
fn parse_to_newline(buf: &[u8]) -> (&[u8], &[u8]) {
buf.iter().position(|ch| *ch == b'\n').map_or((buf, &[]), |pos| buf.split_at(pos))
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ declare_features! (
(accepted, destructuring_assignment, "1.59.0", Some(71126)),
/// Allows using the `#[diagnostic]` attribute tool namespace
(accepted, diagnostic_namespace, "1.78.0", Some(111996)),
/// Controls errors in trait implementations.
(accepted, do_not_recommend, "CURRENT_RUSTC_VERSION", Some(51992)),
/// Allows `#[doc(alias = "...")]`.
(accepted, doc_alias, "1.48.0", Some(50146)),
/// Allows `..` in tuple (struct) patterns.
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,10 +1187,9 @@ pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>>
map
});

pub fn is_stable_diagnostic_attribute(sym: Symbol, features: &Features) -> bool {
pub fn is_stable_diagnostic_attribute(sym: Symbol, _features: &Features) -> bool {
match sym {
sym::on_unimplemented => true,
sym::do_not_recommend => features.do_not_recommend(),
sym::on_unimplemented | sym::do_not_recommend => true,
_ => false,
}
}
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,6 @@ declare_features! (
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
/// Allows deref patterns.
(incomplete, deref_patterns, "1.79.0", Some(87121)),
/// Controls errors in trait implementations.
(unstable, do_not_recommend, "1.67.0", Some(51992)),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
(unstable, doc_auto_cfg, "1.58.0", Some(43781)),
/// Allows `#[doc(cfg(...))]`.
Expand Down
26 changes: 14 additions & 12 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
let mut typeck = self.typeck_results.borrow_mut();
let mut node_ty = typeck.node_types_mut();
if let Some(ty) = node_ty.get(id)
&& let Err(e) = ty.error_reported()
{
// Do not overwrite nodes that were already marked as `{type error}`. This allows us to
// silence unnecessary errors from obligations that were set earlier than a type error
// was produced, but that is overwritten by later analysis. This happens in particular
// for `Sized` obligations introduced in gather_locals. (#117846)
self.set_tainted_by_errors(e);
return;
}

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

if let Err(e) = ty.error_reported() {
self.set_tainted_by_errors(e);
Expand Down Expand Up @@ -1104,7 +1107,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Res::Local(hid) = res {
let ty = self.local_ty(span, hid);
let ty = self.normalize(span, ty);
self.write_ty(hir_id, ty);
return (ty, res);
}

Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,10 +1750,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

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

// Type check the initializer.
if let Some(ref init) = decl.init {
Expand Down Expand Up @@ -1785,11 +1784,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
self.diverges.set(previous_diverges);
}
decl_ty
}

/// Type check a `let` statement.
fn check_decl_local(&self, local: &'tcx hir::LetStmt<'tcx>) {
self.check_decl(local.into());
let ty = self.check_decl(local.into());
self.write_ty(local.hir_id, ty);
if local.pat.is_never_pattern() {
self.diverges.set(Diverges::Always {
span: local.pat.span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ pub struct ParamEnv<'tcx> {
}

impl<'tcx> rustc_type_ir::inherent::ParamEnv<TyCtxt<'tcx>> for ParamEnv<'tcx> {
fn caller_bounds(self) -> impl IntoIterator<Item = ty::Clause<'tcx>> {
fn caller_bounds(self) -> impl inherent::SliceLike<Item = ty::Clause<'tcx>> {
self.caller_bounds()
}
}
Expand Down
Loading

0 comments on commit 367612f

Please sign in to comment.