Skip to content

Commit 6b561b4

Browse files
committed
Auto merge of #67449 - Centril:rollup-04hvg57, r=Centril
Rollup of 7 pull requests Successful merges: - #66755 (Remove a const-if-hack in RawVec) - #67127 (Use structured suggestion for disambiguating method calls) - #67219 (Fix up Command Debug output when arg0 is specified.) - #67285 (Indicate origin of where type parameter for uninferred types ) - #67328 (Remove now-redundant range check on u128 -> f32 casts) - #67367 (Move command line option definitions into a dedicated file) - #67442 (Remove `SOCK_CLOEXEC` dummy variable on platforms that don't use it.) Failed merges: r? @ghost
2 parents 696735f + 3a336c4 commit 6b561b4

File tree

60 files changed

+1378
-1133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1378
-1133
lines changed

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#![feature(const_generic_impls_guard)]
8686
#![feature(const_generics)]
8787
#![feature(const_in_array_repeat_expressions)]
88+
#![feature(const_if_match)]
8889
#![feature(cow_is_borrowed)]
8990
#![feature(dispatch_from_dyn)]
9091
#![feature(core_intrinsics)]

src/liballoc/raw_vec.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,12 @@ impl<T, A: Alloc> RawVec<T, A> {
5252
/// Like `new`, but parameterized over the choice of allocator for
5353
/// the returned `RawVec`.
5454
pub const fn new_in(a: A) -> Self {
55-
// `!0` is `usize::MAX`. This branch should be stripped at compile time.
56-
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
57-
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
55+
let cap = if mem::size_of::<T>() == 0 { core::usize::MAX } else { 0 };
5856

5957
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
6058
RawVec {
6159
ptr: Unique::empty(),
62-
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
63-
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
60+
cap,
6461
a,
6562
}
6663
}
@@ -132,19 +129,7 @@ impl<T> RawVec<T, Global> {
132129
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
133130
/// delayed allocation.
134131
pub const fn new() -> Self {
135-
// FIXME(Centril): Reintegrate this with `fn new_in` when we can.
136-
137-
// `!0` is `usize::MAX`. This branch should be stripped at compile time.
138-
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
139-
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
140-
141-
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
142-
RawVec {
143-
ptr: Unique::empty(),
144-
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
145-
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
146-
a: Global,
147-
}
132+
Self::new_in(Global)
148133
}
149134

150135
/// Creates a `RawVec` (on the system heap) with exactly the

src/librustc/infer/error_reporting/need_type_info.rs

+65-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::hir::{self, Body, FunctionRetTy, Expr, ExprKind, HirId, Local, Pat};
33
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
44
use crate::infer::InferCtxt;
55
use crate::infer::type_variable::TypeVariableOriginKind;
6-
use crate::ty::{self, Ty, Infer, TyVar};
6+
use crate::ty::{self, Ty, Infer, TyVar, DefIdTree};
77
use crate::ty::print::Print;
88
use syntax::source_map::DesugaringKind;
99
use syntax::symbol::kw;
@@ -117,6 +117,8 @@ fn closure_return_type_suggestion(
117117
descr: &str,
118118
name: &str,
119119
ret: &str,
120+
parent_name: Option<String>,
121+
parent_descr: Option<&str>,
120122
) {
121123
let (arrow, post) = match output {
122124
FunctionRetTy::DefaultReturn(_) => ("-> ", " "),
@@ -138,7 +140,12 @@ fn closure_return_type_suggestion(
138140
suggestion,
139141
Applicability::HasPlaceholders,
140142
);
141-
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr));
143+
err.span_label(span, InferCtxt::missing_type_msg(
144+
&name,
145+
&descr,
146+
parent_name,
147+
parent_descr
148+
));
142149
}
143150

144151
/// Given a closure signature, return a `String` containing a list of all its argument types.
@@ -177,16 +184,31 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
177184
&self,
178185
ty: Ty<'tcx>,
179186
highlight: Option<ty::print::RegionHighlightMode>,
180-
) -> (String, Option<Span>, Cow<'static, str>) {
187+
) -> (String, Option<Span>, Cow<'static, str>, Option<String>, Option<&'static str>) {
181188
if let ty::Infer(ty::TyVar(ty_vid)) = ty.kind {
182189
let ty_vars = self.type_variables.borrow();
183190
let var_origin = ty_vars.var_origin(ty_vid);
184-
if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind {
191+
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind {
192+
let parent_def_id = def_id.and_then(|def_id| self.tcx.parent(def_id));
193+
let (parent_name, parent_desc) = if let Some(parent_def_id) = parent_def_id {
194+
let parent_name = self.tcx.def_key(parent_def_id).disambiguated_data.data
195+
.get_opt_name().map(|parent_symbol| parent_symbol.to_string());
196+
197+
let type_parent_desc = self.tcx.def_kind(parent_def_id)
198+
.map(|parent_def_kind| parent_def_kind.descr(parent_def_id));
199+
200+
(parent_name, type_parent_desc)
201+
} else {
202+
(None, None)
203+
};
204+
185205
if name != kw::SelfUpper {
186206
return (
187207
name.to_string(),
188208
Some(var_origin.span),
189209
"type parameter".into(),
210+
parent_name,
211+
parent_desc,
190212
);
191213
}
192214
}
@@ -198,7 +220,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
198220
printer.region_highlight_mode = highlight;
199221
}
200222
let _ = ty.print(printer);
201-
(s, None, ty.prefix_string())
223+
(s, None, ty.prefix_string(), None, None)
202224
}
203225

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

214237
let mut local_visitor = FindLocalByTypeVisitor::new(&self, ty, &self.tcx.hir());
215238
let ty_to_string = |ty: Ty<'tcx>| -> String {
@@ -218,7 +241,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
218241
let ty_vars = self.type_variables.borrow();
219242
let getter = move |ty_vid| {
220243
let var_origin = ty_vars.var_origin(ty_vid);
221-
if let TypeVariableOriginKind::TypeParameterDefinition(name) = var_origin.kind {
244+
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) = var_origin.kind {
222245
return Some(name.to_string());
223246
}
224247
None
@@ -317,6 +340,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
317340
&descr,
318341
&name,
319342
&ret,
343+
parent_name,
344+
parent_descr,
320345
);
321346
// We don't want to give the other suggestions when the problem is the
322347
// closure return type.
@@ -433,8 +458,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
433458
if !err.span.span_labels().iter().any(|span_label| {
434459
span_label.label.is_some() && span_label.span == span
435460
}) && local_visitor.found_arg_pattern.is_none()
436-
{ // Avoid multiple labels pointing at `span`.
437-
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr));
461+
{
462+
// Avoid multiple labels pointing at `span`.
463+
err.span_label(
464+
span,
465+
InferCtxt::missing_type_msg(&name, &descr, parent_name, parent_descr)
466+
);
438467
}
439468

