Skip to content

Commit 402ce0e

Browse files
committed
Auto merge of #147745 - matthiaskrgr:rollup-b4kftk9, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #143191 (Stabilize `rwlock_downgrade` library feature) - #147444 (Allow printing a fully-qualified path in `def_path_str`) - #147527 (Update t-compiler beta nomination Zulip msg) - #147670 (some `ErrorGuaranteed` cleanups) - #147676 (Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes) - #147708 (const `mem::drop`) - #147710 (Fix ICE when using contracts on async functions) - #147716 (Fix some comments) - #147718 (miri: use allocator_shim_contents codegen helper) - #147729 (ignore boring locals when explaining why a borrow contains a point due to drop of a live local under polonius) - #147742 (Revert unintentional whitespace changes to rustfmt-excluded file) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 57ef8d6 + a4d2811 commit 402ce0e

File tree

40 files changed

+421
-373
lines changed

40 files changed

+421
-373
lines changed

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ impl AttributeExt for Attribute {
8686
/// Returns `true` if it is a sugared doc comment (`///` or `//!` for example).
8787
/// So `#[doc = "doc"]` (which is a doc comment) and `#[doc(...)]` (which is not
8888
/// a doc comment) will return `false`.
89-
fn is_doc_comment(&self) -> bool {
89+
fn is_doc_comment(&self) -> Option<Span> {
9090
match self.kind {
91-
AttrKind::Normal(..) => false,
92-
AttrKind::DocComment(..) => true,
91+
AttrKind::Normal(..) => None,
92+
AttrKind::DocComment(..) => Some(self.span),
9393
}
9494
}
9595

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

781781
#[inline]
782782
fn has_name(&self, name: Symbol) -> bool {
@@ -863,8 +863,9 @@ impl Attribute {
863863
AttributeExt::path_matches(self, name)
864864
}
865865

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

870871
#[inline]

compiler/rustc_ast/src/expand/allocator.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,23 @@ pub enum AllocatorTy {
3131
Usize,
3232
}
3333

34+
/// Some allocator methods are known to the compiler: they act more like
35+
/// intrinsics/language primitives than library-defined functions.
36+
/// FIXME: ideally this would be derived from attributes like `#[rustc_allocator]`,
37+
/// so we don't have two sources of truth.
38+
#[derive(Copy, Clone, Debug)]
39+
pub enum SpecialAllocatorMethod {
40+
Alloc,
41+
AllocZeroed,
42+
Dealloc,
43+
Realloc,
44+
}
45+
3446
/// A method that will be codegened in the allocator shim.
3547
#[derive(Copy, Clone)]
3648
pub struct AllocatorMethod {
3749
pub name: Symbol,
50+
pub special: Option<SpecialAllocatorMethod>,
3851
pub inputs: &'static [AllocatorMethodInput],
3952
pub output: AllocatorTy,
4053
}
@@ -47,11 +60,13 @@ pub struct AllocatorMethodInput {
4760
pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
4861
AllocatorMethod {
4962
name: sym::alloc,
63+
special: Some(SpecialAllocatorMethod::Alloc),
5064
inputs: &[AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout }],
5165
output: AllocatorTy::ResultPtr,
5266
},
5367
AllocatorMethod {
5468
name: sym::dealloc,
69+
special: Some(SpecialAllocatorMethod::Dealloc),
5570
inputs: &[
5671
AllocatorMethodInput { name: "ptr", ty: AllocatorTy::Ptr },
5772
AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout },
@@ -60,6 +75,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
6075
},
6176
AllocatorMethod {
6277
name: sym::realloc,
78+
special: Some(SpecialAllocatorMethod::Realloc),
6379
inputs: &[
6480
AllocatorMethodInput { name: "ptr", ty: AllocatorTy::Ptr },
6581
AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout },
@@ -69,6 +85,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
6985
},
7086
AllocatorMethod {
7187
name: sym::alloc_zeroed,
88+
special: Some(SpecialAllocatorMethod::AllocZeroed),
7289
inputs: &[AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout }],
7390
output: AllocatorTy::ResultPtr,
7491
},

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
302302
type Item;
303303
/// A function that converts individual items (of type [`Item`](Self::Item)) into the final attribute.
304304
///
305-
/// For example, individual representations fomr `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
305+
/// For example, individual representations from `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
306306
/// where `x` is a vec of these individual reprs.
307307
const CONVERT: ConvertFn<Self::Item>;
308308

compiler/rustc_attr_parsing/src/attributes/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
2828
}
2929

3030
pub fn is_builtin_attr(attr: &impl AttributeExt) -> bool {
31-
attr.is_doc_comment() || attr.ident().is_some_and(|ident| is_builtin_attr_name(ident.name))
31+
attr.is_doc_comment().is_some()
32+
|| attr.ident().is_some_and(|ident| is_builtin_attr_name(ident.name))
3233
}
3334

3435
pub fn is_doc_alias_attrs_contain_symbol<'tcx, T: AttributeExt + 'tcx>(

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
687687
}
688688
}
689689

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

