Skip to content

Rollup of 7 pull requests #138611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d183da6
Install licenses into `share/doc/rust/licenses`
cuviper Mar 12, 2025
bca5f56
Add a mir-opt test that demonstrates user type annotations
Zalathar Feb 23, 2025
977106a
Simplify handling of `visibility_scope` in `declare_bindings`
Zalathar Feb 16, 2025
7805b46
Split `visit_primary_bindings` into two variants
Zalathar Feb 15, 2025
5434242
Build `UserTypeProjections` lazily when visiting bindings
Zalathar Feb 20, 2025
2439623
Make ControlFlow must_use
compiler-errors Feb 22, 2025
380ce74
Suppress must_use in compiler and tools
compiler-errors Feb 22, 2025
e250bd1
Suppress must_use for ControlFlow in rust-analyzer
compiler-errors Feb 22, 2025
2ff2815
rustdoc-json: Add tests for `#[deprecated(...)]`
aDotInTheVoid Mar 16, 2025
a8a913d
rustdoc: Rename `Item::attributes` param to `is_json`
aDotInTheVoid Mar 16, 2025
677489f
rustdoc-json: Don't also include `#[deprecated]` in `Item::attrs`
aDotInTheVoid Mar 16, 2025
87457f6
Inline and remove `LoweringContext::new_named_lifetime_with_res`.
nnethercote Mar 17, 2025
fe4d144
Avoid double lowering of lifetime identifiers.
nnethercote Mar 17, 2025
6496d69
Make the `match` in `new_named_lifetime` exhaustive.
nnethercote Mar 17, 2025
adf2bb7
Avoid double lowering of generic identifiers.
nnethercote Mar 17, 2025
b30cf11
Emit function declarations for functions with #[linkage="extern_weak"]
1c3t3a Mar 11, 2025
292c622
Stabilize asm_goto
nbdd0121 Dec 2, 2024
3d3f817
Rollup merge of #133870 - nbdd0121:asm, r=traviscross,nnethercote
matthiaskrgr Mar 17, 2025
9adf218
Rollup merge of #137449 - compiler-errors:control-flow, r=Amanieu,lni…
matthiaskrgr Mar 17, 2025
fd4ad33
Rollup merge of #137465 - Zalathar:visit-primary, r=oli-obk
matthiaskrgr Mar 17, 2025
8f5c09b
Rollup merge of #138349 - 1c3t3a:external-weak-cfi, r=rcvalle
matthiaskrgr Mar 17, 2025
78d141f
Rollup merge of #138412 - cuviper:licenses, r=jieyouxu
matthiaskrgr Mar 17, 2025
b15e663
Rollup merge of #138577 - aDotInTheVoid:deprecate-deprecations, r=Gui…
matthiaskrgr Mar 17, 2025
1e58d51
Rollup merge of #138588 - nnethercote:avoid-double-lower_ident, r=com…
matthiaskrgr Mar 17, 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
2 changes: 0 additions & 2 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ ast_lowering_underscore_expr_lhs_assign =
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
using both label and output operands for inline assembly is unstable
ast_lowering_unstable_inline_assembly_label_operands =
label operands for inline assembly are unstable
ast_lowering_unstable_may_unwind = the `may_unwind` option is unstable
ast_lowering_use_angle_brackets = use angle brackets instead
Expand Down
15 changes: 2 additions & 13 deletions compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,22 +470,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}

