Skip to content

Commit 06b9450

Browse files
committed
Auto merge of #68405 - JohnTitor:rollup-kj0x4za, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #67734 (Remove appendix from Apache license) - #67795 (Cleanup formatting code) - #68290 (Fix some tests failing in `--pass check` mode) - #68297 ( Filter and test predicates using `normalize_and_test_predicates` for const-prop) - #68302 (Fix #[track_caller] and function pointers) - #68339 (Add `riscv64gc-unknown-linux-gnu` into target list in build-manifest) - #68381 (Added minor clarification to specification of GlobalAlloc::realloc.) - #68397 (rustdoc: Correct order of `async` and `unsafe` in `async unsafe fn`s) Failed merges: r? @ghost
2 parents b5a3341 + f6406f7 commit 06b9450

27 files changed

+266
-242
lines changed

LICENSE-APACHE

-25
Original file line numberDiff line numberDiff line change
@@ -174,28 +174,3 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
174174
of your accepting any such warranty or additional liability.
175175

176176
END OF TERMS AND CONDITIONS
177-
178-
APPENDIX: How to apply the Apache License to your work.
179-
180-
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
182-
replaced with your own identifying information. (Don't include
183-
the brackets!) The text should be enclosed in the appropriate
184-
comment syntax for the file format. We also recommend that a
185-
file or class name and description of purpose be included on the
186-
same "printed page" as the copyright notice for easier
187-
identification within third-party archives.
188-
189-
Copyright [yyyy] [name of copyright owner]
190-
191-
Licensed under the Apache License, Version 2.0 (the "License");
192-
you may not use this file except in compliance with the License.
193-
You may obtain a copy of the License at
194-
195-
http://www.apache.org/licenses/LICENSE-2.0
196-
197-
Unless required by applicable law or agreed to in writing, software
198-
distributed under the License is distributed on an "AS IS" BASIS,
199-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200-
See the License for the specific language governing permissions and
201-
limitations under the License.

src/libcore/alloc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ pub unsafe trait GlobalAlloc {
525525
/// The memory may or may not have been deallocated,
526526
/// and should be considered unusable (unless of course it was
527527
/// transferred back to the caller again via the return value of
528-
/// this method).
528+
/// this method). The new memory block is allocated with `layout`, but
529+
/// with the `size` updated to `new_size`.
529530
///
530531
/// If this method returns null, then ownership of the memory
531532
/// block has not been transferred to this allocator, and the

src/libcore/fmt/mod.rs

+34-41
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::mem;
1010
use crate::num::flt2dec;
1111
use crate::ops::Deref;
1212
use crate::result;
13-
use crate::slice;
1413
use crate::str;
1514

1615
mod builders;
@@ -234,8 +233,6 @@ pub struct Formatter<'a> {
234233
precision: Option<usize>,
235234

236235
buf: &'a mut (dyn Write + 'a),
237-
curarg: slice::Iter<'a, ArgumentV1<'a>>,
238-
args: &'a [ArgumentV1<'a>],
239236
}
240237

241238
// NB. Argument is essentially an optimized partially applied formatting function,
@@ -1043,8 +1040,6 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10431040
buf: output,
10441041
align: rt::v1::Alignment::Unknown,
10451042
fill: ' ',
1046-
args: args.args,
1047-
curarg: args.args.iter(),
10481043
};
10491044

10501045
let mut idx = 0;
@@ -1063,7 +1058,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10631058
// a string piece.
10641059
for (arg, piece) in fmt.iter().zip(args.pieces.iter()) {
10651060
formatter.buf.write_str(*piece)?;
1066-
formatter.run(arg)?;
1061+
run(&mut formatter, arg, &args.args)?;
10671062
idx += 1;
10681063
}
10691064
}
@@ -1077,6 +1072,39 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10771072
Ok(())
10781073
}
10791074

