Skip to content

Rollup of 7 pull requests #114686

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

Closed
wants to merge 14 commits into from
Closed
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
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
@@ -1843,7 +1843,7 @@ impl Expr<'_> {
.iter()
.map(|field| field.expr)
.chain(init.into_iter())
.all(|e| e.can_have_side_effects()),
.any(|e| e.can_have_side_effects()),

ExprKind::Array(args)
| ExprKind::Tup(args)
@@ -1857,7 +1857,7 @@ impl Expr<'_> {
..
},
args,
) => args.iter().all(|arg| arg.can_have_side_effects()),
) => args.iter().any(|arg| arg.can_have_side_effects()),
ExprKind::If(..)
| ExprKind::Match(..)
| ExprKind::MethodCall(..)
29 changes: 17 additions & 12 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
@@ -645,18 +645,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
}
hir::ExprKind::Call(ref inner_callee, _) => {
// If the call spans more than one line and the callee kind is
// itself another `ExprCall`, that's a clue that we might just be
// missing a semicolon (Issue #51055)
let call_is_multiline = self.tcx.sess.source_map().is_multiline(call_expr.span);
if call_is_multiline {
err.span_suggestion(
callee_expr.span.shrink_to_hi(),
"consider using a semicolon here",
";",
Applicability::MaybeIncorrect,
);
}
if let hir::ExprKind::Path(ref inner_qpath) = inner_callee.kind {
inner_callee_path = Some(inner_qpath);
self.typeck_results.borrow().qpath_res(inner_qpath, inner_callee.hir_id)
@@ -668,6 +656,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

if !self.maybe_suggest_bad_array_definition(&mut err, call_expr, callee_expr) {
// If the call spans more than one line and the callee kind is
// itself another `ExprCall`, that's a clue that we might just be
// missing a semicolon (#51055, #106515).
let call_is_multiline = self
.tcx
.sess
.source_map()
.is_multiline(call_expr.span.with_lo(callee_expr.span.hi()))
&& call_expr.span.ctxt() == callee_expr.span.ctxt();
if call_is_multiline {
err.span_suggestion(
callee_expr.span.shrink_to_hi(),
"consider using a semicolon here to finish the statement",
";",
Applicability::MaybeIncorrect,
);
}
if let Some((maybe_def, output_ty, _)) = self.extract_callable_info(callee_ty)
&& !self.type_is_sized_modulo_regions(self.param_env, output_ty)
{
Original file line number Diff line number Diff line change
@@ -824,11 +824,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
}

ty::Array(ty0, len) => {
let len = len
.try_to_scalar()
.unwrap()
.to_u64()
.unwrap_or_else(|_| panic!("failed to convert length to u64"));
let len = len.eval_target_usize(tcx, ty::ParamEnv::reveal_all());

ty = Ty::new_array(tcx, transform_ty(tcx, *ty0, options), len);
}

7 changes: 6 additions & 1 deletion compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ impl<'a, Ty> Deref for TyAndLayout<'a, Ty> {

/// Trait that needs to be implemented by the higher-level type representation
/// (e.g. `rustc_middle::ty::Ty`), to provide `rustc_target::abi` functionality.
pub trait TyAbiInterface<'a, C>: Sized {
pub trait TyAbiInterface<'a, C>: Sized + std::fmt::Debug {
fn ty_and_layout_for_variant(
this: TyAndLayout<'a, Self>,
cx: &C,
@@ -135,6 +135,11 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
for index in indices {
offset += layout.fields.offset(index);
layout = layout.field(cx, index);
assert!(
layout.is_sized(),
"offset of unsized field (type {:?}) cannot be computed statically",
layout.ty
);
}

offset
2 changes: 1 addition & 1 deletion src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
@@ -1129,7 +1129,7 @@ fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
needs_codegen_cfg
}

const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";
pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_";

fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool {
if path.path.to_str().unwrap().contains(&CODEGEN_BACKEND_PREFIX) {
18 changes: 16 additions & 2 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ use std::str::FromStr;
use crate::cache::{Interned, INTERNER};
use crate::cc_detect::{ndk_compiler, Language};
use crate::channel::{self, GitInfo};
use crate::compile::CODEGEN_BACKEND_PREFIX;
pub use crate::flags::Subcommand;
use crate::flags::{Color, Flags, Warnings};
use crate::util::{exe, output, t};
@@ -1443,8 +1444,21 @@ impl Config {
.map(|v| v.parse().expect("failed to parse rust.llvm-libunwind"));

if let Some(ref backends) = rust.codegen_backends {
config.rust_codegen_backends =
backends.iter().map(|s| INTERNER.intern_str(s)).collect();
let available_backends = vec!["llvm", "cranelift", "gcc"];

config.rust_codegen_backends = backends.iter().map(|s| {
if let Some(backend) = s.strip_prefix(CODEGEN_BACKEND_PREFIX) {
if available_backends.contains(&backend) {
panic!("Invalid value '{s}' for 'rust.codegen-backends'. Instead, please use '{backend}'.");
} else {
println!("help: '{s}' for 'rust.codegen-backends' might fail. \
Codegen backends are mostly defined without the '{CODEGEN_BACKEND_PREFIX}' prefix. \
In this case, it would be referred to as '{backend}'.");
}
}

INTERNER.intern_str(s)
}).collect();
}

config.rust_codegen_units = rust.codegen_units.map(threads_from_config);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# `profile-sample-use
# `profile-sample-use`

---

1 change: 0 additions & 1 deletion tests/ui/async-await/in-trait/return-type-suggestion.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@ trait A {
async fn e() {
Ok(())
//~^ ERROR mismatched types
//~| HELP consider using a semicolon here
}
}

4 changes: 1 addition & 3 deletions tests/ui/async-await/in-trait/return-type-suggestion.stderr
Original file line number Diff line number Diff line change
@@ -2,9 +2,7 @@ error[E0308]: mismatched types
--> $DIR/return-type-suggestion.rs:7:9
|
LL | Ok(())
| ^^^^^^- help: consider using a semicolon here: `;`
| |
| expected `()`, found `Result<(), _>`
| ^^^^^^ expected `()`, found `Result<(), _>`
|
= note: expected unit type `()`
found enum `Result<(), _>`
24 changes: 24 additions & 0 deletions tests/ui/return/return-struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
struct S;

enum Age {
Years(i64, i64)
}

fn foo() {
let mut age = 29;
Age::Years({age += 1; age}, 55)
//~^ ERROR mismatched types
}

fn bar() {
let mut age = 29;
Age::Years(age, 55)
//~^ ERROR mismatched types
}

fn baz() {
S
//~^ ERROR mismatched types
}

fn main() {}
35 changes: 35 additions & 0 deletions tests/ui/return/return-struct.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0308]: mismatched types
--> $DIR/return-struct.rs:9:5
|
LL | Age::Years({age += 1; age}, 55)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Age`
|
help: consider using a semicolon here
|
LL | Age::Years({age += 1; age}, 55);
| +
help: try adding a return type
|
LL | fn foo() -> Age {
| ++++++

error[E0308]: mismatched types
--> $DIR/return-struct.rs:15:5
|
LL | fn bar() {
| - help: try adding a return type: `-> Age`
LL | let mut age = 29;
LL | Age::Years(age, 55)
| ^^^^^^^^^^^^^^^^^^^ expected `()`, found `Age`

error[E0308]: mismatched types
--> $DIR/return-struct.rs:20:5
|
LL | fn baz() {
| - help: try adding a return type: `-> S`
LL | S
| ^ expected `()`, found `S`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
15 changes: 15 additions & 0 deletions tests/ui/sanitize/issue-114275-cfi-const-expr-in-arry-len.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Regression test for issue 114275 `typeid::typeid_itanium_cxx_abi::transform_ty`
// was expecting array type lengths to be evaluated, this was causing an ICE.
//
// build-pass
// compile-flags: -Ccodegen-units=1 -Clto -Zsanitizer=cfi
// needs-sanitizer-cfi

#![crate_type = "lib"]

#[repr(transparent)]
pub struct Array([u8; 1 * 1]);

pub extern "C" fn array() -> Array {
loop {}
}
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ LL | fn vindictive() -> bool { true }
| ----------------------- `vindictive` defined here returns `bool`
...
LL | vindictive()
| -^^^^^^^^^^^- help: consider using a semicolon here: `;`
| -^^^^^^^^^^^- help: consider using a semicolon here to finish the statement: `;`
| _____|
| |
LL | | (1, 2)
38 changes: 38 additions & 0 deletions tests/ui/suggestions/missing-semicolon.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// run-rustfix
#![allow(dead_code, unused_variables, path_statements)]
fn a() {
let x = 5;
let y = x; //~ ERROR expected function
(); //~ ERROR expected `;`, found `}`
}

fn b() {
let x = 5;
let y = x; //~ ERROR expected function
();
}
fn c() {
let x = 5;
x; //~ ERROR expected function
()
}
fn d() { // ok
let x = || ();
x
()
}
fn e() { // ok
let x = || ();
x
();
}
fn f()
{
let y = 5; //~ ERROR expected function
(); //~ ERROR expected `;`, found `}`
}
fn g() {
5; //~ ERROR expected function
();
}
fn main() {}
38 changes: 38 additions & 0 deletions tests/ui/suggestions/missing-semicolon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// run-rustfix
#![allow(dead_code, unused_variables, path_statements)]
fn a() {
let x = 5;
let y = x //~ ERROR expected function
() //~ ERROR expected `;`, found `}`
}

fn b() {
let x = 5;
let y = x //~ ERROR expected function
();
}
fn c() {
let x = 5;
x //~ ERROR expected function
()
}
fn d() { // ok
let x = || ();
x
()
}
fn e() { // ok
let x = || ();
x
();
}
fn f()
{
let y = 5 //~ ERROR expected function
() //~ ERROR expected `;`, found `}`
}
fn g() {
5 //~ ERROR expected function
();
}
fn main() {}
75 changes: 75 additions & 0 deletions tests/ui/suggestions/missing-semicolon.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
error: expected `;`, found `}`
--> $DIR/missing-semicolon.rs:6:7
|
LL | ()
| ^ help: add `;` here
LL | }
| - unexpected token

error: expected `;`, found `}`
--> $DIR/missing-semicolon.rs:32:7
|
LL | ()
| ^ help: add `;` here
LL | }
| - unexpected token

error[E0618]: expected function, found `{integer}`
--> $DIR/missing-semicolon.rs:5:13
|
LL | let x = 5;
| - `x` has type `{integer}`
LL | let y = x
| ^- help: consider using a semicolon here to finish the statement: `;`
| _____________|
| |
LL | | ()
| |______- call expression requires function

error[E0618]: expected function, found `{integer}`
--> $DIR/missing-semicolon.rs:11:13
|
LL | let x = 5;
| - `x` has type `{integer}`
LL | let y = x
| ^- help: consider using a semicolon here to finish the statement: `;`
| _____________|
| |
LL | | ();
| |______- call expression requires function

error[E0618]: expected function, found `{integer}`
--> $DIR/missing-semicolon.rs:16:5
|
LL | let x = 5;
| - `x` has type `{integer}`
LL | x
| ^- help: consider using a semicolon here to finish the statement: `;`
| _____|
| |
LL | | ()
| |______- call expression requires function

error[E0618]: expected function, found `{integer}`
--> $DIR/missing-semicolon.rs:31:13
|
LL | let y = 5
| ^- help: consider using a semicolon here to finish the statement: `;`
| _____________|
| |
LL | | ()
| |______- call expression requires function

error[E0618]: expected function, found `{integer}`
--> $DIR/missing-semicolon.rs:35:5
|
LL | 5
| ^- help: consider using a semicolon here to finish the statement: `;`
| _____|
| |
LL | | ();
| |______- call expression requires function

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0618`.
2 changes: 1 addition & 1 deletion triagebot.toml
Original file line number Diff line number Diff line change
@@ -490,7 +490,7 @@ cc = ["@nnethercote"]
[assign]
warn_non_default_branch = true
contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html"
users_on_vacation = ["jyn514", "WaffleLapkin"]
users_on_vacation = ["jyn514", "WaffleLapkin", "clubby789"]

[assign.adhoc_groups]
compiler-team = [