Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
3dd0a7d
Do not call `unwrap` with `signatures` option enabled
JohnTitor Oct 25, 2020
459dae9
fix #72680 by explicitly checking for or-pattern before test
mark-i-m Nov 7, 2020
43e4783
address reviewer comments
mark-i-m Nov 9, 2020
659aa77
test: add `()=()=()=...` to weird-exprs.rs
slanterns Nov 11, 2020
f5e67b5
Add a test for r# identifiers
poliorcetics Nov 12, 2020
9c70696
Ignore tidy linelength
poliorcetics Nov 12, 2020
bd0eb07
Added some unit tests as requested
richkadel Nov 3, 2020
ecfeac5
Use intradoc-links for the whole test, add a @has check
poliorcetics Nov 12, 2020
562d50e
Include llvm-as in llvm-tools-preview component
zec Nov 12, 2020
e4a43fc
Merge changes from rust-lang/rust
zec Nov 12, 2020
38fa66a
Rename empty_tuple_assignment to monkey_barrel
slanterns Nov 12, 2020
eb9f2bb
Overcome Sync issues with non-parallel compiler
richkadel Nov 12, 2020
775f1e5
fix pretty print for qpath
gui1117 Nov 12, 2020
f8a32e9
Bumped minimal tested LLVM version to 9
DevJPM Nov 7, 2020
6323565
explicitly add llvm-9-dev in dockerfile
DevJPM Nov 7, 2020
6830f1c
Bump the minimal supported LLVM version in the bootstrapping code to 9.0
DevJPM Nov 7, 2020
b51bcc7
fully exploited the dropped support of LLVM 8
DevJPM Nov 7, 2020
8236830
Removed an unused function now that LLVM 9 is the minimal supported v…
DevJPM Nov 7, 2020
7e443c4
Dropped Support for Bidirectional Custom Target Definition Emulation
DevJPM Nov 10, 2020
86193ca
fixed a re-format due to removed chain call
DevJPM Nov 10, 2020
3747df7
Avoid installing external LLVM dylibs
Mark-Simulacrum Nov 12, 2020
010265a
Fix an intrinsic invocation on threaded wasm
alexcrichton Nov 12, 2020
dd682cb
rustc_target: Fix dash vs underscore mismatches in option names
petrochenkov Nov 12, 2020
0b4af16
Never inline when `no_sanitize` attributes differ
tmiasko Nov 11, 2020
ae43326
Never inline cold functions
tmiasko Nov 11, 2020
9bb3d6b
Remove check for impossible condition
tmiasko Nov 11, 2020
66cadec
Fix generator inlining by checking for rust-call abi and spread arg
tmiasko Nov 11, 2020
79d853e
Never inline C variadic functions
tmiasko Nov 11, 2020
2a010dd
./x.py test --bless
tmiasko Nov 11, 2020
d486bfc
Normalize function type during validation
tmiasko Nov 12, 2020
99be78d
Always use param_env_reveal_all_normalized in validator
tmiasko Nov 12, 2020
cc6baf7
rustc_expand: Mark inner `#![test]` attributes as soft-unstable
petrochenkov Nov 12, 2020
016146d
Add column number support to Backtrace
est31 Nov 12, 2020
31741aa
Add `--color` support to bootstrap
jyn514 Nov 12, 2020
8766c04
cleanup: Remove `ParseSess::injected_crate_name`
petrochenkov Nov 12, 2020
c131063
Added a unit test for BcbCounters
richkadel Nov 13, 2020
309d863
Fix wrong XPath
poliorcetics Nov 13, 2020
894b1f7
extract closures into a separate trait
lcnr Nov 13, 2020
b4b0ef3
Addressed feedback
richkadel Nov 13, 2020
75dfc71
refactor: vec_deque ignore-tidy-filelength
DeveloperC286 Nov 13, 2020
bf6902c
Add BTreeMap::retain and BTreeSet::retain
mbrubeck Nov 13, 2020
7eb1a1a
Validate that locals have a corresponding `LocalDecl`
camelid Nov 13, 2020
ac4c1f5
rustc_resolve: Make `macro_rules` scope chain compression lazy
petrochenkov Nov 13, 2020
e7b6b61
Limit storage duration of inlined always live locals
tmiasko Nov 14, 2020
41c44b4
Move Steal to rustc_data_structures.
cjgillot Nov 14, 2020
03cbee8
Rename ItemEnum -> ItemKind, inner -> kind
jyn514 Nov 14, 2020
b825ae7
Style nit
mark-i-m Nov 14, 2020
8cf3564
Add underscore expressions for destructuring assignments
fanzier Nov 11, 2020
c6ef82e
Rollup merge of #78352 - JohnTitor:issue-75229, r=Dylan-DPC
jonas-schievink Nov 14, 2020
84322e0
Rollup merge of #78590 - DeveloperC286:issue_60302, r=varkor
jonas-schievink Nov 14, 2020
0501196
Rollup merge of #78848 - DevJPM:ci-llvm-9, r=nikic
jonas-schievink Nov 14, 2020
fd14608
Rollup merge of #78856 - mark-i-m:fix-or-pat-ice, r=matthewjasper
jonas-schievink Nov 14, 2020
d6fc536
Rollup merge of #78948 - slanterns:master, r=varkor
jonas-schievink Nov 14, 2020
a97a51e
Rollup merge of #78962 - poliorcetics:rustdoc-raw-ident-test, r=jyn514
jonas-schievink Nov 14, 2020
829b5ab
Rollup merge of #78963 - richkadel:llvm-coverage-counters-2.0.4, r=tm…
jonas-schievink Nov 14, 2020
da75594
Rollup merge of #78966 - tmiasko:inline-never, r=oli-obk
jonas-schievink Nov 14, 2020
c6ec024
Rollup merge of #78968 - zec:add-llvm-as, r=Mark-Simulacrum
jonas-schievink Nov 14, 2020
738883f
Rollup merge of #78969 - tmiasko:normalize, r=davidtwco
jonas-schievink Nov 14, 2020
7c8270b
Rollup merge of #78980 - thiolliere:gui-fix-qpath, r=estebank
jonas-schievink Nov 14, 2020
0938665
Rollup merge of #78986 - Mark-Simulacrum:fix-llvm, r=alexcrichton
jonas-schievink Nov 14, 2020
d6a6035
Rollup merge of #78988 - alexcrichton:one-more-intrinsic, r=sfackler
jonas-schievink Nov 14, 2020
9660e60
Rollup merge of #78993 - petrochenkov:specdash, r=oli-obk
jonas-schievink Nov 14, 2020
529cf6b
Rollup merge of #79002 - est31:backtrace_colno, r=dtolnay
jonas-schievink Nov 14, 2020
990d2b3
Rollup merge of #79003 - petrochenkov:innertest, r=estebank
jonas-schievink Nov 14, 2020
7e15e47
Rollup merge of #79004 - jyn514:bacon, r=Mark-Simulacrum
jonas-schievink Nov 14, 2020
656dca4
Rollup merge of #79005 - petrochenkov:noinjected, r=davidtwco
jonas-schievink Nov 14, 2020
8998722
Rollup merge of #79016 - fanzier:underscore-expressions, r=petrochenkov
jonas-schievink Nov 14, 2020
4f3d33c
Rollup merge of #79019 - lcnr:generic-arg-validation, r=petrochenkov
jonas-schievink Nov 14, 2020
5d81b56
Rollup merge of #79026 - mbrubeck:btree_retain, r=m-ou-se
jonas-schievink Nov 14, 2020
a1d5cb3
Rollup merge of #79027 - tmiasko:inline-always-live-locals, r=oli-obk
jonas-schievink Nov 14, 2020
a296c26
Rollup merge of #79031 - camelid:mir-validate-local-decl, r=jonas-sch…
jonas-schievink Nov 14, 2020
129fe1e
Rollup merge of #79034 - petrochenkov:mrscopes3, r=eddyb
jonas-schievink Nov 14, 2020
35d2973
Rollup merge of #79036 - cjgillot:steal, r=oli-obk
jonas-schievink Nov 14, 2020
757443a
Rollup merge of #79041 - jyn514:inner-to-kind, r=petrochenkov
jonas-schievink Nov 14, 2020
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
extract closures into a separate trait
  • Loading branch information
