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 7 pull requests #67449

Merged
merged 21 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3980342
Use structured suggestion for disambiguating method calls
estebank Dec 4, 2019
8c4f1d5
review comments
estebank Dec 12, 2019
8a4632d
Indicate origin of where type parameter for uninferred types
ohadravid Dec 13, 2019
6ad0b55
Remove now-redundant range check on u128 -> f32 casts
Dec 15, 2019
232022f
Fix up Command Debug output when arg0 is specified.
jsgf Dec 11, 2019
ce56e75
Move command-related tests into command/
jsgf Dec 12, 2019
17aa0cb
Remove a const-if-hack in RawVec
mark-i-m Nov 25, 2019
3ec3fca
remove a bit more hackery
mark-i-m Nov 25, 2019
baaf864
use usize::MAX instead of !0
mark-i-m Nov 26, 2019
951f041
fix import
mark-i-m Nov 26, 2019
2535435
add fixme
mark-i-m Nov 26, 2019
7d26811
no need to bootstrap
mark-i-m Dec 18, 2019
b826711
Remove `SOCK_CLOEXEC` dummy variable on platforms that don't use it.
reitermarkus Dec 20, 2019
83fc600
Move command line option definitions into a dedicated file
Dec 17, 2019
57da9d3
Rollup merge of #66755 - mark-i-m:const-vec-new, r=ecstatic-morse
Centril Dec 20, 2019
f0eb4b4
Rollup merge of #67127 - estebank:disambiguate-suggestion, r=varkor
Centril Dec 20, 2019
b779cbb
Rollup merge of #67219 - jsgf:command-argv0-debug, r=joshtriplett
Centril Dec 20, 2019
403bb09
Rollup merge of #67285 - ohadravid:indicate-origin-of-where-type-para…
Centril Dec 20, 2019
efd31c2
Rollup merge of #67328 - rkruppe:simplify-u128-f32-cast, r=matthewjasper
Centril Dec 20, 2019
9f39cb1
Rollup merge of #67367 - 0dvictor:options, r=Centril
Centril Dec 20, 2019
3a336c4
Rollup merge of #67442 - reitermarkus:dummy-variable, r=kennytm
Centril Dec 20, 2019
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
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
#![feature(const_generic_impls_guard)]
#![feature(const_generics)]
#![feature(const_in_array_repeat_expressions)]
#![feature(const_if_match)]
#![feature(cow_is_borrowed)]
#![feature(dispatch_from_dyn)]
#![feature(core_intrinsics)]
Expand Down
21 changes: 3 additions & 18 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,12 @@ impl<T, A: Alloc> RawVec<T, A> {
/// Like `new`, but parameterized over the choice of allocator for
/// the returned `RawVec`.
pub const fn new_in(a: A) -> Self {
// `!0` is `usize::MAX`. This branch should be stripped at compile time.
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
let cap = if mem::size_of::<T>() == 0 { core::usize::MAX } else { 0 };

// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
RawVec {
ptr: Unique::empty(),
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
cap,
a,
}
}
Expand Down Expand Up @@ -132,19 +129,7 @@ impl<T> RawVec<T, Global> {
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
/// delayed allocation.
pub const fn new() -> Self {
// FIXME(Centril): Reintegrate this with `fn new_in` when we can.

// `!0` is `usize::MAX`. This branch should be stripped at compile time.
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };

// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
RawVec {
ptr: Unique::empty(),
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
a: Global,
}
Self::new_in(Global)
}

/// Creates a `RawVec` (on the system heap) with exactly the
Expand Down
78 changes: 65 additions & 13 deletions src/librustc/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::hir::{self, Body, FunctionRetTy, Expr, ExprKind, HirId, Local, Pat};
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
use crate::infer::InferCtxt;
use crate::infer::type_variable::TypeVariableOriginKind;
use crate::ty::{self, Ty, Infer, TyVar};
use crate::ty::{self, Ty, Infer, TyVar, DefIdTree};
use crate::ty::print::Print;
use syntax::source_map::DesugaringKind;
use syntax::symbol::kw;
Expand Down Expand Up @@ -117,6 +117,8 @@ fn closure_return_type_suggestion(
descr: &str,
name: &str,
ret: &str,
parent_name: Option<String>,
parent_descr: Option<&str>,
) {
let (arrow, post) = match output {
FunctionRetTy::DefaultReturn(_) => ("-> ", " "),
Expand All @@ -138,7 +140,12 @@ fn closure_return_type_suggestion(
suggestion,
Applicability::HasPlaceholders,
);
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr));
err.span_label(span, InferCtxt::missing_type_msg(
&name,
&descr,
parent_name,
parent_descr
));
}

/// Given a closure signature, return a `String` containing a list of all its argument types.
Expand Down Expand Up @@ -177,16 +184,31 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&self,
ty: Ty<'tcx>,
highlight: Option<ty::print::RegionHighlightMode>,
) -> (String, Option<Span>, Cow<'static, str>) {
) -> (String, Option<Span>, Cow<'static, str>, Option<String>, Option<&'static str>) {
if let ty::Infer(ty::TyVar(ty_vid)) = ty.kind {
let ty_vars = self.type_variables.borrow();
let var_origin = ty_vars.var_origin(ty_vid);
if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind {
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind {
let parent_def_id = def_id.and_then(|def_id| self.tcx.parent(def_id));
let (parent_name, parent_desc) = if let Some(parent_def_id) = parent_def_id {
let parent_name = self.tcx.def_key(parent_def_id).disambiguated_data.data
.get_opt_name().map(|parent_symbol| parent_symbol.to_string());

let type_parent_desc = self.tcx.def_kind(parent_def_id)
.map(|parent_def_kind| parent_def_kind.descr(parent_def_id));

(parent_name, type_parent_desc)
} else {
(None, None)
};

if name != kw::SelfUpper {
return (
name.to_string(),
Some(var_origin.span),
"type parameter".into(),
parent_name,
parent_desc,
);
}
}
Expand All @@ -198,7 +220,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
printer.region_highlight_mode = highlight;
}
let _ = ty.print(printer);
(s, None, ty.prefix_string())
(s, None, ty.prefix_string(), None, None)
}

pub fn need_type_info_err(
Expand All @@ -209,7 +231,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
error_code: TypeAnnotationNeeded,
) -> DiagnosticBuilder<'tcx> {
let ty = self.resolve_vars_if_possible(&ty);
let (name, name_sp, descr) = self.extract_type_name(&ty, None);
let (name, name_sp, descr, parent_name, parent_descr) = self.extract_type_name(&ty, None);


let mut local_visitor = FindLocalByTypeVisitor::new(&self, ty, &self.tcx.hir());
let ty_to_string = |ty: Ty<'tcx>| -> String {
Expand All @@ -218,7 +241,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let ty_vars = self.type_variables.borrow();
let getter = move |ty_vid| {
let var_origin = ty_vars.var_origin(ty_vid);
if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind {
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) = var_origin.kind {
return Some(name.to_string());
}
None
Expand Down Expand Up @@ -317,6 +340,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&descr,
&name,
&ret,
parent_name,
parent_descr,
);
// We don't want to give the other suggestions when the problem is the
// closure return type.
Expand Down Expand Up @@ -433,8 +458,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if !err.span.span_labels().iter().any(|span_label| {
span_label.label.is_some() && span_label.span == span
}) && local_visitor.found_arg_pattern.is_none()
{ // Avoid multiple labels pointing at `span`.
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr));
{
// Avoid multiple labels pointing at `span`.
err.span_label(
span,
InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr)
);
}

err
Expand Down Expand Up @@ -496,19 +525,42 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
ty: Ty<'tcx>,
) -> DiagnosticBuilder<'tcx> {
let ty = self.resolve_vars_if_possible(&ty);
let (name, _, descr) = self.extract_type_name(&ty, None);
let (name, _, descr, parent_name, parent_descr) = self.extract_type_name(&ty, None);

let mut err = struct_span_err!(
self.tcx.sess, span, E0698, "type inside {} must be known in this context", kind,
);
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr));
err.span_label(span, InferCtxt::missing_type_msg(
&name,
&descr,
parent_name,
parent_descr
));
err
}

