Skip to content

Commit fc93e47

Browse files
committed
Auto merge of rust-lang#80960 - Dylan-DPC:rollup-89tri8x, r=Dylan-DPC
Rollup of 10 pull requests Successful merges: - rust-lang#78901 (diagnostics: Note capturing closures can't be coerced to fns) - rust-lang#79588 (Provide more information for HRTB lifetime errors involving closures) - rust-lang#80232 (Remove redundant def_id lookups) - rust-lang#80662 (Added support for i386-unknown-linux-gnu and i486-unknown-linux-gnu) - rust-lang#80736 (use Once instead of Mutex to manage capture resolution) - rust-lang#80796 (Update to LLVM 11.0.1) - rust-lang#80859 (Fix --pretty=expanded with --remap-path-prefix) - rust-lang#80922 (Revert "Auto merge of rust-lang#76896 - spastorino:codegen-inline-fns2) - rust-lang#80924 (Fix rustdoc --test-builder argument parsing) - rust-lang#80935 (Rename `rustc_middle::lint::LevelSource` to `LevelAndSource`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 150d1fe + 5b90fe1 commit fc93e47

Some content is hidden

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

49 files changed

+661
-101
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
[submodule "src/llvm-project"]
3838
path = src/llvm-project
3939
url = https://github.com/rust-lang/llvm-project.git
40-
branch = rustc/11.0-2020-10-12
40+
branch = rustc/11.0-2021-01-05
4141
[submodule "src/doc/embedded-book"]
4242
path = src/doc/embedded-book
4343
url = https://github.com/rust-embedded/book.git

