Skip to content

Rollup of 16 pull requests #78501

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

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4a15a25
min_const_generics: allow ty param in repeat expr
lcnr Oct 22, 2020
83ecbb4
add tests for self with const params
lcnr Oct 23, 2020
df59a44
rustc_span: improve bounds checks in byte_pos_to_line_and_col
tgnottingham Sep 21, 2020
650e3cb
Prefer new associated numeric consts in float error messages
Rustin170506 Oct 27, 2020
f0ae24e
Handle type errors in closure/generator upvar_tys
arora-aman Oct 27, 2020
47dad31
rustc_span: represent line bounds with Range
tgnottingham Oct 27, 2020
eb8e8bd
Add UI test for invalid values for bool & char
JulianKnodt Oct 26, 2020
5229571
Address comments
roxelo Oct 27, 2020
a3bff69
Use unwrapDIPtr because the Scope may be passed as None
danielframpton Oct 28, 2020
86d6920
Change as_str → to_string in proc_macro::Ident::span() docs
est31 Oct 28, 2020
0217edb
Clean up intra-doc links in `std::path`
camelid Oct 28, 2020
c90ef97
fix a comment in validity check
RalfJung Oct 28, 2020
9e60f45
Add const generics tests for supertraits + dyn traits.
hameerabbasi Oct 28, 2020
6c73adf
Adjust turbofish help message for const generics
varkor Oct 28, 2020
a6d01da
Remove irrelevant FIXME
varkor Oct 28, 2020
fab79c2
Extend test to cover dyn methods/functions.
hameerabbasi Oct 28, 2020
22060fa
Assert in every case.
hameerabbasi Oct 28, 2020
f553c22
Fix typo "compiltest"
GuillaumeGomez Oct 28, 2020
0617156
Inline NonZeroN::from(n)
petertodd Oct 28, 2020
23167cb
Update books
ehuss Oct 28, 2020
72016f4
Update cargo
ehuss Oct 28, 2020
0fabbf9
Fix typos
bugadani Oct 28, 2020
32b5688
Rollup merge of #78224 - lcnr:repeat-expr, r=varkor
jonas-schievink Oct 28, 2020
09346c6
Rollup merge of #78423 - tgnottingham:caching_source_map_bounds_check…
jonas-schievink Oct 28, 2020
7e3ec99
Rollup merge of #78428 - JulianKnodt:invalid_patterns, r=lcnr
jonas-schievink Oct 28, 2020
018fc6b
Rollup merge of #78431 - Rustin-Liu:rustin-patch-lint, r=estebank
jonas-schievink Oct 28, 2020
d354dff
Rollup merge of #78432 - sexxi-goose:fix-77993-take3, r=nikomatsakis
jonas-schievink Oct 28, 2020
b4a2a55
Rollup merge of #78460 - varkor:turbofish-string-generic, r=lcnr
jonas-schievink Oct 28, 2020
49729ce
Rollup merge of #78462 - danielframpton:fixnullisa, r=nagisa
jonas-schievink Oct 28, 2020
9943396
Rollup merge of #78465 - est31:proc_macro_to_string, r=petrochenkov
jonas-schievink Oct 28, 2020
cf1b358
Rollup merge of #78470 - camelid:fixup-std-path-intra-doc, r=jyn514
jonas-schievink Oct 28, 2020
645c007
Rollup merge of #78475 - RalfJung:validity-comment, r=oli-obk
jonas-schievink Oct 28, 2020
c9fe6bb
Rollup merge of #78478 - hameerabbasi:const-generics-supertraits, r=lcnr
jonas-schievink Oct 28, 2020
df69809
Rollup merge of #78487 - rust-lang:GuillaumeGomez-patch-1, r=stevekla…
jonas-schievink Oct 28, 2020
c25149b
Rollup merge of #78491 - petertodd:2020-inline-from-nonzero, r=sfackler
jonas-schievink Oct 28, 2020
d84a458
Rollup merge of #78492 - ehuss:update-books, r=ehuss
jonas-schievink Oct 28, 2020
400c486
Rollup merge of #78493 - ehuss:update-cargo, r=ehuss
jonas-schievink Oct 28, 2020
520876b
Rollup merge of #78494 - bugadani:typo2, r=jonas-schievink
jonas-schievink Oct 28, 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
4 changes: 3 additions & 1 deletion compiler/rustc_hir/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ pub enum Res<Id = hir::HirId> {
/// ```rust
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] {} }
/// ```
/// We do however allow `Self` in repeat expression even if it is generic to not break code
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint.
///
/// FIXME(lazy_normalization_consts): Remove this bodge once this feature is stable.
/// FIXME(lazy_normalization_consts): Remove this bodge once that feature is stable.
SelfTy(Option<DefId> /* trait */, Option<(DefId, bool)> /* impl */),
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