1075+
fn run(fmt: &mut Formatter<'_>, arg: &rt::v1::Argument, args: &[ArgumentV1<'_>]) -> Result {
1076+
fmt.fill = arg.format.fill;
1077+
fmt.align = arg.format.align;
1078+
fmt.flags = arg.format.flags;
1079+
fmt.width = getcount(args, &arg.format.width);
1080+
fmt.precision = getcount(args, &arg.format.precision);
1081+
1082+
// Extract the correct argument
1083+
let value = {
1084+
#[cfg(bootstrap)]
1085+
{
1086+
match arg.position {
1087+
rt::v1::Position::At(i) => args[i],
1088+
}
1089+
}
1090+
#[cfg(not(bootstrap))]
1091+
{
1092+
args[arg.position]
1093+
}
1094+
};
1095+
1096+
// Then actually do some printing
1097+
(value.formatter)(value.value, fmt)
1098+
}
1099+
1100+
fn getcount(args: &[ArgumentV1<'_>], cnt: &rt::v1::Count) -> Option<usize> {
1101+
match *cnt {
1102+
rt::v1::Count::Is(n) => Some(n),
1103+
rt::v1::Count::Implied => None,
1104+
rt::v1::Count::Param(i) => args[i].as_usize(),
1105+
}
1106+
}
1107+
10801108
/// Padding after the end of something. Returned by `Formatter::padding`.
10811109
#[must_use = "don't forget to write the post padding"]
10821110
struct PostPadding {
@@ -1114,41 +1142,6 @@ impl<'a> Formatter<'a> {
11141142
align: self.align,
11151143
width: self.width,
11161144
precision: self.precision,
1117-
1118-
// These only exist in the struct for the `run` method,
1119-
// which won’t be used together with this method.
1120-
curarg: self.curarg.clone(),
1121-
args: self.args,
1122-
}
1123-
}
1124-
1125-
// First up is the collection of functions used to execute a format string
1126-
// at runtime. This consumes all of the compile-time statics generated by
1127-
// the format! syntax extension.
1128-
fn run(&mut self, arg: &rt::v1::Argument) -> Result {
1129-
// Fill in the format parameters into the formatter
1130-
self.fill = arg.format.fill;
1131-
self.align = arg.format.align;
1132-
self.flags = arg.format.flags;
1133-
self.width = self.getcount(&arg.format.width);
1134-
self.precision = self.getcount(&arg.format.precision);
1135-
1136-
// Extract the correct argument
1137-
let value = match arg.position {
1138-
rt::v1::Position::Next => *self.curarg.next().unwrap(),
1139-
rt::v1::Position::At(i) => self.args[i],
1140-
};
1141-
1142-
// Then actually do some printing
1143-
(value.formatter)(value.value, self)
1144-
}
1145-
1146-
fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<usize> {
1147-
match *cnt {
1148-
rt::v1::Count::Is(n) => Some(n),
1149-
rt::v1::Count::Implied => None,
1150-
rt::v1::Count::Param(i) => self.args[i].as_usize(),
1151-
rt::v1::Count::NextParam => self.curarg.next()?.as_usize(),
11521145
}
11531146
}
11541147

src/libcore/fmt/rt/v1.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
#[derive(Copy, Clone)]
99
pub struct Argument {
10+
#[cfg(bootstrap)]
1011
pub position: Position,
12+
#[cfg(not(bootstrap))]
13+
pub position: usize,
1114
pub format: FormatSpec,
1215
}
1316

@@ -37,12 +40,11 @@ pub enum Alignment {
3740
pub enum Count {
3841
Is(usize),
3942
Param(usize),
40-
NextParam,
4143
Implied,
4244
}
4345

46+
#[cfg(bootstrap)]
4447
#[derive(Copy, Clone)]
4548
pub enum Position {
46-
Next,
4749
At(usize),
4850
}

src/librustc/mir/mono.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::dep_graph::{DepConstructor, DepNode, WorkProduct, WorkProductId};
22
use crate::ich::{Fingerprint, NodeIdHashingMode, StableHashingContext};
33
use crate::session::config::OptLevel;
4-
use crate::traits::TraitQueryMode;
54
use crate::ty::print::obsolete::DefPathBasedNames;
65
use crate::ty::{subst::InternalSubsts, Instance, InstanceDef, SymbolName, TyCtxt};
76
use rustc_data_structures::base_n;
@@ -168,9 +167,7 @@ impl<'tcx> MonoItem<'tcx> {
168167
MonoItem::GlobalAsm(..) => return true,
169168
};
170169

171-
// We shouldn't encounter any overflow here, so we use TraitQueryMode::Standard\
172-
// to report an error if overflow somehow occurs.
173-
tcx.substitute_normalize_and_test_predicates((def_id, &substs, TraitQueryMode::Standard))
170+
tcx.substitute_normalize_and_test_predicates((def_id, &substs))
174171
}
175172

176173
pub fn to_string(&self, tcx: TyCtxt<'tcx>, debug: bool) -> String {

src/librustc/query/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1156,11 +1156,11 @@ rustc_queries! {
11561156
desc { "normalizing `{:?}`", goal }
11571157
}
11581158

1159-
query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>, traits::TraitQueryMode)) -> bool {
1159+
query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
11601160
no_force
11611161
desc { |tcx|
1162-
"testing substituted normalized predicates in mode {:?}:`{}`",
1163-
key.2, tcx.def_path_str(key.0)
1162+
"testing substituted normalized predicates:`{}`",
1163+
tcx.def_path_str(key.0)
11641164
}
11651165
}
11661166

