Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7bb106f

Browse files
committedSep 16, 2020
Auto merge of #76786 - Dylan-DPC:rollup-x6p60m6, r=Dylan-DPC
Rollup of 10 pull requests Successful merges: - #76669 (Prefer asm! over llvm_asm! in core) - #76675 (Small improvements to asm documentation) - #76681 (remove orphaned files) - #76694 (Introduce a PartitioningCx struct) - #76695 (fix syntax error in suggesting generic constraint in trait parameter) - #76699 (improve const infer error) - #76707 (Simplify iter flatten struct doc) - #76710 (:arrow_up: rust-analyzer) - #76714 (Small docs improvements) - #76717 (Fix generating rustc docs with non-default lib directory.) Failed merges: r? `@ghost`
2 parents 5fae569 + f631293 commit 7bb106f

35 files changed

+290
-155
lines changed
 

‎compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use rustc_hir::def::{DefKind, Namespace};
66
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
77
use rustc_hir::{Body, Expr, ExprKind, FnRetTy, HirId, Local, Pat};
88
use rustc_middle::hir::map::Map;
9+
use rustc_middle::infer::unify_key::ConstVariableOriginKind;
910
use rustc_middle::ty::print::Print;
1011
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
11-
use rustc_middle::ty::{self, DefIdTree, Ty};
12+
use rustc_middle::ty::{self, DefIdTree, InferConst, Ty};
1213
use rustc_span::source_map::DesugaringKind;
1314
use rustc_span::symbol::kw;
1415
use rustc_span::Span;
@@ -569,14 +570,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
569570
local_visitor.visit_expr(expr);
570571
}
571572

573+
let mut param_name = None;
574+
let span = if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val {
575+
let origin = self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
576+
if let ConstVariableOriginKind::ConstParameterDefinition(param) = origin.kind {
577+
param_name = Some(param);
578+
}
579+
origin.span
580+
} else {
581+
local_visitor.target_span
582+
};
583+
572584
let error_code = error_code.into();
573-
let mut err = self.tcx.sess.struct_span_err_with_code(
574-
local_visitor.target_span,
575-
"type annotations needed",
576-
error_code,
577-
);
585+
let mut err =
586+
self.tcx.sess.struct_span_err_with_code(span, "type annotations needed", error_code);
578587

579-
err.note("unable to infer the value of a const parameter");
588+
if let Some(param_name) = param_name {
589+
err.note(&format!("cannot infer the value of the const parameter `{}`", param_name));
590+
} else {
591+
err.note("unable to infer the value of a const parameter");
592+
}
580593

581594
err
582595
}