// Feature gate checking for asm goto.
// Feature gate checking for `asm_goto_with_outputs`.
if let Some((_, op_sp)) =
operands.iter().find(|(op, _)| matches!(op, hir::InlineAsmOperand::Label { .. }))
{
if !self.tcx.features().asm_goto() {
feature_err(
sess,
sym::asm_goto,
*op_sp,
fluent::ast_lowering_unstable_inline_assembly_label_operands,
)
.emit();
}

// In addition, check if an output operand is used.
// This is gated behind an additional feature.
// Check if an output operand is used.
let output_operand_used = operands.iter().any(|(op, _)| {
matches!(
op,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,6 @@ impl<'hir> LoweringContext<'_, 'hir> {

let bounds = self.lower_param_bounds(bounds, itctx);

let ident = self.lower_ident(ident);
let param_span = ident.span;

// Reconstruct the span of the entire predicate from the individual generic bounds.
Expand All @@ -1739,6 +1738,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let def_id = self.local_def_id(id).to_def_id();
let hir_id = self.next_id();
let res = Res::Def(DefKind::TyParam, def_id);
let ident = self.lower_ident(ident);
let ty_path = self.arena.alloc(hir::Path {
span: param_span,
res,
Expand All @@ -1757,7 +1757,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
})
}
GenericParamKind::Lifetime => {
let ident = self.lower_ident(ident);
let lt_id = self.next_node_id();
let lifetime = self.new_named_lifetime(id, lt_id, ident);
hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {
Expand Down
28 changes: 8 additions & 20 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1769,17 +1769,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

fn lower_lifetime(&mut self, l: &Lifetime) -> &'hir hir::Lifetime {
let ident = self.lower_ident(l.ident);
self.new_named_lifetime(l.id, l.id, ident)
self.new_named_lifetime(l.id, l.id, l.ident)
}

#[instrument(level = "debug", skip(self))]
fn new_named_lifetime_with_res(
fn new_named_lifetime(
&mut self,
id: NodeId,
new_id: NodeId,
ident: Ident,
res: LifetimeRes,
) -> &'hir hir::Lifetime {
let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
let res = match res {
LifetimeRes::Param { param, .. } => hir::LifetimeName::Param(param),
LifetimeRes::Fresh { param, .. } => {
Expand All @@ -1789,31 +1789,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
LifetimeRes::Infer => hir::LifetimeName::Infer,
LifetimeRes::Static { .. } => hir::LifetimeName::Static,
LifetimeRes::Error => hir::LifetimeName::Error,
res => panic!(
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
res, ident, ident.span
),
LifetimeRes::ElidedAnchor { .. } => {
panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
}
};

debug!(?res);
self.arena.alloc(hir::Lifetime {
hir_id: self.lower_node_id(id),
hir_id: self.lower_node_id(new_id),
ident: self.lower_ident(ident),
res,
})
}

#[instrument(level = "debug", skip(self))]
fn new_named_lifetime(
&mut self,
id: NodeId,
new_id: NodeId,
ident: Ident,
) -> &'hir hir::Lifetime {
let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
self.new_named_lifetime_with_res(new_id, ident, res)
}

fn lower_generic_params_mut(
&mut self,
params: &[GenericParam],
Expand Down
28 changes: 24 additions & 4 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ use rustc_abi::{
};
use rustc_codegen_ssa::common;
use rustc_codegen_ssa::traits::*;
use rustc_hir::LangItem;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::interpret::{
Allocation, ConstAllocation, ErrorHandled, InitChunk, Pointer, Scalar as InterpScalar,
read_target_uint,
};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::Instance;
use rustc_middle::mir::mono::{Linkage, MonoItem};
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
use rustc_middle::ty::{self, Instance};
use rustc_middle::{bug, span_bug};
use tracing::{debug, instrument, trace};

Expand Down Expand Up @@ -171,8 +172,27 @@ fn check_and_apply_linkage<'ll, 'tcx>(
if let Some(linkage) = attrs.import_linkage {
debug!("get_static: sym={} linkage={:?}", sym, linkage);

// Declare a symbol `foo` with the desired linkage.
let g1 = cx.declare_global(sym, cx.type_i8());
// Declare a symbol `foo`. If `foo` is an extern_weak symbol, we declare
// an extern_weak function, otherwise a global with the desired linkage.
let g1 = if matches!(attrs.import_linkage, Some(Linkage::ExternalWeak)) {
// An `extern_weak` function is represented as an `Option<unsafe extern ...>`,
// we extract the function signature and declare it as an extern_weak function
// instead of an extern_weak i8.
let instance = Instance::mono(cx.tcx, def_id);
if let ty::Adt(struct_def, args) = instance.ty(cx.tcx, cx.typing_env()).kind()
&& cx.tcx.is_lang_item(struct_def.did(), LangItem::Option)
&& let ty::FnPtr(sig, header) = args.type_at(0).kind()
{
let fn_sig = sig.with(*header);

let fn_abi = cx.fn_abi_of_fn_ptr(fn_sig, ty::List::empty());
cx.declare_fn(sym, &fn_abi, None)
} else {
cx.declare_global(sym, cx.type_i8())
}
} else {
cx.declare_global(sym, cx.type_i8())
};
llvm::set_linkage(g1, base::linkage_to_llvm(linkage));

// Declare an internal global `extern_with_linkage_foo` which
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2136,7 +2136,7 @@ fn add_library_search_dirs(
}

let fallback = Some(NativeLibSearchFallback { self_contained_components, apple_sdk_root });
walk_native_lib_search_dirs(sess, fallback, |dir, is_framework| {
let _ = walk_native_lib_search_dirs(sess, fallback, |dir, is_framework| {
if is_framework {
cmd.framework_path(dir);
} else {
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 @@ -62,6 +62,8 @@ declare_features! (
(accepted, arbitrary_enum_discriminant, "1.66.0", Some(60553)),
/// Allows using `const` operands in inline assembly.
(accepted, asm_const, "1.82.0", Some(93332)),
/// Allows using `label` operands in inline assembly.
(accepted, asm_goto, "CURRENT_RUSTC_VERSION", Some(119364)),
/// Allows using `sym` operands in inline assembly.
(accepted, asm_sym, "1.66.0", Some(93333)),
/// Allows the definition of associated constants in `trait` or `impl` blocks.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ declare_features! (
(unstable, asm_experimental_arch, "1.58.0", Some(93335)),
/// Enables experimental register support in inline assembly.
(unstable, asm_experimental_reg, "1.85.0", Some(133416)),
/// Allows using `label` operands in inline assembly.
(unstable, asm_goto, "1.78.0", Some(119364)),
/// Allows using `label` operands in inline assembly together with output operands.
(unstable, asm_goto_with_outputs, "1.85.0", Some(119364)),
/// Allows the `may_unwind` option in inline assembly.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
_ => {
intravisit::walk_pat(self, p);
let _ = intravisit::walk_pat(self, p);
}
}
ControlFlow::Continue(())
Expand All @@ -556,7 +556,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
method_name,
sugg_let: None,
};
let_visitor.visit_body(&body);
let _ = let_visitor.visit_body(&body);
if let Some(sugg_let) = let_visitor.sugg_let
&& let Some(self_ty) = self.node_ty_opt(sugg_let.init_hir_id)
{
Expand Down
85 changes: 3 additions & 82 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use crate::mir::interpret::{AllocRange, Scalar};
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
use crate::ty::{
self, AdtDef, GenericArg, GenericArgsRef, Instance, InstanceKind, List, Ty, TyCtxt,
TypeVisitableExt, TypingEnv, UserTypeAnnotationIndex,
self, GenericArg, GenericArgsRef, Instance, InstanceKind, List, Ty, TyCtxt, TypeVisitableExt,
TypingEnv, UserTypeAnnotationIndex,
};

mod basic_blocks;
Expand Down Expand Up @@ -1482,53 +1482,10 @@ pub struct UserTypeProjections {
pub contents: Vec<UserTypeProjection>,
}

impl<'tcx> UserTypeProjections {
pub fn none() -> Self {
UserTypeProjections { contents: vec![] }
}

pub fn is_empty(&self) -> bool {
self.contents.is_empty()
}

impl UserTypeProjections {
pub fn projections(&self) -> impl Iterator<Item = &UserTypeProjection> + ExactSizeIterator {
self.contents.iter()
}

pub fn push_user_type(mut self, base_user_type: UserTypeAnnotationIndex) -> Self {
self.contents.push(UserTypeProjection { base: base_user_type, projs: vec![] });
self
}

fn map_projections(mut self, f: impl FnMut(UserTypeProjection) -> UserTypeProjection) -> Self {
self.contents = self.contents.into_iter().map(f).collect();
self
}

pub fn index(self) -> Self {
self.map_projections(|pat_ty_proj| pat_ty_proj.index())
}

pub fn subslice(self, from: u64, to: u64) -> Self {
self.map_projections(|pat_ty_proj| pat_ty_proj.subslice(from, to))
}

pub fn deref(self) -> Self {
self.map_projections(|pat_ty_proj| pat_ty_proj.deref())
}

pub fn leaf(self, field: FieldIdx) -> Self {
self.map_projections(|pat_ty_proj| pat_ty_proj.leaf(field))
}

pub fn variant(
self,
adt_def: AdtDef<'tcx>,
variant_index: VariantIdx,
field_index: FieldIdx,
) -> Self {
self.map_projections(|pat_ty_proj| pat_ty_proj.variant(adt_def, variant_index, field_index))
}
}

/// Encodes the effect of a user-supplied type annotation on the
Expand All @@ -1553,42 +1510,6 @@ pub struct UserTypeProjection {
pub projs: Vec<ProjectionKind>,
}

impl UserTypeProjection {
pub(crate) fn index(mut self) -> Self {
self.projs.push(ProjectionElem::Index(()));
self
}

pub(crate) fn subslice(mut self, from: u64, to: u64) -> Self {
self.projs.push(ProjectionElem::Subslice { from, to, from_end: true });
self
}

pub(crate) fn deref(mut self) -> Self {
self.projs.push(ProjectionElem::Deref);
self
}

pub(crate) fn leaf(mut self, field: FieldIdx) -> Self {
self.projs.push(ProjectionElem::Field(field, ()));
self
}

pub(crate) fn variant(
mut self,
adt_def: AdtDef<'_>,
variant_index: VariantIdx,
field_index: FieldIdx,
) -> Self {
self.projs.push(ProjectionElem::Downcast(
Some(adt_def.variant(variant_index).name),
variant_index,
));
self.projs.push(ProjectionElem::Field(field_index, ()));
self
}
}

rustc_index::newtype_index! {
#[derive(HashStable)]
#[encodable]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/thir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,12 @@ pub enum PatKind<'tcx> {
var: LocalVarId,
ty: Ty<'tcx>,
subpattern: Option<Box<Pat<'tcx>>>,

/// Is this the leftmost occurrence of the binding, i.e., is `var` the
/// `HirId` of this pattern?
///
/// (The same binding can occur multiple times in different branches of
/// an or-pattern, but only one of them will be primary.)
is_primary: bool,
},

Expand Down
46 changes: 19 additions & 27 deletions compiler/rustc_mir_build/src/builder/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
None,
Some((Some(&destination), initializer_span)),
);
this.visit_primary_bindings(
pattern,
UserTypeProjections::none(),
&mut |this, _, _, node, span, _, _| {
this.storage_live_binding(
block,
node,
span,
OutsideGuard,
ScheduleDrops::Yes,
);
},
);
this.visit_primary_bindings(pattern, &mut |this, node, span| {
this.storage_live_binding(
block,
node,
span,
OutsideGuard,
ScheduleDrops::Yes,
);
});
let else_block_span = this.thir[*else_block].span;
let (matching, failure) =
this.in_if_then_scope(last_remainder_scope, else_block_span, |this| {
Expand Down Expand Up @@ -295,20 +291,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
});

debug!("ast_block_stmts: pattern={:?}", pattern);
this.visit_primary_bindings(
pattern,
UserTypeProjections::none(),
&mut |this, _, _, node, span, _, _| {
this.storage_live_binding(
block,
node,
span,
OutsideGuard,
ScheduleDrops::Yes,
);
this.schedule_drop_for_binding(node, span, OutsideGuard);
},
)
this.visit_primary_bindings(pattern, &mut |this, node, span| {
this.storage_live_binding(
block,
node,
span,
OutsideGuard,
ScheduleDrops::Yes,
);
this.schedule_drop_for_binding(node, span, OutsideGuard);
})
}

// Enter the visibility scope, after evaluating the initializer.
Expand Down
Loading
Loading