Auto merge of #72975 - Dylan-DPC:rollup-6zvco5x, r=Dylan-DPC

Rollup of 6 pull requests

Successful merges:

 - #72718 (Add regression test for #72554)
 - #72782 (rustc_target: Remove `pre_link_args_crt`)
 - #72923 (Improve E0433, so that it suggests missing imports)
 - #72950 (fix `AdtDef` docs)
 - #72951 (Add Camelid per request)
 - #72964 (Bump libc dependency to latest version (0.2.71))

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-06-04 10:17:38 +00:00
commit 2a5cbb0e42
19 changed files with 253 additions and 71 deletions

View File

@ -44,6 +44,7 @@ Brian Anderson <banderson@mozilla.com> <andersrb@gmail.com>
Brian Anderson <banderson@mozilla.com> <banderson@mozilla.org>
Brian Dawn <brian.t.dawn@gmail.com>
Brian Leibig <brian@brianleibig.com> Brian Leibig <brian.leibig@gmail.com>
Camelid <camelidcamel@gmail.com> <37223377+camelid@users.noreply.github.com>
Carl-Anton Ingmarsson <mail@carlanton.se> <ca.ingmarsson@gmail.com>
Carol (Nichols || Goulding) <carol.nichols@gmail.com> <193874+carols10cents@users.noreply.github.com>
Carol (Nichols || Goulding) <carol.nichols@gmail.com> <carol.nichols@gmail.com>

View File

@ -1853,9 +1853,9 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
[[package]]
name = "libc"
version = "0.2.69"
version = "0.2.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49"
dependencies = [
"rustc-std-workspace-core",
]

View File

@ -1253,20 +1253,10 @@ fn add_post_link_objects(
/// Add arbitrary "pre-link" args defined by the target spec or from command line.
/// FIXME: Determine where exactly these args need to be inserted.
fn add_pre_link_args(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
crate_type: CrateType,
) {
fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) {
cmd.args(args);
}
if let Some(args) = sess.target.target.options.pre_link_args_crt.get(&flavor) {
if sess.crt_static(Some(crate_type)) {
cmd.args(args);
}
}
cmd.args(&sess.opts.debugging_opts.pre_link_args);
}
@ -1502,7 +1492,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
let crt_objects_fallback = crt_objects_fallback(sess, crate_type);
// NO-OPT-OUT, OBJECT-FILES-MAYBE, CUSTOMIZATION-POINT
add_pre_link_args(cmd, sess, flavor, crate_type);
add_pre_link_args(cmd, sess, flavor);
// NO-OPT-OUT
add_link_script(cmd, sess, tmpdir, crate_type);

View File