‎compiler/rustc_middle/src/infer/unify_key.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub struct ConstVariableOrigin {
124124
pub enum ConstVariableOriginKind {
125125
MiscVariable,
126126
ConstInference,
127+
// FIXME(const_generics): Consider storing the `DefId` of the param here.
127128
ConstParameterDefinition(Symbol),
128129
SubstitutionPlaceholder,
129130
}

‎compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,8 +2285,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
22852285
/// Constants
22862286
///
22872287
/// Two constants are equal if they are the same constant. Note that
2288-
/// this does not necessarily mean that they are "==" in Rust -- in
2289-
/// particular one must be wary of `NaN`!
2288+
/// this does not necessarily mean that they are `==` in Rust -- in
2289+
/// particular, one must be wary of `NaN`!
22902290
22912291
#[derive(Clone, Copy, PartialEq, TyEncodable, TyDecodable, HashStable)]
22922292
pub struct Constant<'tcx> {

‎compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ use std::mem;
6666
use std::ops::{Bound, Deref};
6767
use std::sync::Arc;
6868

69-
/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
70-
/// except through `tcx.err*()`, which are in this module.
69+
/// A type that is not publicly constructable. This prevents people from making [`TyKind::Error`]s
70+
/// except through the error-reporting functions on a [`tcx`][TyCtxt].
7171
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
7272
#[derive(TyEncodable, TyDecodable, HashStable)]
7373
pub struct DelaySpanBugEmitted(());

‎compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,33 +202,59 @@ pub fn suggest_constraining_type_param(
202202
// Suggestion:
203203
// fn foo<T>(t: T) where T: Foo, T: Bar {... }
204204
// - insert: `, T: Zar`
205+
//
206+
// Additionally, there may be no `where` clause whatsoever in the case that this was
207+
// reached because the generic parameter has a default:
208+
//
209+
// Message:
210+
// trait Foo<T=()> {... }
211+
// - help: consider further restricting this type parameter with `where T: Zar`
212+
//
213+
// Suggestion:
214+
// trait Foo<T=()> where T: Zar {... }
215+
// - insert: `where T: Zar`
205216

206-
let mut param_spans = Vec::new();
217+
if matches!(param.kind, hir::GenericParamKind::Type { default: Some(_), .. })
218+
&& generics.where_clause.predicates.len() == 0
219+
{
220+
// Suggest a bound, but there is no existing `where` clause *and* the type param has a
221+
// default (`<T=Foo>`), so we suggest adding `where T: Bar`.
222+
err.span_suggestion_verbose(
223+
generics.where_clause.tail_span_for_suggestion(),
224+
&msg_restrict_type_further,
225+
format!(" where {}: {}", param_name, constraint),
226+
Applicability::MachineApplicable,
227+
);
228+
} else {
229+
let mut param_spans = Vec::new();
207230

208-
for predicate in generics.where_clause.predicates {
209-
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
210-
span, bounded_ty, ..
211-
}) = predicate
212-
{
213-
if let TyKind::Path(QPath::Resolved(_, path)) = &bounded_ty.kind {
214-
if let Some(segment) = path.segments.first() {
215-
if segment.ident.to_string() == param_name {
216-
param_spans.push(span);
231+
for predicate in generics.where_clause.predicates {
232+
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
233+
span,
234+
bounded_ty,
235+
..
236+
}) = predicate
237+
{
238+
if let TyKind::Path(QPath::Resolved(_, path)) = &bounded_ty.kind {
239+
if let Some(segment) = path.segments.first() {
240+
if segment.ident.to_string() == param_name {
241+
param_spans.push(span);
242+
}
217243
}
218244
}
219245
}
220246
}
221-
}
222247

223-
match &param_spans[..] {
224-
&[&param_span] => suggest_restrict(param_span.shrink_to_hi()),
225-
_ => {
226-
err.span_suggestion_verbose(
227-
generics.where_clause.tail_span_for_suggestion(),
228-
&msg_restrict_type_further,
229-
format!(", {}: {}", param_name, constraint),
230-
Applicability::MachineApplicable,
231-
);
248+
match &param_spans[..] {
249+
&[&param_span] => suggest_restrict(param_span.shrink_to_hi()),
250+
_ => {
251+
err.span_suggestion_verbose(
252+
generics.where_clause.tail_span_for_suggestion(),
253+
&msg_restrict_type_further,
254+
format!(", {}: {}", param_name, constraint),
255+
Applicability::MachineApplicable,
256+
);
257+
}
232258
}
233259
}
234260

‎compiler/rustc_middle/src/ty/sty.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,13 +1233,13 @@ rustc_index::newtype_index! {
12331233
/// particular, imagine a type like this:
12341234
///
12351235
/// for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char)
1236-
/// ^ ^ | | |
1237-
/// | | | | |
1238-
/// | +------------+ 0 | |
1239-
/// | | |
1240-
/// +--------------------------------+ 1 |
1241-
/// | |
1242-
/// +------------------------------------------+ 0
1236+
/// ^ ^ | | |
1237+
/// | | | | |
1238+
/// | +------------+ 0 | |
1239+
/// | | |
1240+
/// +----------------------------------+ 1 |
1241+
/// | |
1242+
/// +----------------------------------------------+ 0
12431243
///
12441244
/// In this type, there are two binders (the outer fn and the inner
12451245
/// fn). We need to be able to determine, for any given region, which

‎compiler/rustc_mir/src/monomorphize/partitioning/default.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_middle::ty::print::characteristic_def_id_of_type;
1111
use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt};
1212
use rustc_span::symbol::Symbol;
1313

14+
use super::PartitioningCx;
1415
use crate::monomorphize::collector::InliningMap;
1516
use crate::monomorphize::partitioning::merging;
1617
use crate::monomorphize::partitioning::{
@@ -22,35 +23,36 @@ pub struct DefaultPartitioning;
2223
impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
2324
fn place_root_mono_items(
2425
&mut self,
25-
tcx: TyCtxt<'tcx>,
26+
cx: &PartitioningCx<'_, 'tcx>,
2627
mono_items: &mut dyn Iterator<Item = MonoItem<'tcx>>,
2728
) -> PreInliningPartitioning<'tcx> {
2829
let mut roots = FxHashSet::default();
2930
let mut codegen_units = FxHashMap::default();
30-
let is_incremental_build = tcx.sess.opts.incremental.is_some();
31+
let is_incremental_build = cx.tcx.sess.opts.incremental.is_some();
3132
let mut internalization_candidates = FxHashSet::default();
3233

3334
// Determine if monomorphizations instantiated in this crate will be made
3435
// available to downstream crates. This depends on whether we are in
3536
// share-generics mode and whether the current crate can even have
3637
// downstream crates.
37-
let export_generics = tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics();
38+
let export_generics =
39+
cx.tcx.sess.opts.share_generics() && cx.tcx.local_crate_exports_generics();
3840

39-
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
41+
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);
4042
let cgu_name_cache = &mut FxHashMap::default();
4143

4244
for mono_item in mono_items {
43-
match mono_item.instantiation_mode(tcx) {
45+
match mono_item.instantiation_mode(cx.tcx) {
4446
InstantiationMode::GloballyShared { .. } => {}
4547
InstantiationMode::LocalCopy => continue,
4648
}
4749

48-
let characteristic_def_id = characteristic_def_id_of_mono_item(tcx, mono_item);
50+
let characteristic_def_id = characteristic_def_id_of_mono_item(cx.tcx, mono_item);
4951
let is_volatile = is_incremental_build && mono_item.is_generic_fn();
5052

5153
let codegen_unit_name = match characteristic_def_id {
5254
Some(def_id) => compute_codegen_unit_name(
53-
tcx,
55+
cx.tcx,
5456
cgu_name_builder,
5557
def_id,
5658
is_volatile,
@@ -65,7 +67,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
6567

6668
let mut can_be_internalized = true;
6769
let (linkage, visibility) = mono_item_linkage_and_visibility(
68-
tcx,
70+
cx.tcx,
6971
&mono_item,
7072
&mut can_be_internalized,
7173
export_generics,
@@ -97,17 +99,16 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
9799

98100
fn merge_codegen_units(
99101
&mut self,
100-
tcx: TyCtxt<'tcx>,
102+
cx: &PartitioningCx<'_, 'tcx>,
101103
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
102-
target_cgu_count: usize,
103104
) {
104-
merging::merge_codegen_units(tcx, initial_partitioning, target_cgu_count);
105+
merging::merge_codegen_units(cx, initial_partitioning);
105106
}
106107

107108
fn place_inlined_mono_items(
108109
&mut self,
110+
cx: &PartitioningCx<'_, 'tcx>,
109111
initial_partitioning: PreInliningPartitioning<'tcx>,
110-
inlining_map: &InliningMap<'tcx>,
111112
) -> PostInliningPartitioning<'tcx> {
112113
let mut new_partitioning = Vec::new();
113114
let mut mono_item_placements = FxHashMap::default();
@@ -124,7 +125,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
124125
// Collect all items that need to be available in this codegen unit.
125126
let mut reachable = FxHashSet::default();
126127
for root in old_codegen_unit.items().keys() {
127-
follow_inlining(*root, inlining_map, &mut reachable);
128+
follow_inlining(*root, cx.inlining_map, &mut reachable);
128129
}
129130

130131
let mut new_codegen_unit = CodegenUnit::new(old_codegen_unit.name());
@@ -198,9 +199,8 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
198199

199200
fn internalize_symbols(
200201
&mut self,
201-
_tcx: TyCtxt<'tcx>,
202+
cx: &PartitioningCx<'_, 'tcx>,
202203
partitioning: &mut PostInliningPartitioning<'tcx>,
203-
inlining_map: &InliningMap<'tcx>,
204204
) {
205205
if partitioning.codegen_units.len() == 1 {
206206
// Fast path for when there is only one codegen unit. In this case we
@@ -218,7 +218,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
218218
// Build a map from every monomorphization to all the monomorphizations that
219219
// reference it.
220220
let mut accessor_map: FxHashMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>> = Default::default();
221-
inlining_map.iter_accesses(|accessor, accessees| {
221+
cx.inlining_map.iter_accesses(|accessor, accessees| {
222222
for accessee in accessees {
223223
accessor_map.entry(*accessee).or_default().push(accessor);
224224
}

‎compiler/rustc_mir/src/monomorphize/partitioning/merging.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ use std::cmp;
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::def_id::LOCAL_CRATE;
55
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder};
6-
use rustc_middle::ty::TyCtxt;
76
use rustc_span::symbol::{Symbol, SymbolStr};
87

8+
use super::PartitioningCx;
99
use crate::monomorphize::partitioning::PreInliningPartitioning;
1010

1111
pub fn merge_codegen_units<'tcx>(
12-
tcx: TyCtxt<'tcx>,
12+
cx: &PartitioningCx<'_, 'tcx>,
1313
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
14-
target_cgu_count: usize,
1514
) {
16-
assert!(target_cgu_count >= 1);
15+
assert!(cx.target_cgu_count >= 1);
1716
let codegen_units = &mut initial_partitioning.codegen_units;
1817

1918
// Note that at this point in time the `codegen_units` here may not be in a
@@ -32,7 +31,7 @@ pub fn merge_codegen_units<'tcx>(
3231
codegen_units.iter().map(|cgu| (cgu.name(), vec![cgu.name().as_str()])).collect();
3332

3433
// Merge the two smallest codegen units until the target size is reached.
35-
while codegen_units.len() > target_cgu_count {
34+
while codegen_units.len() > cx.target_cgu_count {
3635
// Sort small cgus to the back
3736
codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate()));
3837
let mut smallest = codegen_units.pop().unwrap();
@@ -56,9 +55,9 @@ pub fn merge_codegen_units<'tcx>(
5655
);
5756
}
5857

59-
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
58+
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);
6059

61-
if tcx.sess.opts.incremental.is_some() {
60+
if cx.tcx.sess.opts.incremental.is_some() {
6261
// If we are doing incremental compilation, we want CGU names to
6362
// reflect the path of the source level module they correspond to.
6463
// For CGUs that contain the code of multiple modules because of the
@@ -84,7 +83,7 @@ pub fn merge_codegen_units<'tcx>(
8483

8584
for cgu in codegen_units.iter_mut() {
8685
if let Some(new_cgu_name) = new_cgu_names.get(&cgu.name()) {
87-
if tcx.sess.opts.debugging_opts.human_readable_cgu_names {
86+
if cx.tcx.sess.opts.debugging_opts.human_readable_cgu_names {
8887
cgu.set_name(Symbol::intern(&new_cgu_name));
8988
} else {
9089
// If we don't require CGU names to be human-readable, we

‎compiler/rustc_mir/src/monomorphize/partitioning/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,31 +108,35 @@ use rustc_span::symbol::Symbol;
108108
use crate::monomorphize::collector::InliningMap;
109109
use crate::monomorphize::collector::{self, MonoItemCollectionMode};
110110

111+
pub struct PartitioningCx<'a, 'tcx> {
112+
tcx: TyCtxt<'tcx>,
113+
target_cgu_count: usize,
114+
inlining_map: &'a InliningMap<'tcx>,
115+
}
116+
111117
trait Partitioner<'tcx> {
112118
fn place_root_mono_items(
113119
&mut self,
114-
tcx: TyCtxt<'tcx>,
120+
cx: &PartitioningCx<'_, 'tcx>,
115121
mono_items: &mut dyn Iterator<Item = MonoItem<'tcx>>,
116122
) -> PreInliningPartitioning<'tcx>;
117123

118124
fn merge_codegen_units(
119125
&mut self,
120-
tcx: TyCtxt<'tcx>,
126+
cx: &PartitioningCx<'_, 'tcx>,
121127
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
122-
target_cgu_count: usize,
123128
);
124129

125130
fn place_inlined_mono_items(
126131
&mut self,
132+
cx: &PartitioningCx<'_, 'tcx>,
127133
initial_partitioning: PreInliningPartitioning<'tcx>,
128-
inlining_map: &InliningMap<'tcx>,
129134
) -> PostInliningPartitioning<'tcx>;
130135

131136
fn internalize_symbols(
132137
&mut self,
133-
tcx: TyCtxt<'tcx>,
138+
cx: &PartitioningCx<'_, 'tcx>,
134139
partitioning: &mut PostInliningPartitioning<'tcx>,
135-
inlining_map: &InliningMap<'tcx>,
136140
);
137141
}
138142

@@ -157,12 +161,13 @@ pub fn partition<'tcx>(
157161
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning");
158162

159163
let mut partitioner = get_partitioner(tcx);
164+
let cx = &PartitioningCx { tcx, target_cgu_count: max_cgu_count, inlining_map };
160165
// In the first step, we place all regular monomorphizations into their
161166
// respective 'home' codegen unit. Regular monomorphizations are all
162167
// functions and statics defined in the local crate.
163168
let mut initial_partitioning = {
164169
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_roots");
165-
partitioner.place_root_mono_items(tcx, mono_items)
170+
partitioner.place_root_mono_items(cx, mono_items)
166171
};
167172

168173
initial_partitioning.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
@@ -172,7 +177,7 @@ pub fn partition<'tcx>(
172177
// Merge until we have at most `max_cgu_count` codegen units.
173178
{
174179
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_merge_cgus");
175-
partitioner.merge_codegen_units(tcx, &mut initial_partitioning, max_cgu_count);
180+
partitioner.merge_codegen_units(cx, &mut initial_partitioning);
176181
debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
177182
}
178183

@@ -182,7 +187,7 @@ pub fn partition<'tcx>(
182187
// local functions the definition of which is marked with `#[inline]`.
183188
let mut post_inlining = {
184189
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_place_inline_items");
185-
partitioner.place_inlined_mono_items(initial_partitioning, inlining_map)
190+
partitioner.place_inlined_mono_items(cx, initial_partitioning)
186191
};
187192

188193
post_inlining.codegen_units.iter_mut().for_each(|cgu| cgu.estimate_size(tcx));
@@ -193,7 +198,7 @@ pub fn partition<'tcx>(
193198
// more freedom to optimize.
194199
if !tcx.sess.link_dead_code() {
195200
let _prof_timer = tcx.prof.generic_activity("cgu_partitioning_internalize_symbols");
196-
partitioner.internalize_symbols(tcx, &mut post_inlining, inlining_map);
201+
partitioner.internalize_symbols(cx, &mut post_inlining);
197202
}
198203

199204
// Finally, sort by codegen unit name, so that we get deterministic results.

‎library/core/src/hint.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn spin_loop() {
111111
#[inline]
112112
#[unstable(feature = "test", issue = "50297")]
113113
#[allow(unreachable_code)] // this makes #[cfg] a bit easier below.
114-
pub fn black_box<T>(dummy: T) -> T {
114+
pub fn black_box<T>(mut dummy: T) -> T {
115115
// We need to "use" the argument in some way LLVM can't introspect, and on
116116
// targets that support it we can typically leverage inline assembly to do
117117
// this. LLVM's interpretation of inline assembly is that it's, well, a black
@@ -121,7 +121,8 @@ pub fn black_box<T>(dummy: T) -> T {
121121
#[cfg(not(miri))] // This is just a hint, so it is fine to skip in Miri.
122122
// SAFETY: the inline assembly is a no-op.
123123
unsafe {
124-
llvm_asm!("" : : "r"(&dummy));
124+
// FIXME: Cannot use `asm!` because it doesn't support MIPS and other architectures.
125+
llvm_asm!("" : : "r"(&mut dummy) : "memory" : "volatile");
125126
}
126127

127128
dummy

‎library/core/src/iter/adapters/flatten.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ use super::Map;
77
/// An iterator that maps each element to an iterator, and yields the elements
88
/// of the produced iterators.
99
///
10-
/// This `struct` is created by the [`flat_map`] method on [`Iterator`]. See its
11-
/// documentation for more.
12-
///
13-
/// [`flat_map`]: trait.Iterator.html#method.flat_map
14-
/// [`Iterator`]: trait.Iterator.html
10+
/// This `struct` is created by [`Iterator::flat_map`]. See its documentation
11+
/// for more.
1512
#[must_use = "iterators are lazy and do nothing unless consumed"]
1613
#[stable(feature = "rust1", since = "1.0.0")]
1714
pub struct FlatMap<I, U: IntoIterator, F> {

‎library/core/src/num/dec2flt/algorithm.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,19 @@ mod fpu_precision {
6060
fn set_cw(cw: u16) {
6161
// SAFETY: the `fldcw` instruction has been audited to be able to work correctly with
6262
// any `u16`
63-
unsafe { llvm_asm!("fldcw $0" :: "m" (cw) :: "volatile") }
63+
unsafe {
64+
asm!(
65+
"fldcw ({})",
66+
in(reg) &cw,
67+
// FIXME: We are using ATT syntax to support LLVM 8 and LLVM 9.
68+
options(att_syntax, nostack),
69+
)
70+
}
6471
}
6572

6673
/// Sets the precision field of the FPU to `T` and returns a `FPUControlWord`.
6774
pub fn set_precision<T>() -> FPUControlWord {
68-
let cw = 0u16;
75+
let mut cw = 0_u16;
6976

7077
// Compute the value for the Precision Control field that is appropriate for `T`.
7178
let cw_precision = match size_of::<T>() {
@@ -78,7 +85,14 @@ mod fpu_precision {
7885
// `FPUControlWord` structure is dropped
7986
// SAFETY: the `fnstcw` instruction has been audited to be able to work correctly with
8087
// any `u16`
81-
unsafe { llvm_asm!("fnstcw $0" : "=*m" (&cw) ::: "volatile") }
88+
unsafe {
89+
asm!(
90+
"fnstcw ({})",
91+
in(reg) &mut cw,
92+
// FIXME: We are using ATT syntax to support LLVM 8 and LLVM 9.
93+
options(att_syntax, nostack),
94+
)
95+
}
8296

8397
// Set the control word to the desired precision. This is achieved by masking away the old
8498
// precision (bits 8 and 9, 0x300) and replacing it with the precision flag computed above.

‎src/bootstrap/builder.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,15 @@ impl<'a> Builder<'a> {
683683

684684
/// Adds the compiler's directory of dynamic libraries to `cmd`'s dynamic
685685
/// library lookup path.
686-
pub fn add_rustc_lib_path(&self, compiler: Compiler, cmd: &mut Cargo) {
686+
pub fn add_rustc_lib_path(&self, compiler: Compiler, cmd: &mut Command) {
687687
// Windows doesn't need dylib path munging because the dlls for the
688688
// compiler live next to the compiler and the system will find them
689689
// automatically.
690690
if cfg!(windows) {
691691
return;
692692
}
693693

694-
add_dylib_path(vec![self.rustc_libdir(compiler)], &mut cmd.command);
694+
add_dylib_path(vec![self.rustc_libdir(compiler)], cmd);
695695
}
696696

697697
/// Gets a path to the compiler specified.
@@ -1488,6 +1488,10 @@ impl Cargo {
14881488
self.command.env(key.as_ref(), value.as_ref());
14891489
self
14901490
}
1491+
1492+
pub fn add_rustc_lib_path(&mut self, builder: &Builder<'_>, compiler: Compiler) {
1493+
builder.add_rustc_lib_path(compiler, &mut self.command);
1494+
}
14911495
}
14921496

14931497
impl From<Cargo> for Command {

‎src/bootstrap/doc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,10 @@ impl Step for RustcBook {
766766
if builder.config.verbose() {
767767
cmd.arg("--verbose");
768768
}
769+
// If the lib directories are in an unusual location (changed in
770+
// config.toml), then this needs to explicitly update the dylib search
771+
// path.
772+
builder.add_rustc_lib_path(self.compiler, &mut cmd);
769773
builder.run(&mut cmd);
770774
// Run rustbook/mdbook to generate the HTML pages.
771775
builder.ensure(RustbookSrc {

‎src/bootstrap/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl Step for Rls {
270270
&[],
271271
);
272272

273-
builder.add_rustc_lib_path(compiler, &mut cargo);
273+
cargo.add_rustc_lib_path(builder, compiler);
274274
cargo.arg("--").args(builder.config.cmd.test_args());
275275

276276
if try_run(builder, &mut cargo.into()) {
@@ -328,7 +328,7 @@ impl Step for Rustfmt {
328328
t!(fs::create_dir_all(&dir));
329329
cargo.env("RUSTFMT_TEST_DIR", dir);
330330

331-
builder.add_rustc_lib_path(compiler, &mut cargo);
331+
cargo.add_rustc_lib_path(builder, compiler);
332332

333333
if try_run(builder, &mut cargo.into()) {
334334
builder.save_toolstate("rustfmt", ToolState::TestPass);
@@ -449,7 +449,7 @@ impl Step for Miri {
449449

450450
cargo.arg("--").args(builder.config.cmd.test_args());
451451

452-
builder.add_rustc_lib_path(compiler, &mut cargo);
452+
cargo.add_rustc_lib_path(builder, compiler);
453453

454454
if !try_run(builder, &mut cargo.into()) {
455455
return;
@@ -554,7 +554,7 @@ impl Step for Clippy {
554554

555555
cargo.arg("--").args(builder.config.cmd.test_args());
556556

557-
builder.add_rustc_lib_path(compiler, &mut cargo);
557+
cargo.add_rustc_lib_path(builder, compiler);
558558

559559
builder.run(&mut cargo.into());
560560
}

‎src/ci/docker/host-x86_64/dist-x86_64-linux/build-git.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎src/ci/docker/host-x86_64/dist-x86_64-linux/build-headers.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎src/ci/docker/host-x86_64/dist-x86_64-linux/build-perl.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎src/doc/unstable-book/src/library-features/asm.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,25 @@ The `h` modifier will emit the register name for the high byte of that register
345345

346346
If you use a smaller data type (e.g. `u16`) with an operand and forget the use template modifiers, the compiler will emit a warning and suggest the correct modifier to use.
347347

348+
## Memory address operands
349+
350+
Sometimes assembly instructions require operands passed via memory addresses/memory locations.
351+
You have to manually use the memory address syntax specified by the respectively architectures.
352+
For example, in x86/x86_64 and intel assembly syntax, you should wrap inputs/outputs in `[]`
353+
to indicate they are memory operands:
354+
355+
```rust,allow_fail
356+
# #![feature(asm, llvm_asm)]
357+
# fn load_fpu_control_word(control: u16) {
358+
unsafe {
359+
asm!("fldcw [{}]", in(reg) &control, options(nostack));
360+
361+
// Previously this would have been written with the deprecated `llvm_asm!` like this
362+
llvm_asm!("fldcw $0" :: "m" (control) :: "volatile");
363+
}
364+
# }
365+
```
366+
348367
## Options
349368

350369
By default, an inline assembly block is treated the same way as an external FFI function call with a custom calling convention: it may read/write memory, have observable side effects, etc. However in many cases, it is desirable to give the compiler more information about what the assembly code is actually doing so that it can optimize better.

‎src/doc/unstable-book/src/library-features/llvm-asm.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ specify some extra info about the inline assembly:
159159

160160
Current valid options are:
161161

162-
1. *volatile* - specifying this is analogous to
162+
1. `volatile` - specifying this is analogous to
163163
`__asm__ __volatile__ (...)` in gcc/clang.
164-
2. *alignstack* - certain instructions expect the stack to be
164+
2. `alignstack` - certain instructions expect the stack to be
165165
aligned a certain way (i.e. SSE) and specifying this indicates to
166166
the compiler to insert its usual stack alignment code
167-
3. *intel* - use intel syntax instead of the default AT&T.
167+
3. `intel` - use intel syntax instead of the default AT&T.
168168

169169
```rust
170170
# #![feature(llvm_asm)]

‎src/test/ui/const-generics/cannot-infer-const-args.full.stderr renamed to ‎src/test/ui/const-generics/infer/cannot-infer-const-args.full.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | foo();
55
| ^^^
66
|
7-
= note: unable to infer the value of a const parameter
7+
= note: cannot infer the value of the const parameter `X`
88

99
error: aborting due to previous error
1010

‎src/test/ui/const-generics/cannot-infer-const-args.min.stderr renamed to ‎src/test/ui/const-generics/infer/cannot-infer-const-args.min.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0282]: type annotations needed
44
LL | foo();
55
| ^^^
66
|
7-
= note: unable to infer the value of a const parameter
7+
= note: cannot infer the value of the const parameter `X`
88

99
error: aborting due to previous error
1010

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/method-chain.rs:21:33
3+
|
4+
LL | Foo.bar().bar().bar().bar().baz();
5+
| ^^^
6+
|
7+
= note: cannot infer the value of the const parameter `N`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/method-chain.rs:21:33
3+
|
4+
LL | Foo.bar().bar().bar().bar().baz();
5+
| ^^^
6+
|
7+
= note: cannot infer the value of the const parameter `N`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// revisions: full min
2+
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(full, allow(incomplete_features))]
5+
#![cfg_attr(min, feature(min_const_generics))]
6+
7+
struct Foo;
8+
9+
impl Foo {
10+
fn bar(self) -> Foo {
11+
Foo
12+
}
13+
14+
fn baz<const N: usize>(self) -> Foo {
15+
println!("baz: {}", N);
16+
Foo
17+
}
18+
}
19+
20+
fn main() {
21+
Foo.bar().bar().bar().bar().baz(); //~ ERROR type annotations needed
22+
}

‎src/test/ui/const-generics/uninferred-consts.full.stderr renamed to ‎src/test/ui/const-generics/infer/uninferred-consts.full.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/uninferred-consts.rs:14:5
2+
--> $DIR/uninferred-consts.rs:14:9
33
|
44
LL | Foo.foo();
5-
| ^^^^^^^^^
5+
| ^^^
66
|
7-
= note: unable to infer the value of a const parameter
7+
= note: cannot infer the value of the const parameter `N`
88

99
error: aborting due to previous error
1010

‎src/test/ui/const-generics/uninferred-consts.min.stderr renamed to ‎src/test/ui/const-generics/infer/uninferred-consts.min.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/uninferred-consts.rs:14:5
2+
--> $DIR/uninferred-consts.rs:14:9
33
|
44
LL | Foo.foo();
5-
| ^^^^^^^^^
5+
| ^^^
66
|
7-
= note: unable to infer the value of a const parameter
7+
= note: cannot infer the value of the const parameter `N`
88

99
error: aborting due to previous error
1010

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-rustfix
2+
3+
#[allow(unused)]
4+
use std::fmt::Debug;
5+
// Rustfix should add this, or use `std::fmt::Debug` instead.
6+
7+
#[allow(dead_code)]
8+
struct ConstrainedStruct<X: Copy> {
9+
x: X
10+
}
11+
12+
#[allow(dead_code)]
13+
trait InsufficientlyConstrainedGeneric<X=()> where X: Copy {
14+
fn return_the_constrained_type(&self, x: X) -> ConstrainedStruct<X> {
15+
//~^ ERROR the trait bound `X: Copy` is not satisfied
16+
ConstrainedStruct { x }
17+
}
18+
}
19+
20+
pub fn main() { }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-rustfix
2+
3+
#[allow(unused)]
4+
use std::fmt::Debug;
5+
// Rustfix should add this, or use `std::fmt::Debug` instead.
6+
7+
#[allow(dead_code)]
8+
struct ConstrainedStruct<X: Copy> {
9+
x: X
10+
}
11+
12+
#[allow(dead_code)]
13+
trait InsufficientlyConstrainedGeneric<X=()> {
14+
fn return_the_constrained_type(&self, x: X) -> ConstrainedStruct<X> {
15+
//~^ ERROR the trait bound `X: Copy` is not satisfied
16+
ConstrainedStruct { x }
17+
}
18+
}
19+
20+
pub fn main() { }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `X: Copy` is not satisfied
2+
--> $DIR/trait-impl-bound-suggestions.rs:14:52
3+
|
4+
LL | struct ConstrainedStruct<X: Copy> {
5+
| ---- required by this bound in `ConstrainedStruct`
6+
...
7+
LL | fn return_the_constrained_type(&self, x: X) -> ConstrainedStruct<X> {
8+
| ^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `X`
9+
|
10+
help: consider further restricting type parameter `X`
11+
|
12+
LL | trait InsufficientlyConstrainedGeneric<X=()> where X: Copy {
13+
| ^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.

‎src/test/ui/type/type-check-defaults.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ LL | trait Base<T = String>: Super<T> { }
5656
|
5757
help: consider further restricting type parameter `T`
5858
|
59-
LL | trait Base<T = String>: Super<T>, T: Copy { }
60-
| ^^^^^^^^^
59+
LL | trait Base<T = String>: Super<T> where T: Copy { }
60+
| ^^^^^^^^^^^^^
6161

6262
error[E0277]: cannot add `u8` to `i32`
6363
--> $DIR/type-check-defaults.rs:24:66

‎src/tools/lint-docs/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,12 @@ fn generate_lint_output(
402402
None => {
403403
let rendered: Vec<&str> =
404404
msgs.iter().filter_map(|msg| msg["rendered"].as_str()).collect();
405+
let non_json: Vec<&str> =
406+
stderr.lines().filter(|line| !line.starts_with('{')).collect();
405407
Err(format!(
406-
"did not find lint `{}` in output of example, got:\n{}",
408+
"did not find lint `{}` in output of example, got:\n{}\n{}",
407409
name,
410+
non_json.join("\n"),
408411
rendered.join("\n")
409412
)
410413
.into())

‎src/tools/rust-analyzer

0 commit comments

Comments
 (0)
Please sign in to comment.