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 7 pull requests #125591

Closed
wants to merge 14 commits into from
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions tests/crashes/123255.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ known-bug: rust-lang/rust#123255
//@ edition:2021
#![crate_type = "lib"]

pub fn a() {}

mod handlers {
pub struct C(&());
pub fn c() -> impl Fn() -> C {
let a1 = ();
|| C((crate::a(), a1).into())
}
}
25 changes: 25 additions & 0 deletions tests/crashes/123276.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//@ known-bug: rust-lang/rust#123276
//@ edition:2021

async fn create_task() {
_ = Some(async { bind(documentation_filter()) });
}

async fn bind<Fut, F: Filter<Future = Fut>>(_: F) {}

fn documentation_filter() -> impl Filter {
AndThen
}

trait Filter {
type Future;
}

struct AndThen;

impl Filter for AndThen
where
Foo: Filter,
{
type Future = ();
}
15 changes: 15 additions & 0 deletions tests/crashes/123887.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ known-bug: rust-lang/rust#123887
//@ compile-flags: -Clink-dead-code

#![feature(extern_types)]
#![feature(unsized_fn_params)]

extern "C" {
pub type ExternType;
}

impl ExternType {
pub fn f(self) {}
}

pub fn main() {}
5 changes: 5 additions & 0 deletions tests/crashes/125013-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@ known-bug: rust-lang/rust#125013
//@ edition:2021
use io::{self as std};
use std::ops::Deref::{self as io};
pub fn main() {}
16 changes: 16 additions & 0 deletions tests/crashes/125013-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ known-bug: rust-lang/rust#125013
//@ edition:2021
mod a {
pub mod b {
pub mod c {
pub trait D {}
}
}
}

use a::*;

use e as b;
use b::c::D as e;

fn main() { }
17 changes: 17 additions & 0 deletions tests/crashes/125014.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ known-bug: rust-lang/rust#125014
//@ compile-flags: -Znext-solver=coherence
#![feature(specialization)]

trait Foo {}

impl Foo for <u16 as Assoc>::Output {}

impl Foo for u32 {}

trait Assoc {
type Output;
}
impl Output for u32 {}
impl Assoc for <u16 as Assoc>::Output {
default type Output = bool;
}
12 changes: 12 additions & 0 deletions tests/crashes/125059.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ known-bug: rust-lang/rust#125059
#![feature(deref_patterns)]
#![allow(incomplete_features)]

fn simple_vec(vec: Vec<u32>) -> u32 {
(|| match Vec::<u32>::new() {
deref!([]) => 100,
_ => 2000,
})()
}

fn main() {}
6 changes: 6 additions & 0 deletions tests/crashes/125323.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ known-bug: rust-lang/rust#125323
fn main() {
for _ in 0..0 {
[(); loop {}];
}
}
16 changes: 16 additions & 0 deletions tests/crashes/125370.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ known-bug: rust-lang/rust#125370

type Field3 = i64;

#[repr(C)]
union DummyUnion {
field3: Field3,
}

const UNION: DummyUnion = loop {};

const fn read_field2() -> Field2 {
const FIELD2: Field2 = loop {
UNION.field3
};
}
17 changes: 17 additions & 0 deletions tests/crashes/125432.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ known-bug: rust-lang/rust#125432

fn separate_arms() {
// Here both arms perform assignments, but only one is illegal.

let mut x = None;
match x {
None => {
// It is ok to reassign x here, because there is in
// fact no outstanding loan of x!
x = Some(0);
}
Some(right) => consume(right),
}
}

fn main() {}
3 changes: 3 additions & 0 deletions tests/crashes/125476.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@ known-bug: rust-lang/rust#125476
pub struct Data([u8; usize::MAX >> 16]);
const _: &'static [Data] = &[];
10 changes: 10 additions & 0 deletions tests/crashes/125512.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ known-bug: rust-lang/rust#125512
//@ edition:2021
#![feature(object_safe_for_dispatch)]
trait B {
fn f(a: A) -> A;
}
trait A {
fn concrete(b: B) -> B;
}
fn main() {}
16 changes: 16 additions & 0 deletions tests/crashes/125520.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ known-bug: #125520
#![feature(generic_const_exprs)]

struct Outer<const A: i64, const B: i64>();
impl<const A: usize, const B: usize> Outer<A, B>
where
[(); A + (B * 2)]:,
{
fn i() -> Self {
Self
}
}

fn main() {
Outer::<1, 1>::o();
}
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`.
9 changes: 9 additions & 0 deletions tests/ui/return/dont-suggest-through-inner-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fn f() -> usize {
//~^ ERROR mismatched types
const FIELD: usize = loop {
0
//~^ ERROR mismatched types
};
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/return/dont-suggest-through-inner-const.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> $DIR/dont-suggest-through-inner-const.rs:4:9
|
LL | 0
| ^ expected `()`, found integer

error[E0308]: mismatched types
--> $DIR/dont-suggest-through-inner-const.rs:1:17
|
LL | const fn f() -> usize {
| - ^^^^^ expected `usize`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
Loading
Loading