pub fn unsolved_variables(&self) -> Vec<Ty<'tcx>> {
let mut inner = self.inner.borrow_mut();
// FIXME(const_generics): should there be an equivalent function for const variables?

let mut vars: Vec<Ty<'_>> = inner
.type_variables()
.unsolved_variables()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ fn lint_literal<'tcx>(
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
lint.build(&format!("literal out of range for `{}`", t.name_str()))
.note(&format!(
"the literal `{}` does not fit into the type `{}` and will be converted to `std::{}::INFINITY`",
"the literal `{}` does not fit into the type `{}` and will be converted to `{}::INFINITY`",
cx.sess()
.source_map()
.span_to_snippet(lit.span)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateTypedef(
LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope) {
return wrap(Builder->createTypedef(
unwrap<DIType>(Type), StringRef(Name, NameLen), unwrap<DIFile>(File),
LineNo, unwrap<DIScope>(Scope)));
LineNo, unwrapDIPtr<DIScope>(Scope)));
}

extern "C" LLVMMetadataRef LLVMRustDIBuilderCreatePointerType(
Expand Down
43 changes: 37 additions & 6 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,19 @@ impl<'tcx> ClosureSubsts<'tcx> {
self.split().parent_substs
}

/// Returns an iterator over the list of types of captured paths by the closure.
/// In case there was a type error in figuring out the types of the captured path, an
/// empty iterator is returned.
#[inline]
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
self.tupled_upvars_ty().tuple_fields()
match self.tupled_upvars_ty().kind() {
TyKind::Error(_) => None,
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
}
.into_iter()
.flatten()
}

/// Returns the tuple type representing the upvars for this closure.
Expand Down Expand Up @@ -515,9 +525,19 @@ impl<'tcx> GeneratorSubsts<'tcx> {
self.split().witness.expect_ty()
}

/// Returns an iterator over the list of types of captured paths by the generator.
/// In case there was a type error in figuring out the types of the captured path, an
/// empty iterator is returned.
#[inline]
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
self.tupled_upvars_ty().tuple_fields()
match self.tupled_upvars_ty().kind() {
TyKind::Error(_) => None,
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
}
.into_iter()
.flatten()
}

/// Returns the tuple type representing the upvars for this generator.
Expand Down Expand Up @@ -660,13 +680,24 @@ pub enum UpvarSubsts<'tcx> {
}

