Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion compiler/rustc_borrowck/src/places_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ fn place_components_conflict<'tcx>(

// Given that the bases of `elem1` and `elem2` are always either equal
// or disjoint (and have the same type!), return the overlap situation
// between `elem1` and `elem2`.
// between `elem1` and `elem2`
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn place_projection_conflict<'tcx>(
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ impl<'tcx> UniversalRegions<'tcx> {
/// that this region imposes on others. The methods in this file
/// handle the part about dumping the inference context internal
/// state.
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_, ()>) {
match self.defining_ty {
DefiningTy::Closure(def_id, args) => {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ mod llvm_enzyme {
// ```
// std::intrinsics::autodiff(source as fn(..) -> .., diff, (args))
// ```
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn call_autodiff(
ecx: &ExtCtxt<'_>,
primal: Ident,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_cranelift/src/debuginfo/unwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) struct UnwindContext {
}

impl UnwindContext {
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
pub(crate) fn new(module: &mut dyn Module, pic_eh_frame: bool) -> Self {
let endian = match module.isa().endianness() {
Endianness::Little => RunTimeEndian::Little,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::inline_asm::{CInlineAsmOperand, codegen_inline_asm_inner};
use crate::intrinsics::*;
use crate::prelude::*;

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
pub(super) fn codegen_x86_llvm_intrinsic_call<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>,
intrinsic: &str,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl<'tcx> CValue<'tcx> {
}
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
pub(crate) fn value_field(
self,
fx: &mut FunctionCx<'_, '_, 'tcx>,
Expand Down Expand Up @@ -520,6 +521,7 @@ impl<'tcx> CPlace<'tcx> {
self.write_cvalue_maybe_transmute(fx, from, "write_cvalue_transmute");
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn write_cvalue_maybe_transmute(
self,
fx: &mut FunctionCx<'_, '_, 'tcx>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
.get_address(self.location)
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn scalable_alloca(&mut self, _elt: u64, _align: Align, _element_ty: Ty<'_>) -> RValue<'gcc> {
todo!()
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_gcc/src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn uncached_gcc_type<'gcc, 'tcx>(
cx: &CodegenCx<'gcc, 'tcx>,
layout: TyAndLayout<'tcx>,
Expand Down Expand Up @@ -177,6 +178,7 @@ pub trait LayoutGccExt<'tcx> {
}

impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn is_gcc_immediate(&self) -> bool {
match self.backend_repr {
BackendRepr::Scalar(_) | BackendRepr::SimdVector { .. } => true,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
/// at that type. Return `true` if the type is indeed primitive.
///
/// Note that not all of these have `FieldsShape::Primitive`, e.g. wide references.
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn try_visit_primitive(
&mut self,
value: &PlaceTy<'tcx, M::Provenance>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,7 @@ impl InvocationCollectorNode for ast::Pat {
_ => unreachable!(),
}
}
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn as_target(&self) -> Target {
todo!();
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ enum PointerKind<'tcx> {
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Returns the kind of unsize information of t, or None
/// if t is unknown.
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn pointer_kind(
&self,
t: Ty<'tcx>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct ClosureSignatures<'tcx> {

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
#[instrument(skip(self, closure), level = "debug")]
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
pub(crate) fn check_expr_closure(
&self,
closure: &hir::Closure<'tcx>,
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_hir_typeck/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,3 +1384,7 @@ pub(crate) struct ProjectOnNonPinProjectType {
)]
pub sugg_span: Option<Span>,
}

#[derive(Diagnostic)]
#[diag("`todo!()` macro used")]
pub(crate) struct TodoMacroUse;
20 changes: 19 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if self.try_structurally_resolve_type(expr.span, ty).is_never()
&& self.tcx.expr_guaranteed_to_constitute_read_for_never(expr)
{
self.diverges.set(self.diverges.get() | Diverges::always(expr.span));
// We only check expansion for calls, because `todo!()` either expands to
// a call to `::core::panicking::panic` or `::core::panicking::panic_fmt`
let diverges = if let ExprKind::Call(..) = expr.kind
&& self.tcx.is_locally_expanded_by(expr.span, sym::todo_macro)
{
self.tcx.emit_node_span_lint(
rustc_lint::builtin::TODO_MACRO_CALLS, // ignore-tidy-todo
expr.hir_id,
expr.span,
crate::errors::TodoMacroUse,
);
// We don't trigger `unreachable_code` for `todo!()` within this crate's code
// that diverges to avoid flooding the user with warnings while they are still
// working on their code.
Diverges::WarnedAlways
} else {
Diverges::always(expr.span)
};
self.diverges.set(self.diverges.get() | diverges);
}

// Record the type, which applies it effects.
Expand Down
23 changes: 23 additions & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ declare_lint_pass! {
TEST_UNSTABLE_LINT,
TEXT_DIRECTION_CODEPOINT_IN_COMMENT,
TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
TODO_MACRO_CALLS, // ignore-tidy-todo
TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS,
TYVAR_BEHIND_RAW_POINTER,
Expand Down Expand Up @@ -832,6 +833,28 @@ declare_lint! {
report_in_external_macro
}

declare_lint! {
/// The `todos` lint detects calls of the `todo!()` macro.
///
/// ### Example
///
/// ```rust,no_run
/// todo!();
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// This macro is ignored during checking for unreachable code, as it is
/// meant for a stand in for code yet to be produced. It is considered
/// bad form to leave it in production code.
/* ignore-tidy-todo */ pub TODO_MACRO_CALLS,
Warn,
"detects `todo!()` macro calls",
report_in_external_macro
}

declare_lint! {
/// The `unreachable_patterns` lint detects unreachable patterns.
///
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/mir/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ impl<O> AssertKind<O> {
/// Note that we deliberately show more details here than we do at runtime, such as the actual
/// numbers that overflowed -- it is much easier to do so here than at runtime.
impl<O: fmt::Debug> fmt::Display for AssertKind<O> {
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
use AssertKind::*;

Expand Down
40 changes: 39 additions & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use rustc_session::config::CrateType;
use rustc_session::cstore::{CrateStoreDyn, Untracked};
use rustc_session::lint::Lint;
use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw};
use rustc_span::{DUMMY_SP, ExpnData, Ident, Span, Symbol, SyntaxContext, kw};
use rustc_type_ir::TyKind::*;
pub use rustc_type_ir::lift::Lift;
use rustc_type_ir::{CollectAndApply, TypeFlags, WithCachedTypeInfo, elaborate, search_graph};
Expand Down Expand Up @@ -1345,6 +1345,44 @@ impl<'tcx> TyCtxt<'tcx> {
None => Err(VarError::NotPresent),
}
}

/// Returns whether this context was expanded by the macro with the given name where
/// the macro call is local in the current crate.
pub fn is_locally_expanded_by(self, span: Span, mac: Symbol) -> bool {
let source_map = self.sess.source_map();
let mut ctxt = span.ctxt();
let Some(mac_def_id) = self.get_diagnostic_item(mac) else {
// do not have a def id to search for, so no match is possible
return false;
};
// first, find the `todo!` call site
let todo_ctxt = loop {
if ctxt.is_root() {
return false;
}
let data = ctxt.outer_expn_data();
if let Some(def_id) = data.macro_def_id
&& mac_def_id == def_id
{
break ctxt;
}
ctxt = data.call_site.ctxt();
};
// get the crate of the root context
let crate_num = |data: &ExpnData| source_map.lookup_source_file(data.call_site.lo()).cnum;
let root_source_crate_num = crate_num(&SyntaxContext::root().outer_expn_data());
// check that all expansions between the `todo!()` call and the root context
// are in the same file as the root context
let mut ctxt = todo_ctxt;
while !ctxt.is_root() {
let data = ctxt.outer_expn_data();
if crate_num(&data) != root_source_crate_num {
return false;
}
ctxt = data.call_site.ctxt();
}
true
}
}

impl<'tcx> TyCtxtAt<'tcx> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,7 @@ impl<'tcx> Ty<'tcx> {

/// Returns the type of metadata for (potentially wide) pointers to this type,
/// or the struct tail if the metadata type cannot be determined.
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
pub fn ptr_metadata_ty_or_tail(
self,
tcx: TyCtxt<'tcx>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ impl<'tcx> Ty<'tcx> {
///
/// Returning true means the type is known to be `!AsyncDrop`. Returning
/// `false` means nothing -- could be `AsyncDrop`, might not be.
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn is_trivially_not_async_drop(self) -> bool {
match self.kind() {
ty::Int(_)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_dataflow/src/value_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ impl<'tcx> Map<'tcx> {
}

#[tracing::instrument(level = "trace", skip(self, tcx, body), ret)]
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
pub fn register_place(
&mut self,
tcx: TyCtxt<'tcx>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
}
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn fold_const(&mut self, c: I::Const) -> I::Const {
if !c.flags().intersects(NEEDS_CANONICAL) {
return c;
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_next_trait_solver/src/solve/effect_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ where
})
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn consider_builtin_fn_ptr_trait_candidate(
_ecx: &mut EvalCtxt<'_, D>,
_goal: Goal<I, Self>,
Expand Down Expand Up @@ -316,6 +317,7 @@ where
)
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn consider_builtin_async_fn_trait_candidates(
_ecx: &mut EvalCtxt<'_, D>,
_goal: Goal<I, Self>,
Expand Down Expand Up @@ -352,6 +354,7 @@ where
unreachable!("Future is not const")
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn consider_builtin_iterator_candidate(
_ecx: &mut EvalCtxt<'_, D>,
_goal: Goal<I, Self>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ where
panic!("`Tuple` does not have an associated type: {:?}", goal);
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn consider_builtin_pointee_candidate(
ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, Self>,
Expand Down Expand Up @@ -871,6 +872,7 @@ where
panic!("`Unsize` does not have an associated type: {:?}", goal);
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn consider_builtin_discriminant_kind_candidate(
ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, Self>,
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_public/src/unstable/convert/stable/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ impl<'tcx> Stable<'tcx> for mir::StatementKind<'tcx> {

impl<'tcx> Stable<'tcx> for mir::Rvalue<'tcx> {
type T = crate::mir::Rvalue;

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn stable<'cx>(
&self,
tables: &mut Tables<'cx, BridgeTys>,
Expand Down Expand Up @@ -413,6 +415,8 @@ impl<'tcx> Stable<'tcx> for mir::Place<'tcx> {

impl<'tcx> Stable<'tcx> for mir::PlaceElem<'tcx> {
type T = crate::mir::ProjectionElem;

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn stable<'cx>(
&self,
tables: &mut Tables<'cx, BridgeTys>,
Expand Down Expand Up @@ -700,6 +704,8 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {

impl<'tcx> Stable<'tcx> for mir::TerminatorKind<'tcx> {
type T = crate::mir::TerminatorKind;

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn stable<'cx>(
&self,
tables: &mut Tables<'cx, BridgeTys>,
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_public/src/unstable/convert/stable/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ impl<'tcx> Stable<'tcx> for Ty<'tcx> {

impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
type T = crate::ty::TyKind;
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn stable<'cx>(
&self,
tables: &mut Tables<'cx, BridgeTys>,
Expand Down Expand Up @@ -475,6 +476,7 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> {
type T = crate::ty::Pattern;

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn stable<'cx>(
&self,
tables: &mut Tables<'cx, BridgeTys>,
Expand Down Expand Up @@ -720,6 +722,7 @@ impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> {
impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> {
type T = crate::ty::ClauseKind;

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn stable<'cx>(
&self,
tables: &mut Tables<'cx, BridgeTys>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ fn encode_region<'tcx>(region: Region<'tcx>, dict: &mut FxHashMap<DictKey<'tcx>,
/// Encodes a ty:Ty using the Itanium C++ ABI with vendor extended type qualifiers and types for
/// Rust types that are not used at the FFI boundary.
#[instrument(level = "trace", skip(tcx, dict))]
#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
pub(crate) fn encode_ty<'tcx>(
tcx: TyCtxt<'tcx>,
ty: Ty<'tcx>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,7 @@ symbols! {
tmm_reg,
to_string,
to_vec,
todo_macro,
tool_attributes,
tool_lints,
trace_macros,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
Ok(())
}

#[cfg_attr(not(bootstrap), allow(todo_macro_calls))]
fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> {
// Basic types, never cached (single-character).
let basic_type = match ty.kind() {
Expand Down
Loading
Loading