Skip to content

Commit 2e3842b

Browse files
committed
Mark all missing generic args as errors
1 parent 24af952 commit 2e3842b

File tree

6 files changed

+63
-68
lines changed

6 files changed

+63
-68
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
422422
span: Span,
423423
inferred_params: Vec<Span>,
424424
infer_args: bool,
425+
incorrect_args: &'a Result<(), GenericArgCountMismatch>,
425426
}
426427

427428
impl<'a, 'tcx> GenericArgsLowerer<'a, 'tcx> for GenericArgsCtxt<'a, 'tcx> {
@@ -508,6 +509,25 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
508509
infer_args: bool,
509510
) -> ty::GenericArg<'tcx> {
510511
let tcx = self.lowerer.tcx();
512+
513+
if let Err(incorrect) = self.incorrect_args {
514+
if incorrect.invalid_args.contains(&(param.index as usize)) {
515+
return match param.kind {
516+
GenericParamDefKind::Lifetime => {
517+
ty::Region::new_error(tcx, incorrect.reported).into()
518+
}
519+
GenericParamDefKind::Type { .. } => {
520+
Ty::new_error(tcx, incorrect.reported).into()
521+
}
522+
GenericParamDefKind::Const { .. } => ty::Const::new_error(
523+
tcx,
524+
incorrect.reported,
525+
Ty::new_error(tcx, incorrect.reported),
526+
)
527+
.into(),
528+
};
529+
}
530+
}
511531
match param.kind {
512532
GenericParamDefKind::Lifetime => self
513533
.lowerer
@@ -568,15 +588,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
568588
}
569589
}
570590
}
571-
572-
let mut args_ctx = GenericArgsCtxt {
573-
lowerer: self,
574-
def_id,
575-
span,
576-
generic_args: segment.args(),
577-
inferred_params: vec![],
578-
infer_args: segment.infer_args,
579-
};
580591
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
581592
&& generics.has_self
582593
&& !tcx.has_attr(def_id, sym::const_trait)
@@ -588,6 +599,16 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
588599
self.set_tainted_by_errors(reported);
589600
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
590601
}
602+
603+
let mut args_ctx = GenericArgsCtxt {
604+
lowerer: self,
605+
def_id,
606+
span,
607+
generic_args: segment.args(),
608+
inferred_params: vec![],
609+
infer_args: segment.infer_args,
610+
incorrect_args: &arg_count.correct,
611+
};
591612
let args = lower_generic_args(
592613
tcx,
593614
def_id,

tests/crashes/123917.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

tests/ui/const-generics/adt_const_params/transmutable-ice-110969.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ fn via_associated_const() {
2424
trait Trait {
2525
const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
2626
//~^ ERROR mismatched types
27-
//~| ERROR `Src` cannot be safely transmuted into `Dst`
2827
//~| ERROR mismatched types
2928
}
3029
}

tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@ error[E0308]: mismatched types
1212
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
1313
| ^^ expected `Assume`, found `()`
1414

15-
error[E0277]: `Src` cannot be safely transmuted into `Dst`
16-
--> $DIR/transmutable-ice-110969.rs:25:60
17-
|
18-
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
19-
| ^^^ `Dst` may carry safety invariants
20-
|
21-
note: required by a bound in `is_transmutable`
22-
--> $DIR/transmutable-ice-110969.rs:11:14
23-
|
24-
LL | pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>()
25-
| --------------- required by a bound in this function
26-
LL | where
27-
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_transmutable`
29-
3015
error[E0308]: mismatched types
3116
--> $DIR/transmutable-ice-110969.rs:25:29
3217
|
3318
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
3419
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
3520

36-
error: aborting due to 4 previous errors
21+
error: aborting due to 3 previous errors
3722

38-
Some errors have detailed explanations: E0107, E0277, E0308.
23+
Some errors have detailed explanations: E0107, E0308.
3924
For more information about an error, try `rustc --explain E0107`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! This test used to ICE: #123917
2+
//! The reason was that while the AST knows about two fields
3+
//! named `ptr`, only one exists at the layout level, so accessing
4+
//! `_extra_field` would use an oob index
5+
//@ compile-flags: -Zmir-opt-level=5 -Zpolymorphize=on
6+
7+
struct NonNull<T>(*mut T);
8+
9+
struct Token<T> {
10+
ptr: *mut T,
11+
ptr: NonNull<T>,
12+
//~^ ERROR: `ptr` is already declared
13+
_extra_field: (),
14+
}
15+
16+
fn tokenize<T>(item: *mut T) -> Token<T> {
17+
Token { ptr: NonNull(item), _extra_field: () }
18+
}
19+
20+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0124]: field `ptr` is already declared
2+
--> $DIR/abi_mismatch.rs:11:5
3+
|
4+
LL | ptr: *mut T,
5+
| ----------- `ptr` first declared here
6+
LL | ptr: NonNull<T>,
7+
| ^^^^^^^^^^^^^^^ field already declared
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0124`.

0 commit comments

Comments
 (0)