440469
err
@@ -496,19 +525,42 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
496525
ty: Ty<'tcx>,
497526
) -> DiagnosticBuilder<'tcx> {
498527
let ty = self.resolve_vars_if_possible(&ty);
499-
let (name, _, descr) = self.extract_type_name(&ty, None);
528+
let (name, _, descr, parent_name, parent_descr) = self.extract_type_name(&ty, None);
529+
500530
let mut err = struct_span_err!(
501531
self.tcx.sess, span, E0698, "type inside {} must be known in this context", kind,
502532
);
503-
err.span_label(span, InferCtxt::missing_type_msg(&name, &descr));
533+
err.span_label(span, InferCtxt::missing_type_msg(
534+
&name,
535+
&descr,
536+
parent_name,
537+
parent_descr
538+
));
504539
err
505540
}
506541

507-
fn missing_type_msg(type_name: &str, descr: &str) -> Cow<'static, str>{
542+
fn missing_type_msg(
543+
type_name: &str,
544+
descr: &str,
545+
parent_name: Option<String>,
546+
parent_descr: Option<&str>,
547+
) -> Cow<'static, str> {
508548
if type_name == "_" {
509549
"cannot infer type".into()
510550
} else {
511-
format!("cannot infer type for {} `{}`", descr, type_name).into()
551+
let parent_desc = if let Some(parent_name) = parent_name {
552+
let parent_type_descr = if let Some(parent_descr) = parent_descr {
553+
format!(" the {}", parent_descr)
554+
} else {
555+
"".into()
556+
};
557+
558+
format!(" declared on{} `{}`", parent_type_descr, parent_name)
559+
} else {
560+
"".to_string()
561+
};
562+
563+
format!("cannot infer type for {} `{}`{}", descr, type_name, parent_desc).into()
512564
}
513565
}
514566
}

src/librustc/infer/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11351135
self.universe(),
11361136
false,
11371137
TypeVariableOrigin {
1138-
kind: TypeVariableOriginKind::TypeParameterDefinition(param.name),
1138+
kind: TypeVariableOriginKind::TypeParameterDefinition(
1139+
param.name,
1140+
Some(param.def_id)
1141+
),
11391142
span,
11401143
},
11411144
);