lcnr committed Nov 13, 2020
commit 894b1f7d3d508bb644e01c62dfb983a394380fd3
25 changes: 10 additions & 15 deletions compiler/rustc_typeck/src/astconv/generics.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::astconv::{
AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, GenericArgPosition,
AstConv, CreateSubstsForGenericArgsCtxt, ExplicitLateBound, GenericArgCountMismatch,
GenericArgCountResult, GenericArgPosition,
};
use crate::errors::AssocTypeBindingNotAllowed;
use rustc_ast::ast::ParamKindOrd;
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorReported};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::{GenericArg, GenericArgs};
use rustc_hir::GenericArg;
use rustc_middle::ty::{
self, subst, subst::SubstsRef, GenericParamDef, GenericParamDefKind, Ty, TyCtxt,
};
Expand Down Expand Up @@ -90,20 +91,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// instantiate a `GenericArg`.
/// - `inferred_kind`: if no parameter was provided, and inference is enabled, then
/// creates a suitable inference variable.
pub fn create_substs_for_generic_args<'b>(
pub fn create_substs_for_generic_args<'a>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
parent_substs: &[subst::GenericArg<'tcx>],
has_self: bool,
self_ty: Option<Ty<'tcx>>,
arg_count: GenericArgCountResult,
args_for_def_id: impl Fn(DefId) -> (Option<&'b GenericArgs<'b>>, bool),
mut provided_kind: impl FnMut(&GenericParamDef, &GenericArg<'_>) -> subst::GenericArg<'tcx>,
mut inferred_kind: impl FnMut(
Option<&[subst::GenericArg<'tcx>]>,
&GenericParamDef,
bool,
) -> subst::GenericArg<'tcx>,
ctx: &mut impl CreateSubstsForGenericArgsCtxt<'a, 'tcx>,
) -> SubstsRef<'tcx> {
// Collect the segments of the path; we need to substitute arguments
// for parameters throughout the entire path (wherever there are
Expand Down Expand Up @@ -142,7 +137,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
substs.push(
self_ty
.map(|ty| ty.into())
.unwrap_or_else(|| inferred_kind(None, param, true)),
.unwrap_or_else(|| ctx.inferred_kind(None, param, true)),
);
params.next();
}
Expand All @@ -151,7 +146,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
}

