Skip to content

Rollup of 12 pull requests #72716

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

Merged
merged 26 commits into from
May 29, 2020
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
27fc7e5
Implement PartialOrd and Ord for SocketAddr*
hch12907 May 16, 2020
2df69ba
Stabilize str_strip feature
tesuji May 22, 2020
716acff
Remove heterogeneous ordering for SocketAddr
hch12907 May 24, 2020
d1bc8ad
Fix tests
hch12907 May 24, 2020
42ddcd3
Add myself to .mailmap
ldm0 May 27, 2020
81f8ee4
Store `LocalDefId` directly in `rustc_resolve::Resolver` where possible
marmeladema May 24, 2020
7b11879
expand unaligned_references test
RalfJung May 27, 2020
5548e69
Add working example for E0617 explanation
GuillaumeGomez May 26, 2020
1ab0db1
Fix incorrect comment in generator test
jonas-schievink May 27, 2020
b1063b8
Clippy should always build
Mark-Simulacrum May 27, 2020
e069524
Add test for #66930
JohnTitor May 28, 2020
bb745d6
update data layout for illumos x86
jclulow May 28, 2020
4329261
Remove rustc-ux-guidelines
ehuss May 28, 2020
1eef0c3
rustc_lint: Remove `unused_crate_dependencies` from the `unused` group
petrochenkov May 28, 2020
b18c55b
Rollup merge of #72239 - hch12907:master, r=dtolnay
Dylan-DPC May 29, 2020
3bcf697
Rollup merge of #72466 - lzutao:stabilize_str-strip, r=dtolnay
Dylan-DPC May 29, 2020
235f382
Rollup merge of #72605 - GuillaumeGomez:cleanup-e0617, r=Dylan-DPC
Dylan-DPC May 29, 2020
48ea37b
Rollup merge of #72636 - marmeladema:resolver-outputs-def-id, r=petro…
Dylan-DPC May 29, 2020
ec0cd2d
Rollup merge of #72645 - ldm0:mailmap, r=nikomatsakis
Dylan-DPC May 29, 2020
733bee5
Rollup merge of #72667 - RalfJung:unaligned-ref-test, r=nikomatsakis
Dylan-DPC May 29, 2020
0204fc3
Rollup merge of #72670 - rust-lang:jonas-schievink-patch-1, r=nikomat…
Dylan-DPC May 29, 2020
feaceb2
Rollup merge of #72674 - Mark-Simulacrum:clippy-always-test-pass, r=o…
Dylan-DPC May 29, 2020
71512e4
Rollup merge of #72682 - JohnTitor:mir-tests, r=RalfJung
Dylan-DPC May 29, 2020
c9f07d3
Rollup merge of #72695 - jclulow:illumos-llvm-catchup, r=nikic
Dylan-DPC May 29, 2020
ada9c11
Rollup merge of #72697 - ehuss:rm-rustc-ux-guidelines, r=nikomatsakis
Dylan-DPC May 29, 2020
049b6dd
Rollup merge of #72702 - petrochenkov:unudeps, r=estebank
Dylan-DPC May 29, 2020
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
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -70,6 +70,8 @@ David Manescu <[email protected]> <[email protected]>
David Ross <[email protected]>
Derek Chiang <[email protected]> Derek Chiang (Enchi Jiang) <[email protected]>
Diggory Hardy <[email protected]> Diggory Hardy <[email protected]>
Donough Liu <[email protected]> <[email protected]>
Donough Liu <[email protected]> DingMing Liu <[email protected]>
Dustin Bensing <[email protected]>
Dylan Braithwaite <[email protected]> <[email protected]>
Dzmitry Malyshau <[email protected]>
60 changes: 26 additions & 34 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
@@ -516,45 +516,37 @@ impl Step for Clippy {
let host = self.host;
let compiler = builder.compiler(stage, host);

let clippy = builder.ensure(tool::Clippy {
let clippy = builder
.ensure(tool::Clippy { compiler, target: self.host, extra_features: Vec::new() })
.expect("in-tree tool");
let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
target: self.host,
extra_features: Vec::new(),
});
if let Some(clippy) = clippy {
let mut cargo = tool::prepare_tool_cargo(
builder,
compiler,
Mode::ToolRustc,
host,
"test",
"src/tools/clippy",
SourceType::InTree,
&[],
);
Mode::ToolRustc,
host,
"test",
"src/tools/clippy",
SourceType::InTree,
&[],
);

// clippy tests need to know about the stage sysroot
cargo.env("SYSROOT", builder.sysroot(compiler));
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
let target_libs = builder
.stage_out(compiler, Mode::ToolRustc)
.join(&self.host)
.join(builder.cargo_dir());
cargo.env("HOST_LIBS", host_libs);
cargo.env("TARGET_LIBS", target_libs);
// clippy tests need to find the driver
cargo.env("CLIPPY_DRIVER_PATH", clippy);
// clippy tests need to know about the stage sysroot
cargo.env("SYSROOT", builder.sysroot(compiler));
cargo.env("RUSTC_TEST_SUITE", builder.rustc(compiler));
cargo.env("RUSTC_LIB_PATH", builder.rustc_libdir(compiler));
let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
let target_libs =
builder.stage_out(compiler, Mode::ToolRustc).join(&self.host).join(builder.cargo_dir());
cargo.env("HOST_LIBS", host_libs);
cargo.env("TARGET_LIBS", target_libs);
// clippy tests need to find the driver
cargo.env("CLIPPY_DRIVER_PATH", clippy);

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

builder.add_rustc_lib_path(compiler, &mut cargo);
builder.add_rustc_lib_path(compiler, &mut cargo);

try_run(builder, &mut cargo.into());
} else {
eprintln!("failed to test clippy: could not build");
}
try_run(builder, &mut cargo.into());
}
}

