Skip to content

Commit aed44b6

Browse files
committed
fix issues and ui test
1 parent ec16e33 commit aed44b6

2 files changed

Lines changed: 2 additions & 15 deletions

File tree

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,8 @@ impl<'tcx> TyCtxt<'tcx> {
21812181
self.constness(def_id) == hir::Constness::Const
21822182
}
21832183
DefKind::Impl { of_trait: true } => {
2184-
self.constness(self.trait_item_of(def_id).unwrap()) == hir::Constness::Const
2184+
let Some(trait_method_did) = self.trait_item_of(def_id) else { return false; };
2185+
self.constness(trait_method_did) == hir::Constness::Const
21852186
&& self.is_conditionally_const(parent_def_id)
21862187
}
21872188
DefKind::Trait => {

tests/ui/typeck/typeck_type_placeholder_item.stderr

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,6 @@ error[E0015]: cannot call non-const method `<std::ops::Range<i32> as Iterator>::
684684
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
685685
| ^^^^^^^^^^^^^^^^^^^^^^
686686
|
687-
note: method `filter` is not const because trait `Iterator` is not const
688-
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
689-
|
690-
= note: this trait is not const
691-
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
692-
|
693-
= note: this method is not const
694687
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
695688

696689
error[E0015]: cannot call non-const method `<Filter<std::ops::Range<i32>, {closure@$DIR/typeck_type_placeholder_item.rs:240:29: 240:32}> as Iterator>::map::<i32, {closure@$DIR/typeck_type_placeholder_item.rs:240:49: 240:52}>` in constants
@@ -699,13 +692,6 @@ error[E0015]: cannot call non-const method `<Filter<std::ops::Range<i32>, {closu
699692
LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x);
700693
| ^^^^^^^^^^^^^^
701694
|
702-
note: method `map` is not const because trait `Iterator` is not const
703-
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
704-
|
705-
= note: this trait is not const
706-
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
707-
|
708-
= note: this method is not const
709695
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
710696

711697
error: aborting due to 83 previous errors

0 commit comments

Comments
 (0)