fn missing_type_msg(type_name: &str, descr: &str) -> Cow<'static, str>{
fn missing_type_msg(
type_name: &str,
descr: &str,
parent_name: Option<String>,
parent_descr: Option<&str>,
) -> Cow<'static, str> {
if type_name == "_" {
"cannot infer type".into()
} else {
format!("cannot infer type for {} `{}`", descr, type_name).into()
let parent_desc = if let Some(parent_name) = parent_name {
let parent_type_descr = if let Some(parent_descr) = parent_descr {
format!(" the {}", parent_descr)
} else {
"".into()
};

format!(" declared on{} `{}`", parent_type_descr, parent_name)
} else {
"".to_string()
};

format!("cannot infer type for {} `{}`{}", descr, type_name, parent_desc).into()
}
}
}
5 changes: 4 additions & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.universe(),
false,
TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeParameterDefinition(param.name),
kind: TypeVariableOriginKind::TypeParameterDefinition(
param.name,
Some(param.def_id)
),
span,
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
if let ty::TyVar(ty_vid) = infer_ty {
let ty_vars = self.infcx.type_variables.borrow();
if let TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeParameterDefinition(_),
kind: TypeVariableOriginKind::TypeParameterDefinition(_, _),
span,
} = *ty_vars.var_origin(ty_vid)
{
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/infer/type_variable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use syntax::symbol::Symbol;
use syntax_pos::Span;
use crate::ty::{self, Ty, TyVid};
use crate::hir::def_id::DefId;

use std::cmp;
use std::marker::PhantomData;
Expand Down Expand Up @@ -49,7 +50,7 @@ pub enum TypeVariableOriginKind {
MiscVariable,
NormalizeProjectionType,
TypeInference,
TypeParameterDefinition(Symbol),
TypeParameterDefinition(Symbol, Option<DefId>),

/// One of the upvars or closure kind parameters in a `ClosureSubsts`
/// (before it has been determined).
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.var_map.entry(ty).or_insert_with(||
infcx.next_ty_var(
TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeParameterDefinition(name),
kind: TypeVariableOriginKind::TypeParameterDefinition(name, None),
span: DUMMY_SP,
}
)
Expand Down
11 changes: 11 additions & 0 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ pub enum AssocKind {
Type
}

impl AssocKind {
pub fn suggestion_descr(&self) -> &'static str {
match self {
ty::AssocKind::Method => "method call",
ty::AssocKind::Type |
ty::AssocKind::OpaqueTy => "associated type",
ty::AssocKind::Const => "associated constant",
}
}
}

impl AssocItem {
pub fn def_kind(&self) -> DefKind {
match self.kind {
Expand Down
43 changes: 7 additions & 36 deletions src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
llval
}
}
(CastTy::Int(_), CastTy::Float) => {
if signed {
bx.sitofp(llval, ll_t_out)
} else {
bx.uitofp(llval, ll_t_out)
}
}
(CastTy::Ptr(_), CastTy::Ptr(_)) |
(CastTy::FnPtr, CastTy::Ptr(_)) |
(CastTy::RPtr(_), CastTy::Ptr(_)) =>
Expand All @@ -352,8 +359,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let usize_llval = bx.intcast(llval, bx.cx().type_isize(), signed);
bx.inttoptr(usize_llval, ll_t_out)
}
(CastTy::Int(_), CastTy::Float) =>
cast_int_to_float(&mut bx, signed, llval, ll_t_in, ll_t_out),
(CastTy::Float, CastTy::Int(IntTy::I)) =>
cast_float_to_int(&mut bx, true, llval, ll_t_in, ll_t_out),
(CastTy::Float, CastTy::Int(_)) =>
Expand Down Expand Up @@ -720,40 +725,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}
}

fn cast_int_to_float<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
bx: &mut Bx,
signed: bool,
x: Bx::Value,
int_ty: Bx::Type,
float_ty: Bx::Type
) -> Bx::Value {
// Most integer types, even i128, fit into [-f32::MAX, f32::MAX] after rounding.
// It's only u128 -> f32 that can cause overflows (i.e., should yield infinity).
// LLVM's uitofp produces undef in those cases, so we manually check for that case.
let is_u128_to_f32 = !signed &&
bx.cx().int_width(int_ty) == 128 &&
bx.cx().float_width(float_ty) == 32;
if is_u128_to_f32 {
// All inputs greater or equal to (f32::MAX + 0.5 ULP) are rounded to infinity,
// and for everything else LLVM's uitofp works just fine.
use rustc_apfloat::ieee::Single;
const MAX_F32_PLUS_HALF_ULP: u128 = ((1 << (Single::PRECISION + 1)) - 1)
<< (Single::MAX_EXP - Single::PRECISION as i16);
let max = bx.cx().const_uint_big(int_ty, MAX_F32_PLUS_HALF_ULP);
let overflow = bx.icmp(IntPredicate::IntUGE, x, max);
let infinity_bits = bx.cx().const_u32(ieee::Single::INFINITY.to_bits() as u32);
let infinity = bx.bitcast(infinity_bits, float_ty);
let fp = bx.uitofp(x, float_ty);
bx.select(overflow, infinity, fp)
} else {
if signed {
bx.sitofp(x, float_ty)
} else {
bx.uitofp(x, float_ty)
}
}
}

fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
bx: &mut Bx,
signed: bool,
Expand Down
Loading