Mark all missing generic args as errors

This commit is contained in:
Oli Scherer 2024-06-03 13:16:56 +00:00
parent 24af952ef7
commit 2e3842b6d0
6 changed files with 63 additions and 68 deletions

View File

@ -422,6 +422,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
span: Span,
inferred_params: Vec<Span>,
infer_args: bool,
incorrect_args: &'a Result<(), GenericArgCountMismatch>,
}
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
@ -508,6 +509,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
infer_args: bool,
) -> ty::GenericArg<'tcx> {
let tcx = self.lowerer.tcx();
if let Err(incorrect) = self.incorrect_args {
if incorrect.invalid_args.contains(&(param.index as usize)) {
return match param.kind {
GenericParamDefKind::Lifetime => {
ty::Region::new_error(tcx, incorrect.reported).into()
}
GenericParamDefKind::Type { .. } => {
Ty::new_error(tcx, incorrect.reported).into()
}
GenericParamDefKind::Const { .. } => ty::Const::new_error(
tcx,
incorrect.reported,
Ty::new_error(tcx, incorrect.reported),
)
.into(),
};
}
}
match param.kind {
GenericParamDefKind::Lifetime => self
.lowerer
@ -568,15 +588,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
}
}
let mut args_ctx = GenericArgsCtxt {
lowerer: self,
def_id,
span,
generic_args: segment.args(),
inferred_params: vec![],
infer_args: segment.infer_args,
};
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
&& generics.has_self
&& !tcx.has_attr(def_id, sym::const_trait)
@ -588,6 +599,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
self.set_tainted_by_errors(reported);
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
}
let mut args_ctx = GenericArgsCtxt {
lowerer: self,
def_id,
span,
generic_args: segment.args(),
inferred_params: vec![],
infer_args: segment.infer_args,
incorrect_args: &arg_count.correct,
};
let args = lower_generic_args(
tcx,
def_id,

View File

@ -1,41 +0,0 @@
//@ known-bug: #123917
//@ compile-flags: -Zmir-opt-level=5 -Zpolymorphize=on
use std::marker::PhantomData;
pub struct Id<'id>();
pub struct Item<'life, T> {
data: T,
}
pub struct Token<'life, 'borrow, 'compact, 'reborrow, T>
where
'life: 'reborrow,
T: Tokenize,
{
ptr: *mut <T as Tokenize>::Tokenized,
ptr: core::ptr::NonNull<T::Tokenized>,
_phantom: PhantomData<Id<'life>>,
}
impl<'life> Arena<'life> {
pub fn tokenize<'before, 'compact, 'borrow, 'reborrow, T, U>(
item: Item<'life, &'before mut T>,
) -> Token<'life, 'borrow, 'compact, 'reborrow, U>
where
T: Tokenize<'life, 'borrow, 'compact, 'reborrow, Untokenized = U>,
T::Untokenized: Tokenize<'life, 'borrow, 'compact, 'reborrow>,
{
let dst = item.data as *mut T as *mut T::Tokenized;
Token {
ptr: core::ptr::NonNull::new(dst as *mut _).unwrap(),
_phantom: PhantomData,
}
}
}
pub trait Tokenize {
type Tokenized;
type Untokenized;
}

View File

@ -24,7 +24,6 @@ fn via_associated_const() {
trait Trait {
const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
//~^ ERROR mismatched types
//~| ERROR `Src` cannot be safely transmuted into `Dst`
//~| ERROR mismatched types
}
}

View File

@ -12,28 +12,13 @@ error[E0308]: mismatched types
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
| ^^ expected `Assume`, found `()`
error[E0277]: `Src` cannot be safely transmuted into `Dst`
--> $DIR/transmutable-ice-110969.rs:25:60
|
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
| ^^^ `Dst` may carry safety invariants
|
note: required by a bound in `is_transmutable`
--> $DIR/transmutable-ice-110969.rs:11:14
|
LL | pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>()
| --------------- required by a bound in this function
LL | where
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_transmutable`
error[E0308]: mismatched types
--> $DIR/transmutable-ice-110969.rs:25:29
|
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0107, E0277, E0308.
Some errors have detailed explanations: E0107, E0308.
For more information about an error, try `rustc --explain E0107`.

View File

@ -0,0 +1,20 @@
//! This test used to ICE: #123917
//! The reason was that while the AST knows about two fields
//! named `ptr`, only one exists at the layout level, so accessing
//! `_extra_field` would use an oob index
//@ compile-flags: -Zmir-opt-level=5 -Zpolymorphize=on
struct NonNull<T>(*mut T);
struct Token<T> {
ptr: *mut T,
ptr: NonNull<T>,
//~^ ERROR: `ptr` is already declared
_extra_field: (),
}
fn tokenize<T>(item: *mut T) -> Token<T> {
Token { ptr: NonNull(item), _extra_field: () }
}
fn main() {}

View File

@ -0,0 +1,11 @@
error[E0124]: field `ptr` is already declared
--> $DIR/abi_mismatch.rs:11:5
|
LL | ptr: *mut T,
| ----------- `ptr` first declared here
LL | ptr: NonNull<T>,
| ^^^^^^^^^^^^^^^ field already declared
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0124`.