Skip to content
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

2018 edition allows ungated access to unstable crates #52489

Closed
alexcrichton opened this issue Jul 18, 2018 · 2 comments
Closed

2018 edition allows ungated access to unstable crates #52489

alexcrichton opened this issue Jul 18, 2018 · 2 comments
Labels
A-rust-2018-preview Area: The 2018 edition preview T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@alexcrichton
Copy link
Member

When compiled with --edition 2018 this code compiles just fine:

use rustc;

fn main() {}

That's bad!

@alexcrichton alexcrichton added this to the Rust 2018 Preview 2 milestone Jul 18, 2018
@alexcrichton alexcrichton added the A-rust-2018-preview Area: The 2018 edition preview label Jul 18, 2018
@Mark-Simulacrum Mark-Simulacrum added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 31, 2018
@Mark-Simulacrum
Copy link
Member

@rust-lang/compiler Can we get some eyes on this, not necessarily to fix but at least to confirm that we believe a fix can be made and landed in time for RC? This is a hard-stop blocker for RC.

@eddyb
Copy link
Member

eddyb commented Aug 1, 2018

So this is generally harmless (you can't actually get anything from the unstable crate), except for it being a minor dead-code-but-allowed hazard.

The culprit appears to be this special-casing:

// FIXME: Last path segment is treated specially in import resolution, so extern crate
// mode for absolute paths needs some special support for single-segment imports.
if module_path.len() == 1 && (module_path[0].name == keywords::CrateRoot.name() ||
module_path[0].name == keywords::Extern.name()) {
let is_extern = module_path[0].name == keywords::Extern.name() ||
(self.session.features_untracked().extern_absolute_paths &&
self.session.rust_2018());

Which loads the crate (producing an error if no crate with that name exists), but doesn't record the resolution. So there's nothing to check - and presumably no way to use that broken import.

The part that's missing is this (recording the import resolutions):

// Record what this import resolves to for later uses in documentation,
// this may resolve to either a value or a type, but for documentation
// purposes it's good enough to just favor one over the other.
self.per_ns(|this, ns| if let Some(binding) = result[ns].get().ok() {
let import = this.import_map.entry(directive.id).or_default();
import[ns] = Some(PathResolution::new(binding.def()));
});

But the special-casing exits early:

let _ = self.try_define(directive.parent, target, TypeNS, binding);
return None;

Expected minimal diff (between the two lines in the last snippet):

let import = self.import_map.entry(directive.id).or_default(); 
import[TypeNS] = Some(PathResolution::new(binding.def())); 

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Aug 1, 2018
rustc_resolve: record single-segment extern crate import resolutions.

Fixes rust-lang#52489 by recording special-cased single-segment imports for later (e.g. stability) checks.

cc @alexcrichton @Mark-Simulacrum @petrochenkov

Does this need to be backported?
pietroalbini added a commit to pietroalbini/rust that referenced this issue Aug 1, 2018
rustc_resolve: record single-segment extern crate import resolutions.

Fixes rust-lang#52489 by recording special-cased single-segment imports for later (e.g. stability) checks.

cc @alexcrichton @Mark-Simulacrum @petrochenkov

Does this need to be backported?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust-2018-preview Area: The 2018 edition preview T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants