mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
consider parent_count
for const param defaults
This commit is contained in:
parent
ed61c139c2
commit
cb596e3015
@ -79,7 +79,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
||||
let generics = tcx.generics_of(parent_def_id.to_def_id());
|
||||
let param_def_idx = generics.param_def_id_to_index[¶m_id.to_def_id()];
|
||||
// In the above example this would be .params[..N#0]
|
||||
let params = generics.params[..param_def_idx as usize].to_owned();
|
||||
let params = generics.param_to(param_def_idx as usize, tcx).to_owned();
|
||||
let param_def_id_to_index =
|
||||
params.iter().map(|param| (param.def_id, param.index)).collect();
|
||||
|
||||
|
@ -220,6 +220,15 @@ impl<'tcx> Generics {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn param_to(&'tcx self, param_index: usize, tcx: TyCtxt<'tcx>) -> &'tcx [GenericParamDef] {
|
||||
if let Some(index) = param_index.checked_sub(self.parent_count) {
|
||||
&self.params[..index]
|
||||
} else {
|
||||
tcx.generics_of(self.parent.expect("parent_count > 0 but no parent?"))
|
||||
.param_to(param_index, tcx)
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the `GenericParamDef` associated with this `EarlyBoundRegion`.
|
||||
pub fn region_param(
|
||||
&'tcx self,
|
||||
|
@ -0,0 +1,8 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
trait Trait<T> {
|
||||
fn fnc<const N: usize = "">(&self) {} //~ERROR defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,8 @@
|
||||
error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
|
||||
--> $DIR/issue-105257.rs:5:12
|
||||
|
|
||||
LL | fn fnc<const N: usize = "">(&self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user