File tree 4 files changed +66
-0
lines changed
rustc_trait_selection/src/traits
4 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -2116,6 +2116,13 @@ rustc_queries! {
2116
2116
}
2117
2117
}
2118
2118
2119
+ query is_impossible_item( def_id: DefId ) -> bool {
2120
+ desc { |tcx|
2121
+ "checking if `{}` is impossible to reference" ,
2122
+ tcx. def_path_str( def_id) ,
2123
+ }
2124
+ }
2125
+
2119
2126
query is_impossible_associated_item( key: ( DefId , DefId ) ) -> bool {
2120
2127
desc { |tcx|
2121
2128
"checking if `{}` is impossible to reference within `{}`" ,
Original file line number Diff line number Diff line change @@ -51,6 +51,11 @@ impl<'tcx> MirLint<'tcx> for KnownPanicsLint {
51
51
return ;
52
52
}
53
53
54
+ if tcx. is_impossible_item ( def_id) {
55
+ trace ! ( "KnownPanicsLint skipped for impossible item {:?}" , def_id) ;
56
+ return ;
57
+ }
58
+
54
59
trace ! ( "KnownPanicsLint starting for {:?}" , def_id) ;
55
60
56
61
let mut linter = ConstPropagator :: new ( body, tcx) ;
Original file line number Diff line number Diff line change @@ -421,6 +421,16 @@ fn instantiate_and_check_impossible_predicates<'tcx>(
421
421
result
422
422
}
423
423
424
+ /// Checks whether an item is impossible to reference.
425
+ #[ instrument( level = "debug" , skip( tcx) , ret) ]
426
+ fn is_impossible_item < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : DefId ) -> bool {
427
+ let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
428
+ impossible_predicates (
429
+ tcx,
430
+ param_env. caller_bounds ( ) . iter ( ) . filter ( |predicate| !predicate. has_param ( ) ) . collect ( ) ,
431
+ )
432
+ }
433
+
424
434
/// Checks whether a trait's associated item is impossible to reference on a given impl.
425
435
///
426
436
/// This only considers predicates that reference the impl's generics, and not
@@ -506,6 +516,7 @@ pub fn provide(providers: &mut Providers) {
506
516
specializes : specialize:: specializes,
507
517
instantiate_and_check_impossible_predicates,
508
518
check_tys_might_be_eq : misc:: check_tys_might_be_eq,
519
+ is_impossible_item,
509
520
is_impossible_associated_item,
510
521
..* providers
511
522
} ;
Original file line number Diff line number Diff line change
1
+ //@ build-pass
2
+ // Regression test for an ICE: https://github.com/rust-lang/rust/issues/123134
3
+
4
+ trait Api : Sized {
5
+ type Device : ?Sized ;
6
+ }
7
+
8
+ struct OpenDevice < A : Api >
9
+ where
10
+ A :: Device : Sized ,
11
+ {
12
+ device : A :: Device ,
13
+ queue : ( ) ,
14
+ }
15
+
16
+ trait Adapter {
17
+ type A : Api ;
18
+
19
+ fn open ( ) -> OpenDevice < Self :: A >
20
+ where
21
+ <Self :: A as Api >:: Device : Sized ;
22
+ }
23
+
24
+ struct ApiS ;
25
+
26
+ impl Api for ApiS {
27
+ type Device = [ u8 ] ;
28
+ }
29
+
30
+ impl < T > Adapter for T
31
+ {
32
+ type A = ApiS ;
33
+
34
+ // This function has the impossible predicate `[u8]: Sized`.
35
+ fn open ( ) -> OpenDevice < Self :: A >
36
+ where
37
+ <Self :: A as Api >:: Device : Sized ,
38
+ {
39
+ unreachable ! ( )
40
+ }
41
+ }
42
+
43
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments