Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
780319a
stabilize unstable `rwlock_downgrade` feature
connortsui20 Aug 23, 2025
fa9162d
Allow printing a fully-qualified path in `def_path_str`
jyn514 Oct 7, 2025
4dfbf11
cleanup ErrorGuaranteed handling
lcnr Oct 14, 2025
3941b42
return spans out of is_doc_comment to reduce reliance on .span() on a…
jdonszelmann Oct 14, 2025
0935df7
Fix ICE when using contracts on async functions
chenyukang Oct 15, 2025
491bc50
const mem::drop
clarfonthey Oct 15, 2025
07df2ad
Fix some comments
zhetaicheleba Oct 15, 2025
de67ea3
Update t-compiler beta nomination Zulip msg
apiraino Oct 9, 2025
68080de
ignore boring locals when explaining borrow due to drop
lqd Oct 15, 2025
804af99
miri: use allocator_shim_contents codegen helper
RalfJung Oct 15, 2025
87e0f43
Revert unintentional whitespace changes to rustfmt-excluded file
Diggsey Oct 15, 2025
8d6356b
Rollup merge of #143191 - connortsui20:stabilize-rwlock-downgrade, r=…
matthiaskrgr Oct 15, 2025
88efae3
Rollup merge of #147444 - jyn514:fully-qualified-paths, r=nnethercote
matthiaskrgr Oct 15, 2025
a71cd41
Rollup merge of #147527 - apiraino:update-beta-nom-zulip-msg, r=Kobzol
matthiaskrgr Oct 15, 2025
e7c1e19
Rollup merge of #147670 - lcnr:no-ok-ret-guar, r=BoxyUwU
matthiaskrgr Oct 15, 2025
c607de5
Rollup merge of #147676 - jdonszelmann:span-is-doc-comment, r=Guillau…
matthiaskrgr Oct 15, 2025
9bd8aa5
Rollup merge of #147708 - clarfonthey:const-drop, r=oli-obk
matthiaskrgr Oct 15, 2025
6908bca
Rollup merge of #147710 - chenyukang:yukang-fix-ice-contracts-async, …
matthiaskrgr Oct 15, 2025
d7b9e66
Rollup merge of #147716 - zhetaicheleba:master, r=jdonszelmann
matthiaskrgr Oct 15, 2025
212826d
Rollup merge of #147718 - RalfJung:miri-allocator_shim_contents, r=bj…
matthiaskrgr Oct 15, 2025
33c2952
Rollup merge of #147729 - lqd:polonius-diagnostics, r=jackh726
matthiaskrgr Oct 15, 2025
a4d2811
Rollup merge of #147742 - Diggsey:db-fix-miri-whitespace, r=RalfJung
matthiaskrgr Oct 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ impl AttributeExt for Attribute {
/// Returns `true` if it is a sugared doc comment (`///` or `//!` for example).
/// So `#[doc = "doc"]` (which is a doc comment) and `#[doc(...)]` (which is not
/// a doc comment) will return `false`.
fn is_doc_comment(&self) -> bool {
fn is_doc_comment(&self) -> Option<Span> {
match self.kind {
AttrKind::Normal(..) => false,
AttrKind::DocComment(..) => true,
AttrKind::Normal(..) => None,
AttrKind::DocComment(..) => Some(self.span),
}
}

Expand Down Expand Up @@ -776,7 +776,7 @@ pub trait AttributeExt: Debug {
/// Returns `true` if it is a sugared doc comment (`///` or `//!` for example).
/// So `#[doc = "doc"]` (which is a doc comment) and `#[doc(...)]` (which is not
/// a doc comment) will return `false`.
fn is_doc_comment(&self) -> bool;
fn is_doc_comment(&self) -> Option<Span>;

#[inline]
fn has_name(&self, name: Symbol) -> bool {
Expand Down Expand Up @@ -863,8 +863,9 @@ impl Attribute {
AttributeExt::path_matches(self, name)
}

// on ast attributes we return a bool since that's what most code already expects
pub fn is_doc_comment(&self) -> bool {
AttributeExt::is_doc_comment(self)
AttributeExt::is_doc_comment(self).is_some()
}

#[inline]
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_ast/src/expand/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,23 @@ pub enum AllocatorTy {
Usize,
}

/// Some allocator methods are known to the compiler: they act more like
/// intrinsics/language primitives than library-defined functions.
/// FIXME: ideally this would be derived from attributes like `#[rustc_allocator]`,
/// so we don't have two sources of truth.
#[derive(Copy, Clone, Debug)]
pub enum SpecialAllocatorMethod {
Alloc,
AllocZeroed,
Dealloc,
Realloc,
}

/// A method that will be codegened in the allocator shim.
#[derive(Copy, Clone)]
pub struct AllocatorMethod {
pub name: Symbol,
pub special: Option<SpecialAllocatorMethod>,
pub inputs: &'static [AllocatorMethodInput],
pub output: AllocatorTy,
}
Expand All @@ -47,11 +60,13 @@ pub struct AllocatorMethodInput {
pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
AllocatorMethod {
name: sym::alloc,
special: Some(SpecialAllocatorMethod::Alloc),
inputs: &[AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout }],
output: AllocatorTy::ResultPtr,
},
AllocatorMethod {
name: sym::dealloc,
special: Some(SpecialAllocatorMethod::Dealloc),
inputs: &[
AllocatorMethodInput { name: "ptr", ty: AllocatorTy::Ptr },
AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout },
Expand All @@ -60,6 +75,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
},
AllocatorMethod {
name: sym::realloc,
special: Some(SpecialAllocatorMethod::Realloc),
inputs: &[
AllocatorMethodInput { name: "ptr", ty: AllocatorTy::Ptr },
AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout },
Expand All @@ -69,6 +85,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
},
AllocatorMethod {
name: sym::alloc_zeroed,
special: Some(SpecialAllocatorMethod::AllocZeroed),
inputs: &[AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout }],
output: AllocatorTy::ResultPtr,
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
type Item;
/// A function that converts individual items (of type [`Item`](Self::Item)) into the final attribute.
///
/// For example, individual representations fomr `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
/// For example, individual representations from `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
/// where `x` is a vec of these individual reprs.
const CONVERT: ConvertFn<Self::Item>;

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
}

pub fn is_builtin_attr(attr: &impl AttributeExt) -> bool {
attr.is_doc_comment() || attr.ident().is_some_and(|ident| is_builtin_attr_name(ident.name))
attr.is_doc_comment().is_some()
|| attr.ident().is_some_and(|ident| is_builtin_attr_name(ident.name))
}

pub fn is_doc_alias_attrs_contain_symbol<'tcx, T: AttributeExt + 'tcx>(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
}
}

Some(Cause::DropVar(local, location)) => {
Some(Cause::DropVar(local, location)) if !is_local_boring(local) => {
let mut should_note_order = false;
if self.local_name(local).is_some()
&& let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place
Expand All @@ -705,7 +705,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
}
}

Some(Cause::LiveVar(..)) | None => {
Some(Cause::LiveVar(..) | Cause::DropVar(..)) | None => {
// Here, under NLL: no cause was found. Under polonius: no cause was found, or a
// boring local was found, which we ignore like NLLs do to match its diagnostics.
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_builtin_macros/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ fn expand_contract_clause(
.span_err(attr_span, "contract annotations can only be used on functions"));
}

// Contracts are not yet supported on async/gen functions
if new_tts.iter().any(|tt| is_kw(tt, kw::Async) || is_kw(tt, kw::Gen)) {
return Err(ecx.sess.dcx().span_err(
attr_span,
"contract annotations are not yet supported on async or gen functions",
));
}

// Found the `fn` keyword, now find either the `where` token or the function body.
let next_tt = loop {
let Some(tt) = cursor.next() else {
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use libc::c_uint;
use rustc_ast::expand::allocator::{
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, SpecialAllocatorMethod,
default_fn_name, global_fn_name,
};
use rustc_codegen_ssa::traits::BaseTypeCodegenMethods as _;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{DebugInfo, OomStrategy};
use rustc_span::sym;
use rustc_symbol_mangling::mangle_internal_symbol;

use crate::attributes::llfn_attrs_from_instance;
Expand Down Expand Up @@ -65,12 +65,12 @@ pub(crate) unsafe fn codegen(
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));

let alloc_attr_flag = match method.name {
sym::alloc => CodegenFnAttrFlags::ALLOCATOR,
sym::dealloc => CodegenFnAttrFlags::DEALLOCATOR,
sym::realloc => CodegenFnAttrFlags::REALLOCATOR,
sym::alloc_zeroed => CodegenFnAttrFlags::ALLOCATOR_ZEROED,
_ => CodegenFnAttrFlags::empty(),
let alloc_attr_flag = match method.special {
Some(SpecialAllocatorMethod::Alloc) => CodegenFnAttrFlags::ALLOCATOR,
Some(SpecialAllocatorMethod::Dealloc) => CodegenFnAttrFlags::DEALLOCATOR,
Some(SpecialAllocatorMethod::Realloc) => CodegenFnAttrFlags::REALLOCATOR,
Some(SpecialAllocatorMethod::AllocZeroed) => CodegenFnAttrFlags::ALLOCATOR_ZEROED,
None => CodegenFnAttrFlags::empty(),
};

let mut attrs = CodegenFnAttrs::new();
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ pub fn allocator_shim_contents(tcx: TyCtxt<'_>, kind: AllocatorKind) -> Vec<Allo
if tcx.alloc_error_handler_kind(()).unwrap() == AllocatorKind::Default {
methods.push(AllocatorMethod {
name: ALLOC_ERROR_HANDLER,
special: None,
inputs: &[],
output: AllocatorTy::Never,
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ enum NodeState<N, S, A: Annotation> {
#[derive(Copy, Clone, Debug)]
enum WalkReturn<S, A: Annotation> {
/// The walk found a cycle, but the entire component is not known to have
/// been fully walked yet. We only know the minimum depth of this
/// been fully walked yet. We only know the minimum depth of this
/// component in a minimum spanning tree of the graph. This component
/// is tentatively represented by the state of the first node of this
/// cycle we met, which is at `min_depth`.
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,12 @@ impl AttributeExt for Attribute {
}

#[inline]
fn is_doc_comment(&self) -> bool {
matches!(self, Attribute::Parsed(AttributeKind::DocComment { .. }))
fn is_doc_comment(&self) -> Option<Span> {
if let Attribute::Parsed(AttributeKind::DocComment { span, .. }) = self {
Some(*span)
} else {
None
}
}

#[inline]
Expand Down Expand Up @@ -1423,7 +1427,7 @@ impl Attribute {
}

#[inline]
pub fn is_doc_comment(&self) -> bool {
pub fn is_doc_comment(&self) -> Option<Span> {
AttributeExt::is_doc_comment(self)
}

Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1651,9 +1651,7 @@ fn check_method_receiver<'tcx>(

// If the receiver already has errors reported, consider it valid to avoid
// unnecessary errors (#58712).
if receiver_ty.references_error() {
return Ok(());
}
receiver_ty.error_reported()?;

let arbitrary_self_types_level = if tcx.features().arbitrary_self_types_pointers() {
Some(ArbitrarySelfTypesLevel::WithPointers)
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_analysis/src/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ fn check_impl<'tcx>(

// Skip impls where one of the self type is an error type.
// This occurs with e.g., resolve failures (#30589).
if trait_ref.references_error() {
return Ok(());
}
trait_ref.error_reported()?;

enforce_trait_manually_implementable(tcx, impl_def_id, trait_ref.def_id, trait_def)
.and(enforce_empty_impls_for_marker_traits(tcx, impl_def_id, trait_ref.def_id, trait_def))
Expand Down Expand Up @@ -188,9 +186,9 @@ fn check_object_overlap<'tcx>(
) -> Result<(), ErrorGuaranteed> {
let trait_def_id = trait_ref.def_id;

if trait_ref.references_error() {
if let Err(guar) = trait_ref.error_reported() {
debug!("coherence: skipping impl {:?} with error {:?}", impl_def_id, trait_ref);
return Ok(());
return Err(guar);
}

// check for overlap with the automatic `impl Trait for dyn Trait`
Expand Down
37 changes: 9 additions & 28 deletions compiler/rustc_hir_analysis/src/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,10 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
impl_def_id: LocalDefId,
) -> Result<(), ErrorGuaranteed> {
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
if impl_self_ty.references_error() {
// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
tcx.dcx().span_delayed_bug(
tcx.def_span(impl_def_id),
format!(
"potentially unconstrained type parameters weren't evaluated: {impl_self_ty:?}",
),
);
// This is super fishy, but our current `rustc_hir_analysis::check_crate` pipeline depends on
// `type_of` having been called much earlier, and thus this value being read from cache.
// Compilation must continue in order for other important diagnostics to keep showing up.
return Ok(());
}

// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
impl_self_ty.error_reported()?;

let impl_generics = tcx.generics_of(impl_def_id);
let impl_predicates = tcx.predicates_of(impl_def_id);
Expand Down Expand Up @@ -174,20 +164,11 @@ pub(crate) fn enforce_impl_non_lifetime_params_are_constrained(
impl_def_id: LocalDefId,
) -> Result<(), ErrorGuaranteed> {
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
if impl_self_ty.references_error() {
// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
tcx.dcx().span_delayed_bug(
tcx.def_span(impl_def_id),
format!(
"potentially unconstrained type parameters weren't evaluated: {impl_self_ty:?}",
),
);
// This is super fishy, but our current `rustc_hir_analysis::check_crate` pipeline depends on
// `type_of` having been called much earlier, and thus this value being read from cache.
// Compilation must continue in order for other important diagnostics to keep showing up.
return Ok(());
}

// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
impl_self_ty.error_reported()?;

let impl_generics = tcx.generics_of(impl_def_id);
let impl_predicates = tcx.predicates_of(impl_def_id);
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::instantiate_identity);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
let ty =
self.check_expr_with_expectation_and_needs(oprnd, hint, Needs::maybe_mut_place(mutbl));
if let Err(guar) = ty.error_reported() {
return Ty::new_error(self.tcx, guar);
}

match kind {
_ if ty.references_error() => Ty::new_misc_error(self.tcx),
hir::BorrowKind::Raw => {
self.check_named_place_expr(oprnd);
Ty::new_ptr(self.tcx, ty, mutbl)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ pub struct MissingDoc;
impl_lint_pass!(MissingDoc => [MISSING_DOCS]);

fn has_doc(attr: &hir::Attribute) -> bool {
if attr.is_doc_comment() {
if attr.is_doc_comment().is_some() {
return true;
}

Expand Down
14 changes: 13 additions & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::ty::{

thread_local! {
static FORCE_IMPL_FILENAME_LINE: Cell<bool> = const { Cell::new(false) };
static SHOULD_PREFIX_WITH_CRATE_NAME: Cell<bool> = const { Cell::new(false) };
static SHOULD_PREFIX_WITH_CRATE: Cell<bool> = const { Cell::new(false) };
static NO_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
static FORCE_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
Expand Down Expand Up @@ -98,7 +99,18 @@ define_helper!(
/// cycle errors, this can result in extra or suboptimal error output,
/// so this variable disables that check.
fn with_forced_impl_filename_line(ForcedImplGuard, FORCE_IMPL_FILENAME_LINE);
/// Adds the crate name prefix to paths where appropriate.
/// Unlike `with_crate_prefix`, this unconditionally uses `tcx.crate_name` instead of sometimes
/// using `crate::` for local items.
///
/// Overrides `with_crate_prefix`.

// This function is not currently used in-tree, but it's used by a downstream rustc-driver in
// Ferrocene. Please check with them before removing it.
fn with_resolve_crate_name(CrateNamePrefixGuard, SHOULD_PREFIX_WITH_CRATE_NAME);
/// Adds the `crate::` prefix to paths where appropriate.
///
/// Ignored if `with_resolve_crate_name` is active.
fn with_crate_prefix(CratePrefixGuard, SHOULD_PREFIX_WITH_CRATE);
/// Prevent path trimming if it is turned on. Path trimming affects `Display` impl
/// of various rustc types, for example `std::vec::Vec` would be trimmed to `Vec`,
Expand Down Expand Up @@ -2313,7 +2325,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {

fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
self.empty_path = true;
if cnum == LOCAL_CRATE {
if cnum == LOCAL_CRATE && !with_resolve_crate_name() {
if self.tcx.sess.at_least_rust_2018() {
// We add the `crate::` keyword on Rust 2018, only when desired.
if with_crate_prefix() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for [hir::Attribute] {
let filtered: SmallVec<[&hir::Attribute; 8]> = self
.iter()
.filter(|attr| {
!attr.is_doc_comment()
attr.is_doc_comment().is_none()
// FIXME(jdonszelmann) have a better way to handle ignored attrs
&& !attr.ident().is_some_and(|ident| hcx.is_ignored_attr(ident.name))
})
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ pub fn attrs_to_doc_fragments<'a, A: AttributeExt + Clone + 'a>(
for (attr, item_id) in attrs {
if let Some((doc_str, comment_kind)) = attr.doc_str_and_comment_kind() {
let doc = beautify_doc_string(doc_str, comment_kind);
let (span, kind, from_expansion) = if attr.is_doc_comment() {
let span = attr.span();
let (span, kind, from_expansion) = if let Some(span) = attr.is_doc_comment() {
(span, DocFragmentKind::SugaredDoc, span.from_expansion())
} else {
let attr_span = attr.span();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_sanitizers/src/cfi/typeid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bitflags! {
const GENERALIZE_REPR_C = 2;
/// Normalizes integers for compatibility with Clang
/// `-fsanitize-cfi-icall-experimental-normalize-integers` option for cross-language LLVM
/// CFI and KCFI support.
/// CFI and KCFI support.
const NORMALIZE_INTEGERS = 4;
/// Do not perform self type erasure for attaching a secondary type id to methods with their
/// concrete self so they can be used as function pointers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
pub struct OnUnimplementedFormatString {
/// Symbol of the format string, i.e. `"content"`
symbol: Symbol,
///The span of the format string, i.e. `"content"`
/// The span of the format string, i.e. `"content"`
span: Span,
is_diagnostic_namespace_variant: bool,
}
Expand Down
Loading
Loading