Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #109516

Closed
wants to merge 24 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f28f77f
resolve: Remove `item_generics_num_lifetimes`
petrochenkov Feb 21, 2023
d99e01f
resolve: Remove `item_attrs_untracked`
petrochenkov Feb 21, 2023
52c7397
resolve: Use `item_name` and `opt_parent` in `Resolver::get_module`
petrochenkov Mar 14, 2023
18b59f5
resolve: Minor cleanup to `Resolver::get_module`
petrochenkov Mar 14, 2023
009ed88
Add `known-bug` test for typeid unsoundness issue
Randl Mar 20, 2023
7c2ee33
Refine error spans for const args in hir typeck
compiler-errors Mar 9, 2023
2e7472f
Note type mismatch on ConstArgHasType
compiler-errors Mar 9, 2023
ec25f08
Demonstration test for MIR building of checked shift operators
scottmcm Mar 22, 2023
b537e6b
Generate simpler MIR for shifts
scottmcm Mar 22, 2023
e8be3d2
Stabilize `arc_into_inner` and `rc_into_inner`.
steffahn Mar 14, 2023
3f7aeb3
make param bound vars visibly bound vars
BoxyUwU Mar 23, 2023
5dc3fd7
Include relation direction in AliasEq predicate
compiler-errors Mar 21, 2023
3a36a09
Rename AliasEq -> AliasRelate
compiler-errors Mar 21, 2023
f6fd754
Printing alias-relate goals correctly
compiler-errors Mar 21, 2023
244cdaa
Remove AliasRelationDirection::Supertype
compiler-errors Mar 22, 2023
e5189cc
Nested impl traits trigger opaque_hidden_inferred_bound too much
compiler-errors Feb 27, 2023
484ef47
Rollup merge of #108541 - compiler-errors:lol-nested-rpits, r=oli-obk
matthiaskrgr Mar 23, 2023
4213fac
Rollup merge of #108961 - compiler-errors:refine-ct-errors, r=BoxyUwU
matthiaskrgr Mar 23, 2023
2c9ac4a
Rollup merge of #109137 - petrochenkov:qcstore2, r=cjgillot
matthiaskrgr Mar 23, 2023
0dac4a1
Rollup merge of #109380 - Randl:patch-1, r=oli-obk
matthiaskrgr Mar 23, 2023
80bfee1
Rollup merge of #109462 - compiler-errors:alias-relate, r=BoxyUwU,lcnr
matthiaskrgr Mar 23, 2023
2603ef0
Rollup merge of #109475 - scottmcm:simpler-shifts, r=WaffleLapkin
matthiaskrgr Mar 23, 2023
9ee96c8
Rollup merge of #109504 - steffahn:stabilize_a_rc_into_inner, r=josht…
matthiaskrgr Mar 23, 2023
eeeb44e
Rollup merge of #109506 - BoxyUwU:debugable_bound_var_printing, r=com…
matthiaskrgr Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refine error spans for const args in hir typeck
  • Loading branch information
compiler-errors committed Mar 20, 2023
commit 7c2ee33137cb3c42e6795804ef62d7eddc09e159
46 changes: 28 additions & 18 deletions compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ use rustc_hir::def::Res;
use rustc_hir::def_id::DefId;
use rustc_infer::traits::ObligationCauseCode;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
use rustc_span::{self, Span};
use rustc_span::{self, symbol::kw, Span};
use rustc_trait_selection::traits;

use std::ops::ControlFlow;
@@ -25,17 +25,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let generics = self.tcx.generics_of(def_id);
let predicate_substs = match unsubstituted_pred.kind().skip_binder() {
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => pred.trait_ref.substs,
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => pred.projection_ty.substs,
_ => ty::List::empty(),
ty::PredicateKind::Clause(ty::Clause::Trait(pred)) => pred.trait_ref.substs.to_vec(),
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
pred.projection_ty.substs.to_vec()
}
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(arg, ty)) => {
vec![ty.into(), arg.into()]
}
ty::PredicateKind::ConstEvaluatable(e) => vec![e.into()],
_ => return false,
};