compiler/rustc_driver/src/pretty.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,15 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> {
363363

364364
fn get_source(input: &Input, sess: &Session) -> (String, FileName) {
365365
let src_name = input.source_name();
366-
let src =
367-
String::clone(&sess.source_map().get_source_file(&src_name).unwrap().src.as_ref().unwrap());
366+
let src = String::clone(
367+
&sess
368+
.source_map()
369+
.get_source_file(&src_name)
370+
.expect("get_source_file")
371+
.src
372+
.as_ref()
373+
.expect("src"),
374+
);
368375
(src, src_name)
369376
}
370377

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(super) fn note_and_explain_region(
9898
// uh oh, hope no user ever sees THIS
9999
ty::ReEmpty(ui) => (format!("the empty lifetime in universe {:?}", ui), None),
100100

101-
ty::RePlaceholder(_) => ("any other region".to_string(), None),
101+
ty::RePlaceholder(_) => return,
102102

103103
// FIXME(#13998) RePlaceholder should probably print like
104104
// ReFree rather than dumping Debug output on the user.
@@ -1675,6 +1675,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16751675
self.check_and_note_conflicting_crates(diag, terr);
16761676
self.tcx.note_and_explain_type_err(diag, terr, cause, span, body_owner_def_id.to_def_id());
16771677

1678+
if let Some(ValuePairs::PolyTraitRefs(exp_found)) = values {
1679+
if let ty::Closure(def_id, _) = exp_found.expected.skip_binder().self_ty().kind() {
1680+
if let Some(def_id) = def_id.as_local() {
1681+
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
1682+
let span = self.tcx.hir().span(hir_id);
1683+
diag.span_note(span, "this closure does not fulfill the lifetime requirements");
1684+
}
1685+
}
1686+
}
1687+
16781688
// It reads better to have the error origin as the final
16791689
// thing.
16801690
self.note_error_origin(diag, cause, exp_found);

compiler/rustc_infer/src/infer/error_reporting/note.rs

+53-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::infer::error_reporting::{note_and_explain_region, ObligationCauseExt};
22
use crate::infer::{self, InferCtxt, SubregionOrigin};
33
use rustc_errors::{struct_span_err, DiagnosticBuilder};
4+
use rustc_middle::traits::ObligationCauseCode;
45
use rustc_middle::ty::error::TypeError;
56
use rustc_middle::ty::{self, Region};
67

@@ -107,14 +108,37 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
107108
infer::Subtype(box trace) => {
108109
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
109110
let mut err = self.report_and_explain_type_error(trace, &terr);
110-
note_and_explain_region(self.tcx, &mut err, "", sup, "...");
111-
note_and_explain_region(
112-
self.tcx,
113-
&mut err,
114-
"...does not necessarily outlive ",
115-
sub,
116-
"",
117-
);
111+
match (sub, sup) {
112+
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
113+
(ty::RePlaceholder(_), _) => {
114+
note_and_explain_region(
115+
self.tcx,
116+
&mut err,
117+
"",
118+
sup,
119+
" doesn't meet the lifetime requirements",
120+
);
121+
}
122+
(_, ty::RePlaceholder(_)) => {
123+
note_and_explain_region(
124+
self.tcx,
125+
&mut err,
126+
"the required lifetime does not necessarily outlive ",
127+
sub,
128+
"",
129+
);
130+
}
131+
_ => {
132+
note_and_explain_region(self.tcx, &mut err, "", sup, "...");
133+
note_and_explain_region(
134+
self.tcx,
135+
&mut err,
136+
"...does not necessarily outlive ",
137+
sub,
138+
"",
139+
);
140+
}
141+
}
118142
err
119143
}
120144
infer::Reborrow(span) => {
@@ -286,13 +310,31 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
286310
sup: Region<'tcx>,
287311
) -> DiagnosticBuilder<'tcx> {
288312
// I can't think how to do better than this right now. -nikomatsakis
313+
debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure");
289314
match placeholder_origin {
315+
infer::Subtype(box ref trace)
316+
if matches!(
317+
&trace.cause.code.peel_derives(),
318+
ObligationCauseCode::BindingObligation(..)
319+
) =>
320+
{
321+
// Hack to get around the borrow checker because trace.cause has an `Rc`.
322+
if let ObligationCauseCode::BindingObligation(_, span) =
323+
&trace.cause.code.peel_derives()
324+
{
325+
let span = *span;
326+
let mut err = self.report_concrete_failure(placeholder_origin, sub, sup);
327+
err.span_note(span, "the lifetime requirement is introduced here");
328+
err
329+
} else {
330+
unreachable!()
331+
}
332+
}
290333
infer::Subtype(box trace) => {
291334
let terr = TypeError::RegionsPlaceholderMismatch;
292-
self.report_and_explain_type_error(trace, &terr)
335+
return self.report_and_explain_type_error(trace, &terr);
293336
}
294-
295-
_ => self.report_concrete_failure(placeholder_origin, sub, sup),
337+
_ => return self.report_concrete_failure(placeholder_origin, sub, sup),
296338
}
297339
}
298340
}