src/librustc/traits/fulfill.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use super::CodeSelectionError;
1616
use super::{ConstEvalFailure, Unimplemented};
1717
use super::{FulfillmentError, FulfillmentErrorCode};
1818
use super::{ObligationCause, PredicateObligation};
19-
use crate::traits::TraitQueryMode;
2019

2120
impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> {
2221
type Predicate = ty::Predicate<'tcx>;
@@ -63,9 +62,6 @@ pub struct FulfillmentContext<'tcx> {
6362
// a snapshot (they don't *straddle* a snapshot, so there
6463
// is no trouble there).
6564
usable_in_snapshot: bool,
66-
67-
// The `TraitQueryMode` used when constructing a `SelectionContext`
68-
query_mode: TraitQueryMode,
6965
}
7066

7167
#[derive(Clone, Debug)]
@@ -79,26 +75,12 @@ pub struct PendingPredicateObligation<'tcx> {
7975
static_assert_size!(PendingPredicateObligation<'_>, 136);
8076

8177
impl<'a, 'tcx> FulfillmentContext<'tcx> {
82-
/// Creates a new fulfillment context with `TraitQueryMode::Standard`
83-
/// You almost always want to use this instead of `with_query_mode`
78+
/// Creates a new fulfillment context.
8479
pub fn new() -> FulfillmentContext<'tcx> {
8580
FulfillmentContext {
8681
predicates: ObligationForest::new(),
8782
register_region_obligations: true,
8883
usable_in_snapshot: false,
89-
query_mode: TraitQueryMode::Standard,
90-
}
91-
}
92-
93-
/// Creates a new fulfillment context with the specified query mode.
94-
/// This should only be used when you want to ignore overflow,
95-
/// rather than reporting it as an error.
96-
pub fn with_query_mode(query_mode: TraitQueryMode) -> FulfillmentContext<'tcx> {
97-
FulfillmentContext {
98-
predicates: ObligationForest::new(),
99-
register_region_obligations: true,
100-
usable_in_snapshot: false,
101-
query_mode,
10284
}
10385
}
10486

@@ -107,7 +89,6 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
10789
predicates: ObligationForest::new(),
10890
register_region_obligations: true,
10991
usable_in_snapshot: true,
110-
query_mode: TraitQueryMode::Standard,
11192
}
11293
}
11394

@@ -116,7 +97,6 @@ impl<'a, 'tcx> FulfillmentContext<'tcx> {
11697
predicates: ObligationForest::new(),
11798
register_region_obligations: false,
11899
usable_in_snapshot: false,
119-
query_mode: TraitQueryMode::Standard,
120100
}
121101
}
122102

@@ -237,7 +217,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
237217
&mut self,
238218
infcx: &InferCtxt<'_, 'tcx>,
239219
) -> Result<(), Vec<FulfillmentError<'tcx>>> {
240-
let mut selcx = SelectionContext::with_query_mode(infcx, self.query_mode);
220+
let mut selcx = SelectionContext::new(infcx);
241221
self.select(&mut selcx)
242222
}
243223