@ -315,6 +315,21 @@ impl<'a> Linker for GccLinker<'a> {
self.build_dylib(out_filename);
}
}
// VxWorks compiler driver introduced `--static-crt` flag specifically for rustc,
// it switches linking for libc and similar system libraries to static without using
// any `#[link]` attributes in the `libc` crate, see #72782 for details.
// FIXME: Switch to using `#[link]` attributes in the `libc` crate
// similarly to other targets.
if self.sess.target.target.target_os == "vxworks"
&& matches!(
output_kind,
LinkOutputKind::StaticNoPicExe
| LinkOutputKind::StaticPicExe
| LinkOutputKind::StaticDylib
)
{
self.cmd.arg("--static-crt");
}
}
fn link_dylib(&mut self, lib: Symbol) {

View File

@ -1846,7 +1846,7 @@ pub struct FieldDef {
/// The definition of a user-defined type, e.g., a `struct`, `enum`, or `union`.
///
/// These are all interned (by `intern_adt_def`) into the `adt_defs` table.
/// These are all interned (by `alloc_adt_def`) into the global arena.
///
/// The initialism *ADT* stands for an [*algebraic data type (ADT)*][adt].
/// This is slightly wrong because `union`s are not ADTs.

View File

@ -1475,7 +1475,7 @@ crate fn show_candidates(
// This is `None` if all placement locations are inside expansions
use_placement_span: Option<Span>,
candidates: &[ImportSuggestion],
better: bool,
instead: bool,
found_use: bool,
) {
if candidates.is_empty() {
@ -1486,6 +1486,7 @@ crate fn show_candidates(
// by iterating through a hash map, so make sure they are ordered:
let mut path_strings: Vec<_> =
candidates.iter().map(|c| path_names_to_string(&c.path)).collect();
path_strings.sort();
path_strings.dedup();
@ -1494,8 +1495,9 @@ crate fn show_candidates(
} else {
("one of these", "items")
};
let instead = if better { " instead" } else { "" };
let msg = format!("consider importing {} {}{}", determiner, kind, instead);
let instead = if instead { " instead" } else { "" };
let mut msg = format!("consider importing {} {}{}", determiner, kind, instead);
if let Some(span) = use_placement_span {
for candidate in &mut path_strings {
@ -1507,12 +1509,13 @@ crate fn show_candidates(
err.span_suggestions(span, &msg, path_strings.into_iter(), Applicability::Unspecified);
} else {
let mut msg = msg;
msg.push(':');
for candidate in path_strings {
msg.push('\n');
msg.push_str(&candidate);
}
err.note(&msg);
}
}

View File

@ -29,8 +29,9 @@ use rustc_span::Span;
use smallvec::{smallvec, SmallVec};
use log::debug;
use rustc_span::source_map::{respan, Spanned};
use std::collections::BTreeSet;
use std::mem::replace;
use std::mem::{replace, take};
mod diagnostics;
crate mod lifetimes;
@ -234,6 +235,13 @@ impl<'a> PathSource<'a> {
}
}
fn is_call(self) -> bool {
match self {
PathSource::Expr(Some(&Expr { kind: ExprKind::Call(..), .. })) => true,
_ => false,
}
}
crate fn is_expected(self, res: Res) -> bool {
match self {
PathSource::Type => match res {
@ -1620,14 +1628,83 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
let report_errors = |this: &mut Self, res: Option<Res>| {
let (err, candidates) = this.smart_resolve_report_errors(path, span, source, res);
let def_id = this.parent_scope.module.normal_ancestor_id;
let better = res.is_some();
let instead = res.is_some();
let suggestion =
if res.is_none() { this.report_missing_type_error(path) } else { None };
this.r.use_injections.push(UseError { err, candidates, def_id, better, suggestion });
this.r.use_injections.push(UseError { err, candidates, def_id, instead, suggestion });
PartialRes::new(Res::Err)
};
// For paths originating from calls (like in `HashMap::new()`), tries
// to enrich the plain `failed to resolve: ...` message with hints
// about possible missing imports.
//
// Similar thing, for types, happens in `report_errors` above.
let report_errors_for_call = |this: &mut Self, parent_err: Spanned<ResolutionError<'a>>| {
if !source.is_call() {
return Some(parent_err);
}
// Before we start looking for candidates, we have to get our hands
// on the type user is trying to perform invocation on; basically:
// we're transforming `HashMap::new` into just `HashMap`
let path = if let Some((_, path)) = path.split_last() {
path
} else {
return Some(parent_err);
};
let (mut err, candidates) =
this.smart_resolve_report_errors(path, span, PathSource::Type, None);
if candidates.is_empty() {
err.cancel();
return Some(parent_err);
}
// There are two different error messages user might receive at
// this point:
// - E0412 cannot find type `{}` in this scope
// - E0433 failed to resolve: use of undeclared type or module `{}`
//
// The first one is emitted for paths in type-position, and the
// latter one - for paths in expression-position.
//
// Thus (since we're in expression-position at this point), not to
// confuse the user, we want to keep the *message* from E0432 (so
// `parent_err`), but we want *hints* from E0412 (so `err`).
//
// And that's what happens below - we're just mixing both messages
// into a single one.
let mut parent_err = this.r.into_struct_error(parent_err.span, parent_err.node);
parent_err.cancel();
err.message = take(&mut parent_err.message);
err.code = take(&mut parent_err.code);
err.children = take(&mut parent_err.children);
drop(parent_err);
let def_id = this.parent_scope.module.normal_ancestor_id;
this.r.use_injections.push(UseError {
err,
candidates,
def_id,
instead: false,
suggestion: None,
});
// We don't return `Some(parent_err)` here, because the error will
// be already printed as part of the `use` injections
None
};
let partial_res = match self.resolve_qpath_anywhere(
id,
qself,
@ -1637,14 +1714,15 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
source.defer_to_typeck(),
crate_lint,
) {
Some(partial_res) if partial_res.unresolved_segments() == 0 => {
Ok(Some(partial_res)) if partial_res.unresolved_segments() == 0 => {
if is_expected(partial_res.base_res()) || partial_res.base_res() == Res::Err {
partial_res
} else {
report_errors(self, Some(partial_res.base_res()))
}
}
Some(partial_res) if source.defer_to_typeck() => {
Ok(Some(partial_res)) if source.defer_to_typeck() => {
// Not fully resolved associated item `T::A::B` or `<T as Tr>::A::B`
// or `<T>::A::B`. If `B` should be resolved in value namespace then
// it needs to be added to the trait map.
@ -1655,25 +1733,34 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}
let mut std_path = vec![Segment::from_ident(Ident::with_dummy_span(sym::std))];
std_path.extend(path);
if self.r.primitive_type_table.primitive_types.contains_key(&path[0].ident.name) {
let cl = CrateLint::No;
let ns = Some(ns);
if let PathResult::Module(_) | PathResult::NonModule(_) =
self.resolve_path(&std_path, ns, false, span, cl)
self.resolve_path(&std_path, Some(ns), false, span, CrateLint::No)
{
// check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
let item_span =
path.iter().last().map(|segment| segment.ident.span).unwrap_or(span);
debug!("accessed item from `std` submodule as a bare type {:?}", std_path);
let mut hm = self.r.session.confused_type_with_std_module.borrow_mut();
hm.insert(item_span, span);
// In some places (E0223) we only have access to the full path
hm.insert(span, span);
}
}
partial_res
}
Err(err) => {
if let Some(err) = report_errors_for_call(self, err) {
self.r.report_error(err.span, err.node);
}
PartialRes::new(Res::Err)
}
_ => report_errors(self, None),
};
@ -1682,6 +1769,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
// Avoid recording definition of `A::B` in `<T as A>::B::C`.
self.r.record_partial_res(id, partial_res);
}
partial_res
}
@ -1711,17 +1799,16 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
span: Span,
defer_to_typeck: bool,
crate_lint: CrateLint,
) -> Option<PartialRes> {
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
let mut fin_res = None;
for (i, ns) in [primary_ns, TypeNS, ValueNS].iter().cloned().enumerate() {
if i == 0 || ns != primary_ns {
match self.resolve_qpath(id, qself, path, ns, span, crate_lint) {
// If defer_to_typeck, then resolution > no resolution,
// otherwise full resolution > partial resolution > no resolution.
match self.resolve_qpath(id, qself, path, ns, span, crate_lint)? {
Some(partial_res)
if partial_res.unresolved_segments() == 0 || defer_to_typeck =>
{
return Some(partial_res);
return Ok(Some(partial_res));
}
partial_res => {
if fin_res.is_none() {
@ -1732,19 +1819,19 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}
}
// `MacroNS`
assert!(primary_ns != MacroNS);
if qself.is_none() {
let path_seg = |seg: &Segment| PathSegment::from_ident(seg.ident);
let path = Path { segments: path.iter().map(path_seg).collect(), span };
if let Ok((_, res)) =
self.r.resolve_macro_path(&path, None, &self.parent_scope, false, false)
{
return Some(PartialRes::new(res));
return Ok(Some(PartialRes::new(res)));
}
}
fin_res
Ok(fin_res)
}
/// Handles paths that may refer to associated items.
@ -1756,7 +1843,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
ns: Namespace,
span: Span,
crate_lint: CrateLint,
) -> Option<PartialRes> {
) -> Result<Option<PartialRes>, Spanned<ResolutionError<'a>>> {
debug!(
"resolve_qpath(id={:?}, qself={:?}, path={:?}, ns={:?}, span={:?})",
id, qself, path, ns, span,
@ -1767,10 +1854,10 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
// This is a case like `<T>::B`, where there is no
// trait to resolve. In that case, we leave the `B`
// segment to be resolved by type-check.
return Some(PartialRes::with_unresolved_segments(
return Ok(Some(PartialRes::with_unresolved_segments(
Res::Def(DefKind::Mod, DefId::local(CRATE_DEF_INDEX)),
path.len(),
));
)));
}
// Make sure `A::B` in `<T as A::B>::C` is a trait item.
@ -1800,10 +1887,10 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
// The remaining segments (the `C` in our example) will
// have to be resolved by type-check, since that requires doing
// trait resolution.
return Some(PartialRes::with_unresolved_segments(
return Ok(Some(PartialRes::with_unresolved_segments(
partial_res.base_res(),
partial_res.unresolved_segments() + path.len() - qself.position - 1,
));
)));
}
let result = match self.resolve_path(&path, Some(ns), true, span, crate_lint) {
@ -1838,11 +1925,10 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
PartialRes::new(module.res().unwrap())
}
PathResult::Failed { is_error_from_last_segment: false, span, label, suggestion } => {
self.r.report_error(span, ResolutionError::FailedToResolve { label, suggestion });
PartialRes::new(Res::Err)
return Err(respan(span, ResolutionError::FailedToResolve { label, suggestion }));
}
PathResult::Module(..) | PathResult::Failed { .. } => return None,
PathResult::Indeterminate => bug!("indetermined path result in resolve_qpath"),
PathResult::Module(..) | PathResult::Failed { .. } => return Ok(None),
PathResult::Indeterminate => bug!("indeterminate path result in resolve_qpath"),
};
if path.len() > 1
@ -1862,7 +1948,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
module.res().unwrap()
}
_ => return Some(result),
_ => return Ok(Some(result)),
}
};
if result.base_res() == unqualified_result {
@ -1871,7 +1957,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
}
}
Some(result)
Ok(Some(result))
}
fn with_resolved_label(&mut self, label: Option<Label>, id: NodeId, f: impl FnOnce(&mut Self)) {

View File

@ -618,13 +618,13 @@ struct PrivacyError<'a> {
struct UseError<'a> {
err: DiagnosticBuilder<'a>,
/// Attach `use` statements for these candidates.
/// Candidates which user could `use` to access the missing type.
candidates: Vec<ImportSuggestion>,
/// The `NodeId` of the module to place the use-statements in.
/// The `DefId` of the module to place the use-statements in.
def_id: DefId,
/// Whether the diagnostic should state that it's "better".
better: bool,
/// Extra free form suggestion. Currently used to suggest new type parameter.
/// Whether the diagnostic should say "instead" (as in `consider importing ... instead`).
instead: bool,
/// Extra free-form suggestion.
suggestion: Option<(Span, &'static str, String, Applicability)>,
}
@ -2577,12 +2577,12 @@ impl<'a> Resolver<'a> {
}
fn report_with_use_injections(&mut self, krate: &Crate) {
for UseError { mut err, candidates, def_id, better, suggestion } in
for UseError { mut err, candidates, def_id, instead, suggestion } in
self.use_injections.drain(..)
{
let (span, found_use) = UsePlacementFinder::check(&self.definitions, krate, def_id);
if !candidates.is_empty() {
diagnostics::show_candidates(&mut err, span, &candidates, better, found_use);
diagnostics::show_candidates(&mut err, span, &candidates, instead, found_use);
} else if let Some((span, msg, sugg, appl)) = suggestion {
err.span_suggestion(span, msg, sugg, appl);
}

View File

@ -733,8 +733,7 @@ pub struct TargetOptions {
pub lld_flavor: LldFlavor,
/// Linker arguments that are passed *before* any user-defined libraries.
pub pre_link_args: LinkArgs, // ... unconditionally
pub pre_link_args_crt: LinkArgs, // ... when linking with a bundled crt
pub pre_link_args: LinkArgs,
/// Objects to link before and after all other object code.
pub pre_link_objects: CrtObjects,
pub post_link_objects: CrtObjects,
@ -997,7 +996,6 @@ impl Default for TargetOptions {
linker: option_env!("CFG_DEFAULT_LINKER").map(|s| s.to_string()),
lld_flavor: LldFlavor::Ld,
pre_link_args: LinkArgs::new(),
pre_link_args_crt: LinkArgs::new(),
post_link_args: LinkArgs::new(),
link_script: None,
asm_args: Vec::new(),
@ -1397,7 +1395,6 @@ impl Target {
key!(post_link_objects_fallback, link_objects);
key!(crt_objects_fallback, crt_objects_fallback)?;
key!(pre_link_args, link_args);
key!(pre_link_args_crt, link_args);
key!(late_link_args, link_args);
key!(late_link_args_dynamic, link_args);
key!(late_link_args_static, link_args);
@ -1629,7 +1626,6 @@ impl ToJson for Target {
target_option_val!(post_link_objects_fallback);
target_option_val!(crt_objects_fallback);
target_option_val!(link_args - pre_link_args);
target_option_val!(link_args - pre_link_args_crt);
target_option_val!(link_args - late_link_args);
target_option_val!(link_args - late_link_args_dynamic);
target_option_val!(link_args - late_link_args_static);

View File

@ -25,7 +25,6 @@ impl Target {
);
for args in &[
&self.options.pre_link_args,
&self.options.pre_link_args_crt,
&self.options.late_link_args,
&self.options.late_link_args_dynamic,
&self.options.late_link_args_static,

View File

@ -1,8 +1,6 @@
use crate::spec::{LinkArgs, LinkerFlavor, TargetOptions};
pub fn opts() -> TargetOptions {
let mut args_crt = LinkArgs::new();
args_crt.insert(LinkerFlavor::Gcc, vec!["--static-crt".to_string()]);
let mut args = LinkArgs::new();
args.insert(
LinkerFlavor::Gcc,
@ -29,7 +27,6 @@ pub fn opts() -> TargetOptions {
pre_link_args: args,
position_independent_executables: false,
has_elf_tls: true,
pre_link_args_crt: args_crt,
crt_static_default: true,
crt_static_respected: true,
crt_static_allows_dylibs: true,

View File

@ -2,7 +2,14 @@ error[E0433]: failed to resolve: use of undeclared type or module `HashMap`
--> $DIR/issue-31997-1.rs:20:19
|
LL | let mut map = HashMap::new();
| ^^^^^^^ use of undeclared type or module `HashMap`
| ^^^^^^^ not found in this scope
|
help: consider importing one of these items
|
LL | use std::collections::HashMap;
|
LL | use std::collections::hash_map::HashMap;
|
error: aborting due to previous error

View File

@ -1,3 +1,3 @@
fn main () {
let map = HashMap::new(); //~ ERROR E0433
let map = NonExistingMap::new(); //~ ERROR E0433
}

View File

@ -1,8 +1,8 @@
error[E0433]: failed to resolve: use of undeclared type or module `HashMap`
error[E0433]: failed to resolve: use of undeclared type or module `NonExistingMap`
--> $DIR/E0433.rs:2:15
|
LL | let map = HashMap::new();
| ^^^^^^^ use of undeclared type or module `HashMap`
LL | let map = NonExistingMap::new();
| ^^^^^^^^^^^^^^ use of undeclared type or module `NonExistingMap`
error: aborting due to previous error

View File

@ -13,9 +13,15 @@ LL | fn f() { ::bar::m!(); }
| ------------ in this macro invocation
...
LL | Vec::new();
| ^^^ use of undeclared type or module `Vec`
| ^^^ not found in this scope
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
|
LL | use std::prelude::v1::Vec;
|
LL | use std::vec::Vec;
|
error[E0599]: no method named `clone` found for unit type `()` in the current scope
--> $DIR/no_implicit_prelude.rs:12:12

View File

@ -0,0 +1,20 @@
use std::collections::BTreeSet;
#[derive(Hash)]
pub enum ElemDerived { //~ ERROR recursive type `ElemDerived` has infinite size
A(ElemDerived)
}
pub enum Elem {
Derived(ElemDerived)
}
pub struct Set(BTreeSet<Elem>);
impl Set {
pub fn into_iter(self) -> impl Iterator<Item = Elem> {
self.0.into_iter()
}
}
fn main() {}

View File

@ -0,0 +1,13 @@
error[E0072]: recursive type `ElemDerived` has infinite size
--> $DIR/issue-72554.rs:4:1
|
LL | pub enum ElemDerived {
| ^^^^^^^^^^^^^^^^^^^^ recursive type has infinite size
LL | A(ElemDerived)
| ----------- recursive without indirection
|
= help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `ElemDerived` representable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0072`.

View File

@ -0,0 +1,7 @@
fn main() {
let x1 = HashMap::new(); //~ ERROR failed to resolve
let x2 = GooMap::new(); //~ ERROR failed to resolve
let y1: HashMap; //~ ERROR cannot find type
let y2: GooMap; //~ ERROR cannot find type
}

View File

@ -0,0 +1,42 @@
error[E0433]: failed to resolve: use of undeclared type or module `GooMap`
--> $DIR/use_suggestion.rs:3:14
|
LL | let x2 = GooMap::new();
| ^^^^^^ use of undeclared type or module `GooMap`
error[E0433]: failed to resolve: use of undeclared type or module `HashMap`
--> $DIR/use_suggestion.rs:2:14
|
LL | let x1 = HashMap::new();
| ^^^^^^^ not found in this scope
|
help: consider importing one of these items
|
LL | use std::collections::HashMap;
|
LL | use std::collections::hash_map::HashMap;
|
error[E0412]: cannot find type `HashMap` in this scope
--> $DIR/use_suggestion.rs:5:13
|
LL | let y1: HashMap;
| ^^^^^^^ not found in this scope
|
help: consider importing one of these items
|
LL | use std::collections::HashMap;
|
LL | use std::collections::hash_map::HashMap;
|
error[E0412]: cannot find type `GooMap` in this scope
--> $DIR/use_suggestion.rs:6:13
|
LL | let y2: GooMap;
| ^^^^^^ not found in this scope
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0412, E0433.
For more information about an error, try `rustc --explain E0412`.