compiler/rustc_lint/src/levels.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir as hir;
1010
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
1111
use rustc_hir::{intravisit, HirId};
1212
use rustc_middle::hir::map::Map;
13-
use rustc_middle::lint::LevelSource;
13+
use rustc_middle::lint::LevelAndSource;
1414
use rustc_middle::lint::LintDiagnosticBuilder;
1515
use rustc_middle::lint::{
1616
struct_lint_level, LintLevelMap, LintLevelSets, LintLevelSource, LintSet,
@@ -106,9 +106,9 @@ impl<'s> LintLevelsBuilder<'s> {
106106
/// diagnostic with no change to `specs`.
107107
fn insert_spec(
108108
&mut self,
109-
specs: &mut FxHashMap<LintId, LevelSource>,
109+
specs: &mut FxHashMap<LintId, LevelAndSource>,
110110
id: LintId,
111-
(level, src): LevelSource,
111+
(level, src): LevelAndSource,
112112
) {
113113
// Setting to a non-forbid level is an error if the lint previously had
114114
// a forbid level. Note that this is not necessarily true even with a

compiler/rustc_middle/src/lint.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl LintLevelSource {
4646
}
4747

4848
/// A tuple of a lint level and its source.
49-
pub type LevelSource = (Level, LintLevelSource);
49+
pub type LevelAndSource = (Level, LintLevelSource);
5050

5151
pub struct LintLevelSets {
5252
pub list: Vec<LintSet>,
@@ -57,11 +57,11 @@ pub enum LintSet {
5757
CommandLine {
5858
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
5959
// flag.
60-
specs: FxHashMap<LintId, LevelSource>,
60+
specs: FxHashMap<LintId, LevelAndSource>,
6161
},
6262

6363
Node {
64-
specs: FxHashMap<LintId, LevelSource>,
64+
specs: FxHashMap<LintId, LevelAndSource>,
6565
parent: u32,
6666
},
6767
}
@@ -75,9 +75,9 @@ impl LintLevelSets {
7575
&self,
7676
lint: &'static Lint,
7777
idx: u32,
78-
aux: Option<&FxHashMap<LintId, LevelSource>>,
78+
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
7979
sess: &Session,
80-
) -> LevelSource {
80+
) -> LevelAndSource {
8181
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
8282

8383
// If `level` is none then we actually assume the default level for this
@@ -113,7 +113,7 @@ impl LintLevelSets {
113113
&self,
114114
id: LintId,
115115
mut idx: u32,
116-
aux: Option<&FxHashMap<LintId, LevelSource>>,
116+
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
117117
) -> (Option<Level>, LintLevelSource) {
118118
if let Some(specs) = aux {
119119
if let Some(&(level, src)) = specs.get(&id) {
@@ -157,7 +157,7 @@ impl LintLevelMap {
157157
lint: &'static Lint,
158158
id: HirId,
159159
session: &Session,
160-
) -> Option<LevelSource> {
160+
) -> Option<LevelAndSource> {
161161
self.id_to_set.get(&id).map(|idx| self.sets.get_lint_level(lint, *idx, None, session))
162162
}
163163
}

compiler/rustc_middle/src/mir/mono.rs

+22-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::dep_graph::{dep_constructor, DepNode, WorkProduct, WorkProductId};
22
use crate::ich::{NodeIdHashingMode, StableHashingContext};
33
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
4+
use rustc_attr::InlineAttr;
45
use rustc_data_structures::base_n;
56
use rustc_data_structures::fingerprint::Fingerprint;
67
use rustc_data_structures::fx::FxHashMap;
@@ -78,6 +79,14 @@ impl<'tcx> MonoItem<'tcx> {
7879
}
7980

8081
pub fn instantiation_mode(&self, tcx: TyCtxt<'tcx>) -> InstantiationMode {
82+
let generate_cgu_internal_copies = tcx
83+
.sess
84+
.opts
85+
.debugging_opts
86+
.inline_in_all_cgus
87+
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
88+
&& !tcx.sess.link_dead_code();
89+
8190
match *self {
8291
MonoItem::Fn(ref instance) => {
8392
let entry_def_id = tcx.entry_fn(LOCAL_CRATE).map(|(id, _)| id);
@@ -90,26 +99,21 @@ impl<'tcx> MonoItem<'tcx> {
9099
return InstantiationMode::GloballyShared { may_conflict: false };
91100
}
92101

93-
let generate_cgu_internal_copies = tcx
94-
.sess
95-
.opts
96-
.debugging_opts
97-
.inline_in_all_cgus
98-
.unwrap_or_else(|| tcx.sess.opts.optimize != OptLevel::No)
99-
&& !tcx.sess.link_dead_code();
100-
101102
// At this point we don't have explicit linkage and we're an
102-
// inlined function. If we should generate local copies for each CGU,
103-
// then return `LocalCopy`, otherwise we'll just generate one copy
104-
// and share it with all CGUs in this crate.
103+
// inlined function. If we're inlining into all CGUs then we'll
104+
// be creating a local copy per CGU.
105105
if generate_cgu_internal_copies {
106-
InstantiationMode::LocalCopy
107-
} else {
108-
// Finally, if we've reached this point, then we should optimize for
109-
// compilation speed. In that regard, we will ignore any `#[inline]`
110-
// annotations on the function and simply codegen it as usual. This could
111-
// conflict with upstream crates as it could be an exported symbol.
112-
InstantiationMode::GloballyShared { may_conflict: true }
106+
return InstantiationMode::LocalCopy;
107+
}
108+
109+
// Finally, if this is `#[inline(always)]` we're sure to respect
110+
// that with an inline copy per CGU, but otherwise we'll be
111+
// creating one copy of this `#[inline]` function which may
112+
// conflict with upstream crates as it could be an exported
113+
// symbol.
114+
match tcx.codegen_fn_attrs(instance.def_id()).inline {
115+
InlineAttr::Always => InstantiationMode::LocalCopy,
116+
_ => InstantiationMode::GloballyShared { may_conflict: true },
113117
}
114118
}
115119
MonoItem::Static(..) | MonoItem::GlobalAsm(..) => {

compiler/rustc_middle/src/ty/consts.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ impl<'tcx> Const<'tcx> {
9292
let item_id = tcx.hir().get_parent_node(hir_id);
9393
let item_def_id = tcx.hir().local_def_id(item_id);
9494
let generics = tcx.generics_of(item_def_id.to_def_id());
95-
let index =
96-
generics.param_def_id_to_index[&tcx.hir().local_def_id(hir_id).to_def_id()];
95+
let index = generics.param_def_id_to_index[&def_id];
9796
let name = tcx.hir().name(hir_id);
9897
ty::ConstKind::Param(ty::ParamConst::new(index, name))
9998
}

compiler/rustc_mir_build/src/thir/cx/expr.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,7 @@ fn convert_path_expr<'a, 'tcx>(
813813
let item_id = cx.tcx.hir().get_parent_node(hir_id);
814814
let item_def_id = cx.tcx.hir().local_def_id(item_id);
815815
let generics = cx.tcx.generics_of(item_def_id);
816-
let local_def_id = cx.tcx.hir().local_def_id(hir_id);
817-
let index = generics.param_def_id_to_index[&local_def_id.to_def_id()];
816+
let index = generics.param_def_id_to_index[&def_id];
818817
let name = cx.tcx.hir().name(hir_id);
819818
let val = ty::ConstKind::Param(ty::ParamConst::new(index, name));
820819
ExprKind::Literal {

compiler/rustc_span/src/source_map.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,10 @@ impl SourceMap {
872872
}
873873

874874
pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>> {
875+
// Remap filename before lookup
876+
let filename = self.path_mapping().map_filename_prefix(filename).0;
875877
for sf in self.files.borrow().source_files.iter() {
876-
if *filename == sf.name {
878+
if filename == sf.name {
877879
return Some(sf.clone());
878880
}
879881
}
@@ -1041,4 +1043,15 @@ impl FilePathMapping {
10411043

10421044
(path, false)
10431045
}
1046+
1047+
fn map_filename_prefix(&self, file: &FileName) -> (FileName, bool) {
1048+
match file {
1049+
FileName::Real(realfile) => {
1050+
let path = realfile.local_path();
1051+
let (path, mapped) = self.map_prefix(path.to_path_buf());
1052+
(FileName::Real(RealFileName::Named(path)), mapped)
1053+
}
1054+
other => (other.clone(), false),
1055+
}
1056+
}
10441057
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use crate::spec::Target;
2+
3+
pub fn target() -> Target {
4+
let mut base = super::i686_unknown_linux_gnu::target();
5+
base.cpu = "i386".to_string();
6+
base.llvm_target = "i386-unknown-linux-gnu".to_string();
7+
base
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use crate::spec::Target;
2+
3+
pub fn target() -> Target {
4+
let mut base = super::i686_unknown_linux_gnu::target();
5+
base.cpu = "i486".to_string();
6+
base.llvm_target = "i486-unknown-linux-gnu".to_string();
7+
base
8+
}

compiler/rustc_typeck/src/check/demand.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3232
if self.suggest_calling_boxed_future_when_appropriate(err, expr, expected, expr_ty) {
3333
return;
3434
}
35+
self.suggest_no_capture_closure(err, expected, expr_ty);
3536
self.suggest_boxing_when_appropriate(err, expr, expected, expr_ty);
3637
self.suggest_missing_parentheses(err, expr);
3738
self.note_need_for_fn_pointer(err, expected, expr_ty);

0 commit comments

Comments
 (0)