Skip to content

Commit f251156

Browse files
bors-ferrocene[bot]Urgauestebankfee1-deadRalfJung
authored
Merge #57
57: Pull upstream master 2023 10 18 r=pietroalbini a=Veykril * rust-lang/rust#116505 * rust-lang/rust#116840 * rust-lang/rust#116767 * rust-lang/rust#116855 * rust-lang/rust#116827 * rust-lang/rust#116787 * rust-lang/rust#116719 * rust-lang/rust#116717 * rust-lang/rust#111072 * rust-lang/rust#116844 * rust-lang/rust#115577 * rust-lang/rust#116756 * rust-lang/rust#116518 Co-authored-by: Urgau <[email protected]> Co-authored-by: Esteban Küber <[email protected]> Co-authored-by: Deadbeef <[email protected]> Co-authored-by: Ralf Jung <[email protected]> Co-authored-by: Camille GILLOT <[email protected]> Co-authored-by: Celina G. Val <[email protected]> Co-authored-by: Nicholas Nethercote <[email protected]> Co-authored-by: Arthur Lafrance <[email protected]> Co-authored-by: Nikolay Arhipov <[email protected]> Co-authored-by: Nikita Popov <[email protected]> Co-authored-by: bors <[email protected]>
2 parents dfeded9 + 9fe9f21 commit f251156

File tree

299 files changed

+3458
-1111
lines changed

Some content is hidden

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

299 files changed

