Skip to content

Commit 60713f4

Browse files
committed
Auto merge of rust-lang#114879 - matthiaskrgr:rollup-tim571q, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#114721 (Optimizing the rest of bool's Ord implementation) - rust-lang#114746 (Don't add associated type bound for non-types) - rust-lang#114779 (Add check before suggest removing parens) - rust-lang#114859 (Add trait related queries to SMIR's rustc_internal) - rust-lang#114861 (fix typo: affect -> effect) - rust-lang#114867 ([nit] Fix a comment typo.) - rust-lang#114871 (Update the link in the docs of `std::intrinsics`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4e3ce0e + 6024ad1 commit 60713f4

File tree

15 files changed

+119
-15
lines changed

15 files changed

+119
-15
lines changed

compiler/rustc_hir_analysis/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
hir_analysis_ambiguous_lifetime_bound =
22
ambiguous lifetime bound, explicit lifetime bound required
33
4+
hir_analysis_assoc_bound_on_const = expected associated type, found {$descr}
5+
.note = trait bounds not allowed on {$descr}
6+
47
hir_analysis_assoc_type_binding_not_allowed =
58
associated type bindings are not allowed here
69
.label = associated type not allowed here

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::astconv::{
1313
AstConv, ConvertedBinding, ConvertedBindingKind, OnlySelfBounds, PredicateFilter,
1414
};
1515
use crate::bounds::Bounds;
16-
use crate::errors::{MultipleRelaxedDefaultBounds, ValueOfAssociatedStructAlreadySpecified};
16+
use crate::errors;
1717