// Check whether this segment takes generic arguments and the user has provided any.
let (generic_args, infer_args) = args_for_def_id(def_id);
let (generic_args, infer_args) = ctx.args_for_def_id(def_id);

let mut args =
generic_args.iter().flat_map(|generic_args| generic_args.args.iter()).peekable();
Expand All @@ -173,7 +168,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _)
| (GenericArg::Type(_), GenericParamDefKind::Type { .. }, _)
| (GenericArg::Const(_), GenericParamDefKind::Const, _) => {
substs.push(provided_kind(param, arg));
substs.push(ctx.provided_kind(param, arg));
args.next();
params.next();
}
Expand All @@ -184,7 +179,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
) => {
// We expected a lifetime argument, but got a type or const
// argument. That means we're inferring the lifetimes.
substs.push(inferred_kind(None, param, infer_args));
substs.push(ctx.inferred_kind(None, param, infer_args));
force_infer_lt = Some(arg);
params.next();
}
Expand Down Expand Up @@ -302,7 +297,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
(None, Some(&param)) => {
// If there are fewer arguments than parameters, it means
// we're inferring the remaining arguments.
substs.push(inferred_kind(Some(&substs), param, infer_args));
substs.push(ctx.inferred_kind(Some(&substs), param, infer_args));
params.next();
}

Expand Down
224 changes: 143 additions & 81 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ pub struct GenericArgCountResult {
pub correct: Result<(), GenericArgCountMismatch>,
}

