mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Mark all missing generic args as errors
This commit is contained in:
parent
24af952ef7
commit
2e3842b6d0
@ -422,6 +422,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
span: Span,
|
span: Span,
|
||||||
inferred_params: Vec<Span>,
|
inferred_params: Vec<Span>,
|
||||||
infer_args: bool,
|
infer_args: bool,
|
||||||
|
incorrect_args: &'a Result<(), GenericArgCountMismatch>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
|
||||||
@ -508,6 +509,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
infer_args: bool,
|
infer_args: bool,
|
||||||
) -> ty::GenericArg<'tcx> {
|
) -> ty::GenericArg<'tcx> {
|
||||||
let tcx = self.lowerer.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 {
|
match param.kind {
|
||||||
GenericParamDefKind::Lifetime => self
|
GenericParamDefKind::Lifetime => self
|
||||||
.lowerer
|
.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
|
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
|
||||||
&& generics.has_self
|
&& generics.has_self
|
||||||
&& !tcx.has_attr(def_id, sym::const_trait)
|
&& !tcx.has_attr(def_id, sym::const_trait)
|
||||||
@ -588,6 +599,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
self.set_tainted_by_errors(reported);
|
self.set_tainted_by_errors(reported);
|
||||||
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
|
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(
|
let args = lower_generic_args(
|
||||||
tcx,
|
tcx,
|
||||||
def_id,
|
def_id,
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -24,7 +24,6 @@ fn via_associated_const() {
|
|||||||
trait Trait {
|
trait Trait {
|
||||||
const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
|
const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
|
||||||
//~^ ERROR mismatched types
|
//~^ ERROR mismatched types
|
||||||
//~| ERROR `Src` cannot be safely transmuted into `Dst`
|
|
||||||
//~| ERROR mismatched types
|
//~| ERROR mismatched types
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,28 +12,13 @@ error[E0308]: mismatched types
|
|||||||
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
|
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
|
||||||
| ^^ expected `Assume`, found `()`
|
| ^^ 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
|
error[E0308]: mismatched types
|
||||||
--> $DIR/transmutable-ice-110969.rs:25:29
|
--> $DIR/transmutable-ice-110969.rs:25:29
|
||||||
|
|
|
|
||||||
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
|
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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`.
|
For more information about an error, try `rustc --explain E0107`.
|
||||||
|
20
tests/ui/polymorphization/abi_mismatch.rs
Normal file
20
tests/ui/polymorphization/abi_mismatch.rs
Normal 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() {}
|
11
tests/ui/polymorphization/abi_mismatch.stderr
Normal file
11
tests/ui/polymorphization/abi_mismatch.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user