708-
Some(Cause::LiveVar(..)) | None => {
708+
Some(Cause::LiveVar(..) | Cause::DropVar(..)) | None => {
709709
// Here, under NLL: no cause was found. Under polonius: no cause was found, or a
710710
// boring local was found, which we ignore like NLLs do to match its diagnostics.
711711
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {

compiler/rustc_builtin_macros/src/contracts.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ fn expand_contract_clause(
7171
.span_err(attr_span, "contract annotations can only be used on functions"));
7272
}
7373

74+
// Contracts are not yet supported on async/gen functions
75+
if new_tts.iter().any(|tt| is_kw(tt, kw::Async) || is_kw(tt, kw::Gen)) {
76+
return Err(ecx.sess.dcx().span_err(
77+
attr_span,
78+
"contract annotations are not yet supported on async or gen functions",
79+
));
80+
}
81+
7482
// Found the `fn` keyword, now find either the `where` token or the function body.
7583
let next_tt = loop {
7684
let Some(tt) = cursor.next() else {

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use libc::c_uint;
22
use rustc_ast::expand::allocator::{
3-
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
3+
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, SpecialAllocatorMethod,
4+
default_fn_name, global_fn_name,
45
};
56
use rustc_codegen_ssa::traits::BaseTypeCodegenMethods as _;
67
use rustc_middle::bug;
78
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
89
use rustc_middle::ty::TyCtxt;
910
use rustc_session::config::{DebugInfo, OomStrategy};
10-
use rustc_span::sym;
1111
use rustc_symbol_mangling::mangle_internal_symbol;
1212

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

68-
let alloc_attr_flag = match method.name {
69-
sym::alloc => CodegenFnAttrFlags::ALLOCATOR,
70-
sym::dealloc => CodegenFnAttrFlags::DEALLOCATOR,
71-
sym::realloc => CodegenFnAttrFlags::REALLOCATOR,
72-
sym::alloc_zeroed => CodegenFnAttrFlags::ALLOCATOR_ZEROED,
73-
_ => CodegenFnAttrFlags::empty(),
68+
let alloc_attr_flag = match method.special {
69+
Some(SpecialAllocatorMethod::Alloc) => CodegenFnAttrFlags::ALLOCATOR,
70+
Some(SpecialAllocatorMethod::Dealloc) => CodegenFnAttrFlags::DEALLOCATOR,
71+
Some(SpecialAllocatorMethod::Realloc) => CodegenFnAttrFlags::REALLOCATOR,
72+
Some(SpecialAllocatorMethod::AllocZeroed) => CodegenFnAttrFlags::ALLOCATOR_ZEROED,
73+
None => CodegenFnAttrFlags::empty(),
7474
};
7575

7676
let mut attrs = CodegenFnAttrs::new();

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ pub fn allocator_shim_contents(tcx: TyCtxt<'_>, kind: AllocatorKind) -> Vec<Allo
669669
if tcx.alloc_error_handler_kind(()).unwrap() == AllocatorKind::Default {
670670
methods.push(AllocatorMethod {
671671
name: ALLOC_ERROR_HANDLER,
672+
special: None,
672673
inputs: &[],
673674
output: AllocatorTy::Never,
674675
});

compiler/rustc_data_structures/src/graph/scc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ enum NodeState<N, S, A: Annotation> {
289289
#[derive(Copy, Clone, Debug)]
290290
enum WalkReturn<S, A: Annotation> {
291291
/// The walk found a cycle, but the entire component is not known to have
292-
/// been fully walked yet. We only know the minimum depth of this
292+
/// been fully walked yet. We only know the minimum depth of this
293293
/// component in a minimum spanning tree of the graph. This component
294294
/// is tentatively represented by the state of the first node of this
295295
/// cycle we met, which is at `min_depth`.

compiler/rustc_hir/src/hir.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,8 +1304,12 @@ impl AttributeExt for Attribute {
13041304
}
13051305

13061306
#[inline]
1307-
fn is_doc_comment(&self) -> bool {
1308-
matches!(self, Attribute::Parsed(AttributeKind::DocComment { .. }))
1307+
fn is_doc_comment(&self) -> Option<Span> {
1308+
if let Attribute::Parsed(AttributeKind::DocComment { span, .. }) = self {
1309+
Some(*span)
1310+
} else {
1311+
None
1312+
}
13091313
}
13101314

13111315
#[inline]
@@ -1423,7 +1427,7 @@ impl Attribute {
14231427
}
14241428

14251429
#[inline]
1426-
pub fn is_doc_comment(&self) -> bool {
1430+
pub fn is_doc_comment(&self) -> Option<Span> {
14271431
AttributeExt::is_doc_comment(self)
14281432
}
14291433

0 commit comments

Comments
 (0)