Skip to content
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

Rollup of 8 pull requests #125593

Merged
merged 17 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
62a104d
Update Tests
veera-sivarajan Apr 16, 2024
f005b45
Support C23's Variadics Without a Named Parameter
veera-sivarajan Apr 16, 2024
531dae1
Only allow immutable statics with #[linkage]
bjorn3 May 12, 2024
4bc41b9
Don't continue probing for method if in suggestion and autoderef hits…
compiler-errors May 23, 2024
c58b7c9
Don't skip inner const when looking for body for suggestion
compiler-errors May 23, 2024
bebcb4e
Also mention my-self for check-cfg docs changes
Urgau May 25, 2024
0c84361
Simplify the `unchecked_sh[lr]` ub-checks a bit
scottmcm May 25, 2024
91b3ef5
Notify T-rustdoc for beta-accepted and stable-accepted too
camelid May 26, 2024
d37f456
Avoid a `FieldIdx::from_usize` in InstSimplify
scottmcm May 26, 2024
866630d
Rollup merge of #124048 - veera-sivarajan:bugfix-123773-c23-variadics…
workingjubilee May 26, 2024
5860d43
Rollup merge of #125046 - bjorn3:no_mutable_static_linkage, r=cjgillot
workingjubilee May 26, 2024
09e7592
Rollup merge of #125466 - compiler-errors:dont-probe-for-ambig-in-sug…
workingjubilee May 26, 2024
b65b2b6
Rollup merge of #125469 - compiler-errors:dont-skip-inner-const-body,…
workingjubilee May 26, 2024
c51fc1d
Rollup merge of #125544 - Urgau:check-cfg-mention-cargo-specific, r=j…
workingjubilee May 26, 2024
25b079a
Rollup merge of #125559 - scottmcm:simplify-shift-ubcheck, r=workingj…
workingjubilee May 26, 2024
45507e4
Rollup merge of #125566 - camelid:notify-accepted, r=GuillaumeGomez
workingjubilee May 26, 2024
4ff7869
Rollup merge of #125582 - scottmcm:less-from-usize, r=jieyouxu
workingjubilee May 26, 2024
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
3 changes: 0 additions & 3 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ ast_passes_fn_body_extern = incorrect function inside `extern` block
ast_passes_fn_param_c_var_args_not_last =
`...` must be the last argument of a C-variadic function

ast_passes_fn_param_c_var_args_only =
C-variadic function must be declared with at least one named argument

ast_passes_fn_param_doc_comment =
documentation comments cannot be applied to function parameters
.label = doc comments are not allowed here
Expand Down
12 changes: 5 additions & 7 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ impl<'a> AstValidator<'a> {

fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
self.check_decl_num_args(fn_decl);
self.check_decl_cvaradic_pos(fn_decl);
self.check_decl_cvariadic_pos(fn_decl);
self.check_decl_attrs(fn_decl);
self.check_decl_self_param(fn_decl, self_semantic);
}
Expand All @@ -379,13 +379,11 @@ impl<'a> AstValidator<'a> {
}
}

fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) {
/// Emits an error if a function declaration has a variadic parameter in the
/// beginning or middle of parameter list.
/// Example: `fn foo(..., x: i32)` will emit an error.
fn check_decl_cvariadic_pos(&self, fn_decl: &FnDecl) {
match &*fn_decl.inputs {
[Param { ty, span, .. }] => {
if let TyKind::CVarArgs = ty.kind {
self.dcx().emit_err(errors::FnParamCVarArgsOnly { span: *span });
}
}
[ps @ .., _] => {
for Param { ty, span, .. } in ps {
if let TyKind::CVarArgs = ty.kind {
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ pub struct FnParamTooMany {
pub max_num_args: usize,
}

#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_c_var_args_only)]
pub struct FnParamCVarArgsOnly {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_c_var_args_not_last)]
pub struct FnParamCVarArgsNotLast {
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,18 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
} else {
codegen_fn_attrs.linkage = linkage;
}
if tcx.is_mutable_static(did.into()) {
let mut diag = tcx.dcx().struct_span_err(
attr.span,
"mutable statics are not allowed with `#[linkage]`",
);
diag.note(
"making the static mutable would allow changing which symbol the \
static references rather than make the target of the symbol \
mutable",
);
diag.emit();
}
}
}
sym::link_section => {
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,11 +1871,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
// If this is due to a block, then maybe we forgot a `return`/`break`.
if due_to_block
&& let Some(expr) = expression
&& let Some((parent_fn_decl, parent_id)) = fcx
.tcx
.hir()
.parent_iter(block_or_return_id)
.find_map(|(_, node)| Some((node.fn_decl()?, node.associated_body()?.0)))
&& let Some(parent_fn_decl) =
fcx.tcx.hir().fn_decl_by_hir_id(fcx.tcx.local_def_id_to_hir_id(fcx.body_id))
{
fcx.suggest_missing_break_or_return_expr(
&mut err,
Expand All @@ -1884,7 +1881,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
expected,
found,
block_or_return_id,
parent_id,
fcx.body_id,
);
}

Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// ambiguous.
if let Some(bad_ty) = &steps.opt_bad_ty {
if is_suggestion.0 {
// Ambiguity was encountered during a suggestion. Just keep going.
debug!("ProbeContext: encountered ambiguity in suggestion");
// Ambiguity was encountered during a suggestion. There's really
// not much use in suggesting methods in this case.
return Err(MethodError::NoMatch(NoMatchData {
static_candidates: Vec::new(),
unsatisfied_predicates: Vec::new(),
out_of_scope_traits: Vec::new(),
similar_candidate: None,
mode,
}));
} else if bad_ty.reached_raw_pointer
&& !self.tcx.features().arbitrary_self_types
&& !self.tcx.sess.at_least_rust_2018()
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/dataflow_const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
_ => return,
};
if let Some(variant_target_idx) = variant_target {
for (field_index, operand) in operands.iter().enumerate() {
for (field_index, operand) in operands.iter_enumerated() {
if let Some(field) = self.map().apply(
variant_target_idx,
TrackElem::Field(FieldIdx::from_usize(field_index)),
TrackElem::Field(field_index),
) {
self.assign_operand(state, field, operand);
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/instsimplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_middle::ty::layout::ValidityRequirement;
use rustc_middle::ty::{self, GenericArgsRef, ParamEnv, Ty, TyCtxt};
use rustc_span::sym;
use rustc_span::symbol::Symbol;
use rustc_target::abi::FieldIdx;
use rustc_target::spec::abi::Abi;

pub struct InstSimplify;
Expand Down Expand Up @@ -217,11 +216,11 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
&& let Some(place) = operand.place()
{
let variant = adt_def.non_enum_variant();
for (i, field) in variant.fields.iter().enumerate() {
for (i, field) in variant.fields.iter_enumerated() {
let field_ty = field.ty(self.tcx, args);
if field_ty == *cast_ty {
let place = place.project_deeper(
&[ProjectionElem::Field(FieldIdx::from_usize(i), *cast_ty)],
&[ProjectionElem::Field(i, *cast_ty)],
self.tcx,
);
let operand = if operand.is_move() {
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,7 @@ macro_rules! int_impl {
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
(
rhs: u32 = rhs,
bits: u32 = Self::BITS,
) => rhs < bits,
) => rhs < <$ActualT>::BITS,
);

// SAFETY: this is guaranteed to be safe by the caller.
Expand Down Expand Up @@ -1381,8 +1380,7 @@ macro_rules! int_impl {
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
(
rhs: u32 = rhs,
bits: u32 = Self::BITS,
) => rhs < bits,
) => rhs < <$ActualT>::BITS,
);

// SAFETY: this is guaranteed to be safe by the caller.
Expand Down
6 changes: 2 additions & 4 deletions library/core/src/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1369,8 +1369,7 @@ macro_rules! uint_impl {
concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
(
rhs: u32 = rhs,
bits: u32 = Self::BITS,
) => rhs < bits,
) => rhs < <$ActualT>::BITS,
);

// SAFETY: this is guaranteed to be safe by the caller.
Expand Down Expand Up @@ -1468,8 +1467,7 @@ macro_rules! uint_impl {
concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
(
rhs: u32 = rhs,
bits: u32 = Self::BITS,
) => rhs < bits,
) => rhs < <$ActualT>::BITS,
);

// SAFETY: this is guaranteed to be safe by the caller.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

bb1: {
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4, const core::num::<impl u16>::BITS) -> [return: bb2, unwind unreachable];
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

bb1: {
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4, const core::num::<impl u16>::BITS) -> [return: bb2, unwind unreachable];
+ _6 = core::num::<impl u16>::unchecked_shl::precondition_check(_4) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

bb1: {
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4, const core::num::<impl i64>::BITS) -> [return: bb2, unwind unreachable];
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

bb1: {
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4, const core::num::<impl i64>::BITS) -> [return: bb2, unwind unreachable];
+ _6 = core::num::<impl i64>::unchecked_shr::precondition_check(_4) -> [return: bb2, unwind unreachable];
+ }
+
+ bb2: {
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/c-variadic/variadic-ffi-no-fixed-args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//@ build-pass

// Supported since C23
// https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf
extern "C" {
fn foo(...);
//~^ ERROR C-variadic function must be declared with at least one named argument
}

fn main() {}
8 changes: 0 additions & 8 deletions tests/ui/c-variadic/variadic-ffi-no-fixed-args.stderr

This file was deleted.

3 changes: 0 additions & 3 deletions tests/ui/issues/issue-33992.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

#![feature(linkage)]

#[linkage = "common"]
pub static mut TEST1: u32 = 0u32;

#[linkage = "external"]
pub static TEST2: bool = true;

Expand Down
15 changes: 15 additions & 0 deletions tests/ui/linkage-attr/linkage-attr-mutable-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! The symbols are resolved by the linker. It doesn't make sense to change
//! them at runtime, so deny mutable statics with #[linkage].

#![feature(linkage)]

fn main() {
extern "C" {
#[linkage = "weak"] //~ ERROR mutable statics are not allowed with `#[linkage]`
static mut ABC: *const u8;
}

unsafe {
assert_eq!(ABC as usize, 0);
}
}
10 changes: 10 additions & 0 deletions tests/ui/linkage-attr/linkage-attr-mutable-static.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: mutable statics are not allowed with `#[linkage]`
--> $DIR/linkage-attr-mutable-static.rs:8:9
|
LL | #[linkage = "weak"]
| ^^^^^^^^^^^^^^^^^^^
|
= note: making the static mutable would allow changing which symbol the static references rather than make the target of the symbol mutable

error: aborting due to 1 previous error

16 changes: 16 additions & 0 deletions tests/ui/methods/suggest-method-on-call-for-ambig-receiver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Fix for <https://github.com/rust-lang/rust/issues/125432>.

fn separate_arms() {
let mut x = None;
match x {
None => {
x = Some(0);
}
Some(right) => {
consume(right);
//~^ ERROR cannot find function `consume` in this scope
}
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0425]: cannot find function `consume` in this scope
--> $DIR/suggest-method-on-call-for-ambig-receiver.rs:10:13
|
LL | consume(right);
| ^^^^^^^ not found in this scope

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0425`.
8 changes: 0 additions & 8 deletions tests/ui/parser/variadic-ffi-semantic-restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ fn f1_1(x: isize, ...) {}

fn f1_2(...) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
//~| ERROR C-variadic function must be declared with at least one named argument

extern "C" fn f2_1(x: isize, ...) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic

extern "C" fn f2_2(...) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
//~| ERROR C-variadic function must be declared with at least one named argument

extern "C" fn f2_3(..., x: isize) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
Expand All @@ -26,7 +24,6 @@ extern "C" fn f3_1(x: isize, ...) {}

extern "C" fn f3_2(...) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
//~| ERROR C-variadic function must be declared with at least one named argument

extern "C" fn f3_3(..., x: isize) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
Expand All @@ -47,8 +44,6 @@ const extern "C" fn f4_3(..., x: isize, ...) {}
//~| ERROR `...` must be the last argument of a C-variadic function

extern "C" {
fn e_f1(...);
//~^ ERROR C-variadic function must be declared with at least one named argument
fn e_f2(..., x: isize);
//~^ ERROR `...` must be the last argument of a C-variadic function
}
Expand All @@ -60,7 +55,6 @@ impl X {
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
fn i_f2(...) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
//~| ERROR C-variadic function must be declared with at least one named argument
fn i_f3(..., x: isize, ...) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
//~| ERROR `...` must be the last argument of a C-variadic function
Expand All @@ -80,10 +74,8 @@ trait T {
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
fn t_f3(...) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
//~| ERROR C-variadic function must be declared with at least one named argument
fn t_f4(...);
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
//~| ERROR C-variadic function must be declared with at least one named argument
fn t_f5(..., x: isize) {}
//~^ ERROR only foreign or `unsafe extern "C"` functions may be C-variadic
//~| ERROR `...` must be the last argument of a C-variadic function
Expand Down
Loading
Loading