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 11 pull requests #62840

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
503ceda
Test that maplike FromIter satisfies uniqueness
nhynes Jul 16, 2019
f22bc2d
Suggest trait bound on type parameter when it is unconstrained
estebank Jul 17, 2019
48b6069
Fix typo in src/libstd/net/udp.rs doc comment
Indy2222 Jul 18, 2019
886fb21
normalize use of backticks in compiler messages for libcore/ptr
Jul 18, 2019
33452b0
warn about deprecated-in-future in most of libstd
RalfJung Jul 17, 2019
13ed0cf
do not use mem::uninitialized in std::io
RalfJung Jul 17, 2019
7c1e405
ONCE_INIT is deprecated-in-future only for bootstrap
RalfJung Jul 17, 2019
469b7a9
rustc_typeck: improve diagnostics for _ const/static declarations
lundibundi Jul 18, 2019
c6735a6
fixup! rustc_typeck: improve diagnostics for _ const/static declarations
lundibundi Jul 19, 2019
10d4159
Revert "Disable stack probing for gnux32."
crlf0710 Jul 19, 2019
f5b2859
Handle more cases of typos misinterpreted as type ascription
estebank Jul 17, 2019
9dbe2e7
review comments
estebank Jul 19, 2019
b361864
fixup! rustc_typeck: improve diagnostics for _ const/static declarations
lundibundi Jul 19, 2019
c1b4d62
rustc: Compile the `fmt_macros` crate as an rlib
alexcrichton Jul 19, 2019
c6e027d
fixup! rustc_typeck: improve diagnostics for _ const/static declarations
lundibundi Jul 19, 2019
19a848d
normalize use of backticks in compiler messages for librustc_metadata
Jul 19, 2019
60ca55c
normalize use of backticks in compiler messages for librustc_incremental
Jul 20, 2019
eb1f631
Rollup merge of #62709 - nhynes:test-maplike-fromiter, r=cuviper
Centril Jul 21, 2019
9182b70
Rollup merge of #62746 - RalfJung:deprecated, r=KodrAus
Centril Jul 21, 2019
785acaf
Rollup merge of #62772 - estebank:trait-bound, r=matthewjasper
Centril Jul 21, 2019
c8c401a
Rollup merge of #62787 - Indy2222:master, r=Mark-Simulacrum
Centril Jul 21, 2019
8d91abc
Rollup merge of #62788 - fakenine:normalize_use_of_backticks_compiler…
Centril Jul 21, 2019
38532ae
Rollup merge of #62791 - estebank:type-ascription, r=petrochenkov
Centril Jul 21, 2019
a82c60b
Rollup merge of #62804 - lundibundi:help-infer-const-static, r=eddyb
Centril Jul 21, 2019
cc8ae62
Rollup merge of #62808 - crlf0710:gnux32_stack_probe, r=nikic
Centril Jul 21, 2019
a343f7d
Rollup merge of #62812 - fakenine:normalize_use_of_backticks_compiler…
Centril Jul 21, 2019
b7d136f
Rollup merge of #62813 - alexcrichton:less-dylib, r=Mark-Simulacrum
Centril Jul 21, 2019
6558b98
Rollup merge of #62832 - fakenine:normalize_use_of_backticks_compiler…
Centril Jul 21, 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
7 changes: 4 additions & 3 deletions src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
unsafe {
let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64
let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 4]>::uninit();
// FIXME(#53491): Technically, this is calling `get_mut` on an uninitialized
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
// FIXME(#53491): This is calling `get_mut` on an uninitialized
// `MaybeUninit` (here and elsewhere in this file). Revisit this once
// we decided whether that is valid or not.
// Using `freeze` is *not enough*; `flt2dec::Part` is an enum!
// We can do this only because we are libstd and coupled to the compiler.
// (FWIW, using `freeze` would not be enough; `flt2dec::Part` is an enum!)
let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
*num, sign, precision,
false, buf.get_mut(), parts.get_mut());
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use crate::ptr::NonNull;
/// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct
/// for any type which upholds Unique's aliasing requirements.
#[unstable(feature = "ptr_internals", issue = "0",
reason = "use NonNull instead and consider PhantomData<T> \
(if you also use #[may_dangle]), Send, and/or Sync")]
reason = "use `NonNull` instead and consider `PhantomData<T>` \
(if you also use `#[may_dangle]`), `Send`, and/or `Sync`")]
#[doc(hidden)]
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
Expand Down
1 change: 0 additions & 1 deletion src/libfmt_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2018"
[lib]
name = "fmt_macros"
path = "lib.rs"
crate-type = ["dylib"]