src/librustc/infer/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
124124
if let ty::TyVar(ty_vid) = infer_ty {
125125
let ty_vars = self.infcx.type_variables.borrow();
126126
if let TypeVariableOrigin {
127-
kind: TypeVariableOriginKind::TypeParameterDefinition(_),
127+
kind: TypeVariableOriginKind::TypeParameterDefinition(_, _),
128128
span,
129129
} = *ty_vars.var_origin(ty_vid)
130130
{

src/librustc/infer/type_variable.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use syntax::symbol::Symbol;
22
use syntax_pos::Span;
33
use crate::ty::{self, Ty, TyVid};
4+
use crate::hir::def_id::DefId;
45

56
use std::cmp;
67
use std::marker::PhantomData;
@@ -49,7 +50,7 @@ pub enum TypeVariableOriginKind {
4950
MiscVariable,
5051
NormalizeProjectionType,
5152
TypeInference,
52-
TypeParameterDefinition(Symbol),
53+
TypeParameterDefinition(Symbol, Option<DefId>),
5354

5455
/// One of the upvars or closure kind parameters in a `ClosureSubsts`
5556
/// (before it has been determined).

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21132113
self.var_map.entry(ty).or_insert_with(||
21142114
infcx.next_ty_var(
21152115
TypeVariableOrigin {
2116-
kind: TypeVariableOriginKind::TypeParameterDefinition(name),
2116+
kind: TypeVariableOriginKind::TypeParameterDefinition(name, None),
21172117
span: DUMMY_SP,
21182118
}
21192119
)

src/librustc/ty/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ pub enum AssocKind {
212212
Type
213213
}
214214

215+
impl AssocKind {
216+
pub fn suggestion_descr(&self) -> &'static str {
217+
match self {
218+
ty::AssocKind::Method => "method call",
219+
ty::AssocKind::Type |
220+
ty::AssocKind::OpaqueTy => "associated type",
221+
ty::AssocKind::Const => "associated constant",
222+
}
223+
}
224+
}
225+
215226
impl AssocItem {
216227
pub fn def_kind(&self) -> DefKind {
217228
match self.kind {

src/librustc_codegen_ssa/mir/rvalue.rs

+7-36
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
341341
llval
342342
}
343343
}
344+
(CastTy::Int(_), CastTy::Float) => {
345+
if signed {
346+
bx.sitofp(llval, ll_t_out)
347+
} else {
348+
bx.uitofp(llval, ll_t_out)
349+
}
350+
}
344351
(CastTy::Ptr(_), CastTy::Ptr(_)) |
345352
(CastTy::FnPtr, CastTy::Ptr(_)) |
346353
(CastTy::RPtr(_), CastTy::Ptr(_)) =>
@@ -352,8 +359,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
352359
let usize_llval = bx.intcast(llval, bx.cx().type_isize(), signed);
353360
bx.inttoptr(usize_llval, ll_t_out)
354361
}
355-
(CastTy::Int(_), CastTy::Float) =>
356-
cast_int_to_float(&mut bx, signed, llval, ll_t_in, ll_t_out),
357362
(CastTy::Float, CastTy::Int(IntTy::I)) =>
358363
cast_float_to_int(&mut bx, true, llval, ll_t_in, ll_t_out),
359364
(CastTy::Float, CastTy::Int(_)) =>
@@ -720,40 +725,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
720725
}
721726
}
722727

723-
fn cast_int_to_float<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
724-
bx: &mut Bx,
725-
signed: bool,
726-
x: Bx::Value,
727-
int_ty: Bx::Type,
728-
float_ty: Bx::Type
729-
) -> Bx::Value {
730-
// Most integer types, even i128, fit into [-f32::MAX, f32::MAX] after rounding.
731-
// It's only u128 -> f32 that can cause overflows (i.e., should yield infinity).
732-
// LLVM's uitofp produces undef in those cases, so we manually check for that case.
733-
let is_u128_to_f32 = !signed &&
734-
bx.cx().int_width(int_ty) == 128 &&
735-
bx.cx().float_width(float_ty) == 32;
736-
if is_u128_to_f32 {
737-
// All inputs greater or equal to (f32::MAX + 0.5 ULP) are rounded to infinity,
738-
// and for everything else LLVM's uitofp works just fine.
739-
use rustc_apfloat::ieee::Single;
740-
const MAX_F32_PLUS_HALF_ULP: u128 = ((1 << (Single::PRECISION + 1)) - 1)
741-
<< (Single::MAX_EXP - Single::PRECISION as i16);
742-
let max = bx.cx().const_uint_big(int_ty, MAX_F32_PLUS_HALF_ULP);
743-
let overflow = bx.icmp(IntPredicate::IntUGE, x, max);
744-
let infinity_bits = bx.cx().const_u32(ieee::Single::INFINITY.to_bits() as u32);
745-
let infinity = bx.bitcast(infinity_bits, float_ty);
746-
let fp = bx.uitofp(x, float_ty);
747-
bx.select(overflow, infinity, fp)
748-
} else {
749-
if signed {
750-
bx.sitofp(x, float_ty)
751-
} else {
752-
bx.uitofp(x, float_ty)
753-
}
754-
}
755-
}
756-
757728
fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
758729
bx: &mut Bx,
759730
signed: bool,

0 commit comments

Comments
 (0)