1818
impl<'tcx> dyn AstConv<'tcx> + '_ {
1919
/// Sets `implicitly_sized` to true on `Bounds` if necessary
@@ -35,7 +35,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
3535
if unbound.is_none() {
3636
unbound = Some(&ptr.trait_ref);
3737
} else {
38-
tcx.sess.emit_err(MultipleRelaxedDefaultBounds { span });
38+
tcx.sess.emit_err(errors::MultipleRelaxedDefaultBounds { span });
3939
}
4040
}
4141
}
@@ -326,7 +326,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
326326
dup_bindings
327327
.entry(assoc_item.def_id)
328328
.and_modify(|prev_span| {
329-
tcx.sess.emit_err(ValueOfAssociatedStructAlreadySpecified {
329+
tcx.sess.emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
330330
span: binding.span,
331331
prev_span: *prev_span,
332332
item_name: binding.item_name,
@@ -488,6 +488,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
488488
}
489489
}
490490

491+
let assoc_item_def_id = projection_ty.skip_binder().def_id;
492+
let def_kind = tcx.def_kind(assoc_item_def_id);
491493
match binding.kind {
492494
ConvertedBindingKind::Equality(..) if return_type_notation => {
493495
return Err(self.tcx().sess.emit_err(
@@ -499,11 +501,9 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
499501
// the "projection predicate" for:
500502
//
501503
// `<T as Iterator>::Item = u32`
502-
let assoc_item_def_id = projection_ty.skip_binder().def_id;
503-
let def_kind = tcx.def_kind(assoc_item_def_id);
504504
match (def_kind, term.unpack()) {
505-
(hir::def::DefKind::AssocTy, ty::TermKind::Ty(_))
506-
| (hir::def::DefKind::AssocConst, ty::TermKind::Const(_)) => (),
505+
(DefKind::AssocTy, ty::TermKind::Ty(_))
506+
| (DefKind::AssocConst, ty::TermKind::Const(_)) => (),
507507
(_, _) => {
508508
let got = if let Some(_) = term.ty() { "type" } else { "constant" };
509509
let expected = tcx.def_descr(assoc_item_def_id);
@@ -516,7 +516,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
516516
format!("{expected} defined here"),
517517
);
518518

519-
if let hir::def::DefKind::AssocConst = def_kind
519+
if let DefKind::AssocConst = def_kind
520520
&& let Some(t) = term.ty() && (t.is_enum() || t.references_error())
521521
&& tcx.features().associated_const_equality {
522522
err.span_suggestion(
@@ -528,8 +528,8 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
528528
}
529529
let reported = err.emit();
530530
term = match def_kind {
531-
hir::def::DefKind::AssocTy => Ty::new_error(tcx, reported).into(),
532-
hir::def::DefKind::AssocConst => ty::Const::new_error(
531+
DefKind::AssocTy => Ty::new_error(tcx, reported).into(),
532+
DefKind::AssocConst => ty::Const::new_error(
533533
tcx,
534534
reported,
535535
tcx.type_of(assoc_item_def_id)
@@ -548,6 +548,15 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
548548
);
549549
}
550550
ConvertedBindingKind::Constraint(ast_bounds) => {
551+
match def_kind {
552+
DefKind::AssocTy => {}
553+
_ => {
554+
return Err(tcx.sess.emit_err(errors::AssocBoundOnConst {
555+
span: assoc_ident.span,
556+
descr: tcx.def_descr(assoc_item_def_id),
557+
}));
558+
}
559+
}
551560
// "Desugar" a constraint like `T: Iterator<Item: Debug>` to
552561
//
553562
// `<T as Iterator>::Item: Debug`

compiler/rustc_hir_analysis/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -918,3 +918,12 @@ pub struct UnusedAssociatedTypeBounds {
918918
#[suggestion(code = "")]
919919
pub span: Span,
920920
}
921+
922+
#[derive(Diagnostic)]
923+
#[diag(hir_analysis_assoc_bound_on_const)]
924+
#[note]
925+
pub struct AssocBoundOnConst {
926+
#[primary_span]
927+
pub span: Span,
928+
pub descr: &'static str,
929+
}

compiler/rustc_hir_typeck/src/callee.rs

+1
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
599599
= self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
600600
// Only suggest removing parens if there are no arguments
601601
&& arg_exprs.is_empty()
602+
&& call_expr.span.contains(callee_expr.span)
602603
{
603604
let descr = match kind {
604605
def::CtorOf::Struct => "struct",

compiler/rustc_smir/src/stable_mir/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ pub fn all_local_items() -> CrateItems {
8585
with(|cx| cx.all_local_items())
8686
}
8787

88+
pub fn all_trait_decls() -> TraitDecls {
89+
with(|cx| cx.all_trait_decls())
90+
}
91+
92+
pub fn trait_decl(trait_def: &TraitDef) -> TraitDecl {
93+
with(|cx| cx.trait_decl(trait_def))
94+
}
95+
96+
pub fn all_trait_impls() -> ImplTraitDecls {
97+
with(|cx| cx.all_trait_impls())
98+
}
99+
100+
pub fn trait_impl(trait_impl: &ImplDef) -> ImplTrait {
101+
with(|cx| cx.trait_impl(trait_impl))
102+
}
103+
88104
pub trait Context {
89105
fn entry_fn(&mut self) -> Option<CrateItem>;
90106
/// Retrieve all items of the local crate that have a MIR associated with them.

library/alloc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
5959
// To run alloc tests without x.py without ending up with two copies of alloc, Miri needs to be
6060
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
61-
// rustc itself never sets the feature, so this line has no affect there.
61+
// rustc itself never sets the feature, so this line has no effect there.
6262
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
6363
//
6464
#![allow(unused_attributes)]

library/alloc/src/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str> {
612612
}
613613

614614
/// Converts the bytes while the bytes are still ascii.
615-
/// For better average performance, this is happens in chunks of `2*size_of::<usize>()`.
615+
/// For better average performance, this happens in chunks of `2*size_of::<usize>()`.
616616
/// Returns a vec with the converted bytes.
617617
#[inline]
618618
#[cfg(not(test))]

library/core/src/cmp.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,22 @@ mod impls {
14061406
_ => unsafe { unreachable_unchecked() },
14071407
}
14081408
}
1409+
1410+
#[inline]
1411+
fn min(self, other: bool) -> bool {
1412+
self & other
1413+
}
1414+
1415+
#[inline]
1416+
fn max(self, other: bool) -> bool {
1417+
self | other
1418+
}
1419+
1420+
#[inline]
1421+
fn clamp(self, min: bool, max: bool) -> bool {
1422+
assert!(min <= max);
1423+
self.max(min).min(max)
1424+
}
14091425
}
14101426

14111427
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }

library/core/src/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! This includes changes in the stability of the constness.
1010
//!
1111
//! In order to make an intrinsic usable at compile-time, one needs to copy the implementation
12-
//! from <https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs> to
12+
//! from <https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics> to
1313
//! <https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/interpret/intrinsics.rs> and add a
1414
//! `#[rustc_const_unstable(feature = "const_such_and_such", issue = "01234")]` to the intrinsic declaration.
1515
//!

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#![cfg(not(test))]
5252
// To run core tests without x.py without ending up with two copies of core, Miri needs to be
5353
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
54-
// rustc itself never sets the feature, so this line has no affect there.
54+
// rustc itself never sets the feature, so this line has no effect there.
5555
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
5656
#![stable(feature = "core", since = "1.6.0")]
5757
#![doc(

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
191191
// To run std tests without x.py without ending up with two copies of std, Miri needs to be
192192
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
193-
// rustc itself never sets the feature, so this line has no affect there.
193+
// rustc itself never sets the feature, so this line has no effect there.
194194
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
195195
// miri-test-libstd also prefers to make std use the sysroot versions of the dependencies.
196196
#![cfg_attr(feature = "miri-test-libstd", feature(rustc_private))]
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(associated_type_bounds)]
2+
3+
pub fn accept(_: impl Trait<K: Copy>) {}
4+
//~^ ERROR expected associated type, found associated constant
5+
6+
pub trait Trait {
7+
const K: i32;
8+
}
9+
10+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected associated type, found associated constant
2+
--> $DIR/consts.rs:3:29
3+
|
4+
LL | pub fn accept(_: impl Trait<K: Copy>) {}
5+
| ^
6+
|
7+
= note: trait bounds not allowed on associated constant
8+
9+
error: aborting due to previous error
10+

tests/ui/suggestions/issue-114701.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enum Enum<T> { SVariant { v: T }, UVariant }
2+
3+
macro_rules! is_variant {
4+
(TSVariant, ) => (!);
5+
(SVariant, ) => (!);
6+
(UVariant, $expr:expr) => (is_variant!(@check UVariant, {}, $expr));
7+
(@check $variant:ident, $matcher:tt, $expr:expr) => (
8+
assert!(if let Enum::$variant::<()> $matcher = $expr () { true } else { false },
9+
);
10+
);
11+
}
12+
13+
fn main() {
14+
is_variant!(UVariant, Enum::<()>::UVariant); //~ ERROR expected function
15+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0618]: expected function, found `Enum<()>`
2+
--> $DIR/issue-114701.rs:14:27
3+
|
4+
LL | enum Enum<T> { SVariant { v: T }, UVariant }
5+
| -------- `Enum::UVariant` defined here
6+
...
7+
LL | assert!(if let Enum::$variant::<()> $matcher = $expr () { true } else { false },
8+
| -------- call expression requires function
9+
...
10+
LL | is_variant!(UVariant, Enum::<()>::UVariant);
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0618`.

0 commit comments

Comments
 (0)