impl<'tcx> UpvarSubsts<'tcx> {
/// Returns an iterator over the list of types of captured paths by the closure/generator.
/// In case there was a type error in figuring out the types of the captured path, an
/// empty iterator is returned.
#[inline]
pub fn upvar_tys(self) -> impl Iterator<Item = Ty<'tcx>> + 'tcx {
let tupled_upvars_ty = match self {
UpvarSubsts::Closure(substs) => substs.as_closure().split().tupled_upvars_ty,
UpvarSubsts::Generator(substs) => substs.as_generator().split().tupled_upvars_ty,
let tupled_tys = match self {
UpvarSubsts::Closure(substs) => substs.as_closure().tupled_upvars_ty(),
UpvarSubsts::Generator(substs) => substs.as_generator().tupled_upvars_ty(),
};
tupled_upvars_ty.expect_ty().tuple_fields()

match tupled_tys.kind() {
TyKind::Error(_) => None,
TyKind::Tuple(..) => Some(self.tupled_upvars_ty().tuple_fields()),
TyKind::Infer(_) => bug!("upvar_tys called before capture types are inferred"),
ty => bug!("Unexpected representation of upvar types tuple {:?}", ty),
}
.into_iter()
.flatten()
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir/src/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'a, 'tcx> Borrows<'a, 'tcx> {
//
// We are careful always to call this function *before* we
// set up the gen-bits for the statement or
// termanator. That way, if the effect of the statement or
// terminator. That way, if the effect of the statement or
// terminator *does* introduce a new loan of the same
// region, then setting that gen-bit will override any
// potential kill introduced here.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/dataflow/impls/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::dataflow::{AnalysisDomain, Backward, GenKill, GenKillAnalysis};
///
/// This analysis considers references as being used only at the point of the
/// borrow. In other words, this analysis does not track uses because of references that already
/// exist. See [this `mir-datalow` test][flow-test] for an example. You almost never want to use
/// exist. See [this `mir-dataflow` test][flow-test] for an example. You almost never want to use
/// this analysis without also looking at the results of [`MaybeBorrowedLocals`].
///
/// [`MaybeBorrowedLocals`]: ../struct.MaybeBorrowedLocals.html
Expand Down Expand Up @@ -134,7 +134,7 @@ impl DefUse {

// `MutatingUseContext::Call` and `MutatingUseContext::Yield` indicate that this is the
// destination place for a `Call` return or `Yield` resume respectively. Since this is
// only a `Def` when the function returns succesfully, we handle this case separately
// only a `Def` when the function returns successfully, we handle this case separately
// in `call_return_effect` above.
PlaceContext::MutatingUse(MutatingUseContext::Call | MutatingUseContext::Yield) => None,

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
// Nothing to check.
Ok(true)
}
// The above should be all the (inhabited) primitive types. The rest is compound, we
// The above should be all the primitive types. The rest is compound, we
// check them by visiting their fields/variants.
// (`Str` UTF-8 check happens in `visit_aggregate`, too.)
ty::Adt(..)
| ty::Tuple(..)
| ty::Array(..)
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use rustc_span::{MultiSpan, Span, SpanSnippetError, DUMMY_SP};

use tracing::{debug, trace};

const TURBOFISH: &str = "use `::<...>` instead of `<...>` to specify type arguments";
const TURBOFISH_SUGGESTION_STR: &str =
"use `::<...>` instead of `<...>` to specify type or const arguments";

/// Creates a placeholder argument.
pub(super) fn dummy_arg(ident: Ident) -> Param {
Expand Down Expand Up @@ -659,7 +660,7 @@ impl<'a> Parser<'a> {
Ok(_) => {
e.span_suggestion_verbose(
binop.span.shrink_to_lo(),
"use `::<...>` instead of `<...>` to specify type arguments",
TURBOFISH_SUGGESTION_STR,
"::".to_string(),
Applicability::MaybeIncorrect,
);
Expand Down Expand Up @@ -814,7 +815,7 @@ impl<'a> Parser<'a> {
let suggest = |err: &mut DiagnosticBuilder<'_>| {
err.span_suggestion_verbose(
op.span.shrink_to_lo(),
TURBOFISH,
TURBOFISH_SUGGESTION_STR,
"::".to_string(),
Applicability::MaybeIncorrect,
);
Expand Down Expand Up @@ -888,7 +889,7 @@ impl<'a> Parser<'a> {
{
// All we know is that this is `foo < bar >` and *nothing* else. Try to
// be helpful, but don't attempt to recover.
err.help(TURBOFISH);
err.help(TURBOFISH_SUGGESTION_STR);
err.help("or use `(...)` if you meant to specify fn arguments");
}

Expand Down
88 changes: 70 additions & 18 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ enum PatternSource {
FnParam,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum IsRepeatExpr {
No,
Yes,
}

impl PatternSource {
fn descr(self) -> &'static str {
match self {
Expand Down Expand Up @@ -437,10 +443,8 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
self.resolve_block(block);
}
fn visit_anon_const(&mut self, constant: &'ast AnonConst) {
debug!("visit_anon_const {:?}", constant);
self.with_constant_rib(constant.value.is_potential_trivial_const_param(), |this| {
visit::walk_anon_const(this, constant);
});
// We deal with repeat expressions explicitly in `resolve_expr`.
self.resolve_anon_const(constant, IsRepeatExpr::No);
}
fn visit_expr(&mut self, expr: &'ast Expr) {
self.resolve_expr(expr, None);
Expand Down Expand Up @@ -647,7 +651,11 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
if !check_ns(TypeNS) && check_ns(ValueNS) {
// This must be equivalent to `visit_anon_const`, but we cannot call it
// directly due to visitor lifetimes so we have to copy-paste some code.
self.with_constant_rib(true, |this| {
//
// Note that we might not be inside of an repeat expression here,
// but considering that `IsRepeatExpr` is only relevant for
// non-trivial constants this is doesn't matter.
self.with_constant_rib(IsRepeatExpr::No, true, |this| {
this.smart_resolve_path(
ty.id,
qself.as_ref(),
Expand Down Expand Up @@ -980,9 +988,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
//
// Type parameters can already be used and as associated consts are
// not used as part of the type system, this is far less surprising.
this.with_constant_rib(true, |this| {
this.visit_expr(expr)
});
this.with_constant_rib(
IsRepeatExpr::No,
true,
|this| this.visit_expr(expr),
);
}
}
AssocItemKind::Fn(_, _, generics, _) => {
Expand Down Expand Up @@ -1023,7 +1033,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
self.with_item_rib(HasGenericParams::No, |this| {
this.visit_ty(ty);
if let Some(expr) = expr {
this.with_constant_rib(expr.is_potential_trivial_const_param(), |this| {
// We already forbid generic params because of the above item rib,
// so it doesn't matter whether this is a trivial constant.
this.with_constant_rib(IsRepeatExpr::No, true, |this| {
this.visit_expr(expr)
});
}
Expand Down Expand Up @@ -1122,12 +1134,29 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f))
}

fn with_constant_rib(&mut self, trivial: bool, f: impl FnOnce(&mut Self)) {
debug!("with_constant_rib");
self.with_rib(ValueNS, ConstantItemRibKind(trivial), |this| {
this.with_rib(TypeNS, ConstantItemRibKind(trivial), |this| {
this.with_label_rib(ConstantItemRibKind(trivial), f);
})
// HACK(min_const_generics,const_evaluatable_unchecked): We
// want to keep allowing `[0; std::mem::size_of::<*mut T>()]`
// with a future compat lint for now. We do this by adding an
// additional special case for repeat expressions.
//
// Note that we intentionally still forbid `[0; N + 1]` during
// name resolution so that we don't extend the future
// compat lint to new cases.
fn with_constant_rib(
&mut self,
is_repeat: IsRepeatExpr,
is_trivial: bool,
f: impl FnOnce(&mut Self),
) {
debug!("with_constant_rib: is_repeat={:?} is_trivial={}", is_repeat, is_trivial);
self.with_rib(ValueNS, ConstantItemRibKind(is_trivial), |this| {
this.with_rib(
TypeNS,
ConstantItemRibKind(is_repeat == IsRepeatExpr::Yes || is_trivial),
|this| {
this.with_label_rib(ConstantItemRibKind(is_trivial), f);
},
)
});
}

Expand Down Expand Up @@ -1272,9 +1301,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
//
// Type parameters can already be used and as associated consts are
// not used as part of the type system, this is far less surprising.
this.with_constant_rib(true, |this| {
visit::walk_assoc_item(this, item, AssocCtxt::Impl)
});
this.with_constant_rib(
IsRepeatExpr::No,
true,
|this| {
visit::walk_assoc_item(
this,
item,
AssocCtxt::Impl,
)
},
);
}
AssocItemKind::Fn(_, _, generics, _) => {
// We also need a new scope for the impl item type parameters.
Expand Down Expand Up @@ -2199,6 +2236,17 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
debug!("(resolving block) leaving block");
}

fn resolve_anon_const(&mut self, constant: &'ast AnonConst, is_repeat: IsRepeatExpr) {
debug!("resolve_anon_const {:?} is_repeat: {:?}", constant, is_repeat);
self.with_constant_rib(
is_repeat,
constant.value.is_potential_trivial_const_param(),
|this| {
visit::walk_anon_const(this, constant);
},
);
}

fn resolve_expr(&mut self, expr: &'ast Expr, parent: Option<&'ast Expr>) {
// First, record candidate traits for this expression if it could
// result in the invocation of a method call.
Expand Down Expand Up @@ -2322,6 +2370,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
ExprKind::Async(..) | ExprKind::Closure(..) => {
self.with_label_rib(ClosureOrAsyncRibKind, |this| visit::walk_expr(this, expr));
}
ExprKind::Repeat(ref elem, ref ct) => {
self.visit_expr(elem);
self.resolve_anon_const(ct, IsRepeatExpr::Yes);
}
_ => {
visit::walk_expr(self, expr);
}
Expand Down
Loading