src/librustc/traits/mod.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum IntercrateMode {
9595
}
9696

9797
/// The mode that trait queries run in.
98-
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, HashStable)]
98+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
9999
pub enum TraitQueryMode {
100100
// Standard/un-canonicalized queries get accurate
101101
// spans etc. passed in and hence can do reasonable
@@ -1014,17 +1014,16 @@ where
10141014
/// environment. If this returns false, then either normalize
10151015
/// encountered an error or one of the predicates did not hold. Used
10161016
/// when creating vtables to check for unsatisfiable methods.
1017-
fn normalize_and_test_predicates<'tcx>(
1017+
pub fn normalize_and_test_predicates<'tcx>(
10181018
tcx: TyCtxt<'tcx>,
10191019
predicates: Vec<ty::Predicate<'tcx>>,
1020-
mode: TraitQueryMode,
10211020
) -> bool {
1022-
debug!("normalize_and_test_predicates(predicates={:?}, mode={:?})", predicates, mode);
1021+
debug!("normalize_and_test_predicates(predicates={:?})", predicates);
10231022

10241023
let result = tcx.infer_ctxt().enter(|infcx| {
10251024
let param_env = ty::ParamEnv::reveal_all();
1026-
let mut selcx = SelectionContext::with_query_mode(&infcx, mode);
1027-
let mut fulfill_cx = FulfillmentContext::with_query_mode(mode);
1025+
let mut selcx = SelectionContext::new(&infcx);
1026+
let mut fulfill_cx = FulfillmentContext::new();
10281027
let cause = ObligationCause::dummy();
10291028
let Normalized { value: predicates, obligations } =
10301029
normalize(&mut selcx, param_env, cause.clone(), &predicates);
@@ -1044,12 +1043,12 @@ fn normalize_and_test_predicates<'tcx>(
10441043

10451044
fn substitute_normalize_and_test_predicates<'tcx>(
10461045
tcx: TyCtxt<'tcx>,
1047-
key: (DefId, SubstsRef<'tcx>, TraitQueryMode),
1046+
key: (DefId, SubstsRef<'tcx>),
10481047
) -> bool {
10491048
debug!("substitute_normalize_and_test_predicates(key={:?})", key);
10501049

10511050
let predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates;
1052-
let result = normalize_and_test_predicates(tcx, predicates, key.2);
1051+
let result = normalize_and_test_predicates(tcx, predicates);
10531052

10541053
debug!("substitute_normalize_and_test_predicates(key={:?}) = {:?}", key, result);
10551054
result
@@ -1102,10 +1101,7 @@ fn vtable_methods<'tcx>(
11021101
// Note that this method could then never be called, so we
11031102
// do not want to try and codegen it, in that case (see #23435).
11041103
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
1105-
// We don't expect overflow here, so report an error if it somehow ends
1106-
// up happening.
1107-
if !normalize_and_test_predicates(tcx, predicates.predicates, TraitQueryMode::Standard)
1108-
{
1104+
if !normalize_and_test_predicates(tcx, predicates.predicates) {
11091105
debug!("vtable_methods: predicates do not hold");
11101106
return None;
11111107
}

src/librustc/ty/instance.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ impl<'tcx> InstanceDef<'tcx> {
141141
}
142142

143143
pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool {
144-
tcx.codegen_fn_attrs(self.def_id()).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
144+
match *self {
145+
InstanceDef::Item(def_id) => {
146+
tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER)
147+
}
148+
_ => false,
149+
}
145150
}
146151
}
147152

src/librustc/ty/query/keys.rs

-9
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,6 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
125125
}
126126
}
127127

128-
impl<'tcx> Key for (DefId, SubstsRef<'tcx>, traits::TraitQueryMode) {
129-
fn query_crate(&self) -> CrateNum {
130-
self.0.krate
131-
}
132-
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
133-
self.0.default_span(tcx)
134-
}
135-
}
136-
137128
impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
138129
fn query_crate(&self) -> CrateNum {
139130
self.1.def_id().krate

0 commit comments

Comments
 (0)