Skip to content

Commit 6a17902

Browse files
committed
Auto merge of rust-lang#108919 - matthiaskrgr:rollup-g271pm2, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#108686 (rustdoc: include link on all.html location header) - rust-lang#108846 (StableMIR: Proof-of-concept implementation + test ) - rust-lang#108873 (Simplify `sort_by` calls) - rust-lang#108883 (Suppress copy impl error when post-normalized type references errors) - rust-lang#108884 (Tweak illegal `Copy` impl message) - rust-lang#108887 (Rename `MapInPlace` as `FlatMapInPlace`.) - rust-lang#108901 (fix: evaluate with wrong obligation stack) - rust-lang#108903 (Move Clippy tests back to their intended directory) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 900c354 + 7732ccc commit 6a17902

File tree

74 files changed

+465
-165
lines changed

Some content is hidden

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

74 files changed

+465
-165
lines changed

Cargo.lock

+2-8
Original file line numberDiff line numberDiff line change
@@ -5283,15 +5283,9 @@ dependencies = [
52835283
name = "rustc_smir"
52845284
version = "0.0.0"
52855285
dependencies = [
5286-
"rustc_borrowck",
5287-
"rustc_driver",
5288-
"rustc_hir",
5289-
"rustc_interface",
52905286
"rustc_middle",
5291-
"rustc_mir_dataflow",
5292-
"rustc_mir_transform",
5293-
"rustc_serialize",
5294-
"rustc_trait_selection",
5287+
"rustc_span",
5288+
"tracing",
52955289
]
52965290

52975291
[[package]]

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::ptr::P;
1212
use crate::token::{self, Token};
1313
use crate::tokenstream::*;
1414

15-
use rustc_data_structures::map_in_place::MapInPlace;
15+
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1616
use rustc_data_structures::sync::Lrc;
1717
use rustc_span::source_map::Spanned;
1818
use rustc_span::symbol::Ident;

compiler/rustc_data_structures/src/map_in_place.rs renamed to compiler/rustc_data_structures/src/flat_map_in_place.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ use smallvec::{Array, SmallVec};
22
use std::ptr;
33
use thin_vec::ThinVec;
44

5-
pub trait MapInPlace<T>: Sized {
6-
fn map_in_place<F>(&mut self, mut f: F)
7-
where
8-
F: FnMut(T) -> T,
9-
{
10-
self.flat_map_in_place(|e| Some(f(e)))
11-
}
12-
5+
pub trait FlatMapInPlace<T>: Sized {
136
fn flat_map_in_place<F, I>(&mut self, f: F)
147
where
158
F: FnMut(T) -> I,
@@ -66,14 +59,14 @@ macro_rules! flat_map_in_place {
6659
};
6760
}
6861

69-
impl<T> MapInPlace<T> for Vec<T> {
62+
impl<T> FlatMapInPlace<T> for Vec<T> {
7063
flat_map_in_place!();
7164
}
7265

73-
impl<T, A: Array<Item = T>> MapInPlace<T> for SmallVec<A> {
66+
impl<T, A: Array<Item = T>> FlatMapInPlace<T> for SmallVec<A> {
7467
flat_map_in_place!();
7568
}
7669

77-
impl<T> MapInPlace<T> for ThinVec<T> {
70+
impl<T> FlatMapInPlace<T> for ThinVec<T> {
7871
flat_map_in_place!();
7972
}

compiler/rustc_data_structures/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ pub fn cold_path<F: FnOnce() -> R, R>(f: F) -> R {
5050
pub mod base_n;
5151
pub mod binary_search_util;
5252
pub mod captures;
53+
pub mod flat_map_in_place;
5354
pub mod flock;
5455
pub mod functor;
5556
pub mod fx;
5657
pub mod graph;
5758
pub mod intern;
5859
pub mod jobserver;
5960
pub mod macros;
60-
pub mod map_in_place;
6161
pub mod obligation_forest;
6262
pub mod owning_ref;
6363
pub mod sip128;

compiler/rustc_expand/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use rustc_ast::tokenstream::{LazyAttrTokenStream, TokenTree};
1212
use rustc_ast::NodeId;
1313
use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem};
1414
use rustc_attr as attr;
15+
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
1516
use rustc_data_structures::fx::FxHashMap;
16-
use rustc_data_structures::map_in_place::MapInPlace;
1717
use rustc_feature::{Feature, Features, State as FeatureState};
1818
use rustc_feature::{
1919
ACCEPTED_FEATURES, ACTIVE_FEATURES, REMOVED_FEATURES, STABLE_REMOVED_FEATURES,

compiler/rustc_expand/src/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_ast::{ForeignItemKind, HasAttrs, HasNodeId};
2020
use rustc_ast::{Inline, ItemKind, MacStmtStyle, MetaItemKind, ModKind};
2121
use rustc_ast::{NestedMetaItem, NodeId, PatKind, StmtKind, TyKind};
2222
use rustc_ast_pretty::pprust;
23-
use rustc_data_structures::map_in_place::MapInPlace;
23+
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
2424
use rustc_data_structures::sync::Lrc;
2525
use rustc_errors::PResult;
2626
use rustc_feature::Features;

compiler/rustc_hir_analysis/locales/en-US.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ hir_analysis_missing_type_params =
8989
.note = because of the default `Self` reference, type parameters must be specified on object types
9090
9191
hir_analysis_copy_impl_on_type_with_dtor =
92-
the trait `Copy` may not be implemented for this type; the type has a destructor
92+
the trait `Copy` cannot be implemented for this type; the type has a destructor
9393
.label = `Copy` not allowed on types with destructors
9494
9595
hir_analysis_multiple_relaxed_default_bounds =
9696
type parameter has more than one relaxed default bound, only one is supported
9797
9898
hir_analysis_copy_impl_on_non_adt =
99-
the trait `Copy` may not be implemented for this type
99+
the trait `Copy` cannot be implemented for this type
100100
.label = type is not a structure or enumeration
101101
102102
hir_analysis_const_impl_for_non_const_trait =

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! up data structures required by type-checking/codegen.
33
44
use crate::errors::{CopyImplOnNonAdt, CopyImplOnTypeWithDtor, DropImplOnWrongItem};
5+
use rustc_data_structures::fx::FxHashSet;
56
use rustc_errors::{struct_span_err, MultiSpan};
67
use rustc_hir as hir;
78
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -86,15 +87,22 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
8687
tcx.sess,
8788
span,
8889
E0204,
89-
"the trait `Copy` may not be implemented for this type"
90+
"the trait `Copy` cannot be implemented for this type"
9091
);
9192

9293
// We'll try to suggest constraining type parameters to fulfill the requirements of
9394
// their `Copy` implementation.
9495
let mut errors: BTreeMap<_, Vec<_>> = Default::default();
9596
let mut bounds = vec![];
9697

98+
let mut seen_tys = FxHashSet::default();
99+
97100
for (field, ty, reason) in fields {
101+
// Only report an error once per type.
102+
if !seen_tys.insert(ty) {
103+
continue;
104+
}
105+
98106
let field_span = tcx.def_span(field.did);
99107
err.span_label(field_span, "this field does not implement `Copy`");
100108

compiler/rustc_hir_typeck/locales/en-US.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ hir_typeck_field_multiply_specified_in_initializer =
44
.previous_use_label = first use of `{$ident}`
55
66
hir_typeck_copy_impl_on_type_with_dtor =
7-
the trait `Copy` may not be implemented for this type; the type has a destructor
7+
the trait `Copy` cannot be implemented for this type; the type has a destructor
88
.label = `Copy` not allowed on types with destructors
99
1010
hir_typeck_multiple_relaxed_default_bounds =
1111
type parameter has more than one relaxed default bound, only one is supported
1212
1313
hir_typeck_copy_impl_on_non_adt =
14-
the trait `Copy` may not be implemented for this type
14+
the trait `Copy` cannot be implemented for this type
1515
.label = type is not a structure or enumeration
1616
1717
hir_typeck_trait_object_declared_with_no_traits =

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10311031
.collect();
10321032

10331033
// Sort them by the name so we have a stable result.
1034-
names.sort_by(|a, b| a.as_str().partial_cmp(b.as_str()).unwrap());
1034+
names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
10351035
names
10361036
}
10371037

compiler/rustc_hir_typeck/src/method/suggest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_trait_selection::traits::{
4242
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
4343
use super::{CandidateSource, MethodError, NoMatchData};
4444
use rustc_hir::intravisit::Visitor;
45-
use std::cmp::Ordering;
45+
use std::cmp::{self, Ordering};
4646
use std::iter;
4747

4848
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -2527,7 +2527,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25272527

25282528
if !candidates.is_empty() {
25292529
// Sort from most relevant to least relevant.
2530-
candidates.sort_by(|a, b| a.cmp(b).reverse());
2530+
candidates.sort_by_key(|&info| cmp::Reverse(info));
25312531
candidates.dedup();
25322532

25332533
let param_type = match rcvr_ty.kind() {

compiler/rustc_monomorphize/src/partitioning/merging.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn merge_codegen_units<'tcx>(
2424
// smallest into each other) we're sure to start off with a deterministic
2525
// order (sorted by name). This'll mean that if two cgus have the same size
2626
// the stable sort below will keep everything nice and deterministic.
27-
codegen_units.sort_by(|a, b| a.name().as_str().partial_cmp(b.name().as_str()).unwrap());
27+
codegen_units.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
2828

2929
// This map keeps track of what got merged into what.
3030
let mut cgu_contents: FxHashMap<Symbol, Vec<Symbol>> =

compiler/rustc_monomorphize/src/partitioning/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub fn partition<'tcx>(
252252
internalization_candidates: _,
253253
} = post_inlining;
254254

255-
result.sort_by(|a, b| a.name().as_str().partial_cmp(b.name().as_str()).unwrap());
255+
result.sort_by(|a, b| a.name().as_str().cmp(b.name().as_str()));
256256

257257
result
258258
}

compiler/rustc_parse/src/lexer/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn report_suspicious_mismatch_block(
7171
.collect();
7272

7373
// sort by `lo`, so the large block spans in the front
74-
matched_spans.sort_by(|a, b| a.0.lo().cmp(&b.0.lo()));
74+
matched_spans.sort_by_key(|(span, _)| span.lo());
7575

7676
// We use larger block whose identation is well to cover those inner mismatched blocks
7777
// O(N^2) here, but we are on error reporting path, so it is fine

compiler/rustc_resolve/src/late/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
17361736

17371737
let name = path[path.len() - 1].ident.name;
17381738
// Make sure error reporting is deterministic.
1739-
names.sort_by(|a, b| a.candidate.as_str().partial_cmp(b.candidate.as_str()).unwrap());
1739+
names.sort_by(|a, b| a.candidate.as_str().cmp(b.candidate.as_str()));
17401740

17411741
match find_best_match_for_name(
17421742
&names.iter().map(|suggestion| suggestion.candidate).collect::<Vec<Symbol>>(),

compiler/rustc_session/src/code_stats.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashSet;
22
use rustc_data_structures::sync::Lock;
33
use rustc_span::Symbol;
44
use rustc_target::abi::{Align, Size};
5-
use std::cmp::{self, Ordering};
5+
use std::cmp;
66

77
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
88
pub struct VariantInfo {
@@ -87,7 +87,7 @@ impl CodeStats {
8787
// Except for Generators, whose variants are already sorted according to
8888
// their yield points in `variant_info_for_generator`.
8989
if kind != DataTypeKind::Generator {
90-
variants.sort_by(|info1, info2| info2.size.cmp(&info1.size));
90+
variants.sort_by_key(|info| cmp::Reverse(info.size));
9191
}
9292
let info = TypeSizeInfo {
9393
kind,
@@ -107,13 +107,7 @@ impl CodeStats {
107107

108108
// Primary sort: large-to-small.
109109
// Secondary sort: description (dictionary order)
110-
sorted.sort_by(|info1, info2| {
111-
// (reversing cmp order to get large-to-small ordering)
112-
match info2.overall_size.cmp(&info1.overall_size) {
113-
Ordering::Equal => info1.type_description.cmp(&info2.type_description),
114-
other => other,
115-
}
116-
});
110+
sorted.sort_by_key(|info| (cmp::Reverse(info.overall_size), &info.type_description));
117111

118112
for info in sorted {
119113
let TypeSizeInfo { type_description, overall_size, align, kind, variants, .. } = info;

compiler/rustc_smir/Cargo.toml

+3-16
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,12 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
rustc_borrowck = { path = "../rustc_borrowck", optional = true }
8-
rustc_driver = { path = "../rustc_driver", optional = true }
9-
rustc_hir = { path = "../rustc_hir", optional = true }
10-
rustc_interface = { path = "../rustc_interface", optional = true }
117
rustc_middle = { path = "../rustc_middle", optional = true }
12-
rustc_mir_dataflow = { path = "../rustc_mir_dataflow", optional = true }
13-
rustc_mir_transform = { path = "../rustc_mir_transform", optional = true }
14-
rustc_serialize = { path = "../rustc_serialize", optional = true }
15-
rustc_trait_selection = { path = "../rustc_trait_selection", optional = true }
8+
rustc_span = { path = "../rustc_span", optional = true }
9+
tracing = "0.1"
1610

1711
[features]
1812
default = [
19-
"rustc_borrowck",
20-
"rustc_driver",
21-
"rustc_hir",
22-
"rustc_interface",
2313
"rustc_middle",
24-
"rustc_mir_dataflow",
25-
"rustc_mir_transform",
26-
"rustc_serialize",
27-
"rustc_trait_selection",
14+
"rustc_span",
2815
]

compiler/rustc_smir/README.md

+37
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,40 @@ git subtree pull --prefix=compiler/rustc_smir https://github.com/rust-lang/proje
7373
Note: only ever sync to rustc from the project-stable-mir's `smir` branch. Do not sync with your own forks.
7474

7575
Then open a PR against rustc just like a regular PR.
76+
77+
## Stable MIR Design
78+
79+
The stable-mir will follow a similar approach to proc-macro2. It’s
80+
implementation will eventually be broken down into two main crates:
81+
82+
- `stable_mir`: Public crate, to be published on crates.io, which will contain
83+
the stable data structure as well as proxy APIs to make calls to the
84+
compiler.
85+
- `rustc_smir`: The compiler crate that will translate from internal MIR to
86+
SMIR. This crate will also implement APIs that will be invoked by
87+
stable-mir to query the compiler for more information.
88+
89+
This will help tools to communicate with the rust compiler via stable APIs. Tools will depend on
90+
`stable_mir` crate, which will invoke the compiler using APIs defined in `rustc_smir`. I.e.:
91+
92+
```
93+
┌──────────────────────────────────┐ ┌──────────────────────────────────┐
94+
│ External Tool ┌──────────┐ │ │ ┌──────────┐ Rust Compiler │
95+
│ │ │ │ │ │ │ │
96+
│ │stable_mir| │ │ │rustc_smir│ │
97+
│ │ │ ├──────────►| │ │ │
98+
│ │ │ │◄──────────┤ │ │ │
99+
│ │ │ │ │ │ │ │
100+
│ │ │ │ │ │ │ │
101+
│ └──────────┘ │ │ └──────────┘ │
102+
└──────────────────────────────────┘ └──────────────────────────────────┘
103+
```
104+
105+
More details can be found here:
106+
https://hackmd.io/XhnYHKKuR6-LChhobvlT-g?view
107+
108+
For now, the code for these two crates are in separate modules of this crate.
109+
The modules have the same name for simplicity. We also have a third module,
110+
`rustc_internal` which will expose APIs and definitions that allow users to
111+
gather information from internal MIR constructs that haven't been exposed in
112+
the `stable_mir` module.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-06-01"
2+
channel = "nightly-2023-02-28"
33
components = [ "rustfmt", "rustc-dev" ]

compiler/rustc_smir/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
test(attr(allow(unused_variables), deny(warnings)))
1212
)]
1313
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
14-
#![deny(rustc::untranslatable_diagnostic)]
15-
#![deny(rustc::diagnostic_outside_of_impl)]
1614

17-
pub mod mir;
15+
pub mod rustc_internal;
16+
pub mod stable_mir;
1817

19-
pub mod very_unstable;
18+
// Make this module private for now since external users should not call these directly.
19+
mod rustc_smir;

compiler/rustc_smir/src/mir.rs

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Module that implements the bridge between Stable MIR and internal compiler MIR.
2+
//!
3+
//! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs
4+
//! until stable MIR is complete.
5+
6+
use crate::stable_mir;
7+
pub use rustc_span::def_id::{CrateNum, DefId};
8+
9+
pub fn item_def_id(item: &stable_mir::CrateItem) -> DefId {
10+
item.0
11+
}
12+
13+
pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
14+
item.id.into()
15+
}

0 commit comments

Comments
 (0)