pub trait CreateSubstsForGenericArgsCtxt<'a, 'tcx> {
fn args_for_def_id(&mut self, def_id: DefId) -> (Option<&'a GenericArgs<'a>>, bool);

fn provided_kind(
&mut self,
param: &ty::GenericParamDef,
arg: &GenericArg<'_>,
) -> subst::GenericArg<'tcx>;

fn inferred_kind(
&mut self,
substs: Option<&[subst::GenericArg<'tcx>]>,
param: &ty::GenericParamDef,
infer_args: bool,
) -> subst::GenericArg<'tcx>;
}

impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
pub fn ast_region_to_region(
&self,
Expand Down Expand Up @@ -321,81 +338,102 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
);

let is_object = self_ty.map_or(false, |ty| ty == self.tcx().types.trait_object_dummy_self);
let default_needs_object_self = |param: &ty::GenericParamDef| {
if let GenericParamDefKind::Type { has_default, .. } = param.kind {
if is_object && has_default {
let default_ty = tcx.at(span).type_of(param.def_id);
let self_param = tcx.types.self_param;
if default_ty.walk().any(|arg| arg == self_param.into()) {
// There is no suitable inference default for a type parameter
// that references self, in an object type.
return true;

struct SubstsForAstPathCtxt<'a, 'tcx> {
astconv: &'a (dyn AstConv<'tcx> + 'a),
def_id: DefId,
generic_args: &'a GenericArgs<'a>,
span: Span,
missing_type_params: Vec<String>,
inferred_params: Vec<Span>,
infer_args: bool,
is_object: bool,
}

impl<'tcx, 'a> SubstsForAstPathCtxt<'tcx, 'a> {
fn default_needs_object_self(&mut self, param: &ty::GenericParamDef) -> bool {
let tcx = self.astconv.tcx();
if let GenericParamDefKind::Type { has_default, .. } = param.kind {
if self.is_object && has_default {
let default_ty = tcx.at(self.span).type_of(param.def_id);
let self_param = tcx.types.self_param;
if default_ty.walk().any(|arg| arg == self_param.into()) {
// There is no suitable inference default for a type parameter
// that references self, in an object type.
return true;
}
}
}
}

false
};
false
}
}

let mut missing_type_params = vec![];
let mut inferred_params = vec![];
let substs = Self::create_substs_for_generic_args(
tcx,
def_id,
parent_substs,
self_ty.is_some(),
self_ty,
arg_count.clone(),
// Provide the generic args, and whether types should be inferred.
|did| {
if did == def_id {
(Some(generic_args), infer_args)
impl<'a, 'tcx> CreateSubstsForGenericArgsCtxt<'a, 'tcx> for SubstsForAstPathCtxt<'a, 'tcx> {
fn args_for_def_id(&mut self, did: DefId) -> (Option<&'a GenericArgs<'a>>, bool) {
if did == self.def_id {
(Some(self.generic_args), self.infer_args)
} else {
// The last component of this tuple is unimportant.
(None, false)
}
},
// Provide substitutions for parameters for which (valid) arguments have been provided.
|param, arg| match (&param.kind, arg) {
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
self.ast_region_to_region(&lt, Some(param)).into()
}
(GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
if *has_default {
tcx.check_optional_stability(
param.def_id,
Some(arg.id()),
arg.span(),
|_, _| {
// Default generic parameters may not be marked
// with stability attributes, i.e. when the
// default parameter was defined at the same time
// as the rest of the type. As such, we ignore missing
// stability attributes.
}

fn provided_kind(
&mut self,
param: &ty::GenericParamDef,
arg: &GenericArg<'_>,
) -> subst::GenericArg<'tcx> {
let tcx = self.astconv.tcx();
match (&param.kind, arg) {
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
self.astconv.ast_region_to_region(&lt, Some(param)).into()
}
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
if has_default {
tcx.check_optional_stability(
param.def_id,
Some(arg.id()),
arg.span(),
|_, _| {
// Default generic parameters may not be marked
// with stability attributes, i.e. when the
// default parameter was defined at the same time
// as the rest of the type. As such, we ignore missing
// stability attributes.
},
)
}
if let (hir::TyKind::Infer, false) =
(&ty.kind, self.astconv.allow_ty_infer())
{
self.inferred_params.push(ty.span);
tcx.ty_error().into()
} else {
self.astconv.ast_ty_to_ty(&ty).into()
}
}
(GenericParamDefKind::Const, GenericArg::Const(ct)) => {
ty::Const::from_opt_const_arg_anon_const(
tcx,
ty::WithOptConstParam {
did: tcx.hir().local_def_id(ct.value.hir_id),
const_param_did: Some(param.def_id),
},
)
.into()
}
if let (hir::TyKind::Infer, false) = (&ty.kind, self.allow_ty_infer()) {
inferred_params.push(ty.span);
tcx.ty_error().into()
} else {
self.ast_ty_to_ty(&ty).into()
}
}
(GenericParamDefKind::Const, GenericArg::Const(ct)) => {
ty::Const::from_opt_const_arg_anon_const(
tcx,
ty::WithOptConstParam {
did: tcx.hir().local_def_id(ct.value.hir_id),
const_param_did: Some(param.def_id),
},
)
.into()
_ => unreachable!(),
}
_ => unreachable!(),
},
// Provide substitutions for parameters for which arguments are inferred.
|substs, param, infer_args| {
}

fn inferred_kind(
&mut self,
substs: Option<&[subst::GenericArg<'tcx>]>,
param: &ty::GenericParamDef,
infer_args: bool,
) -> subst::GenericArg<'tcx> {
let tcx = self.astconv.tcx();
match param.kind {
GenericParamDefKind::Lifetime => tcx.lifetimes.re_static.into(),
GenericParamDefKind::Type { has_default, .. } => {
Expand All @@ -407,48 +445,72 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// other type parameters may reference `Self` in their
// defaults. This will lead to an ICE if we are not
// careful!
if default_needs_object_self(param) {
missing_type_params.push(param.name.to_string());
if self.default_needs_object_self(param) {
self.missing_type_params.push(param.name.to_string());
tcx.ty_error().into()
} else {
// This is a default type parameter.
self.normalize_ty(
span,
tcx.at(span).type_of(param.def_id).subst_spanned(
tcx,
substs.unwrap(),
Some(span),
),
)
.into()
self.astconv
.normalize_ty(
self.span,
tcx.at(self.span).type_of(param.def_id).subst_spanned(
tcx,
substs.unwrap(),
Some(self.span),
),
)
.into()
}
} else if infer_args {
// No type parameters were provided, we can infer all.
let param =
if !default_needs_object_self(param) { Some(param) } else { None };
self.ty_infer(param, span).into()
let param = if !self.default_needs_object_self(param) {
Some(param)
} else {
None
};
self.astconv.ty_infer(param, self.span).into()
} else {
// We've already errored above about the mismatch.
tcx.ty_error().into()
}
}
GenericParamDefKind::Const => {
let ty = tcx.at(span).type_of(param.def_id);
let ty = tcx.at(self.span).type_of(param.def_id);
// FIXME(const_generics:defaults)
if infer_args {
// No const parameters were provided, we can infer all.
self.ct_infer(ty, Some(param), span).into()
self.astconv.ct_infer(ty, Some(param), self.span).into()
} else {
// We've already errored above about the mismatch.
tcx.const_error(ty).into()
}
}
}
},
}
}

let mut substs_ctx = SubstsForAstPathCtxt {
astconv: self,
def_id,
span,
generic_args,
missing_type_params: vec![],
inferred_params: vec![],
infer_args,
is_object,
};
let substs = Self::create_substs_for_generic_args(
tcx,
def_id,
parent_substs,
self_ty.is_some(),
self_ty,
arg_count.clone(),
&mut substs_ctx,
);

self.complain_about_missing_type_params(
missing_type_params,
substs_ctx.missing_type_params,
def_id,
span,
generic_args.args.is_empty(),
Expand Down
Loading