90 changes: 0 additions & 90 deletions src/doc/rustc-ux-guidelines.md

This file was deleted.

7 changes: 2 additions & 5 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
@@ -4052,15 +4052,13 @@ impl str {
/// # Examples
///
/// ```
/// #![feature(str_strip)]
///
/// assert_eq!("foo:bar".strip_prefix("foo:"), Some("bar"));
/// assert_eq!("foo:bar".strip_prefix("bar"), None);
/// assert_eq!("foofoo".strip_prefix("foo"), Some("foo"));
/// ```
#[must_use = "this returns the remaining substring as a new slice, \
without modifying the original"]
#[unstable(feature = "str_strip", reason = "newly added", issue = "67302")]
#[stable(feature = "str_strip", since = "1.45.0")]
pub fn strip_prefix<'a, P: Pattern<'a>>(&'a self, prefix: P) -> Option<&'a str> {
prefix.strip_prefix_of(self)
}
@@ -4082,14 +4080,13 @@ impl str {
/// # Examples
///
/// ```
/// #![feature(str_strip)]
/// assert_eq!("bar:foo".strip_suffix(":foo"), Some("bar"));
/// assert_eq!("bar:foo".strip_suffix("bar"), None);
/// assert_eq!("foofoo".strip_suffix("foo"), Some("foo"));
/// ```
#[must_use = "this returns the remaining substring as a new slice, \
without modifying the original"]
#[unstable(feature = "str_strip", reason = "newly added", issue = "67302")]
#[stable(feature = "str_strip", since = "1.45.0")]
pub fn strip_suffix<'a, P>(&'a self, suffix: P) -> Option<&'a str>
where
P: Pattern<'a>,
11 changes: 11 additions & 0 deletions src/librustc_error_codes/error_codes/E0617.md
Original file line number Diff line number Diff line change
@@ -17,3 +17,14 @@ Certain Rust types must be cast before passing them to a variadic function,
because of arcane ABI rules dictated by the C standard. To fix the error,
cast the value to the type specified by the error message (which you may need
to import from `std::os::raw`).

In this case, `c_double` has the same size as `f64` so we can use it directly:

```no_run
# extern {
# fn printf(c: *const i8, ...);
# }
unsafe {
printf(::std::ptr::null(), 0f64); // ok!
}
```
5 changes: 0 additions & 5 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ pub use rustc_ast::ast::{CaptureBy, Movability, Mutability};
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_ast::node_id::NodeMap;
use rustc_ast::util::parser::ExprPrecedence;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::{par_for_each_in, Send, Sync};
use rustc_macros::HashStable_Generic;
use rustc_span::source_map::{SourceMap, Spanned};
@@ -2664,10 +2663,6 @@ impl<ID> TraitCandidate<ID> {
// Trait method resolution
pub type TraitMap<ID = HirId> = NodeMap<Vec<TraitCandidate<ID>>>;

// Map from the NodeId of a glob import to a list of items which are actually
// imported.
pub type GlobMap = NodeMap<FxHashSet<Symbol>>;

#[derive(Copy, Clone, Debug, HashStable_Generic)]
pub enum Node<'hir> {
Param(&'hir Param<'hir>),
1 change: 0 additions & 1 deletion src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
@@ -276,7 +276,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
UNUSED_ALLOCATION,
UNUSED_DOC_COMMENTS,
UNUSED_EXTERN_CRATES,
UNUSED_CRATE_DEPENDENCIES,
UNUSED_FEATURES,
UNUSED_LABELS,
UNUSED_PARENS,
6 changes: 0 additions & 6 deletions src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
@@ -169,7 +169,6 @@ impl<'hir> Map<'hir> {
})
}

// FIXME(eddyb) this function can and should return `LocalDefId`.
#[inline]
pub fn local_def_id(&self, hir_id: HirId) -> LocalDefId {
self.opt_local_def_id(hir_id).unwrap_or_else(|| {
@@ -192,11 +191,6 @@ impl<'hir> Map<'hir> {
self.tcx.definitions.opt_local_def_id(node)
}

#[inline]
pub fn as_local_node_id(&self, def_id: DefId) -> Option<NodeId> {
self.tcx.definitions.as_local_node_id(def_id)
}

#[inline]
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> HirId {
self.tcx.definitions.as_local_hir_id(def_id)
6 changes: 4 additions & 2 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
@@ -973,7 +973,9 @@ rustc_queries! {
desc { "fetching what a crate is named" }
}
query item_children(_: DefId) -> &'tcx [Export<hir::HirId>] {}
query extern_mod_stmt_cnum(_: DefId) -> Option<CrateNum> {}
query extern_mod_stmt_cnum(_: LocalDefId) -> Option<CrateNum> {
desc { "fetching extern module statement" }
}

query get_lib_features(_: CrateNum) -> LibFeatures {
storage(ArenaCacheSelector<'tcx>)
@@ -1040,7 +1042,7 @@ rustc_queries! {
desc { |tcx| "maybe_unused_trait_import for `{}`", tcx.def_path_str(def_id.to_def_id()) }
}
query maybe_unused_extern_crates(_: CrateNum)
-> &'tcx [(DefId, Span)] {
-> &'tcx [(LocalDefId, Span)] {
eval_always
desc { "looking up all possibly unused extern crates" }
}
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
@@ -925,7 +925,7 @@ pub struct GlobalCtxt<'tcx> {
pub consts: CommonConsts<'tcx>,

/// Resolutions of `extern crate` items produced by resolver.
extern_crate_map: FxHashMap<DefId, CrateNum>,
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,

/// Map indicating what traits are in scope for places where this
/// is relevant; generated by resolve.
@@ -944,7 +944,7 @@ pub struct GlobalCtxt<'tcx> {
pub queries: query::Queries<'tcx>,

maybe_unused_trait_imports: FxHashSet<LocalDefId>,
maybe_unused_extern_crates: Vec<(DefId, Span)>,
maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
/// A map of glob use to a set of names it actually imports. Currently only
/// used in save-analysis.
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -120,10 +120,10 @@ mod sty;
pub struct ResolverOutputs {
pub definitions: rustc_hir::definitions::Definitions,
pub cstore: Box<CrateStoreDyn>,
pub extern_crate_map: FxHashMap<DefId, CrateNum>,
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
pub trait_map: FxHashMap<hir::HirId, Vec<hir::TraitCandidate<hir::HirId>>>,
pub maybe_unused_trait_imports: FxHashSet<LocalDefId>,
pub maybe_unused_extern_crates: Vec<(DefId, Span)>,
pub maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
pub export_map: ExportMap<hir::HirId>,
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
/// Extern prelude entries. The value is `true` if the entry was introduced
13 changes: 7 additions & 6 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ impl<'a> Resolver<'a> {
Some(def_id) => def_id,
None => return self.ast_transform_scopes.get(&expn_id).unwrap_or(&self.graph_root),
};
if let Some(id) = self.definitions.as_local_node_id(def_id) {
if let Some(id) = def_id.as_local() {
self.local_macro_def_scopes[&id]
} else {
let module_def_id = ty::DefIdTree::parent(&*self, def_id).unwrap();
@@ -640,9 +640,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
} else if orig_name == Some(kw::SelfLower) {
self.r.graph_root
} else {
let def_id = self.r.definitions.local_def_id(item.id);
let crate_id =
self.r.crate_loader.process_extern_crate(item, &self.r.definitions);
self.r.extern_crate_map.insert(item.id, crate_id);
self.r.extern_crate_map.insert(def_id, crate_id);
self.r.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX })
};

@@ -1173,10 +1174,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
_ => unreachable!(),
};

let def_id = self.r.definitions.local_def_id(item.id).to_def_id();
let res = Res::Def(DefKind::Macro(ext.macro_kind()), def_id);
self.r.macro_map.insert(def_id, ext);
self.r.local_macro_def_scopes.insert(item.id, parent_scope.module);
let def_id = self.r.definitions.local_def_id(item.id);
let res = Res::Def(DefKind::Macro(ext.macro_kind()), def_id.to_def_id());
self.r.macro_map.insert(def_id.to_def_id(), ext);
self.r.local_macro_def_scopes.insert(def_id, parent_scope.module);

if macro_rules {
let ident = ident.normalize_to_macros_2_0();
8 changes: 5 additions & 3 deletions src/librustc_resolve/check_unused.rs
Original file line number Diff line number Diff line change
@@ -64,16 +64,17 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
fn check_import(&mut self, id: ast::NodeId) {
let mut used = false;
self.r.per_ns(|this, ns| used |= this.used_imports.contains(&(id, ns)));
let def_id = self.r.definitions.local_def_id(id);
if !used {
if self.r.maybe_unused_trait_imports.contains(&id) {
if self.r.maybe_unused_trait_imports.contains(&def_id) {
// Check later.
return;
}
self.unused_import(self.base_id).add(id);
} else {
// This trait import is definitely used, in a way other than
// method resolution.
self.r.maybe_unused_trait_imports.remove(&id);
self.r.maybe_unused_trait_imports.remove(&def_id);
if let Some(i) = self.unused_imports.get_mut(&self.base_id) {
i.unused.remove(&id);
}
@@ -245,7 +246,8 @@ impl Resolver<'_> {
}
}
ImportKind::ExternCrate { .. } => {
self.maybe_unused_extern_crates.push((import.id, import.span));
let def_id = self.definitions.local_def_id(import.id);
self.maybe_unused_extern_crates.push((def_id, import.span));
}
ImportKind::MacroUse => {
let msg = "unused `#[macro_use]` import";
3 changes: 2 additions & 1 deletion src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
@@ -2209,7 +2209,8 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
) -> SmallVec<[NodeId; 1]> {
let mut import_ids = smallvec![];
while let NameBindingKind::Import { import, binding, .. } = kind {
self.r.maybe_unused_trait_imports.insert(import.id);
let id = self.r.definitions.local_def_id(import.id);
self.r.maybe_unused_trait_imports.insert(id);
self.r.add_to_glob_map(&import, trait_name);
import_ids.push(import.id);
kind = &binding.kind;
63 changes: 16 additions & 47 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
use rustc_hir::definitions::{DefKey, Definitions};
use rustc_hir::PrimTy::{self, Bool, Char, Float, Int, Str, Uint};
use rustc_hir::{GlobMap, TraitMap};
use rustc_hir::TraitMap;
use rustc_metadata::creader::{CStore, CrateLoader};
use rustc_middle::hir::exports::ExportMap;
use rustc_middle::middle::cstore::{CrateStore, MetadataLoaderDyn};
@@ -866,7 +866,7 @@ pub struct Resolver<'a> {
label_res_map: NodeMap<NodeId>,

/// `CrateNum` resolutions of `extern crate` items.
extern_crate_map: NodeMap<CrateNum>,
extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
export_map: ExportMap<NodeId>,
trait_map: TraitMap<NodeId>,

@@ -895,11 +895,11 @@ pub struct Resolver<'a> {
underscore_disambiguator: u32,

/// Maps glob imports to the names of items actually imported.
glob_map: GlobMap,
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,

used_imports: FxHashSet<(NodeId, Namespace)>,
maybe_unused_trait_imports: NodeSet,
maybe_unused_extern_crates: Vec<(NodeId, Span)>,
maybe_unused_trait_imports: FxHashSet<LocalDefId>,
maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,

/// Privacy errors are delayed until the end in order to deduplicate them.
privacy_errors: Vec<PrivacyError<'a>>,
@@ -924,7 +924,7 @@ pub struct Resolver<'a> {
dummy_ext_bang: Lrc<SyntaxExtension>,
dummy_ext_derive: Lrc<SyntaxExtension>,
non_macro_attrs: [Lrc<SyntaxExtension>; 2],
local_macro_def_scopes: FxHashMap<NodeId, Module<'a>>,
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'a>>,
ast_transform_scopes: FxHashMap<ExpnId, Module<'a>>,
unused_macros: NodeMap<Span>,
proc_macro_stubs: NodeSet,
@@ -1269,11 +1269,7 @@ impl<'a> Resolver<'a> {

pub fn into_outputs(self) -> ResolverOutputs {
let definitions = self.definitions;
let extern_crate_map = self
.extern_crate_map
.into_iter()
.map(|(k, v)| (definitions.local_def_id(k).to_def_id(), v))
.collect();
let extern_crate_map = self.extern_crate_map;
let export_map = self
.export_map
.into_iter()
@@ -1298,21 +1294,9 @@ impl<'a> Resolver<'a> {
)
})
.collect();
let maybe_unused_trait_imports = self
.maybe_unused_trait_imports
.into_iter()
.map(|id| definitions.local_def_id(id))
.collect();
let maybe_unused_extern_crates = self
.maybe_unused_extern_crates
.into_iter()
.map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp))
.collect();
let glob_map = self
.glob_map
.into_iter()
.map(|(id, names)| (definitions.local_def_id(id), names))
.collect();
let maybe_unused_trait_imports = self.maybe_unused_trait_imports;
let maybe_unused_extern_crates = self.maybe_unused_extern_crates;
let glob_map = self.glob_map;
ResolverOutputs {
definitions: definitions,
cstore: Box::new(self.crate_loader.into_cstore()),
@@ -1334,11 +1318,7 @@ impl<'a> Resolver<'a> {
ResolverOutputs {
definitions: self.definitions.clone(),
cstore: Box::new(self.cstore().clone()),
extern_crate_map: self
.extern_crate_map
.iter()
.map(|(&k, &v)| (self.definitions.local_def_id(k).to_def_id(), v))
.collect(),
extern_crate_map: self.extern_crate_map.clone(),
export_map: self
.export_map
.iter()
@@ -1366,21 +1346,9 @@ impl<'a> Resolver<'a> {
)
})
.collect(),
glob_map: self
.glob_map
.iter()
.map(|(&id, names)| (self.definitions.local_def_id(id), names.clone()))
.collect(),
maybe_unused_trait_imports: self
.maybe_unused_trait_imports
.iter()
.map(|&id| self.definitions.local_def_id(id))
.collect(),
maybe_unused_extern_crates: self
.maybe_unused_extern_crates
.iter()
.map(|&(id, sp)| (self.definitions.local_def_id(id).to_def_id(), sp))
.collect(),
glob_map: self.glob_map.clone(),
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),
extern_prelude: self
.extern_prelude
.iter()
@@ -1522,7 +1490,8 @@ impl<'a> Resolver<'a> {
#[inline]
fn add_to_glob_map(&mut self, import: &Import<'_>, ident: Ident) {
if import.is_glob() {
self.glob_map.entry(import.id).or_default().insert(ident.name);
let def_id = self.definitions.local_def_id(import.id);
self.glob_map.entry(def_id).or_default().insert(ident.name);
}
}

3 changes: 2 additions & 1 deletion src/librustc_target/spec/x86_64_unknown_illumos.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,8 @@ pub fn target() -> TargetResult {
target_endian: "little".to_string(),
target_pointer_width: "64".to_string(),
target_c_int_width: "32".to_string(),
data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
data_layout: "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
.to_string(),
arch: "x86_64".to_string(),
target_os: "illumos".to_string(),
target_env: String::new(),
1 change: 0 additions & 1 deletion src/librustc_trait_selection/lib.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
#![feature(in_band_lifetimes)]
#![feature(crate_visibility_modifier)]
#![feature(or_patterns)]
#![feature(str_strip)]
#![feature(option_zip)]
#![recursion_limit = "512"] // For rustdoc

11 changes: 6 additions & 5 deletions src/librustc_typeck/check_unused.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, DefIdSet, LOCAL_CRATE};
use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LOCAL_CRATE};
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint;
@@ -70,7 +70,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
// Collect first the crates that are completely unused. These we
// can always suggest removing (no matter which edition we are
// in).
let unused_extern_crates: FxHashMap<DefId, Span> = tcx
let unused_extern_crates: FxHashMap<LocalDefId, Span> = tcx
.maybe_unused_extern_crates(LOCAL_CRATE)
.iter()
.filter(|&&(def_id, _)| {
@@ -88,7 +88,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
// Note that if we carry through to the `extern_mod_stmt_cnum` query
// below it'll cause a panic because `def_id` is actually bogus at this
// point in time otherwise.
if tcx.hir().find(tcx.hir().as_local_hir_id(def_id.expect_local())).is_none() {
if tcx.hir().find(tcx.hir().as_local_hir_id(def_id)).is_none() {
return false;
}
true
@@ -112,13 +112,14 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
});

for extern_crate in &crates_to_lint {
let id = tcx.hir().as_local_hir_id(extern_crate.def_id.expect_local());
let def_id = extern_crate.def_id.expect_local();
let id = tcx.hir().as_local_hir_id(def_id);
let item = tcx.hir().expect_item(id);

// If the crate is fully unused, we suggest removing it altogether.
// We do this in any edition.
if extern_crate.warn_if_unused {
if let Some(&span) = unused_extern_crates.get(&extern_crate.def_id) {
if let Some(&span) = unused_extern_crates.get(&def_id) {
tcx.struct_span_lint_hir(lint, id, span, |lint| {
// Removal suggestion span needs to include attributes (Issue #54400)
let span_with_attrs = tcx
107 changes: 106 additions & 1 deletion src/libstd/net/addr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::cmp::Ordering;
use crate::convert::TryInto;
use crate::fmt;
use crate::hash;
@@ -36,7 +37,7 @@ use crate::vec;
/// assert_eq!(socket.port(), 8080);
/// assert_eq!(socket.is_ipv4(), true);
/// ```
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum SocketAddr {
/// An IPv4 socket address.
@@ -653,11 +654,75 @@ impl PartialEq for SocketAddrV6 {
&& self.inner.sin6_scope_id == other.inner.sin6_scope_id
}
}
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialEq<SocketAddrV4> for SocketAddr {
fn eq(&self, other: &SocketAddrV4) -> bool {
match self {
SocketAddr::V4(v4) => v4 == other,
SocketAddr::V6(_) => false,
}
}
}
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialEq<SocketAddrV6> for SocketAddr {
fn eq(&self, other: &SocketAddrV6) -> bool {
match self {
SocketAddr::V4(_) => false,
SocketAddr::V6(v6) => v6 == other,
}
}
}
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialEq<SocketAddr> for SocketAddrV4 {
fn eq(&self, other: &SocketAddr) -> bool {
match other {
SocketAddr::V4(v4) => self == v4,
SocketAddr::V6(_) => false,
}
}
}
#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialEq<SocketAddr> for SocketAddrV6 {
fn eq(&self, other: &SocketAddr) -> bool {
match other {
SocketAddr::V4(_) => false,
SocketAddr::V6(v6) => self == v6,
}
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for SocketAddrV4 {}
#[stable(feature = "rust1", since = "1.0.0")]
impl Eq for SocketAddrV6 {}

#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialOrd for SocketAddrV4 {
fn partial_cmp(&self, other: &SocketAddrV4) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl PartialOrd for SocketAddrV6 {
fn partial_cmp(&self, other: &SocketAddrV6) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl Ord for SocketAddrV4 {
fn cmp(&self, other: &SocketAddrV4) -> Ordering {
self.ip().cmp(other.ip()).then(self.port().cmp(&other.port()))
}
}

#[stable(feature = "socketaddr_ordering", since = "1.45.0")]
impl Ord for SocketAddrV6 {
fn cmp(&self, other: &SocketAddrV6) -> Ordering {
self.ip().cmp(other.ip()).then(self.port().cmp(&other.port()))
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl hash::Hash for SocketAddrV4 {
fn hash<H: hash::Hasher>(&self, s: &mut H) {
@@ -1102,4 +1167,44 @@ mod tests {
assert!(!v6.is_ipv4());
assert!(v6.is_ipv6());
}

#[test]
fn compare() {
let v4_1 = "224.120.45.1:23456".parse::<SocketAddrV4>().unwrap();
let v4_2 = "224.210.103.5:12345".parse::<SocketAddrV4>().unwrap();
let v4_3 = "224.210.103.5:23456".parse::<SocketAddrV4>().unwrap();
let v6_1 = "[2001:db8:f00::1002]:23456".parse::<SocketAddrV6>().unwrap();
let v6_2 = "[2001:db8:f00::2001]:12345".parse::<SocketAddrV6>().unwrap();
let v6_3 = "[2001:db8:f00::2001]:23456".parse::<SocketAddrV6>().unwrap();

// equality
assert_eq!(v4_1, v4_1);
assert_eq!(v6_1, v6_1);
assert_eq!(v4_1, SocketAddr::V4(v4_1));
assert_eq!(v6_1, SocketAddr::V6(v6_1));
assert_eq!(SocketAddr::V4(v4_1), SocketAddr::V4(v4_1));
assert_eq!(SocketAddr::V6(v6_1), SocketAddr::V6(v6_1));
assert!(v4_1 != SocketAddr::V6(v6_1));
assert!(v6_1 != SocketAddr::V4(v4_1));
assert!(v4_1 != v4_2);
assert!(v6_1 != v6_2);

// compare different addresses
assert!(v4_1 < v4_2);
assert!(v6_1 < v6_2);
assert!(v4_2 > v4_1);
assert!(v6_2 > v6_1);

// compare the same address with different ports
assert!(v4_2 < v4_3);
assert!(v6_2 < v6_3);
assert!(v4_3 > v4_2);
assert!(v6_3 > v6_2);

// compare different addresses with the same port
assert!(v4_1 < v4_3);
assert!(v6_1 < v6_3);
assert!(v4_3 > v4_1);
assert!(v6_3 > v6_1);
}
}
2 changes: 1 addition & 1 deletion src/test/ui/generator/resume-arg-size.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ fn main() {
};

// Neither of these generators have the resume arg live across the `yield`, so they should be
// 4 Bytes in size (only storing the discriminant)
// 1 Byte in size (only storing the discriminant)
assert_eq!(size_of_val(&gen_copy), 1);
assert_eq!(size_of_val(&gen_move), 1);
}
15 changes: 11 additions & 4 deletions src/test/ui/lint/unaligned_references.rs
Original file line number Diff line number Diff line change
@@ -2,20 +2,27 @@

#[repr(packed)]
pub struct Good {
data: &'static u32,
data2: [&'static u32; 2],
data: u64,
ptr: &'static u64,
data2: [u64; 2],
aligned: [u8; 32],
}

fn main() {
unsafe {
let good = Good { data: &0, data2: [&0, &0], aligned: [0; 32] };
let good = Good { data: 0, ptr: &0, data2: [0, 0], aligned: [0; 32] };

let _ = &good.ptr; //~ ERROR reference to packed field
let _ = &good.data; //~ ERROR reference to packed field
// Error even when turned into raw pointer immediately.
let _ = &good.data as *const _; //~ ERROR reference to packed field
let _: *const _ = &good.data; //~ ERROR reference to packed field
// Error on method call.
let _ = good.data.clone(); //~ ERROR reference to packed field
// Error for nested fields.
let _ = &good.data2[0]; //~ ERROR reference to packed field
let _ = &*good.data; // ok, behind a pointer

let _ = &*good.ptr; // ok, behind a pointer
let _ = &good.aligned; // ok, has align 1
let _ = &good.aligned[2]; // ok, has align 1
}
30 changes: 23 additions & 7 deletions src/test/ui/lint/unaligned_references.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:14:17
--> $DIR/unaligned_references.rs:15:17
|
LL | let _ = &good.data;
| ^^^^^^^^^^
LL | let _ = &good.ptr;
| ^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/unaligned_references.rs:1:9
@@ -12,28 +12,44 @@ LL | #![deny(unaligned_references)]
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:15:17
--> $DIR/unaligned_references.rs:16:17
|
LL | let _ = &good.data;
| ^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:18:17
|
LL | let _ = &good.data as *const _;
| ^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:16:27
--> $DIR/unaligned_references.rs:19:27
|
LL | let _: *const _ = &good.data;
| ^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:17:17
--> $DIR/unaligned_references.rs:21:17
|
LL | let _ = good.data.clone();
| ^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: reference to packed field is unaligned
--> $DIR/unaligned_references.rs:23:17
|
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
|
= note: fields of packed structs are not properly aligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: aborting due to 4 previous errors
error: aborting due to 6 previous errors

11 changes: 11 additions & 0 deletions src/test/ui/mir/issue-66930.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
// compile-flags: --emit=mir,link
// Regression test for #66930, this ICE requires `--emit=mir` flag.

static UTF8_CHAR_WIDTH: [u8; 0] = [];

pub fn utf8_char_width(b: u8) -> usize {
UTF8_CHAR_WIDTH[b as usize] as usize
}

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/unused-crate-deps/lint-group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// `unused_crate_dependencies` is not currently in the `unused` group
// due to false positives from Cargo.

// check-pass
// aux-crate:bar=bar.rs

#![deny(unused)]

fn main() {}
1 change: 0 additions & 1 deletion src/tools/clippy/src/driver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![feature(rustc_private)]
#![feature(str_strip)]

// FIXME: switch to something more ergonomic here, once available.
// (Currently there is no way to opt into sysroot crates without `extern crate`.)