Auto merge of #86226 - JohnTitor:rollup-5ubdolf, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #85800 (Fix some diagnostic issues with const_generics_defaults feature gate) - #85823 (Do not suggest ampmut if rhs is already mutable) - #86153 (Print dummy spans as `no-location`) - #86174 (Detect incorrect vtable alignment during const eval) - #86189 (Make `relate_type_and_mut` public) - #86205 (Run full const-generics test for issue-72293) - #86217 (Remove "generic type" in boxed.rs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
3198c523cc
@ -938,8 +938,11 @@ fn validate_generic_param_order(
|
||||
}
|
||||
GenericParamKind::Type { default: None } => (),
|
||||
GenericParamKind::Lifetime => (),
|
||||
// FIXME(const_generics_defaults)
|
||||
GenericParamKind::Const { ty: _, kw_span: _, default: _ } => (),
|
||||
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
|
||||
ordered_params += " = ";
|
||||
ordered_params += &pprust::expr_to_string(&*default.value);
|
||||
}
|
||||
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
@ -959,7 +962,7 @@ fn validate_generic_param_order(
|
||||
span,
|
||||
&format!(
|
||||
"reorder the parameters: lifetimes, {}",
|
||||
if sess.features_untracked().const_generics {
|
||||
if sess.features_untracked().unordered_const_ty_params() {
|
||||
"then consts and types"
|
||||
} else {
|
||||
"then types, then consts"
|
||||
|
@ -54,7 +54,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
/// ADTs with no type arguments.
|
||||
pub fn is_simple_text(&self) -> bool {
|
||||
match self.kind() {
|
||||
Adt(_, substs) => substs.types().next().is_none(),
|
||||
Adt(_, substs) => substs.non_erasable_generics().next().is_none(),
|
||||
Ref(_, ty, _) => ty.is_simple_text(),
|
||||
_ => self.is_simple_ty(),
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ pub trait Relate<'tcx>: TypeFoldable<'tcx> + Copy {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Relate impls
|
||||
|
||||
fn relate_type_and_mut<'tcx, R: TypeRelation<'tcx>>(
|
||||
pub fn relate_type_and_mut<'tcx, R: TypeRelation<'tcx>>(
|
||||
relation: &mut R,
|
||||
a: ty::TypeAndMut<'tcx>,
|
||||
b: ty::TypeAndMut<'tcx>,
|
||||
|
@ -902,9 +902,13 @@ fn suggest_ampmut<'tcx>(
|
||||
{
|
||||
let lt_name = &src[1..ws_pos];
|
||||
let ty = &src[ws_pos..];
|
||||
return (assignment_rhs_span, format!("&{} mut {}", lt_name, ty));
|
||||
if !ty.trim_start().starts_with("mut") {
|
||||
return (assignment_rhs_span, format!("&{} mut {}", lt_name, ty));
|
||||
}
|
||||
} else if let Some(stripped) = src.strip_prefix('&') {
|
||||
return (assignment_rhs_span, format!("&mut {}", stripped));
|
||||
if !stripped.trim_start().starts_with("mut") {
|
||||
return (assignment_rhs_span, format!("&mut {}", stripped));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,6 +158,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
let size = u64::try_from(self.force_bits(size, pointer_size)?).unwrap();
|
||||
let align = vtable.read_ptr_sized(pointer_size * 2)?.check_init()?;
|
||||
let align = u64::try_from(self.force_bits(align, pointer_size)?).unwrap();
|
||||
let align = Align::from_bytes(align)
|
||||
.map_err(|e| err_ub_format!("invalid vtable: alignment {}", e))?;
|
||||
|
||||
if size >= self.tcx.data_layout.obj_size_bound() {
|
||||
throw_ub_format!(
|
||||
@ -165,6 +167,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
size is bigger than largest supported object"
|
||||
);
|
||||
}
|
||||
Ok((Size::from_bytes(size), Align::from_bytes(align).unwrap()))
|
||||
Ok((Size::from_bytes(size), align))
|
||||
}
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ impl SourceMap {
|
||||
}
|
||||
|
||||
fn span_to_string(&self, sp: Span, prefer_local: bool) -> String {
|
||||
if self.files.borrow().source_files.is_empty() && sp.is_dummy() {
|
||||
if self.files.borrow().source_files.is_empty() || sp.is_dummy() {
|
||||
return "no-location".to_string();
|
||||
}
|
||||
|
||||
|
@ -1209,7 +1209,7 @@ impl<T: ?Sized + Hasher, A: Allocator> Hasher for Box<T, A> {
|
||||
#[cfg(not(no_global_oom_handling))]
|
||||
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
|
||||
impl<T> From<T> for Box<T> {
|
||||
/// Converts a generic type `T` into a `Box<T>`
|
||||
/// Converts a `T` into a `Box<T>`
|
||||
///
|
||||
/// The conversion allocates on the heap and moves `t`
|
||||
/// from the stack into it.
|
||||
|
@ -85,13 +85,13 @@ yields ()
|
||||
bb8 (cleanup): {
|
||||
StorageDead(_10); // scope 2 at $DIR/generator-storage-dead-unwind.rs:27:15: 27:16
|
||||
StorageDead(_9); // scope 2 at $DIR/generator-storage-dead-unwind.rs:27:16: 27:17
|
||||
goto -> bb10; // scope 2 at $DIR/generator-storage-dead-unwind.rs:1:1: 1:1
|
||||
goto -> bb10; // scope 2 at no-location
|
||||
}
|
||||
|
||||
bb9 (cleanup): {
|
||||
StorageDead(_8); // scope 2 at $DIR/generator-storage-dead-unwind.rs:26:15: 26:16
|
||||
StorageDead(_7); // scope 2 at $DIR/generator-storage-dead-unwind.rs:26:16: 26:17
|
||||
goto -> bb10; // scope 2 at $DIR/generator-storage-dead-unwind.rs:1:1: 1:1
|
||||
goto -> bb10; // scope 2 at no-location
|
||||
}
|
||||
|
||||
bb10 (cleanup): {
|
||||
|
@ -43,7 +43,7 @@ fn main() -> () {
|
||||
_6 = const 1_i32; // scope 0 at $DIR/loop_test.rs:14:17: 14:18
|
||||
FakeRead(ForLet(None), _6); // scope 0 at $DIR/loop_test.rs:14:13: 14:14
|
||||
StorageDead(_6); // scope 0 at $DIR/loop_test.rs:16:5: 16:6
|
||||
goto -> bb3; // scope 0 at $DIR/loop_test.rs:1:1: 1:1
|
||||
goto -> bb3; // scope 0 at no-location
|
||||
}
|
||||
|
||||
bb5 (cleanup): {
|
||||
|
@ -94,8 +94,8 @@
|
||||
_0 = const 3_i32; // scope 0 at $DIR/match-arm-scopes.rs:15:59: 15:60
|
||||
StorageDead(_10); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73
|
||||
StorageDead(_9); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78
|
||||
- goto -> bb23; // scope 0 at $DIR/match-arm-scopes.rs:1:1: 1:1
|
||||
+ goto -> bb20; // scope 0 at $DIR/match-arm-scopes.rs:1:1: 1:1
|
||||
- goto -> bb23; // scope 0 at no-location
|
||||
+ goto -> bb20; // scope 0 at no-location
|
||||
}
|
||||
|
||||
- bb10: {
|
||||
@ -150,8 +150,8 @@
|
||||
_0 = const 3_i32; // scope 0 at $DIR/match-arm-scopes.rs:15:59: 15:60
|
||||
StorageDead(_13); // scope 0 at $DIR/match-arm-scopes.rs:15:72: 15:73
|
||||
StorageDead(_12); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78
|
||||
- goto -> bb23; // scope 0 at $DIR/match-arm-scopes.rs:1:1: 1:1
|
||||
+ goto -> bb20; // scope 0 at $DIR/match-arm-scopes.rs:1:1: 1:1
|
||||
- goto -> bb23; // scope 0 at no-location
|
||||
+ goto -> bb20; // scope 0 at no-location
|
||||
}
|
||||
|
||||
- bb15: {
|
||||
|
@ -40,7 +40,7 @@ fn while_loop(_1: bool) -> () {
|
||||
|
||||
bb4: {
|
||||
StorageDead(_4); // scope 0 at $DIR/while-storage.rs:13:9: 13:10
|
||||
goto -> bb6; // scope 0 at $DIR/while-storage.rs:1:1: 1:1
|
||||
goto -> bb6; // scope 0 at no-location
|
||||
}
|
||||
|
||||
bb5: {
|
||||
|
8
src/test/ui/borrowck/issue-85765.rs
Normal file
8
src/test/ui/borrowck/issue-85765.rs
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
let mut test = Vec::new();
|
||||
let rofl: &Vec<Vec<i32>> = &mut test;
|
||||
//~^ HELP consider changing this to be a mutable reference
|
||||
rofl.push(Vec::new());
|
||||
//~^ ERROR cannot borrow `*rofl` as mutable, as it is behind a `&` reference
|
||||
//~| NOTE `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable
|
||||
}
|
12
src/test/ui/borrowck/issue-85765.stderr
Normal file
12
src/test/ui/borrowck/issue-85765.stderr
Normal file
@ -0,0 +1,12 @@
|
||||
error[E0596]: cannot borrow `*rofl` as mutable, as it is behind a `&` reference
|
||||
--> $DIR/issue-85765.rs:5:5
|
||||
|
|
||||
LL | let rofl: &Vec<Vec<i32>> = &mut test;
|
||||
| ---- help: consider changing this to be a mutable reference: `&mut Vec<Vec<i32>>`
|
||||
LL |
|
||||
LL | rofl.push(Vec::new());
|
||||
| ^^^^ `rofl` is a `&` reference, so the data it refers to cannot be borrowed as mutable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0596`.
|
@ -2,13 +2,13 @@ error: lifetime parameters must be declared prior to const parameters
|
||||
--> $DIR/intermixed-lifetime.rs:7:28
|
||||
|
|
||||
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
|
||||
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const N: usize, T = u32>`
|
||||
| -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>`
|
||||
|
||||
error: lifetime parameters must be declared prior to type parameters
|
||||
--> $DIR/intermixed-lifetime.rs:10:37
|
||||
|
|
||||
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
|
||||
| --------------------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const N: usize, T = u32>`
|
||||
| --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -5,9 +5,12 @@ LL | let e: Example::<13> = ();
|
||||
| ------------- ^^ expected struct `Example`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected struct `Example`
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:14:34
|
||||
--> $DIR/mismatch.rs:15:34
|
||||
|
|
||||
LL | let e: Example2::<u32, 13> = ();
|
||||
| ------------------- ^^ expected struct `Example2`, found `()`
|
||||
@ -18,7 +21,7 @@ LL | let e: Example2::<u32, 13> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:16:34
|
||||
--> $DIR/mismatch.rs:18:34
|
||||
|
|
||||
LL | let e: Example3::<13, u32> = ();
|
||||
| ------------------- ^^ expected struct `Example3`, found `()`
|
||||
@ -29,7 +32,7 @@ LL | let e: Example3::<13, u32> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:18:28
|
||||
--> $DIR/mismatch.rs:21:28
|
||||
|
|
||||
LL | let e: Example3::<7> = ();
|
||||
| ------------- ^^ expected struct `Example3`, found `()`
|
||||
@ -40,12 +43,15 @@ LL | let e: Example3::<7> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:22:28
|
||||
--> $DIR/mismatch.rs:24:28
|
||||
|
|
||||
LL | let e: Example4::<7> = ();
|
||||
| ------------- ^^ expected struct `Example4`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected struct `Example4<7_usize>`
|
||||
found unit type `()`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
@ -5,9 +5,12 @@ LL | let e: Example::<13> = ();
|
||||
| ------------- ^^ expected struct `Example`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected struct `Example`
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:14:34
|
||||
--> $DIR/mismatch.rs:15:34
|
||||
|
|
||||
LL | let e: Example2::<u32, 13> = ();
|
||||
| ------------------- ^^ expected struct `Example2`, found `()`
|
||||
@ -18,7 +21,7 @@ LL | let e: Example2::<u32, 13> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:16:34
|
||||
--> $DIR/mismatch.rs:18:34
|
||||
|
|
||||
LL | let e: Example3::<13, u32> = ();
|
||||
| ------------------- ^^ expected struct `Example3`, found `()`
|
||||
@ -29,7 +32,7 @@ LL | let e: Example3::<13, u32> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:18:28
|
||||
--> $DIR/mismatch.rs:21:28
|
||||
|
|
||||
LL | let e: Example3::<7> = ();
|
||||
| ------------- ^^ expected struct `Example3`, found `()`
|
||||
@ -40,12 +43,15 @@ LL | let e: Example3::<7> = ();
|
||||
found unit type `()`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/mismatch.rs:22:28
|
||||
--> $DIR/mismatch.rs:24:28
|
||||
|
|
||||
LL | let e: Example4::<7> = ();
|
||||
| ------------- ^^ expected struct `Example4`, found `()`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
= note: expected struct `Example4<7_usize>`
|
||||
found unit type `()`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
@ -11,14 +11,17 @@ pub struct Example4<const N: usize=13, const M: usize=4>;
|
||||
fn main() {
|
||||
let e: Example::<13> = ();
|
||||
//~^ Error: mismatched types
|
||||
//~| expected struct `Example`
|
||||
let e: Example2::<u32, 13> = ();
|
||||
//~^ Error: mismatched types
|
||||
//~| expected struct `Example2`
|
||||
let e: Example3::<13, u32> = ();
|
||||
//~^ Error: mismatched types
|
||||
//~| expected struct `Example3`
|
||||
let e: Example3::<7> = ();
|
||||
//~^ Error: mismatched types
|
||||
// FIXME(const_generics_defaults): There should be a note for the error below, but it is
|
||||
// missing.
|
||||
//~| expected struct `Example3<7_usize>`
|
||||
let e: Example4::<7> = ();
|
||||
//~^ Error: mismatched types
|
||||
//~| expected struct `Example4<7_usize>`
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
#![feature(const_generics_defaults)]
|
||||
struct Foo<const M: usize = 10, 'a>(&'a u32);
|
||||
//~^ Error lifetime parameters must be declared prior to const parameters
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,8 @@
|
||||
error: lifetime parameters must be declared prior to const parameters
|
||||
--> $DIR/param-order-err-pretty-prints-default.rs:2:33
|
||||
|
|
||||
LL | struct Foo<const M: usize = 10, 'a>(&'a u32);
|
||||
| ----------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const M: usize = 10>`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -1,10 +0,0 @@
|
||||
struct Const<const P: &'static ()>;
|
||||
//~^ ERROR `&'static ()` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {
|
||||
const A: &'static () = unsafe {
|
||||
std::mem::transmute(10 as *const ())
|
||||
};
|
||||
|
||||
let _ = Const::<{A}>;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
error: `&'static ()` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/transmute-const-param-static-reference.rs:1:23
|
||||
--> $DIR/transmute-const-param-static-reference.rs:7:23
|
||||
|
|
||||
LL | struct Const<const P: &'static ()>;
|
||||
| ^^^^^^^^^^^
|
@ -0,0 +1,16 @@
|
||||
// revisions: full min
|
||||
//[full] check-pass
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
|
||||
struct Const<const P: &'static ()>;
|
||||
//[min]~^ ERROR `&'static ()` is forbidden as the type of a const generic parameter
|
||||
|
||||
fn main() {
|
||||
const A: &'static () = unsafe {
|
||||
std::mem::transmute(10 as *const ())
|
||||
};
|
||||
|
||||
let _ = Const::<{A}>;
|
||||
}
|
21
src/test/ui/consts/const-eval/ub-incorrect-vtable.rs
Normal file
21
src/test/ui/consts/const-eval/ub-incorrect-vtable.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// This test contains code with incorrect vtables in a const context:
|
||||
// - from issue 86132: a trait object with invalid alignment caused an ICE in const eval, and now
|
||||
// triggers an error
|
||||
// - a similar test that triggers a previously-untested const UB error: emitted close to the above
|
||||
// error, it checks the correctness of the size
|
||||
|
||||
trait Trait {}
|
||||
|
||||
const INVALID_VTABLE_ALIGNMENT: &dyn Trait =
|
||||
unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
//~| WARNING this was previously accepted by the compiler
|
||||
//~| invalid vtable: alignment `1000` is not a power of 2
|
||||
|
||||
const INVALID_VTABLE_SIZE: &dyn Trait =
|
||||
unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) };
|
||||
//~^ ERROR any use of this value will cause an error
|
||||
//~| WARNING this was previously accepted by the compiler
|
||||
//~| invalid vtable: size is bigger than largest supported object
|
||||
|
||||
fn main() {}
|
27
src/test/ui/consts/const-eval/ub-incorrect-vtable.stderr
Normal file
27
src/test/ui/consts/const-eval/ub-incorrect-vtable.stderr
Normal file
@ -0,0 +1,27 @@
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/ub-incorrect-vtable.rs:10:14
|
||||
|
|
||||
LL | / const INVALID_VTABLE_ALIGNMENT: &dyn Trait =
|
||||
LL | | unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) };
|
||||
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__-
|
||||
| |
|
||||
| invalid vtable: alignment `1000` is not a power of 2
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: any use of this value will cause an error
|
||||
--> $DIR/ub-incorrect-vtable.rs:16:14
|
||||
|
|
||||
LL | / const INVALID_VTABLE_SIZE: &dyn Trait =
|
||||
LL | | unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) };
|
||||
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__-
|
||||
| |
|
||||
| invalid vtable: size is bigger than largest supported object
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user