Skip to content

Commit

Permalink
Unrolled build for rust-lang#129472
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#129472 - folkertdev:const-refs-to-static-asm-const, r=lcnr

fix ICE when `asm_const` and `const_refs_to_static` are combined

fixes rust-lang#129462
fixes rust-lang#126896
fixes rust-lang#124164

I think this is a case that was missed in the fix for rust-lang#125558, which inserts a type error in the case of an invalid (that is, non-integer) type being passed to an asm `const` operand.

I'm not 100% sure that `span_mirbug_and_err` is the right macro here, but it is used earlier with `builtin_deref` and seems to do the trick.

r? ``@lcnr``
  • Loading branch information
rust-timer committed Sep 6, 2024
2 parents 54fdef7 + 49e3b9a commit 9367a1f
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 10 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ mod diags {
}

pub(crate) fn emit_errors(&mut self) -> Option<ErrorGuaranteed> {
let mut res = None;
let mut res = self.infcx.tainted_by_errors();

// Buffer any move errors that we collected and de-duplicated.
for (_, (_, diag)) in std::mem::take(&mut self.diags.buffered_move_errors) {
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use rustc_macros::extension;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, TyCtxt,
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty,
TyCtxt, TypeVisitableExt,
};
use rustc_middle::{bug, span_bug};
use rustc_span::symbol::{kw, sym};
Expand Down Expand Up @@ -688,7 +689,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
defining_ty: DefiningTy<'tcx>,
) -> ty::Binder<'tcx, &'tcx ty::List<Ty<'tcx>>> {
let tcx = self.infcx.tcx;
match defining_ty {

let inputs_and_output = match defining_ty {
DefiningTy::Closure(def_id, args) => {
assert_eq!(self.mir_def.to_def_id(), def_id);
let closure_sig = args.as_closure().sig();
Expand Down Expand Up @@ -798,6 +800,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
// "output" (the type of the constant).
assert_eq!(self.mir_def.to_def_id(), def_id);
let ty = tcx.type_of(self.mir_def).instantiate_identity();

let ty = indices.fold_to_region_vids(tcx, ty);
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
}
Expand All @@ -807,7 +810,14 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let ty = args.as_inline_const().ty();
ty::Binder::dummy(tcx.mk_type_list(&[ty]))
}
};

// FIXME(#129952): We probably want a more principled approach here.
if let Err(terr) = inputs_and_output.skip_binder().error_reported() {
self.infcx.set_tainted_by_errors(terr);
}

inputs_and_output
}
}

Expand Down
21 changes: 21 additions & 0 deletions tests/ui/asm/const-refs-to-static.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ needs-asm-support
//@ ignore-nvptx64
//@ ignore-spirv

#![feature(const_refs_to_static)]

use std::arch::{asm, global_asm};
use std::ptr::addr_of;

static FOO: u8 = 42;

global_asm!("{}", const addr_of!(FOO));
//~^ ERROR invalid type for `const` operand

#[no_mangle]
fn inline() {
unsafe { asm!("{}", const addr_of!(FOO)) };
//~^ ERROR invalid type for `const` operand
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/asm/const-refs-to-static.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: invalid type for `const` operand
--> $DIR/const-refs-to-static.rs:12:19
|
LL | global_asm!("{}", const addr_of!(FOO));
| ^^^^^^-------------
| |
| is a `*const u8`
|
= help: `const` operands must be of an integer type

error: invalid type for `const` operand
--> $DIR/const-refs-to-static.rs:17:25
|
LL | unsafe { asm!("{}", const addr_of!(FOO)) };
| ^^^^^^-------------
| |
| is a `*const u8`
|
= help: `const` operands must be of an integer type

error: aborting due to 2 previous errors

2 changes: 1 addition & 1 deletion tests/ui/consts/missing_assoc_const_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Range for TwoDigits {

const fn digits(x: u8) -> usize {
match x {
TwoDigits::FIRST..=TwoDigits::LAST => 0,
TwoDigits::FIRST..=TwoDigits::LAST => 0, //~ ERROR: could not evaluate constant pattern
0..=9 | 100..=255 => panic!(),
}
}
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/consts/missing_assoc_const_type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ error: missing type for `const` item
LL | const FIRST: = 10;
| ^ help: provide a type for the associated constant: `u8`

error: aborting due to 1 previous error
error: could not evaluate constant pattern
--> $DIR/missing_assoc_const_type.rs:19:9
|
LL | TwoDigits::FIRST..=TwoDigits::LAST => 0,
| ^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

3 changes: 2 additions & 1 deletion tests/crashes/124164.rs → tests/ui/static/missing-type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ known-bug: #124164
// reported as #124164
static S_COUNT: = std::sync::atomic::AtomicUsize::new(0);
//~^ ERROR: missing type for `static` item

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/static/missing-type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: missing type for `static` item
--> $DIR/missing-type.rs:2:16
|
LL | static S_COUNT: = std::sync::atomic::AtomicUsize::new(0);
| ^ help: provide a type for the static variable: `AtomicUsize`

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ known-bug: rust-lang/rust#126896
//@ compile-flags: -Zvalidate-mir -Zinline-mir=yes

// reported as rust-lang/rust#126896

#![feature(type_alias_impl_trait)]
type Two<'a, 'b> = impl std::fmt::Debug;

Expand All @@ -9,9 +10,8 @@ fn set(x: &mut isize) -> isize {
}

fn d(x: Two) {
let c1 = || set(x);
let c1 = || set(x); //~ ERROR: expected generic lifetime parameter, found `'_`
c1;
}

fn main() {
}
fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/type-alias-impl-trait/taint.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0792]: expected generic lifetime parameter, found `'_`
--> $DIR/taint.rs:13:17
|
LL | type Two<'a, 'b> = impl std::fmt::Debug;
| -- this generic parameter must be used with a generic lifetime parameter
...
LL | let c1 = || set(x);
| ^^^^^^

error: aborting due to 1 previous error

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

0 comments on commit 9367a1f

Please sign in to comment.