[dependencies]
syntax_pos = { path = "../libsyntax_pos" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn check_paths<'tcx>(tcx: TyCtxt<'tcx>, if_this_changed: &Sources, then_this_wou
for &(target_span, _, _, _) in then_this_would_need {
tcx.sess.span_err(
target_span,
"no #[rustc_if_this_changed] annotation detected");
"no `#[rustc_if_this_changed]` annotation detected");

}
return;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_incremental/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ impl FindAllAttrs<'tcx> {
for attr in &self.found_attrs {
if !checked_attrs.contains(&attr.id) {
self.tcx.sess.span_err(attr.span, &format!("found unchecked \
#[rustc_dirty]/#[rustc_clean] attribute"));
`#[rustc_dirty]` / `#[rustc_clean]` attribute"));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_incremental/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ fn find_source_directory_in_iter<I>(iter: I,
if source_directories_already_tried.contains(&session_dir) ||
!is_session_directory(&directory_name) ||
!is_finalized(&directory_name) {
debug!("find_source_directory_in_iter - ignoring.");
debug!("find_source_directory_in_iter - ignoring");
continue
}

Expand Down Expand Up @@ -693,7 +693,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
let timestamp = match extract_timestamp_from_session_dir(lock_file_name) {
Ok(timestamp) => timestamp,
Err(()) => {
debug!("Found lock-file with malformed timestamp: {}",
debug!("found lock-file with malformed timestamp: {}",
crate_directory.join(&lock_file_name).display());
// Ignore it
continue
Expand Down Expand Up @@ -746,7 +746,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
let timestamp = match extract_timestamp_from_session_dir(directory_name) {
Ok(timestamp) => timestamp,
Err(()) => {
debug!("Found session-dir with malformed timestamp: {}",
debug!("found session-dir with malformed timestamp: {}",
crate_directory.join(directory_name).display());
// Ignore it
continue
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,14 +938,14 @@ impl<'a> CrateLoader<'a> {
}
match global_allocator {
Some(Some(other_crate)) => {
self.sess.err(&format!("the #[global_allocator] in {} \
self.sess.err(&format!("the `#[global_allocator]` in {} \
conflicts with this global \
allocator in: {}",
other_crate,
data.root.name));
}
Some(None) => {
self.sess.err(&format!("the #[global_allocator] in this \
self.sess.err(&format!("the `#[global_allocator]` in this \
crate conflicts with global \
allocator in: {}", data.root.name));
}
Expand All @@ -971,7 +971,7 @@ impl<'a> CrateLoader<'a> {
if !has_default {
self.sess.err("no global memory allocator found but one is \
required; link to std or \
add #[global_allocator] to a static item \
add `#[global_allocator]` to a static item \
that implements the GlobalAlloc trait.");
}
self.sess.allocator_kind.set(Some(AllocatorKind::DefaultLib));
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_metadata/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ E0454: r##"
A link name was given with an empty name. Erroneous code example:

```ignore (cannot-test-this-because-rustdoc-stops-compile-fail-before-codegen)
#[link(name = "")] extern {} // error: #[link(name = "")] given with empty name
#[link(name = "")] extern {}
// error: `#[link(name = "")]` given with empty name
```

The rust compiler cannot link to an external library if you don't give it its
Expand Down Expand Up @@ -61,7 +62,7 @@ A link was used without a name parameter. Erroneous code example:

```ignore (cannot-test-this-because-rustdoc-stops-compile-fail-before-codegen)
#[link(kind = "dylib")] extern {}
// error: #[link(...)] specified without `name = "foo"`
// error: `#[link(...)]` specified without `name = "foo"`
```

Please add the name parameter to allow the rust compiler to find the library
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_metadata/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
match item.value_str() {
Some(s) => lib.wasm_import_module = Some(s),
None => {
let msg = "must be of the form #[link(wasm_import_module = \"...\")]";
let msg = "must be of the form `#[link(wasm_import_module = \"...\")]`";
self.tcx.sess.span_err(item.span(), msg);
}
}
Expand All @@ -117,7 +117,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
let requires_name = kind_specified || lib.wasm_import_module.is_none();
if lib.name.is_none() && requires_name {
struct_span_err!(self.tcx.sess, m.span, E0459,
"#[link(...)] specified without \
"`#[link(...)]` specified without \
`name = \"foo\"`")
.span_label(m.span, "missing `name` argument")
.emit();
Expand All @@ -136,7 +136,7 @@ impl Collector<'tcx> {
match span {
Some(span) => {
struct_span_err!(self.tcx.sess, span, E0454,
"#[link(name = \"\")] given with empty name")
"`#[link(name = \"\")]` given with empty name")
.span_label(span, "empty name given")
.emit();
}
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Collector<'tcx> {
&format!("an empty renaming target was specified for library `{}`",name));
} else if !any_duplicate {
self.tcx.sess.err(&format!("renaming of the library `{}` was specified, \
however this crate contains no #[link(...)] \
however this crate contains no `#[link(...)]` \
attributes referencing this library.", name));
} else if renames.contains(name) {
self.tcx.sess.err(&format!("multiple renamings were \
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_target/spec/x86_64_unknown_linux_gnux32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ pub fn target() -> TargetResult {
base.cpu = "x86-64".to_string();
base.max_atomic_width = Some(64);
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-mx32".to_string());
// BUG: temporarily workaround #59674
base.stack_probes = false;
base.stack_probes = true;
base.has_elf_tls = false;
// BUG(GabrielMajeri): disabling the PLT on x86_64 Linux with x32 ABI
// breaks code gen. See LLVM bug 36743
Expand Down
128 changes: 98 additions & 30 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}

fn suggest_traits_to_import<'b>(&self,
err: &mut DiagnosticBuilder<'_>,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: ast::Ident,
source: SelfSource<'b>,
valid_out_of_scope_traits: Vec<DefId>) {
fn suggest_traits_to_import<'b>(
&self,
err: &mut DiagnosticBuilder<'_>,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: ast::Ident,
source: SelfSource<'b>,
valid_out_of_scope_traits: Vec<DefId>,
) {
if self.suggest_valid_traits(err, valid_out_of_scope_traits) {
return;
}
Expand Down Expand Up @@ -683,30 +685,96 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
candidates.sort_by(|a, b| a.cmp(b).reverse());
candidates.dedup();

// FIXME #21673: this help message could be tuned to the case
// of a type parameter: suggest adding a trait bound rather
// than implementing.
err.help("items from traits can only be used if the trait is implemented and in scope");
let mut msg = format!("the following {traits_define} an item `{name}`, \
perhaps you need to implement {one_of_them}:",
traits_define = if candidates.len() == 1 {
"trait defines"
} else {
"traits define"
},
one_of_them = if candidates.len() == 1 {
"it"
} else {
"one of them"
},
name = item_name);

for (i, trait_info) in candidates.iter().enumerate() {
msg.push_str(&format!("\ncandidate #{}: `{}`",
i + 1,
self.tcx.def_path_str(trait_info.def_id)));
let param_type = match rcvr_ty.sty {
ty::Param(param) => Some(param),
ty::Ref(_, ty, _) => match ty.sty {
ty::Param(param) => Some(param),
_ => None,
}
_ => None,
};
err.help(if param_type.is_some() {
"items from traits can only be used if the type parameter is bounded by the trait"
} else {
"items from traits can only be used if the trait is implemented and in scope"
});
let mut msg = format!(
"the following {traits_define} an item `{name}`, perhaps you need to {action} \
{one_of_them}:",
traits_define = if candidates.len() == 1 {
"trait defines"
} else {
"traits define"
},
action = if let Some(param) = param_type {
format!("restrict type parameter `{}` with", param)
} else {
"implement".to_string()
},
one_of_them = if candidates.len() == 1 {
"it"
} else {
"one of them"
},
name = item_name,
);
// Obtain the span for `param` and use it for a structured suggestion.
let mut suggested = false;
if let (Some(ref param), Some(ref table)) = (param_type, self.in_progress_tables) {
let table = table.borrow();
if let Some(did) = table.local_id_root {
let generics = self.tcx.generics_of(did);
let type_param = generics.type_param(param, self.tcx);
let hir = &self.tcx.hir();
if let Some(id) = hir.as_local_hir_id(type_param.def_id) {
// Get the `hir::Param` to verify whether it already has any bounds.
// We do this to avoid suggesting code that ends up as `T: FooBar`,
// instead we suggest `T: Foo + Bar` in that case.
let mut has_bounds = false;
if let Node::GenericParam(ref param) = hir.get(id) {
has_bounds = !param.bounds.is_empty();
}
let sp = hir.span(id);
// `sp` only covers `T`, change it so that it covers
// `T:` when appropriate
let sp = if has_bounds {
sp.to(self.tcx
.sess
.source_map()
.next_point(self.tcx.sess.source_map().next_point(sp)))
} else {
sp
};

// FIXME: contrast `t.def_id` against `param.bounds` to not suggest traits
// already there. That can happen when the cause is that we're in a const
// scope or associated function used as a method.
err.span_suggestions(
sp,
&msg[..],
candidates.iter().map(|t| format!(
"{}: {}{}",
param,
self.tcx.def_path_str(t.def_id),
if has_bounds { " +"} else { "" },
)),
Applicability::MaybeIncorrect,
);
suggested = true;
}
};
}

if !suggested {
for (i, trait_info) in candidates.iter().enumerate() {
msg.push_str(&format!(
"\ncandidate #{}: `{}`",
i + 1,
self.tcx.def_path_str(trait_info.def_id),
));
}
err.note(&msg[..]);
}
err.note(&msg[..]);
}
}

Expand Down
31 changes: 17 additions & 14 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,40 +759,40 @@ fn adt_destructor(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::Destructor> {
fn primary_body_of(
tcx: TyCtxt<'_>,
id: hir::HirId,
) -> Option<(hir::BodyId, Option<&hir::FnHeader>, Option<&hir::FnDecl>)> {
) -> Option<(hir::BodyId, Option<&hir::Ty>, Option<&hir::FnHeader>, Option<&hir::FnDecl>)> {
match tcx.hir().get(id) {
Node::Item(item) => {
match item.node {
hir::ItemKind::Const(_, body) |
hir::ItemKind::Static(_, _, body) =>
Some((body, None, None)),
hir::ItemKind::Const(ref ty, body) |
hir::ItemKind::Static(ref ty, _, body) =>
Some((body, Some(ty), None, None)),
hir::ItemKind::Fn(ref decl, ref header, .., body) =>
Some((body, Some(header), Some(decl))),
Some((body, None, Some(header), Some(decl))),
_ =>
None,
}
}
Node::TraitItem(item) => {
match item.node {
hir::TraitItemKind::Const(_, Some(body)) =>
Some((body, None, None)),
hir::TraitItemKind::Const(ref ty, Some(body)) =>
Some((body, Some(ty), None, None)),
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) =>
Some((body, Some(&sig.header), Some(&sig.decl))),
Some((body, None, Some(&sig.header), Some(&sig.decl))),
_ =>
None,
}
}
Node::ImplItem(item) => {
match item.node {
hir::ImplItemKind::Const(_, body) =>
Some((body, None, None)),
hir::ImplItemKind::Const(ref ty, body) =>
Some((body, Some(ty), None, None)),
hir::ImplItemKind::Method(ref sig, body) =>
Some((body, Some(&sig.header), Some(&sig.decl))),
Some((body, None, Some(&sig.header), Some(&sig.decl))),
_ =>
None,
}
}
Node::AnonConst(constant) => Some((constant.body, None, None)),
Node::AnonConst(constant) => Some((constant.body, None, None, None)),
_ => None,
}
}
Expand Down Expand Up @@ -825,7 +825,7 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
let span = tcx.hir().span(id);

// Figure out what primary body this item has.
let (body_id, fn_header, fn_decl) = primary_body_of(tcx, id)
let (body_id, body_ty, fn_header, fn_decl) = primary_body_of(tcx, id)
.unwrap_or_else(|| {
span_bug!(span, "can't type-check body of {:?}", def_id);
});
Expand Down Expand Up @@ -856,7 +856,10 @@ fn typeck_tables_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::TypeckTables<'_> {
fcx
} else {
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
let expected_type = tcx.type_of(def_id);
let expected_type = body_ty.and_then(|ty| match ty.node {
hir::TyKind::Infer => Some(AstConv::ast_ty_to_ty(&fcx, ty)),
_ => None
}).unwrap_or_else(|| tcx.type_of(def_id));
let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type);
fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized);

Expand Down
Loading