Skip to content

Rollup of 6 pull requests #105008

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 22 commits into from
Nov 28, 2022
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
40a0533
small method code cleanup
lcnr Nov 25, 2022
a215b7b
remove `TypeError::ObjectUnsafeCoercion`
lcnr Nov 25, 2022
4f07008
remove confusing comment
lcnr Nov 25, 2022
6436c34
Remove SelectionContext::infcx() in favor of field access
compiler-errors Nov 25, 2022
61e185b
simplify some binder shifting logic
compiler-errors Nov 26, 2022
881862e
Rename `fn_trait_kind_from_{from_lang=>def_id}` to better convey meaning
WaffleLapkin Nov 22, 2022
d0c7ed3
Remove `ty::ClosureKind::from_def_id`
WaffleLapkin Nov 22, 2022
4b6e1d1
Add `TyCtxt::is_fn_trait`
WaffleLapkin Nov 22, 2022
fa89f53
Simplify `ty::ClosureKind::extends`
WaffleLapkin Nov 22, 2022
ea44792
micro doc fixes
WaffleLapkin Nov 22, 2022
5ba0056
Use `TyCtxt::is_fn_trait` is a couple more places
WaffleLapkin Nov 22, 2022
5b0e80e
Stabilize native library modifier `verbatim`
petrochenkov Nov 13, 2022
99c3dda
fix type
lcnr Nov 27, 2022
ab04080
Change multiline span ASCII art visual order
estebank Nov 23, 2022
6f64432
Tweak output
estebank Nov 23, 2022
136ffa2
fix clippy tests
estebank Nov 28, 2022
f33d409
Rollup merge of #104360 - petrochenkov:stabverb, r=TaKO8Ki
Dylan-DPC Nov 28, 2022
f90484d
Rollup merge of #104732 - WaffleLapkin:from_def_idn't, r=compiler-errors
Dylan-DPC Nov 28, 2022
79fe15c
Rollup merge of #104795 - estebank:multiline-spans, r=TaKO8Ki
Dylan-DPC Nov 28, 2022
8a84dd8
Rollup merge of #104890 - lcnr:small-cleanup, r=fee1-dead
Dylan-DPC Nov 28, 2022
9178bc0
Rollup merge of #104907 - compiler-errors:selcx-infcx, r=oli-obk
Dylan-DPC Nov 28, 2022
d5de2a8
Rollup merge of #104927 - compiler-errors:binder-shifting-logic, r=ol…
Dylan-DPC Nov 28, 2022
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
16 changes: 6 additions & 10 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
@@ -377,12 +377,8 @@ fn link_rlib<'a>(
find_native_static_library(name.as_str(), lib.verbatim, &lib_search_paths, sess);
if sess.opts.unstable_opts.packed_bundled_libs && flavor == RlibFlavor::Normal {
let filename = lib.filename.unwrap();
let lib_path = find_native_static_library(
filename.as_str(),
Some(true),
&lib_search_paths,
sess,
);
let lib_path =
find_native_static_library(filename.as_str(), true, &lib_search_paths, sess);
let src = read(lib_path)
.map_err(|e| sess.emit_fatal(errors::ReadFileError { message: e }))?;
let (data, _) = create_wrapper_file(sess, b".bundled_lib".to_vec(), &src);
@@ -465,7 +461,7 @@ fn collate_raw_dylibs<'a, 'b>(

for lib in used_libraries {
if lib.kind == NativeLibKind::RawDylib {
let ext = if matches!(lib.verbatim, Some(true)) { "" } else { ".dll" };
let ext = if lib.verbatim { "" } else { ".dll" };
let name = format!("{}{}", lib.name.expect("unnamed raw-dylib library"), ext);
let imports = dylib_table.entry(name.clone()).or_default();
for import in &lib.dll_imports {
@@ -1335,7 +1331,7 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
NativeLibKind::Static { bundle: Some(false), .. }
| NativeLibKind::Dylib { .. }
| NativeLibKind::Unspecified => {
let verbatim = lib.verbatim.unwrap_or(false);
let verbatim = lib.verbatim;
if sess.target.is_like_msvc {
Some(format!("{}{}", name, if verbatim { "" } else { ".lib" }))
} else if sess.target.linker_flavor.is_gnu() {
@@ -2306,7 +2302,7 @@ fn add_native_libs_from_crate(
_ => &codegen_results.crate_info.native_libraries[&cnum],
};

let mut last = (None, NativeLibKind::Unspecified, None);
let mut last = (None, NativeLibKind::Unspecified, false);
for lib in native_libs {
let Some(name) = lib.name else {
continue;
@@ -2323,7 +2319,7 @@ fn add_native_libs_from_crate(
};

let name = name.as_str();
let verbatim = lib.verbatim.unwrap_or(false);
let verbatim = lib.verbatim;
match lib.kind {
NativeLibKind::Static { bundle, whole_archive } => {
if link_static {
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
@@ -515,7 +515,7 @@ impl<'a> Linker for GccLinker<'a> {
// -force_load is the macOS equivalent of --whole-archive, but it
// involves passing the full path to the library to link.
self.linker_arg("-force_load");
let lib = find_native_static_library(lib, Some(verbatim), search_path, &self.sess);
let lib = find_native_static_library(lib, verbatim, search_path, &self.sess);
self.linker_arg(&lib);
}
}
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ pub struct NativeLib {
pub name: Option<Symbol>,
pub filename: Option<Symbol>,
pub cfg: Option<ast::MetaItem>,
pub verbatim: Option<bool>,
pub verbatim: bool,
pub dll_imports: Vec<cstore::DllImport>,
}

@@ -127,7 +127,7 @@ impl From<&cstore::NativeLib> for NativeLib {
filename: lib.filename,
name: lib.name,
cfg: lib.cfg.clone(),
verbatim: lib.verbatim,
verbatim: lib.verbatim.unwrap_or(false),
dll_imports: lib.dll_imports.clone(),
}
}
10 changes: 8 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
@@ -2282,7 +2282,7 @@ impl FileWithAnnotatedLines {
}

// Find overlapping multiline annotations, put them at different depths
multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, ml.line_end));
multiline_annotations.sort_by_key(|&(_, ref ml)| (ml.line_start, usize::MAX - ml.line_end));
for (_, ann) in multiline_annotations.clone() {
for (_, a) in multiline_annotations.iter_mut() {
// Move all other multiline annotations overlapping with this one
@@ -2300,8 +2300,14 @@ impl FileWithAnnotatedLines {
}

let mut max_depth = 0; // max overlapping multiline spans
for (file, ann) in multiline_annotations {
for (_, ann) in &multiline_annotations {
max_depth = max(max_depth, ann.depth);
}
// Change order of multispan depth to minimize the number of overlaps in the ASCII art.
for (_, a) in multiline_annotations.iter_mut() {
a.depth = max_depth - a.depth + 1;
}
for (file, ann) in multiline_annotations {
let mut end_ann = ann.as_end();
if !ann.overlaps_exactly {
// avoid output like
108 changes: 54 additions & 54 deletions compiler/rustc_expand/src/tests.rs
Original file line number Diff line number Diff line change
@@ -272,13 +272,13 @@ error: foo
--> test.rs:3:3
|
3 | X0 Y0
| ____^__-
| | ___|
| ___^__-
| |___|
| ||
4 | || X1 Y1
5 | || X2 Y2
| ||____^__- `Y` is a good letter too
| |____|
| |_____|
| `X` is a good letter
"#,
@@ -311,12 +311,12 @@ error: foo
--> test.rs:3:3
|
3 | X0 Y0
| ____^__-
| | ___|
| ___^__-
| |___|
| ||
4 | || Y1 X1
| ||____-__^ `X` is a good letter
| |_____|
| |____|
| `Y` is a good letter too
"#,
@@ -351,13 +351,13 @@ error: foo
--> test.rs:3:6
|
3 | X0 Y0 Z0
| ______^
4 | | X1 Y1 Z1
| |_________-
| _______^
4 | | X1 Y1 Z1
| | _________-
5 | || X2 Y2 Z2
| ||____^ `X` is a good letter
6 | | X3 Y3 Z3
| |_____- `Y` is a good letter too
6 | | X3 Y3 Z3
| |____- `Y` is a good letter too
"#,
);
@@ -395,15 +395,15 @@ error: foo
--> test.rs:3:3
|
3 | X0 Y0 Z0
| _____^__-__-
| | ____|__|
| || ___|
| ___^__-__-
| |___|__|
| ||___|
| |||
4 | ||| X1 Y1 Z1
5 | ||| X2 Y2 Z2
| |||____^__-__- `Z` label
| ||____|__|
| |____| `Y` is a good letter too
| ||_____|__|
| |______| `Y` is a good letter too
| `X` is a good letter
"#,
@@ -487,17 +487,17 @@ error: foo
--> test.rs:3:6
|
3 | X0 Y0 Z0
| ______^
4 | | X1 Y1 Z1
| |____^_-
| _______^
4 | | X1 Y1 Z1
| | ____^_-
| ||____|
| | `X` is a good letter
5 | | X2 Y2 Z2
| |____-______- `Y` is a good letter too
| ____|
| |
6 | | X3 Y3 Z3
| |________- `Z`
| | `X` is a good letter
5 | | X2 Y2 Z2
| |___-______- `Y` is a good letter too
| ___|
| |
6 | | X3 Y3 Z3
| |_______- `Z`
"#,
);
@@ -570,14 +570,14 @@ error: foo
--> test.rs:3:6
|
3 | X0 Y0 Z0
| ______^
4 | | X1 Y1 Z1
| |____^____-
| _______^
4 | | X1 Y1 Z1
| | ____^____-
| ||____|
| | `X` is a good letter
5 | | X2 Y2 Z2
6 | | X3 Y3 Z3
| |___________- `Y` is a good letter too
| | `X` is a good letter
5 | | X2 Y2 Z2
6 | | X3 Y3 Z3
| |__________- `Y` is a good letter too
"#,
);
@@ -941,18 +941,18 @@ error: foo
--> test.rs:3:6
|
3 | X0 Y0 Z0
| ______^
4 | | X1 Y1 Z1
| |____^____-
| _______^
4 | | X1 Y1 Z1
| | ____^____-
| ||____|
| | `X` is a good letter
5 | | 1
6 | | 2
7 | | 3
... |
15 | | X2 Y2 Z2
16 | | X3 Y3 Z3
| |___________- `Y` is a good letter too
| | `X` is a good letter
5 | | 1
6 | | 2
7 | | 3
... |
15 | | X2 Y2 Z2
16 | | X3 Y3 Z3
| |__________- `Y` is a good letter too
"#,
);
@@ -996,21 +996,21 @@ error: foo
--> test.rs:3:6
|
3 | X0 Y0 Z0
| ______^
4 | | 1
5 | | 2
6 | | 3
7 | | X1 Y1 Z1
| |_________-
| _______^
4 | | 1
5 | | 2
6 | | 3
7 | | X1 Y1 Z1
| | _________-
8 | || 4
9 | || 5
10 | || 6
11 | || X2 Y2 Z2
| ||__________- `Z` is a good letter too
... |
15 | | 10
16 | | X3 Y3 Z3
| |_______^ `Y` is a good letter
... |
15 | | 10
16 | | X3 Y3 Z3
| |________^ `Y` is a good letter
"#,
);
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
@@ -237,6 +237,8 @@ declare_features! (
(accepted, native_link_modifiers, "1.61.0", Some(81490), None),
/// Allows specifying the bundle link modifier
(accepted, native_link_modifiers_bundle, "1.63.0", Some(81490), None),
/// Allows specifying the verbatim link modifier
(accepted, native_link_modifiers_verbatim, "CURRENT_RUSTC_VERSION", Some(81490), None),
/// Allows specifying the whole-archive link modifier
(accepted, native_link_modifiers_whole_archive, "1.61.0", Some(81490), None),
/// Allows using non lexical lifetimes (RFC 2094).
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
@@ -455,8 +455,6 @@ declare_features! (
(active, naked_functions, "1.9.0", Some(32408), None),
/// Allows specifying the as-needed link modifier
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),
/// Allows specifying the verbatim link modifier
(active, native_link_modifiers_verbatim, "1.53.0", Some(81490), None),
/// Allow negative trait implementations.
(active, negative_impls, "1.44.0", Some(68318), None),
/// Allows the `!` type. Does not imply 'exhaustive_patterns' (below) any more.
16 changes: 10 additions & 6 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
@@ -179,12 +179,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

// Hack: we know that there are traits implementing Fn for &F
// where F:Fn and so forth. In the particular case of types
// like `x: &mut FnMut()`, if there is a call `x()`, we would
// normally translate to `FnMut::call_mut(&mut x, ())`, but
// that winds up requiring `mut x: &mut FnMut()`. A little
// over the top. The simplest fix by far is to just ignore
// this case and deref again, so we wind up with
// `FnMut::call_mut(&mut *x, ())`.
// like `f: &mut FnMut()`, if there is a call `f()`, we would
// normally translate to `FnMut::call_mut(&mut f, ())`, but
// that winds up potentially requiring the user to mark their
// variable as `mut` which feels unnecessary and unexpected.
//
// fn foo(f: &mut impl FnMut()) { f() }
// ^ without this hack `f` would have to be declared as mutable
//
// The simplest fix by far is to just ignore this case and deref again,
// so we wind up with `FnMut::call_mut(&mut *f, ())`.
ty::Ref(..) if autoderef.step_count() == 0 => {
return None;
}
12 changes: 0 additions & 12 deletions compiler/rustc_hir_typeck/src/cast.rs
Original file line number Diff line number Diff line change
@@ -46,7 +46,6 @@ use rustc_span::def_id::{DefId, LOCAL_CRATE};
use rustc_span::symbol::sym;
use rustc_span::Span;
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::error_reporting::report_object_safety_error;

/// Reifies a cast check to be checked once we have full type information for
/// a function context.
@@ -727,9 +726,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
debug!(" -> CoercionCast");
fcx.typeck_results.borrow_mut().set_coercion_cast(self.expr.hir_id.local_id);
}
Err(ty::error::TypeError::ObjectUnsafeCoercion(did)) => {
self.report_object_unsafe_cast(&fcx, did);
}
Err(_) => {
match self.do_check(fcx) {
Ok(k) => {
@@ -741,14 +737,6 @@ impl<'a, 'tcx> CastCheck<'tcx> {
};
}
}

fn report_object_unsafe_cast(&self, fcx: &FnCtxt<'a, 'tcx>, did: DefId) {
let violations = fcx.tcx.object_safety_violations(did);
let mut err = report_object_safety_error(fcx.tcx, self.cast_span, did, violations);
err.note(&format!("required by cast to type '{}'", fcx.ty_to_string(self.cast_ty)));
err.emit();
}

/// Checks a cast, and report an error if one exists. In some cases, this
/// can return Ok and create type errors in the fcx rather than returning
/// directly. coercion-cast is handled in check instead of here.
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
@@ -178,7 +178,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
let kind = object_type
.principal_def_id()
.and_then(|did| self.tcx.fn_trait_kind_from_lang_item(did));
.and_then(|did| self.tcx.fn_trait_kind_from_def_id(did));
(sig, kind)
}
ty::Infer(ty::TyVar(vid)) => self.deduce_signature_from_predicates(
@@ -235,7 +235,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
_ => None,
};
if let Some(closure_kind) =
trait_def_id.and_then(|def_id| self.tcx.fn_trait_kind_from_lang_item(def_id))
trait_def_id.and_then(|def_id| self.tcx.fn_trait_kind_from_def_id(def_id))
{
expected_kind = Some(
expected_kind
@@ -263,7 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let trait_def_id = projection.trait_def_id(tcx);

let is_fn = tcx.fn_trait_kind_from_lang_item(trait_def_id).is_some();
let is_fn = tcx.is_fn_trait(trait_def_id);
let gen_trait = tcx.require_lang_item(LangItem::Generator, cause_span);
let is_gen = gen_trait == trait_def_id;
if !is_fn && !is_gen {
Loading