let find_param_matching = |matches: &dyn Fn(&ty::ParamTy) -> bool| {
predicate_substs.types().find_map(|ty| {
ty.walk().find_map(|arg| {
let find_param_matching = |matches: &dyn Fn(ty::ParamTerm) -> bool| {
predicate_substs.iter().find_map(|arg| {
arg.walk().find_map(|arg| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& let ty::Param(param_ty) = ty.kind()
&& matches(param_ty)
&& let ty::Param(param_ty) = *ty.kind()
&& matches(ty::ParamTerm::Ty(param_ty))
{
Some(arg)
} else if let ty::GenericArgKind::Const(ct) = arg.unpack()
&& let ty::ConstKind::Param(param_ct) = ct.kind()
&& matches(ty::ParamTerm::Const(param_ct))
{
Some(arg)
} else {
@@ -47,21 +58,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Prefer generics that are local to the fn item, since these are likely
// to be the cause of the unsatisfied predicate.
let mut param_to_point_at = find_param_matching(&|param_ty| {
self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) == def_id
let mut param_to_point_at = find_param_matching(&|param_term| {
self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) == def_id
});
// Fall back to generic that isn't local to the fn item. This will come
// from a trait or impl, for example.
let mut fallback_param_to_point_at = find_param_matching(&|param_ty| {
self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) != def_id
&& param_ty.name != rustc_span::symbol::kw::SelfUpper
let mut fallback_param_to_point_at = find_param_matching(&|param_term| {
self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) != def_id
&& !matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper)
});
// Finally, the `Self` parameter is possibly the reason that the predicate
// is unsatisfied. This is less likely to be true for methods, because
// method probe means that we already kinda check that the predicates due
// to the `Self` type are true.
let mut self_param_to_point_at =
find_param_matching(&|param_ty| param_ty.name == rustc_span::symbol::kw::SelfUpper);
let mut self_param_to_point_at = find_param_matching(
&|param_term| matches!(param_term, ty::ParamTerm::Ty(ty) if ty.name == kw::SelfUpper),
);

// Finally, for ambiguity-related errors, we actually want to look
// for a parameter that is the source of the inference type left
@@ -225,14 +237,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
.own_substs(ty::InternalSubsts::identity_for_item(self.tcx, def_id));
let Some((index, _)) = own_substs
.iter()
.filter(|arg| matches!(arg.unpack(), ty::GenericArgKind::Type(_)))
.enumerate()
.find(|(_, arg)| **arg == param_to_point_at) else { return false };
let Some(arg) = segment
.args()
.args
.iter()
.filter(|arg| matches!(arg, hir::GenericArg::Type(_)))
.nth(index) else { return false; };
error.obligation.cause.span = arg
.span()
15 changes: 15 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -1035,6 +1035,21 @@ impl<'tcx> TermKind<'tcx> {
}
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum ParamTerm {
Ty(ParamTy),
Const(ParamConst),
}

impl ParamTerm {
pub fn index(self) -> usize {
match self {
ParamTerm::Ty(ty) => ty.index as usize,
ParamTerm::Const(ct) => ct.index as usize,
}
}
}

/// This kind of predicate has no *direct* correspondent in the
/// syntax, but it roughly corresponds to the syntactic forms:
///
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unconstrained generic constant
--> $DIR/cross_crate_predicate.rs:7:13
--> $DIR/cross_crate_predicate.rs:7:44
|
LL | let _ = const_evaluatable_lib::test1::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
|
= help: try adding a `where` bound using this expression: `where [(); std::mem::size_of::<T>() - 1]:`
note: required by a bound in `test1`
@@ -12,10 +12,10 @@ LL | [u8; std::mem::size_of::<T>() - 1]: Sized,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `test1`

error: unconstrained generic constant
--> $DIR/cross_crate_predicate.rs:7:13
--> $DIR/cross_crate_predicate.rs:7:44
|
LL | let _ = const_evaluatable_lib::test1::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
|
= help: try adding a `where` bound using this expression: `where [(); std::mem::size_of::<T>() - 1]:`
note: required by a bound in `test1`
4 changes: 2 additions & 2 deletions tests/ui/const-generics/type_mismatch.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: the constant `N` is not of type `u8`
--> $DIR/type_mismatch.rs:2:5
--> $DIR/type_mismatch.rs:2:11
|
LL | bar::<N>()
| ^^^^^^^^
| ^
|
note: required by a bound in `bar`
--> $DIR/type_mismatch.rs:6:8