+3458
-1111
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ dependencies = [
11191119
"glob",
11201120
"hex",
11211121
"home",
1122+
"indexmap 2.0.0",
11221123
"lazycell",
11231124
"libc",
11241125
"miow",

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,11 @@ fn print_flag_list<T>(
11851185
///
11861186
/// So with all that in mind, the comments below have some more detail about the
11871187
/// contortions done here to get things to work out correctly.
1188-
fn handle_options(handler: &EarlyErrorHandler, args: &[String]) -> Option<getopts::Matches> {
1188+
///
1189+
/// This does not need to be `pub` for rustc itself, but @chaosite needs it to
1190+
/// be public when using rustc as a library, see
1191+
/// <https://github.com/rust-lang/rust/commit/2b4c33817a5aaecabf4c6598d41e190080ec119e>
1192+
pub fn handle_options(handler: &EarlyErrorHandler, args: &[String]) -> Option<getopts::Matches> {
11891193
if args.is_empty() {
11901194
// user did not write `-v` nor `-Z unstable-options`, so do not
11911195
// include that extra information.

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10911091
self.trait_defines_associated_item_named(r.def_id(), ty::AssocKind::Const, assoc_name)
10921092
});
10931093

1094-
let (bound, next_cand) = match (matching_candidates.next(), const_candidates.next()) {
1094+
let (mut bound, mut next_cand) = match (matching_candidates.next(), const_candidates.next())
1095+
{
10951096
(Some(bound), _) => (bound, matching_candidates.next()),
10961097
(None, Some(bound)) => (bound, const_candidates.next()),
10971098
(None, None) => {
@@ -1107,6 +1108,37 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11071108
};
11081109
debug!(?bound);
11091110

1111+
// look for a candidate that is not the same as our first bound, disregarding
1112+
// whether the bound is const.
1113+
while let Some(mut bound2) = next_cand {
1114+
debug!(?bound2);
1115+
let tcx = self.tcx();
1116+
if bound2.bound_vars() != bound.bound_vars() {
1117+
break;
1118+
}
1119+
1120+
let generics = tcx.generics_of(bound.def_id());
1121+
let Some(host_index) = generics.host_effect_index else { break };
1122+
1123+
// always return the bound that contains the host param.
1124+
if let ty::ConstKind::Param(_) = bound2.skip_binder().args.const_at(host_index).kind() {
1125+
(bound, bound2) = (bound2, bound);
1126+
}
1127+
1128+
let unconsted_args = bound
1129+
.skip_binder()
1130+
.args
1131+
.iter()
1132+
.enumerate()
1133+
.map(|(n, arg)| if host_index == n { tcx.consts.true_.into() } else { arg });
1134+
1135+
if unconsted_args.eq(bound2.skip_binder().args.iter()) {
1136+
next_cand = matching_candidates.next().or_else(|| const_candidates.next());
1137+
} else {
1138+
break;
1139+
}
1140+
}
1141+
11101142
if let Some(bound2) = next_cand {
11111143
debug!(?bound2);
11121144

compiler/rustc_hir_analysis/src/bounds.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,33 @@ impl<'tcx> Bounds<'tcx> {
4343
trait_ref: ty::PolyTraitRef<'tcx>,
4444
span: Span,
4545
polarity: ty::ImplPolarity,
46+
) {
47+
self.push_trait_bound_inner(tcx, trait_ref, span, polarity);
48+
49+
// if we have a host param, we push an unconst trait bound in addition
50+
// to the const one.
51+
// FIXME(effects) we should find a better way than name matching
52+
if tcx.features().effects && trait_ref.skip_binder().args.host_effect_param().is_some() {
53+
let generics = tcx.generics_of(trait_ref.def_id());
54+
let Some(host_index) = generics.host_effect_index else { return };
55+
let trait_ref = trait_ref.map_bound(|mut trait_ref| {
56+
trait_ref.args =
57+
tcx.mk_args_from_iter(trait_ref.args.iter().enumerate().map(|(n, arg)| {
58+
if host_index == n { tcx.consts.true_.into() } else { arg }
59+
}));
60+
trait_ref
61+
});
62+
63+
self.push_trait_bound_inner(tcx, trait_ref, span, polarity);
64+
}
65+
}
66+
67+
fn push_trait_bound_inner(
68+
&mut self,
69+
tcx: TyCtxt<'tcx>,
70+
trait_ref: ty::PolyTraitRef<'tcx>,
71+
span: Span,
72+
polarity: ty::ImplPolarity,
4673
) {
4774
self.clauses.push((
4875
trait_ref

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::intravisit::{self, Visitor};
1111
use rustc_middle::ty::{self, Ty, TyCtxt};
1212
use rustc_middle::ty::{GenericPredicates, ImplTraitInTraitData, ToPredicate};
1313
use rustc_span::symbol::Ident;
14-
use rustc_span::{Span, DUMMY_SP};
14+
use rustc_span::{sym, Span, DUMMY_SP};
1515

1616
/// Returns a list of all type predicates (explicit and implicit) for the definition with
1717
/// ID `def_id`. This includes all predicates returned by `predicates_defined_on`, plus
@@ -38,11 +38,38 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
3838
// an obligation and instead be skipped. Otherwise we'd use
3939
// `tcx.def_span(def_id);`
4040
let span = rustc_span::DUMMY_SP;
41-
result.predicates =
42-
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
43-
ty::TraitRef::identity(tcx, def_id).to_predicate(tcx),
41+
let non_const_bound = if tcx.features().effects && tcx.has_attr(def_id, sym::const_trait) {
42+
// when `Self` is a const trait, also add `Self: Trait<.., true>` as implied bound,
43+
// because only implementing `Self: Trait<.., false>` is currently not possible.
44+
Some((
45+
ty::TraitRef::new(
46+
tcx,
47+
def_id,
48+
ty::GenericArgs::for_item(tcx, def_id, |param, _| {
49+
if param.is_host_effect() {
50+
tcx.consts.true_.into()
51+
} else {
52+
tcx.mk_param_from_def(param)
53+
}
54+
}),
55+
)
56+
.to_predicate(tcx),
4457
span,
45-
))));
58+
))
59+
} else {
60+
None
61+
};
62+
result.predicates = tcx.arena.alloc_from_iter(
63+
result
64+
.predicates
65+
.iter()
66+
.copied()
67+
.chain(std::iter::once((
68+
ty::TraitRef::identity(tcx, def_id).to_predicate(tcx),
69+
span,
70+
)))
71+
.chain(non_const_bound),
72+
);
4673
}
4774
debug!("predicates_of(def_id={:?}) = {:?}", def_id, result);
4875
result

compiler/rustc_hir_typeck/src/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
650650
.sess
651651
.source_map()
652652
.is_multiline(call_expr.span.with_lo(callee_expr.span.hi()))
653-
&& call_expr.span.ctxt() == callee_expr.span.ctxt();
653+
&& call_expr.span.eq_ctxt(callee_expr.span);
654654
if call_is_multiline {
655655
err.span_suggestion(
656656
callee_expr.span.shrink_to_hi(),

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
221221
let item_def_id = tcx.hir().ty_param_owner(def_id);
222222
let generics = tcx.generics_of(item_def_id);
223223
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
224+
// HACK(eddyb) should get the original `Span`.
225+
let span = tcx.def_span(def_id);
224226
ty::GenericPredicates {
225227
parent: None,
226228
predicates: tcx.arena.alloc_from_iter(
227229
self.param_env.caller_bounds().iter().filter_map(|predicate| {
228230
match predicate.kind().skip_binder() {
229231
ty::ClauseKind::Trait(data) if data.self_ty().is_param(index) => {
230-
// HACK(eddyb) should get the original `Span`.
231-
let span = tcx.def_span(def_id);
232232
Some((predicate, span))
233233
}
234234
_ => None,

compiler/rustc_interface/src/interface.rs

Lines changed: 132 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,13 @@ pub fn parse_cfgspecs(
125125
/// Converts strings provided as `--check-cfg [specs]` into a `CheckCfg`.
126126
pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> CheckCfg {
127127
rustc_span::create_default_session_if_not_set_then(move |_| {
128-
let mut check_cfg = CheckCfg::default();
128+
// If any --check-cfg is passed then exhaustive_values and exhaustive_names
129+
// are enabled by default.
130+
let exhaustive_names = !specs.is_empty();
131+
let exhaustive_values = !specs.is_empty();
132+
let mut check_cfg = CheckCfg { exhaustive_names, exhaustive_values, ..CheckCfg::default() };
129133

134+
let mut old_syntax = None;
130135
for s in specs {
131136
let sess = ParseSess::with_silent_emitter(Some(format!(
132137
"this error occurred on the command line: `--check-cfg={s}`"
@@ -142,18 +147,21 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
142147
};
143148
}
144149

145-
let expected_error = || {
146-
error!(
147-
"expected `names(name1, name2, ... nameN)` or \
148-
`values(name, \"value1\", \"value2\", ... \"valueN\")`"
149-
)
150-
};
150+
let expected_error =
151+
|| error!("expected `cfg(name, values(\"value1\", \"value2\", ... \"valueN\"))`");
151152

152153
match maybe_new_parser_from_source_str(&sess, filename, s.to_string()) {
153154
Ok(mut parser) => match parser.parse_meta_item() {
154155
Ok(meta_item) if parser.token == token::Eof => {
155156
if let Some(args) = meta_item.meta_item_list() {
156157
if meta_item.has_name(sym::names) {
158+
// defaults are flipped for the old syntax
159+
if old_syntax == None {
160+
check_cfg.exhaustive_names = false;
161+
check_cfg.exhaustive_values = false;
162+
}
163+
old_syntax = Some(true);
164+
157165
check_cfg.exhaustive_names = true;
158166
for arg in args {
159167
if arg.is_word() && arg.ident().is_some() {
@@ -167,6 +175,13 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
167175
}
168176
}
169177
} else if meta_item.has_name(sym::values) {
178+
// defaults are flipped for the old syntax
179+
if old_syntax == None {
180+
check_cfg.exhaustive_names = false;
181+
check_cfg.exhaustive_values = false;
182+
}
183+
old_syntax = Some(true);
184+
170185
if let Some((name, values)) = args.split_first() {
171186
if name.is_word() && name.ident().is_some() {
172187
let ident = name.ident().expect("multi-segment cfg key");
@@ -216,6 +231,116 @@ pub fn parse_check_cfg(handler: &EarlyErrorHandler, specs: Vec<String>) -> Check
216231
} else {
217232
expected_error();
218233
}
234+
} else if meta_item.has_name(sym::cfg) {
235+
old_syntax = Some(false);
236+
237+
let mut names = Vec::new();
238+
let mut values: FxHashSet<_> = Default::default();
239+
240+
let mut any_specified = false;
241+
let mut values_specified = false;
242+
let mut values_any_specified = false;
243+
244+
for arg in args {
245+
if arg.is_word() && let Some(ident) = arg.ident() {
246+
if values_specified {
247+
error!("`cfg()` names cannot be after values");
248+
}
249+
names.push(ident);
250+
} else if arg.has_name(sym::any)
251+
&& let Some(args) = arg.meta_item_list()
252+
{
253+
if any_specified {
254+
error!("`any()` cannot be specified multiple times");
255+
}
256+
any_specified = true;
257+
if !args.is_empty() {
258+
error!("`any()` must be empty");
259+
}
260+
} else if arg.has_name(sym::values)
261+
&& let Some(args) = arg.meta_item_list()
262+
{
263+
if names.is_empty() {
264+
error!(
265+
"`values()` cannot be specified before the names"
266+
);
267+
} else if values_specified {
268+
error!(
269+
"`values()` cannot be specified multiple times"
270+
);
271+
}
272+
values_specified = true;
273+
274+
for arg in args {
275+
if let Some(LitKind::Str(s, _)) =
276+
arg.lit().map(|lit| &lit.kind)
277+
{
278+
values.insert(Some(s.to_string()));
279+
} else if arg.has_name(sym::any)
280+
&& let Some(args) = arg.meta_item_list()
281+
{
282+
if values_any_specified {
283+
error!(
284+
"`any()` in `values()` cannot be specified multiple times"
285+
);
286+
}
287+
values_any_specified = true;
288+
if !args.is_empty() {
289+
error!("`any()` must be empty");
290+
}
291+
} else {
292+
error!(
293+
"`values()` arguments must be string literals or `any()`"
294+
);
295+
}
296+
}
297+
} else {
298+
error!(
299+
"`cfg()` arguments must be simple identifiers, `any()` or `values(...)`"
300+
);
301+
}
302+
}
303+
304+
if values.is_empty() && !values_any_specified && !any_specified {
305+
values.insert(None);
306+
} else if !values.is_empty() && values_any_specified {
307+
error!(
308+
"`values()` arguments cannot specify string literals and `any()` at the same time"
309+
);
310+
}
311+
312+
if any_specified {
313+
if !names.is_empty()
314+
|| !values.is_empty()
315+
|| values_any_specified
316+
{
317+
error!("`cfg(any())` can only be provided in isolation");
318+
}
319+
320+
check_cfg.exhaustive_names = false;
321+
} else {
322+
for name in names {
323+
check_cfg
324+
.expecteds
325+
.entry(name.to_string())
326+
.and_modify(|v| match v {
327+
ExpectedValues::Some(v)
328+
if !values_any_specified =>
329+
{
330+
v.extend(values.clone())
331+
}
332+
ExpectedValues::Some(_) => *v = ExpectedValues::Any,
333+
ExpectedValues::Any => {}
334+
})
335+
.or_insert_with(|| {
336+
if values_any_specified {
337+
ExpectedValues::Any
338+
} else {
339+
ExpectedValues::Some(values.clone())
340+
}
341+
});
342+
}
343+
}
219344
} else {
220345
expected_error();
221346
}

compiler/rustc_interface/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(internal_output_capture)]
44
#![feature(thread_spawn_unchecked)]
55
#![feature(lazy_cell)]
6+
#![feature(let_chains)]
67
#![feature(try_blocks)]
78
#![recursion_limit = "256"]
89
#![allow(rustc::potential_query_instability)]

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ fn test_unstable_options_tracking_hash() {
779779
);
780780
tracked!(codegen_backend, Some("abc".to_string()));
781781
tracked!(crate_attr, vec!["abc".to_string()]);
782+
tracked!(cross_crate_inline_threshold, Some(200));
782783
tracked!(debug_info_for_profiling, true);
783784
tracked!(debug_macros, true);
784785
tracked!(dep_info_omit_d_target, true);

compiler/rustc_lint/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ lint_renamed_lint = lint `{$name}` has been renamed to `{$replace}`
494494
495495
lint_requested_level = requested on the command line with `{$level} {$lint_name}`
496496
497+
lint_span_use_eq_ctxt = use `.eq_ctxt()` instead of `.ctxt() == .ctxt()`
498+
497499
lint_supertrait_as_deref_target = `{$t}` implements `Deref` with supertrait `{$target_principal}` as target
498500
.label = target type is set here
499501

0 commit comments

Comments
 (0)